CS-460/560, Wk-2b
Spring, 2000
R. Eckert


Tektronix Direct View Storage Tube (first "inexpensive" graphics
display device -- late 60s)--

   Two electron guns: writing gun, flood gun
   Image stored as charges on grid behind screen.
   Whenever writing gun beam hits grid, electrons knocked out,
      leaves + charges behind
   Image stored as patterns of + charges on grid
   Flood gun supplies continuous source of unfocused electrons
   They migrate toward the + charges on grid
   Pass through grid and strike screen phosphors --> lighted dots
   Electrons continue to hit + charges ==> continuous light
   (Up to an hour)
   Erasure of image--
      1. Plus charge applied to entire grid
      Attract electrons to entire grid --> entire screen flashes
      (Image gone)
      2. Minus charge applied to entire grid
      Provide electrons that can be knocked out by writing gun
      Ready to draw next image with writing gun.
   Advantages to DVST--
      No refresh needed ==> Unlimited image complexity possible
      High resolution
      Crisp lines
      Low cost (no fast refresh circuitry needed)
   Disadvantages to DVST--
      No selective erase (whole image or nothing)
      No animation
      Low light output ==> poor contrast, must use in subdued light
      No color
      No area fill

Interlaced Displays--

   All even screen lines scanned first, then all odd lines.
   Typically 1/60 second each (standard TV refresh rate)
   ==> Same image presented twice in 1/30 second
   Image changed at half non-interlaced frequency
   ==> Less demands on image generation system
   Can be less expensive
   30 Hz is borderline for flicker
   Lower quality image (seeing half the image at a time)


Each pixel on screen composed of three different phosphors, glowing
red, green, and blue. Three electron guns shoot their beams through a
shadow mask so beams hit the sensitive phosphors. Intensity of three
beams determines how bright each phosphor glows. Human eye detects an
additive mix of colors; e.g., Red, Green, Blue at full intensitiy is
perceived as white.

Direct color systems--

   The frame buffer is divided into bit planes. A bit plane contributes
   one bit to the color each pixel. If the resolution of the screen is
   R x S, a bit plane is an R x S x 1 bit memory. Bit planes are
   organized into three color channels. As the raster scan occurs, the
   contents of the bit planes of a color channel provide the red,
   blue, and green intensity values fed to the each color electron gun
   for each pixel on the screen. A system with N bit planes per color
   channel will have 2^N shades of red, 2^N shades of green, and 2^N
   shades of blue, for a total of 2^3N different colors that can be
   displayed simultaneously.

True color systems--

   Direct color systems with N=8 ==> 2^24 = 16,777,216 different
   colors possible for each pixel on the screen. This is more
   colors than is discernable by the human eye.

Indirect color systems--

   Values stored in the bit planes are used as indices into one or more
   color lookup tables (CLUT) that store the Red, Green, and Blue
   intensities of each pixel. The number of bit planes determines the
   number of colors displayable simultaneously on the screen. The width
   of the CLUT determines the number of possible colors. If there are N
   bit planes per color channel and each set of bit planes indexes a
   CLUT of width W, the number of entries in each CLUT is 2^N, and we
   say that there 2^3N colors displayable, chosen from a total of 2^3W
   possible colors. Each set of 2^3N colors is often called a palette.
   (The CLUTs are also often called palette registers.)

Advantages to indirect color--

   If the CLUTs are very wide (large W) there is a huge number of
   POSSIBLE colors. Keeping the number of bit planes (N) modest means
   that the video RAM is not excessive in size. This also means that
   the number of entries in the CLUTs is also modest. So we get lots of
   POSSIBLE colors with relatively little memory expense. The down side
   is that ultimately the number of colors displayable at one time on
   the screen is limited by the number of bit planes. So, while a large
   number of colors might be POSSIBLE, only a small fraction of them
   can be used at a time. For graphics applications, this means setting
   up the CLUTs so that the values correspond to the most frequently
   occurring colors in the scene. Different scenes might require
   different combinations of colors in the CLUTs. 

   In multitasking systems like Windows, indirect color usually means 
   that the foreground task (window) sets up the CLUT (also called 
   the system palette) as it desires. This may leave background windows 
   with limited and/or incorrect colors. 

   Another benefit of indirect color is that entire scene colors can be
   changed rapidly by changing the CLUTs. This can be used effectively
   in certain types of animation.

