GB: Partially fix timers

This commit is contained in:
Jeffrey Pfau 2016-01-26 20:57:34 -08:00
parent bac417d270
commit eee24961b1
3 changed files with 13 additions and 10 deletions

View File

@ -55,10 +55,8 @@ void GBIOWrite(struct GB* gb, unsigned address, uint8_t value) {
case REG_DIV:
GBTimerDivReset(&gb->timer);
return;
case REG_TIMA:
// ???
return;
case REG_JOYP:
case REG_TIMA:
case REG_TMA:
case REG_LYC:
// Handled transparently by the registers

View File

@ -71,15 +71,19 @@ uint8_t GBTimerUpdateTAC(struct GBTimer* timer, GBRegisterTAC tac) {
timer->timaPeriod = 256;
break;
}
timer->nextTima = timer->eventDiff + timer->timaPeriod;
if (timer->nextTima < timer->nextEvent) {
timer->nextEvent = timer->nextTima;
if (timer->nextEvent < timer->p->cpu->nextEvent) {
timer->p->cpu->nextEvent = timer->nextEvent;
}
}
GBTimerUpdateTIMA(timer);
} else {
timer->nextTima = INT_MAX;
}
return tac;
}
void GBTimerUpdateTIMA(struct GBTimer* timer) {
timer->nextTima = timer->eventDiff + timer->p->cpu->cycles + timer->timaPeriod;
if (timer->eventDiff + timer->timaPeriod < timer->nextEvent) {
timer->nextEvent = timer->eventDiff + timer->timaPeriod;
if (timer->nextEvent < timer->p->cpu->nextEvent) {
timer->p->cpu->nextEvent = timer->nextEvent;
}
}
}

View File

@ -32,5 +32,6 @@ void GBTimerReset(struct GBTimer*);
int32_t GBTimerProcessEvents(struct GBTimer*, int32_t cycles);
void GBTimerDivReset(struct GBTimer*);
uint8_t GBTimerUpdateTAC(struct GBTimer*, GBRegisterTAC tac);
void GBTimerUpdateTIMA(struct GBTimer* timer);
#endif