Skip to Content
Under the HoodEmulator InternalsHow a television draws a picture

How a Television Draws a Picture

Every home computer of the ZX Spectrum’s and the ZX81’s generation was plugged into a television, and the television set the rules. It decided how fast the picture had to be delivered, in what order, and what the signal had to look like. Understanding it explains a great deal about why these machines were built the way they were, and why an accurate emulator has to work the way it does.

This article explains how an old cathode ray tube (CRT) television draws its picture, first in black and white and then in colour. You do not need to know anything about televisions or video hardware. The ZX81 display article builds on this one to show how a machine with no video chip at all produces its picture.

The electron beam

A cathode ray tube (CRT) television has an electron gun at the back of the glass. It shoots a thin beam of electrons at the inside of the screen, which is coated with phosphor: wherever the beam hits, the phosphor glows for a moment. A stronger beam makes a brighter dot; no beam leaves the spot dark.

The beam can light only one spot at a time. To make a whole picture, magnetic coils around the tube sweep it across the screen in a fixed pattern called a raster:

  1. The beam travels from left to right, drawing one horizontal scan line.
  2. At the right edge it snaps back to the left, a little lower, and draws the next line. This quick return is the horizontal retrace.
  3. When it reaches the bottom, it snaps back to the top-left corner and starts again. This is the vertical retrace.
⋮scan line: the beam drawshorizontal retrace (HSYNC)back to the left, one line lowervertical retrace (VSYNC)back to the top: a new frame
The raster. Solid lines are drawn; dashed lines are the retraces, when the beam is switched off.

A European (PAL) television draws a line every 64 microseconds and a full screen, a frame, 50 times a second. That is fast enough that your eye sees a steady picture instead of a moving dot.

The signal carries only “how bright, right now”

Here is the part that matters most. The signal going into the television does not contain pixels or coordinates. It is just one voltage that changes over time, and it means “this is how bright the spot under the beam is, at this very instant”.

The television does not know which dot belongs where. It knows only when. A dot appears 20 microseconds into a line because the voltage changed 20 microseconds after the line started. In a video signal, time is position.

So how does the television know when a line or a frame starts? The signal also carries two kinds of special pulses, each a short stretch of “blacker than black” voltage:

  • HSYNC (horizontal sync): “start a new line now”. One arrives every 64 µs.
  • VSYNC (vertical sync): “go back to the top now”. One arrives every frame. It is much longer than an HSYNC, so the television can tell them apart.
whiteblacksync⋯the dots of one lineHSYNCHSYNCHSYNCVSYNC: back to the topone line: 64 µstime
The video signal, simplified. Higher voltage is a brighter dot; the dips below black are the sync pulses. A real VSYNC lasts several lines.

The ZX81 needs only the three levels of the diagram, because its dots are either black or white. In Wilf Rigter’s description of the ZX81 video hardware , the ULA’s video output sits at about +5 V for white, +2.5 V for black and 0 V for sync. A resistor divider then scales these down to about +1 V, +0.5 V and 0 V at the input of the TV modulator. The same source gives HSYNC as about 5 µs long, every 64 µs, and VSYNC as about 400 µs long. These are nominal figures: owners who have measured their machines report noticeably different levels, which vary with the board and the ULA version.

The television locks onto these pulses. Its own sweep circuits (the flywheels) keep running at roughly the right speed even if a pulse is missing, which is why a picture rolls or tears rather than vanishing when the sync goes wrong.

Why you must follow the beam

There is no memory inside an old television. Nothing stores the picture. Whatever is on the signal wire now becomes the dot under the beam now, and a few milliseconds later it has faded away. So the computer has to deliver every dot at exactly the right microsecond, 50 times a second, forever. Programmers call this racing the beam.

PAL and NTSC. “50 times a second” is the European PAL standard: a line every 64 µs and 50 pictures a second, with 625 lines split into two interlaced halves of 312½. North America and Japan use NTSC: about 60 pictures a second, with 525 lines in halves of 262½. Home computers like the ZX81 ignore the interlacing and draw the same half-frame every time.

