all repos — mgba @ 6243b7fd3bbbf4a5569ff4d4739fbfbbf2929429

mGBA Game Boy Advance Emulator

GB: Convert SIO events to mTiming
Jeffrey Pfau jeffrey@endrift.com
Sat, 17 Sep 2016 19:04:36 -0700
commit

6243b7fd3bbbf4a5569ff4d4739fbfbbf2929429

parent

e2357f0b70ed3eab14883819b41c19d1e9f30b8e

3 files changed, 22 insertions(+), 24 deletions(-)

jump to
M src/gb/gb.csrc/gb/gb.c

@@ -565,11 +565,6 @@ nextEvent = testEvent;

} } - testEvent = GBSIOProcessEvents(&gb->sio, cycles); - if (testEvent < nextEvent) { - nextEvent = testEvent; - } - cpu->cycles -= cycles; cpu->nextEvent = nextEvent;
M src/gb/sio.csrc/gb/sio.c

@@ -9,8 +9,13 @@ #include "gb/gb.h"

#include "gb/io.h" #include "gb/serialize.h" +void _GBSIOProcessEvents(struct mTiming* timing, void* context, uint32_t cyclesLate); + void GBSIOInit(struct GBSIO* sio) { sio->pendingSB = 0xFF; + sio->event.context = sio; + sio->event.name = "GB SIO"; + sio->event.callback = _GBSIOProcessEvents; } void GBSIOReset(struct GBSIO* sio) {

@@ -23,31 +28,26 @@ UNUSED(sio);

// Nothing to do yet } -int32_t GBSIOProcessEvents(struct GBSIO* sio, int32_t cycles) { - if (sio->nextEvent != INT_MAX) { - sio->nextEvent -= cycles; - } - if (sio->nextEvent <= 0) { - --sio->remainingBits; - sio->p->memory.io[REG_SB] &= ~(8 >> sio->remainingBits); - sio->p->memory.io[REG_SB] |= sio->pendingSB & ~(8 >> sio->remainingBits); - if (!sio->remainingBits) { - sio->p->memory.io[REG_IF] |= (1 << GB_IRQ_SIO); - sio->p->memory.io[REG_SC] = GBRegisterSCClearEnable(sio->p->memory.io[REG_SC]); - GBUpdateIRQs(sio->p); - sio->nextEvent = INT_MAX; - } else { - sio->nextEvent += sio->period; - } +void _GBSIOProcessEvents(struct mTiming* timing, void* context, uint32_t cyclesLate) { + UNUSED(cyclesLate); + struct GBSIO* sio = context; + --sio->remainingBits; + sio->p->memory.io[REG_SB] &= ~(8 >> sio->remainingBits); + sio->p->memory.io[REG_SB] |= sio->pendingSB & ~(8 >> sio->remainingBits); + if (!sio->remainingBits) { + sio->p->memory.io[REG_IF] |= (1 << GB_IRQ_SIO); + sio->p->memory.io[REG_SC] = GBRegisterSCClearEnable(sio->p->memory.io[REG_SC]); + GBUpdateIRQs(sio->p); + } else { + mTimingSchedule(timing, &sio->event, sio->period); } - return sio->nextEvent; } void GBSIOWriteSC(struct GBSIO* sio, uint8_t sc) { sio->period = 0x1000; // TODO Shift Clock if (GBRegisterSCIsEnable(sc)) { if (GBRegisterSCIsShiftClock(sc)) { - sio->nextEvent = sio->p->cpu->cycles + sio->period; + mTimingSchedule(&sio->p->timing, &sio->event, sio->period); } sio->remainingBits = 8; }
M src/gb/sio.hsrc/gb/sio.h

@@ -8,9 +8,13 @@ #define GB_SIO_H

#include "util/common.h" +#include "core/timing.h" + struct GB; struct GBSIO { struct GB* p; + + struct mTimingEvent event; int32_t nextEvent; int32_t period;

@@ -27,7 +31,6 @@

void GBSIOInit(struct GBSIO* sio); void GBSIOReset(struct GBSIO* sio); void GBSIODeinit(struct GBSIO* sio); -int32_t GBSIOProcessEvents(struct GBSIO* sio, int32_t cycles); void GBSIOWriteSC(struct GBSIO* sio, uint8_t sc); #endif