DOSbox - on iPad

The Problem:  This whole effort has been driven by the math problems in DOSbox.  I fixed these on my first Blackberry Playbook version, and then later, on my Android gDOSbox stuff, and the GNUplot37 and APL's that I put up on the Google Play Store.  But DOSpad, the DOSbox inplementation on my hacked iPad has math problems.  I had to use a hacked/jailbroken iPad, since Apple iStore does *not* allow any programming languages or interpreters, and locks you into the "sandbox" where you cannot even save your own files to your own device.    The essense of the problem is shown in pic on screen right - the "Math Overflow Error" in a simple Fortran program that calculates sine using a Taylor series.  And it gets worse in GNUplot, with crazy number values appearing on the axis of graphs.

On the iPad1, running DOSpad, the math fails.  But running my repaired version (DOSpad Math) in an Xcode iPad device simulator, the same program calculates correctly.

[Nov. 1, 2017] - Solution Update:  I got the repaired DOSBOX code to run on the original iPad.  I call it: DOSPAD-Gsys.  DOSPAD-Gsys app running on the older iPad, and have installed the original IBM/Microsoft Fortran 5.1 compiler under DOSPAD-Gsys, and got it to work right.   (See screen below, which shows the "demo1.for" program running on both iPad 1 and inside a Windows "Cmd" shell.  Note:  The IBM/Microsoft Fortran 5.1 *compiler* runs on the iPad, not just Fortran programs.   You can write and compile ".for" programs on the iPad, and then run them inside of DOSPAD-Gsys.   The screen following the demo1.for sine calculator is the REALG.FOR sample program that draws graphics on the screen.  Again, it is shown running on the iPad, and inside a Windows "Cmd" shell (which jumps to full screen, if run directly in Windows "Cmd".  If you run it in Windows version of DOSBOX, it can be run in a proper Windows window.)


Using Xcode to Deploy To a Real iPad 2

The Solution:   The solution here was to create a math-fixed version of DOSbox for the iPad that could actually be deployed to a real iPad.  This turns out to be a non-trivial project.  Something that should be a "./configure .. make .. make install" effort (10 minutes, maybe) on a Linux box, turns into a long, multi-day effort, with a few very late night search missions thru most of the IOS stuff on Stack Overflow.  After installing 4 different versions of Xcode (standardized on ver. 6.3.2, as I still am trying to get my new  "DOSpad Math" version of DOSbox onto by beloved iPad1 [Update: Fall, 2017: Got it working!] ).   But I have succeeded in getting a deployed version (using Xcode 7.1.1) to an iPad2, where I have confirmed the math routines run.  The picture at right, shows GNUplot37 running correctly in the Xcode Device Simulator.  Just getting the DOSpad fork, and the DOSbox stuff to compile under Xcode was an unbelievable amount of work, involving all-night head banging... Real "heavy metal" effort... 🙂

And here is "DOSpad Math" running GNUplot37 on an iPad2. The massive amount of floating-point calcs required to draw a 3-D surface in GNUplot are a good test of an emulator's FPU (floating point unit) math processing capabilities. But I'm not sure if my developer credentials that code-signed the iPad's deployment will trigger what we used to call a "time-bomb", and stop the app from working in a week. Plus, I cannot migrate any GNUplot files, data-series, or workspaces until and unless I jailbreak the iPad2. But the proof-of-concept works. The iPad2 with it's little ARM chip, can be a powerful workstation you can slip in your pocket - if only Apple would be more sensible, and accommodate its developer community. They could allow FTP access to local storage, the way Android has always done. This would make the iPad vastly more useful. Apple might consider acting less like an abusive commandant of the IOS "jail", and more like a helpful concierge of a high-end hotel! Wouldn't that be a viable and profitable strategy? :)

DOSPAD-Gsys & Fortran!

I managed to get a further modified DOSbox running on the iPad 1, which I call the DOSPAD-Gsys version of the DOSBOX code, which includes the math-fixes.  As a test, and to see if it could support some real work, I put an original Fortran compiler on the iPad.

I deployed the entire IBM/Microsoft Fortran 5.1 *compiler* (not just the running programs) from a Windows box to the iPad-1 application data area, and got it to work.  This was again, non-trivial.  With Fortran 5.1, you can do absolutely anything.   This approach works.  It means NO MORE annoying "Killed 9" issue like I get running native code on the restrictive and deliberately crippled Apple iOS operating system.

Since the iPad was jailbroken (and I had root access), I was able to drop the Fortran 5.1 compiler into the application data area for the DOSPAD-Gsys app.  This is key.  You have to use "root" and the Linux/Unix utilities to change the protections, so that the compiler can actually create files on the fly, it needs to run.  The Apple "Sandbox" restrictions work hard to prevent you actually doing anything useful with iPad, but once jailbroken, you can bypass a lot of this foolish nonsense.  You can use the iPad, like a real computer.

Note, you have to use OpenSSH and OpenSSL and the entire Cygwin suite to get code like "ssh" and "scp" running on your Windows box.  (They are typically standard login access and file transfer utilities on a Linux box.  But you can get the open-source code suites to install OpenSSH and OpenSSL for your Windows box, and you need that to login to the iPad and migrate files back and forth easily.  I also configured the iPad with static IP#'s in IPv4, so it can be accessed by any machine in the lab - Linux, Android, Windows or iOS-Apple.  Of course, the most work and difficulty is with the Apple MacBook.)

Below are some quick notes (very preliminary) on how I moved the Fortran 5.1 Compiler to iPad 1, which is now running DOSPAD-Gsys, a local iPad version of DOSbox:


Notes on the "DOSPAD-Gsys" app on the iPad - IBM/Microsoft Fortran 5.1  Example

Just a note on the "DOSPAD Gsys" app on the iPad...

The data area for this app (essentially, the emulated DOS C-disk), is in
the directory:


You can create a directory (example FORTRAN5), and put stuff from your Windows box
onto a directory there, and access it inside the DOS emulator, if you have
root access to the iPad.

This means you can run the same code on a Windows box (assuming it runs in a
DOS-style "Cmd" shell window), and on the iPad.  It is not super-fast, but it
can be sufficiently accurate for financial and scientific purposes.

Eg:  How to migrate a simple program:

    1) Log into the iPad from your Windows or Linux box, using "ssh".
       The "ssh" program stands for "secure shell".
       You will have had to install the "ssh" stuff on the iPad, as part
       of the jailbreak process that you use to get root access to the
       iPad.  You will have ssh, sshd, and scp by default on a Linux
       setup, typically.  If you are running Windows (eg. WinXP/SP3 or
       higher), you can use the cygwin utilities and OpenSSH to put the
           "ssh" and "scp" programs on your Windows box.

                 ( on Windows box )

                  C:\FORTRAN> ssh root@L2-ipad     
                  root@L2-ipad's password:                   (enter the root password you setup as part of the jailbreak)

          iPad:~ root#                                              (you are now logged into the iPad as if it were a standard Linux/Unix computer )

          iPad:~ root# ls -l                                        (list the files here )

          iPad:~ root# cd /                                       (go to the very top root directory,  and see what is there... )

          iPad:~ root# ls -l

          iPad:~ root# cd User                                  ( cd to the User area. It is also called /var/mobile )

          iPad:~ root# pwd                                       ( pwd stands for "print working directory"  )

                                                                         ( it says "/User", but it is actually "/var/mobile" )
          iPad:~ root# ls -l                                        ( list all the files ... )

          iPad:~ root# cd /var/mobile

           iPad:~ root# ls -l      
                                                                         ( same bunch of files and directories )
                                                                         ( Note in the root directory, the "/", the directory /User is in a different colour, and has a trailing @ behind it. It is a link file, pointing to the /var/mobile directory )

    2) Go to the /var/mobile/Applications or /User/Applications directory (they are same)
           and then look thru the silly long hex names for your DOSPAD directory. Mine is
           in /F3CCD1C6-4BBB-4900-9595-7834E14C4946

          ( you are still logged into the root account on your iPad ...)

        iPad:~ root# cd /var/mobile/Applications
        iPad:~ root# ls -l                         ( look for your DOSPAD-Gsys directory )

        iPad:~ root# cd F3CC     ( and press the ESC key.  The iPad psudo-Linux operating system will fill in the full file name, and you can press return, and connect)

     3) Once in the DOSPAD

                ( connect to the Documents directory )
                (this ../Documents directory is your "C:\" data directory for DOSPAD-Gsys )

                ( you can make a directory here, and copy files back and forth from your
                 Windows or Linux machine, using "scp" (which stands for "secure copy" ) )

        ls -l
        mkdir FORTRAN5
        cd FORTRAN5

        (if you have setup your "hosts" file correctly on the iPad, and you have an "sshd" demon running on your Windows or Linux box, you can just use "scp" to migrate a bunch of files from a remote machine into this directory. )

        (In our example here, we grab the old IBM/Microsoft Fortran 5.1 compiler and dev. tools and put them here...)

        ping hpxp         ( make sure you can see your remote box. Mine is called "hpxp" )
        ps aux              ( look at the running process on the iPad, see if all is working... )

                scp Myuserid@hpxp:/cygdrive/c/FORTRAN5/demo1.exe .

                             ( move a program over.  Protections may stop the copy working...)

                             ( use chmod to open up the directory.  No security now, be careful..)
        cd ..
        chmod 777 FORTRAN5   
        cd FORTRAN5

                scp Myuserid@hpxp:/cygdrive/c/FORTRAN5/demo1.exe

                scp -r Myuserid@hpxp:/cygdrive/c/FORTRAN5/* .         

                                                                      ( the -r means move *all* the

                                                                       FORTRAN5 files over into the
                                                                       DOSPAD-Gsys directory )

       4) Logout of root on the iPad, and try it to see if you can run "demo1.exe" on the iPad,
              from within DOSPAD.


                      (grab the iPad, double press the DOSPAD-Gsys icon and try to run "demo1.exe" )

                      (Start DOSPAD-Gsys and enter ...)

        cd FORTRAN5

                     ( you should see the simple sine calculations...)


                           ( If you have copied all the FORTRAN5 files over, then

                           you will see programs: COLTEXT.EXE, REALG.EXE,
                           SIEVE.EXE, GRAPHIC.EXE and SINE.EXE.  You can
                           run these, and inspect the source to see what is
                           possible with Fortran 5.1 iPad with DOSPAD-Gsys.)

- MCL, Oct. 2017
  ssh and scp to the Windows XP/SP3 box (hpxp) was not working initially, even from Linux boxes.  
    Now fixed.  I had stopped some network services on Windows, probably why. Had to reboot to fix.
    I am running OpenSSH7 and it works well.  In the OpenSSH7 there is a link to the
     home directory on the Windows box, and it has the gpg keys and the file of previous known
    hosts, and such.  OpenSSH7 looks like it starts "cygrunsrv" process, which shows up in the
    Windows Tasks lists.  When working, I can "ssh" into the Windows HPXP box, from both the iPad
    and the Linux boxes (CentOS and Fedora9 boxes).   Also, scp can be used, but you have to
    remember to use /cygdrive/c/... in front of the files on c: disk, and I suppose /cygdrive/e/
    in front of files on e: disk.

    I am running "cygrunsrv" in tasks, looks to be the openssh7 stuff.  Had to shutdown and restart
    the WindowsXP/SP3 box, to get the sshd stuff working right for Windows-32 OpenSSH7.

    Put all of the FORTRAN5 stuff onto iPad and the CentOS box.  Ran tests, confirmed DOSPAD-Gsys
    runs all original Fortran-5.1 programs that run in Windows "Cmd" shell.

- MCL, Nov 1, 2017

    In Linux (CentOS and Fedora), you use DOSemu to run the Fortran files and compiler. 

    On Windows, you can use either Windows DOSbox, or the Windows "Cmd" shell to run Fortran-built .EXE files.
    On iPad and Android, the GEMESYS implementations of DOSbox - DOSPAD-Gsys on
    iPad and gDOSBOX on Android.  Tests with the original commercial-quality IBM/Microsoft Fortran 5.1
    compiler confirm that the single and double precision math calculations appear to be working
    correctly, and yielding consistant, self-similar results across all platforms.

    Note to get the compiler to work, you have to set the path, and some environment variables:
    See Fortran-supplied file called: NEW-VARS.BAT
        On thie iPad, I put the Fortran compiler into directory called: FORTRAN5 on virtual C:\ disk, so I need to run this file below. 
        File: NEWVARS5.BAT

        SET PATH=%PATH%;C:\FORTRAN5\BIN\;C:\FORTRAN5\BINB\;C:\fortran5\lib;\c:\fortran5\include;C:\;
        SET TMP=C:\TEMP

        You also have to make sure that the C:\TEMP directory has write-access, or the compiler will
        fail with a file-write error.


How To run the IBM/Microsoft Fortran 5.1 compiler and compile DEMO1.FOR:


       ( from within DOSPAD-Gsys or in Windows Cmd shell, or on Linux DOSemu window: )

               C:\FORTRAN5> NEWVARS5

       ( this sets up the path and environment variables )

              C:\FORTRAN5> FL DEMO1.FOR

       ( this will compile the program DEMO1.FOR and make DEMO1.EXE, an executable program file.  It shows a Taylor Series calculating sine. Run it and check that it works.)

             C:\FORTRAN> DEMO1.EXE


       Code:   DEMO1.FOR


C This program evaluates and prints the trigonometric sine
C of ten numbers using two methods:
C     1. A function, MYSIN, which uses a Taylor
C        series approximation.
C     2. The intrinsic function SIN from the
C        RM/FORTRAN library.
      REAL MYSIN,X(10,3)
      OPEN(6, FILE='CON')
2000  FORMAT(10X,'X',10X,'MYSIN(X)',11X,'SIN(X)',11X,
     1         'TERMS',/)
      DO 10 I = 1, 10
      VAL = I * 0.1
      X(I,1) = VAL
      X(I,2) = MYSIN(VAL,N)
      X(I,3) = SIN(VAL)
10    NUMBER(I) = N
      WRITE (6,20)  (( X(J,I),I=1,3),NUMBER(J),J=1,10)
20    FORMAT(7X, F5.1, 8X, F10.8, 9X, F10.8, 8X, I3)
C This function computes the sine of the first argument P1 using
C a Taylor series.  It also returns in P2 the number of Taylor
C series terms required.
      REAL P1
      INTEGER P2
      MYSIN = P1
      DO 10 P2 = 1,100
      DELTA = (-1)**P2 * P1**(2*P2+1) / FACTRL(2*P2+1)
      IF (ABS(DELTA) .LT. 1E-7) RETURN
C This function evaluates the factorial of the integer argument.
      FACTRL = 1
      DO 10 K=2,I

You can compile this Fortran program on the all platforms.  It should produce the results shown in the first screen below


[ See Images below - .EXE files running on Windows Cmd shell, and on iPad, under DOSPAD-Gsys.  Note that within Fortran 5.1, the original MS-DOS graphics features work also. It all seems to work on Linux running DOSemu, as well.]

Got it! Got DOSPAD-Gsys on the iPad 1 working right. This is the original IBM/Microsoft Fortran 5.1 Compiler and built-programs (as .EXE files) running on an iPad 1 (first generation), and on a WIndows-XP/SP3 box, inside a standard Windows "Cmd" shell. The "demo1" program works, which calculates sine, and so does the "Sieve of Eratosthenes", a process for determining prime numbers. The graphics programs built using Fortran5 also run correctly on both machines.

This is a program called "REALG.FOR", running on iPad under DOSPAD-Gsys, and on a Windows box on the right, using the standard "Cmd" shell. It calculates real numbers, and displays them as graphics. It is a test program included in the /FORTRAN/SOURCE/SAMPLES directory of the original Fortran 5.1 compiler, offered by both IBM and Microsoft, back in the early 1990's, for MS-DOS and OS/2. This is a full-featured, commercial-quality compiler, which can still be used to do useful calculations. I have a matrix inversion program, and a program for matrix multiplication, which can thus be used to evalute the tensors generated by a neural-network. You can basically take the results of your NN-AI, and drop them onto the iPad, and evaluated a data-block, sourced from data harvested from the internet. Note that you can *run the compiler* on the iPad, and create working programs, without the resorting to the complex toolsets and program development environments required to construct and deploy modern iOS "apps". Note: I have Python 2.7 also running on this iPad, but getting it to load the useful libraries (ie. NUMPY and such) proves to be problematic. The Python NUMPY library is simply the original IMSL routines - which are very useful, debugged, mathematically correct programs - and were all written in Fortran. I expect to be able to use those here, using this original Fortran 5.1 compiler.

DOSemu running the REALG.FOR Fortran 5.1 under DOSemu on CentOS 6.6 Linux. Works good.

Running the Microsoft Fortran 5.1 test program, "DEMO1.FOR" in DOSemu, on CentOS 6.6 Linux. Also works correctly, using both single and double precision REALs.