OpenWatcom, Gateway to Ancient World of x86

Access to the old art through the hand of the ancient.

OpenWatcom, Gateway to Ancient World of x86

In my articles in this retrocoding.net I use OpenWatcom compiler extensively. This is because this is the only compiler which allows me to program back into the ancient world. By ancient, I meant, the world of 8088, where the first PC was made. I explore the wisdom of the old world of PASCAL calling convention ubiquitous in 16-bit operating systems such as Windows 3.x.

Supported Host Systems

I use primarily OpenWatcom 1.9 which you can download from OpenWatcom.org website but it's largely unmaintained. The 2.x fork is hosted on Github which is actively maintained. It supports Windows and Linux as the host OS, and you can also use macOS from the 2.x fork but you'd need to build yourselves.

Because it uses Linux, you're able to run it under docker. I maintain the Watcom 1.9 Linux docker. Just pull and you can use it to compile program for old systems.

$ docker pull ykode/openwatcom:1.9-ubi

Supported Target Systems

OpenWatcom has very extensive target system both in processors as well as the operating systems. OpenWatcom is the only compiler that I know which is able to generate code for 8088 to Pentium Pro. Watcom also supports these target systems:

  • MS DOS Real Mode, both COM and EXE files.
  • MS DOS with DOS Extender.
  • 16-bit Windows like Windows 3.x.
  • 32-bit Windows like Windows 9x and Windows NT.
  • QNX
  • And many more. You can read from the tools.pdf file included in github or openwatcom.org website.

The OpenWatcom Linker is actually pretty configurable in which you can add more systems yourself if you want. You can write

Supported Programming Languages

OpenWatcom supports C and C++ as well as Fortran. It also provides additional calling convention for 16 and 32 bit application called WATCOM which will mangle function symbol name by adding additional underscore after symbol and will pass parameters by register rather than stack.

OpenWatcom also provides C Runtime libraries which is able to be run on 386, 486 both for Windows and DOS which are the processors and operating systems I'm interested in exploring.

id Softwore used Watcom as the compiler for DOOM. Watcom is used extensively in game programming on DOS. The original DOOM uses Watcom when it was still a commercial product. You can read the full story here.

Carmack chose the Watcom compiler because of DOS/4GW; DOOM would quite literally have been impossible without it. In the aftermath of DOOM‘s prominent use of it, Watcom’s would become the C compiler of choice for game development, right through the remaining years of the MS-DOS-gaming era.

Hello World, for 8088

Let's say you have original IBM PC model 5150 released 40 years ago in 1981 and you want to create a program running on that computer today. What you can do is just open up text editor and write some C code as usual.

#include <stdio.h>

int main(int argc, char **argv) {
  printf("Hello, World!");  
  return 0;
}

And of course a CMakeLists.txt file

project(hello)

set(SOURCES main.c)

add_executable(hello ${SOURCES})

And of course we create a build/dos88 directory to be able to build it for 8088-based MS-DOS computers like IBM XT.

> cd build/dos88

> cmake -DCMAKE_SYSTEM_NAME=DOS -DCMAKE_SYSTEM_PROCESSOR=I86 -DCMAKE_C_FLAGS="-0 -bt=dos -d0 -oaxt" -G "Watcom WMake" ../..

> wmake

You'll get a hello.exe file which you can copy to a floppy image and insert or mount if you're using emulator.

Hello, World! In 8088 IBM XT Computer running MS-DOS 1980

Conclusion

OpenWatcom is a compiler that enables us to build and run x86-based system on old platforms like MS-DOS. With CMake this task is even easier.