Color Graphics on PC Compatible Computers--

   Graphics capabilities such as resolution and numbers of colors
   depend on which display adapter (video card) is in the system.
   Common ones: CGA (Color Graphics Adapter, EGA (Enhanced Graphics
   Adapter), VGA (Video Graphics Array), and many different types of
   SVGA (Super VGA) boards. Each display adapter can function in many
   different text and graphics modes.

   Each graphics mode and adapter work differently. So if you're trying
   to access pixels directly (for speed--always important in computer
   graphics), the techniques used will vary widely. Fortunately, most
   video adapters are complient with Video Electronics Standard
   Association (VESA) standards, so that VESA SVGA modes can be
   programmed with relative ease (often at the expense of performance).

Setting the Graphics Mode of Operation--

   The easiest way to set a PC graphics mode is to use the BIOS / VGA 
   BIOS Extension via the video interrupt 0x10. Set AH register to 0 
   (set mode) and AL to the desired mode. Then make the call to INT 10h.

   INT 10 can be used for many other graphics/video functions.

CGA Graphics Modes--

     320 X 200 X 4 colors ==> 2 bits/pixel; Video RAM at 0xB800:0000;
        Set up for interlaced displays (even line block, odd line
     640 X 200 X 2 "colors" ==> 1 bit/pixel.
     For these modes, to set a pixel directly, program must:
        1. Determine byte that contains pixel at screen loc (x,y).
        2. Determine the bit(s) in the byte that control the pixel.
        3. Write to that byte, changing only bit(s) from 2.

EGA Graphics Modes--

     CGA + 640 X 200 X 16 colors, 640 X 350 X 16 colors; VRAM at
     0xA000:0000; Four bit planes ==> 16 colors; Each pixel is accessed
     with one bit in VRAM. The bit can be written to the bit planes. To
     paint a pixel, you must set bits in the position in the bit planes
     that control that pixel using two special EGA registers--the Map
     Mask Register (MMR, 4 bits wide) and the Bit Map Register (BMR, 8
     bits wide). The MMR mask determines which of the 4 bit planes is
     written to; the BMR mask determines which of 8 possible bit plane
     positions is(are) written to. Specifically, to set the pixel at
     screen location (x,y) to a given color (simplified):

        1. Determine offset of byte that contains pixel at screen
           location (x,y)  [offset = (WIDTH * y + x) / 8].
        2. Determine the bit position within that byte
           [position = WIDTH * y +x) % 8].
        3. Set corresponding bit in the BMR ==> selects correct one of
           8 location in the 4 planes that are controlled by the byte
           from step 1--i.e., selects one pixel from eight possible.
        4. Set the 4-bit color in the MMR.
        5. Write a 1 to bit position (from step 2) at the address (from
           step 1), offset from 0xA000:0000.
        6. This sets the bits in the position within the bit planes
           that control the pixel at (x,y) to the desired color.

     Accessing the MMR and the BMR--
        To write color c to MMR:
           outportb (0x3C4,2);  /* select MMR from its reg. group */
           outportb (0x3C5,c);  /* write color c to selected reg. */
        To write mask value m to BMR:
           outportb (0x3CE,8);  /* select BMR from its reg. group */
           outportb (0x3CF,m);  /* write mask m to selected reg.  */

     There are several other EGA modes of operation.

     Also, EGA is actually an indirect color system--
        The 4-bit output of bit planes is an index into a 6-bit CLUT
        ==> 2^6 = 64 possible colors
        Organization (bit positions) of a CLUT word:  RH GH BH RL GL BL

     Changing EGA CLUT entries using BIOS:
        AL = 0, AH = 0x10, BL = CLUT address to be changed (0-63),
        BH = new color (0-15), invoke interrupt 0x10 using int86().

VGA Graphics Modes--

     EGA + 640 X 480 X 16 colors--access as with EGA

     320 X 200 X 256 colors (mode 13h)--
       One byte of VRAM controls one pixel.
       To set pixel at (x,y) to a given color:
         Set a segment register (e.g., ES) to start of video RAM, 0A000h;
         Compute the offset = 320 * y + x
         Load offset into a pointer register (e.g., SI)
         Set the pixel by loading the location with a color (byte)--
            mov ES:[SI], color

     Mode 13h color control is indirect through a 256 X 18 CLUT.
     The color written to the VRAM is a byte-size index into this table.
     Entries in table: 6 bits for Red, 6 for Green, 6 for Blue.
     To change an entry in the VGA CLUT, use the video interrupt (10h):
        AH = 10h, AL = 10H, BX = CLUT position to be changed (0-255)
        DH, CH, CL = {Red, Green, Blue intensity: 0-63 each}

VESA Super VGA BIOS Extgension (VBE)--Using high resolution, high color
SVGA display modes in a standard way. 

See, for example:
  Super VGA/VESA Programming Notes
To get the "official" VESA 1.2 and VESA 2.4 Specifications, you can download vesasp12.zip and vesa24-2.zip from the following site:
 ftp site for vesasp12.zip and vesa24-2.zip files--Complete VESA Specs