# SPDX-License-Identifier: MIT """Census of the No-Intro Plus/4 set and of the 264-series and drive firmware we hold, read in place. python -I scripts/census.py nointro # $NO_INTRO_DIR/"Commodore - Plus-4" python -I scripts/census.py firmware # $MAME_ROMPATH sets and No-Intro's [BIOS] zips python -I scripts/census.py softlist # $MAME_HASHPATH plus4_cart/cass/flop.xml (CC0) Nothing is copied or written except the report on stdout. `nointro` counts the set by tag, member extension and size, and looks for the "CBM" bytes at offset 7 of each cartridge image (where the 264 KERNAL's cartridge scan is reported to look: HYPOTHESIS until the board reads it from the KERNAL's behaviour). `firmware` hashes every image in the MAME sets and the No-Intro [BIOS] zips by SHA-1 and names the known ones. `softlist` counts MAME's software lists, which are CC0-1.0 data. Where the sets live is an environment variable, never a path in this repository: NO_INTRO_DIR holds "Commodore - Plus-4" (No-Intro's folder name); MAME_ROMPATH holds MAME's non-merged romsets; MAME_HASHPATH holds MAME's hash/ folder. The TOSEC Plus/4 and C16 sets are not in this machine's mirror (2026-11-26); `nointro` says so if TOSEC_DIR is unset. """ from __future__ import annotations import argparse import collections import hashlib import os import re import sys import xml.etree.ElementTree as ET import zipfile from pathlib import Path FOLDER = "Commodore - Plus-4" # The images MAME 0.285 names (`mame -listroms plus4 plus4p c16 c16p c16_hu c116 c232 c264 # v364 c1551 c1541`, run 2026-11-26), by SHA-1: role, chip location, sets. KNOWN = { "161c96b4ad20f3a4f2321808e37a5ded26a135dd": "BASIC 3.5, 318006-01 (U23; every 264-series row)", "5df52c693387c0e2b5d682613a3b5a65477311cf": "KERNAL NTSC, 318005-04 (U24; plus4, c16)", "a3d9e5be091b98de39a046ab167fb7632d053682": "KERNAL NTSC, 318005-05 (U24; plus4, c16; MAME default)", "97814dab9d757fe5a3a61d357a9a81da588a9783": "KERNAL PAL, 318004-03 (U24; plus4p, c16p, c116)", "514ad3c29d01a2c0a3b143d9c1d4143b1912b793": "KERNAL PAL, 318004-04 (U24; plus4p, c16p, c116)", "7c7e07f016391174a557e790c4ef1cbe33512cdb": "KERNAL PAL, 318004-05 (U24; plus4p, c16p, c116; MAME default)", "20cf3c4bf6c54ef09799af41887218933f2e27ee": "KERNAL Hungary, 318030-02 (c16_hu)", "3c77caf72914c1c0a0875b3a7f6935cd30c54201": "KERNAL C232 prototype, 318004-01 (c232)", "d481faf5fcbb331878dc7851c642d04f26a32873": "KERNAL C264 prototype (c264)", "473fce23afa07000cdca899fbcffd6961b36a8a0": "BASIC C264 prototype (c264)", "b9a5b5dacd57ca117ef0b3af29e91998bf4d7e5f": "KERNAL V364 prototype (v364)", "59af401cbb2194f689898271c6e8aafa28a7af11": "V364 speech ROM (v364)", "3b69f6e7cb4c18bb08e203fb18b7dabfa853390f": "3-plus-1 low, 317053-01 (U25; plus4, plus4p, v364)", "0ad7ac2db7da692d972e586ca0dfd747d82c7693": "3-plus-1 high, 317054-01 (U26; plus4, plus4p, v364)", "a89b18b2261233443c933c8b4663b108e7630924": "PLA 251641-02 (U19; 245 bytes, a dumped 82S100 table)", "9bc1b1c3da9ca642deae717905f990d8e36e6c3b": "KERNAL replacement: JiffyDOS Plus/4 (third-party, plus4 option)", "fae3c788ad9a6cc2dbdfbcf6c0264b2ca921d55e": "1551 DOS, 318001-01 (U4; c1551)", "8e0547430135ba462525c224e76356bd3d430f11": "1541 DOS low half, 325302-01 (UAB4)", "7a1054c6156b51c25410caec0f609efb079d3a77": "1541 DOS high half, 901229-01 (UAB5)", "91321142e226168b1139c30c83896933f317d000": "1541 DOS high half, 901229-02 (UAB5)", "03d17bd745066f1ead801c5183ac1d3af7809744": "1541 DOS high half, 901229-03 (UAB5)", "f5d60777440829e46dc91285e662ba072acd2d8b": "1541 DOS high half, 901229-05 AE (UAB5; MAME default)", "c7f94f4f51d6de4cdc21ecbb7e57bb209f0530c0": "1541 DOS high half, 901229-06 AA (UAB5)", } MAME_SETS = ("plus4", "plus4p", "c16", "c16p", "c16_hu", "c116", "c232", "c264", "v364", "c1551", "c1541") TAGS = ("Rev", "Alt", "Proto", "Beta", "Demo", "Program", "Unl", "Pirate", "Aftermarket") def nointro(_: argparse.Namespace) -> int: base = os.environ.get("NO_INTRO_DIR") if not base: print(f"set NO_INTRO_DIR to the directory holding '{FOLDER}'", file=sys.stderr) return 2 folder = Path(base) / FOLDER names = sorted(p.name for p in folder.iterdir() if p.suffix == ".zip") bios = [n for n in names if n.startswith("[BIOS]")] regions, tags, exts, sizes, signature = (collections.Counter() for _ in range(5)) for name in names: groups = re.findall(r"\(([^)]*)\)", name) regions[groups[0] if groups else "?"] += 1 for group in groups[1:]: for tag in TAGS: if group.startswith(tag): tags[tag] += 1 if name in bios: continue with zipfile.ZipFile(folder / name) as archive: for member in archive.namelist(): data = archive.read(member) ext = member.rsplit(".", 1)[-1].lower() exts[ext] += 1 sizes[(ext, len(data))] += 1 if ext == "bin": signature["CBM at offset 7" if data[7:10] == b"CBM" else "none"] += 1 print(f"{len(names)} zips: {len(names) - len(bios)} software, {len(bios)} [BIOS]") print("regions:", dict(regions.most_common())) print("tags:", dict(tags.most_common())) print("members by extension:", dict(exts.most_common())) print("members by (extension, size):", dict(sorted(sizes.items()))) print("cartridge images, signature:", dict(signature)) if not os.environ.get("TOSEC_DIR"): print("TOSEC: TOSEC_DIR unset; the mirror holds no Commodore TOSEC sets (2026-11-26)") return 0 def hash_zip(path: Path, seen: dict[str, list[str]]) -> None: with zipfile.ZipFile(path) as archive: for member in archive.namelist(): sha = hashlib.sha1(archive.read(member)).hexdigest() seen.setdefault(sha, []).append(f"{path.name}:{member}") def firmware(_: argparse.Namespace) -> int: seen: dict[str, list[str]] = {} rompath = os.environ.get("MAME_ROMPATH") if rompath: for name in MAME_SETS: path = Path(rompath) / f"{name}.zip" if path.exists(): hash_zip(path, seen) else: print(f"MAME set missing: {name}.zip") base = os.environ.get("NO_INTRO_DIR") if base: for path in sorted((Path(base) / FOLDER).glob("[[]BIOS[]]*.zip")): hash_zip(path, seen) found = [sha for sha in KNOWN if sha in seen] print(f"known images held: {len(found)} of {len(KNOWN)}") for sha, role in KNOWN.items(): where = seen.get(sha) print(f" {'have' if where else 'MISSING':7} {sha} {role}" + (f" ({len(where)} copies)" if where else "")) unknown = [sha for sha in seen if sha not in KNOWN] print(f"other images in those sets (not named above): {len(unknown)}") for sha in unknown: print(f" {sha} {seen[sha][0]}") return 0 def softlist(_: argparse.Namespace) -> int: hashes = os.environ.get("MAME_HASHPATH") if not hashes: print("set MAME_HASHPATH to MAME's hash/ folder", file=sys.stderr) return 2 for name in ("plus4_cart", "plus4_cass", "plus4_flop"): root = ET.parse(Path(hashes) / f"{name}.xml").getroot() entries = list(root.iter("software")) support = collections.Counter(s.get("supported", "yes") for s in entries) features = collections.Counter(f.get("name") for s in entries for f in s.iter("feature")) print(f"{name}.xml: {len(entries)} entries; supported: {dict(support)}; features: {dict(features.most_common(6))}") return 0 def main() -> int: parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) sub = parser.add_subparsers(dest="command", required=True) for name, func in (("nointro", nointro), ("firmware", firmware), ("softlist", softlist)): sub.add_parser(name).set_defaults(func=func) args = parser.parse_args() return args.func(args) if __name__ == "__main__": sys.exit(main())