#!/usr/bin/env python # SPDX-License-Identifier: MIT """Fetch the YM2610's judges, detectors and documents into ``reference/``. python scripts/fetch_references.py # fetch what is missing python scripts/fetch_references.py --verify # only check what is there python scripts/fetch_references.py --repin # rewrite scripts/reference-pins.sha256 Everything lands in ``reference/`` (git-ignored) and is never committed. Repositories are pinned by commit here; single files by SHA-256 in ``scripts/reference-pins.sha256`` (sha256sum format, committed). An entry marked ``live`` is a page anyone may edit: a mismatch there means the page changed since the pin, and is reported without failing. No entry is live since 2026-11-26, when the Neo Geo Development Wiki's pages and the YM3016 sheet it hosted were set aside (docs/provenance.md, "Author respect"); the YM3016's pages are cited from the 1990 LSI catalogue instead. Licences and uses are stated per entry (docs/restart.md has the rules). The one die model fetched, YM2608-LLE, is GPL-2.0: CLOSED BOX ONLY, built and driven through its header, its source files never opened; it is still fetched because validation/build_referees.sh compiles the referee from it. YM2203-LLE and Nuked-OPN2 are not fetched (Aubrey, 2026-11-24); docs/provenance.md cites them by upstream commit. The readable code is BSD-3 (ymfm, Geolith's ymfm_opn.c, MAME 0.285's ymopn.*), used with its notice. The Yamaha manual transcriptions and the catalogue carry no licence: facts only, cited, not copied. The GPL and non-commercial emulators the first repository pinned (MAME 0.229 fm.cpp/ymdeltat.cpp, FinalBurn Neo, jt12) are no longer fetched. """ 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" AGENT = "Mozilla/5.0 (X11; Linux x86_64) reference-fetch" MAME_0285 = "f379cd060ac3b2bd567ebbd0957aed059d6895ff" # tag mame0285 GEOLITH = "05ddef568212e7225ceec22f3ecb20b5a9b640e6" PINS = ROOT / "scripts" / "reference-pins.sha256" def mame(rev: str, path: str) -> str: return f"https://raw.githubusercontent.com/mamedev/mame/{rev}/{path}" def geolith(path: str) -> str: return f"https://gitlab.com/jgemu/geolith/-/raw/{GEOLITH}/{path}" REPOS = [ # YM2608-LLE (nukeykt, 7a2aca7, the judge), YM2203-LLE (817387f) and Nuked-OPN2 # (335747d) are not fetched since 2026-11-24 (Aubrey): the die models run only through # the family's GPL tools. YM2608-LLE's YM2610 build is the tool's own # ($EMU_TOOLS_GPL2/tools/ym2608-lle/build.sh, called by validation/build_referees.sh). { "path": "src/ymfm", "url": "https://github.com/aaronsgiles/ymfm", "rev": "81aec25ccbb98f4873a255f7551ac4dadac59b4a", "why": "Aaron Giles's Yamaha FM cores (MAME's since 0.230), with ADPCM-A/B. " "BSD-3-Clause: code OK with its notice kept (NOTICE).", }, ] FILES = [ # --- manufacturer documents, as the community carries them --------------- { "path": "docs/ajworld-ym2610am_en.html", "url": "http://www.ajworld.net/neogeodev/ym2610am_en.html", "why": "Yamaha, YM2610 Application Manual (1995-01-20 print), an HTML " "transcription partly translated to English. No licence.", }, { "path": "docs/YM2608J_Translated.pdf", "url": "https://csclub.uwaterloo.ca/~pbarfuss/YM2608J_Translated.PDF", "why": "Yamaha, YM2608 OPNA Application Manual, machine-translated (56 " "pages): FM, timers, ADPCM (the YM2610's ADPCM-B), the ADPCM " "algorithm, status flags. No licence.", }, { "path": "docs/1990_Yamaha_LSI_Condensed_Catalog.pdf", "url": "https://bitsavers.org/components/yamaha/1990_Yamaha_LSI_Condensed_Catalog.pdf", "why": "Yamaha's 1990 LSI catalogue (bitsavers scan, OCR layer): the " "one-paragraph manufacturer descriptions of the OPN family and DACs, and " "the YM3016 sheet (printed pp. 32-33).", }, # --- permissive code: readable with notice ------------------------------- { "path": "src/mame-0285/ymopn.cpp", "url": mame(MAME_0285, "src/devices/sound/ymopn.cpp"), "why": "MAME 0.285's device wrapper around ymfm (clock, streams, ROM " "regions). BSD-3-Clause.", }, { "path": "src/mame-0285/ymopn.h", "url": mame(MAME_0285, "src/devices/sound/ymopn.h"), "why": "Its header.", }, { "path": "src/geolith/ymfm_opn.c", "url": geolith("src/ymfm/ymfm_opn.c"), "why": "Geolith's YM2610 including ADPCM-A/B: Rupert Carmichael's C port of " "ymfm. BSD-3-Clause: code OK with its notice kept (NOTICE).", }, # The Neo Geo Development Wiki's 11 pages and its YM3016.pdf were pinned here # until 2026-11-26 (set aside for author respect: docs/provenance.md). ] def sha256(path: Path) -> str: return hashlib.sha256(path.read_bytes()).hexdigest() def head(path: Path) -> str | None: if not (path / ".git").exists(): return None done = subprocess.run( ["git", "-C", str(path), "rev-parse", "HEAD"], capture_output=True, text=True ) return done.stdout.strip() or None def fetch_repo(entry: dict, verify: bool) -> bool: path = REFERENCE / entry["path"] short = entry["rev"][:7] if head(path) == entry["rev"]: print(f"ok {entry['path']} @ {short}") return True if verify: print(f"MISSING {entry['path']} (want {short})") 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"], entry["rev"]], check=True) subprocess.run([*git, "checkout", "-q", "--detach", "FETCH_HEAD"], check=True) good = head(path) == entry["rev"] print(f"{'fetched ' if good else 'WRONG '} {entry['path']} @ {short}") return good def read_pins() -> dict[str, str]: if not PINS.exists(): return {} pins = {} for line in PINS.read_text().splitlines(): digest, _, name = line.partition(" ") pins[name] = digest return pins def fetch_file(entry: dict, verify: bool, pins: dict[str, str]) -> bool: path = REFERENCE / entry["path"] if not path.exists() or path.stat().st_size == 0: if verify: print(f"MISSING {entry['path']}") return bool(entry.get("optional")) path.parent.mkdir(parents=True, exist_ok=True) request = urllib.request.Request(entry["url"], headers={"User-Agent": AGENT}) try: with urllib.request.urlopen(request, timeout=90) as response: path.write_bytes(response.read()) except OSError as error: print(f"FAILED {entry['path']}: {error}") return bool(entry.get("optional")) digest = sha256(path) pinned = pins.get(entry["path"]) if pinned is None: print(f"unpinned {entry['path']} {digest}") return True if digest == pinned: print(f"ok {entry['path']}") return True if entry.get("live"): print(f"changed {entry['path']} (a live page, edited since the pin)") return True print(f"MISMATCH {entry['path']}: {digest}") return False 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("--repin", action="store_true", help="rewrite the SHA-256 pins") args = parser.parse_args(argv) if args.repin: lines = [ f"{sha256(REFERENCE / entry['path'])} {entry['path']}" for entry in FILES if (REFERENCE / entry["path"]).exists() ] PINS.write_text("\n".join(lines) + "\n") print(f"wrote {len(lines)} pins to {PINS.relative_to(ROOT)}") return 0 pins = read_pins() good = [fetch_repo(entry, args.verify) for entry in REPOS] good += [fetch_file(entry, args.verify, pins) for entry in FILES] return 0 if all(good) else 1 if __name__ == "__main__": sys.exit(main())