fix(apu): resolve off-by-one error

This commit is contained in:
Rekai Nyangadzayi Musuka 2021-08-17 23:14:56 -05:00
parent 22f96a10e7
commit 5d64e539a7
2 changed files with 5 additions and 9 deletions

View File

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

View File

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