#!/usr/bin/env python3 """Milestone 1: run ZEXDOC or ZEXALL (ZEXALL-SMS v0.21) on the board. The programs print to the SDSC debug console (ports $FC/$FD), which the System captures; the VDP runs without rendering and the PSG unclocked, since only the console text matters. Each console line is echoed as it arrives, and the run ends when the program prints "Tests complete" (or a test fails, with --stop-on-error). python scripts/run_zex.py zexdoc # the image from tests/test_roms/github/ python scripts/run_zex.py zexall --machine sms1 The CRCs it checks against are those compiled into the program: Maxim's port was "run on a real SMS and ... noted the results" (docs/validation.md). """ from __future__ import annotations import argparse import sys import time import zipfile from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src")) from sms_python.board import MACHINES from sms_python.cartridge import Cartridge from sms_python.system import System ROOT = Path(__file__).resolve().parents[1] ARCHIVE = ROOT / "tests" / "test_roms" / "github" / "ZEXALL-SMS-0.21.zip" def main() -> int: parser = argparse.ArgumentParser(description=__doc__.split("\n\n")[0]) parser.add_argument("program", choices=["zexdoc", "zexall"]) parser.add_argument("--machine", choices=sorted(MACHINES), default="sms2") parser.add_argument("--stop-on-error", action="store_true") args = parser.parse_args() with zipfile.ZipFile(ARCHIVE) as archive: image = archive.read(f"{args.program}.sms") system = System(MACHINES[args.machine], Cartridge(image), sdsc_console=True, audio=False) system.board.vdp.render = False started = time.time() shown = 0 errors = 0 while True: system.run_cycles(3_579_545) # one emulated second between checks text = system.console lines = text[shown:].split("\n") for line in lines[:-1]: print(line, flush=True) if "ERROR" in line: errors += 1 shown = len(text) - len(lines[-1]) if "Tests complete" in text or (errors and args.stop_on_error): break elapsed = time.time() - started print( f"{args.program} on {system.board.machine.name}: {errors} errors; " f"{system.instructions:,} instructions, {system.cycles:,} cycles, {elapsed:,.0f} s " f"({sys.implementation.name} {sys.version.split()[0]})" ) return 1 if errors else 0 if __name__ == "__main__": sys.exit(main())