liveBook · Manning

Color palette

As explained in Classic Game Programming on the NES: Make your own retro video game

A graphics palette is a set of color values available for rendering graphical content.

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

How Classic Game Programming on the NES: Make your own retro video game covers it

How deep it goes
Explains ROM definitions, RAM changes, and a 32-byte VRAM transfer loop; defers tile and sprite palette use.
Examples
Demonstrates a default 32-entry palette and swaps two tile-palette colors to flash score, lives, and a planet base.
What it assumes
Introduces palette bytes and transfer steps directly while assuming access to NES PPU registers and an NMI routine.
What you can do after
Apply it by editing RAM palette entries and relying on the NMI update to change shared on-screen colors.
How it connects
Connects palettes to the PPU, VRAM, NMI routines, sprites, background tiles, and attribute tables.

Also explained in

Compare how 11 books explain color palette →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Classic Game Programming on the NES: Make your own retro video game. The section links point to the parts of the book it draws on.