In the first Deluxe Paint for the Amiga, Electronic Arts included a picture of a waterfall. Nothing in it was redrawn, yet AmigaWorld’s reviewer reported in 1986 that “the water appears to be flowing”. The trick was palette cycling, also called colour cycling. The picture’s pixels did not hold colours: each held a number that pointed into a small table of colour registers. Paint the water with a run of neighbouring register numbers, then shift the colours along those registers once a frame, and the bands of colour appear to move down the cliff while the bitmap does not change at all.
The technique is cheap, but not free. A program still has to write a handful of registers every frame, and the artist has to plan the picture around it: every register given over to the waterfall is a colour the rest of the picture cannot use.
How it works
Palette cycling needs indexed colour. On the Amiga, the Atari ST and the VGA card in a PC, a pixel’s value is an index into a colour table, and the table holds the actual red, green and blue values. Change one entry in the table and every pixel that uses it changes on the next frame.
To animate, the artist draws the moving part with a sequence of registers, say 1 to 7, painted in order along the direction of movement, and fills those registers with a gradient. Each frame the program rotates the values: register 1 takes register 2’s colour, 2 takes 3’s, and so on, with the colour that falls off the end going back to the start. André LaMothe’s Black Art of 3D Game Programming (1995) gives the same recipe for a waterfall drawn in VGA registers 10, 11 and 12:
temp = color register 10
color register 10 = color register 11
color register 11 = color register 12
color register 12 = tempThe speed of the animation is the number of frames between rotations. LaMothe’s example program applied the same idea to a picture of a road, rotating the colours of the road surface and the roadside markers so that the road looked as if it was moving, and he pointed out that changing the rotation rate would change the apparent speed.
Amiga
The original Amiga chipset has 32 colour registers, COLOR00 to COLOR31, at $DFF180 to $DFF1BE. Each holds 12 bits, four each for red, green and blue, so each register can be any of 4,096 colours. The Amiga Hardware Reference Manual adds a warning that matters for cycling: “The color registers are write-only. Only by looking at the screen can you find out the contents of each color register.” Its advice is to keep a copy of the colours in RAM and update the copy whenever you write a register. A cycling routine therefore rotates its own table and copies the result to the hardware; it cannot read the registers back.
; Rotate colours 1-7 once a frame.
; The colour registers are write-only, so the palette lives in a RAM
; table: rotate the table, then copy it to COLOR01-COLOR07.
CUSTOM equ $dff000
VPOSR equ $004
COLOR01 equ $182
start:
lea CUSTOM,a5
move.w #299,d7 ; run for 300 frames, then exit
frame:
.wait: move.l VPOSR(a5),d0 ; wait for raster line 300
and.l #$1ff00,d0
cmp.l #300<<8,d0
bne.s .wait
.leave: move.l VPOSR(a5),d0 ; and for it to pass, so we run once a frame
and.l #$1ff00,d0
cmp.l #300<<8,d0
beq.s .leave
lea palette(pc),a0 ; rotate the RAM copy by one entry
move.w (a0),d0 ; save entry 1
moveq #5,d1 ; shift entries 2-7 down one place
.rot: move.w 2(a0),(a0)+
dbf d1,.rot
move.w d0,(a0) ; old entry 1 becomes entry 7
lea palette(pc),a0 ; write the table to the hardware
lea COLOR01(a5),a1
moveq #6,d1
.copy: move.w (a0)+,(a1)+
dbf d1,.copy
dbf d7,frame
moveq #0,d0
rts
palette:
dc.w $001,$002,$003,$004,$005,$006,$007The routine waits for a raster line below the visible picture before it writes, so the colours never change halfway down the screen. Run on an emulated Amiga 500, it writes COLOR01 to COLOR07 once a frame, and the seven values move along the registers by one place each time, returning to where they started every seven frames.
The Copper, the Amiga’s display coprocessor, can also write colour registers at chosen lines down the screen. That makes a different effect, changing a colour line by line for sky and ground gradients, and a program can combine the two by cycling the values the Copper list writes.
The Amiga’s most famous early demonstration used the technique. The spinning of the Boing Ball, shown at the Consumer Electronics Show in 1984, was colour cycling: each red or white check was drawn as narrow slices in different colour registers, and the program moved red and white along the registers every frame, so the checks seemed to turn while the ball’s pixels never changed. Deluxe Paint offered colour cycling to artists from its first version in 1985, and Electronic Arts listed it among the program’s features in its 1986 advertisements (see the Dan Silva entry).
Atari ST
The Atari ST holds its 16-colour palette in registers at $FF8240 to $FF825E. In February 1987 Atari ST User explained the effect to its readers: change a palette value “and all the corresponding pixels on the screen will also change automatically. This effect is called colour cycling and leads to such effects as the famous boink bouncing ball and the Neochrome waterfall demonstrations.” NEOchrome, an early ST paint program, was known for its cycling waterfall.
PC and VGA
The VGA card’s 256 colour registers are reached through I/O ports. A program writes the number of the register it wants to change to port 0x3C8, then writes the red, green and blue values to port 0x3C9, one byte after another; a counter inside the card decides which component each byte sets. Each component is only 6 bits wide, 0 to 63. LaMothe noted the catch: with one data port and three components, “we can’t select one component of the color register … and write specifically to it. We must write to all three.”
Commodore 64
The Commodore 64 has no programmable palette. Its sixteen colours are fixed, so true palette cycling is impossible. What it does have is a set of shared colour registers. In multicolour character mode, Commodore’s Programmer’s Reference Guide explains, the bit pairs 00, 01 and 10 in a character are “references to the registers associated with those colors” at $D021 to $D023, and it draws the conclusion: “Simply changing one of the indirect registers will change every dot drawn in that color. Therefore everything drawn in the screen and background colors can be changed on the whole screen instantly.” The guide’s own example POKEs a random colour into 53282 ($D022) in a loop. Extended background colour mode adds a fourth register, $D024, chosen for each character by the top two bits of its screen code, at the price of using only 64 different characters.
Changing those registers in turn on every frame gives the flashing, colour-washed text familiar from C64 scene programs. A Codebase64 article, written about the “char flashing” in notewriters such as Face Noter, switches on extended background colour mode and, from a raster interrupt, writes values from three tables of colours into $D022, $D023 and $D024. Text drawn in ordinary character colours has to be cycled the slow way, by rewriting colour RAM. A 1989 COMPUTE!’s Gazette reader’s tip by Jacques Bingham did exactly that, installing an interrupt that walked a 32-entry table of colour codes through colour RAM behind a title. Paint programs advertised the effect too: in 1986 Activision’s Paintworks promised “color cycling for animation effects”.
In games
Games used cycling for water, fire and lights. ST Format‘s review of The Secret of Monkey Island in June 1991 found the cost even so: “when there is a lot of colour cycling on-screen — next to a waterfall for instance — you do tend to slow down to more of a leisurely stroll.” Amiga Computing singled out “a good example of colour cycling in a fairly neat waterfall” in the 1990 Amiga version of Toobin’, though it found the rest of the graphics small and slow. Mark Ferrari, one of the artists who painted Monkey Island’s backgrounds, has an entry of his own.
Limits
- Planning. The picture has to be drawn for cycling from the start, with the moving parts painted in ordered runs of registers.
- Colours. Every register in a cycle is a colour the rest of the picture cannot use. On a 16- or 32-colour screen that is a real cost.
- Movement, not shape. Cycling can only move colour along paths already drawn. Nothing changes outline or position.
- Machines without palettes. Where colours are fixed, as on the C64, the effect is limited to the shared colour registers, or needs the slower route of rewriting colour memory.
Sources
- Amiga Hardware Reference Manual, third edition (Commodore-Amiga / Addison-Wesley, 1991), chapter 3, “Playfield Hardware”, pp. 45–46 (the colour table, 12-bit colour registers, “The color registers are write-only”, the advice to keep a RAM copy) and p. 91; appendix A, pp. 291–292 (COLOR00–COLOR31 at
$180–$1BE, write-only). - The Amiga routine above was assembled with vasm (Motorola syntax, Amiga hunk executable) and run from a floppy image on an emulated Amiga 500 (OCS, PAL) in Emu198x; the emulator’s log of colour register writes showed COLOR04–COLOR07 written once a frame, 1,200 writes in 300 frames, each value moving one register per frame.
- André LaMothe, Black Art of 3D Game Programming (Waite Group Press, 1995), chapter 3, pp. 77–79 (VGA colour registers, ports
0x3C8and0x3C9, 6-bit components) and chapter 4, pp. 194–197 (colour rotation, the waterfall example and the road demonstration). - Atari ST Internals (Abacus Software, 1986): colour palette registers at
$FF8240–$FF825E. - Atari ST User, February 1987: colour cycling, the bouncing ball and the NEOchrome waterfall.
- Abigail Reifsnyder, review of Deluxe Paint, AmigaWorld vol. 2 no. 2, March/April 1986, pp. 72–77: the colour-cycled waterfall (see the Deluxe Paint entry).
- Jimmy Maher, The Future Was Here: The Commodore Amiga (MIT Press, 2012), chapter 2: the Boing Ball’s colour cycling (see the Boing Ball entry).
- Commodore 64 Programmer’s Reference Guide (Commodore Business Machines and Howard W. Sams, 1982), pp. 116–117 (multicolour mode and the indirect colour registers) and pp. 119–120 (extended background colour mode).
- Richard Bayliss, “Colour Flashing Notewriter Style”, Codebase64 wiki (web, secondary). https://codebase64.net/doku.php?id=base:colour_flashing_notewriter_style
- COMPUTE!’s Gazette vol. 7 no. 10, October 1989, p. 56: “Printing with Style” by Jacques Bingham, The Programmer’s Page.
- COMPUTE!’s Gazette vol. 4 no. 42 (December 1986), pp. 71–72: Activision Paintworks advertisement.
- ST Format issue 23, June 1991, p. 52: The Secret of Monkey Island review.
- Amiga Computing vol. 2 no. 9, February 1990, p. 25: Toobin’ review.