RasterCore

Mode 13h: The Golden Age of PC Graphics

:: SysOp

64,000 Pixels of Freedom

In 1987, IBM introduced the PS/2 line of computers, and with them, the VGA (Video Graphics Array) standard. While VGA supported high-resolution business modes (like 640x480 with 16 colors), it included one specific mode intended for games. It was technically “Mode 19” in the BIOS list, but every programmer knew it by its hexadecimal interrupt number: Mode 13h.

Mode 13h offered a resolution of 320x200 pixels with 256 colors. But its popularity wasn’t just about the colors—it was about the memory layout. For the first time on the PC, graphics memory was Linear.

The Nightmare of Planes vs. The Joy of Linear

To understand why Mode 13h was such a relief, you have to look at what came before: EGA. In EGA (and standard VGA 16-color modes), video memory was “Planar.” To write a pixel, you had to:

  1. Select a “Bit Plane” via an I/O port.
  2. Read a byte from memory (to preserve the other 7 pixels in that byte).
  3. Modify the specific bit for your pixel.
  4. Write the byte back.
  5. Repeat for all 4 color planes (Red, Green, Blue, Intensity).

It was slow, complex, and painful.

Mode 13h Changed Everything. In Mode 13h, memory started at address 0xA0000. Each pixel was exactly one byte.

  • Pixel (0,0) was at 0xA0000
  • Pixel (1,0) was at 0xA0001
  • Pixel (0,1) was at 0xA0000 + 320

The formula to plot a pixel at (x, y) with color c was simply:

offset = (y * 320) + x;
video_memory[offset] = c;

This simplicity allowed the CPU to blast pixels to the screen at incredible speeds, enabling the fast-paced action of Wolfenstein 3D and Doom.

Setting the Mode

Entering Mode 13h was a rite of passage for every DOS programmer. It involved calling the BIOS Interrupt 10h.

; x86 Assembly: Enter Mode 13h
mov ax, 0x0013  ; AH=00 (Set Video Mode), AL=13h (Mode 13)
int 0x10        ; Call BIOS Video Service

Once in the mode, you set your “Segment Register” (ES) to the video memory segment:

mov ax, 0xA000
mov es, ax      ; ES now points to video RAM

Now, writing to the screen was just a memory move:

; Draw a white pixel (Color 15) at top-left corner
mov di, 0       ; Offset 0
mov al, 15      ; Color White
mov [es:di], al ; Write to screen

The Palette: 256 Colors from 262,144

While you could only show 256 colors at once, you weren’t stuck with a fixed set. The VGA card had a DAC (Digital-to-Analog Converter) with a palette of 256 entries. Each entry could be defined by 6 bits of Red, 6 bits of Green, and 6 bits of Blue (values 0-63).

This gave a total spectrum of 262,144 possible colors ($2^{18}$).

Palette Animation (Color Cycling)

Because the video hardware looked up the RGB values from the DAC for every pixel, every frame, you could animate the screen without redrawing pixels. By simply changing the RGB definition of “Color 10” from Red to Blue, every pixel on the screen using Color 10 would instantly turn Blue.

This technique was used for:

  • Flowing Water: Shifting blue tones in the palette.
  • Fire Effects: Rotating red/orange/yellow ranges.
  • Glowing UI: Pulsing the brightness of a button color.
// C-style pseudo-code for palette cycling
outp(0x3C8, 0); // Tell DAC to start writing at Color 0
for (int i=0; i<256; i++) {
   outp(0x3C9, red[i]);   // Write Red
   outp(0x3C9, green[i]); // Write Green
   outp(0x3C9, blue[i]);  // Write Blue
}

Optimization Tricks

The 64KB Limit

The 8086/286 architecture had 64KB segments. 320 x 200 pixels = 64,000 bytes. This was wonderfully convenient! The entire screen fit into a single 64KB memory segment with just 1,536 bytes to spare. You never had to change the segment register while drawing a frame, which was a costly operation on older CPUs.

Lookup Tables

Multiplication (like y * 320) was slow on early CPUs. Programmers would pre-calculate a “Y-Table”:

unsigned short y_table[200];
void init_table() {
    for(int i=0; i<200; i++) y_table[i] = i * 320;
}
// Plotting becomes: memory[y_table[y] + x] = color;

The Legacy of 13h

Mode 13h defined the look of PC gaming from 1987 to roughly 1994. It was the canvas for LucasArts Adventures, SimCity 2000, Dune II, and the early demoscene. While later “Super VGA” cards offered higher resolutions (640x480, 800x600), they lacked a standard driver interface until VESA came along. Mode 13h was the universal standard—if a computer was IBM compatible, it ran Mode 13h.

Even today, when you run a retro-style indie game that uses “chunky” pixel art, it is spiritually emulating the linear framebuffer of Mode 13h.


Technical Modules

Source & Further Reading

  • “The VGA BIOS Guide” by Ferraro: The “Bible” of VGA programming.
  • Michael Abrash’s Graphics Programming Black Book: Chapter 23 covers the linear model of Mode 13h.
  • VGA Hardware Register Reference: A technical map of the VGA’s internal sequencer and controller. External Link
  • “256-Color VGA Programming in C”: A classic tutorial series from the 90s BBS era.