#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """Census of the No-Intro Bit Corporation Gamate set: sizes, SHA-1s, headers, MAME's list. Reads every zip under ``$NO_INTRO_DIR/Bit Corporation - Gamate`` in place (members are read, never extracted or copied) and prints one line per image: - size and SHA-1; - the cartridge header as Kevtris's "Gamate Inside" (KH) and cc65's ``header.s`` describe it: the 16-bit checksum at 0000/0001 (LSB first), the string "COPYRIGHT BIT CORPORATION" at 0005, the three entry jumps at 0020/0023/0026 (reset, NMI, IRQ); - whether the stored checksum equals the 16-bit sum of the bytes at ROM 1000-1FFF (CPU 7000-7FFF on a flat or banked cart at reset; KH, "Cartridge Hardware" step 8; cc65: "simple 8bit adds"); - MAME 0.285's software-list entry with the same SHA-1 and its ``slot`` feature (reference/mame-hash/gamate.xml, CC0). BIOS images ("[BIOS]" zips) are reported by size and SHA-1 only, matched against the two SHA-1s MAME's ``gamate`` machine names; firmware is never copied. NO_INTRO_DIR=... python -I scripts/census.py > tests/detectors/census-nointro-.txt """ 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 = "Bit Corporation - Gamate" MAME_LIST = ROOT / "reference" / "mame-hash" / "gamate.xml" COPYRIGHT = b"COPYRIGHT BIT CORPORATION" # MAME 0.285 `mame -listxml gamate` (2026-11-26): the machine's two BIOS sets. MAME_BIOS = { "ea449dc607601f9a68d855ad6ab53800d2e99297": "gamate_bios_umc.bin (MAME bios 'default')", "4e9dfbfe916ca485530ef4221593ab68738e2217": "gamate_bios_bit.bin (MAME bios 'newer')", } def mame_hashes() -> dict[str, tuple[str, str]]: """SHA-1 -> (software name, slot type) from MAME's CC0 software list.""" found: dict[str, tuple[str, str]] = {} if not MAME_LIST.exists(): return found for software in ET.parse(MAME_LIST).getroot().findall("software"): slot = "plain" for feature in software.iter("feature"): if feature.get("name") == "slot": slot = feature.get("value") for rom in software.iter("rom"): if rom.get("sha1"): found[rom.get("sha1")] = (software.get("name"), slot) return found def header(data: bytes) -> str: stored = data[0] | data[1] << 8 total = sum(data[0x1000:0x2000]) & 0xFFFF text = "copyright ok" if data[5 : 5 + len(COPYRIGHT)] == COPYRIGHT else "NO copyright string" jumps = all(data[offset] == 0x4C for offset in (0x20, 0x23, 0x26)) entry = f"reset {data[0x21] | data[0x22] << 8:04X}" if data[0x20] == 0x4C else "reset ?" return f"sum {'ok' if stored == total else 'BAD'} ({stored:04X}/{total:04X}) | {text} | jumps {'ok' if jumps else 'NO'} {entry}" 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() slots: Counter[str] = Counter() carts = in_mame = sums_ok = 0 zips = sorted(folder.glob("*.zip")) for path in zips: with zipfile.ZipFile(path) as archive: for member in archive.infolist(): data = archive.read(member) sha1 = hashlib.sha1(data).hexdigest() if path.name.startswith("[BIOS]"): print(f"BIOS {len(data):7d} {sha1} | {MAME_BIOS.get(sha1, 'not a MAME gamate BIOS')} | {member.filename}") continue carts += 1 sizes[len(data)] += 1 listed = mame.get(sha1) if listed: in_mame += 1 slots[listed[1]] += 1 line = header(data) sums_ok += " sum ok " in f" {line} " note = f"MAME {listed[0]} slot={listed[1]}" if listed else "not in MAME's list by SHA-1" print(f"{len(data):7d} {sha1} | {line} | {note} | {member.filename}") print() print(f"zips: {len(zips)}; cartridge images: {carts}; 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("MAME slot types of matched images: " + ", ".join(f"{k} x{v}" for k, v in sorted(slots.items()))) print(f"header checksum (7000-7FFF) matches: {sums_ok} of {carts}") print(f"MAME list entries: {len({name for name, _ in mame.values()})}") return 0 if __name__ == "__main__": sys.exit(main())