// SPDX-License-Identifier: MIT //! Milestone 1, exit (b): the BIOS picks the mode, on both BIOS rows (the reference's //! tests/test_bios_modes.py). The reference marks the whole-board runs `slow`; here they //! are fast enough to run always. mod common; use a7800::board::{EXT, LOCK, MEN}; use a7800::cartridge::bios_test::bios_verdict_default; use a7800::cartridge::connector::{Cartridge, Linear}; use a7800::cartridge_any; use a7800::machine::{Machine, NTSC, PAL}; use a7800::system::System; /// A 2K/4K 2600 cartridge on the middle 24 contacts: it answers where A12 is high. struct Plain2600 { rom: Vec, } impl Cartridge for Plain2600 { fn access(&mut self, address: u16, _data: u8, read: bool, _halt: bool, _t: u64) -> Option { if read && address & 0x1000 != 0 { return Some(self.rom[address as usize % self.rom.len()]); } None } cartridge_any!(); } #[test] fn bios_test_verdicts() { for row in ["ntsc", "pal"] { let bios = if row == "ntsc" { common::ntsc_bios() } else { common::pal_bios() }; let (Some(bios), Some(asteroids), Some(combat), Some(centipede)) = ( bios, common::licensed("Asteroids (USA).zip"), common::a2600("Combat (Europe).zip"), common::licensed("Centipede (Europe).zip"), ) else { return; }; assert_eq!(bios_verdict_default(&bios, &asteroids).unwrap(), "7800"); assert_eq!(bios_verdict_default(&bios, &combat).unwrap(), "2600"); // the NTSC BIOS refuses a PAL cartridge by its region byte; the PAL BIOS takes it (C8) let expected = if row == "ntsc" { "2600" } else { "7800" }; assert_eq!(bios_verdict_default(&bios, ¢ipede).unwrap(), expected); } } fn run_to_mode(system: &mut System, frames: u64) { let max = system.machine.frame_clocks() * frames; system.run_until( |s| s.board().locked || (s.mode() == "7800" && (0x4000..0xF000).contains(&s.cpu.pc)), max, ); } #[test] fn bios_locks_a_2600_image_into_2600_mode() { for machine in [NTSC, PAL] { let Some(combat) = common::a2600("Combat (Europe).zip") else { return; }; let Ok(mut system) = System::new(Box::new(Plain2600 { rom: combat }), machine, None, "bios", None) else { eprintln!("skipped: no BIOS for {}", machine.name); return; }; run_to_mode(&mut system, 60); let board = system.board(); assert!(board.locked && board.inptctrl & (LOCK | MEN | EXT) == LOCK | EXT); assert_eq!(system.mode(), "2600"); // The lock holds: the 2600 program's own TIA writes must not reach the latch. let latch = board.inptctrl; system.run_frames(2); assert_eq!(system.board().inptctrl, latch); } } #[test] fn pal_bios_starts_a_7800_image_in_7800_mode() { let Some(centipede) = common::licensed("Centipede (Europe).zip") else { return; }; let machine: Machine = PAL; let Ok(mut system) = System::new(Box::new(Linear::new(¢ipede).unwrap()), machine, None, "bios", None) else { eprintln!("skipped: no PAL BIOS"); return; }; run_to_mode(&mut system, 60); assert!(system.mode() == "7800" && system.board().inptctrl & (MEN | EXT) == MEN | EXT); }