207. Flag control implied opcodes

wire implied flag-control opcodes.

Lesson 207 of 356 · tests/chapter_01_cpu/test_207_flag_control_implied_opcodes.py

Why this step exists

In this step, update `emulator/cpu/opcodes.py's instruction import and OPCODE_TABLE. The functions from step 206 become executable through emulator/cpu/cpu.py::CPU.step`.

Suggested implementation

# Add clc, sec, cli, sei, cld, sed, clv to the instruction import.
OPCODE_TABLE = {
    # existing entries
    0x18: clc,
    0x38: sec,
    0x58: cli,
    0x78: sei,
    0xD8: cld,
    0xF8: sed,
    0xB8: clv,
}

Invariant: every mapping dispatches directly to a one-argument operation; each instruction is one byte, so opcode fetch alone advances PC to the next byte and only the target flag changes. The common misconception is to add an addressing mode that consumes an operand, or to transpose set/clear opcode pairs.

Out of scope: NOP and opcode $EA belong to steps 208-209, and interrupt delivery semantics are later behavior.

Run this lesson

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