Skip to content

Latest commit

 

History

History
345 lines (267 loc) · 14.3 KB

README.md

File metadata and controls

345 lines (267 loc) · 14.3 KB

What is Open Watcom

Watcom C/C++ was an integrated development environment for C, C++, and Fortran programming languages that was a commercial product until it was discontinued, it has since been released under the Sybase Open Watcom Public License as Open Watcom. Open Watcoms niche over other typical compiler choices is it's build targets for legacy hardware and software. Open Watcom builds native code for 16-bit x86 processors and can compile code from a modern Linux/Windows host for ancient versions of DOS, OS/2 & Windows.

Note: Building Newth with Watcom is considered experimental due to the Watt32 library requirement

Watcom compiler flags

Open Watcoms compiler flags (wcc & wcc386) are quite different compared to a typical modern Clang, or GCC. Here are some of the more common ones:

-bt=      : Set build target...
    com   : ... 16-bit DOS COM file
    dos   : ... 16-bit DOS EXE file
    dos4g : ... 32-bit DOS EXE file
-d        : Debug level/define variable...
  0       : ... No debugging information (release build)
  1       : ... Some debugging information (debug build)
  2       : ... Full debugging information (developer build)
  FOO=bar : ... Set define 'FOO' to value 'bar'
-m        : Memory model...
  f       : ... flat  (32-bit only)
  s       : ... small (16-bit only)
  l       : ... large (16-bit only)
-0        : Optimize for 8086
-3        : Optimize for 386
-o        : Optimize...
  r       : ... instructions to make the most effective use of the CPU pipeline
  s       : ... for space over performance
-q        : Be quiet!
-s        : Disable stack overflow checks
-zc       : Place const data into code segment

Setup Open Watcom

Requirements

To build Newth with Watcom you will need the following:

Tip: If hardware isn't available it's possible to proceed with a emulator such as Dosbox-X

Choose processor architecture

Open Watcom can build DOS executables for both 16-bit real mode and 32-bit protected mode. It is important to decide what version to build (if not both) before proceeding. The 16-bit version can run on 32-bit processors and this might be desired for portability but typically, the 32-bit version should be used whenever a processor can run it as it will give the program more memory to use and take advantage of the ISA.

Processor compatibility matrix

Compatibility 8086 8088 80186 80286 80386 80486 i586 i686 x86_64
Real Mode Yes Native Yes Yes Yes Yes Yes Yes Yes
DOS4GW No No No No Native Yes Yes Yes Yes

Note: Open Watcom is a DOS4GW binary

Build time

Depending on the hardware being used to build Newth long periods may pass without any output printed to the screen. Expected build times are listed below:

Market Name ISA Clock Build time (up to)
Intel i386 80386 25Mhz ~14 minutes
Intel i486 80486 33Mhz ~6 minutes
Intel i486 DX2 80486 66Mhz ~3 minutes
Intel Pentium i586 60Mhz ~3 minutes
Intel Pentium MMX i586+MMX 133Mhz ~1 minute
AMD K6 K6 133Mhz ~50 seconds
AMD Athlon K7 600Mhz ~30 seconds

Installing Open Watcom

Installation instructions for Watcom differ depending on the build machines operating system. Some common operating systems are listed in the table below:

Operating System Installation Instructions
FreeDOS Load the bonus CD/ISO then run FDIMPLES, navigate to the Development group and check WATCOMC for installation
SvarDOS Run PKGNET pull ow or download manually then run PKG install ow.svp
Other Download and run the Open Watcom installation binary. If choosing a selective installation then make sure the 16-bit compiler with Large memory model and DOS Target operating system are selected for installation

Note: although Open Watcom can cross compile from Linux/Posix & NT systems these instruction will assume Newth is being built by a DOS-like system.

Installing SvarDOS package manager onto another DOS (optional)

If you already have a packet driver setup on your DOS system then it is relatively straight forward to setup the SvarDOS package manager. .SVP files are normal zip files so it should be possible to bootstrap the SvarDOS repository by extracting PKG.EXE and moving it and PKGNET.SVP onto the system. After which you can use PKG.EXE to install PKGNET.SVP to download PKG.SVP to install.

Make sure the network packet driver is loaded and both %DOSDIR% & %PATH% are set correctly then run the following:

PKG.EXE install PKGNET.SVP
PKGNET pull pkg
PKG.EXE install PKG.SVP

Optionally, remove the extracted PKG.EXE and .SVP files to free disk space:

DEL PKG.EXE
DEL *.SVP

Building Newth

Setup Watcom build environment

The Open Watcom build environment needs to be setup before it can be used. A script is included to do this. On a typical DOS installation of Open Watcom run the following to enable the build environment.

Note: the following steps will need to be repeated each time DOS boots. If this system is using Open Watcom frequently consider making the following commands part of your AUTOEXEC.BAT/FDAUTO.BAT script

%DOSDIR%\DEVEL\OW\OWSETENV.BAT

Tip: wcc, wlink & wmake should now be valid commands if this isn't the case check the directories in the script and modify them as necessary.

Configuring Watt32 library for linking with Newth

Newth on DOS depends on Watt32. The Watt32s folder should be extracted on symlinked into the directory containing makefile so that it looks like so.

Watcom\Dos16\makefile
Watcom\Dos16\Watt32s\inc
Watcom\Dos16\Watt32s\lib
Watcom\Dos4g\makefile
Watcom\Dos4g\Watt32s\inc
Watcom\Dos4g\Watt32s\lib

Newth depends on BSD-like networking API and compiling for DOS is no exception. For Newth to link to Watt32 correctly USE_BSD_API must be defined when building Watt32 library.

To do this Watt32s\src\config.h has to be manually modified like so:

 #undef USE_DEBUG
 #undef USE_MULTICAST
 #undef USE_BIND
