"""Run one SingleStepTests/680x0 case on the core (rung 5: a detector only). The 680x0 corpus (Tom Harte's, generated by his CLK emulator; no license file, so nothing of it is committed) differs from the m68000 corpus in its conventions, which ``corpus.read_680x0`` and this host absorb: RAM is byte-addressed, a byte transaction carries the byte rather than the bus half, there are no strobe fields, and an access an address error aborts is not listed at all. What is compared is otherwise the m68000 gate's: registers, SR, both stack pointers, the prefetch address and pair, RAM, the clock total and the ordered accesses with kind, address, size, value and function code. A disagreement here is a question, never a verdict (docs/validation.md): ``scripts/run_680x0.py`` sorts them into explained categories. """ from __future__ import annotations from corpus import Case from harness import load, registers_of from m68000_python import M68000CPU class ByteHost: """Byte-addressed sparse RAM logging accesses in the 680x0 corpus's shape.""" def __init__(self, ram: dict[int, int]) -> None: self.memory = dict(ram) self.log: list[tuple] = [] def read_word(self, address: int, fc: int = 0) -> int: value = (self.memory.get(address, 0) << 8) | self.memory.get(address + 1, 0) self.log.append(("r", address, ".w", value, fc)) return value def read_byte(self, address: int, fc: int = 0) -> int: value = self.memory.get(address, 0) self.log.append(("r", address, ".b", value, fc)) return value def write_word(self, address: int, value: int, fc: int = 0) -> None: self.memory[address] = value >> 8 self.memory[address + 1] = value & 0xFF self.log.append(("w", address, ".w", value, fc)) def write_byte(self, address: int, value: int, fc: int = 0) -> None: self.memory[address] = value self.log.append(("w", address, ".b", value, fc)) def run_case_680x0(case: Case) -> tuple[list[str], int, list[tuple], list[tuple]]: """Run ``case``; return (differences, clocks, our accesses, theirs).""" host = ByteHost(case.initial.ram) cpu = M68000CPU( host.read_byte, host.read_word, host.write_byte, host.write_word, function_codes=True, tas_write=host.write_byte, ) load(cpu, case.initial) cycles = cpu.step() differences = [] actual = registers_of(cpu) for name, value in case.final.registers.items(): if actual[name] != value: differences.append(f"{name}: {actual[name]:#x} != {value:#x}") if (cpu.ir, cpu.irc) != tuple(case.final.prefetch): differences.append("prefetch") for address, value in case.final.ram.items(): if host.memory.get(address, 0) != value: differences.append(f"ram[{address:#08x}]") if cycles != case.cycles: differences.append(f"cycles: {cycles} != {case.cycles}") theirs = [ ( t.kind, t.address, t.size, t.data if t.size == ".w" else t.data >> (0 if t.lds else 8), t.fc, ) for t in case.transactions ] if host.log != theirs: differences.append("transactions") return differences, cycles, host.log, theirs