abrash-black-book/32-01.md
2013-12-30 20:26:41 +11:00

113 lines
6.2 KiB
Markdown

Chapter 32\
Be It Resolved: 360x480 {#Heading1}
------------------------
### Taking 256-Color Modes About as Far as the Standard VGA Can Take Them {#Heading2}
In the last chapter, we learned how to coax 320x400 256-color resolution
out of a standard VGA. At the time, I noted that the VGA was actually
capable of supporting 256-color resolutions as high as 360x480, but
didn't pursue the topic further, preferring to concentrate on the
versatile and easy-to-set 320x400 256-color mode instead.
Some time back I was sent a particularly useful item from John Bridges,
a longtime correspondent and an excellent programmer. It was a complete
mode set routine for 360x480 256-color mode that he has placed into the
public domain. In addition, John wrote, "I also have a couple of
freeware (free, but not public domain) utilities out there, including
PICEM, which displays PIC, PCX, and GIF images not only in 360x480x256
but also in 640x350x256, 640x400x256, 640x480x256, and 800x600x256 on
SuperVGAs."
In this chapter, I'm going to combine John's mode set code with
appropriately modified versions of the dot-plot code from Chapter 31 and
the line-drawing code that we'll develop in Chapter 35. Together, those
routines will make a pretty nifty demo of the capabilities of 360x480
256-color mode.
### Extended 256-Color Modes: What's Not to Like? {#Heading3}
When last we left 256-color programming, we had found that the standard
256-color mode, mode 13H, which officially offers 320x200 resolution,
actually displays 400, not 200, scan lines, with line-doubling used to
reduce the effective resolution to 320x200. By tweaking a few of the
VGA's mode registers, we converted mode 13H to a true 320x400 256-color
mode. As an added bonus, that 320x400 mode supports two graphics pages,
a distinct improvement over the single graphics page supported by mode
13H. (We also learned how to get *four* graphics pages at 320x200
resolution, should that be needed.)
I particularly like 320x400 256-color mode for two reasons: It supports
two-page graphics, which is very important for animation applications;
and it doesn't require changing any of the monitor timing
characteristics of the VGA. The mode bits that we changed to produce
320x400 256-color mode are pretty much guaranteed to be the same from
one VGA to another, but the monitor-oriented registers are less certain
to be constant, especially for VGAs that provide special support for the
extended capabilities of various multiscanning monitors.
All in all, those are good arguments for 320x400 256-color mode.
However, the counter-argument seems compelling as well—nothing beats
higher resolution for producing striking graphics. Given that, and given
that John Bridges was kind enough to make his mode set code available,
I'm going to look at 360x480 256mode next. However, bear in mind that
the drawbacks of this mode are the flip side of the strengths of 320x400
256-color mode: Only one graphics page, and direct setting of the
monitorregisters. Also, this mode has a peculiar and unique aspect
ratio, with 480 pixels (as many as high-resolution mode 12H) vertically
and only 360 horizontally. That makes for fairly poor horizontal
resolution and sometimes-jagged drawing; on the other hand, the
resolution is better in both directions than in mode 13H, and mode 13H
itself has an odd aspect ratio, so it seems a bit petty to complain.
The single graphics page isn't a drawback if you don't need page
flipping, of course, so there's not much to worry about there: If you
need page flipping, don't use this mode. The direct setting of the
monitor-oriented registers is another matter altogether.
I don't know how likely this code is to produce problems with clone VGAs
in general; however, I did find that I had to put an older Video Seven
VRAM VGA into "pure" mode—where it treats the VRAMs as DRAMs and exactly
emulates a plain-vanilla IBM VGA—before 360x480 256-color mode would
work properly. Now, that particular problem was due to an inherent
characteristic of VRAMs, and shouldn't occur on Video Seven's Fastwrite
adapter or any other VGA clone. Nonetheless, 360x480 256-color mode is a
good deal different from any standard VGA mode, and while the code in
this chapter runs perfectly well on all other VGAs in my experience, I
can't guarantee its functionality on any particular VGA/monitor
combination, unlike 320x400 256-color mode. Mind you, 360x480 256-color
mode *should* work on all VGAs—there are just too many variables
involved for me to be certain. Feedback from readers with broad 360x480
256-color experience is welcome.
The above notwithstanding, 360x480 256-color mode offers 64 times as
many colors and nearly three times as many pixels as IBM's original CGA
color graphics mode, making startlingly realistic effects possible. No
mode of the VGA (at least no mode that I know of!), documented or
undocumented, offers a better combination of resolution and color; even
320x400 256-color mode has 26 percent fewer pixels.
In other words, 360x480 256-color mode is worth considering—so let's
have a look.
### 360x480 256-Color Mode {#Heading4}
I'm going to start by showing you 360x480 256-color mode in action,
after which we'll look at how it works. I suspect that once you see what
this mode looks like, you'll be more than eager to learn how to use it.
Listing 32.1 contains three C-callable assembly functions. As you would
expect, **Set360x480Mode** places the VGA into 360x480 256mode.
**Draw360x480Dot** draws a pixel of the specified color at the specified
location. Finally, **Read360x480Dot** returns the color of the pixel at
the specified location. (This last function isn't actually used in the
example program in this chapter, but is included for completeness.)
Listing 32.2 contains an adaptation of some C linecode I'll be
presenting shortly in Chapter 35. If you're reading this book in serial
fashion and haven't gotten there yet, simply take it on faith. If you
really *really* need to know how the line-draw code works right *now*,
by all means make a short forward call to Chapter 35 and digest it. The
line-draw code presented below has been altered to select 360x480
256-color mode, and to cycle through all 256 colors that this mode
supports, drawing each line in a different color.