The ZX81 handles both with the same 207 T-state line, which fits either standard. The US machine (sold as the Timex Sinclair 1000) only draws fewer border lines: 263 lines a frame, about 60 frames a second, against 311 lines and about 50 on a European machine. The ROM finds out which kind of machine it is on by itself (Part 8 of the ZX81 display article shows how). This article gives the PAL numbers unless it says otherwise.

That is why an accurate emulator also has to keep a virtual beam: a model of where the real beam would be at every moment of the emulated machine’s time. If a program changes something halfway down the screen, the emulator must show the change from that line onwards, not on the whole picture. On the ZX81 this is not an optional extra, because, as the ZX81 display article shows, the picture is nothing but the CPU’s timing turned into light.

How colour is displayed

Everything so far describes a black-and-white television: one beam, one kind of phosphor, one voltage for brightness. Colour television had to be added on top of that without breaking it. Millions of black-and-white sets were already in people’s homes, and they had to keep showing a good picture from a colour broadcast. That one requirement shapes everything that follows.

Three phosphors, three beams

Your eye has three kinds of colour receptor, most sensitive to red, green and blue light. Mix those three lights in the right proportions and the eye sees almost any colour: red and green make yellow, all three at full strength make white, none makes black. This is additive colour mixing, and a colour tube is built around it.

The inside of a colour screen is covered not with one phosphor but with a fine pattern of three: tiny dots (or stripes) that glow red, green and blue, arranged in groups of three called triads. They are so small that from a normal viewing distance your eye cannot see them separately; it sees only the mixture.

At the back of the tube there are now three electron guns, one for each colour. They sweep the screen together, in the same raster as before, but each beam must hit only the phosphor of its own colour. That is the job of the shadow mask: a thin metal sheet just behind the screen, punched with one tiny hole for every triad. The three guns sit side by side and so arrive at each hole from slightly different angles. After passing through the hole, each beam lands on a different spot, and the tube is built so that the spot is the phosphor of its own colour. The mask blocks everything else.

red gungreen gunblue gunshadow maskblue lands heregreen lands herered lands herephosphor on the screen
A shadow mask, seen from the side and much enlarged. The three beams cross in the hole and each lands on the dot of its own colour; the faded dots belong to the neighbouring triads.

Some tubes, Sony’s Trinitron the best known, use vertical phosphor stripes and an aperture grille of fine vertical wires instead of a mask full of holes, but the principle is the same: the geometry makes sure that each beam can only reach its own colour.

The strength of each beam now sets the brightness of one colour. Inside the television, then, a colour picture is just three black-and-white pictures at once, one red, one green and one blue, drawn by three beams that move in step. Everything you learned above still holds for each of them.

Colour on a signal made for black and white

Three pictures need three signals, but the broadcast, and the aerial socket of the television, have room for only one. And an old black-and-white set must still be able to make sense of that one signal. The engineers of the 1950s and 1960s solved both problems in the same way.

First, the signal keeps carrying the brightness, exactly as before. It is now called the luminance (written Y), and it is a weighted mix of the three colours, matching how bright each one looks to the eye:

Y = 0.299 × red + 0.587 × green + 0.114 × blue

Green counts most and blue least, because that is how bright they appear to us. A black-and-white television displays Y and gets a correct grey picture.

Second, the colour information is added on top of the luminance, as a separate ingredient called the chrominance (or chroma). It does not carry red, green and blue directly. Since Y already holds the brightness, only two numbers are needed to tell the colours apart: how far the blue is from the brightness (B − Y) and how far the red is (R − Y). These are the colour-difference signals, called U and V in PAL. The television can recover green from Y, U and V by arithmetic. A grey dot has no colour difference at all: U and V are both zero.

The colour subcarrier: phase is hue, amplitude is saturation

The two colour-difference signals ride on a fast sine wave, the colour subcarrier: about 4.43 MHz in PAL (4.43361875 MHz exactly) and about 3.58 MHz in NTSC. U and V are combined into one wave of that frequency, and its shape carries the colour:

  • The phase of the wave (where its peaks fall in time) gives the hue: red, yellow, green, blue and every shade in between are different points around the circle.
  • The amplitude of the wave (how big its swings are) gives the saturation: a large wave is a vivid colour, a small one a pale colour, no wave at all is grey.

