# SPDX-License-Identifier: MIT """Census of the No-Intro NGP/NGPC sets and of the NGP BIOS images we hold, read in place. NO_INTRO_DIR=... python -I scripts/census.py carts [--list] MAME_ROMPATH=... python -I scripts/census.py bios [dir ...] `carts` opens every zip in the three No-Intro folders and reads the image's first 64 bytes in memory (nothing is extracted or written): the 28-byte licence string, the 24-bit entry point (0x1C), the catalog number (0x20, 16-bit), the sub-catalog (0x22), the colour-mode byte (0x23: 0x00 mono, 0x10 colour, per Judge's ngpctech.txt) and the 12-byte title (0x24). It counts sizes (so flash chip sizes: 4, 8, 16 Mbit, or 32 Mbit as two chips), licence strings, colour modes, regions, and entry points outside the cartridge window. `bios` hashes the BIOS files in MAME's ngp/ngpc sets and any directory given, by SHA-1, and names each known image. Where the sets live is an environment variable, never a path in this repository. """ from __future__ import annotations import argparse import collections import hashlib import os import re import struct import sys import zipfile from pathlib import Path FOLDERS = ("SNK - NeoGeo Pocket", "SNK - NeoGeo Pocket (Aftermarket)", "SNK - NeoGeo Pocket Color") # MAME 0.285 -listxml (snk/ngp.cpp), confirmed by hashing $MAME_ROMPATH's sets 2026-11-26. KNOWN = { "2f6429b68446536d8b03f35d02f1e98beb6460a0": "NGP (monochrome) BIOS, 64 KiB (MAME ngp: ngp_bios.ngp; No-Intro [BIOS] SNK NeoGeo Pocket (Japan, Europe) (En))", "edc13192054a59be49c6d55f83b70e2510968e86": "NGPC BIOS, 64 KiB (MAME ngpc: ngpcbios.rom; No-Intro [BIOS] SNK NeoGeo Pocket Color (World) (En,Ja))", # No-Intro's NGP folder, hashed 2026-11-26; not in MAME 0.285. "50db9b1c267baf88a0d969dea4f72d92e46cdfaf": "NGP BIOS, beta (No-Intro [BIOS] SNK NeoGeo Pocket (Japan) (En) (Beta))", "470781ddb614d4eca11e5a3d8a97be0e04314af6": "NGP BIOS (No-Intro [BIOS] SNK NeoGeo Pocket (Japan, Europe) (En,Ja) (Monochrome))", } IMAGE = re.compile(r"\.(ngp|ngc|npc|ngpc)$", re.I) def header(data: bytes) -> dict: entry = struct.unpack_from(" int: base = os.environ.get("NO_INTRO_DIR") if not base: print("set NO_INTRO_DIR to the No-Intro root", file=sys.stderr) return 2 for folder in FOLDERS: path = Path(base) / folder zips = sorted(path.glob("*.zip")) if path.is_dir() else [] sizes, licences, modes, regions, exts = (collections.Counter() for _ in range(5)) odd_entry, catalogs, titles = [], collections.Counter(), set() for z in zips: with zipfile.ZipFile(z) as archive: if z.name.startswith("[BIOS]"): for member in archive.infolist(): sha1 = hashlib.sha1(archive.read(member)).hexdigest() print(f" BIOS entry {sha1} {member.file_size} {member.filename}: " f"{KNOWN.get(sha1, 'not a known NGP BIOS')}") # fmt: skip continue members = [m for m in archive.infolist() if IMAGE.search(m.filename)] for member in members: with archive.open(member) as handle: head = header(handle.read(64)) sizes[member.file_size] += 1 exts[Path(member.filename).suffix.lower()] += 1 licences[head["licence"]] += 1 modes[f"{head['mode']:02X}"] += 1 catalogs[head["catalog"]] += 1 if not 0x200000 <= head["entry"] < 0x400000: odd_entry.append((z.name, f"{head['entry']:06X}")) if args.list: print(f" {head['catalog']:04X}/{head['sub']:02X} mode {head['mode']:02X} " f"entry {head['entry']:06X} {member.file_size:>8} {head['title']!r} {z.name}") # fmt: skip for group in re.findall(r"\(([^)]*)\)", z.name)[:1]: regions[group] += 1 titles.add(re.sub(r"\s*\(.*", "", z.name)) print(f"== {folder}: {len(zips)} zips, {len(titles)} titles") print(f" sizes (bytes): {dict(sorted(sizes.items()))}") print(f" extensions: {dict(exts)}") print(f" colour-mode byte 0x23: {dict(modes)}") print(f" licence strings: {dict(licences)}") print(f" first bracket (region): {dict(regions.most_common())}") print(f" catalog numbers shared by more than one image: " f"{ {f'{k:04X}': v for k, v in catalogs.items() if v > 1} }") # fmt: skip print(f" entry points outside 200000-3FFFFF: {odd_entry}") return 0 def bios(args: argparse.Namespace) -> int: places = [Path(p) for p in args.dirs] rompath = os.environ.get("MAME_ROMPATH") if rompath: places += [Path(rompath) / "ngp.zip", Path(rompath) / "ngpc.zip"] base = os.environ.get("NO_INTRO_DIR") if base: places += sorted(p for folder in FOLDERS for p in (Path(base) / folder).glob("[[]BIOS[]]*.zip")) found = 0 for place in places: blobs = [] if place.suffix == ".zip" and place.is_file(): with zipfile.ZipFile(place) as archive: blobs = [(f"{place.name}:{m.filename}", archive.read(m)) for m in archive.infolist()] elif place.is_dir(): blobs = [(str(p.name), p.read_bytes()) for p in sorted(place.iterdir()) if p.is_file() and p.stat().st_size == 65536] # fmt: skip for name, data in blobs: sha1 = hashlib.sha1(data).hexdigest() found += sha1 in KNOWN print(f"{sha1} {len(data):>6} {name}: {KNOWN.get(sha1, 'not a known NGP BIOS')}") print(f"{found} known BIOS image(s) found") return 0 def main() -> int: parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) sub = parser.add_subparsers(dest="what", required=True) c = sub.add_parser("carts") c.add_argument("--list", action="store_true") b = sub.add_parser("bios") b.add_argument("dirs", nargs="*") args = parser.parse_args() return carts(args) if args.what == "carts" else bios(args) if __name__ == "__main__": sys.exit(main())