"""Rung 5: srg320's P65C816 VHDL as a third opinion, cycle by cycle. For SingleStepTests cases from every file, the HDL (under GHDL, tests/p65c816.py), the core and the corpus each give every bus cycle, and each category of difference is put to a vote. The gate: - the core never stands alone, and the three never all differ: wherever the HDL and the corpus agree, the core agrees with them; - the corpus stands alone only on the contested items decided for the datasheet (C1: JMP/JSR (a,x)'s pointer reads; C2: WDM's operand; C4: (d,x)'s emulation-mode high byte), so the HDL sides with the core there. Where the HDL stands alone (the core and the corpus agree) it is P65C816's own behaviour, recorded in docs/validation.md, not gated: emulator-derived HDL is a detector, never a judge. """ import pytest from p65c816 import BUILD_HINT, TESTBENCH, run_core, run_corpus, run_testbench, vote from single_step import CORPUS, FETCH_HINT, corpus_present, load_cases CASES_PER_FILE = 50 NAMES = sorted(p.name.removesuffix(".json") for p in CORPUS.glob("*.json")) #: Opcodes where the corpus may stand alone, and in which categories. CONTESTED = { 0x7C: frozenset(("vda", "vpa")), # C1 0xFC: frozenset(("vda", "vpa")), # C1 0x42: frozenset(("vpa",)), # C2: the corpus has an IO cycle, so its VPA differs **dict.fromkeys( (0x01, 0x21, 0x41, 0x61, 0x81, 0xA1, 0xC1, 0xE1), frozenset(("value", "address")) ), # C4 } @pytest.mark.slow @pytest.mark.parametrize("name", NAMES or ["(none)"]) def test_the_hdl_never_outvotes_the_core(name: str) -> None: if not corpus_present(): pytest.skip(FETCH_HINT) if not TESTBENCH.exists(): pytest.skip(BUILD_HINT) cases = load_cases(name)[:CASES_PER_FILE] opcode = int(name[:2], 16) problems = [] for case, hdl in zip(cases, run_testbench(cases), strict=True): assert hdl is not None, f"{case['name']}: the loader did not reach the case" for category, side in vote(run_core(case), hdl, run_corpus(case)).items(): if side in ("core alone", "all differ"): problems.append(f"{case['name']}: {category}: {side}") elif side == "corpus alone" and category not in CONTESTED.get(opcode, ()): problems.append(f"{case['name']}: {category}: the corpus alone, uncontested") assert not problems, problems[:10]