# SPDX-License-Identifier: MIT """Where romsets and firmware live: environment variables only, never a machine path. The family's rule (charter, methodology "Provenance in practice"): carts and the boot ROM are found through environment variables and read in place. - ``NO_INTRO_DIR``: the No-Intro root; the Lynx sets are its subdirectories ``Atari - Atari Lynx (LNX)``, ``(LYX)``, ``(LYX) (Aftermarket)``, ``(LYX) (Private)`` and ``(BLL)``. - ``MAME_ROMPATH``: MAME's ROM path (``;``-separated, as MAME takes it); the boot ROM is a member of ``lynx.zip`` there, found by hash. - ``LYNX_EXTRA_SETS``: optional further cart directories (``os.pathsep``-separated). - ``LYNX_NOINTRO_DAT``: optional path of the No-Intro LYX DAT (milestone 0's table). """ from __future__ import annotations import os from pathlib import Path NO_INTRO_SETS = ( "Atari - Atari Lynx (LNX)", "Atari - Atari Lynx (LYX)", "Atari - Atari Lynx (LYX) (Aftermarket)", "Atari - Atari Lynx (LYX) (Private)", "Atari - Atari Lynx (BLL)", ) def no_intro_dir() -> Path | None: value = os.environ.get("NO_INTRO_DIR") return Path(value) if value else None def no_intro_sets() -> dict[str, Path]: """Label -> directory for each Lynx set under ``$NO_INTRO_DIR`` (empty if unset).""" root = no_intro_dir() if root is None: return {} labels = ("No-Intro LNX", "No-Intro LYX", "No-Intro LYX Aftermarket", "No-Intro LYX Private") sets = {label: root / name for label, name in zip(labels, NO_INTRO_SETS, strict=False)} sets["No-Intro BLL"] = root / NO_INTRO_SETS[4] return sets def extra_sets() -> dict[str, Path]: value = os.environ.get("LYNX_EXTRA_SETS", "") return {f"extra {Path(p).name}": Path(p) for p in value.split(os.pathsep) if p} def all_sets() -> dict[str, Path]: return {**no_intro_sets(), **extra_sets()} def mame_rompaths() -> list[Path]: value = os.environ.get("MAME_ROMPATH", "") return [Path(p) for p in value.split(";") if p] def nointro_dat() -> Path | None: value = os.environ.get("LYNX_NOINTRO_DAT") return Path(value) if value else None def find_cart(title: str) -> Path | None: """The first file under the No-Intro Lynx sets whose name starts with ``title``.""" for directory in no_intro_sets().values(): if directory.is_dir(): for path in sorted(directory.iterdir()): if path.name.startswith(title): return path return None