#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """Milestone 7: the Bankset Test Suite (its README, tier 3) on the board, both formats. The suite's programs alternate two demo effects (plasma, flames) every 4 s; its README lists the failure modes: a green screen with the CPU stopped (SALLY ran MARIA's set), blank blue / black screens alternating (MARIA shown SALLY's set), no title text (bank RAM), yellow with the CPU stopped (a BRK from a bad fetch). Each program is run from the NTSC BIOS (``.a78``: the header types it; ``.bin``: loaded with the description its README names, the way a user types a headerless image, ``--as``) to frame 900, with PNGs at frames 400, 520, 640 and 760 (2 s apart, both effects) kept in ``tests/detector_runs/m7-banksets/``. The judge, per program: every frame shows at least 4 colours (the README's blank screens show 2-3), frames 240 apart differ, the CPU is still executing at frame 900 (its PC changes), and the .a78 and the .bin give identical frames. The frames are looked at for the text lines the README names (recorded in docs/build-progress.md). Seeded fault ``maria-sees-sally``: MARIA reads SALLY's set; the README's "blank" failure mode must then appear. python scripts/m7_banksets.py [--fault maria-sees-sally] [--only 2x32K] """ from __future__ import annotations import argparse import io import sys import zipfile from pathlib import Path ROOT = Path(__file__).resolve().parents[1] sys.path.insert(0, str(ROOT / "src")) from a7800_python.cartridge import formats # noqa: E402 from a7800_python.cartridge.schemes import Bankset # noqa: E402 from a7800_python.system import System # noqa: E402 from a7800_python.television import Television, frame_png # noqa: E402 SUITE = ROOT / "reference/test_roms/Bankset_Test_Suite_v1.zip" OUT = ROOT / "tests/detector_runs/m7-banksets" SHOTS = (400, 520, 640, 760) # 2 s apart: two of each effect (4 s each) # The README's names, as hardware words for the headerless images. BIN_AS = { "2x32K": "linear,bankset", "2x32K Pokey4000": "linear,bankset,pokey@4000", "2x32K RAM Pokey800": "linear,bankset,bankram,pokey@800", "2x48K": "linear,bankset", "2x48K Pokey4000": "linear,bankset,pokey@4000", "2x52K": "linear,bankset", "2x52K Pokey4000": "linear,bankset,pokey@4000", "2x128K": "supergame,bankset,bank6@4000", "2x128K RAM": "supergame,bankset,bankram", "2x128K RAM Pokey800": "supergame,bankset,bankram,pokey@800", } # fmt: skip def run(name: str, data: bytes, override: str | None, fault: bool) -> tuple[bool, str]: overrides = formats.parse_as(override) if override else None system = System.from_rom(data, overrides=overrides) cart = system.board.cartridge if not isinstance(cart, Bankset): return False, f"loaded as {system.description.summary()} (not a bankset)" if fault: cart.maria = cart.sally tv = Television(system.board.maria, keep=1) shots = {} pcs = set() while tv.count < 900: before = tv.count while tv.count == before: system.step() if tv.count in SHOTS: shots[tv.count] = tv.frames[-1] if tv.count > 880: pcs.add(system.cpu.pc if hasattr(system, "cpu") else system.board.cpu.pc) OUT.mkdir(parents=True, exist_ok=True) stem = name.replace(" ", "_") + ("-fault" if fault else "") for n, frame in shots.items(): (OUT / f"{stem}-f{n}.png").write_bytes(frame_png(frame)) colours = [len({c for row in shots[n] for c in row}) for n in SHOTS] differ = shots[SHOTS[0]] != shots[SHOTS[2]] and shots[SHOTS[1]] != shots[SHOTS[3]] running = len(pcs) > 1 ok = min(colours) >= 4 and differ and running SEEN[name] = [shots[n] for n in SHOTS] return ok, f"colours {colours}, frames 240 apart differ {differ}, CPU running {running}" SEEN: dict[str, list] = {} def main() -> int: parser = argparse.ArgumentParser(description=__doc__.split("\n\n")[0]) parser.add_argument("--fault", choices=("maria-sees-sally",)) parser.add_argument("--only", default="") args = parser.parse_args() passed = total = 0 with zipfile.ZipFile(SUITE) as z: for member in sorted(z.namelist()): path = Path(member) if path.suffix not in (".a78", ".bin"): continue name = path.stem.replace("Bankset Test - ", "") if args.only and name not in args.only.split(","): continue label = f"{name} ({path.suffix[1:]})" override = BIN_AS[name] if path.suffix == ".bin" else None try: ok, detail = run(label, z.read(member), override, bool(args.fault)) except Exception as error: # noqa: BLE001 - a refusal is a result ok, detail = False, f"{type(error).__name__}: {error}" total += 1 passed += ok print(f"{label:28} {'ok ' if ok else 'FAIL'} {detail}", flush=True) # Both formats of one program must give the same frames (the .bin typed by the # README's description, the .a78 by its header). for label, frames in sorted(SEEN.items()): if label.endswith("(a78)"): twin = SEEN.get(label.replace("(a78)", "(bin)")) if twin is not None and twin != frames: passed -= 1 print(f"{label[:-6]}: the .a78 and .bin frames differ: FAIL") print(f"{passed} of {total} pass") return 0 if passed == total else 1 if __name__ == "__main__": sys.exit(main())