#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """Census of the No-Intro "Fairchild - Channel F" set and the console's BIOS PSUs. Hashes every member of every zip in "$NO_INTRO_DIR/Fairchild - Channel F" in place (zip members are read, never extracted or copied), and the BIOS images in $MAME_ROMPATH (channelf.zip). Each cartridge is matched by SHA-1 against MAME's software list (`mame -getsoftlist channelf`; the list's hash file is CC0-1.0) to get the cartridge type MAME assigns (`slot`: std, maze, hangman, chess, multi_old, multi) and any RAM it declares. Without MAME on PATH the census reports sizes only. NO_INTRO_DIR=... MAME_ROMPATH=... python -I scripts/census_nointro.py Prints a report; nothing is written. The BIOS SHA-1 list below is fact data, not firmware: it was taken from `mame -listxml channelf` (MAME 0.285), docs/bios.md. """ from __future__ import annotations import collections import hashlib import os import shutil import subprocess import sys import xml.etree.ElementTree as ET import zipfile from pathlib import Path # SHA-1 -> (name, role). OBSERVED: mame -listxml channelf, MAME 0.285. BIOS = { "81193965a374d77b99b4743d317824b53c3e3c78": ("sl31253", "PSU 1 (0000h-03FFh), first Channel F units"), "8f70d1b74483ba3a37e86cf16c849d601a8c3d2c": ("sl31254", "PSU 2 (0400h-07FFh), every unit"), "759e2ed31fbde4a2d8daf8b9f3e0dffebc90dae2": ("sl90025", "PSU 1 (0000h-03FFh), later units and the Channel F II"), } SYSTEM = "Fairchild - Channel F" def softlist() -> dict[str, dict[str, str]]: """SHA-1 -> {name, description, slot, ram} from MAME's software list, if MAME is here.""" mame = shutil.which("mame") if not mame: return {} result = subprocess.run([mame, "-getsoftlist", "channelf"], capture_output=True, text=True, check=False) if result.returncode: return {} table: dict[str, dict[str, str]] = {} for software in ET.fromstring(result.stdout).iter("software"): part = software.find("part") if part is None: continue slot = next((f.get("value", "") for f in part.iter("feature") if f.get("name") == "slot"), "") ram = next((a.get("size", "") for a in part.iter("dataarea") if a.get("name") == "ram"), "") for rom in part.iter("rom"): if rom.get("sha1"): table[rom.get("sha1")] = { "name": software.get("name", ""), "description": software.findtext("description", ""), "slot": slot or "std", "ram": ram, } return table def main() -> int: nointro = os.environ.get("NO_INTRO_DIR") if not nointro: print("set NO_INTRO_DIR", file=sys.stderr) return 2 folder = Path(nointro) / SYSTEM known = softlist() print(f"# Census of $NO_INTRO_DIR/{SYSTEM}") print(f"# MAME software list entries with SHA-1s: {len(known)}") sizes: collections.Counter[int] = collections.Counter() slots: collections.Counter[str] = collections.Counter() bios_seen: dict[str, str] = {} carts = 0 for path in sorted(folder.glob("*.zip")): with zipfile.ZipFile(path) as archive: for member in archive.infolist(): data = archive.read(member) sha1 = hashlib.sha1(data).hexdigest() if sha1 in BIOS: bios_seen[sha1] = f"$NO_INTRO_DIR/{SYSTEM}/{path.name}:{member.filename}" print(f"BIOS {len(data):6d} {sha1} {BIOS[sha1][0]:8s} {path.name}") continue carts += 1 sizes[len(data)] += 1 entry = known.get(sha1) slot = entry["slot"] if entry else "?" slots[slot] += 1 ram = f" ram={entry['ram']}" if entry and entry["ram"] else "" listed = entry["name"] if entry else "not in MAME's list" print(f"CART {len(data):6d} {sha1} {slot:9s} {listed}{ram} {path.name}") print(f"# cartridges: {carts}") print("# sizes: " + ", ".join(f"{size} B x{count}" for size, count in sorted(sizes.items()))) print("# MAME slot types: " + ", ".join(f"{slot} x{count}" for slot, count in sorted(slots.items()))) mame = os.environ.get("MAME_ROMPATH") if mame: for base in mame.split(";"): zpath = Path(base) / "channelf.zip" if zpath.is_file(): with zipfile.ZipFile(zpath) as archive: for member in archive.infolist(): sha1 = hashlib.sha1(archive.read(member)).hexdigest() if sha1 in BIOS: bios_seen.setdefault(sha1, f"$MAME_ROMPATH/channelf.zip:{member.filename}") for sha1, (name, role) in BIOS.items(): where = bios_seen.get(sha1, "MISSING") print(f"# BIOS {name} {sha1} {role}: {where}") return 0 if __name__ == "__main__": sys.exit(main())