Everything2
Near Matches
Ignore Exact
Full Text
Everything2

palette swapping

created by yerricde

(idea) by yerricde (8.7 mon) (print)   ?   (I like it!) 1 C! Thu Aug 30 2001 at 0:52:46

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.


printable version
chaos

palette swap NES programming NES PPU Kitana
Nesticle dedicated cabinet power-up 2A03
color Skate or Die NES Mileena
mapper Luigi Mortal Kombat palette
Ranger X Super Mario Brothers Scorpion Windows 98
Mario Windows 95 dynamic enemy
Y'know, if you log in, you can write something here, or contact authors directly on the site. Create a New User if you don't already have an account.
  Epicenter
Login
Password

password reminder
register

Everything2 Help

Cool Staff Picks
Little presents from the Node Fairy:
Stained Glass Primer
Scalping
deliciously oily
Civilization
Singing Sand
Choosing a wine
The Soft Bulletin
Irish
Chinese Exclusion Act of 1882
Shall I Compare Thee to a Dead Portuguese Man-of-War Lying Bloated on a Polluted Beach?
Living up to your potential
Vasilopita
Brace Yourself
New Writeups
XWiz
Trism(review)
artman2003
Briefcase Full of Souls - Part I(fiction)
Dreamvirus
Alan Ladd(person)
waverider37
Harold Holt(person)
The Debutante
Until death do us part(fiction)
Ysardo
a brother to a sister(personal)
antigravpussy
your warm whispers(personal)
Clarke
Multiculturalism(idea)
aneurin
Earl of Landaff(person)
Heitah
Pseudocide(idea)
XWiz
Google Knol(lede)
Mythi
July 24, 2008(personal)
locke baron
The fall of Earth(fiction)
BookReader
Fear the Cold(dream)
Pavlovna
Kathleen MacInnes(person)
This page courtesy of The Everything Development Company