# SPDX-License-Identifier: MIT """Rung 2: krom's 31 GSUTest ROMs, 1,226 PASS/FAIL rows, on the bare core (test-author tier). The S-CPU's side is read from each ROM's own 65C816 code (harness.krom_script) and the row count is checked against the ``PrintText(Pass`` count in the ``.asm`` beside it. MAME 0.285 and Mesen2 2.1.1 pass every row (validation.md). **C9.** One row separates the core's default from the emulators: FMULT row 8 runs ``WITH R4; FMULT`` with R4 = FFFFh, R6 = 0 and expects R4 = 0 (the high word stored, as ares and MAME do). BK2 9.33 says the result "will not be stored in R4", fullsnes says R4 is "reportedly" unchanged; manufacturer and research outrank test-author (validation.md), so the default keeps R4 (decision 5) and fails that row; ``FMULT_R4_UNCHANGED = False`` passes all 1,226. """ from __future__ import annotations import re import pytest from conftest import KROM, require from gsu_python import GSU, GSU1 from gsu_python.harness import run_krom TESTS = [ "ADC", "ADD", "AND", "ASR", "BIC", "CACHEINJECT", "CMP", "DEC", "DIV2", "FMULT", "HIB", "IBT", "INC", "IWT", "LMULT", "LOB", "LSR", "MERGE", "MOVE", "MOVES", "MULT", "NOT", "OR", "ROL", "ROR", "SBC", "SEX", "SUB", "SWAP", "UMULT", "XOR", ] # fmt: skip #: (test, row index) -> the C/U entry that explains a default-core FAIL. EXPLAINED = {("FMULT", 8): "C9"} class EmulatorC9(GSU): FMULT_R4_UNCHANGED = False def load(name: str) -> tuple[bytes, int]: folder = require(KROM / "GSUTest" / name) rom = (folder / f"GSU{name}.sfc").read_bytes() rows = len(re.findall(r"PrintText\(Pass", (folder / f"GSU{name}.asm").read_text())) return rom, rows @pytest.mark.parametrize("name", TESTS) def test_krom_rows(name): rom, rows = load(name) result = run_krom(rom) assert len(result.rows) == rows failed = {(name, row.index) for row in result.failed} assert failed <= set(EXPLAINED), result.failed emulator = run_krom(rom, gsu=EmulatorC9(rom, bytearray(0x8000), model=GSU1)) assert emulator.passed == rows def test_total_rows(): """All 31 ROMs: 1,226 rows; the default core fails exactly C9's row.""" total = passed = 0 for name in TESTS: rom, _ = load(name) result = run_krom(rom) total += len(result.rows) passed += result.passed assert (total, passed) == (1226, 1225)