liveBook · Manning

Zero-page indirect-Y addressing mode

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

Zero-page indirect-Y addressing mode reads a 16-bit base address from zero-page memory and adds the Y register to obtain the final operand address.

Zero-page indirect-Y addressing mode uses two adjacent zero-page bytes as a 16-bit base address, then adds Y to reach the final memory address. The syntax places the zero-page address in parentheses and Y after a comma: `(<zero-page address>),Y`. section 3.3.1

Set up the pointer by storing its low byte first and its high byte immediately after it. If `$05` contains `$00` and `$06` contains `$03`, the pair specifies `$0300`. With `Y = $06`, an operand written as `($05),Y` reaches `$0306`. section 3.3.1 section 3.3.2

The mode can use that calculated address for several operations:

  • Load from it with `LDA ($05),Y`. If `$0306` holds `$EE`, A becomes `$EE`. section 3.3.1
  • Store A through it with `STA ($05),Y`. With the pointer at `$0300`, `Y = $06`, and `A = $EE`, memory location `$0306` receives `$EE`. section 3.3.2
  • Add the byte found through it with `ADC ($02),Y`. A pointer to `$0300` plus `Y = $02` reaches `$0302`; adding `$14` to A's `$10` produces `$24`. section 4.1.1

Follow one indirect-Y load

Store `$00` at `$05` and `$03` at `$06` to form the base address `$0300`. Store `$EE` at `$0306`, load Y with `$06`, then run `LDA ($05),Y`. The processor reads the two-byte address from zero page, adds Y, and loads the byte at `$0306` into A. section 3.3.1

Figure 3.13 Loading a value from memory using a calculated location

Use the diagram to trace the two-stage lookup: zero-page bytes provide the base address, and Y selects the final byte. section 3.3.1

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

How deep it goes
Explains pointer-byte setup, syntax, final-address calculation, and worked LDA, STA, and ADC results.
Examples
Uses pointers to $0300 with Y offsets to load or store $EE at $0306 and add $14 from $0302.
What it assumes
Introduces the required zero-page pointer setup while relying on basic registers, memory addresses, and load/store instructions.
What you can do after
Apply it via 6502 LDA, STA, and ADC instructions to access an address calculated from a zero-page pointer and Y.
How it connects
Connects zero-page memory, 16-bit addresses, the Y register, LDA, STA, and ADC.

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.