- Online Community Forums » Programming Questions » CGA, EGA and VGA Coding

This thread is locked; no one can reply to it. rss feed Print
CGA, EGA and VGA Coding
Kris Asick
Member #1,424
July 2001

Wow, it's been awhile since I've been here... ::)

So anyways, in the midst of making a new webshow entitled Ancient DOS Games, (link provided for anyone interested just by that name), I started thinking more about where to take my game making. Originally, I wanted to delve into XNA, but I had a curious thought...

DOSBox is cross-platform and programming for DOS is SUBSTANTIALLY easier than for Windows. Always has been. With my new webshow going and having extremely little time to make games anymore, and the fact that much of my future audience to my website will have at least a passing interest in DOS, it sort of makes sense to make DOS games from now on.

The real trick is that Allegro doesn't natively go too far back with its graphical support. IE: No CGA or EGA support, nor PC Speaker sound. (And the VGA support it has doesn't include the 16-colour VGA modes.)

So I'm a bit curious what options are available for Allegro that can utilize these legacy components, or if it would just be better to code directly for them using direct memory and port I/O, and if anyone has any links on where to learn more about coding for them. (I know how to do direct VGA but that's about it.)

Thanks ahead of time for anyone who can help me out here! ;)

--- Kris Asick (Gemini)

Martin Kalbfuß
Member #9,131
October 2007

You could write your own lib, wrapping up the direct memory access. Graphical programming under DOS is not that hard, and good documented. But you have to access the soundcard, too. This is some extra work, to do. But If you write it for DosBox you only have to support the SB.
It's fun and you can customize it to your needs. But it is more difficult then writing programs with a lib like Allegro.

The memory area for CGA/HGC video memory is B000:0000 and for EGA/VGA A000:0000.

Example CGA 320x200

B800:0000 and B800:2000. Are the memory areas to acces the screen. B800:0000 for even(0,2,4,...) lines and B800:2000 for odd(1,3,5...) lines.
One line has 80 bytes. 4 pixels in one byte.
There are only four colors. so 2 bit are enough to represent a pixel.

Address := 2000H * (Y MOD 2) + 80 * INT(Y/2) + INT(X/4);
BitNum := 6 - 2 * (X MOD 4);

Don't forget to set the correct video mode, before accessing the memory.

Have a look at the FreePASCAL compiler, too. Maybe this is a good choice for DOS programming. -- my server side lisp interpreter -- Modula-2 alias Pascal++

Arthur Kalliokoski
Second in Command
February 2005

DOSBox is cross-platform and programming for DOS is SUBSTANTIALLY easier than for Windows.

I know how to do direct VGA but that's about it.

You can always restrict the number of colors to 4 or 16 colors. 16 colors (4 bit color) was always a pain because you had to write to hardware ports to enable/disable the four planes available. CGA programming involved setting particular bits (set/clear 1 bit for 640 x 200, or set/clear adjacent pairs of bits for 4 color). The PC speaker could be programmed by setting the timer chip to "play" a particular frequency, or you could send "push speaker/release speaker" via port 61h to adjust frequency on the fly. I don't see why you couldn't write values to the sound buffer the same as allegro4.4.x/examples/exstream.c does (although due to superior quality speakers it won't sound quite the same).

The only downside I see for Allegro for direct memory access to a video buffer is the scanlines for an Allegro bitmap may be scattered about, so you have to use the array of line pointers. However, modern computers are so much faster than in the heyday of DOS that the drawing will still be faster.

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

Go to: