// SPDX-License-Identifier: MIT //! Public ARM7TDMI CPU API. //! //! Transcribed from `arm7tdmi_python/cpu.py`. The host owns memory and every device. It //! implements [`Bus`], calls [`ARM7TDMI::step`], and advances its devices **inside** the //! callbacks: every bus cycle is one callback, in chip order, internal cycles included, so the //! host never adds `step()`'s return value on top. See the reference's docs/handoff-brief.md //! "The bus contract". use crate::core::{Bus, ARM7TDMI}; use crate::modes::{MASK_F, MASK_I, SVC}; impl ARM7TDMI { /// A CPU in the reset state whose bus is `bus` (the reference's /// `ARM7TDMI(read, write, idle)`; the decode tables are static here). pub fn new(bus: B) -> Self { ARM7TDMI::init_registers(bus) } /// nRESET: Supervisor mode, ARM state, I and F set, PC = 0, then the two refill /// fetches, N at 0 and S at 4 (TRM 2.10, 3.10). Other registers keep their values. pub fn reset(&mut self) { self.switch_mode(SVC); self.cpsr = (self.cpsr | MASK_I | MASK_F) & !0x20; self.cycles = 0; self.set_pc(0); } /// R15 <- `address` and the two refill fetches, as a branch there would (in the /// current state, ARM or Thumb). For hosts that start without a BIOS: the minimal harness, /// and a board's skip-BIOS start. pub fn start_at(&mut self, address: u32) { self.cycles = 0; self.set_pc(address); } }