// SPDX-License-Identifier: MIT //! Immutable values for capturing and restoring SPC700 processor state (`state.py`). //! //! Differences forced by Rust: the reference's dataclass checks each field's //! type and range in `__post_init__`; here the field types are those ranges, so //! there is nothing left to check. /// Complete CPU-owned state at an instruction boundary. /// /// It excludes host memory, devices, scheduling and counters, so restoring it /// restores the processor, not a machine. The defaults are the values the /// reference's U12 names: ares' power-on registers, which equal the state the /// IPL ROM leaves for uploaded code, except PC. #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct CpuState { pub a: u8, pub x: u8, pub y: u8, pub sp: u8, pub pc: u16, pub psw: u8, pub stopped: bool, } impl Default for CpuState { fn default() -> Self { CpuState { a: 0, x: 0, y: 0, sp: 0xEF, pc: 0, psw: 0x02, stopped: false, } } } impl CpuState { /// Y:A, the 16-bit pair of MOVW, ADDW, SUBW, CMPW, MUL and DIV. pub fn ya(&self) -> u16 { (self.y as u16) << 8 | self.a as u16 } }