RasterCore

Mode X: The Zen of VGA Graphics

:: SysOp

Breaking the Standard

By 1990, the PC demoscene and game industry were hitting a wall. The standard Mode 13h (320x200, 256 colors) was easy to use, but it had severe limitations.

  1. Low Resolution: The pixels were non-square (aspect ratio 1.2:1), making circles look like eggs.
  2. No Page Flipping: You only had one screen worth of memory (64KB) accessible. Animation required drawing everything to system RAM and copying it over, which was slow.
  3. Wasted Memory: The VGA card actually had 256KB of RAM, but Mode 13h only let you touch the first 64KB. The rest sat idle.

Then, in July 1991, Michael Abrash published an article in Dr. Dobb’s Journal titled “Mode X: 320x240”. It changed PC graphics programming forever.

Unchaining the Beast

Mode 13h is a “Chained” mode. The VGA hardware automatically maps 4 planes of memory into one linear address space. To unlock “Mode X,” you had to manually reprogram the VGA Sequencer registers to “unchain” the memory.

This was done by manipulating the Sequencer Memory Mode Register (Port 0x3C4, Index 0x04). Turning off the “Chain-4” bit organized memory into four parallel planes.

  • Pixel 0 is stored in Plane 0.
  • Pixel 1 is stored in Plane 1.
  • Pixel 2 is stored in Plane 2.
  • Pixel 3 is stored in Plane 3.
  • Pixel 4 is stored in Plane 0 (Byte 1).

Why Complicate Things?

At first glance, this seems terrible. Instead of a linear array, you have this interleaved planar mess. Why do it?

1. Hardware Parallelism (The 4x Speedup) The VGA controller allowed you to select which planes to write to using the Map Mask Register. If you enabled all 4 planes and wrote a single byte to address 0, the hardware would write that byte to Plane 0, 1, 2, AND 3 simultaneously. This meant you could fill the screen with a solid color four times faster than in Mode 13h. This was critical for polygon fillers in 3D games.

2. Video Memory for Days Unchaining the memory gave you access to the full 256KB of VRAM.

  • 320x240 uses 76,800 bytes.
  • 256,000 / 76,800 = 3.3 full screens. This allowed for Triple Buffering: drawing to Page 2 while displaying Page 1, ensuring perfectly smooth, tear-free animation at 60 FPS (or 70Hz in 320x200).

3. Square Pixels By tweaking the CRT Controller timing registers, Mode X achieved a resolution of 320x240. On a standard 4:3 monitor, this produced perfectly square pixels. Circles were finally round!

Smooth Hardware Scrolling

Perhaps the most impressive feature of Mode X was hardware scrolling. The Amiga had done this for years, but PC gamers were used to jerky “tile-based” scrolling (like in Commander Keen).

Mode X allowed you to change the Start Address of the display window within the 256KB VRAM. By incrementing this address, you could scroll through a large virtual map instantly. Better yet, the VGA had a Pixel Pan Register that allowed shifting the image by 0-3 pixels. Combined with the byte-offset start address, this allowed for buttery-smooth pixel-perfect scrolling in all directions.

Code Example: Setting Mode X

Setting Mode X wasn’t a simple BIOS call; it was a register surgery.

// C Pseudo-code to enter Mode X
void set_mode_x() {
    // 1. Start with standard Mode 13h to set standard timings
    _asm {
        mov ax, 0x0013
        int 0x10
    }
    
    // 2. Unchain Memory (The "Magic" part)
    // Port 0x3C4 (Sequencer), Index 4 (Memory Mode)
    outp(0x3C4, 0x04);
    byte mask = inp(0x3C5);
    mask &= ~0x08;  // Turn OFF Bit 3 (Chain-4)
    mask |= 0x04;   // Turn ON Bit 2 (Odd/Even disable)
    outp(0x3C5, mask);

    // 3. Turn off Odd/Even mode in Graphics Controller
    outp(0x3CE, 0x05); // Index 5 (Mode Register)
    mask = inp(0x3CF);
    mask &= ~0x10;  // Turn OFF Bit 4 (Odd/Even)
    outp(0x3CF, mask);

    // 4. Clear VRAM (Since the BIOS only cleared the first 64KB)
    // ... custom clear loop required here ...
}

The Cultural Impact

Mode X was the secret weapon of the early 90s.

  • Epic Pinball: Used the vertical hardware scrolling for its tall tables.
  • Jazz Jackrabbit: Used the smooth horizontal scrolling to rival Sonic the Hedgehog.
  • Demoscene: Groups like Future Crew used Mode X to create 3D engines and plasma effects that seemed impossible on standard hardware.

It also separated the “novices” from the “wizards.” If you were still using Mode 13h in 1993, you weren’t writing a serious graphics engine. Michael Abrash’s writings on Mode X fostered a culture of deep hardware understanding—the idea that you should “assume nothing” and read the silicon datasheets directly.


Technical Modules

Source & Further Reading

  • “The Graphics Programming Black Book” by Michael Abrash: Now available for free online.
  • “Mode X: 320x240 256-color”: Original Dr. Dobb’s Journal article (July 1991).
  • VGA Register Map: Technical details on the Sequencer and CRT Controller. External Link
  • “Tweak”: A famous utility by Robert Schmidt that allowed users to test custom VGA register tweaks.