← All Essays
Technology 11 min read

The Copper and the Raster Interrupt

How 1980s programmers made the display hardware do things it could not do, by changing its mind mid-scanline

The beam is the opportunity

A cathode ray tube draws the picture one horizontal line at a time, sweeping left to right, then returning to start the next. That return trip takes time, and during it nothing is being drawn. The entire technique rests on noticing that this interval is an opportunity: whatever the graphics chip's registers say when a line is drawn is what that line looks like, and you can change them in the gap.

Do this once and you get a split screen with two different configurations. Do it every scanline and the machine's advertised limits stop being limits. The Commodore 64's VIC-II could supply an interrupt when the raster reached a specific line: you write a value to the raster register, the chip latches it, and every time the raster register increments it compares against that value and fires an interrupt on a match. The CPU then has a narrow window to change something before the beam moves on.

What it bought on the C64

The C64's official capabilities were modest and its actual output was not, and raster interrupts are much of the difference. The machine supports eight hardware sprites; with raster interrupts a programmer can reposition a sprite after it has been drawn and have it drawn again lower down the screen, producing far more than eight visible objects. This is sprite multiplexing, and it is why C64 games are full of more moving things than the datasheet permits.

The same trick swaps display modes partway down a screen — a bitmap playfield above, a text status bar below — and expands the colour palette beyond what any single configuration allows. None of this is documented capability. It is all a consequence of the fact that the hardware's state is mutable and the beam is slow, and it requires code timed to the microsecond, because a raster interrupt that fires a few cycles late writes its change while the beam is already drawing and produces a visible tear.

The Amiga did it in hardware

Commodore's Amiga took the technique and gave it a dedicated processor. The Copper is a coprocessor whose entire purpose is servicing raster effects: it runs a small program of simple instructions, synchronised to the video hardware, and its instruction set is essentially "wait for the beam to reach this position" and "write this value to this hardware register." It is a programmable state machine that spends its life either fetching an instruction, executing it, or waiting for a beam position.

The efficiency is the point. On the Amiga, the Copper takes the equivalent of about 8 CPU cycles to change a colour register and about 12 to wait for a screen position — so a raster bar costs roughly 20 cycles, and crucially it costs the main CPU nothing, because the Copper is doing it. The copper bars scrolling behind every Amiga demo and title screen are not the processor straining; they are a dedicated chip doing its job while the CPU gets on with the game. The Copper can also reuse sprites by moving them after they are drawn, and set per-scanline horizontal scroll to produce wave effects.

Programming against the picture

What these techniques have in common is a relationship to the display that modern programming has entirely lost. The programmer is not describing a scene to a rendering system and waiting for a frame; they are intervening in the physical act of drawing, dozens or hundreds of times per frame, with timing measured against the movement of an electron beam across phosphor. The code is coupled to the hardware's real-time behaviour so tightly that changing the television standard breaks it — which is a substantial part of why PAL and NTSC conversions of this era were so frequently broken.

The Copper is the more elegant answer and the C64's raster interrupts are the more instructive one, because the C64 had no special hardware for this at all. Someone noticed a comparison register and an interrupt line and worked out that they added up to a way around the machine's limits, and then a decade of programmers built a body of technique on top of that observation. The Amiga's designers watched that happen and put a chip in the machine to do it properly. That sequence — a hack becomes standard practice, then standard practice becomes silicon — is one of the most reliable patterns in the history of hardware, and it is the same one that gave the Genesis its parallax planes.