164. Instruction bcc

implement Branch if Carry Clear behavior.

Lesson 164 of 356 · tests/chapter_01_cpu/test_164_instruction_bcc.py

Why this step exists

Lesson 163 already returns a signed displacement and leaves PC at the next instruction. BCC owns only the Carry-clear decision and target addition.

In this step, add exactly this implementation to `emulator/cpu/instructions.py::bcc`:

def bcc(cpu: CPU, offset: int):
    if not cpu.flags.get_carry_flag():
        cpu.pc = (cpu.pc + offset) & 0xFFFF

The mask preserves the CPU's 16-bit address space.

Invariants: Carry clear adds positive, zero, or negative `offset modulo 0x10000`; Carry set leaves PC unchanged. Flags, registers other than PC, and memory are untouched. Misconception: BCC means Carry *clear*, and it must not fetch or sign-convert the operand inside this instruction function.

Out of scope: BCS/BEQ/BNE/BPL/BMI/BVC/BVS are lessons 165-171. Importing branch functions into `emulator/cpu/opcodes.py`, relative handlers, and opcode table entries belong to lessons 172-179.

Run this lesson

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