Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using GCC on Mac OS to Compile C Program for MS-DOS (DOSBox)

Tags:

c++

c

macos

gcc

dos

I am running GCC 4.2.1 under Snow Leopard on Mac OS X. I want to use it to compile some old C/C++ DOS games I wrote 15 years ago so that I can run them under DosBox. To do this they obviously need to be compiled in DOS executable format, can anyone tell me how to do this using GCC please?

Thanks!

like image 969
Scruffers Avatar asked Dec 06 '10 20:12

Scruffers


3 Answers

DOSBox runs 16 bit x86 real-mode code under emulation. The regular GCC compiler on OSX 10.6 targets the OSX operating system and 32 bit x86 protected mode, so you cannot use that to build code to run in DOSBox.

What you may be able to do is run a DOS compiler in DOSBox itself. DJGPP is an MS-DOS port of GCC, however it generates 32bit protected mode code targetted at the DPMI subsystem. It is not clear to me that DOSBox supports DPMI, but I imagine that it does, and DJGPP itself is in the DOSBox compatability list, so one would imagine that the code it generates might run also if it does not do anything too out of the ordinary to the emulated hardware.

Borland Turbo C is also on the compatability list, and TC 2.01 is legitimately available for free. Other versions are offered for download elsewhare, but I doubt the legality of such distribution.

A more robust solution however is probably to install a genuine MS-DOS or DOS compatible OS in a Virtual Machine hosted on OSX using VirtualBox. If you do not have a copy of MS-DOS, you might try FreeDOS.

like image 95
Clifford Avatar answered Sep 19 '22 13:09

Clifford


Might be of some use: Question on compiling DOS programs in Debian

like image 40
lm2s Avatar answered Sep 21 '22 13:09

lm2s


Are your old DOS games written for 16-bit or for a 32-bit environment with a DOS extender?

If it's 16-bit code, GCC won't be of any use. You might want to look into OpenWatcom or Digital Mars, both of which claim 16-bit DOS support (though I have no idea how well they work for that). You may have to run the compiler in a Windows VM (certainly for Digital Mars, not sure about OpenWatcom).

If you're looking for 32-bit DOS Extender toolchain, both of the above also claim to work for that, but you might also get GCC to work for you (DJGPP might help - again, I don't know how well it works or if it'll cross compile from a Linux or Mac environment).

like image 35
Michael Burr Avatar answered Sep 21 '22 13:09

Michael Burr