080. Instruction inx

add the INX instruction primitive.

Lesson 80 of 356 · tests/chapter_01_cpu/test_080_instruction_inx.py

In this step, add only emulator/cpu/instructions.py:inx. Opcode 0xE8 is lesson 081, while dex and opcode 0xCA are lessons 082-083.

Why this step exists

INX is implied register behavior, so it needs no addressing helper or bus access. The primitive performs 8-bit arithmetic and derives flags directly from the new X value.

Suggested implementation in emulator/cpu/instructions.py, after dec:

def inx(cpu: CPU):
    result = cpu.x + 1
    result_8 = result & 0xFF

    # Set flags
    cpu.flags.set_negative_flag((result_8 & 0b1000_0000) != 0)
    cpu.flags.set_zero_flag(result_8 == 0)

    cpu.x = result_8

Invariants: X remains eight-bit ($FF + 1 == $00); Zero and Negative reflect the masked result; A, Y, memory, Carry, and Overflow remain unchanged; this primitive itself does not fetch operands or advance PC.

Misconception: INX is not memory INC with X as an address. It mutates the X register directly and takes only cpu.

Out of scope: importing and mapping inx, adding dex, and mapping 0xCA belong to lessons 081-083.

Run this lesson

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