// SPDX-License-Identifier: MIT //! Where the romsets are: environment variables, never a machine path. //! //! The family's rule (emulator-lineage methodology, "Provenance in practice"): ROM, //! BIOS and MAME set locations come from the environment. //! //! - `NO_INTRO_DIR`: the No-Intro tree. The 7800 sets are the folders //! `Atari - Atari 7800 (BIN)`, `... (BIN) (Aftermarket)`, `... (BIN) (Private)`; //! 2600 mode's dumps are `Atari - Atari 2600`. //! - `MAME_ROMPATH`: MAME's non-merged sets; the BIOS images are in `a7800.zip` //! (NTSC) and `a7800p.zip` (PAL). //! - `RETROBAT_DIR` (optional, only for the census scripts): a curated set whose //! `atari7800` folder holds `.7z` copies; left out of the census when unset. //! //! The library's BIOS search (`system::find_bios`) treats an unset `MAME_ROMPATH` as //! "no BIOS here"; the tests skip, naming the variable. //! //! Rust-forced differences (a7800-python `romsets.py` at d6b220d): `RomsetUnset` is an //! error value. use std::path::PathBuf; pub const LICENSED_7800: &str = "Atari - Atari 7800 (BIN)"; pub const AFTERMARKET_7800: &str = "Atari - Atari 7800 (BIN) (Aftermarket)"; pub const PRIVATE_7800: &str = "Atari - Atari 7800 (BIN) (Private)"; pub const DUMPS_2600: &str = "Atari - Atari 2600"; /// A romset variable is not set in the environment. #[derive(Clone, Debug, PartialEq, Eq)] pub struct RomsetUnset(pub String); impl std::fmt::Display for RomsetUnset { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.write_str(&self.0) } } /// The folder named by environment variable `name`; an error naming it when unset. pub fn env_dir(name: &str, what: &str) -> Result { match std::env::var(name) { Ok(value) if !value.is_empty() => Ok(PathBuf::from(value)), _ => Err(RomsetUnset(format!( "{name} is not set: export it as the folder that holds {what}" ))), } } /// `$NO_INTRO_DIR/`. pub fn no_intro(folder: &str) -> Result { Ok(env_dir("NO_INTRO_DIR", "the No-Intro sets")?.join(folder)) } /// `$MAME_ROMPATH`: MAME's sets (a7800.zip, a7800p.zip). pub fn mame_rompath() -> Result { env_dir("MAME_ROMPATH", "MAME's sets (a7800.zip, a7800p.zip)") } /// `$RETROBAT_DIR/atari7800`, or None when the optional variable is unset. pub fn retrobat_7800() -> Option { match std::env::var("RETROBAT_DIR") { Ok(value) if !value.is_empty() => Some(PathBuf::from(value).join("atari7800")), _ => None, } }