liveBook · Manning

Vblank flag

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

A vBlank flag is a status bit indicating whether the NES display is in or has reached a vertical blanking interval.

A vBlank flag is a PPU status bit that indicates whether the NES display has entered or reached vertical blanking. Startup code polls this flag before sending hardware commands. section 5.12

A typical startup sequence uses the flag in two stages:

  • Test PPU_STATUS once, then loop until the vBlank flag changes. section 5.12
  • Clear RAM and place sprites offscreen while the PPU is becoming ready. section 5.12
  • Poll PPU_STATUS again before enabling NMI and transferring control to the main program. section 5.12
Listing 5.13 Waiting for the first vBlank (example.s)
                   #1
bit PPU_STATUS
wait_vblank:
    bit PPU_STATUS
    bpl wait_vblank

The polling pattern tests PPU_STATUS and branches back with BPL until the vBlank status condition is reached. section 5.12

Waiting for vBlank

Use BIT PPU_STATUS before the loop, then repeatedly execute BIT PPU_STATUS and branch back with BPL wait_vblank. The same pattern is repeated for the second vBlank. section 5.12

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

How deep it goes
Demonstrates status-bit polling in 6502 assembly, without detailing the PPU’s internal timing beyond its startup delay.
Examples
Uses first- and second-vBlank wait loops during NES startup, alongside RAM clearing and offscreen sprite placement.
What you can do after
Operate NES startup synchronization by polling PPU_STATUS before enabling NMI and entering the main program.
How it connects
Connects vBlank polling with the NES PPU, PPU_STATUS, NMI interrupts, RAM clearing, and sprite initialization.

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.