Back to home page

DOS ain't dead

Forum index page

Log in | Register

Back to index page
Thread view  Board view
Laaca

Homepage

Czech republic,
27.07.2026, 22:13
 

Freepascal, Win98 and realmode DOS (Developers)

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!

Rugxulo

Homepage

Usono,
28.07.2026, 23:38

@ Laaca
 

Freepascal, Win98 and realmode DOS

> 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.

You say that, but with the integrated assembler and linker, it should be easier to build and work with Go32v2 host. Yet nobody needed it badly enough (yet), so I guess it's not properly supported. Last I heard (maybe only rumor), WinXP in VM was used for Go32v2 builds.

> 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.

WLINK, WLIB, and NASM ... if I recall correctly. No longer needed.

> 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.

You obviously don't need base binaries or libraries at all, they are incompatible.

> Interestingly, this add-on is about three times larger than the base package itself.

The .PPU files for the generics units take A TON of space (multiply that times six for the various memory models).

> I was unable to use older versions because I could not get the OpenWatcom
> linker (used by those releases) working under HX.

But OpenWatcom (including WLINK) does run under HX, last I heard. Maybe set HDPMI=32

I say that, but I do recall running into LFN troubles and super-long Win32 cmdlines. That could've been solved by JWlink / JWlib and a response file, but nobody was interested. That may have only affected smartlinking (on by default?). Try -CX- . (It was also much slower to compile due to that.)

> Newer version 3.2.2 is not usable either, because it refuses to start under HX,
> complaining about the missing OpenThread function.

Which version of HX? Can't you ignore unsupported imports? Set DPMILDR=128 or 136 .

> This gives you a Pascal compiler for real-mode DOS that surpasses Turbo
> Pascal in many respects.

The code is a bit larger, the memory allocations tend to take a bit more space, but yes there are improvements. {$mode tp} is very good (albeit not default), but there are other modes. Default {$mode fps} gives you structured return types and function overloading. {$H+} gives you heap-allocated strings longer than 255. {$mode $delphi} has heap-based classes. There's also added functions like readstr() and writestr() which are convenient. Oh, and an int64 type. And LFN support. More useful units included. Better {$mode iso} classic ISO 7185 support (lookahead file^ can be helpful).

marcov

29.07.2026, 09:47

@ Rugxulo
 

Freepascal, Win98 and realmode DOS

> You say that, but with the integrated assembler and linker, it should be
> easier to build and work with Go32v2 host. Yet nobody needed it badly
> enough (yet), so I guess it's not properly supported. Last I heard (maybe
> only rumor), WinXP in VM was used for Go32v2 builds.

Afaik that is only because the FPC repo needs LFN. That should be less of a problem if you use it to program yourself

Laaca

Homepage

Czech republic,
29.07.2026, 16:19

@ marcov
 

Freepascal, Win98 and realmode DOS

> > You say that, but with the integrated assembler and linker, it should be
> > easier to build and work with Go32v2 host. Yet nobody needed it badly
> > enough (yet), so I guess it's not properly supported. Last I heard
> (maybe
> > only rumor), WinXP in VM was used for Go32v2 builds.
>
> Afaik that is only because the FPC repo needs LFN. That should be less of a
> problem if you use it to program yourself


Of course, crosscompilation from GO32V2 to MSDOS (realmode) would be beautiful, even with the necesserity of the LFN support.


But the crosscompilation from Win32 to MSDOS in situation when is it possible through HX is acceptable although a little bit "hackish".


Unfortunately, i was not able to do a next step further.
I wish to use the IDE from GO32V2 for writting, syntax highlighting, maybe even for some test compilation. Then I wanted to use the IDE ability "call the external tool". I mapped to SHIFT-F9 the call to PPCROSS8086 $EDNAME.
Unfortunately it does no work for me. If I use normaly CWSDPMI it just silently does nothing - no crash, no hang, but it just does nothing. If I preload HDPMI32 I get some error message - I do not remember the exact message now however it also do not work. Maybe I could experiment with the envoronment variable HDPMI, maybe it has some solution but I have not found it so far.

---
DOS-u-akbar!

Back to index page
Thread view  Board view
23493 Postings in 2218 Threads, 408 registered users (0 online)
DOS ain't dead | Admin contact
RSS Feed
powered by my little forum