Why phase and amplitude? Encoding colour this way was a practical choice, not just an elegant one. In the 1950s a television was built from valves, and later from a handful of transistors, so the decoder had to be a few cheap analogue parts. Phase and amplitude are exactly what such parts measure easily. The classic circuit is the synchronous detector: it multiplies the incoming wave by a reference wave of the same frequency, and a resistor and a capacitor smooth the result. The output is a steady voltage proportional to how much of the incoming wave is in step with the reference. Two such detectors, one with the reference delayed by a quarter of a cycle, give U and V directly. The television never measures an angle or computes anything: the colour-difference voltages simply come out of the circuit. All it needs is a reference wave, and the next section shows where that comes from.

This wave is added to the luminance. Where the picture is coloured, the brightness signal wiggles up and down very fast around its average level; where it is grey, it does not wiggle.

The subcarrier frequency is chosen very carefully, with an exact relation to the line frequency, so that the wiggles fall into gaps in the luminance’s spectrum and largely cancel out on the screen. A black-and-white set displays them anyway, as a faint fine dot pattern over coloured areas, but they are small enough to be ignored.

The colour burst: the television’s reference

Phase only means something when there is a reference to compare it with. A wave that is “90 degrees late” must be late relative to something. So every line carries a short sample of the subcarrier itself, at a fixed phase: the colour burst, about ten cycles of the wave just after the HSYNC, on the stretch of black called the back porch, before the picture of the line begins.

whiteblacksyncHSYNCcolour bursta vivid colourgreya paler, darker colournext linetime
One line of a colour signal, simplified and not to scale. The burst is a sample of the subcarrier; in the picture, the size of the wiggle is the saturation and its phase, which a drawing cannot show, is the hue.

The television has its own oscillator running at the subcarrier frequency. On every line it uses the burst to pull that oscillator exactly into step, and then, during the picture, it compares the incoming wave against it. The phase difference gives the hue, the size of the wave the saturation, and from those the decoder rebuilds U and V. Together with Y, that yields the red, green and blue voltages that drive the three guns.

In a colour signal, time is still position. The burst is a time reference too, but for a far finer clock: a phase error of a few nanoseconds is enough to change a colour.

What a real signal looks like

The diagrams so far draw the signal as flat steps joined by vertical jumps, with the colour as a zigzag. That makes the idea easy to see, but it is a cartoon. A real video signal, seen on an oscilloscope, differs in three ways.

Nothing changes instantly. A television channel carries only about 5 MHz of bandwidth, and a signal limited to 5 MHz simply cannot jump: going from black to white takes on the order of a hundred nanoseconds. The standards go further and require soft edges: a PAL sync pulse must rise and fall in about a quarter of a microsecond. A perfectly square edge would contain frequencies the channel cannot carry, and what reached the screen would overshoot and ring around the edge. So every step is a smooth slope, and even the ZX81’s sharp on-off dots arrive at the screen with soft edges.

Colour is a sine wave. The subcarrier is a pure sine wave, and so is the burst: about ten cycles that fade in and out rather than switch on. At 4.43 MHz a 52 µs picture line holds about 230 cycles. Seen across a whole line, they are far too close together to tell apart and merge into a solid band around the brightness level: the band’s height is the colour’s strength, and its centre is the luminance.

The levels are standard. A composite video signal is 1 V from the bottom of the sync to peak white: 0.3 V of sync below the blanking level, and 0.7 V from black to white above it. The colour wave is added on top, so a strongly coloured dark area can swing below black, part of the way towards the sync level. The television’s sync separator ignores such fast swings, because it looks only for the long, slow sync pulses.

The figure shows one line of the most familiar test signal, the colour bars: white, then yellow, cyan, green, magenta, red and blue at 75% strength, then black. The bars are sorted by brightness, so the luminance falls in a staircase from left to right. Its waveform is computed from the formulas above, using the PAL standard’s timings and levels.

