liveBook · Manning

Attribute table

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

An attribute table is the 64-byte NES data structure that specifies palette selection for each 16 × 16 screen block.

An NES attribute table is a 64-byte VRAM region immediately following a name table. Each entry selects the palette used by a 16 × 16 background area, so the same tile patterns can be shown in different colors. section 5.14.3 section 6.9

Use an attribute table alongside name-table data:

  • When clearing a name table, write its 30 × 32 blank tile values, then write 64 zero values to clear the following attribute table. section 5.14.3
  • Set the VRAM address to the required attribute-table location before sending attribute values. section 6.7
  • Change an attribute block when text or graphics need another palette while keeping the same tile patterns. section 6.7 section 6.9

Giving title text a different color

Title text and “Press Play” text can use the same alphabet tiles. Writing %00000101 across the second eight-byte attribute block selects the second tile palette set for the title area, making its first-color pixels medium green while the other text remains dark pink. section 6.7

Listing 5.26 Clearing the name table (example.s)
.segment "CODE"
.proc clear_nametable
     lda PPU_STATUS         #1
     lda #$20               #2
     sta PPU_VRAM_ADDRESS2
     lda #$00
     sta PPU_VRAM_ADDRESS2
  
                            #3
     lda #0
     ldy #30                #4
     rowloop:
         ldx #32            #5
         columnloop:
             sta PPU_VRAM_IO
             dex
             bne columnloop
         dey
         bne rowloop
  
                            #6
     ldx #64                #7
     loop:
         sta PPU_VRAM_IO
         dex
         bne loop
     rts
 .endproc 

This routine first writes blank tiles across 30 rows of 32 entries, then uses a 64-iteration loop to clear the attribute table that follows the name table. section 5.14.3

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

How deep it goes
Defines the 64-byte layout and demonstrates clearing it and writing an eight-byte title-screen attribute block.
Examples
Uses title and Press Play text that share tiles but display with green and dark-pink palette choices.
What it assumes
Builds from name-table tile writing and introduces the following 64 attribute bytes as a separate clearing step.
What you can do after
Operate/configure it by clearing 64 bytes and writing a selected attribute-table block through VRAM.
How it connects
Connects name tables, tile patterns, palette entries, VRAM addresses, and macros.

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.