# SPDX-License-Identifier: MIT """The board's cart table: facts per payload SHA-1, built from data by ``scripts/build_cart_table.py``. docs/cartridge.md, "The table". Sources, none of them code: - ``nointro``: the No-Intro DAT "Atari - Atari Lynx (LYX)" (names, sizes, hashes); - ``softlist``: MAME 0.285 ``hash/lynx.xml`` (CC0-1.0): ``granularity`` (block size), ``rotation``, ``audin_offset``; an entry there with no rotation or AUDIN feature means none, and MAME has no EEPROM support, so a softlist entry says "no EEPROM" only in the sense that the commercial carts it lists had none; - ``lnx-header``: the LNX headers of our own files whose payload has that hash (our observation of files we hold). Where two sources give a field, the softlist wins inside the table and the disagreement is kept in the entry's ``conflicts`` (C14: Zaku (Beta); Raiden). """ from __future__ import annotations import json from dataclasses import dataclass, field from functools import cache from importlib import resources from typing import Any FIELDS = ("bank0_block", "bank1_block", "audin", "rotation", "eeprom") @dataclass(frozen=True) class TableEntry: sha1: str name: str | None size: int | None crc32: str | None fields: dict[str, tuple[Any, str]] # field -> (value, source) lnx_header: dict[str, Any] | None conflicts: tuple[dict[str, Any], ...] = field(default=()) sources: tuple[str, ...] = field(default=()) class CartTable: def __init__(self, raw: dict[str, Any]) -> None: self.about: dict[str, Any] = raw.get("about", {}) self._entries: dict[str, dict[str, Any]] = raw.get("entries", {}) def __len__(self) -> int: return len(self._entries) def __contains__(self, sha1: str) -> bool: return sha1 in self._entries def get(self, sha1: str) -> TableEntry | None: raw = self._entries.get(sha1) if raw is None: return None fields = {} for key, item in raw.get("fields", {}).items(): value = item["value"] if key == "eeprom" and value is not None: value = (value[0], value[1]) fields[key] = (value, item["source"]) return TableEntry( sha1=sha1, name=raw.get("name"), size=raw.get("size"), crc32=raw.get("crc32"), fields=fields, lnx_header=raw.get("lnx_header"), conflicts=tuple(raw.get("conflicts", ())), sources=tuple(raw.get("sources", ())), ) def sha1s(self) -> list[str]: return list(self._entries) @cache def default_table() -> CartTable: """The table shipped with the package (``cart/table.json``).""" text = resources.files("lynx_python.cart").joinpath("table.json").read_text("utf-8") return CartTable(json.loads(text)) def empty_table() -> CartTable: return CartTable({})