A GameCube/Wii emulator and debugger written in Rust.
clean up (sunshine and wario world draw smth!)
Layle4c641c96c075
diff --git a/crates/backend-wgpu/src/triangulate.rs b/crates/backend-wgpu/src/triangulate.rsindex 2b6138b..8696438 100644--- a/crates/backend-wgpu/src/triangulate.rs+++ b/crates/backend-wgpu/src/triangulate.rs@@ -75,7 +75,9 @@ pub(crate) fn triangulate_into(dc: &DrawCall, out: &mut Vec<GpuVertex>) {out.push((&dc.vertices[i]).into());}}- _ => unimplemented!("triangulation for {:?}", dc.primitive),+ _ => {+ eprintln!("triangulate: skipping unsupported primitive {:?}", dc.primitive);+ }}}diff --git a/crates/gecko/src/flipper/dsp.rs b/crates/gecko/src/flipper/dsp.rsindex bab2ef4..bc89e66 100644--- a/crates/gecko/src/flipper/dsp.rs+++ b/crates/gecko/src/flipper/dsp.rs@@ -248,56 +248,19 @@ impl GameCube {self.dsp.registers.nia = natural_nia;// Save state before main instruction so extensions read pre-instruction values.- // Extensions see the old accumulators and status (for saturation/sign-extension).- let has_ext = instr.ext_opcode().is_some();- let saved = if has_ext {- Some((- self.dsp.registers.ac0_high,- self.dsp.registers.ac0_mid,- self.dsp.registers.ac0_low,- self.dsp.registers.ac1_high,- self.dsp.registers.ac1_mid,- self.dsp.registers.ac1_low,- self.dsp.registers.status,- ))- } else {- None- };+ let pre_snap = instr+ .ext_opcode()+ .map(|_| self.dsp.registers.snapshot());lut::dispatch(self, instr);- // Dispatch extension opcode if present.- // Extensions read accumulator/status values from BEFORE the main instruction.+ // Dispatch extension opcode: it reads accumulator/status from before the main instructionif let Some(ext) = instr.ext_opcode() {let ext = instruction::GcDspExt(ext);- if let Some((h0, m0, l0, h1, m1, l1, old_sr)) = saved {- let new_ac = (- self.dsp.registers.ac0_high,- self.dsp.registers.ac0_mid,- self.dsp.registers.ac0_low,- self.dsp.registers.ac1_high,- self.dsp.registers.ac1_mid,- self.dsp.registers.ac1_low,- );- let new_sr = self.dsp.registers.status;- self.dsp.registers.ac0_high = h0;- self.dsp.registers.ac0_mid = m0;- self.dsp.registers.ac0_low = l0;- self.dsp.registers.ac1_high = h1;- self.dsp.registers.ac1_mid = m1;- self.dsp.registers.ac1_low = l1;- self.dsp.registers.status = old_sr;-- lut::dispatch_gc_dsp_ext(self, ext);-- self.dsp.registers.ac0_high = new_ac.0;- self.dsp.registers.ac0_mid = new_ac.1;- self.dsp.registers.ac0_low = new_ac.2;- self.dsp.registers.ac1_high = new_ac.3;- self.dsp.registers.ac1_mid = new_ac.4;- self.dsp.registers.ac1_low = new_ac.5;- self.dsp.registers.status = new_sr;- }+ let post_snap = self.dsp.registers.snapshot();+ self.dsp.registers.restore(&pre_snap.unwrap());+ lut::dispatch_gc_dsp_ext(self, ext);+ self.dsp.registers.restore(&post_snap);}// Check if we've reached the end of a loop.diff --git a/crates/gecko/src/flipper/dsp/core.rs b/crates/gecko/src/flipper/dsp/core.rsindex 1db424e..75e4855 100644--- a/crates/gecko/src/flipper/dsp/core.rs+++ b/crates/gecko/src/flipper/dsp/core.rs@@ -39,6 +39,17 @@ pub mod reg {pub const AC1M: u8 = 31;}+#[derive(Clone, Copy)]+pub struct Snapshot {+ pub ac0_high: u16,+ pub ac0_mid: u16,+ pub ac0_low: u16,+ pub ac1_high: u16,+ pub ac1_mid: u16,+ pub ac1_low: u16,+ pub status: StatusRegister,+}+#[derive(Default)]pub struct Registers {pub pc: u16,@@ -68,6 +79,28 @@ pub struct Registers {}impl Registers {+ pub fn snapshot(&self) -> Snapshot {+ Snapshot {+ ac0_high: self.ac0_high,+ ac0_mid: self.ac0_mid,+ ac0_low: self.ac0_low,+ ac1_high: self.ac1_high,+ ac1_mid: self.ac1_mid,+ ac1_low: self.ac1_low,+ status: self.status,+ }+ }++ pub fn restore(&mut self, snap: &Snapshot) {+ self.ac0_high = snap.ac0_high;+ self.ac0_mid = snap.ac0_mid;+ self.ac0_low = snap.ac0_low;+ self.ac1_high = snap.ac1_high;+ self.ac1_mid = snap.ac1_mid;+ self.ac1_low = snap.ac1_low;+ self.status = snap.status;+ }+/// Increment address register by 1 with WR wrapping.#[inline(always)]pub fn increment_ar(&self, reg: usize) -> u16 {diff --git a/crates/gecko/src/flipper/gx.rs b/crates/gecko/src/flipper/gx.rsindex fd61b0c..51c1d36 100644--- a/crates/gecko/src/flipper/gx.rs+++ b/crates/gecko/src/flipper/gx.rs@@ -87,7 +87,7 @@ impl GraphicsProcessor {FifoCmd::Xf(data) => self.load_xf(&data),FifoCmd::Bp(data) => self.load_bp(&data),FifoCmd::CallDisplayList { phys_addr, nbytes } => {- let addr = phys_addr as usize;+ let addr = (phys_addr & 0x3FFFFFFF) as usize;let len = nbytes as usize;self.execute_display_list(mmio, &mmio.ram[addr..addr + len].to_vec());}