// SPDX-License-Identifier: MIT //! Booting and running a cart: `boot` and `run_frames` of the reference's `__main__.py`, //! shared by the `lynx` command, `lynx-play`, the trace and the test-ROM harness. //! //! The cart is any image the front door takes (.lnx, .lyx, BLL; loose, .zip, .7z), read //! in place. The boot ROM is found by hash through `$MAME_ROMPATH` (crate::bootrom); //! without one the host-decryption path is not yet wired (as in the reference). //! //! Differences forced by Rust: Python's `SystemExit` for a missing boot ROM is an `Err`. use crate::board::Lynx; use crate::bootrom; use crate::cart::{eeprom, CartDescription}; use crate::machine::Machine; pub fn boot(description: &CartDescription, machine: Machine) -> Result { let rom = bootrom::find(None)?; let Some(rom) = rom else { // The host-decryption path (cart.decrypt) is checked against the ROM (M1) but // not yet wired to start a cart: the boot ROM's hand-over state is owed. return Err("no Lynx boot ROM found under $MAME_ROMPATH (lynx.zip)".into()); }; let mut board = Lynx::new( &description.payload, description.bank0_block, machine, Some(&rom), description.bank1(), description.bank1_block, ); // The cart's EEPROM, if its description has one, saved under the user's data // directory by payload SHA-1 (crate::cart::eeprom), never beside the ROM. board.hw_mut().port.eeprom = eeprom::for_cart(description); board.reset(); Ok(board) } pub fn run_frames(board: &mut Lynx, frames: u64) { let target = board.hw().mikey.display.frames + frames; while board.hw().mikey.display.frames < target { board.step(); } }