Palette swapping for fast full-screen color changes
Up until the introduction of the first popular 3D hardware, game consoles and PCs have had a problem with video memory bandwidth. For instance, the NES allows its CPU to copy only about 128 bytes to its PPU in one NTSC vertical blank period. Because rewriting a palette takes only five writes for the whole screen as opposed to one to three writes for each affected 8x8 pixel tile, it's often a good idea to animate the palette and change a color across the whole screen. (This is also called palette animation, palette rotation, or color rotation.) Windows 95 and Windows 98 rotate the colors of the progress bar during startup; some games (especially Pole Position clones) rotate the colors to provide an illusion of motion.
Theoretically, the NES can show 25 simultaneous colors on a given scanline: one background color, four sets of three colors for background tiles, and four sets of three colors for sprites. The attribute table in video RAM chooses palettes for 16-byte blocks of the screen (see NES PPU for the gory details). This method becomes especially apparent if you try to run Skate or Die 2 on an emulator with faulty support for SoD2's mapper. (Note that NESticle is so bad I don't even try to run anything on it anymore.) You get a scrambled screen where 16x16 pixel tiles change color in response to the music, where the words "SKATE", "OR", and "DIE" are supposed to appear.
Palette swapping for more than one type of character
Ever wonder why you don't get lots of different types of enemies in one area of Super Mario Brothers? Easy. SMB dynamically allocates its palettes to enemies; typically you get one palette for Mario or Luigi (which the game swaps when you get power-ups), one for a power-up or other incidental sprites, and two for enemies. (This is also why you don't get Mario and Luigi simultaneously in the scrolling game.) If you enter an area with lots of bottomless pits, the game swaps one of the palettes into "red turtle" colors and alters the turtles' behavior. (Red turtles pace instead of walking or hopping off cliffs.) Older Mortal Kombat games do something similar with Classic Sub-Zero vs. Scorpion and Mileena vs. Kitana.
An alternative take on this same material is available at palette swap.
(return to) NES programming
© 2001 Damian Yerrick. Verbatim copying and redistribution are permitted.