Skip to content

armgit / gecko

Public Imported from GitHub
0

A GameCube/Wii emulator and debugger written in Rust.

what the fuck is wrong with dsp

Layled6bad65883a8
diff --git a/crates/gecko/src/flipper/ai.rs b/crates/gecko/src/flipper/ai.rs
index 660d512..f638c6f 100644
--- a/crates/gecko/src/flipper/ai.rs
+++ b/crates/gecko/src/flipper/ai.rs
@@ -1,6 +1,6 @@
pub mod regs;
-use crate::gamecube::GameCube;
+use crate::{flipper::dsp, gamecube::GameCube};
/// CPU cycles per AI sample at 32kHz: 486MHz / 32000 = 15187
const CYCLES_PER_SAMPLE_32K: u64 = 15187;
@@ -58,6 +58,28 @@ crate::mmio_device_dispatch! {
],
}
+#[inline(always)]
+pub fn start_audio_dma(gc: &mut GameCube) {
+ if !gc.dsp.audio_dma_control.play() {
+ return;
+ }
+
+ let addr = gc.dsp.audio_dma_start_addr.raw();
+ let len = gc.dsp.audio_dma_control.length() as u32 * 32;
+
+ tracing::warn!(addr = format!("{addr:08X}"), len, "Audio DMA");
+
+ // TODO: actually stream samples to audio output.
+ const AUDIO_DMA_DELAY: u64 = 10_000;
+ gc.scheduler.schedule_in(AUDIO_DMA_DELAY, |gc| {
+ gc.dsp.audio_dma_control.set_length(0);
+ gc.dsp.csr.set_dma_status(false);
+ gc.dsp.csr.set_ai_interrupt(true);
+ // gc.dsp.audio_dma_control.set_play(false);
+ dsp::refresh_interrupts(gc);
+ });
+}
+
#[inline(always)]
pub fn refresh_interrupts(gc: &mut GameCube) {
use crate::flipper::pi::InterruptFlag;
diff --git a/crates/gecko/src/flipper/dsp.rs b/crates/gecko/src/flipper/dsp.rs
index c83ab00..2214883 100644
--- a/crates/gecko/src/flipper/dsp.rs
+++ b/crates/gecko/src/flipper/dsp.rs
@@ -124,22 +124,6 @@ impl Dsp {
self.csr = self.csr.with_ar_interrupt(true);
}
- pub fn process_audio_dma(&mut self, _mmio: &mut Mmio) {
- if !self.audio_dma_control.play() {
- return;
- }
-
- let addr = self.audio_dma_start_addr.raw();
- let len = self.audio_dma_control.length() as u32 * 32;
-
- tracing::debug!(addr = format!("{addr:08X}"), len, "Audio DMA");
-
- // TODO: actually stream samples to audio output
- self.audio_dma_control.set_length(0);
- self.csr.set_dma_status(false);
- self.csr.set_ai_interrupt(true);
- }
-
pub fn process_ucode_upload(&mut self, mmio: &mut Mmio) {
const UCODE_ADDR: usize = 0x8100_0000;
const UCODE_SIZE: usize = 1024;
diff --git a/crates/gecko/src/flipper/dsp/interpreter.rs b/crates/gecko/src/flipper/dsp/interpreter.rs
index 22a746d..8e64596 100644
--- a/crates/gecko/src/flipper/dsp/interpreter.rs
+++ b/crates/gecko/src/flipper/dsp/interpreter.rs
@@ -1219,11 +1219,7 @@ pub fn ext_ld<const OP: u32>(ctx: &mut GameCube, instr: GcDspExt) {
ctx.dsp.registers.write::<true>(d_reg, value0);
let r_reg = if r != 0 { reg::AX1H } else { reg::AX1L };
- let value1 = if same_bank {
- value0
- } else {
- dsp::read_dmem(ctx, ar_3)
- };
+ let value1 = if same_bank { value0 } else { dsp::read_dmem(ctx, ar_3) };
ctx.dsp.registers.write::<true>(r_reg, value1);
// AR increments: "" = +1/+1, "N" = +ix[s]/+1, "M" = +1/+ix[3], "NM" = +ix[s]/+ix[3]
@@ -1261,11 +1257,7 @@ pub fn ext_ldax<const OP: u32>(ctx: &mut GameCube, instr: GcDspExt) {
let ar_3 = ctx.dsp.registers.ar[3];
let same_bank = (ar_s >> 10) == (ar_3 >> 10);
let high = dsp::read_dmem(ctx, ar_s);
- let low = if same_bank {
- high
- } else {
- dsp::read_dmem(ctx, ar_3)
- };
+ let low = if same_bank { high } else { dsp::read_dmem(ctx, ar_3) };
ctx.dsp.registers.axh[r] = high;
ctx.dsp.registers.ax[r] = low;
diff --git a/crates/gecko/src/flipper/dsp/regs.rs b/crates/gecko/src/flipper/dsp/regs.rs
index 435b69a..b9460c7 100644
--- a/crates/gecko/src/flipper/dsp/regs.rs
+++ b/crates/gecko/src/flipper/dsp/regs.rs
@@ -1,4 +1,4 @@
-use crate::flipper::dsp;
+use crate::flipper::{ai, dsp};
use crate::gamecube::GameCube;
use crate::mmio::traits::{MmioAccess, WriteMask};
use chapa::BitEnum;
@@ -292,7 +292,7 @@ impl MmioAccess<GameCube> for AudioDmaControl {
fn write(self, gc: &mut GameCube, _: WriteMask) {
gc.dsp.audio_dma_control = self;
- gc.dsp.process_audio_dma(&mut gc.mmio);
+ ai::start_audio_dma(gc);
dsp::refresh_interrupts(gc);
}
}