diff --git a/agb/src/sound/mixer/hw.rs b/agb/src/sound/mixer/hw.rs index 43d3bf75..c8abe42a 100644 --- a/agb/src/sound/mixer/hw.rs +++ b/agb/src/sound/mixer/hw.rs @@ -6,7 +6,13 @@ const DMA1_DEST_ADDR: MemoryMapped = unsafe { MemoryMapped::new(0x0400_00c0 const _DMA1_WORD_COUNT: MemoryMapped = unsafe { MemoryMapped::new(0x0400_00c4) }; // sound ignores this for some reason const DMA1_CONTROL: MemoryMapped = unsafe { MemoryMapped::new(0x0400_00c6) }; +const DMA2_SOURCE_ADDR: MemoryMapped = unsafe { MemoryMapped::new(0x0400_00ca) }; +const DMA2_DEST_ADDR: MemoryMapped = unsafe { MemoryMapped::new(0x0400_00cc) }; +const _DMA2_WORD_COUNT: MemoryMapped = unsafe { MemoryMapped::new(0x0400_00d0) }; +const DMA2_CONTROL: MemoryMapped = unsafe { MemoryMapped::new(0x0400_00d2) }; + const FIFOA_DEST_ADDR: u32 = 0x0400_00a0; +const FIFOB_DEST_ADDR: u32 = 0x0400_00a4; // Similarly for proper timer support const TIMER0_COUNTER: MemoryMapped = unsafe { MemoryMapped::new(0x0400_0100) }; @@ -15,17 +21,28 @@ const TIMER0_CONTROL: MemoryMapped = unsafe { MemoryMapped::new(0x0400_0102 const SOUND_CONTROL: MemoryMapped = unsafe { MemoryMapped::new(0x0400_0082) }; const SOUND_CONTROL_X: MemoryMapped = unsafe { MemoryMapped::new(0x0400_0084) }; -pub(super) fn enable_dma1_for_sound(sound_memory: &[i8]) { +const DMA_CONTROL_SETTING_FOR_SOUND: u16 = { let dest_fixed: u16 = 2 << 5; // dest addr control = fixed let repeat: u16 = 1 << 9; let transfer_type: u16 = 1 << 10; // transfer in words let dma_start_timing: u16 = 3 << 12; // sound fifo timing let enable: u16 = 1 << 15; // enable + dest_fixed | repeat | transfer_type | dma_start_timing | enable +}; + +pub(super) fn enable_dma1_for_sound(sound_memory: &[i8]) { DMA1_CONTROL.set(0); DMA1_SOURCE_ADDR.set(sound_memory.as_ptr() as u32); DMA1_DEST_ADDR.set(FIFOA_DEST_ADDR); - DMA1_CONTROL.set(dest_fixed | repeat | transfer_type | dma_start_timing | enable); + DMA1_CONTROL.set(DMA_CONTROL_SETTING_FOR_SOUND); +} + +pub(super) fn enable_dma2_for_sound(sound_memory: &[i8]) { + DMA2_CONTROL.set(0); + DMA2_SOURCE_ADDR.set(sound_memory.as_ptr() as u32); + DMA2_DEST_ADDR.set(FIFOB_DEST_ADDR); + DMA2_CONTROL.set(DMA_CONTROL_SETTING_FOR_SOUND); } pub(super) fn set_sound_control_register_for_mixer() {