144. Bit zero page

add BIT zero-page opcode ``0x24``.

Lesson 144 of 356 · tests/chapter_01_cpu/test_144_BIT_zero_page.py

Why this step exists

The first BIT opcode must fetch an operand from memory rather than modify A, then delegate its distinct Z/N/V rules to the instruction primitive.

In this step, lesson 143 already adds `bit. As BIT's first opcode lesson, add its import and exactly the following handler/table entry in emulator/cpu/opcodes.py`:

from emulator.cpu.instructions import (..., bit)

def bit_zero_page(cpu: CPU):
    addr = zero_page(cpu)
    value = cpu.bus.read(addr)
    bit(cpu, value)

OPCODE_TABLE = {
    ...
    0x24: bit_zero_page,
}

`addressing_modes.zero_page` consumes the operand as an address; the bus read supplies the value whose bits BIT tests. Z/N/V may change, while A, Carry, X, Y, and memory are invariant; opcode plus operand advances PC two bytes.

Misconception: the operand byte is not tested directly and BIT does not write the addressed byte. Out of scope: BIT absolute is lesson 145.

Run this lesson

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