# SPDX-License-Identifier: MIT """Census of the No-Intro VIC-20 set and of the VIC-20 and 1541 firmware we hold, read in place. python -I scripts/census.py nointro # $NO_INTRO_DIR/"Commodore - VIC-20" python -I scripts/census.py firmware # $MAME_ROMPATH sets and No-Intro's [BIOS] zips Nothing is copied or written except the report on stdout. `nointro` counts the set by region and tag, by the load block each image names in its extension (No-Intro names a VIC-20 image by its load address: `.a0` = $A000, `.60` = $6000, ...), by size and by the combination of blocks a multi-image set fills; it looks for the KERNAL's autostart signature (`A0CBM` at $A004, PRG ch. 4 / the KERNAL's own check) in every $A000 image; and, when MAME_HASHPATH names MAME's `hash/` folder, it matches each image by SHA-1 against MAME's CC0 software list `vic1001_cart.xml` and counts the slot features (the cartridges that need more than plain ROM). `firmware` hashes the KERNAL, BASIC and character ROMs and the drive ROMs by SHA-1 and says which known image each is. Where the sets live is an environment variable, never a path in this repository: NO_INTRO_DIR holds "Commodore - VIC-20" (No-Intro's own folder name); MAME_ROMPATH holds MAME's non-merged romsets; MAME_HASHPATH (optional) holds MAME's software lists. """ 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 - VIC-20" # The images MAME 0.285 names (`mame -listroms vic20 vic20p vic1001 vic20_se c1540 c1541 # c1541c c1541ii`, run 2026-11-26), by SHA-1. Role, chip location, MAME set. KNOWN = { "587d1e90950675ab6b12d91248a3f0d640d02e8d": "BASIC V2, 901486-01 (UE11; every VIC-20 and the VIC-1001)", "06de7ec017a5e78bd6746d89c2ecebb646efeb19": "KERNAL NTSC, 901486-06 (UE12; vic20)", "ce0137ed69f003a299f43538fa9eee27898e621e": "KERNAL PAL, 901486-07 (UE12; vic20p)", "c9ead45e6674d1042ca6199160e8583c23aeac22": "KERNAL Japan, 901486-02 (vic1001)", "cb3e2f6e661ea7f567977751846ce9ad524651a3": "KERNAL Sweden/Finland, NEC 22081-206 (vic20_se)", "4fd85ab6647ee2ac7ba40f729323f2472d35b9b4": "character ROM, 901460-03 (UD7; vic20, vic20p)", "dae61ac03065aa2904af5c123ce821855898c555": "character ROM Japan, 901460-02 (vic1001)", "f403f0b0ce5922bd61bbd768bdd6f0b38e648c9f": "character ROM Sweden/Finland, NEC 22101-207 (vic20_se)", "83fb83e97b5a840311dbf7e1fe56fe828f41936d": "KERNAL replacement: JiffyDOS VIC-20 NTSC (third-party, vic20 option)", "5a03623a4b855531b8bffd756f701306f128be2d": "KERNAL replacement: JiffyDOS VIC-20 PAL (third-party, vic20p option)", "8e0547430135ba462525c224e76356bd3d430f11": "1540/1541 DOS low half, 325302-01 (UAB4; c1540, c1541)", "56dfe79b26f50af4e83fd9604857756d196516b9": "1540 DOS high half, 325303-01 (UAB5; c1540)", "7a1054c6156b51c25410caec0f609efb079d3a77": "1541 DOS high half, 901229-01 (UAB5; c1541)", "91321142e226168b1139c30c83896933f317d000": "1541 DOS high half, 901229-02 (UAB5; c1541)", "03d17bd745066f1ead801c5183ac1d3af7809744": "1541 DOS high half, 901229-03 (UAB5; c1541)", "f5d60777440829e46dc91285e662ba072acd2d8b": "1541 DOS high half, 901229-05 AE (UAB5; c1541, MAME default)", "c7f94f4f51d6de4cdc21ecbb7e57bb209f0530c0": "1541 DOS high half, 901229-06 AA (UAB5; c1541)", "8e893932de8cce244117fcea4c46b7c39c6a7765": "1541C DOS, 251968-01 (UA2; c1541c)", "38a7a489c7bbc8661cf63476bf1eb07b38b1c704": "1541C DOS, 251968-02 (UA2; c1541c)", "d3b78c3dbac55f5199f33f3fe0036439811f7fb3": "1541-II DOS, 251968-03 (U4; c1541ii)", "ab16f56989b27d89babe5f89c5a8cb3da71a82f0": "1541-II DOS, 355640-01 (U4; c1541ii)", "db6cfaa6d9b78d58746c811de29f3b1f44d99ddf": "1541 DOS replacement: JiffyDOS 1541 (third-party, c1541 option)", "b1a5b826304d3df2a27d7163c6a81a532e040d32": "1541-II DOS replacement: JiffyDOS 1541-II (third-party)", "95407e59a9c1d26a0e4bcf2c244cfe8942576e2c": "1541 DOS replacement: Speed-DOS Plus, 16 KB (third-party, c1541 option)", "04c892c4b3d7c74750576521fa081f07d8ca8557": "1541 DOS replacement: rolo27 (third-party, c1541 option)", "4d6ffdce6ab122e9627b0a839861687bcd4e03ec": "1541 DOS replacement: ttd34, 32 KB (third-party, c1541 option)", "99d3d848344c68410b686cda812f3788b41fead3": "1541 DOS replacement: DigiDOS (third-party, c1541 option)", } MAME_SETS = ("vic20", "vic20p", "vic1001", "vic20_se", "c1540", "c1541", "c1541c", "c1541ii") BLOCKS = {"20": "BLK1", "40": "BLK2", "60": "BLK3", "70": "BLK3+", "80": "char", "a0": "BLK5", "b0": "BLK5+"} REGION = re.compile(r"(World|USA|Europe|Japan|Germany|Netherlands|Sweden|Canada|Australia|UK)" r"(, (World|USA|Europe|Japan|Germany|Netherlands|Sweden|Canada|Australia|UK))*") SIGNATURE = b"A0\xc3\xc2\xcd" # "A0CBM" with CBM in PETSCII shifted letters, at $A004 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") regions, tags, exts, sizes, combos = (collections.Counter() for _ in range(5)) autostart = collections.Counter() shas = {} bios = [n for n in names if n.startswith("[BIOS]")] for name in names: groups = re.findall(r"\(([^)]*)\)", name) region = next((g for g in groups if REGION.fullmatch(g)), "?") regions[region] += 1 for group in groups[1:]: for tag in ("Rev", "Alt", "Proto", "Beta", "Demo", "Program", "Unl", "SYS", "Pirate", "Aftermarket"): if group.startswith(tag): tags[tag] += 1 if name in bios: continue with zipfile.ZipFile(folder / name) as archive: members = sorted(m for m in archive.namelist() if not m.endswith("/")) combo = [] for member in members: data = archive.read(member) ext = member.rsplit(".", 1)[-1].lower() exts[ext] += 1 sizes[len(data)] += 1 combo.append(BLOCKS.get(ext, ext)) shas[hashlib.sha1(data).hexdigest()] = f"{name}:{member}" if ext == "a0": autostart["A0CBM" if data[4:9] == SIGNATURE else "no signature"] += 1 combos[" + ".join(combo)] += 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("images by extension (load block):", dict(exts.most_common())) print("images by size:", dict(sorted(sizes.items()))) print("block combinations per zip:") for combo, count in combos.most_common(): print(f" {count:4} {combo}") print("$A000 images, autostart signature at $A004:", dict(autostart)) hashes = os.environ.get("MAME_HASHPATH") if hashes: softlist(Path(hashes) / "vic1001_cart.xml", shas) return 0 def softlist(path: Path, shas: dict[str, str]) -> None: """Match No-Intro images against MAME's CC0 cartridge list by SHA-1.""" root = ET.parse(path).getroot() listed = {} features = collections.Counter() for software in root.iter("software"): slot = [f.get("value") for f in software.iter("feature") if f.get("name") == "slot"] areas = sorted({d.get("name") for d in software.iter("dataarea")}) for rom in software.iter("rom"): if rom.get("sha1"): listed[rom.get("sha1")] = (software.get("name"), slot[0] if slot else "", areas) if slot: features[slot[0]] += 1 found = sum(1 for sha in shas if sha in listed) print(f"MAME vic1001_cart.xml: {len(set(n for n, _, _ in listed.values()))} entries, " f"{len(listed)} ROM hashes; No-Intro images found in it: {found} of {len(shas)}") # fmt: skip print(" MAME entries needing a slot device:", dict(features.most_common())) special = sorted({listed[sha][1] for sha in shas if sha in listed and listed[sha][1]}) print(" slot devices among the No-Intro matches:", special or "none") 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 not path.exists(): print(f"missing MAME set {name}.zip") continue with zipfile.ZipFile(path) as archive: for member in archive.namelist(): digest = hashlib.sha1(archive.read(member)).hexdigest() seen.setdefault(digest, []).append(f"{name}.zip:{member}") base = os.environ.get("NO_INTRO_DIR") if base: folder = Path(base) / FOLDER for path in sorted(folder.glob("[[]BIOS[]]*.zip")): with zipfile.ZipFile(path) as archive: for member in archive.namelist(): digest = hashlib.sha1(archive.read(member)).hexdigest() seen.setdefault(digest, []).append(f"No-Intro {path.name}:{member}") for digest, role in KNOWN.items(): where = "; ".join(seen.get(digest, [])) or "NOT FOUND" print(f"{digest} {role}\n {where}") extra = {d: w for d, w in seen.items() if d not in KNOWN} if extra: print("held but not in the known table:") for digest, where in extra.items(): print(f"{digest}\n {'; '.join(where)}") return 0 def main() -> int: parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) sub = parser.add_subparsers(dest="what", required=True) sub.add_parser("nointro") sub.add_parser("firmware") args = parser.parse_args() return nointro(args) if args.what == "nointro" else firmware(args) if __name__ == "__main__": sys.exit(main())