liveBook · Manning

Branch on plus

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

The BPL instruction branches when the 6502 negative flag is clear.

BPL is a 6502 conditional branch. It jumps to its label when the negative flag, N, is clear (0). N is bit 7 of the status register, so BPL tests whether that bit is not set. section 4.4.2

Like other branches, BPL provides an IF-style decision: execution jumps when its flag condition is true and otherwise continues with the next instruction. Branch destinations are limited by a one-byte relative offset, allowing at most 129 bytes forward or 126 bytes backward. section 4.4.2

Wait until vBlank

BIT reads PPU_STATUS and sets N from its bit 7. The first read clears the existing vBlank flag; the loop then keeps branching back while N is clear. Once vBlank sets bit 7, N becomes set, BPL does not branch, and execution leaves the loop. 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

This short polling loop shows BPL targeting its own wait_vblank label until the PPU status indicates vBlank. section 5.12

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

How deep it goes
Defines BPL through the negative flag and demonstrates it in a PPU-status loop, while noting relative branch range limits.
Examples
Demonstrates a wait_vblank loop that repeatedly tests PPU_STATUS with BIT before branching with BPL.
What it assumes
Introduces branching through an IF THEN ELSE analogy while explaining BPL's negative-flag condition explicitly.
What you can do after
Apply it to implement a vBlank polling loop after BIT sets N from PPU status.
How it connects
Connects BPL to conditional branching, status flags, BIT, the PPU status register, 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.