202. Txs 隐含寻址

接通隐含寻址 TXS 操作码 $9A。

202 / 356 · tests/chapter_01_cpu/test_202_TXS_implied.py

本步骤存在的原因

在本步骤中,目标是 `emulator/cpu/opcodes.py 的指令导入以及 OPCODE_TABLEemulator/cpu/instructions.py::txs 已在步骤 201 中存在。此操作码接线使该独立行为可以通过 emulator/cpu/cpu.py::CPU.step` 执行。

建议实现

from emulator.cpu.instructions import txs  # add to the existing import

OPCODE_TABLE = {
    # existing entries
    0x9A: txs,
}

不变式:TXS 为单字节指令,因此 CPU.step 的操作码取指是唯一的 PC 前进操作;分派直接调用 `txs(cpu)`,并保持 X 和 P 不变。常见的误解是将隐含寻址的 TXS 通过某种寻址模式来处理,并消耗下一个字节作为操作数。

范围之外:实现 TSX 或注册 $BA 属于步骤 203-204;周期计数以及后续的 CPU 功能不属于本次变更。

运行本课

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