Computing: Free Pascal Programming

Installing Free Pascal on FreeDOS.

The latest version of Free Pascal for DOS (or more exactly Free Pascal for go32v2) may be freely downloaded from the Free Pascal website. Go32 is a so-called DOS extender. Use of this extender with FPC allows DOS programs to access more memory than would normally be possible with real-mode. The actual Free Pascal version (March 2022) is FPC 3.2.2. The download file, called (75 MB) includes everything you need to build Free Pascal applications for DOS (go32v2, the compiler, a Turbo Pascal similar IDE, the debugger; it also contains the FPC documentation and all sources). A smaller file, called (33 MB) contains the complete Free Pascal development environment for DOS, too, but does not include the documentation and the sources. It's the full 3.2.2 package that I used, when writing this tutorial. The whole on FreeDOS version 1.3 RC5.
The ZIP archive contains the installation folders and files and you'll have to burn them onto CD. In a virtual environment (in my case VMware 16), it's simpler to create an ISO. I did this, using ISO Workshop, a free Windows desktop application specifically designed to facilitate ISO image management and conversion, as well as CD/DVD/Blu-ray burning and copying operations.
Some of the go32v2 features need long file name support, so you must load a LFN driver when doing the installation. The FreeDOS distribution includes the long file name TSR, that you can either load from FDCONFIG.SYS (installhigh or from FDAUTO.BAT, respectively the command line (lh If you don't do so, the Free Pascal installation program will pop up a message telling you that your operating system has no long file name support and it will not be possible to install the related go32v2 components.
To start the installation, navigate to your CD drive (and the folder with the Free Pascal files, if you created one on the CD) and launch the install program. In the General tab of the installation window, you can choose, the installation directory. The default is C:\PP; I changed it to C:\FPC322 (screenshot on the left). The other tabs allow to select the components to be installed. By default, they are all checked (that may result in an abortion of the setup process; see further down in the text). The screenshot on the right shows the tab, where you can select the DOS/go32v2 components.
Free Pascal on FreeDOS: Choosing the installation directory
Free Pascal on FreeDOS: Selecting the DOS/go32v2 components to be installed
Pushing the Continue button, makes the setup program extracting the files (screenshot on the left). No chance however: File copy ends with a disk error (screenshot on the right), unrecoverable and the problem remaining when retrying by relaunching the installation from the beginning.
Free Pascal on FreeDOS: File extraction from the installation archives
Free Pascal on FreeDOS: Unrecoverable disk error during installation
I have no idea, what the problem is, but there is a simple work-around: Do not install the sources (unchecking all items in the last three tabs of the installation window. The setup process ends with a message that C:\fpc322\bin\go32v2 has to be added to the path (you'll have to replace "fpc322" by whatever you have called the installation directory). The pop-up window also says that you can compile using fpc. In fact, fpc.exe is the Free Pascal command line compiler; the file, corresponding to the IDE is called fp.exe.
Free Pascal on FreeDOS: Successful installation
It's a good idea to start the IDE from a batch file. Advantages:
  • You can set the path to the Free Pascal binaries here (instead of FDAUTO.BAT).
  • You can load the LFN driver here (instead of FDCONFIG.SYS or FDAUTO.BAT).
  • You can navigate to your working directory (the directory, where you have your Pascal source files). Doing so, will directly open this directory, when you use the Open menu command in the IDE (and the object and executable files resulting from the build will also placed here).
Here the content of my batch file FP#.BAT (my working directory being on drive D:):
    @echo off
    set path=%path%;C:\fpc322\bin\go32v2
    cd \DEVEL\FPC
When starting the IDE, using the batch file, that sets the current directory to my working directory on D:, the IDE pops up a message, telling that it has never been started from this directory and asking how to proceed to create the new configuration file (that will be placed in the current directory).
Free Pascal on FreeDOS: Creating a configuration file in the current directory [1]
Free Pascal on FreeDOS: Creating a configuration file in the current directory [2]
The IDE is very similar to the one of Turbo Pascal. Menus are accessible with the mouse as well as with the keyboard. If you use the keyboard, push the ALT key together with the highlighted letter of the menu, you want to open (ex: ALT+F to open the File menu). Then, use the up and down arrays to navigate to the wanted item and press ENTER. A third possibility is to use the shortcuts; for example: F9 = Make, CTRL+F9 = Run. When asking the IDE to open a file, the corresponding dialog box showed the files, that I wanted to be shown, i.e. those in my Pascal working directory.
Free Pascal on FreeDOS: Opening a source file in the IDE
But, the build failed! I don't know if my choices (those on the screenshots before) were wrong or if this happens independently of what option, concerning the new configuration file, you choose. The fact is, that the paths to the different Free Pascal directories, such as the directories that contain the units, had not bee set and when trying to build a program, build aborted with a Can't find unit ... error message.
Free Pascal on FreeDOS: Unit directory not found error
I found the unit settings in the original fp.cfg file in the Free Pascal directory on C:. For all 3 build modes, I inserted (copied) the following to the new fp.cfg, created in my working directory.
    #IFDEF cpui8086
After having changed the fp.cfg file, the unit and other paths were displayed in the directories settings of the IDE.
Free Pascal on FreeDOS: Unit directories correctly set in the IDE
And the build of my program succeeded. The screenshots below show the build and the execution of my calendar program, developped for Command Prompt on my Windows 10 laptop.
Free Pascal on FreeDOS: Building a program in the IDE
Free Pascal on FreeDOS: Running a program from within the IDE
As on the other platforms, it is important to remove the debug information from the executable, when the program is running correctly. This will result in an important reduction of the executable's file size. As an example, the executable of my simple sound test program with 53,427 bytes, was reduced to 38,400 bytes, when the IDE was configured to remove the debug info. As in Lazarus, this settings change has to be done for each new source file. In the DOS IDE, you'll have to select the Options > Debugger > Strip all debug symbols from the executable checkbox. The size gain is about 30% and that's a lot! On the other hand, the FPC executable, even when stripped, is some 10 times bigger than the build of the same source with Turbo Pascal! But, these are not really values, that you can compare. Don't forget that the FPC output is 32 bits and that the executable, build to run in the go32v2 environment has lots more memory available than the 16 bits TP executable running in real mode.

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