Game Programming
VGA Hardware Overview

Overview

If you've read the article on the VGA display principles, you have a flavor for what the VGA needs to do. It's job is mainly to get those three color values out rapidly, one after another, fast enough that the monitor can keep on going without missing a step. Meanwhile, the VGA hardware also needs to provide appropriate suggestions (control signals) to the VGA monitor about the horizontal and vertical blanking and retrace times. All this is happening at a very fast pace, sometimes at rates over 50 million pixels a second. Meanwhile, the VGA hardware also needs to accept commands and information from the PC.

The VGA provides a series of registers that allow you to specify the number of horizontal pixels on the screen, the number of vertical lines, and the horizontal and vertical timing signals. This allows the VGA to support many different resolutions, limited mostly by imagination and the monitors you can use.

Memory Layout

One issue in designing the memory was the fact that the VGA needed to support the older EGA, which supported 16 colors, selected from a palette of 64. This earlier EGA design organized the memory into four parallel planes of memory and extracted one bit from each of them, once for each pixel being sent to the monitor. Using four parallel planes meant that each one could be read at the same time, using the same address. This meant only one address register was needed since it was used for all four memory sections and, because each memory plane was a separate memory block on it's own, they could ask all four to be read at the same time. Together, this means fast speed with less hardware -- a useful goal in designing hardware.

The EGA actually read four bytes at a time, one from each plane, and placed the result in four, 8-bit registers (latches.) They would then shift out one bit at a time from these until they were empty, then load another byte from each plane from the next address. This process repeated until the whole image was displayed.

Now the VGA designers were faced with maintaining this method while providing some new capability, like offering 256 colors from a much larger palette. So they kept the part that read up the four bytes, one from each plane, but they added a new mode that would simply use the entire latch value as the color, rather than taking one bit from each latch. But the EGA used one bit from each plane to form a pixel color and had eight pixels per address used (to read one byte each from four planes), so that each plane carried a part of each pixel color. This new VGA mode used the entire latch from each plane as the color value, so now plane 0 held the entire color for pixel 0, 4, 8, etc., and plane 1 held the entire color for pixel 1, 5, 9, etc., and so on.

Being the tricky sort, the VGA designers came up with another idea. The decided to add a "chain-4" mode, which would cause successive addresses from the PC (from A000:0000 to A000:FFFF), to access alternating planes automatically, so the programmer would not have to worry about which plane a pixel was on. So, offset 0000 would access address 0000 of plane 0 and offset 0001 would access address 0000 of plane 1, and so on, until offset 0004 would access address 0001 of plane 0, and so the cycle repeats. Every four adjacent addresses access the four different planes, but at the same address on the planes.

Although this greatly simplified accessing the pixels from the PC software, it meant that only the first 16k byte of each plane could be accessed. Even though each plane could hold up to 64k byte, you can't get at the memory that way.

So two basic methods exist for accessing the VGA memory. The chain-4 method makes the access simple, but limits you to the first 16k byte of each of the four planes. The unchained method allows you to access all 64k of each plane, but requires you to go through an extra step of notifying the VGA hardware which plane you want to be talking to, before using an address to access it. This allows all 64k of the memory region at A000 to be used for one plane or another plane, just not all at the same time.

In any case, the VGA memory organization in 256-color modes is a new addition and manages its feat by setting it up so that every fourth pixel, horizontally, resides on the same plane. You can imagine this easily by imagining putting a blue color on plane 0, red on plane 1, green on plane 2, and yellow on plane 3. The resulting VGA display would be a series of vertical lines that run from top to bottom, alternating between these four colors as you move from left to right across the screen.

256 Colors

Once the design was finished about how to specify 256 colors, the next problem was that the EGA palette registers just couldn't hack it. So the VGA designers added a whole new section for the purpose, providing a separate group of 256 18-bit color registers, each with 6 bits for each of red, green, and blue. The older EGA palette registers are still retained, for those graphics modes still requiring them, but the designers added an odd mapping that translates these older palette register color values and tranlates the results over for use against the newer 256 color registers. This maintains some compatibility with older 16-color EGA software, while allowing more sophisticated software using these older 16-color graphics modes to perform more tricks than before.

Miscellaneous

The VGA hardware supports some extra features, like built-in XOR, AND, and OR modes that operate when writing the VGA memory from the PC. There is also a special bit mask that allows you to specify which bits of the color values are changed, protecting the rest of the bits from writing to them. Finally, because the VGA actually reads all four planes any and every time the PC reads from any address, four pixels can be copied at once. Better, because the VGA also has a simple 4-bit mask to say which planes are affected by a write, you can mask out certain pixels while copying four at a time.

The VGA, like the EGA, supports split screens and smooth panning, too. But I'll cover the technical details of this, elsewhere.

Quick Links:
 
 
 
    Creation Date:  Mon 29-Mar-1999 15:21:11
    Last Modified:  Sun 09-Apr-2000 21:06:47
    Copyright (C) 1999, 2000 Jonathan Dale Kirwan