Color Graphics Adapter
The Color Graphics Adapter (CGA), introduced in 1981, was IBM's first color graphics card, and the first color computer display standard, for the PC. The standard IBM CGA graphics card was equipped with 16 kilobytes of video memory. The CGA card featured several graphics and text modes with a resolution of up to 640×200 and up to 16 colors (albeit not at that resolution). It is commonly believed that the CGA could only display a maximum of 4 colors at a resolution of 320×200. However, this is not correct: There were several ways — some official, some not — by which more colors could be displayed, even for graphics display purposes. These additional modes and "tricks" were however rather seldom used — even few programmers were aware of their existence. In the following sections, the commonly used modes are described first and the said rarely used modes are discussed further below.
The CGA color palette
Full CGA color palette | ||
0 - black | 8 - (dark) gray | |
1 - blue | 9 - bright blue | |
2 - green | 10 - bright green | |
3 - cyan | 11 - bright cyan | |
4 - red | 12 - bright red | |
5 - magenta | 13 - bright magenta | |
6 - brown (orange) | 14 - yellow | |
7 - white (light gray) | 15 - bright white | |
these colors may be off – corrections are welcome |
Before moving on to the actual display modes however, a brief overview of the CGA color palette is in order:
The CGA card worked with CRT RGB color monitors. Such monitors consisted of a cathode ray tube with three rays: One for red, one for green and one for blue color. (The electron rays were not actually colored, but aligned to aim at respective colored holes, one for each dot and color, in the monitor's dot matrix.)
The CGA's color palette was geared towards RGB CRTs, making it very simple to technologically achieve display of its colors on these monitors:
It consisted of 16 colors. Black (not strictly a color) simply meant all rays were (almost) off. The colors red, green and blue directly corresponded to the three available cathode rays of the monitor. Cyan was a mix between the blue and green rays, magenta was a mix between blue and red and the third orange-brownish color was a mix between green and red. White (or light gray) was a mix between all three rays (see RGB color model). The remaining 8 colors were simply achieved by turning on an "intensifier" bit, which made all the rays brighter. Thus there were 8 brighter versions for each of the initial 8 colors. The dark gray color wasn't distinguishable from black with many monitors, because making no rays brighter still equals no rays — for dark gray to work properly, there had to be remainder rays even with black, which could then be intensified to gray.
The CGA's "RGB plus intensity bit" design was also called RGBI.
Standard text modes
There were two text modes offered by CGA:
- The first was for 40×25 characters in up to 16 colors. Each of these characters was a pattern of 8×8 dots. The effective screen resolution in this mode was 320×200 pixels (a pixel aspect ratio of 1.33:1). This number is arrived at through calculating character width (8 pixels) by columns of text (40) and character height (8 pixels) by lines of text (25). However, the individual pixels could not be addressed independently in this mode. The choice of patterns for any given row/column location on the screen was thus limited to one of the 256 available ASCII characters. (Ironically, the upper 128 characters could be redefined to a user-definable font, but would only be recognized by the BIOS when printing text in graphics modes only. Thus, the font in actual text mode is fixed and cannot be changed.) In terms of colour use, this mode allowed for each character to have a foreground and a background colour, both of which could be freely chosen from the entire CGA palette (see table). So for example red on yellow text could be used for one character, white on black for the next and cyan on gray for yet another. Enough video RAM was present to allow for 8 different text pages in this mode.
- The second text mode allowed 80×25 characters in up to 16 colors. For this mode, too, the characters consisted of 8×8 dot patterns, achieved by using a decidedly non-square aspect ratio (pixels had an aspect ratio of 2.66:1, making them "skinny"). The effective screen resolution of this mode was 640×200 pixels. This number is arrived at through calculating character width (8 pixels) by columns of text (80) and character height (8 pixels) by lines of text (25). Again, being a text mode, the individual pixels used to make up the screen could not be individually addressed in this mode. The 80×25 mode had access to all 16 colors just as the 40×25 mode could. Enough video RAM was present to allow for 4 different text pages in this mode.
Standard graphics modes
Fixed CGA color palette #1 | ||
default | 5 - magenta | |
3 - cyan | 7 - white (light gray) | |
Fixed CGA color palette #2 | ||
default | 4 - red | |
2 - green | 6 - brown (orange) | |
these colors may be off – corrections are welcome |
There were two commonly used graphics modes offered by CGA:
- The first allowed for 320×200 pixels, which was the same overall resolution as the 40×25 text mode. In this graphics mode however, each and every pixel could be addressed independently. The tradeoff was a limitation in the colors that could be displayed: In this mode, only 4 colors (out of CGA's palette of 16) could be displayed at a time. These four colors, however, could not be freely chosen: There were only two official (see below for the third) fixed palettes that could be used in this graphics mode:
- The first consisted of magenta, cyan, and white, plus background color (black by default).
- The second consisted of red, green, and brown, plus background color (black by default).
- The second graphics mode allowed for 640×200 pixels, which was the same overall resolution as the 80×25 text mode. Again, in this graphics mode, all pixels could be addressed seperately. Yet once more, improvement came at a cost in that the mode was a monochrome one, offering only black and white as "colors" (but could be changed; see below). With an aspect ratio of 2.33:1, the pixels were heavily rectangular, which absolutely always had to be taken into account when using this mode.
The composite video modes
Little known to many was an additional 160×200 graphics mode, which could utilize 16 different colors (not the same color table as the CGA color set, but similar; a table will be provided in the future). This mode however only worked with the RCA jack composite video output. This port, which existed on original IBM CGA cards and was optional on clone cards, allowed the user to connect a TV set or composite color monitor to the computer. (Incidentally, it was the possibility of connecting a TV set to the PC that made IBM choose the original clockspeed of 4.77 MHz for the PC/XT.)
However, CGA's composite color mode was rarely utilized in software. There was no BIOS support for this mode at all, which led to poor programmer adoption. Also, most users preferred keep their PC connected to a monitor, because the only modes that could be displayed in color via composite video were composite color mode, 40-column text mode, and 320×200 graphics mode. Finally, the IBM PC was primarily viewed as a business computer, so the number of television sets -- a display device found in the home, not a commercial business -- actually connected to the IBM PC was very low. As a result of the above factors, only a handful of software titles were made that used the 160×200 graphics mode, most of them games.
Further graphics modes and improvements
However, there were still quite a few official and unofficial features that could be exploited to achieve better graphics on the actual computer monitor:
- In 320×200 graphics mode, the background color, which defaulted to black on mode initialization, could be changed to any of the other 15 colors of the CGA palette. This allowed for some variation as well as literally "flashy" effects as the background color could be changed without having to redraw the screen.
- In addition to this, the border color (the color displayed outside the regular display area) could be changed from its usual black to any of the other 15 colors.
- In 640×200 graphics mode, both colors could be changed; for example, one could have blue and orange-brown as the displayed colors instead of black and white.
- A third 320x200 4-color palette available was achieved by enabling the monochrome bit while in color graphics mode; this switched the current graphics palette to red, cyan, and white (and the background color).
- Through very exact timing, it was possible to switch to another palette while the screen content was still being drawn. Using this method, the screen could display more than 4 colors as 2 palettes (or more) would be combined (albeit only in different horizontal areas of the display).
Examples of this palette switching and of other graphics tweaking tricks could be found in several games. Again, most software titles didn't avail of these possibilities, but there were a few impressive (at the time) exceptions. Some of these above tweaks could even be combined.
The 160×100 16 color mode
One of the most outlandish features however must be the CGA card's lowest resolution graphics mode, which offered 160 by 100 individually addressable pixels at 16 colors, to which the entire palette was available without limitation.
In technical terms however, this mode wasn't a graphics mode, but rather a tweak of the 80×25 text mode:
To start with, the character cell height register was changed to display only 2 lines per character cell instead of the normal number of 8 lines. This quadrupled the number of text rows displayed from 25 to 100. These "tightly squeezed" text characters were not full characters but instead had their top two lines of pixels displayed before moving on to the next row.
To understand the next step it is important to recall that in 16 color text mode each character would have two colors defined for it: The foreground and the background color. As explained above, a user might have green on black text for one character and blue on brown for the next.
Now there existed a character within the character table — character 221 in the extended ASCII character set — which consisted of a box occupying the left half of the character matrix. It looked like this: . Now because each character could be assigned different foreground and background colors, this very same single text character could be colored (for example) cyan on the left (foreground color) and magenta on the right (background color), like so: File:Half-block.character.cyan.magenta.gif. This could also be reversed without changing the actual character, just by swapping the fore- and background colors: File:Half-block.character.magenta.cyan.gif. Finally, because each and every text character on the screen could have different fore- and background colors, it becomes clear that using the character 221, every half of every character matrix (box) could be treated like an individual pixel. Through this technique, 2 times 80, ie. 160 horizontal pixels could be made available per each line. As all the lines were highly compressed and their constituent characters twice as wide as high, sort of splitting each of these "wide" characters vertically (using the above technique) would yield near square pixels: Thus, 160×100 pixels at 16 colors would have been made available.
Alert readers might have noticed that a near identical character to character 221 existed: character 222 occupied the right half and looked like this: . The same effect described above could be achieved by using the character 222 — the only difference would be that the foreground and background colors for each pixel would have needed to be set the other way around. (Note that these characters are actually inline pictures in this text, to ensure best current browser compatibility. While the characters correspond to Unicode characters 258C and 2590, there are still too many browsers who display inline .gifs more reliable than these characters.)
While this may seem a very roundabout way of achieving 16 color graphics display, it worked quite well and, although no details were given as to how to achieve it, was mentioned in IBM's official hardware documentation.
To top things off, even more detail could be achieved in the 160×100 "graphics" mode by using yet other than the aforesaid characters, thus combining ASCII art with the aforesaid technique.
Links to several screenshots from this graphics mode (with use of other characters) are listed under "External links" below.
Summary of color capabilities
As we have seen, the Color Graphics Adapter featured only one 4-color mode — the 320×200 mode.
It did however feature four 16-color modes: the 40×25 and 80×25 text modes, the 160×200 composite graphics mode and the 160×100 text/graphics mode.
(The claim that CGA was only capable of displaying up to 4 colors is thus disproved.)
Bugs and Errata
CGA's most noticable hardware bug was the issue of snow in 80x25 text mode. Due to a design issue, the display RAM on the original IBM CGA card was not dual-ported; this resulted in random "snow" being displayed if display memory was being written to by the CPU at the same time it was being read by the display hardware. This bug was fixed by most third-party clone CGA cards, but still existed in some iterations (such as the AT&T PC 6300 display adapter).
Another annoyance, at least for programmers, was the fact that CGA display memory in graphics modes was arranged in an interlaced fashion. Normally, video memory is arranged linearly, with the next row of display data corresponding to the next row of displayed pixels. But on CGA, the next row of display data moved two rows down. So, filling CGA memory from start to finish, you would find rows 0, 2, 4, 6, 8, 10, etc. being filled, and then as you started filling the last half of CGA RAM you would see rows 1, 3, 5, 7, 9, etc. being filled. This added annoying extra calculation steps to most graphics operations in CGA graphics modes (as compared to other traditional graphics modes on other computers before and since).
Competing adapters
There were two commonly available competing display adapters:
- For business and wordprocessing use, IBM had launched its Monochrome Display Adapter (MDA) at the same time as their CGA. Again, the MDA produced significantly sharper text display in 80-column mode: It rendered characters in a box of 9×14 pixels, of which 7×11 made out the character itself (the other pixels being used for space between character columns and lines). This was clearly superior than the CGA's 8×8 dots text character matrix. Because of this and because of the CGA's higher price at the time, MDA was often preferred for business use.
- In 1982, the non-IBM Hercules Graphics Card (also HGC) was introduced. It offered two modes: an MDA compatible high resolution text mode and a monochrome graphics mode. Its graphics mode was black and white at a resolution of 720×348 pixels. This resolution was better than even the highest b/w resolution CGA cards could offer. Thus, even without a color capability of any kind, the Hercules adapter's offer of good (for its time) monochrome graphics without sacrificing MDA-equivalent text quality made it a very desirable choice for many. In addition, there were emulator drivers that allowed the Hercules card to display the standard CGA modes as well (albeit reduced to black and white). The HGC thus outsold both CGA and MDA adapters, and despite no support or standardization by IBM quickly became a de-facto standard.
External links
- ZiffDavis-Net site with info on old display adapters, including CGA
(Note: Inaccurately quotes Hercules cards as having offered 4 colors.) - Comprehensive FAQ on old display adapters (apparently a Usenet archive)
- IBM PC-Compatible CGA Video Reference — includes technical details
- Life Before Demos — page with detailed info on CGA modes, including the rarer ones
See heading "Low Resolution equals More Color" for info on the 160×200 composite 16 color mode. - Explanation of the 16 color 160×100 CGA mode (also on the Life Before Demos page)
- 16 color 160×100 CGA mode screenshot #1
- 16 color 160×100 CGA mode screenshot #2
- 16 color 160×100 CGA mode screenshot #3
See also
This article is based on material taken from the Free On-line Dictionary of Computing prior to 1 November 2008 and incorporated under the "relicensing" terms of the GFDL, version 1.3 or later. The article has however since been largely rewritten.