#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """Census of the No-Intro Watara Supervision set: sizes, SHA-1s, vectors, MAME's list. Reads every zip under ``$NO_INTRO_DIR/Watara - Supervision`` in place (members are read, never extracted or copied), and prints one line per ROM: size, SHA-1, the 6502 vectors as they would appear with the last 16 KB at C000-FFFF (Horton's bank rule), whether the image is two identical halves (a mirrored dump), and whether MAME 0.285's software list (reference/mame-hash/svision.xml, CC0) has the same SHA-1 and with which size. NO_INTRO_DIR=... python -I scripts/census.py > tests/detectors/census-nointro-.txt Nothing here is firmware: the Supervision has no boot ROM (Horton: the system is the ASIC, two 8K SRAMs and the cartridge). The TV-Link's own ROM is reported separately. """ from __future__ import annotations import hashlib import os import sys import xml.etree.ElementTree as ET import zipfile from collections import Counter from pathlib import Path ROOT = Path(__file__).resolve().parents[1] SYSTEM = "Watara - Supervision" MAME_LIST = ROOT / "reference" / "mame-hash" / "svision.xml" def mame_hashes() -> dict[str, tuple[str, int, str | None]]: """SHA-1 -> (software name, size, supported) from MAME's CC0 software list.""" found: dict[str, tuple[str, int, str | None]] = {} if not MAME_LIST.exists(): return found for software in ET.parse(MAME_LIST).getroot().findall("software"): for rom in software.iter("rom"): if rom.get("sha1"): found[rom.get("sha1")] = (software.get("name"), int(rom.get("size"), 0), software.get("supported")) return found def mirrored(data: bytes) -> str: """The smallest power-of-two block the image is a repetition of, if any.""" size = len(data) block = size while block > 1024 and data[: block // 2] == data[block // 2 : block] and data == data[:block // 2] * (size // (block // 2)): block //= 2 return "" if block == size else f"repeats every {block // 1024} KB" def vectors(data: bytes) -> str: top = data[-16384:] if len(data) >= 16384 else data word = lambda offset: top[offset] | top[offset + 1] << 8 # noqa: E731 base = len(top) - 6 return f"NMI {word(base):04X} RESET {word(base + 2):04X} IRQ {word(base + 4):04X}" def main() -> int: root = os.environ.get("NO_INTRO_DIR") if not root: print("set NO_INTRO_DIR", file=sys.stderr) return 2 folder = Path(root) / SYSTEM mame = mame_hashes() sizes: Counter[int] = Counter() in_mame = 0 rows = 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() sizes[len(data)] += 1 rows += 1 listed = mame.get(sha1) if listed: in_mame += 1 note = f"MAME {listed[0]} ({listed[1]} B{', supported=' + listed[2] if listed[2] else ''})" if listed else "not in MAME's list by SHA-1" print(f"{len(data):7d} {sha1} {vectors(data)} | {mirrored(data) or '-'} | {note} | {member.filename}") print() print(f"ROMs: {rows} in {len(list(folder.glob('*.zip')))} zips; SHA-1 also in MAME 0.285's list: {in_mame}") print("sizes: " + ", ".join(f"{size // 1024} KB x{count}" for size, count in sorted(sizes.items()))) print(f"MAME list entries: {len({name for name, _, _ in mame.values()})}") return 0 if __name__ == "__main__": sys.exit(main())