diff --git a/lib/src/processor/memory/mmio/apu/channels.rs b/lib/src/processor/memory/mmio/apu/channels.rs index 82a16bc..dc839a3 100644 --- a/lib/src/processor/memory/mmio/apu/channels.rs +++ b/lib/src/processor/memory/mmio/apu/channels.rs @@ -95,13 +95,18 @@ impl From for DutyCycle { } } +const TWELVE_POINT_FIVE: [u8; 8] = [0, 0, 0, 0, 0, 0, 0, 1]; +const TWENTY_FIVE: [u8; 8] = [1, 0, 0, 0, 0, 0, 0, 1]; +const FIFTY: [u8; 8] = [1, 0, 0, 0, 0, 1, 1, 1]; +const SEVENTY_FIVE: [u8; 8] = [0, 1, 1, 1, 1, 1, 1, 0]; + impl DutyCycle { - fn as_waveform(&self) -> [u8; 8] { + fn get_waveform(&self, index: usize) -> u8 { match self { - DutyCycle::TwelvePointFive => [0, 0, 0, 0, 0, 0, 0, 1], - DutyCycle::TwentyFive => [1, 0, 0, 0, 0, 0, 0, 1], - DutyCycle::Fifty => [1, 0, 0, 0, 0, 1, 1, 1], - DutyCycle::SeventyFive => [0, 1, 1, 1, 1, 1, 1, 0], + DutyCycle::TwelvePointFive => TWELVE_POINT_FIVE[index], + DutyCycle::TwentyFive => TWENTY_FIVE[index], + DutyCycle::Fifty => FIFTY[index], + DutyCycle::SeventyFive => SEVENTY_FIVE[index], } } @@ -167,7 +172,7 @@ impl PwmChannel { self.wave_position = (self.wave_position + 1) % 8; self.set_wave_timer(); } - self.dac(self.duty_cycle.as_waveform()[self.wave_position]) + self.dac(self.duty_cycle.get_waveform(self.wave_position)) }) .collect() } else {