Atari Colour Registers and the 128-Colour Palette

Full-screen GRAPHICS 7 covered in thin vertical stripes in four colours

Atari 8-bit graphics never store colours directly in screen memory. Screen bytes say "use colour register 2", and the register holds the actual colour. De Re Atari compares it to a socket wrench versus a fixed spanner: a little more to learn, far more flexible. Change one register and every pixel using it changes colour instantly — which is how Atari programs flash warnings, fade screens, and animate scenes without redrawing anything.

What you'll learn: the nine registers and their shadows, the colour value formula, which register each BASIC graphics mode uses, colour cycling, attract mode, and why your colours look different on another machine.

What you need: Atari BASIC on any 8-bit Atari or emulator.

Nine registers, two addresses each

GTIA has nine write-only colour registers. The OS keeps a RAM copy of each — a shadow — and copies the shadows into the hardware during every vertical blank. From BASIC you always use the shadows:

Purpose Hardware Shadow (decimal / hex) SETCOLOR number
Player/missile 0 COLPM0 $D012 704 / $2C0 —
Player/missile 1 COLPM1 $D013 705 / $2C1 —
Player/missile 2 COLPM2 $D014 706 / $2C2 —
Player/missile 3 COLPM3 $D015 707 / $2C3 —
Playfield 0 COLPF0 $D016 708 / $2C4 0
Playfield 1 COLPF1 $D017 709 / $2C5 1
Playfield 2 COLPF2 $D018 710 / $2C6 2
Playfield 3 COLPF3 $D019 711 / $2C7 3
Background / border COLBK $D01A 712 / $2C8 4

If you POKE a hardware register from BASIC, the OS overwrites it within 1/60 second. Writing hardware registers directly is only for display list interrupts or programs that replace the OS vertical blank routine. The player colours have no SETCOLOR number; POKE 704–707.

The colour value

