206. Instruction flag controls

implement flag-control operations.

Lesson 206 of 356 · tests/chapter_01_cpu/test_206_instruction_flag_controls.py

Why this step exists

In this step, add `emulator/cpu/instructions.py symbols clc, sec, cli, sei, cld, sed, and clv. Each delegates one status-bit change to the existing cpu.flags` API, including Decimal helpers from 205.

Suggested implementation

def clc(cpu: CPU):
    cpu.flags.set_carry_flag(False)
def sec(cpu: CPU):
    cpu.flags.set_carry_flag(True)
def cli(cpu: CPU):
    cpu.flags.set_interrupt_disable_flag(False)
def sei(cpu: CPU):
    cpu.flags.set_interrupt_disable_flag(True)
def cld(cpu: CPU):
    cpu.flags.set_decimal_flag(False)
def sed(cpu: CPU):
    cpu.flags.set_decimal_flag(True)
def clv(cpu: CPU):
    cpu.flags.set_overflow_flag(False)

Invariant: each function changes exactly its named bit and preserves all other flags, registers, S, PC, and memory. CLI clears the interrupt-disable mask; it does not clear an interrupt event. Another common misconception is treating CLV or any clear operation as a reset of the complete status register.

Prerequisite: step 205 added the Decimal helpers. Out of scope: the `emulator/cpu/opcodes.py` imports and mappings belong to step 207.

Run this lesson

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