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.

PC Images

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.

AdapterYearBest graphicsColours
CGA1981320×200 / 640×2004 / 2
EGA1984640×35016 of 64
VGA1987320×200 / 640×480256 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.

Property320×200640×200
Pixels per byte48
Bits per pixel21
Colours4 (fixed palette)2
Even lines atB800:0000
Odd lines atB800: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.

PropertyValue
Resolutions320×200, 640×200, 640×350
Colours on screen16
Colours available64
Memory modelPlanar, 4 bit-planes
SegmentA000:0000
Bits per plane byte8 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.

PropertyMode 13hMode 12h
Resolution320×200640×480
Colours25616
Memory modelLinear (chunky)Planar, 4 planes
Bytes per pixel1½ bit per plane
SegmentA000:0000A000:0000
Offset of (x, y)y * 320 + xplane-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.

PortRole
3C8hWrite the palette slot number to set next.
3C9hWrite R, then G, then B (6 bits each, 0–63).
3C7hWrite 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.

ModeAdapterResolutionColoursMemory modelSegment
04hCGA320×2004Chunky, 2 bpp, line-interleavedB800:0000
06hCGA640×2002Chunky, 1 bpp, line-interleavedB800:0000
0DhEGA320×20016Planar, 4 planesA000:0000
10hEGA640×35016Planar, 4 planesA000:0000
12hVGA640×48016Planar, 4 planesA000:0000
13hVGA320×200256Linear (chunky), 1 byte/pixelA000:0000
Mode-XVGA320×240256Planar, 4 planesA000:0000