061. Adc indirect y

Add ADC (Indirect),Y.

Lesson 61 of 356 · tests/chapter_01_cpu/test_061_ADC_indirect_y.py

File to update

emulator/cpu/opcodes.py

Symbols to add/update

opcodes.adc_indirect_y and OPCODE_TABLE[0x71]

Why this step exists

This final ADC addressing variant connects the existing indirect_y address helper to the existing value-based adc instruction for opcode $71.

Complete example implementation

# emulator/cpu/opcodes.py
def adc_indirect_y(cpu: CPU):
    addr = indirect_y(cpu)
    value = cpu.bus.read(addr)
    adc(cpu, value)

OPCODE_TABLE = {
    # ... existing entries ...
    0x71: adc_indirect_y,
}

Important invariants

  • indirect_y fetches the one-byte operand and returns the final address
  • the handler reads the value at that address exactly once
  • adc, rather than the handler, updates A and arithmetic flags
  • executing the two-byte instruction advances PC by two bytes

Common misconception

Do not pass the address returned by indirect_y directly to adc; adc accepts the byte stored at that address.

Out of scope

  • SBC and its opcode handlers
  • new addressing-mode helpers or refactors
  • cycle timing and page-cross penalties

Run this lesson

uv run pytest tests/chapter_01_cpu/test_061_ADC_indirect_y.py -v