GB: Partially fix timers
Jeffrey Pfau jeffrey@endrift.com
Tue, 26 Jan 2016 20:57:34 -0800
3 files changed,
13 insertions(+),
10 deletions(-)
M
src/gb/io.c
→
src/gb/io.c
@@ -55,10 +55,8 @@ switch (address) {
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
M
src/gb/timer.c
→
src/gb/timer.c
@@ -71,15 +71,19 @@ case 3:
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; + } + } +}
M
src/gb/timer.h
→
src/gb/timer.h
@@ -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