// SPDX-License-Identifier: MIT //! Where romsets and firmware live: environment variables only, never a machine path //! (`romsets.py`). //! //! 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 (`:`-separated). //! - `LYNX_NOINTRO_DAT`: optional path of the No-Intro LYX DAT (milestone 0's table). //! //! Differences forced by Rust: the dicts are vectors of (label, directory) in the same //! order. use std::path::PathBuf; pub const NO_INTRO_SETS: [&str; 5] = [ "Atari - Atari Lynx (LNX)", "Atari - Atari Lynx (LYX)", "Atari - Atari Lynx (LYX) (Aftermarket)", "Atari - Atari Lynx (LYX) (Private)", "Atari - Atari Lynx (BLL)", ]; fn env(name: &str) -> Option { std::env::var(name).ok().filter(|v| !v.is_empty()) } pub fn no_intro_dir() -> Option { env("NO_INTRO_DIR").map(PathBuf::from) } /// Label -> directory for each Lynx set under `$NO_INTRO_DIR` (empty if unset). pub fn no_intro_sets() -> Vec<(String, PathBuf)> { let Some(root) = no_intro_dir() else { return Vec::new(); }; let labels = [ "No-Intro LNX", "No-Intro LYX", "No-Intro LYX Aftermarket", "No-Intro LYX Private", ]; let mut sets: Vec<(String, PathBuf)> = labels .iter() .zip(NO_INTRO_SETS) .map(|(l, n)| (l.to_string(), root.join(n))) .collect(); sets.push(("No-Intro BLL".into(), root.join(NO_INTRO_SETS[4]))); sets } pub fn extra_sets() -> Vec<(String, PathBuf)> { env("LYNX_EXTRA_SETS") .map(|v| { std::env::split_paths(&v) .filter(|p| !p.as_os_str().is_empty()) .map(|p| { let name = p .file_name() .map(|n| n.to_string_lossy().to_string()) .unwrap_or_default(); (format!("extra {name}"), p) }) .collect() }) .unwrap_or_default() } pub fn all_sets() -> Vec<(String, PathBuf)> { let mut sets = no_intro_sets(); sets.extend(extra_sets()); sets } pub fn mame_rompaths() -> Vec { env("MAME_ROMPATH") .map(|v| { v.split(';') .filter(|p| !p.is_empty()) .map(PathBuf::from) .collect() }) .unwrap_or_default() } pub fn nointro_dat() -> Option { env("LYNX_NOINTRO_DAT").map(PathBuf::from) } /// The first file under the No-Intro Lynx sets whose name starts with `title`. pub fn find_cart(title: &str) -> Option { for (_, directory) in no_intro_sets() { if directory.is_dir() { let mut paths: Vec = std::fs::read_dir(&directory) .ok()? .filter_map(|e| e.ok().map(|e| e.path())) .collect(); paths.sort(); for path in paths { if path .file_name() .map(|n| n.to_string_lossy().starts_with(title)) .unwrap_or(false) { return Some(path); } } } } None }