# SPDX-License-Identifier: MIT # Holds data from MAME 0.285 hash/a7800.xml (CC0-1.0, via mame_softlist.json) and the # slot names of MAME's bus/a7800/a78_slot.cpp and a78_carts.h (BSD-3-Clause, Fabio # Priuli; facts only, no code). Notices and attribution: NOTICE, sections 1 and 2. """The payload-hash table: which hardware a headerless dump needs. Two kinds of rows, and only two, may be committed (docs/handoff-brief.md "Open decisions" 6, decided (b)): 1. **softlist**: MAME 0.285's ``hash/a7800.xml``, CC0-1.0, copied by ``scripts/make_cart_table.py`` into ``mame_softlist.json``. An entry matches a payload when its ROM chips, concatenated in list order, are the payload (SHA-1 per chip, as the list keys them). 2. **confirmed**: rows in :data:`CONFIRMED`, each confirmed by this project from the dump's own bytes or its behaviour on this board, written in our own words, each citing how it was confirmed. Seventeen today: Double Dragon (NTSC), Double Dragon (PAL) and Rampage (NTSC), the Activision dumps whose bytes are the CC0 list's entries with the 8 KiB halves of every bank exchanged (``scripts/outside_softlist.py``; the facts are the CC0 entries', the chip order ours), and 14 SuperGame dumps with bank 6 at $4000, confirmed from their own code (:data:`_BANK6`). No row comes from a GPL table. The GPL tables themselves (ProSystem.dat, A7800DS's Database.c) are never read here; ``scripts/count_carts.py`` reads them at run time from the ignored ``reference/`` tree, as detectors' answers. """ from __future__ import annotations import collections import hashlib import json from dataclasses import dataclass from functools import cache from pathlib import Path DATA = Path(__file__).with_name("mame_softlist.json") @dataclass(frozen=True) class Row: """One cartridge's hardware, as a table states it.""" source: str # "softlist" or "confirmed" key: str # software name (softlist) or payload SHA-256 (confirmed) title: str scheme: str at_4000: str pokey: tuple[int, ...] hsc: bool xm: bool region: str lightgun: bool citation: str # MAME slot feature -> (scheme, $4000 option, POKEY bases, hsc, xm). Read off # MAME 0.285's src/devices/bus/a7800/a78_slot.cpp slot names and # a78_carts.h descriptions (OBSERVED: MAME 0.285's statement of each board); the # 144 KiB "a78_sg9" boards carry a ninth ROM bank at $4000 and the 128 KiB one # bank 6 there (C9, settled per dump by size; DOC: Stolberg's options). SLOTS = { "a78_rom": ("linear", "none", ()), "a78_pokey": ("linear", "pokey", (0x4000,)), "a78_sg": ("supergame", "none", ()), "a78_sg_pokey": ("supergame", "pokey", (0x4000,)), "a78_sg_ram": ("supergame", "ram16", ()), "a78_sg9": ("supergame", "rom", ()), "a78_mram": ("linear", "mirror-ram-2k", ()), "a78_abs": ("absolute", "none", ()), "a78_act": ("activision", "none", ()), "a78_hsc": ("linear", "none", ()), "a78_xboard": ("linear", "none", (0x450,)), "a78_xm": ("linear", "none", (0x450,)), "a78_p450_t0": ("linear", "none", (0x450,)), "a78_p450_t1": ("linear", "pokey", (0x4000, 0x450)), "a78_p450_t6": ("supergame", "ram16", (0x450,)), "a78_p450_ta": ("supergame", "rom", (0x450,)), } def _softlist_row(entry: dict) -> Row: scheme, at_4000, pokey = SLOTS[entry["slot"]] size = sum(r[0] for r in entry["roms"]) if entry["slot"] in ("a78_sg9", "a78_p450_ta") and size == 0x20000: at_4000 = "fixed-bank" # 128 KiB: no ninth bank, bank 6 at $4000 (C9) if entry["slot"] in ("a78_sg_ram", "a78_p450_t6") and entry["ram"] == 0x2000: at_4000 = "ram8-mirror" # 8 KiB RAM in the list (OBSERVED: MAME 0.285); DOC: Stolberg region ={"NTSC": "ntsc", "PAL": "pal"}.get(entry["compatibility"] or "", "unknown") return Row( "softlist", entry["name"], entry["description"], scheme, at_4000, pokey, entry["slot"] == "a78_hsc", entry["slot"] in ("a78_xm", "a78_xboard"), region, entry["lightgun"], f"MAME 0.285 hash/a7800.xml '{entry['name']}' slot {entry['slot']}", ) # fmt: skip @cache def _softlist() -> tuple[dict, dict[int, list[dict]]]: data = json.loads(DATA.read_text(encoding="utf-8")) by_size: dict[int, list[dict]] = collections.defaultdict(list) for entry in data["entries"]: if entry["roms"] and entry["slot"] in SLOTS: by_size[sum(r[0] for r in entry["roms"])].append(entry) return data, by_size def softlist_version() -> str: return _softlist()[0]["mame_version"] # Rows confirmed by this project (see the module docstring). Payload SHA-256 -> # Row, each saying how it was confirmed. # # The three Activision dumps: MAME's CC0 list has these ROMs, but stores them # with the two 8 KiB halves of every 16 KiB bank exchanged (its Activision # mapping reads $A000 from a bank's second half; Stolberg's guide, whose # layout this board follows, from its first). Confirmed by the dumps' own # bytes: each payload, so rearranged, has exactly the SHA-1 of the named list # entry (scripts/outside_softlist.py, milestone 3). The facts are the CC0 # list's; only the chip order is ours. _ACTIVISION = "confirmed: = MAME 0.285 hash/a7800.xml '{}' (CC0) with 8 KiB halves exchanged" CONFIRMED: dict[str, Row] = { "12e5272697550c7b4d40db1937f157a3fa9c65a8fa0f4b40aba5a96e780f3fad": Row( "confirmed", "ddragonu", "Double Dragon (NTSC)", "activision", "none", (), False, False, "ntsc", False, _ACTIVISION.format("ddragonu"), ), "126fbe59060f41861f3c779d8df7e0b70e2454ad9c6d273a64b7dafd57ed5973": Row( "confirmed", "ddragon", "Double Dragon (PAL)", "activision", "none", (), False, False, "pal", False, _ACTIVISION.format("ddragon"), ), "5cdd510c97021f7c74bb635398278185efd265c14cd0bb29510159c4704bb049": Row( "confirmed", "rampage", "Rampage (NTSC)", "activision", "none", (), False, False, "ntsc", False, _ACTIVISION.format("rampage"), ), } # fmt: skip # Bank 6 fixed at $4000-$7FFF on 128 KiB SuperGame boards: what the CC0 list # does not say. It types every plain 128 KiB SuperGame board ``a78_sg`` and # states nothing about $4000-$7FFF; Stolberg's guide (tier 3) says "some games # have bank 6 fixed at this area" without naming them. The rule used here: # a dump gets bank 6 at $4000 when **its own bytes** show the need, i.e. code # that the fixed bank (bank 7 at $C000) reaches by its own flow from the # vectors calls or jumps into $4000-$7FFF, and bank 6, placed there, is code # from those targets (thousands of documented instructions, none # undocumented). ``scripts/scan_4000.py`` makes that check; of the 64 and # 128 KiB SuperGame dumps in the licensed set exactly these 14 meet it, and no # other dump has a single such call. Evidence per row: (first call site -> # target, calls found, bank-6 instructions reached from them). The first # four were found by the milestone-3 boot sweep (black at frame 400 with # nothing at $4000; Basketbrawl and Scrapyard Dog fell into 2600 mode, the # BIOS's signature check failing), Xenophobe (USA) by the frame compare (its # call from $F7E5 is the instruction stream MAME 0.285's trace runs there); # the rest by the scan. The rest of each row is the CC0 list's entry. Evidence: the # option DOC (Stolberg); which dumps, the dumps' own code (read, not run). _BANK6 = { "050ad25f716eaa9df63ea3bd897656b2742d3db32a936a6ce720c5c026f9612e": ("Basketbrawl (USA)", "reset vector -> $FD35 JMP $4D64, 1 call, 4,704"), "6b7cde57e026d97b7696aff8a1ff24afac50bec960dc31a63aed50750052bb7f": ("Basketbrawl (Europe)", "reset vector -> $FD35 JMP $4D70, 1 call, 4,677"), "7fcd51b4c54feb8eebae9f2c2e0c63f1ebaf86bd04f9238825d1e4d4e99d0468": ("Scrapyard Dog (USA)", "$F7A5 -> $4002, 1 call, 2,612"), "29fc4bb1ecad0f4c5af85164fe13498a8f96fb59eb7a4eca11f388dbe36aefb4": ("Scrapyard Dog (Europe)", "$F7A5 -> $4002, 1 call, 2,612"), "3d17789bf2cfa187e3cbdec6a7c8fd65924efcccec90d0ce54917a9252878680": ("Midnight Mutants (USA)", "$FF21 -> $4000, 1 call, 3,464"), "49f0dfe29c05a93178cd8dcd2e317dadb43793f29a777b8114d1a6d63a51dee8": ("Midnight Mutants (Europe)", "$FF21 -> $4000, 1 call, 3,464"), "501af1f3c2a8ceee19d35113de0b68ce26374ad24a1b3a85ba88fff30dd25c7f": ("Meltdown (USA)", "$C81D -> $4000, 1 call, 1,223"), "0921f020d97a0de260a4fe2ed548703cef436abc068faa174821653b373443a2": ("Meltdown (Europe)", "$C81D -> $4000, 1 call, 1,223"), "3239db5465f42d4e05220a50fd7a489687c441539dcd287b57ea7208f9753f28": ("Xenophobe (USA)", "$F7E5 -> $6EA4, 35 calls, 453"), "5233eb4782033ede4044a83815a78b93a339899cfac5cd0b255513946de27296": ("Xenophobe (Europe)", "$F7E5 -> $6EE8, 35 calls, 453"), "aabbf94532d88428a7df26c27c5b4286f3848dc2f9fc39a13fb65b661622064b": ("Fatal Run (USA)", "$D333 -> $685D, 19 calls, 1,871"), "5d00b144b258f38f30a26654479ba257f9cd59ec20222510fe8232fa1c00e736": ("Fatal Run (Europe)", "$D333 -> $685D, 19 calls, 1,871"), "9a2d9bda7c19386a4a1111090174ec0fc39fbacfd2529874e83dacd65de7cf9f": ("Touchdown Football (USA)", "$D0AB -> $6000, 14 calls, 538"), # 64 KiB: "bank 6" is the dump's third 16 KiB (banks masked to four). # Stolberg names this one: "PAL Karateka ... only uses banks 4-7 ... and # bank 6 is also fixed at $4000-$7fff". "b733ceffcb351ac7e56a9cb4a8a98251c77ecb82e2246b5f24682f26a6500961": ("Karateka (Europe)", "reset vector $4000, NMI $58E5, IRQ $59E4, 3 calls, 164"), } # fmt: skip # The same board option shown by the dump's behaviour instead of its code: run # from the BIOS with nothing at $4000 (``scripts/uses_4000.py``, frame 400), # each of these fetches from $4000-$7FFF, as display-list or graphics reads by # MARIA (DMA) or as CPU reads of tables, with no write to the address first # (a write-then-read is a RAM probe: Planet Smashers and Sentinel probe # $4000-$5DFF that way, and Planet Smashers does nothing else there, so it gets # no row). What sits there is bank 6: with it, each title's frame 400 shows # the picture that was garbled or missing (Ace of Aces, Mean 18, Klax: the # title art and text are fetched there). Evidence: (first access, counts). Tag: the # option DOC (Stolberg); the choice per dump FITTED to its frame-400 picture on this # board (the alternative tried: nothing at $4000, garbled or missing art). _BANK6_BEHAVIOUR = { "749cbebd7f950223efe7b24f43a4baa368f6068cc4078600918a4b3dbb7713b9": ("Ace of Aces (USA)", "DMA from $4726 at frame 161, 63,096 DMA and 552 CPU reads"), "4f1d3158b8915388a3b7be01e446c4abdff69764576f79faa563113903373ed4": ("Ace of Aces (Europe)", "DMA from $4726 at frame 5, 104,224 DMA and 552 CPU reads"), "02eeb391cd00f500d40ba5afc902090ab2753b163ac90e72c52c3bb1b0985433": ("Dark Chambers (USA)", "DMA from $731A at frame 128, 7,725 DMA reads"), "37ff94f060480bda1f66b540c29709bbefae1a44c51994b28520a4e8d7fd8100": ("Fight Night (USA)", "CPU reads from $4C3C at frame 162, 474 reads"), "df321876394ed8fe2471f95c1499b610c213ca0f90ceebd73f81717c9552574e": ("Klax (USA) (Proto)", "DMA from $7373 at frame 165, 107,015 DMA reads"), "645fa4dec063e18fa4ccc3de83fa1839b30d01151881e108a13cd6ca26d6d521": ("Mean 18 Ultimate Golf (USA)", "DMA from $7F53 at frame 163, 1,213,440 DMA reads"), "6592c476a80076fa7c133ca1283c88c9ecdfc10a314ccb6a675769100b8e8a96": ("Mean 18 Ultimate Golf (Europe)", "DMA from $7F53 at frame 8, 2,006,720 DMA reads"), "b5bb5a789a55ef60235edc43da72a8a88c4cb23e9fa99ac6acf9f62bbf810b3d": ("Ninja Golf (USA)", "DMA from $5555 at frame 161, 381,400 DMA reads"), "41efbf839627f6d8cc4e289cfdad604ad6fb54771194994731053f7b30a8dca0": ("Ninja Golf (Europe)", "DMA from $5500 at frame 6, 635,277 DMA reads"), "68767f30282bddb1a46b830cf7722a32ecb29c2e0dd80a14fe568c78153aa8f0": ("Rampart (USA) (Proto)", "DMA from $7060 and CPU reads from $783C at frame 163"), "9ed55ee94011b76f630841a19c13e18f628510271471a88381d20bed6566e16f": ("Sentinel (USA) (Proto)", "DMA from $7743 at frame 166, 832,088 DMA reads"), "807ee2cc97963f6132e47beef76ca553b62b2c0c2cea69d2365ee0e6f36ee4cc": ("Sentinel (Europe)", "DMA from $7743 at frame 6, 1,411,824 DMA reads"), } # fmt: skip def lookup(payload: bytes) -> Row | None: """The table's row for this exact payload, or None.""" digest = hashlib.sha256(payload).hexdigest() row = CONFIRMED.get(digest) if row is not None: return row for entry in _softlist()[1].get(len(payload), ()): offset = 0 for size, _crc, sha1 in entry["roms"]: if hashlib.sha1(payload[offset : offset + size]).hexdigest() != sha1: break offset += size else: row = _softlist_row(entry) if digest in _BANK6 or digest in _BANK6_BEHAVIOUR: if digest in _BANK6: citation = (f"confirmed from the dump's own bytes (scripts/scan_4000.py): " f"bank 6 at $4000, fixed-bank code calls it ({_BANK6[digest][1]}" f" instructions of bank 6); otherwise {row.citation}") # fmt: skip else: citation = (f"confirmed from the dump's behaviour (scripts/uses_4000.py): " f"bank 6 at $4000, read with nothing written there " f"({_BANK6_BEHAVIOUR[digest][1]}); otherwise " f"{row.citation}") # fmt: skip row = Row("confirmed", row.key, row.title, row.scheme, "fixed-bank", row.pokey, row.hsc, row.xm, row.region, row.lightgun, citation) # fmt: skip return row return None def hsc_rom_row(payload: bytes) -> bool: """True if ``payload`` is the High Score Cartridge's ROM as MAME lists it ('hsc').""" row = lookup(payload) return row is not None and row.hsc