# SPDX-License-Identifier: MIT """Census of the Odyssey 2 / Videopac library and firmware, read in place (docs/census.md). NO_INTRO_DIR=... python -I scripts/census.py carts # the No-Intro folders python -I scripts/census.py carts --dir SOME/FOLDER # any other folder of zips MAME_ROMPATH=... python -I scripts/census.py bios # BIOS and chip ROMs by SHA-1 Nothing is copied: zips are opened in place, each member hashed (size, CRC-32, SHA-1) and matched against MAME 0.285's software list hash/videopac.xml (CC0-1.0; found with "mame -showconfig"'s hashpath) for its slot device, ROM size and the bank wiring. The output is a table on stdout; docs/census.md records the run. """ from __future__ import annotations import argparse import hashlib import os import subprocess import sys import xml.etree.ElementTree as ET import zipfile import zlib from collections import Counter from pathlib import Path NO_INTRO_SYSTEMS = ("Magnavox - Odyssey2", "Philips - Videopac+") # The firmware the board will ask the player for, by SHA-1 (MAME 0.285 -listxml and # hash/videopac.xml). Names are MAME's; a player's file may have any name. FIRMWARE = { "b2e1955d957a475de2411770452eff4ea19f4cee": "o2bios.rom: Odyssey 2 / Videopac G7000 BIOS (videopac, odyssey2)", "a6120aed50831c9c0d95dbdf707820f601d9452e": "c52.rom: Radiola/Schneider/Philips C52 BIOS (videopacf)", "5130243429b40b01a14e1304d0394b8459a6fbae": "g7400.bin: Videopac+ G7400 BIOS (videopacp)", "0a38c5f2cea929d2fe0a23e5e1a60de9155815dc": "odyssey3.bin: Odyssey 3 prototype BIOS (odyssey3)", "54b8d2c1317628de51a85fc1c424423a986775e4": "jopac.bin: Brandt Jopac BIOS (jopac)", "415382715455b47b69401b3d60bd8f0036dd7fef": "charset_i8244.bin: 8244/8245 character ROM, MAME's dump (i8244)", "f8e3892234da6626eb4302e171179ada5a51fca8": "charset_ef9340_1.rom: EF9341 character ROM, MAME's dump, marked baddump (ef9340_1)", "49f5326ad45392dc96c89d1d4e089a20bd21e609": "sp0256b-019.bin: The Voice's SP0256B-019 resident ROM (softlist voice)", "0f31f46bc02e9272885779a6dd7102c78b18895b": "spr128-003.bin: The Voice's 16 KB speech ROM (softlist voice)", } MAME_SETS = ("videopac", "odyssey2", "videopacf", "videopacp", "odyssey3", "jopac", "i8244", "i8245", "ef9340_1") def softlist() -> dict[str, dict]: """sha1 -> {name, description, slot, size, area} from hash/videopac.xml.""" hashpath = None try: out = subprocess.run(["mame", "-showconfig"], capture_output=True, text=True, timeout=60).stdout for line in out.splitlines(): if line.startswith("hashpath"): hashpath = line.split(None, 1)[1].strip() except (OSError, subprocess.TimeoutExpired): pass path = Path(hashpath or "/usr/share/games/mame/hash") / "videopac.xml" table: dict[str, dict] = {} if not path.exists(): print(f"(no {path}: slot types unknown)", file=sys.stderr) return table for sw in ET.parse(path).getroot().iter("software"): part = sw.find("part") slot = "o2_rom" bpin = False for feat in part.iter("feature"): if feat.get("name") == "slot": slot = feat.get("value") if feat.get("name") == "b_pin": bpin = True for area in part.iter("dataarea"): for rom in area.iter("rom"): if rom.get("sha1"): table[rom.get("sha1")] = { "name": sw.get("name"), "description": sw.findtext("description"), "slot": slot + ("+b_pin" if bpin else ""), "area": area.get("name"), "size": int(area.get("size"), 0), } return table def members(zpath: Path): with zipfile.ZipFile(zpath) as z: for info in z.infolist(): if info.is_dir(): continue data = z.read(info) yield info.filename, data def carts(folders: list[Path]) -> int: table = softlist() for folder in folders: files = sorted(p for p in folder.iterdir() if p.is_file()) print(f"== {folder.name}: {len(files)} files") if not files: continue sizes, slots, unmatched = Counter(), Counter(), [] bios = [] for zpath in files: if zpath.suffix.lower() != ".zip": print(f" not a zip: {zpath.name}") continue for name, data in members(zpath): sha1 = hashlib.sha1(data).hexdigest() crc = f"{zlib.crc32(data):08x}" sizes[len(data)] += 1 hit = table.get(sha1) if sha1 in FIRMWARE or name.startswith("[BIOS]") or zpath.name.startswith("[BIOS]"): bios.append((zpath.name, len(data), crc, sha1, FIRMWARE.get(sha1, "not in MAME 0.285"))) continue if hit: slots[hit["slot"]] += 1 else: unmatched.append((zpath.name, len(data), crc, sha1)) print(" sizes:", ", ".join(f"{k} B x{v}" for k, v in sorted(sizes.items()))) print(" MAME slot device:", ", ".join(f"{k} x{v}" for k, v in slots.most_common())) for row in bios: print(" BIOS: %s %d B crc %s sha1 %s = %s" % row) print(f" not in hash/videopac.xml: {len(unmatched)}") for row in unmatched: print(" %s %d B crc %s sha1 %s" % row) return 0 def bios(rompath: str) -> int: found: dict[str, list[str]] = {} for folder in rompath.split(";"): for setname in MAME_SETS: zpath = Path(folder) / f"{setname}.zip" if not zpath.exists(): continue for name, data in members(zpath): found.setdefault(hashlib.sha1(data).hexdigest(), []).append(f"{setname}.zip:{name} ({len(data)} B)") for sha1, what in FIRMWARE.items(): where = found.get(sha1) print(f"{'FOUND ' if where else 'MISSING'} {sha1} {what}") for w in where or []: print(f" {w}") return 0 def main() -> int: parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) sub = parser.add_subparsers(dest="cmd", required=True) c = sub.add_parser("carts") c.add_argument("--dir", action="append", default=[], help="a folder of zips (instead of NO_INTRO_DIR)") sub.add_parser("bios") args = parser.parse_args() if args.cmd == "carts": folders = [Path(d) for d in args.dir] if not folders: root = os.environ.get("NO_INTRO_DIR") if not root: print("set NO_INTRO_DIR (or pass --dir)", file=sys.stderr) return 2 folders = [Path(root) / s for s in NO_INTRO_SYSTEMS] return carts(folders) rompath = os.environ.get("MAME_ROMPATH") if not rompath: print("set MAME_ROMPATH", file=sys.stderr) return 2 return bios(rompath) if __name__ == "__main__": sys.exit(main())