From 2609fb966d934fa6396e3e972ef146db1b28806e Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Mon, 20 Feb 2023 16:21:16 +1100 Subject: [PATCH] fix masked io in apu --- src/processor/memory/mmio/apu.rs | 6 +++++- src/processor/memory/mmio/apu/channels.rs | 15 +++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/processor/memory/mmio/apu.rs b/src/processor/memory/mmio/apu.rs index 1ef6d17..869e040 100644 --- a/src/processor/memory/mmio/apu.rs +++ b/src/processor/memory/mmio/apu.rs @@ -239,7 +239,11 @@ impl Apu { } 0xFF26 => { // NR52 - Sound on/off - let mut v = if self.apu_enable { 1 << 7 } else { 0 }; + let mut v = if self.apu_enable { + 0b11111111 + } else { + 0b01111111 + }; v = set_or_clear_bit(v, 0, self.channels.one.enabled); v = set_or_clear_bit(v, 1, self.channels.two.enabled); v = set_or_clear_bit(v, 2, self.channels.three.enabled); diff --git a/src/processor/memory/mmio/apu/channels.rs b/src/processor/memory/mmio/apu/channels.rs index 0d6cd4d..089b00e 100644 --- a/src/processor/memory/mmio/apu/channels.rs +++ b/src/processor/memory/mmio/apu/channels.rs @@ -220,7 +220,7 @@ impl PwmChannel { pub(super) fn get_sweep_register(&self) -> u8 { set_or_clear_bit( - ((self.sweep.pace & 0b1110000) << 4) | (self.sweep.slope & 0b111), + (0b10000000 | (self.sweep.pace << 4) & 0b1110000) | (self.sweep.slope & 0b111), 3, self.sweep.mode == EnvelopeMode::Decrease, ) @@ -401,13 +401,12 @@ impl WaveChannel { } pub(super) fn get_volume(&self) -> u8 { - 0b10011111 - & (match self.volume { - ShiftVolumePercent::Zero => 0b00, - ShiftVolumePercent::TwentyFive => 0b11, - ShiftVolumePercent::Fifty => 0b10, - ShiftVolumePercent::OneHundred => 0b01, - } << 5) + match self.volume { + ShiftVolumePercent::Zero => 0b10011111, + ShiftVolumePercent::TwentyFive => 0b11111111, + ShiftVolumePercent::Fifty => 0b11011111, + ShiftVolumePercent::OneHundred => 0b10111111, + } } pub(super) fn update_wavelength_low(&mut self, data: u8) {