# SPDX-License-Identifier: MIT # Relies on the Acid800 suite's label names and verdict codes (MIT, Copyright (C) # 2010-2022 Avery Lee); its notice is in NOTICE. No suite file is committed. """Acid5200 harness: run one standalone test ROM headless, read its verdict. Acid800 1.2 (MIT, Avery Lee) builds each 5200 test as an 8K cartridge at $A000 (``src/Acid5200/source/sacartridge.s``). The cartridge boots through the BIOS logo, runs the test, and ends in ``_jam`` (an endless ``JMP *``) with Y = $00 pass, $80 fail, $40 skipped (``src/Acid800/source/library.s``, ``_testPassed``, ``_testFailed``, ``_testSkipped``). Its text goes to a 40 x 24 screen whose row addresses are at $0380 (low) and $0398 (high) (``display5200.s``). The harness takes ``_jam``'s address from the ROM's label file and reads the verdict and the screen from memory. Tier 3: the suite's author states the tests pass on real hardware; no recorded 5200 run exists (U7). The harness's addresses and verdict codes are DOC (the suite's MIT sources, files named above); its verdicts are TEST ROM. """ from __future__ import annotations import time from dataclasses import dataclass from pathlib import Path from .system import Console DEFAULT_DIR = Path(__file__).resolve().parents[2] / "tests/test_roms/acid800/out/Release/Acid5200" VERDICTS = {0x00: "pass", 0x80: "fail", 0x40: "skipped"} @dataclass class AcidResult: name: str verdict: str # pass | fail | skipped | timeout | jam text: str frames: int cycles: int seconds: float def __str__(self) -> str: lines = [ln for ln in self.text.splitlines() if ln.strip()] tail = " | ".join(lines[-3:]) return f"{self.name}: {self.verdict} ({self.frames} frames) {tail}" def labels(path: Path) -> dict[str, int]: table = {} for line in path.read_text("latin-1").splitlines(): parts = line.split() if len(parts) >= 3: try: table[parts[2]] = int(parts[1], 16) except ValueError: continue return table def screen_text(board) -> str: ram = board.ram rows = [] for row in range(24): address = ram[0x380 + row] | ram[0x398 + row] << 8 chars = [] for col in range(40): code = board.peek((address + col) & 0xFFFF) & 0x7F if code < 0x40: code += 0x20 elif code < 0x60: code -= 0x40 chars.append(chr(code) if 32 <= code < 127 else ".") rows.append("".join(chars).rstrip()) return "\n".join(rows) def run_test( name: str, directory: Path = DEFAULT_DIR, max_frames: int = 1500, console_hook=None, ) -> AcidResult: rom = directory / "standalone" / f"{name}.rom" jam = labels(rom.with_suffix(".lab"))["_jam"] console = Console(rom, mapping="8k") if console_hook is not None: console_hook(console) board = console.board cpu = board.cpu limit = board.machine.cycles_per_frame * max_frames start = time.perf_counter() step = cpu.step verdict = "timeout" while board.cycles < limit: step() if cpu.pc == jam: verdict = VERDICTS.get(cpu.y, f"y={cpu.y:02x}") break if cpu.halted: verdict = "jam" break # Let the screen settle for the text (the result was printed before _jam). return AcidResult( name=name, verdict=verdict, text=screen_text(board), frames=board.frames, cycles=board.cycles, seconds=time.perf_counter() - start, ) def run_full(directory: Path = DEFAULT_DIR, max_frames: int = 6000) -> tuple[str, int]: """Run the whole suite (``acid5200.rom``, 32K) until its summary line; (screen, frames).""" console = Console(directory / "acid5200.rom") board = console.board text = "" while board.frames < max_frames: console.run_frames(30) text = screen_text(board) if "All tests complete" in text: break return text, board.frames def all_tests(directory: Path = DEFAULT_DIR) -> list[str]: return sorted(p.stem for p in (directory / "standalone").glob("*.rom")) def main(argv: list[str] | None = None) -> int: import argparse parser = argparse.ArgumentParser(description="Run Acid5200 standalone tests") parser.add_argument("tests", nargs="*", help="test names or prefixes (default: all)") parser.add_argument("--dir", type=Path, default=DEFAULT_DIR) parser.add_argument("--frames", type=int, default=1500) parser.add_argument("--text", action="store_true", help="print the whole screen") parser.add_argument("--fault", action="append", default=[], help="seed a board fault") parser.add_argument( "--switch", action="append", default=[], help="NAME=0|1: set a named board switch" ) parser.add_argument("--full", action="store_true", help="run acid5200.rom to its summary") args = parser.parse_args(argv) if args.full: text, frames = run_full(args.dir) print(text) print(f"[{frames} frames]") return 0 if "Failed: 0" in text else 1 names = all_tests(args.dir) if args.tests: names = [n for n in names if any(n == t or n.startswith(t) for t in args.tests)] def hook(console): console.board.faults.update(args.fault) for item in args.switch: name, _, value = item.partition("=") if not hasattr(console.board, name): raise SystemExit(f"no board switch {name!r}") setattr(console.board, name, bool(int(value or "1"))) passed = 0 for name in names: result = run_test(name, args.dir, args.frames, hook) passed += result.verdict == "pass" print(f"{result} [{result.seconds:.1f}s]", flush=True) if args.text: print(result.text) print(f"{passed}/{len(names)} pass") return 0 if passed == len(names) else 1 if __name__ == "__main__": raise SystemExit(main())