liveBook · Manning

Pattern table

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

Graphical data describing the pixels or appearance of a movable game object.

A pattern table stores the pixel shapes used to draw NES tiles and sprites. Graphics come from an 8K cartridge area or, in some configurations, writable graphics RAM; the PPU uses this data rather than a display where every screen pixel is independently controlled. section 1.2 section 1.5.2

Each pattern is an 8 × 8 pixel shape. A tile row occupies two bytes: combining the corresponding bits produces a 2-bit pixel value from 0 to 3. That value selects a color within a palette; a background tile also uses an attribute value to choose one of four background palettes shared by each 2 × 2 tile area. section 6.5.2

Figure 6.5 How the two pattern table bytes combine

Use the bit-combination diagram to see how two bytes describe one row of four-color pixel values. section 6.5.2

Pattern tables support both layers of NES graphics:

  • Background tiles form screen layouts. The same tile pattern can appear in multiple places and use different palette entries through the attribute table. section 6.9
  • Sprites are movable objects drawn in front of or behind background tiles. A sprite can use one 8 × 8 pattern in 8 × 8 mode or two patterns in 8 × 16 mode. section 7.1
  • The PPU control setup can select the first pattern table for backgrounds and the second for sprites. section 6.4

Ship, bullet, and animated stars

A player ship larger than 8 × 8 pixels is assembled from four patterns and four sprites, while a bullet needs one pattern and one sprite. Background stars can animate by leaving their screen locations unchanged and periodically changing the tile-pattern number written there; keep the number of video-memory changes small each frame. section 7.2 section 13.2.1 section 13.2

Before a title screen or game screen can use its graphics, load the required tile and sprite patterns from ROM into PPU video memory when the chosen storage arrangement requires it. Pattern editing can add new shapes to an existing background tile set. section 1.5.1 section 13.2

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

How deep it goes
Explains 8 × 8 patterns down to two-byte rows, 2-bit pixels, palette attributes, and PPU table selection.
Examples
Uses a four-pattern player ship, one-pattern bullet, edited background shapes, and randomly placed animated stars.
What it assumes
Teaches graphics representation from the NES tile model while assuming access to game ROM, PPU memory, and optional pattern editors.
What you can do after
Build it from scratch by defining 8 × 8 graphics patterns, assigning them to tiles or sprites, and selecting their PPU tables.
How it connects
Connects pattern tables with the PPU, VRAM, tiles, sprites, palettes, attribute tables, OAM, and vBlank.

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.