Skip to content

Commit

Permalink
SuperFX: implement interrupt
Browse files Browse the repository at this point in the history
  • Loading branch information
twvd committed Feb 24, 2024
1 parent 16145b5 commit e0a16db
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 3 deletions.
15 changes: 15 additions & 0 deletions src/cpu_gsu/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub struct CpuGsu {
dreg: usize,
last_instr: u8,
branch_pc: Option<u16>,
irq_pending: bool,

pub cache_valid: [bool; CACHE_LINES],
}
Expand All @@ -52,6 +53,7 @@ impl CpuGsu {
last_instr: 0,
branch_pc: None,
cache_valid: [false; CACHE_LINES],
irq_pending: false,
};

c.rom[0..rom.len()].copy_from_slice(rom);
Expand Down Expand Up @@ -208,6 +210,13 @@ impl CpuGsu {
(0x00, _, _) => {
// STOP
self.regs.write_flags(&[(Flag::G, false)]);
println!("{}", self.regs);

if !self.regs.test_cfgr(CFGRFlag::IRQ) {
self.regs.write_flags(&[(Flag::IRQ, true)]);
self.irq_pending = true;
}

self.cycles(1)?;
}
(0x01, _, _) => {
Expand Down Expand Up @@ -929,6 +938,12 @@ impl CpuGsu {
}
// TODO cycles
}

pub fn get_clr_int(&mut self) -> bool {
let v = self.irq_pending;
self.irq_pending = false;
v
}
}

impl Tickable for CpuGsu {
Expand Down
2 changes: 1 addition & 1 deletion src/cpu_gsu/regs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ impl RegisterFile {
Register::SCBR => self.scbr.into(),
Register::CLSR => self.clsr.into(),
Register::SCMR => self.scmr.into(),
Register::VCR => 0,
Register::VCR => 1,
Register::RAMBR => self.rambr.into(),
Register::BRAMBR => self.brambr.into(),
Register::COLR => self.colr.into(),
Expand Down
4 changes: 4 additions & 0 deletions src/snes/bus/mainbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,10 @@ where
self.timeup.set(true);
}

if self.cartridge.get_clr_int() {
self.intreq_int = true;
}

Ok(())
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/snes/cartridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,14 @@ impl Cartridge {
_ => None,
}
}

pub fn get_clr_int(&mut self) -> bool {
if let Some(sfx) = self.co_superfx.as_mut() {
return sfx.get_clr_int();
}

false
}
}

impl fmt::Display for Cartridge {
Expand Down
13 changes: 11 additions & 2 deletions src/snes/coprocessor/superfx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ impl SuperFX {
cpu: RefCell::new(CpuGsu::new(rom)),
}
}

pub fn get_clr_int(&mut self) -> bool {
let mut cpu = self.cpu.borrow_mut();
cpu.get_clr_int()
}
}

impl Tickable for SuperFX {
Expand All @@ -34,7 +39,7 @@ impl Tickable for SuperFX {
impl BusMember<Address> for SuperFX {
fn read(&self, fulladdr: Address) -> Option<u8> {
let (_bank, addr) = ((fulladdr >> 16) as usize, (fulladdr & 0xFFFF) as usize);
let cpu = self.cpu.borrow();
let mut cpu = self.cpu.borrow_mut();

//println!("SuperFX read: {:04X}", addr);
match addr {
Expand All @@ -49,7 +54,11 @@ impl BusMember<Address> for SuperFX {
Some((cpu.regs.read_r(r) >> 8) as u8)
}
}
0x3030 => Some(cpu.regs.read(Register::SFR) as u8),
0x3030 => {
let v = cpu.regs.read(Register::SFR) as u8;
cpu.regs.write_flags(&[(Flag::IRQ, false)]);
Some(v)
}
0x3031 => Some((cpu.regs.read(Register::SFR) >> 8) as u8),
// 0x3032 unused
0x3033 => Some(cpu.regs.read8(Register::BRAMBR)),
Expand Down

0 comments on commit e0a16db

Please sign in to comment.