all repos — mgba @ eee24961b1f2b2bcdb50b132486c8690b8d7237c

mGBA Game Boy Advance Emulator

GB: Partially fix timers
Jeffrey Pfau jeffrey@endrift.com
Tue, 26 Jan 2016 20:57:34 -0800
commit

eee24961b1f2b2bcdb50b132486c8690b8d7237c

parent

bac417d270b5259612bee9434e16de744f5e24a4

3 files changed, 13 insertions(+), 10 deletions(-)

jump to
M src/gb/io.csrc/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.csrc/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.hsrc/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