077. Dec zero page x

wire DEC Zero Page,X (`0xD6`).

Lesson 77 of 356 · tests/chapter_01_cpu/test_077_DEC_zero_page_x.py

In this step, with dec imported by lesson 076, add emulator/cpu/opcodes.py:dec_zero_page_x and OPCODE_TABLE[0xD6] only.

Why this step exists

Delegate indexed page-zero address calculation to the existing addressing helper and memory mutation to the existing DEC primitive.

Suggested implementation in emulator/cpu/opcodes.py:

def dec_zero_page_x(cpu: CPU):
    addr = zero_page_x(cpu)
    dec(cpu, addr)

Add this exact entry to the existing OPCODE_TABLE:

0xD6: dec_zero_page_x,

Invariants: one operand byte is consumed; base plus X wraps at $FF within page zero; PC advances to the next two-byte instruction; DEC writes an 8-bit result and updates only Z/N.

Misconception: $FF,X with X=1 does not target $0100; zero-page indexed addressing resolves $0000 before DEC runs.

Out of scope: dec_absolute/0xCE and dec_absolute_x/0xDE are lessons 078-079.

Run this lesson

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