#!/usr/bin/env python3 # SPDX-License-Identifier: MIT # Matches against MAME's hash/a7800.xml (CC0-1.0); cites MAME bus/a7800/rom.cpp # (BSD-3-Clause, Fabio Priuli) for one fact. NOTICE, sections 1 and 2. """Milestone 3: the licensed No-Intro dumps MAME's CC0 list does not match, one by one. For each licensed dump whose payload no table row matches, ask whether it is the same ROM in another chip order (MAME's list keys whole chips by SHA-1, so an order difference is a miss): the payload is rearranged by each of a few fixed transforms and hashed against every list entry's concatenated chips. - ``swap-8k``: the two 8 KiB halves of every 16 KiB bank exchanged (MAME's Activision mapping reads $A000 from a bank's second half, Stolberg's from its first; `bus/a7800/rom.cpp` against the wiki's guide); - ``reverse-16k``: the 16 KiB banks in reverse order; - ``swap-16k``: the two 16 KiB halves of every 32 KiB exchanged. A miss under every transform is reported as "bytes differ", with the list entries of the same title (by MAME's description) for the record. python scripts/outside_softlist.py """ from __future__ import annotations import hashlib import json import re import sys import zipfile from pathlib import Path ROOT = Path(__file__).resolve().parents[1] sys.path.insert(0, str(ROOT / "src")) from a7800_python import romsets # noqa: E402 from a7800_python.cartridge import table # noqa: E402 LICENSED = romsets.no_intro(romsets.LICENSED_7800) def blocks(data: bytes, size: int) -> list[bytes]: return [data[i : i + size] for i in range(0, len(data), size)] TRANSFORMS = { "swap-8k": lambda d: b"".join(b[0x2000:] + b[:0x2000] for b in blocks(d, 0x4000)), "reverse-16k": lambda d: b"".join(reversed(blocks(d, 0x4000))), "swap-16k": lambda d: b"".join(b[0x4000:] + b[:0x4000] for b in blocks(d, 0x8000)), } def main() -> int: entries = json.loads(table.DATA.read_text())["entries"] whole = {} for entry in entries: if entry["roms"]: chips = entry["roms"] whole[(sum(c[0] for c in chips), tuple(c[2] for c in chips))] = entry outside = 0 for path in sorted(LICENSED.glob("*.zip")): if path.name.startswith("[BIOS]"): continue with zipfile.ZipFile(path) as z: payload = z.read(z.infolist()[0]) if table.lookup(payload) is not None: continue outside += 1 found = None for name, transform in TRANSFORMS.items(): moved = transform(payload) row = table.lookup(moved) if row is not None: found = (name, row.key) break title = re.sub(r" \(.*", "", path.stem).lower() same = [e["name"] for e in entries if title.split(" - ")[0][:10] in e["description"].lower()] if found: print(f"chip order ({found[0]}): {path.stem} = MAME '{found[1]}'") else: print(f"bytes differ: {path.stem} ({len(payload)} bytes, sha1 " f"{hashlib.sha1(payload).hexdigest()[:12]}); list entries of the title: " f"{', '.join(same) or 'none'}") # fmt: skip print(f"{outside} licensed dumps outside the list") return 0 if __name__ == "__main__": sys.exit(main())