168. Instruction bpl

implement Branch if Plus behavior.

Lesson 168 of 356 · tests/chapter_01_cpu/test_168_instruction_bpl.py

Why this step exists

In 6502 terminology, "plus" means the existing Negative flag is clear, so BPL selects on that flag rather than inspecting the offset or PC.

In this step, after BNE, add exactly

`emulator/cpu/instructions.py::bpl`::

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

The function applies the decoded signed offset to the post-operand PC and masks the result to the 16-bit address space.

Invariants: Negative clear takes the branch; Negative set leaves PC unchanged. No flags, other registers, or memory change. Misconception: BPL does not test whether PC or `offset` is positive and does not recompute Negative.

Out of scope: BMI/BVC/BVS are lessons 169-171. Opcode imports, relative handlers, and table entries are lessons 172-179.

Run this lesson

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