#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """Census the Midway TMS34010 boards in MAME's machine list and in $MAME_ROMPATH. Reads the output of ``mame -listxml`` (a closed-box run of the installed MAME binary; the XML is MAME's description of its own sets, not source code), keeps the machines whose ``sourcefile`` is one of the Midway Y/T/Wolf/X-unit drivers, and for each one reports: parent or clone, year, the CPUs and sound chips with their clocks, the ROM regions and their sizes, ROMs MAME marks ``nodump`` or ``baddump``, and whether the set is present in ``$MAME_ROMPATH`` with every file's SHA-1 matching. Nothing is copied; zip members are hashed in place. mame -listxml > tests/mame_traces/listxml-full.xml # once, about 300 MB python3 -I scripts/census_mame.py tests/mame_traces/listxml-full.xml \\ --json tests/mame_traces/census.json > docs/census-table.txt The romset directory comes only from the ``MAME_ROMPATH`` environment variable (a non-merged set: one zip per machine holding every file the machine needs). """ from __future__ import annotations import argparse import hashlib import json import os import sys import xml.etree.ElementTree as ET import zipfile from collections import Counter from pathlib import Path DRIVERS = { "midway/midyunit.cpp": "Y", "midway/midtunit.cpp": "T", "midway/midwunit.cpp": "W", "midway/midxunit.cpp": "X", } def machines(listxml: Path): for _event, element in ET.iterparse(listxml): if element.tag != "machine": continue unit = DRIVERS.get(element.get("sourcefile", "")) if unit and element.get("isdevice") != "yes": yield unit, element element.clear() def describe(unit: str, element: ET.Element) -> dict: chips = [ {"type": c.get("type"), "tag": c.get("tag"), "name": c.get("name"), "clock": c.get("clock")} for c in element.findall("chip") ] roms = [ { "name": r.get("name"), "region": r.get("region"), "size": int(r.get("size", "0")), "sha1": r.get("sha1"), "status": r.get("status", "good"), } for r in element.findall("rom") ] driver = element.find("driver") return { "unit": unit, "name": element.get("name"), "cloneof": element.get("cloneof"), "description": element.findtext("description"), "year": element.findtext("year"), "manufacturer": element.findtext("manufacturer"), "status": driver.get("status") if driver is not None else None, "chips": chips, "roms": roms, "devices": sorted({d.get("name") for d in element.findall("device_ref")}), } def check_set(rompath: Path | None, machine: dict) -> str: """'ok', 'missing', or 'partial: n of m' by SHA-1 of the zip's members.""" if rompath is None: return "no MAME_ROMPATH" path = rompath / f"{machine['name']}.zip" if not path.exists(): return "missing" wanted = {r["sha1"] for r in machine["roms"] if r["sha1"] and r["status"] != "nodump"} found = set() with zipfile.ZipFile(path) as archive: for member in archive.infolist(): digest = hashlib.sha1() with archive.open(member) as handle: for block in iter(lambda: handle.read(1 << 20), b""): digest.update(block) found.add(digest.hexdigest()) have = len(wanted & found) return "ok" if have == len(wanted) else f"partial: {have} of {len(wanted)}" def cpu_summary(machine: dict) -> str: parts = [] for chip in machine["chips"]: if chip["type"] == "cpu": clock = int(chip["clock"]) / 1e6 if chip["clock"] else 0 parts.append(f"{chip['name']} {clock:g}") return "; ".join(parts) def sound_board(machine: dict) -> str: for chip in machine["chips"]: if chip["type"] == "audio" and chip["tag"] and ":" not in chip["tag"] and chip["name"] != "Speaker": return chip["name"] return "-" def main() -> int: parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) parser.add_argument("listxml", type=Path) parser.add_argument("--json", type=Path, help="write the full census here (git-ignored)") args = parser.parse_args() env = os.environ.get("MAME_ROMPATH") rompath = Path(env) if env else None rows = [] for unit, element in machines(args.listxml): machine = describe(unit, element) machine["present"] = check_set(rompath, machine) rows.append(machine) rows.sort(key=lambda m: ("YTWX".index(m["unit"]), m["cloneof"] or m["name"], m["cloneof"] is not None, m["name"])) print("unit | set | parent | year | driver status | CPUs (MHz) | sound board | ROM bytes | nodump | in MAME_ROMPATH | description") for m in rows: size = sum(r["size"] for r in m["roms"]) nodump = [r["name"] for r in m["roms"] if r["status"] == "nodump"] print( f"{m['unit']} | {m['name']} | {m['cloneof'] or '-'} | {m['year']} | {m['status']} | " f"{cpu_summary(m)} | {sound_board(m)} | {size} | {','.join(nodump) or '-'} | " f"{m['present']} | {m['description']}" ) print() for unit in "YTWX": group = [m for m in rows if m["unit"] == unit] parents = [m for m in group if not m["cloneof"]] present = Counter(m["present"].split(":")[0] for m in group) boards = Counter(sound_board(m) for m in group) print(f"{unit}-unit: {len(group)} sets, {len(parents)} parents; present {dict(present)}; sound {dict(boards)}") regions = Counter((m["unit"], r["region"]) for m in rows for r in m["roms"]) print("ROM regions by unit:", dict(sorted(regions.items()))) devices = Counter(d for m in rows for d in m["devices"]) print("devices:", dict(sorted(devices.items()))) if args.json: args.json.write_text(json.dumps(rows, indent=1), encoding="utf-8") return 0 if __name__ == "__main__": sys.exit(main())