Reputation: 917
I was given the source code to modify an MS-DOS program built back in 1992. I have the EXE file and it runs fine, but I need to modify the source code. The source code needs the below headers to compile.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <dos.h>
#include <dir.h>
#include <alloc.h>
#include <ctype.h>
#include <string.h>
#include <mem.h>
#include <values.h>
Does anyone know what was used and are there any modern compilers that can handle this? I tried with Visual Studio 2010 and GCC "out of the box", but it fails because some headers are missing (dir.h, alloc.h, mem.h, values.h)
Upvotes: 6
Views: 1227
Reputation: 1240
I wasn't able to find a compiler to compile C for MS-DOS directly from Windows 10 as a host, but only from an MS-DOS emulator as a host (which is DOSBox) and the compiler that worked for me was Borland Turbo C++ 3.0. Here are the steps:
download DOSBox
install it
run it you will get a command prompt like Z:\>
now back to Windows 10 for preparing a directory dedicated to DOSBox where we will work, for ex create one in your C:\
drive and name it DOS
, you can choose another path and name if you want
back to DOSBox, in the prompt type:
Z:\>MOUNT C C:\DOS
Z:\>C:
the first command MOUNT
will mount the C:\DOS
directory (of your system) for DOSBox, so referencing C:\SOMETHING
from inside DOSBox is like referencing a file C:\DOS\SOMETHING
from your system. The second command C:
will change your prompt to become C:\>
like you are pointing into your new C drive (which in turn points to C:\DOS
of your system) so typing DIR
directly will list files and directories composing it
now back to Windows and download Borland Turbo C++ 3.0 zip
unzip it inside C:\DOS
so you will have C:\DOS\TCC\TURBOC.EXE
go back to DOSBox and while in C:\>
type:
C:\>CD TCC
C:\TCC>TURBOC.EXE
this will start the installer, you will get prompted with "some files already exist. Overwrite (y/n)?" so type "y" everytime
the installer will create a bunch of files inside TCC
that's the compiler files and most importantly we will use TCC.EXE
to compile C files
back to windows and put a C source file to compile (for ex TEST.C
) inside the DOS
folder
back to DOSBox and still inside TCC
folder, type:
C:\TCC>TCC.exe -I. -L. C:\TEST.C
command explanation: TCC.exe
is the compiler executable, -I.
is a compiler option to say to use the current directory .
as the Include directory, -L.
is a compiler option to say to use the current directory .
as the Libraries directory and C:\TEST.C
is the full path to the C source file to compile
TCC
folder, TEST.EXE
and TEST.OBJ
(this is the object file you can delete it if you want), TEST.EXE
is the compiled program you can test it by typing TEST.EXE
DOS\TCC
that's your executableUpvotes: 1
Reputation: 62086
There's Turbo C++ 1.01, not so modern, though, that appears to have all these header files as well. I still occasionally use it.
Upvotes: 4
Reputation: 9385
You could try the Open Watcom compiler, which is one of the few relatively up-to-date compilers that builds 16-bit DOS executables. Other than finding an old MS or Borland compiler (or whatever was originally used), that's probably the easiest route.
If you want to rebuild for a different platform instead of rebuilding for DOS again, you'll likely have to make a lot of changes to the program itself. That may be worthwhile, but may be a lot of work and have a lot of surprise headaches.
Upvotes: 5
Reputation: 101241
It might be more interesting to ask what what function declarations, type declarations, global variable declarations and macros it needs to have. The particular arrangement of those things into headers isn't very interesting as long as they are all there.
So comment out the offending #includes
and let the compiler complain about the bits it is missing. Then you know what you're looking for.
Upvotes: 10
Reputation: 23876
a) Remove all the header files b) Try a compile c) Look up which header file the undefined function/type is int d) Add the header file e) repeat
Upvotes: 1
Reputation: 41
You might try using DJGPP. According to the documentation, it may have the headers you need.
Upvotes: 4