#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """Build the gate's synthetic inputs into ``external/inputs/`` (never committed). - The C23 probe: the reference's ``probes/dliprobe.s`` (at d6b220d, from the clone in ``external/a7800-python``), assembled with ca65/ld65 (cc65 2.19, ``$CC65_DIR`` or ``~/.local/opt/cc65-2.19/bin``) for NTSC and PAL, as the reference's ``scripts/dli_probe.py`` builds it (``-DPAL=0/1``, ``probes/probe.cfg``), with an A78 header in front that states the payload as that script's ``a78.build`` does (written here byte for byte from the A78 v4 layout: linear, no options, region). - The Bankset Test Suite's ``.a78`` programs (its v1 zip, read in place from the reference checkout's fetched ``reference/test_roms/``, ``$BANKSET_SUITE`` to move it). python3 scripts/inputs.py """ from __future__ import annotations import os import subprocess import zipfile from pathlib import Path ROOT = Path(__file__).resolve().parents[1] REF = ROOT / "external" / "a7800-python" OUT = ROOT / "external" / "inputs" CC65 = Path(os.environ.get("CC65_DIR", Path.home() / ".local/opt/cc65-2.19/bin")) SUITE = Path(os.environ.get( "BANKSET_SUITE", ROOT.parent / "a7800-python/reference/test_roms/Bankset_Test_Suite_v1.zip")) def a78_header(payload: bytes, title: str, pal: bool) -> bytes: """The reference's ``a78.build`` for a linear, option-free description.""" out = bytearray(128) out[0] = 4 out[1:10] = b"ATARI7800" out[17:49] = title.encode("latin-1")[:32].ljust(32, b"\0") out[49:53] = len(payload).to_bytes(4, "big") out[55] = out[56] = 1 # ProLine, ProLine out[57] = 1 if pal else 0 out[100:128] = b"ACTUAL CART DATA STARTS HERE" return bytes(out) def main() -> int: OUT.mkdir(parents=True, exist_ok=True) for pal in (False, True): name = "dli-pal" if pal else "dli-ntsc" obj, binary = OUT / f"{name}.o", OUT / f"{name}.bin" subprocess.run([str(CC65 / "ca65"), f"-DPAL={int(pal)}", "-o", str(obj), str(REF / "probes/dliprobe.s")], check=True) subprocess.run([str(CC65 / "ld65"), "-C", str(REF / "probes/probe.cfg"), "-o", str(binary), str(obj)], check=True) rom = binary.read_bytes() (OUT / f"{name}.a78").write_bytes(a78_header(rom, f"dliprobe {name}", pal) + rom) print(f"{name}.a78: {len(rom)} bytes") banksets = OUT / "banksets" banksets.mkdir(exist_ok=True) with zipfile.ZipFile(SUITE) as z: for info in z.infolist(): if info.filename.endswith(".a78"): target = banksets / Path(info.filename).name target.write_bytes(z.read(info)) print(f"banksets/{target.name}: {info.file_size} bytes") return 0 if __name__ == "__main__": raise SystemExit(main())