kristofer sweger Home
ANSIPLUS Home


Color Selection and Definition

Esc [!#;#;#;#;#c  Define available colors, palette, blinking

ANSIPLUS manages two sets of colors: the current set displayed by the VGA/EGA controller, and a default set maintained within the ANSIPLUS driver. The Esc [!c ANSIPLUS control sequence defines either of these color schemes.

The standard IBM VGA/EGA color palette has limitations that ANSIPLUS removes. The first limitation is that there are normally only 8 low intensity background colors in text modes, because blinking is enabled in the normal VGA/EGA configuration. Unless told otherwise, ANSIPLUS keeps VGA/EGA hardware blinking disabled, so that all 16 background colors can be used. For those applications that need both blinking and more than 8 background colors, ANSIPLUS provides control sequences that let any of the 16 colors on the screen blink at independent rates, in either text or graphics modes.

The second limitation removed is the color choices themselves. The standard IBM VGA/EGA palette is generated mechanically, with little apparent consideration for the subjective appearance of the colors individually or in combination. The IBM 64-color palette simply consists of all possible combinations of 0, 33, 67 and 100 percent intensities for the red, green and blue CRT cathodes. The 8 low intensity colors (black, red, brown, green, cyan, blue, magenta and light gray) are mixed with white to form 8 high intensity colors, giving a washed out appearance to many of the high intensity colors.

For the ANSIPLUS palette, individual attention has been given to both the 16 colors selected from the EGA palette and to the VGA DAC color intensities of all 256 VGA colors, with the goal being to select colors that are more vivid and provide generally better contrast and appearance when combined. For those with other color preferences, ANSIPLUS provides color control functions and utility programs that assist developing personal or application color schemes. The 16 default ANSIPLUS and OEM/IBM colors (actually, the closest web-friendly approximations of them) are compared in the following table:

ANSIPLUS Color Names and Code Numbers
Color
Number
ANSIPLUS
Color
OEM/IBM
Color
Foreground
Code
Background
Code
0 Black Black 128 192
1 Dark Red Red 129 193
2 Bluish Green Green 130 194
3 Brown Brown 131 195
4 Dark Blue Blue 132 196
5 Purple Magenta 133 197
6 Cyan Cyan 134 198
7 Light Gray Light Gray 135 199
8 Dark Gray Dark Gray 136 200
9 Intense Red Light Red 137 201
10 Intense Green Light Green 138 202
11 Yellow Light Yellow 139 203
12 Sky Blue Light Blue 140 204
13 Pink Light Magenta 141 205
14 Intense Cyan Light Cyan 142 206
15 White White 143 207

The Esc [!c control sequence includes options for setting the current and default colors, the 64 VGA/EGA palette registers (PALs), and the 256 VGA DAC registers, for selecting the PAL registers to use for colors, and for color blinking. Because of all these options, six variations of the Esc [!c control sequence can be used, depending on the number of parameters supplied. Some of these require red, green and blue color intensities (RGB values), which all range from 0 (darkest) to 255 (brightest). The six variations of Esc [!c are:

  1. Zero parameters resets all colors, PALs and DACs to default values:

    Esc [!c Restore the default color scheme
  2. One parameter restores a single color or PAL to either its default value or to the OEM value. The interpretation of the parameter varies for different ranges according to the table following. For example:

    Esc [!5c Reset color 5 to default palette and DAC selection
    Esc [!38c Set color 6 to OEM EGA palette/DAC selection
    Esc [!65c Reset PAL 1 to default DAC values (65=64+1)
    Esc [!130c Reset PAL 2 to OEM EGA DAC color (130=128+2)

    Interpretation of Color Reset Selectors
    Selector
    Meaning
    0 to 15
    Default color 0 to 15 (16 colors)
    16
    Default screen border color
    32 to 47
    OEM color 0 to 15 (16 colors)
    48
    OEM screen border color
    64 to 127
    Default VGA/EGA PAL number 0 to 63 (64 EGA colors)
    128 to 191
    OEM VGA/EGA PAL number 0 to 63 (64 EGA colors)
  3. Two parameters select the PAL code to use for a color. The first parameter selects the color (0-16 for current, 32-48 for default), and the second parameter selects the PAL register (0-63). For example:

    Esc [!4;8c Set color 4 to select PAL 8 until the next mode set
    Esc [!36;8c Set color 4 to select PAL 8 as default (36=32+4)
  4. Three parameters define blink color and duration. The first parameter selects a color (0-16), the second selects the EGA PAL (0-63) to use as the blink color, and the third parameter is the time in milliseconds for a complete blink cycle (100-28000). For example:

    Esc [!1;0;400c Set color 1 to blink black (PAL 0) on a 400 ms cycle
  5. Four parameters define the RGB values for a color, PAL or DAC. The first parameter selects the color (see table below), and the next three define the RGB values:

    Esc [!4;0;0;128c Set color 4 values to 0 red, 0 green, 128 blue using a PAL or DAC of ANSIPLUS’s choice until the next mode set
    Esc [!36;0;0;128c Set color 4 PAL and DAC now and as default (36=32+4)
    Esc [!65;128;0;0c Set PAL/DAC 1 to 128 red, 0 green/blue (65=64+1)
    Esc [!129;128;0;0c Set PAL/DAC 1 as default (129=128+1)
    Esc [!257;128;0;0c Set DAC 1 until next mode set (257=256+1)
    Esc [!513;128;0;0c Set DAC 1 now and as default (513=512+1)
  6. Five parameters define both the PAL and RGB values for a color. The first parameter is the color selector (see table following), the second selects the palette register to use (0-63), and the final three define the RGB color values:

    Esc [!4;8;0;0;128c Set color 4 to 0 red, 0 green and 128 blue using PAL number 8 until next mode set
    Esc [!36;8;0;0;128c Set color 4 to use PAL 8 and the RGB values as default (36=32+4)

    Interpretation of Color Definition Selectors
    Selector
    Meaning
    0 to 15
    Current color 0 to 15 (16 colors)
    16
    Current screen border color
    32 to 47
    Default color 0 to 15 (16 colors)
    48
    Default screen border color
    64 to 127
    Current VGA/EGA PAL number 0 to 63 (64 EGA colors)
    128 to 191
    Default VGA/EGA PAL number 0 to 63 (64 EGA colors)
    256 to 511
    Current VGA DAC color 0 to 255 (256 VGA colors)
    512 to 767
    Default VGA DAC color 0 to 255 (256 VGA colors)

Esc [#;... #m  Select output color attributes

The MS-DOS ANSI.sys driver is aware of 8 foreground and 8 background colors. It also provides control over intensity, underline, blinking and reverse video. All the original ANSI.sys graphics renditions are supported by ANSIPLUS (see the table at the end of this section).

However, to use 16 foreground colors with the ANSI.sys driver, programs have to break color codes apart and set both intensity and color. For 16 background colors, the same thing has to be done using "blink." A further complication is that the only way to reset either blink or intensity is to reset the foreground to gray and background to black with Esc [0m.

ANSIPLUS Extended Color Codes
Codes
Meaning
128 to 143 Foreground colors 0 to 15
192 to 207
Background colors 0 to 15
256 to 511
Foreground colors 0 to 255
512 to 767
Background colors 0 to 255 or mixed background colors

ANSIPLUS eliminates these complications by allowing several additional control codes for colors. In text modes, foreground and background colors are chosen directly from a 16 color palette. When using a VGA or EGA display in a sixteen color graphics mode, ANSIPLUS allows mixing any two colors to form a composite background color, for a total of 136 mixed and unmixed background color combinations, so foreground colors are chosen from 16 possibilities, and background colors from either 16 or 256 possibilities. In 256-color graphics modes, the foreground and background colors are selected from a 256 color palette. A summary of the ANSIPLUS extended color codes is shown in the adjacent table. The 16 ANSIPLUS foreground and background color codes are related to their names in a table above.

In addition to the color code extensions, three parameter values have slightly changed meanings in ANSIPLUS from the ANSI.sys driver, and several parameters have been added for special applications. First, the changed meanings:

The following parameter values have been added for special applications:

DOS ANSI.sys Color Selection Escape Sequences
Escape Seq. Color Selection
Esc [0m Reset color attributes to default
Esc [1m Intense foreground
Esc [4m Underline (monochrome text modes only)
Esc [5m Blink (Intense background)
Esc [7m Reverse video
Esc [8m Invisible video
   
Esc [30m Black foreground
Esc [31m Red foreground
Esc [32m Green foreground
Esc [33m Brown foreground
Esc [34m Blue foreground
Esc [35m Purple/magenta foreground
Esc [36m Cyan foreground
Esc [37m Light gray foreground
   
Esc [40m Black background
Esc [41m Red background
Esc [42m Green background
Esc [43m Brown background
Esc [44m Blue background
Esc [45m Pink/magenta background
Esc [46m Cyan background
Esc [47m Light gray background

© Copyright 2000-2007, Kristofer Sweger. All rights reserved.
Rev. 10/16/07