fix(ppu): improve accuracy of timer

This commit is contained in:
Rekai Nyangadzayi Musuka 2021-09-21 12:50:31 -03:00
parent 142231d355
commit 9964b49ce1
1 changed files with 15 additions and 16 deletions

View File

@ -21,17 +21,6 @@ impl Timer {
use State::*;
use TimerSpeed::*;
match self.state {
TIMAOverflow(_) | AbortedTIMAOverflow(_) => self.next(),
LoadTMA => {
self.counter = self.modulo;
self.interrupt = true;
self.next();
}
Normal => {}
}
self.divider = self.divider.wrapping_add(1);
// Get Bit Position
@ -53,6 +42,17 @@ impl Timer {
}
self.and_result = Some(new_result);
match self.state {
TIMAOverflow(_) | AbortedTIMAOverflow(_) => self.next(),
LoadTIMA => {
self.counter = self.modulo;
self.interrupt = true;
self.next();
}
Normal => {}
}
}
/// 0xFF05 | TIMA - Timer Counter
@ -70,7 +70,7 @@ impl Timer {
self.counter = byte;
self.state = AbortedTIMAOverflow(step);
}
LoadTMA => {}
LoadTIMA => { /* Ignored */ }
}
}
@ -95,9 +95,8 @@ impl Timer {
use State::*;
self.state = match self.state {
Normal | LoadTMA => Normal,
AbortedTIMAOverflow(4) => Normal,
TIMAOverflow(4) => LoadTMA,
Normal | LoadTIMA | AbortedTIMAOverflow(3) => Normal,
TIMAOverflow(3) => LoadTIMA,
AbortedTIMAOverflow(step) => AbortedTIMAOverflow(step + 1),
TIMAOverflow(step) => TIMAOverflow(step + 1),
}
@ -181,5 +180,5 @@ enum State {
TIMAOverflow(u8),
AbortedTIMAOverflow(u8),
Normal,
LoadTMA,
LoadTIMA,
}