# SPDX-License-Identifier: MIT """Census the Konami System GX romsets in $MAME_ROMPATH, read in place. MAME is a closed box: machine descriptions come from `mame -listxml` (run here), never from its source. Each set's zip is opened read-only and every member is checked against the description by CRC32 and by SHA-1 (computed here). Nothing is copied. MAME_ROMPATH=... python -I scripts/census.py # every konamigx.cpp set MAME_ROMPATH=... python -I scripts/census.py --parents # one table row per parent MAME_ROMPATH=... python -I scripts/census.py --nv # factory EEPROM images MAME_ROMPATH=... python -I scripts/census.py --bios # the shared firmware set Adapted from konami68k-python's census.py (the family's own MIT tooling). """ from __future__ import annotations import argparse import hashlib import os import subprocess import sys import xml.etree.ElementTree as ET import zipfile import zlib DRIVERS = ("konami/konamigx.cpp",) # Device short names as `-listxml` gives them in . CHIPS = ("m68ec020", "m68000", "tms57002", "k054539", "okim6295", "k056832", "k055673", "k055555", "k054338", "k053252", "k056800", "adc0834", "gfxdecode", "timer", "93c46_16") def sets_for_sources(sources): out = subprocess.run(["mame", "-listsource"], capture_output=True, text=True, check=True).stdout return [p[0] for p in (line.split() for line in out.splitlines()) if len(p) == 2 and p[1] in sources] def rompaths(): raw = os.environ.get("MAME_ROMPATH") if not raw: sys.exit("set MAME_ROMPATH (a non-merged MAME romset directory; ';' separates several)") return [p for p in raw.split(";") if p] def find_zip(name, paths): for p in paths: z = os.path.join(p, name + ".zip") if os.path.exists(z): return z return None def members(zpath): found = {} with zipfile.ZipFile(zpath) as z: for info in z.infolist(): data = z.read(info) found[f"{zlib.crc32(data):08x}"] = (info.filename, hashlib.sha1(data).hexdigest(), len(data)) return found def main(): ap = argparse.ArgumentParser() ap.add_argument("sources", nargs="*", default=list(DRIVERS)) ap.add_argument("--parents", action="store_true", help="print a row per parent") ap.add_argument("--nv", action="store_true", help="list factory EEPROM image SHA-1s") ap.add_argument("--bios", action="store_true", help="list the BIOS set's ROMs") a = ap.parse_args() names = sets_for_sources(set(a.sources)) root = ET.fromstring(subprocess.run(["mame", "-listxml", *names], capture_output=True, check=True).stdout) paths = rompaths() totals = {"sets": 0, "present": 0, "complete": 0, "bytes": 0, "nodump": 0} nv = {} status = {} for m in root.iter("machine"): name = m.get("name") if name not in names: continue totals["sets"] += 1 drv = m.find("driver").get("status") status[drv] = status.get(drv, 0) + 1 totals["nodump"] += sum(1 for r in m.findall("rom") if r.get("status") == "nodump") roms = [r for r in m.findall("rom") if r.get("status") != "nodump"] zpath = find_zip(name, paths) devs = {d.get("name") for d in m.iter("device_ref")} tag = " ".join(c for c in CHIPS if c in devs) if zpath is None: print(f"{name:12} MISSING {tag}") continue totals["present"] += 1 totals["bytes"] += os.path.getsize(zpath) have = members(zpath) bad = [] for r in roms: hit = have.get(r.get("crc")) if hit is None or hit[1] != r.get("sha1"): bad.append(r.get("name")) elif r.get("region") == "eeprom": nv[name] = (r.get("name"), r.get("size"), r.get("sha1")) totals["complete"] += not bad state = "complete" if not bad else "INCOMPLETE " + ",".join(bad) print(f"{name:12} {len(roms):3} roms {drv:12} {state:9} {tag}") if a.bios and m.get("isbios") == "yes": for r in roms: print(f" BIOS | {r.get('name')} | {r.get('size')} | {r.get('sha1')}") if a.parents and not m.get("cloneof"): clones = [c.get("name") for c in root.iter("machine") if c.get("cloneof") == name] print(f" PARENT | {name} | {len(clones)} | {m.findtext('year')} | " f"{m.findtext('description')} | {tag}") print("totals", totals, "status", status) if a.nv: for name, (fn, size, sha1) in sorted(nv.items()): print(f"nv {name:12} {fn:22} {size:>4} {sha1}") if __name__ == "__main__": main()