149. Cmp zero page x

add CMP zero-page,X opcode ``0xD5``.

Lesson 149 of 356 · tests/chapter_01_cpu/test_149_CMP_zero_page_x.py

Why this step exists

Indexed zero-page CMP supports compact table lookups and confirms that X addition wraps within zero page before the comparison value is read.

In this step, building only on lessons 146-148, add exactly the following to `emulator/cpu/opcodes.py`:

def cmp_zero_page_x(cpu: CPU):
    addr = zero_page_x(cpu)
    value = cpu.bus.read(addr)
    cmp(cpu, value)

OPCODE_TABLE = {
    ...
    0xD5: cmp_zero_page_x,
}

`addressing_modes.zero_page_x computes (operand + X) & 0xFF` before the bus read. C/Z/N may change; A, Overflow, X, Y, and memory remain invariant; opcode plus operand advances PC two bytes.

Misconception: indexing past `$FF` does not carry into page one; it wraps within zero page. Out of scope: absolute CMP starts in lesson 150, with its indexed and indirect variants deferred to lessons 151-154.

Run this lesson

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