128. Ora zero page x
add ORA zero-page,X opcode ``0x15``.
Lesson 128 of 356 · tests/chapter_01_cpu/test_128_ORA_zero_page_x.py
Why this step exists
This enables compact indexed ORA access and verifies that adding X obeys zero-page wraparound before the selected byte is combined with A.
In this step, following lesson 127, add only this handler and table entry to `emulator/cpu/opcodes.py`:
def ora_zero_page_x(cpu: CPU):
addr = zero_page_x(cpu)
value = cpu.bus.read(addr)
or_a(cpu, value)
OPCODE_TABLE = {
...
0x15: ora_zero_page_x,
}`emulator/cpu/addressing_modes.py::zero_page_x computes (base + cpu.x) & 0xFF before the bus read. The resolved value feeds instructions.or_a; A and Z/N change, X, Carry/Overflow, and memory do not, and PC advances two bytes. Thus base 0xFE plus X 0x03 reads $0001`.
Misconception: zero-page indexing wraps to `$0001, not $0101`; X does not alter the loaded value. Out of scope: absolute and indirect ORA modes (lessons 129-133).
Run this lesson
uv run pytest tests/chapter_01_cpu/test_128_ORA_zero_page_x.py -v