From 5d64e539a781574a6028bba5c24ad040066bcd02 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Tue, 17 Aug 2021 23:14:56 -0500 Subject: [PATCH] fix(apu): resolve off-by-one error --- src/apu.rs | 4 ++-- src/apu/types.rs | 10 +++------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/apu.rs b/src/apu.rs index 1b94377..9c76f76 100644 --- a/src/apu.rs +++ b/src/apu.rs @@ -101,8 +101,6 @@ impl Apu { if self.falling_edge(12, div) { use FrameSequencerState::*; - self.sequencer.next(); - match self.sequencer.state() { Length => self.handle_length(), LengthAndSweep => { @@ -112,6 +110,8 @@ impl Apu { Envelope => self.handle_envelope(), Nothing => {} } + + self.sequencer.next(); } self.div_prev = Some(div); diff --git a/src/apu/types.rs b/src/apu/types.rs index 7a36f3d..01a8016 100644 --- a/src/apu/types.rs +++ b/src/apu/types.rs @@ -531,13 +531,9 @@ pub(super) mod fs { self.step = (self.step + 1) % 8; self.state = match self.step { - 0 => Length, - 1 => Nothing, - 2 => LengthAndSweep, - 3 => Nothing, - 4 => Length, - 5 => Nothing, - 6 => LengthAndSweep, + 1 | 3 | 5 => Nothing, + 0 | 4 => Length, + 2 | 6 => LengthAndSweep, 7 => Envelope, _ => unreachable!("Step {} is invalid for the Frame Sequencer", self.step), };