mirror of https://github.com/mgba-emu/mgba.git
GB: Partially fix timers
This commit is contained in:
parent
bac417d270
commit
eee24961b1
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue