Timers: Add missing event update after resetting count/target

This commit is contained in:
Connor McLaughlin 2020-06-10 01:37:11 +10:00
parent bdf9c91271
commit 34d27bad4a

View file

@ -115,11 +115,20 @@ void Timers::AddTicks(u32 timer, TickCount count)
{
interrupt_request |= cs.mode.irq_at_target;
cs.mode.reached_target = true;
if (cs.mode.reset_at_target)
{
if (cs.target > 0)
cs.counter %= cs.target;
else
cs.counter = 0;
}
}
if (cs.counter >= 0xFFFF)
{
interrupt_request |= cs.mode.irq_on_overflow;
cs.mode.reached_overflow = true;
cs.counter %= 0xFFFFu;
}
if (interrupt_request)
@ -137,18 +146,6 @@ void Timers::AddTicks(u32 timer, TickCount count)
UpdateIRQ(timer);
}
}
if (cs.mode.reset_at_target)
{
if (cs.target > 0)
cs.counter %= cs.target;
else
cs.counter = 0;
}
else
{
cs.counter %= 0xFFFF;
}
}
void Timers::AddSysClkTicks(TickCount sysclk_ticks)
@ -242,6 +239,8 @@ void Timers::WriteRegister(u32 offset, u32 value)
{
Log_DebugPrintf("Timer %u write counter %u", timer_index, value);
cs.counter = value & u32(0xFFFF);
if (timer_index == 2 || !cs.external_counting_enabled)
UpdateSysClkEvent();
}
break;
@ -265,6 +264,8 @@ void Timers::WriteRegister(u32 offset, u32 value)
{
Log_DebugPrintf("Timer %u write target 0x%04X", timer_index, ZeroExtend32(Truncate16(value)));
cs.target = value & u32(0xFFFF);
if (timer_index == 2 || !cs.external_counting_enabled)
UpdateSysClkEvent();
}
break;