# SPDX-License-Identifier: MIT """The self-checking programs of rungs 2 and 3: where they are, where they end, how to run them. Klaus Dormann's 65C02 extended-opcodes test and Bruce Clark's decimal test are assembled by ``scripts/build_tools.py`` into ``reference/build/dormann`` (never committed): the extended test once per row (``wdc``: with ``WAI``/``STP`` reserved and the bit instructions; ``rockwell``: ``$CB``/``$DB`` tested as one-byte NOPs, with the bit instructions; ``sc``: those and ``x7``/``xF`` tested as one-byte NOPs), the decimal test with ``cputype = 1``. Dormann's NMOS functional test is the prebuilt image of the pinned repository. Every outcome of each program ends in a jump to itself, and the address says which. Their tier is that of the evidence that they pass on real hardware (docs/validation.md): logic-analyser captures exist of a real G65SC12 and a real R65C02 running these programs to the end, so tier 1 for the ``G65SC02`` and ``R65C02`` rows; the ``W65C02S`` and ``Lynx2Cell`` rows have no such capture. """ from pathlib import Path from w65c02_python import G65SC02, R65C02, W65C02S, Lynx2Cell from w65c02_python.harness import Harness ROOT = Path(__file__).resolve().parents[1] BUILT = ROOT / "reference" / "build" / "dormann" FUNCTIONAL = ROOT / "reference" / "src" / "dormann" / "bin_files" / "6502_functional_test.bin" DECIMAL = BUILT / "65C02_decimal_test.bin" BUILD_HINT = "not built: python -I scripts/fetch_references.py, then scripts/build_tools.py" ROWS = (W65C02S, R65C02, G65SC02, Lynx2Cell) #: row -> (image, the address of its success trap, from the build's own listing). EXTENDED = { W65C02S: ("wdc", 0x24F1), R65C02: ("rockwell", 0x2569), G65SC02: ("sc", 0x2434), Lynx2Cell: ("rockwell", 0x2569), } #: The functional test's success trap (its listing, label ``success``). FUNCTIONAL_SUCCESS = 0x3469 #: The decimal test's ERROR byte: 1 while running and on failure, 0 on success. DECIMAL_ERROR = 0x000B def extended_image(name: str) -> Path: """The extended-opcodes test built as ``wdc``, ``rockwell`` or ``sc``.""" return BUILT / f"65C02_extended_opcodes_test_{name}.bin" def decimal_image() -> bytes: """Clark's test with ERROR pre-filled: the test must overwrite it (1 while running).""" image = bytearray(DECIMAL.read_bytes()) image[DECIMAL_ERROR] = 0xA5 return bytes(image) def run_to_trap(row: type, image: bytes, budget: int = 400_000_000) -> Harness: """Load ``image`` at 0, start at $0400 (the programs' entry), run until it jumps to itself, the CPU halts, or ``budget`` cycles.""" harness = Harness(row) harness.load(image) harness.start(0x0400) harness.run(budget) return harness