// SPDX-License-Identifier: MIT //! Save states (added here; the reference has none): saved anywhere between instructions, //! loaded into a fresh console, the run goes on identically. The gate's `--save-at-half` //! proves it against the reference; this checks the round trip on its own, mid-frame //! included (where MARIA's DMA engine can be waiting with its locals). mod common; use std::cell::RefCell; use std::rc::Rc; use a7800::cartridge::formats::{self, LoadOptions, Source}; use a7800::machine::NTSC; use a7800::state::{load_state, save_state}; use a7800::system::System; fn traced(system: &mut System) -> Rc>> { let log = Rc::new(RefCell::new(Vec::new())); let l = log.clone(); system .board_mut() .bus_observers .push(Box::new(move |k, a, v, c| l.borrow_mut().push((k, a, v, c)))); log } #[test] fn a_round_trip_mid_frame_goes_on_identically() { let Some(payload) = common::licensed("Commando (USA).zip") else { return; }; let build = || { let desc = formats::load(Source::Bytes(&payload), &LoadOptions::default()).unwrap(); let cartridge = formats::build(&desc).unwrap(); System::new(cartridge, NTSC, None, "direct", Some(desc)).unwrap() }; let mut a = build(); a.run_frames(40); for _ in 0..12_345 { a.step(); // somewhere inside a frame } let saved = save_state(&a); let mut b = build(); load_state(&mut b, &saved).unwrap(); let (la, lb) = (traced(&mut a), traced(&mut b)); for _ in 0..30 { a.run_frames(1); b.run_frames(1); assert_eq!(*la.borrow(), *lb.borrow()); assert_eq!(a.cpu.capture_state(), b.cpu.capture_state()); assert_eq!(a.board().maria.pixels, b.board().maria.pixels); la.borrow_mut().clear(); lb.borrow_mut().clear(); } }