DOS Game Programming: The “old-school” way

By | 29 mayo, 2019
Old-DOS-Games

DOS games are fun, but it could be even more fun to be able to create your own game for DOS and run it alongside other big titles like Doom, Commander Keen, Duke Nukem and many more…

Programming a game for DOS would (almost) feel like developing for a retro console like the PS1 or the SNES, which can be either “cool” or tedious, depending on how you look at it. But fortunately, nowadays there are modern tools and libraries that makes programming for DOS much easier. DOS also supports a wide variety of screen resolutions and color depths, but many games of the 90s used what is called “Mode 13h” (320×200, 256-colors) because of how easy it was to display graphics on the screen with this mode.

One advantage of making DOS games right now, is being able to test your game on any platform that has a DOS emulator (much like emulators for other retro consoles), so your game will be playable on many systems and also on vintage hardware.

That said, you can use free tools like DJGPP with the Allegro library to make simple DOS VGA games, or if you want to go a bit further, Allegro also supports VESA graphic modes, ranging from 640×480 up to 1280×1024 with 8, 16 or 32-bit color depths! DJGPP only targets 32-bit processors (386, 486 and later) on DOS, so no 286 or 8088/8086 support is available.

Another BIG advantage of DJGPP is that it’s still being updated to this day with the latest release of the GCC compiler, which supports C++11 and later features, so you won’t be stuck with plain old C89 or C++98 for development.

Get the files

You can download a full pre-compiled DJGPP + Allegro package from here:

http://www.mediafire.com/file/n1cg3gnbm8r68r1/GDK4DOS_V1.1.7z/file

This includes the standard set of tools of DJGPP with a newly compiled version of Allegro 4.2.3.1 meant to be used with GCC 5.5. The Allegro library included in this pack was patched to fix an issue with Sound Blaster Pro cards (thanks to the people @ the Allegro.cc forums!), but it works nicely with Sound Blaster 16 too. It also comes with the standard utilities like make, gcc, gpp (C++ compiler) and RHIDE for DOS.

Installation instructions

First, place all the .zip files in a directory like C:\DJGPP, and run unzip32.exe for each file to decompress it.

Next, you have to edit the AUTOEXEC.BAT file, which is normally located in the root of the C: drive, and add these lines:

set PATH=%PATH%;C:\djgpp\bin
set DJGPP=C:\djgpp\djgpp.env

Now restart the machine and open a DOS prompt. Type “rhide” and it should bring up an IDE similar to “Turbo C++” from Borland that you can use to start developing in C/C++ for DOS:

rhide

Note: In order to use C++ libraries like <iostream> or <vector>, you should use a DOS environment with Long-Filename Support (LFS) like Windows 95, 98, Me or DOSEMU (Linux); DOSBox does not have this feature. However, if you are programming in pure C, this won’t be a problem and you can use C libraries normally under real DOS or DOSBox.

Sample code to set up a 320×200 mode:

// test.cpp

#include <allegro.h>

int main()
{
   // Init the Allegro library
   allegro_init();

   // Init the keyboard
   install_keyboard();

   // Set the color depth and resolution
   set_color_depth(8);
   set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0);

   // Print the current GFX driver being used at the center of the screen.
   textprintf_centre_ex(screen, font, 160, 100, makecol(255, 255, 255)
   , -1, "%s", gfx_driver->name);

   // Wait for a key press...
   readkey();

   return 0;
}
END_OF_MAIN()

This program outputs the name of the current graphics driver being used to the center of the screen. You can then press any key to exit.

Game distribution

One thing to note before distributing games and applications made with DJGPP, is that they require a special DPMI server known as “CWSDPMI.EXE” before running. If you attempt to run a DJGPP application without this utility, it will print a message like this:

Load error: no DPMI - Get csdpmi*b.zip

To fix this, you must copy the file CWSDPMI.EXE (located in C:\DJGPP\BIN) to the same location as your game or application, and it will run normally on any 486+ machine.

I will be writing another article about how to program DOS games in a “modern” way, using modern tools like CodeBlocks and a compiler toolchain that targets 32-bit DOS from within Windows and Linux.

Other useful links

Allegro homepage: https://liballeg.org/

Allegro 4.x reference manual: https://liballeg.org/stabledocs/en/allegro.html

DJGPP website: http://www.delorie.com/djgpp/

DOS Haven (a site that compiles modern DOS games): http://www.doshaven.eu/

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *