CGA Palette

From ModdingWiki
Jump to navigation Jump to search
CGA Palette
Format typePalette
HardwareCGA
Colour depth2-bit
Number of colours4
GamesNone

CGA has three resolutions it can handle, and the lower the resolution, the higher the amount of usable colours. The lowest-resolution mode, 160×100, can use a range of 16 colours identical to the default EGA palette. The highest resolution, 640×200, is strictly 1-bit, with black as background and any choice from the EGA palette as second colour. Since, palette-wise, there is little else to say about those two, this article will focus only on the two bit per pixel 320×200 mode (BIOS mode 4 and 5), which uses colour palettes with four colours.

Note that this is not really a file format. This article outlines the general principles used by the CGA hardware to result in a colour palette, but how this data is stored varies; in most programs, it is just hardcoded. Given its structure, the full palette information only takes 7 bits, meaning it can fit inside a single byte. However, file formats like PCX that support CGA will have their own specific way of storing it.

Basic principles

The colour handling in CGA 320×200 mode is a bit different from how colour palettes usually work. Rather than a list of colours, the CGA hardware has a set of predetermined three-colour palettes to use, together with an explicitly set background colour for palette index 0, which can be any of the 16 available EGA colours.

Status bits

Normally, the palette is defined by two status bits fed into the hardware; one bit determines which of two pre-set palettes to use, the other determines whether the colours on the palette are brighter or darker. However, there is a third bit flag, meant to switch between the coloured 'mode 4' and the monochrome 'mode 5'. Monochrome mode is meant to give a more uniform gray fade on monochrome monitors, but due to the fact this still produces actual colours internally, using monochrome mode on a colour monitor creates an unofficial 'palette 2'.

Name Description
ColorBurst Technically indicates the presence of colour on the palette, but disabling the bit actually causes a switch to Mode 5, which, on colour monitors, gives access to the extra unofficial palette 2.
Palette Choice between palette 0 and palette 1. If ColorBurst is disabled, this bit is ignored.
Intensity Choice between dark (0) or bright (1) version of the palette.

Final palettes

The full range of colours available in CGA is a set of 16 which corresponds to the default EGA palette. The possible 2-bit CGA palettes are comprised of the following indices from that palette. The Intensity modifier simply increases all indices by 8 to get the bright equivalents of these colours.

Palette # Dark colours Bright colours Description
0 [02,04,06] [10,12,14] Mode 4, palette 0
1 [03,05,07] [11,13,15] Mode 4, palette 1
2 [03,04,07] [11,12,15] The unofficial Mode 5 palette, accessed by disabling ColorBurst.

As mentioned, these colours end up on indices 1, 2 and 3 of the palette. Index 0, the background colour, can be any of the colours from the full 16-colour palette. In most cases, it is left black.