# SPDX-License-Identifier: MIT """Census the Konami TMNT-era 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 # the five drivers MAME_ROMPATH=... python -I scripts/census.py --parents # one table row per parent MAME_ROMPATH=... python -I scripts/census.py --nv # factory EEPROM images Adapted from namcos2-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/tmnt.cpp", "konami/tmnt2.cpp", "konami/simpsons.cpp", "konami/xmen.cpp", "konami/aliens.cpp") CHIPS = ("m68000", "konami_cpu", "z80", "ym2151", "k007232", "k053260", "k054539", "upd7759", "samples", "k052109", "k051960", "k053244", "k053247", "k053251", "k053936", "k054000", "k054321", "er5911_8", "eeprom_serial_93cxx_16bit") 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") 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} {m.get('sourcefile'):22} {len(roms):3} roms {drv:10} {state:9} {tag}") 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()