home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Big Blue Disk 10
/
bbd10new.zip
/
VIDEO6.TXT
< prev
next >
Wrap
Text File
|
1987-05-22
|
17KB
|
282 lines
|D╔══════════════════╗════════════════════════════════════════════════════════════
|D║ |5The Happy Hacker |D║════════════════════════════════════════════════════════════
|D╚══════════════════╝════════════════════════════════════════════════════════════
^C^1A VIDEO TUTORTIAL -- Part 6
^Cby Joel Ellis Rea
Last issue I discussed the "heart" of both the MDA and the CGA (as well as
boards which are enhancements to these, such as the Hercules and Plantronics),
the Motorola 6845 Cathode Ray Tube Controller (CRTC) chip. I mentioned then
that there are other registers implemented in the hardware of the MDA and CGA
besides the 18 CRTC registers. I specifically described 2 of these, which are
used to access the 18 CRTC registers themselves. In this issue, I will more
fully describe the non-CRTC registers of both the MDA and the CGA, as well as
give some examples of their use. Also on this issue is a demonstration program
which shows some of the effects possible by directly "tweaking" these registers
as well as the CRTC registers.
Any board that is installed into the IBM-PC bus usually presents some form
of memory or pseudo-memory to the PC address space. This is usually one or
more of the following three types:
1. RAM (Random Access Memory), which can be read from or written to.
2. ROM (Read-Only Memory), which can only be read from, not written to.
This is generally used to add new commands to the System BIOS (Basic Input/
Output System) ROM located on the motherboard. The EGA does this, the CGA
and MDA do not.
3. I/O (Input/Output) ports. These use a different form of addressing than
RAM or ROM, and thus do not take up "space" in the CPU's 1Meg address
space. Rather, they form their own 64K address space.
The MDA and CGA have types 1 and 3, RAM and I/O ports. The RAM is for the
display buffer, and the I/O ports are for control. They also have ROM (for the
character generator) but it is not made available to the PC bus. It is used by
the card's circuitry alone.
It is a fundamental law of hardware interfacing that no two devices can
claim the same memory addresses in the system at the same time. Should this
occur, the system will lock up (or crash) due to "bus contention", meaning two
devices fighting over the same area of memory. This goes for the 64K I/O space
as well, which is really just another area of memory with its own address
space. IBM planned a way to avoid contention by allocating both the memory and
I/O spaces for particular purposes. The memory space ranges from 00000h to
FFFFFh (1M), while the I/O space ranges from 0000h to FFFFh (64K). System RAM
can reside in space from 00000h to 0AFFFFh (640K). The rest of the space, from
0B0000h to 0FFFFFh (384K), is reserved for plug-in boards and the System BIOS,
bootstrap, BASIC and diagnostic ROMs.
The memory space from 0B0000h through 0B7FFFh (32K) has been allocated to
the MDA board and its clones and extensions, though the MDA itself only uses 4K
of that (0B0000h through 0B0FFFh). Likewise, the space from 0B8000h through
0BFFFFh (also 32K) has been allocated to the CGA and its clones and extensions,
though the CGA itself only uses 16K of that (from 0B8000h through 0BBFFFh).
The total memory space allocated to video, then, is 64K, from 0B0000h to
0BFFFFh. Any video board that needs more than that must use some form of
"bank-switching" or indirect memory access.
The I/O space is another matter. The MDA is allocated the I/O space from
03B0h through 03BFh (16 bytes) for its functions. The CGA is allocated the I/O
space from 03D0h through 03DFh (also 16 bytes) for its functions. The EGA can
somewhat simulate the CGA and MDA by using those spaces in a way somewhat
similar (but not identical) to the way the CGA and MDA do. It also uses the
I/O space from 03C0h through 03CFh, giving it the total video I/O space from
03B0h through 03DFh (48 bytes).
Both the MDA and the CGA contain ports for accessing the CRTC registers,
plus a general control port and a general status port. The CGA also contains a
color port and two light pen ports, while the MDA contains three ports for
controlling the on-board parallel printer interface (LPT1:). I will not
discuss the parallel printer interface ports in this series of articles.
The last hexadecimal digit in the port address determines which port is
being accessed. The same hex digit denotes the same port on both the MDA and
CGA, where they both have similar ports. In such cases, I will use the
notation "03?#h", where "#" is the port-identifying hex digit and "?" is "D"
in the case of a CGA and "B" in the case of an MGA. Where a port, or feature
of a port, is unique to the CGA, I will use "03D#h". In the case of uniqueness
to the MDA, I will use "03B#h".
The 16 ports for the MDA and CGA are as follows:
^1 PORT MDA NAME CGA NAME
^1 03?0h Unused (03B4h phantom) Unused (03D4h phantom)
^1 03?1h Unused (03B5h phantom) Unused (03D5h phantom)
^1 03?2h Unused (03B4h phantom) Unused (03D4h phantom)
^1 03?3h Unused (03B5h phantom) Unused (03D5h phantom)
^1 03?4h 6845 CRTC Index 6845 CRTC Index
^1 03?5h 6845 CRTC Data 6845 CRTC Data
^1 03?6h Unused (03B4h phantom) Unused (03D4h phantom)
^1 03?7h Unused (03B5h phantom) Unused (03D5h phantom)
^1 03?8h MDA Control Port CGA Control Port
^1 03?9h Unused (Reserved) CGA Color/Palette Port
^1 03?Ah MDA Status Port CGA Status Port
^1 03?Bh Unused (Reserved) CGA Light Pen Latch Clear
^1 03?Ch Parallel Data Port CGA Light Pen Latch Preset
^1 03?Dh Parallel Status Port Unused (Reserved?)
^1 03?Eh Parallel Control Port Unused (03D4 phantom?)
^1 03?Fh Unused Unused (03D5 phantom?)
As discussed last issue, port 03?4h is used to select which of the 18 CRTC
registers (R0-R17) will appear at port 03?5h for reading and/or writing. The
ports labeled "phantom" act the same as 03?4h or 03?5h. Thus, you could use
03D0h and 03D1h instead of 03D4h and 03D5h, but this is not recommended. Many
of the MDA/CGA enhancements co-opt these ports for their own uses. The
Plantronics ColorPLUS, for example, uses 03DDh, while the Genoa Spectrum and
the ATI Graphics Solution uses both 03DDh (for Plantronics ColorPLUS emulation)
and 03DEh (for their own functions, such as 132-column text). See the
instruction book with any enhanced board for details on its registers.
For now, we will concentrate on the control (03?8h), color/palette (03D9h)
and status (03?Ah) ports. The control port allocates its 8 bits as follows:
^1 BIT VALUE MDA USAGE (when set) CGA USAGE (when set)
^1 0 1 High Resolution (?) 80x25 Alphanumeric
^1 1 2 Unused 320x200 Graphics
^1 2 4 Unused Color Burst Disable
^1 3 8 Video Enable Video Enable
^1 4 16 Unused 640x200 Graphics
^1 5 32 Blink Enable Blink Enable
^1 6 64 Unused Unused
^1 7 128 Unused Unused
The single most important bit in the control port is bit #3, the video
enable signal. If that bit is not set, then the screen will be BLANK, no
matter what other bits or registers are set. The primary use of this is to
disable the video while radically changing the video display, so that a partial
change will not damage the monitor.
A useful one is bit #5, blink enable. This, like bit #3, is normally set.
When it is set, bit #7 (the most significant bit, or MSB) of the attribute
bytes for each character will cause that character to blink. When cleared, the
MSB of the attribute byte will instead set the background intensity of the
character cell. On the MDA, this will allow you to have bold as well as dim
inverse characters. That is, the background will be bright instead of normal
when inverted. On the CGA, this will allow you to have 16 colors for text
backgrounds as well as for the text characters themselves, all visible on the
screen at once, instead of the usual 8 background colors. Note that the BIOS
clears this bit whenever it is called upon to scroll or clear the screen. For
screen displays that don't scroll, this capability is very useful. It is an
important part of the "formula" for making the CGA's "hidden" 160x100 16-color
"low-res" graphics mode. It also allows black text on a yellow background,
which is scientifically proven to be the most readable color combination to the
human eye. Yellow cannot normally be a background color, since it is high-
intensity. Brown is its low-intensity analog.
Bit #0 on the MDA is labeled "High Resolution Mode" in the IBM Personal
Computer Technical Reference Manual for the IBM PC/XT, page 1-118. However, I
have not been able to get it to produce any discernable effect whatsoever.
Thus the "(?)" in its description in my table above. Of course it has a
DEFINITE effect on the CGA. It doubles the video output rate, thus allowing
the 80x25 text display to be possible. However, switching between 40 and 80
column modes involves more than just this bit. Several of the CRTC registers
must also be changed. This is one of those cases where it is wise to disable
video first, make the changes, then re-enable video.
Bit #2 on the CGA disables the color burst when set, or enables it when
reset, allowing a sharper but black and white display on composite (VCR-
compatible) monitors. In particular, it removes the vertical striping effect
caused by the presence of NTSC color information. On RGB monitors, it has no
effect in text or 640x200 hi-res modes, but it has a very useful effect on the
320x200 4-color medium-res mode: it provides access to a third palette,
providing red, cyan and white as foreground colors in addition to the two
palettes mentioned in the IBM BASIC manuals!
On the CGA, the graphics modes differ from the 40x25 text mode only in that
the video information comes straight from memory rather than by way of the
character generator ROM and by the vertical settings of the CRTC. In
particular, the CRTC is set up to provide 100 "character rows", each 2 scan
lines high, instead of 25 character rows each 8 scan lines high. Then bit #1
is set to enable graphics, and bit #4 is set if hi-res (640x200) graphics is
desired. By setting bit #4 without also setting bit #1, a very strange effect
is produced. It seems to be similar to the "low-res" (160x100) mode, but not
as controllable.
That about covers the command register. The color/palette register does not
exist on the MDA. Its bits on the CGA are as follows:
^1 BIT VALUE CGA usage
^1 0 1 BLUE bit of Special color.
^1 1 2 GREEN bit of Special color.
^1 2 4 RED bit of Special color.
^1 3 8 INTENSITY bit of Special color.
^1 4 16 Intensity of med-res graphics foreground or text background.
^1 5 32 Palette for 320x200 (med-res) graphics foreground.
^1 6 64 Unused.
^1 7 128 Unused.
Bits 0-3 select one of 16 colors as the CGA "Special" color. In text modes
(and low-res 160x100 "graphics" mode which is actually a form of the 80-column
text mode), this refers to the border color. This is how you set the border
color in text mode. In medium-res 320x200 graphics mode, this refers instead
to the common background color. While the three foreground colors can only be
selected from a few hard-wired palettes, the background can be any of 16
colors, and this is what selects which color it is. In high-res 640x200
graphics mode, the background is always black. The "Special" color bits
instead set the foreground (drawing) color. "But I thought 640x200 graphics
mode was black & white only!" you say? That is indeed what the IBM BASIC
manual says. But actually, you can have any of the 16 colors (but only one on
the screen at a time) on a black background by using this register!
Bit 4 selects the palette used by the 320x200 color graphics mode (with
color burst on). As you may know, in that mode you can have three foreground
colors on one background color. The background color can be any of the 16 CGA
colors (selected by the Special Color bits 0-3 of this very register!), but the
foreground colors are more limited. In "color-burst on" mode, you can choose
from red/green/brown, or magenta/cyan/light gray. When bit 4 is reset you get
the red/green/brown palette. When set, you get the magenta/cyan/light gray
palette. Note that in the 320x200 "B&W" ("color-burst off") mode, this bit has
no effect and the only palette consists of red/cyan/light Gray. Bit 4 has
another meaning in alphanumeric modes. It is supposed to set the intensity of
the background when you have "blink" enabled in the Control Port (03D8h, bit
5), but I have not been able to demonstrate this effect on any machine we have
here. We have no true CGAs, but we have several work-alikes on which all these
other "tricks" work. Also, one of my fellow employees has a true CGA at home,
and he says it doesn't work there either. The demo program included will
attempt to demonstrate this.
Bit 5 allows you to set the intensity of the three foreground colors in
either version of the 320x200 medium-res graphics modes. When reset, the
colors are low-intensity. When set, they are high-intensity. Thus, instead of
red/ green/brown, magenta/cyan/light gray and red/cyan/light gray, you get
light red/ light green/yellow, light magenta/light cyan/white and light
red/light cyan/ white. Between bits 4 and 5, and the color-burst bit in the
control port, you have 6 total palettes you can use in 320x200 medium-res
graphics mode.
So much for the color/palette register. Now we come to the last register
that is on both the MDA as well as the CGA -- the status register, at 03?Ah
(03BAh for MDA, 03DAh for CGA). Its bits are as follows:
^1 Bit Value MDA Meaning CGA Meaning
^1 0 1 Horizontal Retrace Horizontal Retrace
^1 1 2 Unused Light Pen Trigger Set
^1 2 4 Unused Light Pen Triggered
^1 3 8 Vertical Retrace Vertical Retrace
(Bits 4-7 are not used on either the MDA or CGA.)
We will not discuss the CGA light pen in this article. For now, we will
concentrate on the retrace signals common to both boards. When these are
zero, the beam is in the process of scanning the visible portion of a line.
This means that the display circuitry is accessing display RAM. If the CPU
also tries to access the display RAM at the same time, there is no problem
EXCEPT ON THE CGA, IN 80x25 ALPHANUMERIC ("TEXT") MODE (and modes derived from
it, such as the 160x100 16-color + border low-res pseudo-graphics mode)!
Should such simultaneous access occur in the CGA 80x25 text mode, the 6845 will
be trying to read memory during the same cycles that the CPU is. The CPU, of
course, has priority (to prevent system crashes), so the 6845 reads false data,
usually all ones. This causes a momentary "glitch" on the screen. If this
happens often enough to be really noticeable, the effect is called "digital
snow" and is very distracting -- so much so that the BIOS scroll routines will
prefer to turn the video off while scrolling, causing the "blink" so familiar
to true CGA owners. Believe me, the blink is preferrable to the blizzard!
Scrolling is, of course, a mass-memory move. But when doing more minor
access to the display memory, it is not necessary to blank the screen each
time. Just wait until vertical blanking (Bit 3 set) and do your access. If
you are programming in assembly language ONLY and wish to have more access
time, you can also use horizontal blanking (Bit 0 set). Each horizontal
blanking pulse lasts barely long enough to access ONE byte with a 4.77MHz 8088,
however. "Turbo" machines and "AT-class" machines have less of a problem here.
The REAL solution, of course, is to have a faster video board that doesn't
make like the Colorado ski season all over your screen. Most CGA work-alikes
have made this change, and the effect is VERY nice. You appreciate it only
after you have worked with a true IBM CGA or other "slow/snow" clone card.
This concludes our discussion of the more important ports and registers of
the CGA and MDA boards. I have provided a demonstration program which will
show off many of the effects I have discussed. You can run it from here by
simply pressing the [RETURN] ([─┘]) key. ^1NOTE^N: This demo works only on CGA
and compatible adapters, and does ^1NOT^N work on an EGA or a PCjr.
Next time I will discuss the BIOS, and how it makes living with the CGA and
MDA a little easier. Until then, happy viewing!