mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-24 00:31:34 +11:00
Make sound now take the first class timer object
This commit is contained in:
parent
8876c47aa9
commit
bfc02e0aa8
|
@ -17,7 +17,7 @@ fn main() -> ! {
|
|||
let mut input = ButtonController::new();
|
||||
let vblank_provider = agb::interrupt::VBlank::get();
|
||||
|
||||
let mut mixer = gba.mixer.mixer();
|
||||
let mut mixer = gba.mixer.mixer(gba.timers.timer0);
|
||||
mixer.enable();
|
||||
|
||||
let channel = SoundChannel::new(DEAD_CODE);
|
||||
|
|
|
@ -14,11 +14,11 @@ fn main() -> ! {
|
|||
let mut gba = Gba::new();
|
||||
let vblank_provider = agb::interrupt::VBlank::get();
|
||||
|
||||
let timer_controller = gba.timer;
|
||||
let timer_controller = gba.timers;
|
||||
let mut timer = timer_controller.timer1;
|
||||
timer.set_enabled(true);
|
||||
|
||||
let mut mixer = gba.mixer.mixer();
|
||||
let mut mixer = gba.mixer.mixer(timer_controller.timer0);
|
||||
mixer.enable();
|
||||
|
||||
let mut channel = SoundChannel::new(LET_IT_IN);
|
||||
|
|
|
@ -63,7 +63,7 @@ pub struct Gba {
|
|||
pub display: display::Display,
|
||||
pub sound: sound::dmg::Sound,
|
||||
pub mixer: sound::mixer::MixerController,
|
||||
pub timer: timer::TimerController,
|
||||
pub timers: timer::TimerController,
|
||||
}
|
||||
|
||||
impl Gba {
|
||||
|
@ -76,7 +76,7 @@ impl Gba {
|
|||
display: display::Display::new(),
|
||||
sound: sound::dmg::Sound::new(),
|
||||
mixer: sound::mixer::MixerController::new(),
|
||||
timer: timer::TimerController::new(),
|
||||
timers: timer::TimerController::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use crate::memory_mapped::MemoryMapped;
|
||||
use crate::timer::Timer;
|
||||
|
||||
const fn dma_source_addr(dma: usize) -> usize {
|
||||
0x0400_00b0 + 0x0c * dma
|
||||
|
@ -24,10 +25,6 @@ const DMA2_CONTROL: MemoryMapped<u16> = unsafe { MemoryMapped::new(dma_control_a
|
|||
const FIFOA_DEST_ADDR: u32 = 0x0400_00a0;
|
||||
const FIFOB_DEST_ADDR: u32 = 0x0400_00a4;
|
||||
|
||||
// Similarly for proper timer support
|
||||
const TIMER0_COUNTER: MemoryMapped<u16> = unsafe { MemoryMapped::new(0x0400_0100) };
|
||||
const TIMER0_CONTROL: MemoryMapped<u16> = unsafe { MemoryMapped::new(0x0400_0102) };
|
||||
|
||||
const SOUND_CONTROL: MemoryMapped<u16> = unsafe { MemoryMapped::new(0x0400_0082) };
|
||||
const SOUND_CONTROL_X: MemoryMapped<u16> = unsafe { MemoryMapped::new(0x0400_0084) };
|
||||
|
||||
|
@ -94,9 +91,7 @@ pub(super) fn set_sound_control_register_for_mixer() {
|
|||
SOUND_CONTROL_X.set(1 << 7);
|
||||
}
|
||||
|
||||
pub(super) fn set_timer_counter_for_frequency_and_enable(frequency: i32) {
|
||||
let counter = 65536 - (16777216 / frequency);
|
||||
TIMER0_COUNTER.set(counter as u16);
|
||||
|
||||
TIMER0_CONTROL.set(1 << 7); // enable the timer
|
||||
pub(super) fn set_timer_counter_for_frequency_and_enable(timer: &mut Timer, frequency: i32) {
|
||||
timer.set_overflow_amount((16777216 / frequency) as u16);
|
||||
timer.set_enabled(true);
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ pub use sw_mixer::ChannelId;
|
|||
pub use sw_mixer::Mixer;
|
||||
|
||||
use crate::number::Num;
|
||||
use crate::timer::Timer;
|
||||
|
||||
#[non_exhaustive]
|
||||
pub struct MixerController {}
|
||||
|
@ -14,8 +15,8 @@ impl MixerController {
|
|||
MixerController {}
|
||||
}
|
||||
|
||||
pub fn mixer(&mut self) -> Mixer {
|
||||
Mixer::new()
|
||||
pub fn mixer(&mut self, timer: Timer) -> Mixer {
|
||||
Mixer::new(timer)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ use super::hw;
|
|||
use super::hw::LeftOrRight;
|
||||
use super::{SoundChannel, SoundPriority};
|
||||
use crate::number::Num;
|
||||
use crate::timer::Timer;
|
||||
|
||||
// Defined in mixer.s
|
||||
extern "C" {
|
||||
|
@ -22,21 +23,25 @@ pub struct Mixer {
|
|||
buffer: MixerBuffer,
|
||||
channels: [Option<SoundChannel>; 8],
|
||||
indices: [i32; 8],
|
||||
|
||||
timer: Timer,
|
||||
}
|
||||
|
||||
pub struct ChannelId(usize, i32);
|
||||
|
||||
impl Mixer {
|
||||
pub(super) fn new() -> Self {
|
||||
pub(super) fn new(timer: Timer) -> Self {
|
||||
Mixer {
|
||||
buffer: MixerBuffer::new(),
|
||||
channels: Default::default(),
|
||||
indices: Default::default(),
|
||||
|
||||
timer,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn enable(&self) {
|
||||
hw::set_timer_counter_for_frequency_and_enable(SOUND_FREQUENCY);
|
||||
pub fn enable(&mut self) {
|
||||
hw::set_timer_counter_for_frequency_and_enable(&mut self.timer, SOUND_FREQUENCY);
|
||||
hw::set_sound_control_register_for_mixer();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue