So far, I have gotten by with using the BIOS draw-pixel routine here: http://stanislavs.org/helppc/int_10-c.html

This works of course, but I can't imagine that commercial games used this BIOS call as its pretty slow. Considering too that 320x200 = 64K, drawing a full screen requires speed.

Writing to graphics memory is fairly straight forward for CGA, but EGA uses planar addressing and is a bit tricky to find documentation on. I'm trying to "write games" not reinvent the wheel here. Ideally, I'm looking for a general purpose pixel drawing routine that I can learn from and possibly just use. Any help is very much appreciated!

  • 2
    Any pixel drawing routine will be slow. It's not intuitive, but drawing single pixels is not the fundamental operation that all other operations are based that you might think it is. A more important operation, especially for games would be bit blit or bitmap copy.
    – user722
    Jan 18, 2019 at 2:13
  • In the DOS days there were specific programming books for this. Try to get hold of them. A quick Google for book "programming ega graphics" turns up this PDF, book "programming vga graphics" gives many more hits, and John's answer suggests other search terms. Too bad I threw my books away years ago ;-)
    – user8725
    Jan 18, 2019 at 12:25
  • If you're trying to write games, you really want the "PC Game Programmer's Encyclopedia", an excellent collection of text files on how to do everything in the DOS era.
    – pjc50
    Jan 18, 2019 at 15:02
  • If you do choose to do some single pixel after all, there's some code for 640x480 16 color VGA mode, which operates the same way, in one of my old demo projects: github.com/BrianKnoblauch/Circ-VGA/blob/master/CIRC.ASM Jan 18, 2019 at 18:46
  • @BrianKnoblauch: IIRC, the main write mode I used on the VGA was one which didn't exist on the EGA. On the EGA, it was necessary to set an 8-bit mask register for each pixel to be written, but on the VGA the 8-bit mask could be taken from the value written. I think your code looks like it might be using that technique.
    – supercat
    May 23 at 17:15

2 Answers 2


Writing single pixels is a non-starter if you want any performance, even if you don't go through the overhead of a BIOS call for each pixel.

Graphics libraries in and around the EGA era were based on drawing entire lines at a time, curved lines that were segments of axis-parallel elipses, and things like filled rectangles and circles.

The interior of the big flat fills could be sped up by manipulating the write mask register: by setting more than one bit, more than one of the bit planes would accept writes at the same time, so to write a single word of FFFF or 0000 you could set or clear the bits of 16 pixels in any combination of planes you wanted. You'd first write all the planes you want to set to 0 all at once, then all the planes you want to set to 1 (or, of course, vice versa). At the boundaries of your shape, where you need to partially keep the screen content within a word or byte, you'd need to switch to a slower plane-by-plane implementation.

If you wanted more intricate graphics than you could make with plain lines or fills, you would blit (in software) bitmaps to the screen from a pre-rendered in-memory representation that was already split into planes and bytes the right way. If you wanted smooth horizontal movement, you would have 8 rendered versions of each bitmap depending on the horizontal position of the image relative to the byte boundaries.

Draw single pixels only as an absolute last resort.

  • 1
    This makes a lot of sense. I have developed my own RLE routine to import bitmaps drawn in a paint tool and it works. i was hoping to base my maps on 16x16 tiles and draw them as you move. The benefit i guess i have with RLE is i can focus on long runs as horizontal lines. i have not read much on blitting but this points me in the right direction! Jan 18, 2019 at 3:57

Source for the GEM video drivers is available - the files EGAMMRE1.A86 and EGAMMRE2.A86 contain functions to draw a filled rectangle (RECTFIL), an arbitrary line (ABLINE) and a 16x16 mouse pointer (MDRAW) on EGA/VGA hardware.

If you can find a copy of Richard Wilton's Programmer's Guide To PC Video Systems, that contains a thorough explanation of how the EGA works and provides a number of drawing functions for it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.