Computing: DOS, OS/2 & Windows Programming

Installing and running GFA-BASIC on FreeDOS.

"GFA-BASIC is a dialect of the BASIC programming language, by Frank Ostrowski. The name is derived from the company ("GFA Systemtechnik GmbH"), which distributed the software. In the mid-1980s to the 1990s it enjoyed popularity as an advanced BASIC dialect, but has been mostly superseded by several other programming languages.", you can read in Wikipedia. GFA-BASIC has a long history. The first version was released in 1985 for the Atari ST, followed by a version for the Amiga. Then GFA-BASIC was developed for the Intel processors: GFA-BASIC for MS-DOS, GFA-BASIC for Windows 3.1, and GFA-BASIC 32 for Windows 95 and later, including the latest Windows releases.

That GFA-BASIC 32 wouldn't probably be the first choice of BASIC programmers on actual Windows versions, I wrote in my BASIC programming: Alternatives to Microsoft Visual Basic tutorial. On DOS, this is a completely different story. Probably not only the best BASIC, but the best whatever programming language available. GFA-BASIC for DOS includes over 500 commands and functions (and lots of pre-defined variables), with all that you need to do structured programming. It includes the math not only for integers and reals, but also for bits and matrices. It includes inline assembly, direct access to the CPU registers and the computer memory. There are more and more powerful text graphics routines as in other BASIC dialects. It also allows to manipulate drawings (ex: mirroring) and text (ex: magnify, stretch).But, the amazing thing is: GFA-BASIC allows to create real GUI applications. You can create menu bars with pull-down menus, alerts and pop-up menus. And, you can create windows! Real desktop-style Windows (with scrollbars, and full mouse support), that you can open and close, minimize and maximize, move around on the screen. Multiple windows applications, implemented by easy to use commands, on plain DOS - I had no idea that this does exist! Amazing!

This tutorial is about the installation of GFA-BASIC 4.51 on FreeDOS. I suppose that it also applies to other DOS platforms. The software can be downloaded from the FreeDOS repository at github. Unfortunately, the download is only a trial version limited to some 300 lines of code. This will not allow to create really big applications, but on the other hand, the commands and functions of GFA-BASIC are really powerful, and you can do a lot with few code. And, there is always the possibility to write several programs that call one another.

The download archive includes the folder structure of a typical FreeDOS package. I unpacked the files on my Windows 10 and created a CD ISO. On my FreeDOS machine, with FreeDOS installed in c:\freedos, and the development software in c:\devel, I created the directory c:\devel\gfacomp and copied the content of the 3 installation folders appinfo, links, and devel\gfacomp (that I had put into a the common folder fdos on my CDROM, drive F:) to my harddisk using the following commands:
    mkdir c:\devel\gfacomp
    f:
    cd fdos\appinfo
    copy *.* c:\freedos\appinfo
    cd ..\links
    copy *.* c:\freedos\links
    cd ..\devel\gfacomp
    xcopy *.* c:\devel\gfacomp /E /I /H /Q

The screenshot shows the content of the GFA-BASIC installation directory.

GFA-BASIC on FreeDOS: Content of the installation directory

The GFA-BASIC development environment includes an editor that allows to start the GFA-BASIC interpreter to run the source code in the editor window. It can be launched using gfa.bat (that we copied to c:\freedos\links). This will however result in the error message Bad command or filename popup (then, after a key has been pressed, the editor will start up). The program popup.exe is a tool that may be used to install any program as TSR, and is intended here to make the GFA-BASIC help program available at any moment. However, popup.exe is not included with the installation files (and I did not find it on the Internet). Not really important, it concerns the help system, so has nothing to do with the correctly working of the development environment.

I created a custom batch file, called #gfa.bat and located in a directory that is in my executables path. The script adds the GFA-BASIC directory to the PATH (note that the environment variable %path0% is specific to my system and set equal to %path% in fdauto.bat), switches to my development directory on drive D: and then either starts the editor with the empty file noname.gfa, or loads the GFA file specified as command line parameter (the extension .gfa is added by the script). Here is the code (%devel% is a custom environment variable of my system, that you can comment out or remove):
    @echo off
    set path=%path0%;c:\devel\gfacomp
    set devel=gfa
    d:
    cd \devel\gfabasic
    if "%1"=="" goto End
    set _prog=%1.gfa
    if exist %_prog% goto End
    echo File %_prog% does not exist
    echo Loading default file noname.gfa
    pause
    :End
    c:\devel\gfacomp\gfabas37.exe %_prog%
    set _prog=

The screenshot below shows the editor with the demo program 1dra.gfa (loaded before) and the "Load Program" dialog box (menu command File > Load) ready to load the program mat3det.gfa.

GFA-BASIC on FreeDOS: GFA-BASIC editor - Loading a program

