# SPDX-License-Identifier: MIT """Census of the TI-99/4A firmware and cartridge library, read in place. python -I scripts/census.py firmware # $MAME_ROMPATH (and $TI99_BIOS_DIR if set) python -I scripts/census.py nointro # $NO_INTRO_DIR/"Texas Instruments - TI-99-4A" python -I scripts/census.py softlist # reference/hash/ti99_cart.xml (MAME 0.285, CC0) Nothing is copied or written except the report on stdout. `firmware` hashes the console ROM, GROM, speech ROM and DSR ROM images inside MAME's romsets (and any zips or files in a BIOS directory) by SHA-1 and names each known image. `nointro` counts the No-Intro set by region, tag and file extension. `softlist` counts MAME's cartridge list by PCB type and by the data areas each cartridge carries (GROM, ROM, RAM, NVRAM). 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 sys import xml.etree.ElementTree as ET import zipfile from pathlib import Path ROOT = Path(__file__).resolve().parents[1] # The images MAME 0.285's TI-99/4A machines and devices name (romsets hashed 2026-11-26), # by SHA-1: role, MAME set and file name. Firmware is TI's: identified here, never copied. KNOWN = { "a45245707c3dccea902b718554a882d214a82504": "99/4A console ROM, high byte (ti99_4a, ti99_4ae, ti99_4ev, ti99_4qi: 994a_rom_hb.u610)", "f4e774fd5913b387a763f1b8de5524c54b255434": "99/4A console ROM, low byte (same sets: 994a_rom_lb.u611)", "ea15d8b0ac52112dc0d5f4ab9a79ac8ca1cc1bbc": "99/4A console GROM 0 (ti99_4a, ti99_4ae, ti99_4ev: 994a_grom0.u500)", "3ecead4b83ec525084c70b6123d4053f8a80e1f7": "99/4A console GROM 1 (ti99_4a, ti99_4ae, ti99_4qi: 994a_grom1.u501)", "e255f0d65d69b927cecb8fcfac7a4c17d585ea96": "99/4A console GROM 2 (ti99_4a, ti99_4ae, ti99_4ev, ti99_4qi: 994a_grom2.u502)", "95dcf5b7350ade65297eadd2d680c27561cc975c": "99/4QI console GROM 0 (ti99_4qi: 994qi_grom0.u29)", "1a98de5ee886dce705de5cce11034a7be31aceac": "99/4A GROM 1 patched for the EVPC (ti99_4ev: 994ev_grom1.u501)", "d085213c64701d429ae535f9a4ac8a50427a8343": "99/4 console ROM, high byte (ti99_4, ti99_4e: 994_rom_hb.u610)", "7741ae9294c51a44a78033d1b77c01568a6bbfb9": "99/4 console ROM, low byte (ti99_4, ti99_4e: 994_rom_lb.u611)", "4658d3d01c0131c283a30cebd12e76754d41a84a": "99/4 console GROM 0 (ti99_4, ti99_4e: 994_grom0.u500)", "6d849a76011273a069a98ed0c3feaf13831c942f": "99/4 console GROM 1 (ti99_4, ti99_4e: 994_grom1.u501)", "725e3f26f8c819f356e4bb405b4102b5ae1e0e70": "99/4 console GROM 2 (ti99_4, ti99_4e: 994_grom2.u502)", "0ef4f178716b575a1c0c970c56af8a8d97561ffe": "Speech Synthesizer VSM 0 (ti99_speech: cd2325a.u2a)", "a367242c2c96cebf0e2bf21862f3f6734b2b3020": "Speech Synthesizer VSM 1 (ti99_speech: cd2326a.u2b)", "0c24fb4944843ad3f08b0b139244a6bb05e1c6c2": "TI disk controller DSR ROM, u26 (ti99_fdc: fdc_dsr.u26)", "3646c3bcd2dce16b918ee01ea65312f36ae811d2": "TI disk controller DSR ROM, u27 (ti99_fdc: fdc_dsr.u27)", "6e8060f86e3bb9c36f244d88825e3fe237bfe9a9": "SNUG EVPC DSR ROM (ti99_4ev, ti99_4p: evpc_dsr.u21)", "35e585b2dcd3f2a0005bebb15ede6c5b8c787366": "SNUG SGCPU ROM, high byte (ti99_4p: sgcpu_hb.bin)", "dec141fe2eea0b930859cbe1ebd715ac29fa8ecb": "SNUG SGCPU ROM, low byte (ti99_4p: sgcpu_lb.bin)", } MAME_SETS = ("ti99_4a", "ti99_4ae", "ti99_4", "ti99_4e", "ti99_4ev", "ti99_4qi", "ti99_4p", "ti99_speech", "ti99_fdc") NOINTRO_FOLDER = "Texas Instruments - TI-99-4A" def sha1(data: bytes) -> str: return hashlib.sha1(data).hexdigest() def report_zip(path: Path, seen: dict[str, list[str]]) -> None: with zipfile.ZipFile(path) as archive: for member in archive.infolist(): if member.is_dir(): continue digest = sha1(archive.read(member)) seen.setdefault(digest, []).append(f"{path.name}:{member.filename} ({member.file_size} bytes)") def firmware(_: argparse.Namespace) -> int: seen: dict[str, list[str]] = {} rompath = os.environ.get("MAME_ROMPATH") if not rompath: print("set MAME_ROMPATH (MAME's ';'-separated rompath)", file=sys.stderr) return 2 for folder in rompath.split(";"): for name in MAME_SETS: candidate = Path(folder) / f"{name}.zip" if candidate.is_file(): report_zip(candidate, seen) extra = os.environ.get("TI99_BIOS_DIR") if extra: for path in sorted(Path(extra).iterdir()): if path.suffix.lower() == ".zip": report_zip(path, seen) elif path.is_file() and path.stat().st_size <= 1 << 20: seen.setdefault(sha1(path.read_bytes()), []).append(path.name) found = 0 for digest, role in KNOWN.items(): where = seen.get(digest) found += bool(where) print(f"{'have' if where else 'MISSING':7} {digest} {role}") for place in where or []: print(f" {place}") unknown = [d for d in seen if d not in KNOWN] print(f"{found} of {len(KNOWN)} known images present; {len(unknown)} other images in those sets") for digest in unknown: print(f" other {digest} {', '.join(seen[digest])}") return 0 def nointro(_: argparse.Namespace) -> int: base = os.environ.get("NO_INTRO_DIR") if not base: print("set NO_INTRO_DIR to the directory holding the No-Intro sets", file=sys.stderr) return 2 folder = Path(base) / NOINTRO_FOLDER if not folder.is_dir(): near = [p.name for p in Path(base).iterdir() if "texas" in p.name.lower() or "ti-99" in p.name.lower()] print(f"absent: no '{NOINTRO_FOLDER}' folder under $NO_INTRO_DIR " f"({len(list(Path(base).iterdir()))} sets there; TI-like names: {near or 'none'})") return 1 names = sorted(p.name for p in folder.iterdir() if p.is_file()) regions: collections.Counter[str] = collections.Counter() tags: collections.Counter[str] = collections.Counter() exts: collections.Counter[str] = collections.Counter() for name in names: groups = re.findall(r"\(([^)]*)\)", name) regions[groups[0] if groups else "?"] += 1 for group in groups[1:]: for tag in ("Rev", "Demo", "Beta", "Proto", "Sample", "Unl", "Alt", "Program"): if group.startswith(tag): tags[tag] += 1 if name.lower().endswith(".zip"): with zipfile.ZipFile(folder / name) as archive: for member in archive.namelist(): exts[Path(member).suffix.lower()] += 1 else: exts[Path(name).suffix.lower()] += 1 print(f"{len(names)} files") for region, count in regions.most_common(): print(f" {count:5} {region}") print("tags:", dict(tags)) print("member extensions:", dict(exts)) return 0 def softlist(_: argparse.Namespace) -> int: path = ROOT / "reference" / "hash" / "ti99_cart.xml" if not path.is_file(): print("run python -I scripts/fetch_references.py first", file=sys.stderr) return 2 root = ET.parse(path).getroot() software = root.findall("software") pcbs: collections.Counter[str] = collections.Counter() areas: collections.Counter[str] = collections.Counter() publishers: collections.Counter[str] = collections.Counter() sizes: dict[str, collections.Counter[int]] = collections.defaultdict(collections.Counter) for entry in software: publishers[entry.findtext("publisher") or "?"] += 1 for part in entry.findall("part"): features = {f.get("name"): f.get("value") for f in part.findall("feature")} pcb = features.get("pcb", "(none)") pcbs[pcb] += 1 names = [] for area in part.findall("dataarea"): names.append(area.get("name")) sizes[area.get("name")][int(area.get("size"), 0)] += 1 areas["+".join(sorted(names))] += 1 print(f"{len(software)} cartridges in {root.get('name')} ({root.get('description')})") print("PCB types:") for pcb, count in pcbs.most_common(): print(f" {count:5} {pcb}") print("data areas:") for combo, count in areas.most_common(): print(f" {count:5} {combo}") for name, counter in sorted(sizes.items()): print(f"{name} sizes: " + ", ".join(f"{size:#x} x{n}" for size, n in sorted(counter.items()))) print("publishers (top 10):", ", ".join(f"{p} {n}" for p, n in publishers.most_common(10))) return 0 def main() -> int: parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) sub = parser.add_subparsers(dest="command", required=True) sub.add_parser("firmware").set_defaults(run=firmware) sub.add_parser("nointro").set_defaults(run=nointro) sub.add_parser("softlist").set_defaults(run=softlist) args = parser.parse_args() return args.run(args) if __name__ == "__main__": sys.exit(main())