How did DOS games draw to the screen so fast?
The EGA and VGA video standards share some similarities with how the Amiga did graphics, but the similarities end when it comes to the 256 color graphics that defined 90s PC gaming. Topaz walks you through the basics of how those video modes worked, and what made them get so fast over time.
Thanks to Tyrel (@tyrel@mastodon.social)!
References
3d game source code
- Wolfenstein 3D (https://github.com/id-Software/wolf3d/blob/master/WOLFSRC/WL_AGENT.C#L244-L361)
- Wolfenstein 3D using latched VGA copies to draw things on screen
- Duke Nukem 3D (https://github.com/grepwood/duke3d/blob/master/source/buildengine/dos_drvr.c#L532)
- The DOS driver shovels data into the chunky mode as fast as it can. It didn’t use page flipping.
- Quake (https://github.com/id-Software/Quake/blob/master/QW/client/d_copy.s#L20-L148)
- Quake shoveling data into either the planar or chained VGA. Quake didn’t use any of the page-flipping approaches that unchaned modes allowed, so the only benefit was higher resolutions.
- Commander Keen in Keen Dreams (https://github.com/keendreams/keen/blob/master/id_vw_ae.asm)
- The EGA drawing routines used in this game were more sophisticated than in the earlier Commander Keen 1, but all of the fun tricks are still there.
Code on Hackerbun
- VGA and SVGA code examples (https://code.hackerbun.dev/TheIndustriousRabbit/vga-logic-processor-examples)
- My code exploring how the VGA and SVGA modes work in more detail, as well as learning more about x86 assembler.
2d games and the EGA pipeline
- Duke Nukem II Reconstructed (https://github.com/lethal-guitar/Duke2Reconstructed)
- Walks through a ton of detail on how this VGA game used the EGA pipeline, but on a VGA card, to achieve its smooth scrolling
- Lethal Guitar’s Duke Nukem platformer blog posts (https://lethalguitar.wordpress.com/2023/11/04/duke-nukem-1s-tile-rendering/)
- A much more detailed overview on the EGA drawing pipeline and how it was used effectively for platforming games
Why are, like, half these examples id Software games?
- Graphics Programming Black Book by Michael Abrash (https://www.phatcode.net/res/224/files/html/index.html)
- This book not only has a lot of incredible detail about the x86 processor, the DOS platform, and how these EGA and VGA modes work, but the author also worked on the Quake engine, and his earlier articles helped John Carmack make games like Commander Keen run so smoothly. Even if you’re not going to write low-level code for retro machines, the first three chapters are a fantastic read for any software developer who gets caught up in prematurely optimizing anything (code, date, features) at any level of the process. Highly recommended.
Credits
Music
- “Show Your Moves” by Kevin MacLeod