GB Timer: Fix timing adjustments when writing to TAC (fixes #1340)

This commit is contained in:
Vicki Pfau 2019-03-23 22:46:58 -07:00
parent 8796f75fd3
commit 3e178f3dd7
2 changed files with 5 additions and 3 deletions

View File

@ -17,6 +17,7 @@ Emulation fixes:
- GBA DMA: Fix DMA0-2 lengths (fixes mgba.io/i/1344)
- GB Video: Fix window y changing mid-window (fixes mgba.io/i/1345)
- GB Video: Fix more window edge cases (fixes mgba.io/i/1346)
- GB Timer: Fix timing adjustments when writing to TAC (fixes mgba.io/i/1340)
Other fixes:
- Qt: More app metadata fixes
- Qt: Fix load recent from archive (fixes mgba.io/i/1325)

View File

@ -92,6 +92,10 @@ void GBTimerDivReset(struct GBTimer* timer) {
uint8_t GBTimerUpdateTAC(struct GBTimer* timer, GBRegisterTAC tac) {
if (GBRegisterTACIsRun(tac)) {
timer->nextDiv -= mTimingUntil(&timer->p->timing, &timer->event);
mTimingDeschedule(&timer->p->timing, &timer->event);
_GBTimerDivIncrement(timer, (timer->p->cpu->executionState + 2) & 3);
switch (GBRegisterTACGetClock(tac)) {
case 0:
timer->timaPeriod = 1024 >> 4;
@ -107,9 +111,6 @@ uint8_t GBTimerUpdateTAC(struct GBTimer* timer, GBRegisterTAC tac) {
break;
}
timer->nextDiv -= mTimingUntil(&timer->p->timing, &timer->event);
mTimingDeschedule(&timer->p->timing, &timer->event);
_GBTimerDivIncrement(timer, (timer->p->cpu->executionState + 2) & 3);
timer->nextDiv += GB_DMG_DIV_PERIOD;
mTimingSchedule(&timer->p->timing, &timer->event, timer->nextDiv);
} else {