#!/usr/bin/env python # SPDX-License-Identifier: MIT """Fetch the references this repository's documents cite, at their pins. python -I scripts/fetch_references.py # fetch what is missing python -I scripts/fetch_references.py --verify # only check what is there python -I scripts/fetch_references.py --only IKAOPM Everything lands in ``reference/`` (git-ignored) and is never committed: repositories under ``reference/src/`` at a commit hash, single files under ``reference/docs/`` and ``reference/files/`` checked by SHA-256. What each one is for, its licence and how it may be used are in docs/provenance.md. Standard library only. Downloads are untrusted data: nothing fetched is run by this script. Nuked-OPM is not fetched (Aubrey, 2026-11-24): the referee is built and run only in emu-tools-gpl (nuked-harness's opm-events, under EMU_TOOLS_GPL), as a closed box whose source is never opened (docs/restart.md). It is cited as nukeykt/Nuked-OPM at f209e6ed3712032b641d53ce8fb24824eae6adc3. """ from __future__ import annotations import argparse import hashlib import subprocess import sys import urllib.request from pathlib import Path ROOT = Path(__file__).resolve().parent.parent REFERENCE = ROOT / "reference" USER_AGENT = "reference-fetch/1.0" #: Git repositories, each at one commit. ``why`` is a reminder, not the record. REPOS = [ # Nuked-OPM (the referee, f209e6e) is not fetched since 2026-11-24 (Aubrey): it is # built and run only in emu-tools-gpl. { "path": "src/IKAOPM", "url": "https://github.com/ika-musume/IKAOPM", "rev": "08a5b40ed14418319287df450f7d4a523ddeed5e", "why": "A die-derived YM2151 in Verilog with a traced schematic: the readable " "die source. BSD-2-Clause: code OK with its notice kept (NOTICE).", }, # jt51 (jotego, GPL-3.0, 2ca6601) is not fetched since 2026-11-24 (Aubrey): no # closed-box source in an MIT repository; docs/validation.md cites it by URL and commit. { "path": "src/ymfm", "url": "https://github.com/aaronsgiles/ymfm", "rev": "81aec25ccbb98f4873a255f7551ac4dadac59b4a", "why": "Aaron Giles's FM family; ymfm_opm.* is MAME 0.285's YM2151. " "BSD-3-Clause: code OK with its notice kept (NOTICE).", }, ] #: Single files, each checked by SHA-256. FILES = [ { "path": "docs/YM2151_199112.pdf", "url": "https://bitsavers.org/components/yamaha/YM2151_199112.pdf", "sha256": "9c15c4be47cc1b4dbcc61d81d4275248fab604b52ec4b687889096a00c873216", "why": "Yamaha's YM2151 catalog (data sheet), LSI-2121512, 1991-12, 10 pages.", }, { "path": "docs/yamaha_ym2151_synthesis.pdf", "url": "https://map.grauw.nl/resources/sound/yamaha_ym2151_synthesis.pdf", "sha256": "ec3d9b0f1934873b49e1f3820b7cde9aa1bfff6d917fb2a8a09be609fcee8640", "why": "Yamaha's YM2151 application manual, 31 scanned pages, no text layer.", }, { "path": "files/mame0285/ymopm.cpp", "url": "https://raw.githubusercontent.com/mamedev/mame/mame0285/src/devices/sound/ymopm.cpp", "sha256": "96c7de5f7fb4786752eab192f89be1b78a18e040ea3b62795f2e172115fcc8e1", "why": "MAME 0.285's YM2151/YM2164 devices: thin wrappers over ymfm. BSD-3-Clause.", }, { "path": "files/mame0285/ymopm.h", "url": "https://raw.githubusercontent.com/mamedev/mame/mame0285/src/devices/sound/ymopm.h", "sha256": "bc60e520046579807e6c45bac71c3182e8fd87afd717d1045565bc2bfca71b6b", "why": "As above.", }, { "path": "files/mame0285/ymfm_mame.h", "url": "https://raw.githubusercontent.com/mamedev/mame/mame0285/src/devices/sound/ymfm_mame.h", "sha256": "7f91742fdc5cbd643e986b73a3ad126eb4984133d597066451b1b55449e37a48", "why": "How MAME 0.285 gives ymfm its timers and BUSY. BSD-3-Clause.", }, { "path": "files/mame0285/ymfm_opm.cpp", "url": "https://raw.githubusercontent.com/mamedev/mame/mame0285/3rdparty/ymfm/src/ymfm_opm.cpp", "sha256": "2235d57101d26cdd70d4021fd1f3b8116faeba6fd5efb2ca83ba3be1298b22dc", "why": "MAME 0.285's copy of ymfm's OPM: byte-identical to ymfm @ 81aec25.", }, { "path": "web-archive/siliconpr0n-ym2151.html", "url": "https://web.archive.org/web/20250114134429id_/" "https://siliconpr0n.org/archive/doku.php?id=mcmaster:yamaha:ym2151", "sha256": "863c5f409b5cf0eb8b65a61d63b19b80ec321ebc832ee3403da280e2d6e9314d", "why": "John McMaster's YM2151 decap page (siliconpr0n), through the Wayback " "Machine because the site answers scripts with a bot challenge: package " "marking, die label, links to the die maps (not fetched: 40 and 200 MiB).", }, ] #: MAME 0.285 driver files cited in docs/users.md for how boards wire the chip #: (clock, /IRQ, CT pins). (folder, file, sha256); they land in #: ``reference/files/mame0285-drivers/_``. Every file listed has a #: BSD-3-Clause header (checked 2026-11-19); GPL-2.0+ drivers (taito/opwolf.cpp, #: taito/rastan.cpp) were dropped from the list and are not read. MAME_DRIVERS = [ ("atari", "atarijsa.cpp", "7b3b7ea04c3d99575f94bf59e8cfada6e1e60f40e819558b5de0eb23b12697c3"), ("atari", "atarisy1.cpp", "04ca78b412f3b44df84a9695a28ddb5a38845f2e11c6388c4255ee84d28c78bb"), ("atari", "atarisy2.cpp", "f934bcdfc1edab4a4c558a32f0a19a3e401346f31470ec89d9a252907440092e"), ("atari", "gauntlet.cpp", "22b6c1f748b4f9150b18d3e7405f5f7082cf47070b041397cdf4f67d5900dfbf"), ("capcom", "cps1.cpp", "e0b6df00a7d0efccc91bfe9c3e752ec36c6edc8c98757331d1f1ebc6f739532e"), ("dataeast", "cninja.cpp", "c004a844394d8bed3709eb924685f8122ce40371329936b088ae41205718b4e1"), ("irem", "m72.cpp", "70cf7772f0c7550e4fe6897f707d264097a600b991adc1b4562029c21084f9dc"), ("jaleco", "megasys1.cpp", "6193f0b0614249724e472157a2a7455f3ace74d9bfa4a94d74d9d14c7bbbe8a0"), ("konami", "88games.cpp", "0b5d6164731ce630968dcd11006c3501c4fd132258b40f14b3da370622ac8f9c"), ("konami", "aliens.cpp", "8d05219768d6e6c83953feb960ac2f64b45a19ff3a76fb7d81989e4b066afc16"), ("konami", "thunderx.cpp", "9444d1ba9f6d478660523037b9af55b4f96ba540a93e545f36c97fa34f94881d"), ("konami", "tmnt.cpp", "fdae7c74c4fa568e4fddbb0ccc8920cae8f5ccaf86fe3d07c9584e863df04f96"), ("konami", "twin16.cpp", "d70425135d0f2c067ec98005bef5374524bc18630e548dd3d2686d11737c29c1"), ("midway", "williams.cpp", "e41d5fc979197bd6ef51a0ad3c8398e964b651318472d4f64e9d30d7a9504731"), ("namco", "namcos2.cpp", "3c0ecd7e6333eee0b34082b61113f89248d4dc3020f5bfdc073b4026c5721f47"), ("nmk", "nmk16.cpp", "c7d8a3f165536f2bb1b47158bf1fb59a3e7682fa26cf7529b69e5623172394bf"), ("sega", "segaorun.cpp", "03df4e6a04cc122680bfdab1f2bc0a1d6c8db1b365a872171a30537cbb9cc0a6"), ("sega", "segas16b.cpp", "a860cae4108645b1aa8405d4ddecda4236ae54064e0252ec43b92aa9f8b68756"), ("shared", "williamssound.cpp", "84c02fa507b97606c2ba244b717e0e180c429a4a5b76a88d10ee8b5c40a5a831"), ("sharp", "x68k.cpp", "dc5cf3b80db5c618f7d59fb207e54364cc6ad93aa97bbc69ef631d72e7ebd59f"), ("technos", "ddragon.cpp", "7a224ff22e411ccca4ce1c7d411567e1b9080073d6672ff2238c48ffb9114ba1"), ("toaplan", "raizing.cpp", "1349fc0ef4a4bb5632ff214f02120608c4aaa1b6b73a2c14036328fe3bb53731"), ] FILES += [ { "path": f"files/mame0285-drivers/{folder}_{name}", "url": f"https://raw.githubusercontent.com/mamedev/mame/mame0285/src/mame/{folder}/{name}", "sha256": digest, "why": "A MAME 0.285 driver: how a board wires the YM2151.", } for folder, name, digest in MAME_DRIVERS ] def head(path: Path) -> str | None: if not (path / ".git").exists(): return None result = subprocess.run( ["git", "-C", str(path), "rev-parse", "HEAD"], capture_output=True, text=True ) return result.stdout.strip() or None def fetch_repo(entry: dict, verify: bool) -> bool: path = REFERENCE / entry["path"] rev = entry["rev"] if head(path) == rev: print(f"{entry['path']}: at {rev[:7]}") return True if verify: print(f"{entry['path']}: missing or not at {rev[:7]}") return False path.mkdir(parents=True, exist_ok=True) git = ["git", "-C", str(path)] if not (path / ".git").exists(): subprocess.run([*git, "init", "-q"], check=True) subprocess.run([*git, "fetch", "-q", "--depth", "1", entry["url"], rev], check=True) subprocess.run([*git, "checkout", "-q", "--detach", "FETCH_HEAD"], check=True) if head(path) != rev: print(f"{entry['path']}: fetched the wrong revision") return False print(f"{entry['path']}: fetched {rev[:7]}") return True def sha256(path: Path) -> str: digest = hashlib.sha256() with path.open("rb") as handle: for block in iter(lambda: handle.read(1 << 20), b""): digest.update(block) return digest.hexdigest() def fetch_file(entry: dict, verify: bool) -> bool: path = REFERENCE / entry["path"] want = entry["sha256"] if path.exists() and sha256(path) == want: print(f"{entry['path']}: sha256 {want[:12]}") return True if verify: print(f"{entry['path']}: missing or changed (want sha256 {want[:12]})") return False if path.exists(): print(f"{entry['path']}: present with another hash; move it to trash/ and rerun") return False path.parent.mkdir(parents=True, exist_ok=True) request = urllib.request.Request(entry["url"], headers={"User-Agent": USER_AGENT}) with urllib.request.urlopen(request, timeout=120) as response: data = response.read() got = hashlib.sha256(data).hexdigest() if got != want: print(f"{entry['path']}: the download has sha256 {got}, not the pin; not kept") return False path.write_bytes(data) print(f"{entry['path']}: fetched, sha256 {want[:12]}") return True def main(argv: list[str] | None = None) -> int: parser = argparse.ArgumentParser(description=__doc__.split("\n\n")[0]) parser.add_argument("--verify", action="store_true", help="check, do not fetch") parser.add_argument("--only", help="fetch only entries whose path contains this text") args = parser.parse_args(argv) bad = 0 for entry in REPOS: if args.only and args.only not in entry["path"]: continue bad += not fetch_repo(entry, args.verify) for entry in FILES: if args.only and args.only not in entry["path"]: continue bad += not fetch_file(entry, args.verify) return 1 if bad else 0 if __name__ == "__main__": sys.exit(main())