# SPDX-License-Identifier: GPL-3.0-or-later """Compile and run the GIME qualification and joystick exercise against a real CoCo 3 ROM.""" import argparse import os from pathlib import Path import re import subprocess import tempfile def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("runtime", type=Path) parser.add_argument("core", type=Path, help="current libVCCCore.a") parser.add_argument("rom", type=Path, help="privately supplied CoCo 3 BASIC ROM") parser.add_argument("--capture", type=Path, help="save the lander display to this PNG") parser.add_argument("--disk-roms", type=Path, help="also test disk EXEC with the local profile ROMs") args = parser.parse_args() fixture = Path(__file__).resolve().parent root = fixture.parents[2] runtime = args.runtime.resolve(strict=True) env = dict(os.environ, VCC_CMOC_COMPAT="0", PATH=str(runtime / "bin") + os.pathsep + os.environ["PATH"]) with tempfile.TemporaryDirectory(prefix="vcc-gime-") as tmp: work = Path(tmp) subprocess.run(["xcrun", "clang++", "-std=c++17", "-O2", "-mmacosx-version-min=14.0", "-I", root / "src", fixture / "run.cpp", args.core.resolve(strict=True), "-o", "run"], cwd=work, check=True) for optimization in ("-O0", "-O2"): for source, output in ((fixture / "qualification.c", "QUAL"), (root / "examples/cmoc/manual/lander.c", "LANDER")): subprocess.run([runtime / "bin/cmoc", "--coco", "--intermediate", optimization, "-Werror", "--org=2800", "-o", output + ".bin", source, "-lgime", "-lbgraph", "-lbcontrol"], cwd=work, env=env, check=True) symbols = dict(re.findall(r"^Symbol: _(\w+) \(.+?\) = ([0-9A-F]+)$", (work / "QUAL.map").read_text(), re.MULTILINE)) print("Checking", optimization, flush=True) subprocess.run(["./run", args.rom.resolve(strict=True), "QUAL.bin", "LANDER.bin", *(symbols[name] for name in ("stage", "advanceStage", "finishedFlips"))], cwd=work, check=True) if args.disk_roms: from disk import check_disk_launch check_disk_launch(runtime, args.core.resolve(strict=True), args.disk_roms.resolve(strict=True), work, work / "LANDER.bin") if args.capture: args.capture.parent.mkdir(parents=True, exist_ok=True) subprocess.run(["sips", "-s", "format", "png", work / "lander.bmp", "--out", args.capture], check=True, stdout=subprocess.DEVNULL) if __name__ == "__main__": main()