mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-22 12:33:29 +00:00
Mildly adjust layout of inner loop.
This commit is contained in:
parent
032eeb4757
commit
2a0375e9c2
@ -275,9 +275,27 @@ template void MFP68901::set_timer_event_input<3>(bool);
|
||||
|
||||
template <int timer>
|
||||
void MFP68901::decrement_timer(int amount) {
|
||||
while(amount--) {
|
||||
while(amount) {
|
||||
if(timers_[timer].value > amount) {
|
||||
timers_[timer].value -= amount;
|
||||
return;
|
||||
}
|
||||
|
||||
// Keep this check here to avoid the case where a decrement to zero occurs during one call to
|
||||
// decrement_timer, triggering an interrupt, then the timer is already 0 at the next instance,
|
||||
// causing a second interrupt.
|
||||
//
|
||||
// ... even though it would be nice to move it down below, after value has overtly been set to 0.
|
||||
if(!timers_[timer].value) {
|
||||
--timers_[timer].value;
|
||||
if(timers_[timer].value < 1) {
|
||||
--amount;
|
||||
continue;
|
||||
}
|
||||
|
||||
// If here then amount is sufficient to, at least once, decrement the timer
|
||||
// from 1 to 0. So there's an interrupt.
|
||||
//
|
||||
// (and, this switch is why this function is templated on timer ID)
|
||||
switch(timer) {
|
||||
case 0: begin_interrupts(Interrupt::TimerA); break;
|
||||
case 1: begin_interrupts(Interrupt::TimerB); break;
|
||||
@ -287,9 +305,11 @@ void MFP68901::decrement_timer(int amount) {
|
||||
|
||||
// Re: reloading when in event counting mode; I found the data sheet thoroughly unclear on
|
||||
// this, but it appears empirically to be correct. See e.g. Pompey Pirates menu 27.
|
||||
amount -= timers_[timer].value;
|
||||
if(timers_[timer].mode == TimerMode::Delay || timers_[timer].mode == TimerMode::EventCount) {
|
||||
timers_[timer].value += timers_[timer].reload_value; // TODO: properly.
|
||||
}
|
||||
timers_[timer].value = timers_[timer].reload_value; // TODO: properly.
|
||||
} else {
|
||||
timers_[timer].value = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user