// SPDX-License-Identifier: MIT //! Shared helpers (the reference's tests/conftest.py): tiny cartridges built //! from hand-assembled 6502 code, and where the reference's data lives. #![allow(dead_code)] use std::path::PathBuf; use a2600::board::Board; use a2600::cartridge::connector::Cartridge; use a2600::cartridge::{load, mame_hash, Options, Rom}; use a2600::machine::VCS_NTSC; use a2600::System; /// A 4K image with `program` at its start and the reset vector pointing at it. pub fn image_4k(program: &[u8]) -> Vec { image_4k_at(program, 0xF000) } pub fn image_4k_at(program: &[u8], origin: u16) -> Vec { let mut rom = vec![0u8; 0x1000]; rom[..program.len()].copy_from_slice(program); rom[0xFFC] = (origin & 0xFF) as u8; rom[0xFFD] = (origin >> 8) as u8; rom } pub fn cart(image: &[u8], scheme: &str) -> Box { load(Rom::Bytes(image), Some(scheme), None, &mame_hash(), Options::default()) .expect("load") .cartridge } /// A powered-on console about to execute `program` (reset sequence done). pub fn system_running(program: &[u8]) -> System { let mut system = System::with_cartridge(cart(&image_4k(program), "4K")); system.step(); system } /// A fresh NTSC board with a blank 4K cartridge. pub fn blank_board() -> Board { Board::new(VCS_NTSC, cart(&[0u8; 0x1000], "4K"), None, None, 0).expect("board") } /// The a2600-python checkout whose fetched references the data tests read /// (`A2600_PYTHON_ROOT`, default `../a2600-python`). pub fn reference_root() -> PathBuf { match std::env::var("A2600_PYTHON_ROOT") { Ok(r) if !r.is_empty() => PathBuf::from(r), _ => PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../a2600-python"), } }