fix masked io in apu

This commit is contained in:
Alex Janka 2023-02-20 16:21:16 +11:00
parent a790e4cbd1
commit 2609fb966d
2 changed files with 12 additions and 9 deletions

View file

@ -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);

View file

@ -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) {