|Dͻ
|D |5The Happy Hacker |D
|Dͼ

^CIBM-PC VIDEO PRIMER
^Cby:  Joel Ellis Rea

^CPart Three:  Video and the IBM-PC (Monochrome)

The IBM Monochrome Display Adapter (MDA) was one of the original two display 
adapters available to early IBM PC owners.  Coupled with the IBM Monochrome 
Display Monitor, it displayed reasonably sharp green text of well-defined 
characters with plenty of space between lines.  A matrix of 25 rows contained 
80 character cells each.  The monitor used a pure green, high-persistence 
phosphor coating in a solid sheet.  Some third-party monitors came in other 
colors, such as medium-persistence amber or short-persistence pale "seasick" 
green. 

Virtually every PC-clone manufacturer sells their own equivalent of the 
Monochrome Display Adapter.  These are usually interchangable between systems. 
This means an IBM MDA board plugs into a PC-compatible computer, or an MDA- 
compatible board into an IBM-PC.  Hercules makes a board that is MDA- 
compatible, with even higher resolution graphics than the "high-resolution" 
mode of the Color Graphics Adapter (CGA).  This board and all  compatible 
boards are also compatible with the MDA.  For the purposes of this article, MDA 
will refer to all boards compatible with the IBM MDA, and MGA will refer to the 
Hercules Monochrome Graphics Adapter and all boards compatible with it, and 
thus with the MDA as well. 

One megabyte of memory is addressable by the Intel 8088, 8086, 80188 and 80186 
CPUs (as well as the 80286 and 80386 chips in "real," or 8086-emulation 
addressing mode).  Computers use binary numbers, so common numbers are usually 
rounded to the nearest power of two.  Thus, 1K is 1024, not 1000; 1M is 1024K, 
or 1024 x 1024, or 1,048,576.  One byte is eight bits, one bit is a single 
true/false or on/off value, represented by a "0" or a "1."  Eight bits can hold 
any value between 0 and 255, for a total of 256 possible values.  Since there 
are 254 displayable characters in the IBM character set, including the space, 
one byte is equivalent to one character.  So, the 8088 (or compatible) can 
address 1,048,576 characters. 

Not all this memory is used for storing text.  Some holds permanent program 
code, called the "bootstrap" or "boot," and "Basic Input/ Output System" (BIOS) 
in memory called Read Only Memory, or ROM, which can only be read from, not 
written to.  Real IBM-PC's also contain the IBM Cassette BASIC in ROM, but 
"clones" are not legally permitted to include it.  Other memory is allocated to 
adapter boards, including the CGA and MDA, as well as disk interfaces, etc. The 
remaining 640K is allocated to Random Access Memory, or RAM.  That's why MS-DOS 
computers currently have a working limit of 640K accessible from MS-DOS. 

We want to focus on the adapter boards.  Each basic type of board has memory 
allocated to be used as the board sees fit.  Display adapter boards, such as 
the MDA, MGA, etc., use their memory for holding the characters or graphics 
that appear on the screen.  You would think that it would require only one byte 
per character, since we established that one byte was sufficient to hold one 
character, but that is not the case.  Each character can be displayed as dim, 
bold, inverse, underscored, flashing, and even invisible, as well as various 
combinations, such as bold flashing underscored.  These are called 
"attributes," and are stored in separate bytes corresponding to each character 
cell.  So, 25 lines of 80 character cells each equals 2,000 cells.  Two bytes 
each means the MDA needs at least 4,000 bytes to hold its display.  Because 
computer memory is organized in powers of two, the MDA actually has 4,096 (4K) 
bytes of RAM for display storage.  The extra 96 bytes are wasted but 
theoretically could be used as "scratchpad" storage, outside the 640K MS-DOS 
memory, by an enterprising programmer.  This memory is available only on MDA-
equipped systems. 

MGA boards need sufficient memory to hold one bit for every dot, or "pixel" 
(picture element) on the screen.  Resolution is 720 across by 348 down, 
requiring enough RAM to hold 348 lines of 720 bits.  Each line takes up 720/8, 
or 90 bytes.  348 x 90 = 31,320, so each screen requires nearly 32K, or 32,768 
bytes of RAM.  MGA boards contain 64K of RAM, providing room for two such 
screens.  When emulating an MDA, only the first 4K is available for use as a 
text display buffer. 

