change update_sweep to be in line with other channel mmio functions

This commit is contained in:
Alex Janka 2023-02-19 21:49:58 +11:00
parent 26e5cc3431
commit 20f324caa8
2 changed files with 10 additions and 18 deletions

View file

@ -1,7 +1,4 @@
use self::{ use self::types::{Channels, DacSample, Mixer, VinEnable, Volume};
channels::EnvelopeMode,
types::{Channels, DacSample, Mixer, VinEnable, Volume},
};
use crate::{ use crate::{
processor::{ processor::{
memory::{masked_update, Address}, memory::{masked_update, Address},
@ -252,16 +249,7 @@ impl Apu {
pub fn mmio_write(&mut self, addr: Address, data: u8) { pub fn mmio_write(&mut self, addr: Address, data: u8) {
match addr { match addr {
0xFF10 => { 0xFF10 => self.channels.one.update_sweep(data),
let pace = (data & 0b1110000) >> 4;
let mode = if get_bit(data, 3) {
EnvelopeMode::Decrease
} else {
EnvelopeMode::Increase
};
let slope = data & 0b111;
self.channels.one.update_sweep(pace, mode, slope);
}
0xFF11 => self.channels.one.update_length_timer_and_duty_cycle(data), 0xFF11 => self.channels.one.update_length_timer_and_duty_cycle(data),
0xFF12 => self.channels.one.update_volume_and_envelope(data), 0xFF12 => self.channels.one.update_volume_and_envelope(data),
0xFF13 => self.channels.one.update_wavelength_low(data), 0xFF13 => self.channels.one.update_wavelength_low(data),

View file

@ -205,10 +205,14 @@ impl PwmChannel {
} }
} }
pub(super) fn update_sweep(&mut self, pace: u8, mode: EnvelopeMode, slope: u8) { pub(super) fn update_sweep(&mut self, data: u8) {
self.sweep.pace = pace; self.sweep.pace = (data & 0b1110000) >> 4;
self.sweep.mode = mode; self.sweep.mode = if get_bit(data, 3) {
self.sweep.slope = slope; EnvelopeMode::Decrease
} else {
EnvelopeMode::Increase
};
self.sweep.slope = data & 0b111;
} }
pub(super) fn get_sweep_register(&self) -> u8 { pub(super) fn get_sweep_register(&self) -> u8 {