The installation files include lots of program samples, mostly small demos to show how to implement a given feature. The screenshots below show examples of drawings mirroring (screenshot on the left) and text stretching (screenshot on the right). Note that these programs run in a GUI window with menu bar, as well as close, minimize and maximize functionality.

GFA-BASIC on FreeDOS: Demo programs - Example of drawings mirroring
GFA-BASIC on FreeDOS: Demo programs - Example of text stretching

GFA-BASIC includes lots of graphics commands. And graphics are really fast! The screenshot on the left shows a demo concerning circle drawing, the screenshot on the right shows an implementation of the Mandelbrot Set.

GFA-BASIC on FreeDOS: Demo programs - Example of circle drawing
GFA-BASIC on FreeDOS: Demo programs - Mandelbrot set

One of the nice features of GFA-BASIC are the alerts, kind of dialog boxes, that may be implemented either as simple text boxes, or as GUI-like components. Here is the code of a little program of my own. It displays today's date and time and the day of the week (using an alert):
    SCREEN 18
    DIM Days$(6)
    FOR I% = 0 TO 6
        READ Days$(I%)
    NEXT I%
    DATA Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
    DAT$ = DATE$
    TIM$ = TIME$
    MODE 0
    MM% = VAL(LEFT$(DAT$, 2))
    DD% = VAL(MID$(DAT$, 3, 2))
    YY% = VAL(RIGHT$(DAT$, 2))
    DW% = @DayOfWeek(YY%, MM%, DD%)
    A$  = "Day = " + Days$(DW%) + "|" + "Date = " + DAT$ + "|" + "Time = " + TIM$
    ALERT 0, A$, 1, "OK", A&
    SCREEN 3
    END
    FUNCTION DayOfWeek(Y%, M%, D%)
        DIM MKeys%(11)
        LOCAL Dow%, I%
        FOR I% = 0 TO 11
            READ MKeys%(I%)
        NEXT I%
        DATA 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4
        IF M% < 3
            DEC(Y%)
        ENDIF
        Dow% = MOD((Y% + DIV(Y%, 4) - DIV(Y%, 100) + DIV(Y%, 400) + MKeys%(M% - 1) + D%), 7)
        RETURN Dow%
    ENDFUNC

And here is the program output.

GFA-BASIC on FreeDOS: Simple date/time program

Another really nice feature is the file selection dialog box, included in the GFA-BASIC language and ready to use (this looks really desktop-like, just as on a GUI operating system, doesn't it?). The demo program load_pcx.gfa displays such a box to select a PCX file (screenshot on the left), and then displays the PCX image (oh yes yet another special feature of GFA-BASIC!) (screenshot on the right).

GFA-BASIC on FreeDOS: Demo programs - Displaying a PCX image file [1]
GFA-BASIC on FreeDOS: Demo programs - Displaying a PCX image file [2]

Notes concerning the editor commands:
Load and Save load resp. save a GFA file. These files are saved in a BASIC specific format and may not be viewed in a text editor. To save the editor source code in ASCII format (plein text file), use the commands Write (to create a new file), or Merge (to append to an existing file). The command Run starts the GFA-BASIC interpreter that executes the code in the editor window.

Creating GFA-BASIC executables.

The GFA-BASIC installation files include a compiler named gfa2exe.exe. It takes a GFA file as input and creates a DOS executable (EXE file). The screenshot below shows the compilation of load_pcx.gfa.

GFA-BASIC on FreeDOS: Compiling a GFA file

Important to know that the executables created by gfa2exe need one of the overlay files included with the GFA-BASIC installation files. The provided files are the following:

If GFA-BASIC doesn't find the overlay file it searches for, it will look for gfabasic.ovl. So, one possibility is to include all 4 files with the executable; a more reasonable possibility is to just use gfaba573.ovl (best renaming it to gfabasic.ovl). In fact, all actual hardware, as well as virtualization software, has a processor that is better than an 80386, and they also have a math co-processor.

Note: There is a bug in GFA-BASIC, the overlay file searched for being gfaba5ic.ovl (instead of gfabasic.ovl). Thus, use this name when you rename your overlay file!

Running GFA-BASIC programs on MS-DOS.

The executables, created by gfa2exe on FreeDOS normally run without problems on MS-DOS 6.22, provided that you place the overlay file together with the executable (placing it in a directory that is in the PATH should also work). However, programs that access some file may not work correctly on MS-DOS. This is due to the way how files in the current directory are specified. In the source of load_pcx, for example, the syntax ".\*.pcx" is used to designate all PCX files in the current directory. This seems not to be understood by MS-DOS (?). Change the source and simply use "*.pcx" instead.


If you find this text helpful, please, support me and this website by signing my guestbook.