diff --git a/src/mmio_addresses.rs b/src/mmio_addresses.rs index dd75600..50203e6 100644 --- a/src/mmio_addresses.rs +++ b/src/mmio_addresses.rs @@ -161,6 +161,22 @@ pub const NOISE_LEN_ENV: VolAddress = pub const NOISE_FREQ_CNT: VolAddress = unsafe { VolAddress::new(0x0400_007C) }; +/// [SOUNDCNT_L](https://problemkaputt.de/gbatek.htm#gbasoundcontrolregisters) +pub const SOUND_CONTROL: VolAddress = + unsafe { VolAddress::new(0x0400_0080) }; +/// [SOUNDCNT_X](https://problemkaputt.de/gbatek.htm#gbasoundcontrolregisters) +pub const SOUND_STATUS: VolAddress = + unsafe { VolAddress::new(0x0400_0084) }; +/// [SOUNDBIAS](https://problemkaputt.de/gbatek.htm#gbasoundcontrolregisters) +pub const SOUND_BIAS: VolAddress = + unsafe { VolAddress::new(0x0400_0088) }; + +/// [SOUNDCNT_H](https://problemkaputt.de/gbatek.htm#gbasoundcontrolregisters) (R/W fields) +pub const FIFO_CONTROL: VolAddress = + unsafe { VolAddress::new(0x0400_0082) }; +/// [SOUNDCNT_H](https://problemkaputt.de/gbatek.htm#gbasoundcontrolregisters) (write-only fields) +pub const FIFO_RESET: VolAddress = + unsafe { VolAddress::new(0x0400_0082) }; /// [FIFO_A](https://problemkaputt.de/gbatek.htm#gbasoundchannelaandbdmasound) pub const FIFO_A: VolAddress = unsafe { VolAddress::new(0x0400_00A0) }; /// [FIFO_B](https://problemkaputt.de/gbatek.htm#gbasoundchannelaandbdmasound) diff --git a/src/mmio_types.rs b/src/mmio_types.rs index a88eeef..3601e91 100644 --- a/src/mmio_types.rs +++ b/src/mmio_types.rs @@ -183,6 +183,21 @@ pub use register_ram_reset_control::*; mod interrupt_flags; pub use interrupt_flags::*; +mod fifo_control; +pub use fifo_control::*; + +mod fifo_reset; +pub use fifo_reset::*; + +mod sound_control; +pub use sound_control::*; + +mod sound_status; +pub use sound_status::*; + +mod sound_bias; +pub use sound_bias::*; + mod timer_control; pub use timer_control::*; diff --git a/src/mmio_types/fifo_control.rs b/src/mmio_types/fifo_control.rs new file mode 100644 index 0000000..80573e8 --- /dev/null +++ b/src/mmio_types/fifo_control.rs @@ -0,0 +1,25 @@ +use super::*; + +#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] +#[repr(transparent)] +pub struct FifoControl(u16); +impl FifoControl { + const_new!(); + bitfield_enum!(u16; 0..=1: MixVolume, mix_volume, with_mix_volume, set_mix_volume); + bitfield_bool!(u16; 2, full_volume_a, with_full_volume_a, set_full_volume_a); + bitfield_bool!(u16; 3, full_volume_b, with_full_volume_b, set_full_volume_b); + bitfield_bool!(u16; 8, enable_right_a, with_enable_right_a, set_enable_right_a); + bitfield_bool!(u16; 9, enable_left_a, with_enable_left_a, set_enable_left_a); + bitfield_bool!(u16; 10, use_timer1_a, with_use_timer1_a, set_use_timer1_a); + bitfield_bool!(u16; 12, enable_right_b, with_enable_right_b, set_enable_right_b); + bitfield_bool!(u16; 13, enable_left_b, with_enable_left_b, set_enable_left_b); + bitfield_bool!(u16; 14, use_timer1_b, with_use_timer1_b, set_use_timer1_b); +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[repr(u16)] +pub enum MixVolume { + _25 = 0, + _50 = 1, + _100 = 2, +} diff --git a/src/mmio_types/fifo_reset.rs b/src/mmio_types/fifo_reset.rs new file mode 100644 index 0000000..2fdc63e --- /dev/null +++ b/src/mmio_types/fifo_reset.rs @@ -0,0 +1,10 @@ +use super::*; + +#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] +#[repr(transparent)] +pub struct FifoReset(u16); +impl FifoReset { + const_new!(); + bitfield_bool!(u16; 11, reset_a, with_reset_fifo_a, set_reset_fifo_a); + bitfield_bool!(u16; 15, reset_b, with_reset_fifo_b, set_reset_fifo_b); +} diff --git a/src/mmio_types/sound_bias.rs b/src/mmio_types/sound_bias.rs new file mode 100644 index 0000000..d975e6e --- /dev/null +++ b/src/mmio_types/sound_bias.rs @@ -0,0 +1,19 @@ +use super::*; + +#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] +#[repr(transparent)] +pub struct SoundBias(u16); +impl SoundBias { + const_new!(); + bitfield_int!(u16; 1..=9: u16, bias, with_bias, set_bias); + bitfield_enum!(u16; 14..=15: SampleBits, sample_bits, with_sample_bits, set_sample_bits); +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[repr(u16)] +pub enum SampleBits { + _9 = 0 << 14, + _8 = 1 << 14, + _7 = 2 << 14, + _6 = 3 << 14, +} diff --git a/src/mmio_types/sound_control.rs b/src/mmio_types/sound_control.rs new file mode 100644 index 0000000..24b14ef --- /dev/null +++ b/src/mmio_types/sound_control.rs @@ -0,0 +1,18 @@ +use super::*; + +#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] +#[repr(transparent)] +pub struct SoundControl(u16); +impl SoundControl { + const_new!(); + bitfield_int!(u16; 0..=2: u16, right_volume, with_right_volume, set_right_volume); + bitfield_int!(u16; 4..=6: u16, left_volume, with_left_volume, set_left_volume); + bitfield_bool!(u16; 8, tone1_right, with_tone1_right, set_tone1_right); + bitfield_bool!(u16; 9, tone2_right, with_tone2_right, set_tone2_right); + bitfield_bool!(u16; 10, wave_right, with_wave_right, set_wave_right); + bitfield_bool!(u16; 11, noise_right, with_noise_right, set_noise_right); + bitfield_bool!(u16; 12, tone1_left, with_tone1_left, set_tone1_left); + bitfield_bool!(u16; 13, tone2_left, with_tone2_left, set_tone2_left); + bitfield_bool!(u16; 14, wave_left, with_wave_left, set_wave_left); + bitfield_bool!(u16; 15, noise_left, with_noise_left, set_noise_left); +} diff --git a/src/mmio_types/sound_status.rs b/src/mmio_types/sound_status.rs new file mode 100644 index 0000000..37d57c4 --- /dev/null +++ b/src/mmio_types/sound_status.rs @@ -0,0 +1,13 @@ +use super::*; + +#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] +#[repr(transparent)] +pub struct SoundStatus(u8); +impl SoundStatus { + const_new!(); + bitfield_bool!(u8; 0, tone1_playing, with_tone1_playing, set_tone1_playing); + bitfield_bool!(u8; 1, tone2_playing, with_tone2_playing, set_tone2_playing); + bitfield_bool!(u8; 2, wave_playing, with_wave_playing, set_wave_playing); + bitfield_bool!(u8; 3, noise_playing, with_noise_playing, set_noise_playing); + bitfield_bool!(u8; 7, enabled, with_enabled, set_enabled); +}