153. Cmp indirect x
add CMP (indirect,X) opcode ``0xC1``.
Lesson 153 of 356 · tests/chapter_01_cpu/test_153_CMP_indirect_x.py
Why this step exists
The (indirect,X) form lets CMP use pre-indexed zero-page pointer tables while leaving pointer resolution to the addressing helper.
In this step, after lessons 146-152, add exactly the following to `emulator/cpu/opcodes.py`:
def cmp_indirect_x(cpu: CPU):
addr = indirect_x(cpu)
value = cpu.bus.read(addr)
cmp(cpu, value)
OPCODE_TABLE = {
...
0xC1: cmp_indirect_x,
}`emulator/cpu/addressing_modes.py::indirect_x fetches the operand, computes (base + X) & 0xFF`, and reads a little-endian pointer whose high-byte lookup also wraps in zero page. The handler then reads the pointed value. Only C/Z/N change; A, X, pointer bytes, target memory, and Overflow are invariant; the opcode and operand advance PC two bytes.
Misconception: X is applied before dereferencing, not to the final 16-bit address. Out of scope: CMP (indirect),Y (154) and CPX/CPY (155-162).
Run this lesson
uv run pytest tests/chapter_01_cpu/test_153_CMP_indirect_x.py -v