From 20f324caa890ab45ff42254b1f30112f211a3f2f Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Sun, 19 Feb 2023 21:49:58 +1100 Subject: [PATCH] change update_sweep to be in line with other channel mmio functions --- src/processor/memory/mmio/apu.rs | 16 ++-------------- src/processor/memory/mmio/apu/channels.rs | 12 ++++++++---- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/src/processor/memory/mmio/apu.rs b/src/processor/memory/mmio/apu.rs index 618a396..5cff384 100644 --- a/src/processor/memory/mmio/apu.rs +++ b/src/processor/memory/mmio/apu.rs @@ -1,7 +1,4 @@ -use self::{ - channels::EnvelopeMode, - types::{Channels, DacSample, Mixer, VinEnable, Volume}, -}; +use self::types::{Channels, DacSample, Mixer, VinEnable, Volume}; use crate::{ processor::{ memory::{masked_update, Address}, @@ -252,16 +249,7 @@ impl Apu { pub fn mmio_write(&mut self, addr: Address, data: u8) { match addr { - 0xFF10 => { - 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); - } + 0xFF10 => self.channels.one.update_sweep(data), 0xFF11 => self.channels.one.update_length_timer_and_duty_cycle(data), 0xFF12 => self.channels.one.update_volume_and_envelope(data), 0xFF13 => self.channels.one.update_wavelength_low(data), diff --git a/src/processor/memory/mmio/apu/channels.rs b/src/processor/memory/mmio/apu/channels.rs index 79cabb3..afd98c0 100644 --- a/src/processor/memory/mmio/apu/channels.rs +++ b/src/processor/memory/mmio/apu/channels.rs @@ -205,10 +205,14 @@ impl PwmChannel { } } - pub(super) fn update_sweep(&mut self, pace: u8, mode: EnvelopeMode, slope: u8) { - self.sweep.pace = pace; - self.sweep.mode = mode; - self.sweep.slope = slope; + pub(super) fn update_sweep(&mut self, data: u8) { + self.sweep.pace = (data & 0b1110000) >> 4; + self.sweep.mode = if get_bit(data, 3) { + EnvelopeMode::Decrease + } else { + EnvelopeMode::Increase + }; + self.sweep.slope = data & 0b111; } pub(super) fn get_sweep_register(&self) -> u8 {