PC Images
The PC has no single screen: each graphics adapter defines its own modes, colours and memory layout. CGA gave a handful of low-colour modes, EGA added 16 colours across four bit-planes, and VGA brought the flat 256-colour mode 13h and a programmable palette. These pages describe how the picture is stored in each.
Overview
Graphics on the PC are set by whichever adapter is fitted, and each newer card is a superset of the last. A mode number passed to the BIOS selects a resolution, colour depth and memory layout. Two things vary between modes: how many colours a pixel can be, and how those pixels are packed into the video memory that the display reads. The two memory models that matter are planar, where the bits of a pixel are spread across separate parallel banks, and linear (chunky), where each pixel is one whole byte in a single run of memory.
| Adapter | Year | Best graphics | Colours |
|---|---|---|---|
| CGA | 1981 | 320×200 / 640×200 | 4 / 2 |
| EGA | 1984 | 640×350 | 16 of 64 |
| VGA | 1987 | 320×200 / 640×480 | 256 of 262144 / 16 |
CGA
The Color Graphics Adapter has 16 KB of video memory at segment B800:0000. Its two graphics modes are both 200 lines tall. The 320×200 mode packs four pixels into each byte, two bits per pixel, giving four colours drawn from a fixed palette; the 640×200 mode packs eight pixels per byte, one bit each, giving two colours.
CGA memory is interleaved by scanline parity. The bytes for all the even scanlines sit in the first 8 KB starting at B800:0000, and the bytes for all the odd scanlines sit in the second 8 KB starting at B800:2000. So the address of a row depends on whether it is even or odd, and consecutive rows on screen are 0x2000 apart, not one line-length apart.
| Property | 320×200 | 640×200 |
|---|---|---|
| Pixels per byte | 4 | 8 |
| Bits per pixel | 2 | 1 |
| Colours | 4 (fixed palette) | 2 |
| Even lines at | B800:0000 | |
| Odd lines at | B800:2000 | |
The four-colour mode does not let a program pick any four colours. It offers a small set of fixed palettes, typically cyan / magenta / white plus a chosen background, or green / red / brown plus a background, a limit that gave CGA art its characteristic look.
EGA
The Enhanced Graphics Adapter reaches 640×350 in 16 colours, and also does 320×200 in 16 colours. Its memory sits at segment A000:0000 and is organised as four parallel bit-planes. A 16-colour pixel needs four bits, and EGA stores one of those bits in each plane at the same offset. So a single byte address holds eight pixels' worth of one bit-plane, and the four planes together supply the four bits of each of those eight pixels.
Because all four planes share one address range, the program writes them through latches and mask registers on the adapter rather than four separate memory windows. The 16 displayable colours are chosen from a wider set of 64 by programming the palette registers, so the four-bit pixel value is an index into a small colour table.
| Property | Value |
|---|---|
| Resolutions | 320×200, 640×200, 640×350 |
| Colours on screen | 16 |
| Colours available | 64 |
| Memory model | Planar, 4 bit-planes |
| Segment | A000:0000 |
| Bits per plane byte | 8 pixels, 1 bit each |
VGA
The Video Graphics Array added the mode games are best known for: mode 13h, 320×200 in 256 colours with a linear chunky layout. Every pixel is one byte, and the bytes run left to right, top to bottom in a single flat block at A000:0000. A pixel at column x, row y is the byte at offset y * 320 + x. That directness, one write per pixel with no plane juggling, is what made mode 13h the standard target for DOS action games.
VGA also has a planar 640×480 16-colour mode (mode 12h), laid out like EGA across four bit-planes at A000:0000, used for higher-resolution work. The 256 colours of mode 13h are each an index into the palette DAC described below, so the byte written is not a colour but a slot number.
| Property | Mode 13h | Mode 12h |
|---|---|---|
| Resolution | 320×200 | 640×480 |
| Colours | 256 | 16 |
| Memory model | Linear (chunky) | Planar, 4 planes |
| Bytes per pixel | 1 | ½ bit per plane |
| Segment | A000:0000 | A000:0000 |
| Offset of (x, y) | y * 320 + x | plane-based |
Mode-X
Mode-X is an undocumented VGA setup, not a BIOS mode, made by reprogramming the adapter after entering mode 13h. The common form is 320×240 with square pixels. It trades the simple chunky layout for a planar one: the four bit-planes are used to hold every fourth pixel, so plane 0 holds columns 0, 4, 8…, plane 1 holds columns 1, 5, 9, and so on.
The cost is more awkward pixel writes, since the program must select the right plane before each column. The gain is that VGA's full 256 KB becomes usable, not just the 64 KB a chunky mode can address, which leaves room for several full screens of memory. That extra room is what makes hardware page flipping and off-screen composition possible, covered on the sprites page.
The palette and DAC
In 256-colour VGA modes the pixel byte is an index, 0 to 255, into a hardware colour table in the DAC (digital-to-analogue converter). Each of the 256 slots holds a red, green and blue value of six bits each, so a colour is 18-bit, giving 262144 possible shades. Changing a slot repaints every pixel using it at once, which is how palette fades and cycling effects work without touching the image.
The DAC is programmed through two I/O ports. Write the slot number to port 3C8h, then write three bytes, red then green then blue, to port 3C9h; the internal pointer advances after every third write, so a whole palette can be sent as one run of writes.
| Port | Role |
|---|---|
| 3C8h | Write the palette slot number to set next. |
| 3C9h | Write R, then G, then B (6 bits each, 0–63). |
| 3C7h | Write the slot number to read a colour back. |
Modes table
The common DOS-era graphics modes, with their resolution, colour count, memory model and the segment their video memory occupies.
| Mode | Adapter | Resolution | Colours | Memory model | Segment |
|---|---|---|---|---|---|
| 04h | CGA | 320×200 | 4 | Chunky, 2 bpp, line-interleaved | B800:0000 |
| 06h | CGA | 640×200 | 2 | Chunky, 1 bpp, line-interleaved | B800:0000 |
| 0Dh | EGA | 320×200 | 16 | Planar, 4 planes | A000:0000 |
| 10h | EGA | 640×350 | 16 | Planar, 4 planes | A000:0000 |
| 12h | VGA | 640×480 | 16 | Planar, 4 planes | A000:0000 |
| 13h | VGA | 320×200 | 256 | Linear (chunky), 1 byte/pixel | A000:0000 |
| Mode-X | VGA | 320×240 | 256 | Planar, 4 planes | A000:0000 |