0.7 V0 V−0.3 Vsyncthe picture: eight colour bars, 52 µsnext sync0.7 V0 V−0.3 VHSYNC, 4.7 µsburstwhite baryellow bar20 µs010 µs
One PAL line of colour bars, computed rather than sketched. Top: the whole line, with the colour bars it draws above it; the colour wave is too fast to resolve at this scale and shows as a band. Bottom: the dashed section enlarged, where the sloped sync edges, the burst and the colour wave of the yellow bar become visible. The white bar has no colour, so it has no wave.

PAL and NTSC: what to do about phase errors

Because the hue lives in the phase, anything that delays the subcarrier by a tiny amount on its way to the television shifts every colour around the colour circle. Faces turn green or purple.

  • NTSC, the older system, simply lives with it: NTSC televisions have a hue (or tint) knob, and the viewer turns it until faces look right.
  • PAL (Phase Alternating Line) flips the sign of the V signal on every other line. A phase error then shifts the hue one way on one line and the opposite way on the next. The television keeps the previous line in a delay line (64 µs long, one line), averages the two, and the errors cancel. What is left is a slight loss of saturation, which the eye forgives far more readily than a wrong hue. PAL sets need no hue knob.

The alternation is also how a PAL decoder tells odd lines from even ones: the phase of the burst itself swings back and forth on alternate lines.

Colour is blurrier than brightness

The eye sees fine detail in brightness much better than in colour, and the colour system takes advantage of it. The luminance has about 5 MHz of bandwidth in PAL, but the colour-difference signals have only about 1.3 MHz. So the colour can change only about a quarter as quickly along a line as the brightness can. A thin coloured line is drawn with sharp brightness edges and a colour that bleeds a little to either side.

It also means the two ingredients can be confused. Very fine luminance detail near the subcarrier frequency, a pattern of thin stripes, for example, looks to the decoder just like a colour wave, and the television paints a shimmer of false colours over it (cross-colour). Some home computers turned this into a feature and produced colours on purpose from carefully chosen patterns of black and white dots, but on a PAL television that rarely works as well as on NTSC.

For a computer racing the beam, nothing new is needed: colour is just more of “how bright, right now”. At every instant the signal says how bright the spot is and what colour it is, and the computer has to deliver both at the right microsecond. What changes is how fine the colour can be: a computer designer who knows the colour is blurry has little reason to let the colour change from dot to dot, so many machines of the era give a whole block of dots a single colour. The ZX Spectrum’s 8 × 8 colour cells are a well-known example (ZX Spectrum: How the Screen Is Drawn).

How a computer produces it

A home computer does not usually build the subcarrier wave itself. Its video chip works out, for each dot, a luminance and two colour-difference levels, or simply red, green and blue, and hands them to a PAL (or NTSC) encoder. That chip mixes in the subcarrier, adds the burst, and produces the composite video signal, which a modulator then turns into a broadcast-style signal for the television’s aerial socket.

Every step from the computer to the screen costs some quality: the modulator, the tuner, the shared bandwidth of luminance and colour. That is why, as soon as televisions had a SCART or RGB input, people used it. An RGB connection skips the whole encoding and decoding chain. It carries the red, green and blue voltages on three separate wires, plus the sync, straight to the three guns, and the colours come out exactly as the computer meant them.

No burst, no colour: the black-and-white ZX81

The ZX81 is a black-and-white computer, and its signal shows it: no subcarrier, and no colour burst. A colour television notices the missing burst and switches off its colour decoder entirely (a circuit called the colour killer exists for precisely this). It then treats the signal as pure luminance and displays a clean grey picture. Without the colour killer, the sharp edges of the ZX81’s dots, which contain energy at all sorts of frequencies, would be decoded into random fringes of colour.

Klive and colour. Like most emulators, Klive does not generate an analogue video signal and decode it again. Its machine cores work out the colour each dot would have, at the moment the virtual beam passes over it, and write that colour straight into the picture you see, much as an RGB connection would deliver it. The beam’s timing is followed exactly; the subcarrier, the burst and the decoder are not, and so neither are the blurred colour and the cross-colour of a real television picture.

Last updated on