liveBook · Manning

Name table

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

A name table is NES video memory containing tile references that specify the arrangement of a background screen.

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

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

How deep it goes
Defines tile layout, palette attributes, mirroring, scrolling, and clearing code, while deferring detailed scrolling implementation.
Examples
Uses a blank-screen clearing routine, mirrored scrolling layouts, status-screen swapping, and Super Mario Bros. as a scrolling example.
What it assumes
Assumes familiarity with NES video memory and tile graphics, while teaching the screen grid, attributes, layouts, and clearing loops.
What you can do after
Build it from scratch by writing tile and attribute data to VRAM, clearing a screen, or arranging tables for scrolling.
How it connects
Connects tile graphics, attribute tables, video memory, scrolling, screen refresh, and cartridge expansion.

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.