0

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. – Ross Ridge Jan 18 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 ;-) – Jan Doggen Jan 18 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 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 – Brian Knoblauch Jan 18 at 18:46
6

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! – JohnnyStarr Jan 18 at 3:57
3

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 acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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