SETCOLOR register,hue,luminance stores hue × 16 + luminance into shadow 708 + register. The upper nybble is the hue (0–15), the lower nybble the luminance (0–14). Bit 0 of the luminance is ignored, so only even luminances are distinct: 16 hues × 8 luminances = 128 colours. Hue 0 is the grey scale. (The one exception is GTIA's GRAPHICS 9, which bypasses the registers and can show all 16 luminances.)

So SETCOLOR 2,4,6 and POKE 710,70 do the same thing.

The hues are usually named as follows (luminance 0 values shown; add the luminance):

Hue Value Name Hue Value Name
0 0 black/grey 8 128 medium blue
1 16 rust 9 144 dark blue
2 32 red-orange 10 160 blue-grey
3 48 dark orange 11 176 olive green
4 64 red 12 192 medium green
5 80 dark lavender 13 208 dark green
6 96 cobalt blue 14 224 orange-green
7 112 ultramarine 15 240 orange

Treat these names as rough guides — see "Why colours differ" below. The power-up defaults are 708 = 40, 709 = 202, 710 = 148, 711 = 70 and 712 = 0; the player colours start at 0.

Which register does each mode use?

BASIC mode What uses which register
0 Background of text area = 710; text luminance = 709 (the text takes 710's hue); border = 712
1, 2 Characters coloured by their code: uppercase/digits 708, lowercase 709, inverse uppercase 710, inverse lowercase 711; background 712
3, 5, 7 COLOR 1 = 708, COLOR 2 = 709, COLOR 3 = 710, COLOR 0 = background 712
4, 6 COLOR 1 = 708, COLOR 0 = background 712
8 Lit pixels take 709's luminance and 710's hue; background 710; border 712
9–11 See the GTIA modes guide

In the four-colour map modes each pixel is a bit pair, 00 = background, 01 = playfield 0, 10 = playfield 1, 11 = playfield 2. In GRAPHICS 0 only "two and one-half" registers are used, because characters take their hue from playfield 2 and only their luminance from playfield 1. The GRAPHICS 1/2 assignment is the character-colour table from Charles Delp's article in COMPUTE!'s Second Book of Atari Graphics.

A palette browser

10 GRAPHICS 0:POKE 752,1
20 FOR H=0 TO 15:FOR L=0 TO 14 STEP 2
30 C=H*16+L:POKE 710,C:POKE 712,C:POKE 709,14*(L<8)
40 POSITION 4,11:PRINT "HUE ";H;"  LUM ";L;"  VALUE ";C;"    "
50 FOR W=1 TO 200:NEXT W
60 NEXT L:NEXT H
70 GOTO 20

POKE 709,14*(L<8) keeps the text readable: Atari BASIC evaluates (L<8) as 1 or 0, so the text is bright on dark colours and dark on bright ones.

Colour cycling

De Re Atari's colour-cycling demo shows how much motion you get for free. It draws vertical stripes in all four colours of a full-screen GRAPHICS 7, then rotates the register contents — the stripes appear to march sideways although no pixel is ever redrawn:

10 GRAPHICS 23
20 FOR X=0 TO 39
30 FOR I=0 TO 3
40 COLOR I
50 PLOT 4*X+I,0
60 DRAWTO 4*X+I,95
70 NEXT I
80 NEXT X
90 A=PEEK(712)
100 POKE 712,PEEK(710)
110 POKE 710,PEEK(709)
120 POKE 709,PEEK(708)
130 POKE 708,A
140 GOTO 90

De Re Atari also suggested other uses: flashing the border on a wrong keypress, a different background colour on each page of a menu, or showing one stored shape in several colours to represent different objects — far cheaper than storing different shapes. Even a one-liner like FOR I=0 TO 254 STEP 2:POKE 712,I:NEXT I makes an eye-catching border sweep.

Attract mode

If nobody presses a key for roughly seven to nine minutes, the OS starts cycling the screen colours at reduced brightness to protect the TV from burn-in. The mechanism:

  • ATRACT (77, $4D) is a timer incremented every four seconds by the VBI and zeroed by every keypress. When it passes 127, attract mode switches on. POKE 77,128 shows the effect immediately.
  • DRKMSK (78, $4E) and COLRSH (79, $4F) are applied to every shadow colour as it is copied to the hardware: the colour is EORed with COLRSH (a changing value during attract mode) and ANDed with DRKMSK (which limits luminance while attract mode is on).

Joysticks don't reset the timer, so joystick-only games should POKE 77,0 regularly. Colours stored by DLIs aren't affected unless the DLI applies EOR COLRSH : AND DRKMSK itself, as De Re Atari shows.

Why colours differ between machines

There's no single "correct" Atari palette. On NTSC machines, GTIA produces hues by delaying the colour subcarrier in roughly 24° steps from the colour burst, and the step size is set by a trimmer on the motherboard. The adjustment affects higher hue numbers most, so hue 15 can range from green through yellow to orange between machines, while hue 1 barely changes. Official documents even disagree on whether hues 1 and 15 should match. Other quirks:

  • Dark colours are more saturated than bright ones, because colour strength doesn't scale with brightness.
  • Luminance levels 7 and 8 can be almost identical.
  • Luminance 0 is "blacker than black" on most NTSC sets.
  • PAL machines generate colour differently, with fixed, unevenly spaced phases; hues 1 and 15 are always identical on PAL, and colour is more consistent between machines.

Programs can tell which they're running on by reading the read-only PAL register at 53268 ($D014): bits 1–3 are all 0 on a PAL machine and all 1 on NTSC.

10 P=PEEK(53268):B=INT(P/2)-8*INT(P/16)
20 IF B=0 THEN PRINT "PAL MACHINE"
30 IF B=7 THEN PRINT "NTSC MACHINE"

Troubleshooting

  • SETCOLOR seems to do nothing: you changed a register the current mode doesn't use (see the table). In GRAPHICS 0, SETCOLOR 1 only changes text brightness.
  • Colour reverts instantly: you POKEd a hardware register ($D016 etc.) from BASIC. Use the shadow.
  • Odd luminance values look the same as even ones: bit 0 is ignored by the colour registers.
  • Colours go dim and change after a while: attract mode. POKE 77,0 periodically.
  • Text vanishes in GRAPHICS 0: text and background share 710's hue, so if 709 and 710 have similar luminances the text disappears.

Further reading

  • De Re Atari (Atari, 1982), Chapter 3 — colour register indirection and its applications.
  • Mapping the Atari by Ian Chadwick (COMPUTE! Books), locations 704–712 — includes a machine-language colour-rotation routine.
  • Atari Color Graphics by Joseph W. Collins (Arrays, 1984) — a beginner's workbook.
  • Altirra Hardware Reference Manual, section 6.3, for the electronics behind the palette.

Credits