CS-220, Sec.90, Week 11-A
R. Eckert

THE VIDEO DISPLAY SYSTEM (PC)--

Almost all digital computers use "memory-mapped" I/O to implement the video
subsystem. This means that a special memory is dedicated to the video. Each
location in this read/write memory (called the Video RAM, or VRAM) is
dedicated to a screen location--either a character cell on the screen
(text mode) or a dot (pixel) on the screen (graphics mode). The following
is a block diagram of a typical video system:

                              _______________
     ________________        |               |
    |                |       |               |
    |                | ----> |   Video RAM   |
    |                |       |               |
    |                |       |_______________|
    | Microprocessor |               |
    |                |               |
    |                |        _______v_______         ___________
    |                |       |   Video       |       | Video     |
    |                | ----> |   Display     | ----> | Display   |
    |________________|       |   Adapter     |       | Device    |
                             |_______________|       | (Monitor) |
                                                     |___________|

The program running on the microprocessor sends information on what is to
be displayed to the video RAM (VRAM). The Video Display Adapter
continually reads from the video RAM and sends the signals necssary for
the display device to update the screen. Thus any character or dot (pixel)
color written to the VRAM will automatically be displayed on the screen at
the position corresponding to the VRAM location written to. Because the
processor can be writing to the VRAM at any point in time and the display
adapter can also be reading at any time, the Video RAM must be "dual-
ported"--as close to simutaneously readable and writeable as possible.
Typically the Display Adapter must cause the entire screen to be updated
60 times a second. Since an entire screen could be millions of dots
(pixels), the video RAM must also be very fast.

Most video systems can operate in many different "display modes." These can
be broken down into two general categories--text and graphics. Each mode is
characterized by it resolution and the number of colors that can be
displayed. For text modes, the resolution is usually expressed by the number
of columns and the number of rows of character cells on the screen, for
example, 80 X 25. Graphics mode resolution is specified in terms of
horizontal and vertical dots (pixels), for example 640 X 480. The number
of colors displayable depends on the number of bits per pixel (or per
character cell) in the Video RAM. The rule is:

    number of colors = 2^n,

where n is the number of bits per pixel in the Video RAM.


SOME IBM-PC DISPLAY ADAPTERS AND DISPLAY MODES

The earliest PCs had monochrome display adapters (MDA). Then came simple
color systems using the Color Graphics Adapter (CGA). Next came the
Enhanced Graphics Display (EGA) with increased color and resolution
capabilities. Then IBM came out with the Video Graphics Array (VGA) with
even greater capabilities. Finally, many companies have come out with
Super VGA (SVGA) display adapters. All of these are "upward compatable,"
meaning that programs that use display adapters with lower video
capabilities will also run on systems having display adapters with greater
capabilities. Some of the video modes supported by MDA, CGA, EGA, and/or
VGA are shown in the following table.


Mode  Colors  Text/Graphics Resolution   Adapter   Start Address of VRAM
------------------------------------------------------------------------
 1    16,         Text        40 x 25     CGA       0B800:0000
 2    16 grey     Text        80 x 25     CGA       0B800:0000
 3    16          Text        80 x 25     CGA       0B800:0000
 4    4           Graphics   320 x 200    CGA       0B800:0000
 5    4 grey      Graphics   320 x 200    CGA       0B800:0000
 6    2 (B & W)   Graphics   640 x 200    CGA       0B800:0000
 7    2 (B & W)   Text        80 x 25     MA        0B000:0000
13    16          Graphics   320 x 200    EGA       0A000:0000
14    16          Graphics   640 x 200    EGA       0A000:0000
15    2 (B & W)   Graphics   640 x 350    EGA       0A000:0000
16    16          Graphics   640 x 350    EGA       0A000:0000
17    2 (B & W)   Graphics   640 x 480    VGA       0A000:0000
18    16          Graphics   640 x 480    VGA       0A000:0000
19    256         Graphics   320 x 200    VGA       0A000:0000

Because there are so many Super VGA manufacturers, it is difficult to
summarize the various SVGA modes available. The Video Electroncs Standards
Association (VESA) has come up with so-called VESA standards for SVGA
adapters that are supported by most video card manufacturers. See, for
example the following Web sites:

The VESA BIOS Extension 2.0

The VESA BIOS Extension (VBE) Version 3.0 Standard Core Functions
USING PC BIOS SERVICES TO PERFORM VIDEO OUTPUT--TEXT MODE

Probably the easiest way of doing video output is to use the services built
into the BIOS video interrups, INT 10h. In all cases, the service is
selected by the value loaded into AH register prior to executing the
interrupt. The following gives some of the most important INT 10h text mode
services:

AH  Service               Register Usage
---------------------------------------------------------------------------
 0  Set mode              AL=Mode (see above table)
 2  Set cursor pos'n      DH=Row, DL=Column, BH=Page Number (0)
 3  Get cursor pos'n      BH=pg #, (DH,DL) will contain (Row,Column)
 5  Change active page    AL=Page Number (default active page=0)
 6  Scroll window up      (CH,CL)=(Row,Col) of upper, left corner
                          (DH,DL)=(Row,Col) of lower, right corner
                          AL=# of lines to scroll (0==>whole window)
                          BH=Display Attribute* of incoming lines
 8 Read ASCII/Attrib      BH=Page #
   at cursor position     Returns with AL=ASCII, AH=Attribute    
 9 Write char/attrib      AL=ASCII code of character
   at cursor pos'n        BL=Display Attribute* of character
                          CX=Number of duplicates
                          BH=Page to write to (0)

*Several of these services use the idea of a display attribute. This is an
8-bit number that, for color modes, permits specification of things like
foreground and background color. The following gives the meaning of the
bits for color systems:

      7  6  5  4  3  2  1  0
      B  RB GB BB IF RF GF BF

B = Blink, 1==> character will blink, 0==> no blink
RB = Red Background on/off (1/0)
GB = Green Background on/off (1/0)
BB = Blue Background on/off (1/0)
IF = Intensity Bit of foreground (1=intensity on, 0=intensity off)
RF = Red Foreground on/off (1/0)
GF = Green Foreground on/off (1/0)
BF = Blue Foreground on/off (1/0)

The following gives the available foreground colors, according to the
IF,RF,GF,BF bits:

IF     0     0    0     0    0    0       0     0
RF     0     0    0     0    1    1       1     1
GF     0     0    1     1    0    0       1     1
BF     0     1    0     1    0    1       0     1
Color  black dark dark  dark dark dark    brown white
             blue green cyan red  magenta

IF     1    1     1     1     1     1       1      1
RF     0    0     0     0     1     1       1      1
GF     0    0     1     1     0     0       1      1
BF     0    1     0     1     0     1       0      1
Color  grey light light light light light   yellow bright
            blue  green cyan  red   magenta        white