A name table is NES video memory containing tile references that arrange a background screen. Each screen uses 8 × 8 pixel tiles in a grid 32 tiles wide and 30 tiles high, for 960 tile entries and a nominal resolution of 256 × 240 pixels. section 6.5
A name table also determines how the background is stored and displayed:
- The 64 bytes after each name table form an attribute table, assigning palettes to each 16 × 16 area. section 5.14.3
- The NES has two name tables in video memory; fixed layouts mirror them horizontally or vertically, repeat one table, or use four separate tables with extra cartridge-provided video RAM. section 6.5.1 section 16.2
- Scroll positions select the visible portion of a layout, while switching between tables can change screens quickly without redrawing them. section 6.5.1
- Vertical mirroring supports horizontal scrolling by drawing upcoming scenery into the offscreen table and swapping tables at the screen edge. section 16.4.2
Clearing a name table
Set the VRAM destination to $2000, the first name table. Send zero 32 times for each of 30 rows, then send 64 more zeros for the attribute table. If tile pattern zero is blank, the visible screen becomes clear. Nested assembly loops provide the 30-by-32 tile writes, followed by a separate 64-byte loop. section 5.14.3
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
Inspect the complete assembly routine for setting the VRAM address, writing 30 rows of 32 entries, and clearing the 64-byte attribute table. section 5.14.3
