133 lines
7.1 KiB
Markdown
133 lines
7.1 KiB
Markdown
------------------------ --------------------------------- --------------------
|
||
[Previous](30-07.html) [Table of Contents](index.html) [Next](31-02.html)
|
||
------------------------ --------------------------------- --------------------
|
||
|
||
Chapter 31\
|
||
Higher 256-Color Resolution on the VGA {#Heading1}
|
||
---------------------------------------
|
||
|
||
### When Is 320x200 Really 320x400? {#Heading2}
|
||
|
||
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 (320x200) 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 640x480 16-color mode and the 320x200 256-color mode is so great
|
||
that many programmers must regretfully decide that they simply can’t
|
||
afford to use the 256-color mode.
|
||
|
||
If there’s one thing we’ve learned about the VGA, however, it’s that
|
||
there’s *never* just one way to do things. With the VGA, alternatives
|
||
always exist for the clever programmer, and that’s 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 360x480—and that’s with the vanilla IBM VGA!
|
||
|
||
In this chapter, I’m going to focus on one of my favorite 256-color
|
||
modes, which provides 320x400 resolution and two graphics pages and can
|
||
be set up with very little reof the VGA. In the next chapter, I’ll
|
||
discuss higher-resolution 256-color modes, and starting in Chapter 47,
|
||
I’ll cover the high-performance “Mode X” 256-color programming that many
|
||
games use.
|
||
|
||
So. Let’s get started.
|
||
|
||
### Why 320x200? Only IBM Knows for Sure {#Heading3}
|
||
|
||
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 320x200. This is the same
|
||
scan-doubling approach used by the VGA to convert the CGA’s
|
||
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
|
||
limitation—it’s the first 256-color mode ever offered by IBM, if you
|
||
don’t count the late and unlamented Professional Graphics Controller
|
||
(PGC). Why, then, would IBM choose to limit the resolution of mode 13H?
|
||
|
||
There’s 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 320x200 256-color mode requires 64,000
|
||
bytes of display memory. That’s no problem for the VGA, which has 256K
|
||
of display memory, but it’s 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 640x480 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 640x480
|
||
2-color graphics and mode 12H for 640x480 16-color graphics. The same
|
||
could have been done for 256-color graphics—but wasn’t. Why? I don’t
|
||
know. Maybe IBM just didn’t like the odd aspect ratio of a 320x400
|
||
graphics mode. Maybe they didn’t 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.
|
||
|
||
### 320x400 256-Color Mode {#Heading4}
|
||
|
||
Okay, what’s so great about 320x400 256-color mode? Two things: easy,
|
||
safe mode sets and page flipping.
|
||
|
||
As I said above, mode 13H is really a 320x400 mode, albeit with each
|
||
line doubled to produce an effective resolution of 320x200. That means
|
||
that we don’t need to change any display timings, widths, or heights in
|
||
order to tweak mode 13H into 320x400 mode—and that makes 320x400 a safe
|
||
choice. Basically, 320x400 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 320x400 256-color mode is that two pages are
|
||
supported. Each 320x400 256-color mode requires 128,000 bytes of display
|
||
memory, so we can just barely manage two pages in 320x400 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
|
||
VGA’s 256K, though, and the higher-resolution 256-color modes, which use
|
||
still larger bitmaps (areas of display memory that control pixels on the
|
||
screen), can’t support two pages at all. As we’ve 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.
|
||
|
||
That’s why I like 320x400 256-color mode. The next step is to understand
|
||
how display memory is organized in 320x400 mode, and that’s not so
|
||
simple.
|
||
|
||
#### Display Memory Organization in 320x400 Mode {#Heading5}
|
||
|
||
First, let’s look at why display memory must be organized differently in
|
||
320x400 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 320x200. This was accomplished *in
|
||
hardware*, so there is no way to extend the bitmap organization of mode
|
||
13H to 320x400 mode.
|
||
|
||
------------------------ --------------------------------- --------------------
|
||
[Previous](30-07.html) [Table of Contents](index.html) [Next](31-02.html)
|
||
------------------------ --------------------------------- --------------------
|
||
|
||
* * * * *
|
||
|
||
Graphics Programming Black Book © 2001 Michael Abrash
|