A color palette is the set of color values used to render graphics. On the NES, palettes are split into a table for background tiles and a separate table for sprites. Each table has four sets of four colors, so graphics can reuse the same tile patterns while selecting different palette entries. section 5.8 section 6.9
Store a starting palette as bytes in ROM, then keep the current palette values in RAM for updates. During the NMI routine, write the PPU VRAM address as $3F00 and send all 32 palette values through the PPU VRAM I/O register. The address advances after each write, so a loop can transfer the complete table. section 5.8 section 5.13
The palette system provides several practical constraints and opportunities:
- Background tiles can show 13 colors selected from a palette of 52 at one time. section 6.9
- Sprites use separate palettes and can add another 12 colors, for 25 colors on screen in total. section 6.9
- An attribute table can make identical tile patterns use different palette sets. section 6.9
Animate a shared color
To create a low-cost flashing effect, swap two entries in the first tile palette table inside the main loop. Every tile using those entries changes together: the score, extra-lives display, and planet base can alternate colors. Because the NMI routine copies the RAM palette table to the PPU, changing RAM entries is enough to update the screen. section 13.2.2
Listing 13.9 Swapping two colors in the first palette table (megablast.s)
jsr player_actions
jsr move_player_bullet
jsr spawn_enemies
jsr move_enemies
lda time
and #%111
bne @nopalettechange
ldx palette+1
lda palette+2
sta palette+1
stx palette+2
@nopalettechange:
jmp mainloop
.endproc
This listing swaps palette entries 1 and 2 after a timing check, producing a visible color change wherever that palette is used. section 13.2.2










