43 lines
1.3 KiB
Rust
43 lines
1.3 KiB
Rust
#[derive(Debug, Default)]
|
|
pub struct Sound {
|
|
enabled: u8,
|
|
sound_length_1: u8,
|
|
sound_control_1: u8,
|
|
sound_channel_volume_control: u8,
|
|
sound_output_terminal_selector: u8,
|
|
sound_freq_low: u8,
|
|
sound_freq_high: u8,
|
|
}
|
|
|
|
impl Sound {
|
|
pub fn new() -> Sound {
|
|
Sound::default()
|
|
}
|
|
|
|
pub fn write_byte(&mut self, addr: u16, val: u8) {
|
|
match addr {
|
|
0xFF11 => self.sound_length_1 = val,
|
|
0xFF12 => self.sound_control_1 = val,
|
|
0xFF13 => self.sound_freq_low = val,
|
|
0xFF14 => self.sound_freq_high = val,
|
|
0xFF24 => self.sound_channel_volume_control = val,
|
|
0xFF25 => self.sound_output_terminal_selector = val,
|
|
0xFF26 => self.enabled = val,
|
|
_ => panic!("Sound: Write {:02X} to {:04X} unsupported", val, addr),
|
|
}
|
|
}
|
|
|
|
pub fn read_byte(&self, addr: u16) -> u8 {
|
|
match addr {
|
|
0xFF11 => self.sound_length_1,
|
|
0xFF12 => self.sound_control_1,
|
|
0xFF13 => self.sound_freq_low,
|
|
0xFF14 => self.sound_freq_high,
|
|
0xFF24 => self.sound_channel_volume_control,
|
|
0xFF25 => self.sound_output_terminal_selector,
|
|
0xFF26 => self.enabled,
|
|
_ => panic!("Sound: Read from {:04X} unsupported", addr),
|
|
}
|
|
}
|
|
}
|