Skip to content

Commit

Permalink
DSP-1: add busy-loop detection
Browse files Browse the repository at this point in the history
  • Loading branch information
twvd committed Feb 3, 2024
1 parent bc97c62 commit e85ac42
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/snes/coprocessor/dsp1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@ use crate::tickable::{Tickable, Ticks};
/// DSP-1 co-processor
#[derive(Serialize, Deserialize)]
pub struct DSP1 {
/// uPD77C25 CPU core
cpu: RefCell<CpuUpd77c25>,

/// Last seen CPU PC register (for busy loop detection)
last_pc: u16,

/// Flip-flop to switch reading LSB/MSB of SR
sr_read_msb: Cell<bool>,
}

impl DSP1 {
pub fn new() -> Self {
Self {
last_pc: 0,
cpu: RefCell::new(CpuUpd77c25::new()),
sr_read_msb: Cell::new(false),
}
Expand Down Expand Up @@ -86,9 +91,14 @@ impl DSP1 {

impl Tickable for DSP1 {
fn tick(&mut self, _ticks: Ticks) -> Result<()> {
// TODO more granular or only as much as needed based on comms?
let mut cpu = self.cpu.borrow_mut();
cpu.step()?;

// Detect busy loops (JRQM $PC)
if !cpu.regs.test_sr(SR::RQM) || (cpu.regs.pc != self.last_pc) {
self.last_pc = cpu.regs.pc;
cpu.step()?;
}

Ok(())
}
}

0 comments on commit e85ac42

Please sign in to comment.