#!/usr/bin/env python3 """Fetch the pinned MAME sources this repository's documents rest on. Everything in docs/ that is attributed to MAME is attributed to three files at one commit. This script fetches exactly those three, verifies each against a SHA-256 recorded here, and leaves them in a gitignored directory. Nothing it downloads is committed: MAME is BSD-3-Clause and belongs upstream. python scripts/fetch_sources.py # fetch and verify python scripts/fetch_sources.py --check # verify what is already there The pin is MAME release 0.285, annotated tag `mame0285`, which resolves to commit f379cd060ac3b2bd567ebbd0957aed059d6895ff (2026-01-29, Vas Crabb). That is the same release as the `/usr/games/mame` binary used for docs/mame-oracle.md, which reports "0.285 (unknown)". """ from __future__ import annotations import argparse import hashlib import pathlib import sys import urllib.request MAME_TAG = "mame0285" MAME_COMMIT = "f379cd060ac3b2bd567ebbd0957aed059d6895ff" RAW = "https://raw.githubusercontent.com/mamedev/mame/{commit}/{path}" # path in the MAME tree -> sha256 of the file at MAME_COMMIT FILES = { "src/devices/cpu/mcs48/mcs48.cpp": "29d5a0530edba19dcdbe8de8360edb366e9f237a0ab5ca703d71e48bb87ad09b", "src/devices/cpu/mcs48/mcs48.h": "a660900d63594fc4aeed956a838af2d297c50782d2509cc65c712606e51c652f", "src/devices/cpu/mcs48/mcs48dsm.cpp": "54cf5795d109d92901c9c2b7dc08c59e322ba064c2ce2a59d48d9d8ed6ddf959", # The Donkey Kong driver and its audio section: the source of the # "8035 at 6 MHz" figure and of the sound board's port map. "src/mame/nintendo/dkong.h": "05b3f635177de567df97ce1350b023352ddcd7cd9a98fef4975e2ed3c985a089", "src/mame/nintendo/dkong_a.cpp": "a381457eac2b0777c3c8a61bedcb16057ba6f89d06b34ba3df81f0c406228c4b", } DEST = pathlib.Path(__file__).resolve().parent.parent / "vendor" / "mame" def sha256(data: bytes) -> str: return hashlib.sha256(data).hexdigest() def fetch(path: str) -> bytes: url = RAW.format(commit=MAME_COMMIT, path=path) with urllib.request.urlopen(url, timeout=120) as response: return response.read() def main() -> int: parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--check", action="store_true", help="verify files already present; do not download") args = parser.parse_args() DEST.mkdir(parents=True, exist_ok=True) failures = 0 for path, expected in FILES.items(): local = DEST / pathlib.PurePosixPath(path).name if args.check: if not local.exists(): print(f"MISSING {local}") failures += 1 continue data = local.read_bytes() else: data = fetch(path) got = sha256(data) if expected == "PENDING": print(f"UNPINNED {local.name} sha256={got}") elif got != expected: print(f"MISMATCH {local.name}\n expected {expected}\n got {got}") failures += 1 continue else: print(f"ok {local.name} {len(data):,} bytes") if not args.check: local.write_bytes(data) if failures: print(f"\n{failures} file(s) failed verification.", file=sys.stderr) return 1 print(f"\nMAME {MAME_TAG} @ {MAME_COMMIT[:12]} -> {DEST}") return 0 if __name__ == "__main__": raise SystemExit(main())