Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Peter Norton Programmer's Guide - Norton Guide http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]

  A variety of colors is available in every video mode except of course on a
  monochrome display. You may have noticed that among the various modes
  there are substantial differences in the number of colors available. In
  this section, we will describe the color options for the video modes.

  Colors for the video display screens are produced by combinations of four
  elements: three color components--red, green, and blue--plus an intensity,
  or brightness, component. Text and graphics modes use the same colors and
  intensity options, but they combine them in different ways to produce
  their colored displays. The text modes, whose basic unit is a character
  composed of several pixels, use an entire byte to set the color, the
  intensity, and the blinking characteristics of the character and its
  background. In graphics modes, each pixel is represented by a group of 1
  through 8 bits whose value determines the color and brightness of the
  displayed pixel.

  In 16-color text and graphics modes, the four basic color and brightness
  components can be combined in 16 ways. Colors are specified by a group of
  4 bits. Each bit designates whether a particular color component is on or
  off. The result is 16 color combinations that correspond to the 16 4-bit
  binary numbers. (See Figure 4-4.)

  In some video modes, the data in the video buffer consists of 4-bit
  attribute values that correspond exactly to the 16 possible color
  combinations on the screen. In other video modes, the attribute values do
  not directly specify colors. For example, on the EGA, each attribute value
  designates one of 16 palette registers, each of which contains a color
  value. (See Figure 4-5.) It is the palette color values that determine
  the color combinations displayed on the screen.

  Intensity Red       Green    Blue      Binary    Hex       Description
  ------------------------------------------------------------------------------
  0         0         0        0         0000B     00H       Black
  0         0         0        1         0001B     01H       Blue
  0         0         1        0         0010B     02H       Green
  0         0         1        1         0011B     03H       Cyan (blue-green)
  0         1         0        0         0100B     04H       Red
  0         1         0        1         0101B     05H       Magenta
  0         1         1        0         0110B     06H       Brown (or dark
                                                             yellow)
  0         1         1        1         0111B     07H       Light gray (or
                                                             ordinary white)
  1         0         0        0         1000B     08H       Dark gray (black on
                                                             many screens)
  1         0         0        1         1001B     09H       Light blue
  1         0         1        0         1010B     0AH       Light green
  1         0         1        1         1011B     0BH       Light cyan
  1         1         0        0         1100B     0CH       Light red
  1         1         0        1         1101B     0DH       Light magenta
  1         1         1        0         1110B     0EH       Yellow (or light
                                                             yellow)
  1         1         1        1         1111B     0FH       Bright white
  ------------------------------------------------------------------------------

  Figure 4-4.  Default colors available in 16-color text and graphics modes.

  +------------------------------------ +-------------+
  | 0110 1010 1010 0111 0101 0101 1101  |#############|
  |                +--+                 |-------------|
  |                  |                  |#############|
  |                  |                  |-------------|
  |                  |                  |#############|
  |                  |                  |-------------|
  |                  |                  |#############|
  |                  |                  |-------------|    +----------
  |                  +-----------------.| Color value |---.| +--------
  |                                     |-------------|    | | #
  |                                     |#############|    | |
  |                                     |-------------|    | |
  |                                     |#############|    | |
                                        |-------------|
                                        |#############|
             Attribute value in         +-------------+     Color on
                video buffer           Pallette registers    screen

  Figure 4-5.  How EGA colors are specified using palette registers. Each
  attribute value in the video buffer designates a palette register whose
  contents specify a color.

  The use of palettes makes it possible to specify one of a broad range of
  colors using relatively few bits of data in the video buffer. Each of the
  EGA's 16 palette registers, for example, can contain one of 64 different
  6-bit color values. In this way, any 2 of 64 different colors can be used
  in a 2-color EGA video mode, any 4 out of 64 can be used in a 4-color
  mode, and any 16 of 64 can be used in a 16-color mode.

  All IBM video subsystems except the MDA can use palettes to display
  colors. The CGA has three built-in, 4-color palettes for use in 320 x 200,
  4-color mode. The EGA, as we have seen, has a 16-color palette in which
  each color can be selected from a set of 64 colors. The MCGA and the VGA,
  which can display an even wider range of colors, use a separate
  palette-like component, the video digital to analog converter (video DAC),
  to send color signals to the screen.

  The video DAC contains 256 color registers, each of which contains 6-bit
  color values for red, green, and blue. Since there are 64 possible values
  for each of the RGB components, each video DAC color register can contain
  one of 64 x 64 x 64, or 262,144 different color values. That wide range of
  colors can help you display very subtle color shades and contours.

  With the MCGA, the video DAC color registers serve much the same purpose
  as the palette registers do with the EGA. Attribute values in the video
  buffer designate video DAC color registers whose contents specify the
  colors that appear on the screen. Unfortunately, only one MCGA video mode
  can take full advantage of the video DAC's capabilities: 320 x 200,
  256-color mode. Only this video mode uses 8-bit attribute values that can
  specify all 256 of the video DAC's color registers. All remaining video
  modes use attribute values that have no more than 4 bits, so only the
  first 16 video DAC color registers are used.

  The VGA gets around this limitation (and complicates matters somewhat) by
  using a set of 16 palette registers like the EGA's, as well as a set of
  256 video DAC color registers like the MCGA's. An attribute value in the
  video buffer selects one of the 16 palette registers, whose contents
  select one of the 256 video DAC color registers--whose contents "in turn"
  determine the color displayed on the screen. (See Figure 4-6.)

  Specifying colors on an EGA, MCGA, or VGA is clearly more complicated than
  it is on the CGA. To simplify this process, however, the ROM BIOS loads
  the palette registers (on the EGA and VGA) and the video DAC color
  registers (on the MCGA and VGA) with color values that exactly match those
  available on the CGA. If you use CGA-compatible text and graphics modes on
  the newer subsystems and ignore the palette and video DAC registers,
  you'll see the same colors you would on a CGA.

  +--------------------------------------
  | 0110 1010 1010 0111 0101 0101 1101
  |                +--+                            .
  |                  |   +-------------+    |      .      |
  |                  |   |#############|    |      .      |
  |                  |   |-------------|    |-------------|
  |                  |   |#############|    |#############|
  |                  |   |-------------|    |-------------|
  | Attribute value  |   |#############|    |#############|
  | in video buffer  |   |-------------|    |-------------|
  |                  +--.|    Color    |-+  |#############|
  |                      |   register  | |  |-------------|   +---------
  |                      |-------------| |  |  RGB color  |--.| +-------
  |                      |#############| +-.|    value    |   | | #
  |                      |-------------|    |-------------|   | |
                         |#############|    |#############|   | |
                         |-------------|    |-------------|   | |
                         |#############|    |#############|   | |
                         +-------------+    |-------------|
                         Palette registers  |#############|    Color on
                                            |-------------|     screen
                                            |      .      |
                                            |      .      |
                                                   .
                                       Video DAC color registers

  Figure 4-6.  How VGA colors are specified using palette registers and the
  video DAC.

  For this reason it's usually best to ignore the palette and video DAC
  registers when you start developing an application. Once your application
  works properly with the CGA-compatible colors, you can add program code
  that changes the palette and/or the video DAC colors. The ROM BIOS
  provides a complete set of services that let you access the palette and
  video DAC registers. Chapter 9 covers these services in detail.

  In considering color, read each of the remaining sections, which discuss
  important color-related items.

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson