EGA Palettes

Mixing colors in EGA (Enhanced Graphics Adapter) is similar to the VGA mixing described in “VGA Palettes”, but there are fewer levels of intensity for the red, green, and blue (RGB) components. In the modes that offer 64 colors, the RGB values include two bits and can range in value from 0–3. The long integer that defines a color value looks like this:

The bits marked 0 should be zeros; the bits marked ? are ignored. EGA color values are defined this way to maintain compatibility with VGA color values.

To form a pure red color value, use the constant 0x00000030L. For cyan (blue plus green), use 0x00303000L. The RGB macro defined above for VGA color mixing can be used as is, or you can modify it for EGA monitors:

#define EGARGB( r, g, b ) (0x303030L & ((long)(b) << 20 | (g) << 12 | (r << 4)))

In this macro, you would pass values in the range 0–3 instead of 0–63.

For an example program that remaps a color index to a color value, see YELLOW.C in “VGA Palettes”.