GB Timer: Improve DIV reset behavior

This commit is contained in:
Jeffrey Pfau 2016-10-08 09:57:01 -07:00
parent b5e706981f
commit 5ff3e339fe
2 changed files with 11 additions and 3 deletions

View File

@ -3,6 +3,7 @@ Features:
- GBA: Support printing debug strings from inside a game - GBA: Support printing debug strings from inside a game
Bugfixes: Bugfixes:
- LR35902: Fix core never exiting with certain event patterns - LR35902: Fix core never exiting with certain event patterns
- GB Timer: Improve DIV reset behavior
Misc: Misc:
- SDL: Remove scancode key input - SDL: Remove scancode key input
- GBA Video: Clean up unused timers - GBA Video: Clean up unused timers

View File

@ -30,9 +30,6 @@ int32_t GBTimerProcessEvents(struct GBTimer* timer, int32_t cycles) {
timer->nextEvent += timer->nextDiv; timer->nextEvent += timer->nextDiv;
} }
while (timer->nextDiv <= 0) { while (timer->nextDiv <= 0) {
if ((timer->internalDiv & 15) == 15) {
++timer->p->memory.io[REG_DIV];
}
timer->nextDiv += GB_DMG_DIV_PERIOD; timer->nextDiv += GB_DMG_DIV_PERIOD;
// Make sure to trigger when the correct bit is a falling edge // Make sure to trigger when the correct bit is a falling edge
@ -44,6 +41,7 @@ int32_t GBTimerProcessEvents(struct GBTimer* timer, int32_t cycles) {
} }
} }
++timer->internalDiv; ++timer->internalDiv;
timer->p->memory.io[REG_DIV] = timer->internalDiv >> 4;
} }
if (timer->nextEvent <= 0) { if (timer->nextEvent <= 0) {
// Batch div increments // Batch div increments
@ -64,6 +62,15 @@ int32_t GBTimerProcessEvents(struct GBTimer* timer, int32_t cycles) {
void GBTimerDivReset(struct GBTimer* timer) { void GBTimerDivReset(struct GBTimer* timer) {
timer->p->memory.io[REG_DIV] = 0; timer->p->memory.io[REG_DIV] = 0;
timer->internalDiv = 0;
timer->nextDiv = timer->p->cpu->cycles + GB_DMG_DIV_PERIOD;
if (timer->nextDiv < timer->nextEvent) {
timer->nextEvent = timer->nextDiv;
}
if (timer->nextDiv < timer->p->cpu->nextEvent) {
timer->p->cpu->nextEvent = timer->nextDiv;
}
timer->nextDiv += timer->eventDiff;
} }
uint8_t GBTimerUpdateTAC(struct GBTimer* timer, GBRegisterTAC tac) { uint8_t GBTimerUpdateTAC(struct GBTimer* timer, GBRegisterTAC tac) {