-#undef USE_BSD_API
+#define USE_BSD_API
 #undef USE_BSD_FATAL
-#undef USE_BOOTP
-#undef USE_DHCP
+#define USE_BOOTP
+#define USE_DHCP
 #undef USE_RARP
 #undef USE_GEOIP
 #undef USE_IPV6
 #undef USE_LANGUAGE
 #undef USE_FRAGMENTS
 #undef USE_STATISTICS
 #undef USE_STACKWALKER
 #undef USE_FSEXT

Caution: some versions of watt-32 have a broken implementation of DHCP that can cause an infinite loop. On a real DOS this means it could very well lock up the computer with no option but to hard reset. If in doubt leave USE_DHCP undefined. Most DHCP servers are backwards compatible with BOOTP.

Build Newth

Build for 16-bit (Real Mode)

From the Dos16 directory run wmake to build the project. Two self contained 16-bit binary called DL.EXE and TH.EXE will be made and can be run from any path (including a floppy diskette) on any DOS 2.0 or later computer.

Build for 32-bit (DOS4GW)

From the Dos4g directory run wmake to build the project. Two 32-bit binary called DL.EXE and TH.EXE will be made and can be run from any path (including a floppy diskette) on any DOS 4.0 or later computer with a 80386 compatible CPU.

DOS4GW.EXE will need to either exist in a %PATH% directory or the same directory as the binaries for the programs to function. To put a copy of DOS4GW.EXE in the same directory as DL.EXE and TH.EXE run COPY %WATCOM%\BINW\DOS4GW.EXE ..

After building

Compress binary (optional)

On DOS machines disk space is usually at a premium. Even though the release builds are stripped of all debugging symbols it is possible to make the binary take substantially less disk space with UPX compression so that it fits comfortably on a smaller diskette standard.

Build UPX Command Fits on
Real Mode UPX DL.EXE TH.EXE --best --8086 5¼-inch DD (360k)
DOS4GW UPX DL.EXE --best 5¼-inch QD (720k)
DOS4GW UPX DL.EXE TH.EXE --best 5¼-inch HD (1200k)

Create diskette image (optional)

On a real DOS machines it makes sense to directly copy the new binaries onto a newly formatted diskette. Conversely when cross compiling or distributing over the Internet it may make more sense to distribute as a floppy disk image so that users can make their own disks locally. This can be achieve with GNU Mtools.

Note: At the time of writing there's no DOS port of GNU Mtools. The newly created binaries will need to be transferred to a more modern Linux or Windows machine to use Mtools on them.

With compression the binaries will fit much better into diskette image then they otherwise would, in some cases becoming compatible with a lower standard of diskette. While there might be a lot of free space after copying the files to the image users may want to put other files on the disk (such as WatTCP configuration and/or a network packet driver) and a real diskette may contain bad sectors.

With Mtools installed, create a diskette image with mformat then copy the binaries to the new image with mcopy. Below are some example configurations.

Tip: If you can only spare one diskette which can't fit both programs on it. You could write DL.EXE and a packet driver to the disk then use these to download TH.EXE over the network.

On Compressed Binaries

Real Mode 5¼-inch DD Diskette
mformat -C -i newth360.ima -v "NEWTH" -f 360
mcopy -i newth360.ima DL.EXE TH.EXE ::
DOS4GW 5¼-inch QD Diskettes
mformat -C -i dl4g_720.ima -v "DL4GW" -f 720
mcopy -i dl4g_720.ima DL.EXE DOS4GW.EXE ::
mformat -C -i th4g_720.ima -v "TH4GW" -f 720
mcopy -i th4g_720.ima TH.EXE DOS4GW.EXE ::
Multi-arch 3½-inch HD Diskettes
mformat -C -i dlma_1.4.ima -v "DLMULTI" -f 1440
mmd -i dlma_1.4.ima ::\16 \4G
mcopy -i dlma_1.4.ima Dos16/DL.EXE ::\16
mcopy -i dlma_1.4.ima Dos4g/DL.EXE Dos4g/DOS4GW.EXE ::\4G
mformat -C -i thma_1.4.ima -v "THMULTI" -f 1440
mmd -i thma_1.4.ima ::\16 \4G
mcopy -i thma_1.4.ima Dos16/TH.EXE ::\16
mcopy -i thma_1.4.ima Dos4g/TH.EXE Dos4g/DOS4GW.EXE ::\4G
Multi-arch 3½-inch ED Diskette
mformat -C -i newth2.8.ima -v "NEWTH MA" -f 2880
mmd -i newth2.8.ima ::\16 \4G
mcopy -i newth2.8.ima Dos16/DL.EXE Dos16/TH.EXE ::\16
mcopy -i newth2.8.ima Dos4g/DL.EXE Dos4g/TH.EXE Dos4g/DOS4GW.EXE ::\4G

On Uncompressed Binaries

Real Mode 5¼-inch QD Diskettes
mformat -C -i dl_720.ima -v "DL" -f 720
mcopy -i dl_720.ima DL.EXE ::
mformat -C -i th_720.ima -v "TH" -f 720
mcopy -i th_720.ima TH.EXE ::
DOS4GW 3½-inch HD Diskettes
mformat -C -i dl4g_1.4.ima -v "DL4GW" -f 1440
mcopy -i dl4g_1.4.ima DL.EXE DOS4GW.EXE ::
mformat -C -i th4g_1.4.ima -v "TH4GW" -f 1440
mcopy -i th4g_1.4.ima TH.EXE DOS4GW.EXE ::
DOS4GW 3½-inch ED Diskette
mformat -C -i new4g2.8.ima -v "NEWTH 4G" -f 2880
mcopy -i new4g2.8.ima DL.EXE TH.EXE DOS4GW.EXE ::