From a790e4cbd19ddf13ff85a9d0cf8e0df5d430ed39 Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Mon, 20 Feb 2023 15:51:39 +1100 Subject: [PATCH] fix length timer --- src/processor/memory/mmio/apu/channels.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/processor/memory/mmio/apu/channels.rs b/src/processor/memory/mmio/apu/channels.rs index 41f5166..0d6cd4d 100644 --- a/src/processor/memory/mmio/apu/channels.rs +++ b/src/processor/memory/mmio/apu/channels.rs @@ -371,8 +371,8 @@ impl WaveChannel { pub(super) fn length_tick(&mut self) { if self.length_enable && self.enabled { - self.length_timer += 1; - if self.length_timer >= 64 { + self.length_timer = self.length_timer.saturating_add(1); + if self.length_timer == 0xFF { self.enabled = false; } } @@ -528,6 +528,7 @@ impl NoiseChannel { fn trigger(&mut self) { self.enabled = true; self.envelope = self.queued_envelope; + self.lfsr.register = 0; } pub fn tick(&mut self, steps: usize) -> Vec {