|Previous||Table of Contents||Next|
One of the more appealing features of the VGA is its ability to display 256 simultaneous colors. Unfortunately, one of the less appealing features of the VGA is the limited resolution (320×200) of the one 256-color mode the IBM-standard BIOS supports. (There are, of course, higher resolution 256-color modes in the legion of SuperVGAs, but they are by no means a standard, and differences between seemingly identical modes from different manufacturers can be vexing.) More colors can often compensate for less resolution, but the resolution difference between the 640×480 16-color mode and the 320×200 256-color mode is so great that many programmers must regretfully decide that they simply cant afford to use the 256-color mode.
If theres one thing weve learned about the VGA, however, its that theres never just one way to do things. With the VGA, alternatives always exist for the clever programmer, and thats more true than you might imagine with 256-color mode. Not only is there a high 256-color resolution, there are lots of higher 256-color resolutions, going all the way up to 360×480and thats with the vanilla IBM VGA!
In this chapter, Im going to focus on one of my favorite 256-color modes, which provides 320×400 resolution and two graphics pages and can be set up with very little reof the VGA. In the next chapter, Ill discuss higher-resolution 256-color modes, and starting in Chapter 47, Ill cover the high-performance Mode X 256-color programming that many games use.
So. Lets get started.
The first question, of course, is, How can it be possible to get higher 256-color resolutions out of the VGA? After all, there were no unused higher resolutions to be found in the CGA, Hercules card, or EGA.
The answer is another question: Why did IBM not use the higher-resolution 256-color modes of the VGA? The VGA is easily capable of twice the 200-scan-line vertical resolution of mode 13H, the 256-color mode, and IBM clearly made a decision not to support a higher-resolution 256-color mode. In fact, mode 13H does display 400 scan lines, but each row of pixels is displayed on two successive scan lines, resulting in an effective resolution of 320×200. This is the same scan-doubling approach used by the VGA to convert the CGAs 200-scan-line modes to 400 scan lines; however, the resolution of the CGA has long been fixed at 200 scan lines, so IBM had no choice with the CGA modes but to scan-double the lines. Mode 13H has no such historical limitationits the first 256-color mode ever offered by IBM, if you dont count the late and unlamented Professional Graphics Controller (PGC). Why, then, would IBM choose to limit the resolution of mode 13H?
Theres no way to know, but one good guess is that IBM wanted a standard 256-color mode across all PS/2 computers (for which the VGA was originally created), and mode 13H is the highest-resolution 256-color mode that could fill the bill. You see, each 256-color pixel requires one byte of display memory, so a 320×200 256-color mode requires 64,000 bytes of display memory. Thats no problem for the VGA, which has 256K of display memory, but its a stretch for the MCGA of the Model 30, since the MCGA comes with only 64K.
On the other hand, the smaller display memory size of the MCGA also limits the number of colors supported in 640×480 mode to 2, rather than the 16 supported by the VGA. In this case, though, IBM simply created two modes and made both available on the VGA: mode 11H for 640×480 2-color graphics and mode 12H for 640×480 16-color graphics. The same could have been done for 256-color graphicsbut wasnt. Why? I dont know. Maybe IBM just didnt like the odd aspect ratio of a 320×400 graphics mode. Maybe they didnt want to have to worry about how to map in more than 64K of display memory. Heck, maybe they made a mistake in designing the chip. Whatever the reason, mode 13H is really a 400-scan-line mode masquerading as a 200-scan-line mode, and we can readily end that masquerade.
Okay, whats so great about 320×400 256-color mode? Two things: easy, safe mode sets and page flipping.
As I said above, mode 13H is really a 320×400 mode, albeit with each line doubled to produce an effective resolution of 320×200. That means that we dont need to change any display timings, widths, or heights in order to tweak mode 13H into 320×400 modeand that makes 320×400 a safe choice. Basically, 320×400 mode differs from mode 13H only in the settings of mode bits, which are sure to be consistent from one VGA clone to the next and which work equally well with all monitors. The other hi-res 256-color modes differ from mode 13H not only in the settings of the mode bits but also in the settings of timing and dimension registers, which may not be exactly the same on all VGA clones and particularly not on all multisync monitors. (Because multisyncs sometimes shrink the active area of the screen when used with standard VGA modes, some VGAs use alternate register settings for multisync monitors that adjust the CRT Controller timings to use as much of the screen area as possible for displaying pixels.)
The other good thing about 320×400 256-color mode is that two pages are supported. Each 320×400 256-color mode requires 128,000 bytes of display memory, so we can just barely manage two pages in 320×400 mode, one starting at offset 0 in display memory and the other starting at offset 8000H. Those two pages are the largest pair of pages that can fit in the VGAs 256K, though, and the higher-resolution 256-color modes, which use still larger bitmaps (areas of display memory that control pixels on the screen), cant support two pages at all. As weve seen in earlier chapters and will see again in this book, paging is very useful for off-screen construction of images and fast, smooth animation.
Thats why I like 320×400 256-color mode. The next step is to understand how display memory is organized in 320×400 mode, and thats not so simple.
First, lets look at why display memory must be organized differently in 320×400 256-color mode than in mode 13H. The designers of the VGA intentionally limited the maximum size of the bitmap in mode 13H to 64K, thereby limiting resolution to 320×200. This was accomplished in hardware, so there is no way to extend the bitmap organization of mode 13H to 320×400 mode.
|Previous||Table of Contents||Next|