043. Ldy zero page
Add LDY zero page ($A4).
Lesson 43 of 356 · tests/chapter_01_cpu/test_043_LDY_zero_page.py
File to update
emulator/cpu/opcodes.pyLocations
opcodes imports of zero_page and ldy
opcodes.ldy_zero_page
opcodes.OPCODE_TABLE[$A4]Why this step exists
Unlike immediate LDY, zero-page LDY resolves the operand to an address, reads the byte at that address, and then delegates register and flag behavior to ldy.
Complete example implementation
# emulator/cpu/opcodes.py
from emulator.cpu.addressing_modes import zero_page
from emulator.cpu.instructions import ldy
def ldy_zero_page(cpu: CPU):
addr = zero_page(cpu)
value = cpu.bus.read(addr)
ldy(cpu, value)
OPCODE_TABLE = {
# Preserve existing entries.
0xA4: ldy_zero_page,
}Important invariants
- $A4 maps to ldy_zero_page and consumes one operand byte
- zero_page returns an address in $0000-$00FF
- the handler performs one data read and passes that value, not its address, to ldy
ldyupdates Zero and Negative
Common misconception
Passing addr directly to ldy would load the zero-page location number rather than the byte stored there.
Out of scope
- zero-page,X and absolute LDY encodings
- new addressing-mode helpers
- cycle timing
Run this lesson
uv run pytest tests/chapter_01_cpu/test_043_LDY_zero_page.py -v