Hi! I am in process of updating my czech webpages about pascal and I made some test of crosscompiler from Win32 to realmode DOS.
It can be interresting not only for czech speaking people but also for others. So here is transplation to english:
============================================================
In 2015, with the release of Free Pascal 3.0.0, support for compiling real-mode DOS programs appeared for the first time. It should be noted that this has always been, and almost certainly will remain, a cross-compilation target from another operating system.
Initially, the support was rather incomplete and affected by a large number of bugs, but starting with version 3.0.4 it became a genuinely interesting option for writing Pascal programs for real-mode DOS.
Up to that version, the compiler depended on external utilities borrowed from OpenWatcom. Since version 3.2.0, however, no external utilities are required anymore.
Last week I tested the Win32 cross-compilers targeting the MSDOS platform (that is, real-mode DOS). First, you need to install the base package, followed by the add-on that enables DOS compilation. Interestingly, this add-on is about three times larger than the base package itself.
The good news is that the Win32 version of FPC works perfectly well even under Windows 98. The only issue is the installer, which reports that Windows 98 is not a supported operating system. Fortunately, this can be worked around by installing KernelEX. After that, right-click the installer, open its Properties dialog, enable Windows XP compatibility mode, and the installer will run normally.
The DOS real-mode add-on can be installed the same way.
You can now compile a program from the command line using either
fpc Hello.pas
or
ppc386 Hello.pas
Both commands produce Hello.exe, which is a standard Win32 console application. It can be executed under Windows 9x as well as under plain DOS using the HX DOS Extender.
If you want a 16-bit DOS application instead, simply run
ppcross8086 Hello.pas
This produces Hello.exe for real-mode DOS. Optional command-line switches allow you to choose the desired memory model. This is well documented in the official documentation.
Nothing prevents you from routinely cross-compiling DOS applications from Windows 98, and in fact this is by far the easiest approach.
But what if you want to compile directly from plain DOS?
This is possible as well, although you obviously need the HX DOS Extender installed. You will also need an LFN driver. At the moment, the only version suitable for this setup is Free Pascal 3.2.0.
I was unable to use older versions because I could not get the OpenWatcom linker (used by those releases) working under HX. Newer version 3.2.2 is not usable either, because it refuses to start under HX, complaining about the missing OpenThread function.
When compiling Win32 applications from plain DOS, you must use
ppc386 Hello.pas
For some reason,
fpc Hello.pas
does not work in this environment.
Finally, just as under Windows 98, running
ppcross8086 Hello.pas
from DOS produces a real-mode DOS executable.
To make it easier to obtain the correct version, and to avoid the installation issues under Windows 98 (or plain DOS), I have uploaded a complete package containing Free Pascal 3.2.0 for Win32 together with the DOS16 add-on:
FPC320w
Simply unpack the ZIP archive. The only thing you must remember is to edit FPC.CFG manually and adjust the installation paths to match your directory layout. My installation resides in
D:\TP\FPC320w
but yours will most likely be different.
This gives you a Pascal compiler for real-mode DOS that surpasses Turbo Pascal in many respects. One of my favorite improvements is the integrated assembler's ability to access the processor's 32-bit registers directly. Instead of the old Turbo Pascal trick
db 66h
mov ax,3
you can simply write
mov eax,3
which is considerably cleaner and much easier to read. --- DOS-u-akbar! |