To display a character at a particular place on the screen, the screen 
(extended ASCII) character code is placed in that location by multiplying the 
row number times 160 (two bytes per character and 80 characters per row) and 
multiplying the column number times two (two bytes per character), then adding 
the two products.  The sum is the address of the character cell, relative to 
the start of the character screen buffer RAM.  The attribute is placed in the 
location following.  Thus a screen in memory consists of 4000 bytes in 25 rows 
of 80 two-byte character/attribute pairs. 

If the first location in the screen buffer contains the code for "A" (65) and 
the location following it contains an attribute meaning bold and underscored 
(attribute 9), a bold, underscored "A" appears in the upper left corner of the 
screen. 

How is it that 65 specifies the shape of the letter "A"?  Actually, the 65 
means to look up in another memory area (available only to the circuitry on the 
video board itself, not the CPU), and find the actual character shape.  This 
special memory is called the "Character Generator ROM" and is Read Only Memory. 
It stores the entire shapes of all 256 possible characters.  MDA characters are 
formed in a 14-row by nine-pixel matrix and each entry needs a minimum of 9 
times 14, or 126 bits.  Each row requires one more pixel than will fit in one 
byte, requiring two bytes for each row, 28 bytes for each character.  256 28-
byte characters require 7,168 bytes of ROM.  The smallest practical ROM chip is 
8,192 bytes. 

While it appears that the computer is doing nothing, it is actually waiting for 
a keypress, and the video board is really quite busy.  It must do a lot of work 
just to display the text screen.  With an MDA or MGA, the following occurs: 

The scan starts at the top of the screen.  The video board sends timely scan 
synchronization signals, plus the actual video signal.  For each screen, the 
beam is turned off and aimed slightly above and to the left of the top left 
corner.  The beam is left off while it scans a few blank lines, then moves down 
to the normal screen area.  Next, the video board analyzes the first text line 
-- all 160 bytes.  For each character, its code and attribute is extracted. The 
code is then used as an index in the Character Generator ROM to retrieve a row 
of pixels needed for the character.  It scans the first row of all characters 
on the line, then the second row, etc., down to the 14th row.  When it finishes 
that line of text, it advances to the next and starts the cycle over. 

For each scan line in a character, the video circuitry obtains a row of nine 
pixels.  For the middle of the "A," just above the crossbar, it asks for row 7 
of character 65 from the Character Generator ROM.  Two bytes are retrieved: 
"01100011 00000000."  Only the first nine bits are used, so only "011000110" is 
significant.  This tells which parts of the scan are considered "on" and which 
parts are "off."  Now the attribute is examined to see how to handle the beam. 
If the attribute is normal, the video signal is on for each "1" bit and off for 
each "0" bit.  If the attribute is inverse, it reverses the meanings, so that 
the signal is on for "0" and off for "1."  If the bold attribute is set, a 
secondary video signal called "Intensity" is similarly activated.  When both 
Video and Intensity are on, the monitor responds by brightening the beam.  When 
the attribute is for invisible text, the Video signal is kept off for both "0" 
and "1," unless inverse is also active, in which case the beam is kept on. When 
the attribute is set for flashing, depending on the current status of a 
hardware timer on the board, it alternately acts as visible and invisible. 

After all 14 scan rows of the 25 text rows are scanned, the video beam is again 
shut off, a few more blank lines are scanned, then it is brought back to the 
starting point and the process starts again.  For an MDA or MGA, this happens 
50 times a second, thus the Vertical Sync Rate of monochrome monitors is stated 
as 50Hz.  (1 "Hz," or Hertz, means once per second.)  Lines are scanned from 
left to right, blanked briefly and brought back to the left for the next line 
at a rate such that if this happened uninterrupted by vertical retracing, it 
would draw 18,432 lines per second.  The Horizontal Sync Rate is therefore said 
to be 18.432kHz (1 kHz, or "kiloHertz," equals 1,000 Hertz.) 

The MDA display memory access circuitry is fast and efficient.  It can access 
almost 2 million bytes per second.  The actual rate is 1.8Mb (Megabytes) per 
second.  This allows reading display memory without conflicting with the CPU 
which is also trying to read or write this memory.  The MDA is not subject to 
the "snow" that plagues the CGA when both the CPU and the video board 
simultaneously access the same memory. 

Next time I will discuss the original IBM Color Graphics Adapter (CGA) board, 
and how it differs from the MDA.  I will explain why text is easier to read 
when generated by the MDA and why you can have one of each in your system.  I 
will also describe some little-known CGA features, and explain the "snow" 
problem and a possible solution.  See you then. 
