119. And zero page x

add AND zero-page,X opcode ``0x35``.

Lesson 119 of 356 · tests/chapter_01_cpu/test_119_AND_zero_page_x.py

In this step, after lesson 118, add only the indexed zero-page handler and table entry in `emulator/cpu/opcodes.py`.

Why this step exists

This adds indexed access to zero-page AND and verifies that address calculation wraps within the zero page before the memory value reaches the AND primitive.

Suggested implementation

def and_zero_page_x(cpu: CPU):
    addr = zero_page_x(cpu)
    value = cpu.bus.read(addr)
    and_a(cpu, value)

OPCODE_TABLE = {
    ...
    0x35: and_zero_page_x,
}

`emulator/cpu/addressing_modes.py::zero_page_x computes (base + cpu.x) & 0xFF. The resolved byte is read once conceptually and passed to instructions.and_a: A and Z/N change, Carry/Overflow and memory do not, and PC advances two bytes. Base 0xFE plus X 0x03 must read $0001, not $0101`.

Misconception: indexing does not alter the data and must wrap before the bus read. Out of scope: absolute through indirect,Y AND (lessons 120-124), and changes to the already-existing addressing helper or instruction semantics.

Run this lesson

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