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
