all repos — mgba @ 4680a767c638530856255b133e7a88bf1ebb333e

mGBA Game Boy Advance Emulator

Core: Manage next event internally to mTiming
Jeffrey Pfau jeffrey@endrift.com
Sat, 24 Sep 2016 11:04:20 -0700
commit

4680a767c638530856255b133e7a88bf1ebb333e

parent

a506f6cd9d6fd025410f62e3b663b0aaea3f0b82

4 files changed, 16 insertions(+), 10 deletions(-)

jump to
M src/core/timing.csrc/core/timing.c

@@ -7,10 +7,11 @@ #include "timing.h"

DEFINE_VECTOR(mTimingEventList, struct mTimingEvent*); -void mTimingInit(struct mTiming* timing, int32_t* relativeCycles) { +void mTimingInit(struct mTiming* timing, int32_t* relativeCycles, int32_t* nextEvent) { mTimingEventListInit(&timing->events, 0); timing->masterCycles = 0; timing->relativeCycles = relativeCycles; + timing->nextEvent = nextEvent; } void mTimingDeinit(struct mTiming* timing) {

@@ -23,7 +24,11 @@ timing->masterCycles = 0;

} void mTimingSchedule(struct mTiming* timing, struct mTimingEvent* event, int32_t when) { - event->when = when + timing->masterCycles + *timing->relativeCycles; + int32_t nextEvent = when + *timing->relativeCycles; + event->when = nextEvent + timing->masterCycles; + if (nextEvent < *timing->nextEvent) { + *timing->nextEvent = nextEvent; + } size_t e; for (e = 0; e < mTimingEventListSize(&timing->events); ++e) { struct mTimingEvent* next = *mTimingEventListGetPointer(&timing->events, e);

@@ -54,6 +59,7 @@ while (mTimingEventListSize(&timing->events)) {

struct mTimingEvent* next = *mTimingEventListGetPointer(&timing->events, 0); int32_t nextWhen = next->when - timing->masterCycles; if (nextWhen > 0) { + *timing->nextEvent = nextWhen; return; } mTimingEventListShift(&timing->events, 0, 1);
M src/core/timing.hsrc/core/timing.h

@@ -24,9 +24,10 @@ struct mTimingEventList events;

uint32_t masterCycles; int32_t* relativeCycles; + int32_t* nextEvent; }; -void mTimingInit(struct mTiming* timing, int32_t* relativeCycles); +void mTimingInit(struct mTiming* timing, int32_t* relativeCycles, int32_t* nextEvent); void mTimingDeinit(struct mTiming* timing); void mTimingClear(struct mTiming* timing); void mTimingSchedule(struct mTiming* timing, struct mTimingEvent*, int32_t when);
M src/gb/gb.csrc/gb/gb.c

@@ -83,7 +83,7 @@

gb->coreCallbacks = NULL; gb->stream = NULL; - mTimingInit(&gb->timing, &gb->cpu->cycles); + mTimingInit(&gb->timing, &gb->cpu->cycles, &gb->cpu->nextEvent); } static void GBDeinit(struct mCPUComponent* component) {
M src/gba/gba.csrc/gba/gba.c

@@ -112,7 +112,7 @@ gba->pristineRom = 0;

gba->pristineRomSize = 0; gba->yankedRomSize = 0; - mTimingInit(&gba->timing, &gba->cpu->cycles); + mTimingInit(&gba->timing, &gba->cpu->cycles, &gba->cpu->nextEvent); } void GBAUnloadROM(struct GBA* gba) {

@@ -188,6 +188,7 @@ gba->memory.romSize = gba->yankedRomSize;

gba->memory.romMask = toPow2(gba->memory.romSize) - 1; gba->yankedRomSize = 0; } + mTimingClear(&gba->timing); GBAMemoryReset(gba); GBAVideoReset(&gba->video); GBAAudioReset(&gba->audio);

@@ -235,10 +236,11 @@ }

do { int32_t cycles = cpu->nextEvent; - int32_t nextEvent = INT_MAX; + int32_t nextEvent; int32_t testEvent; cpu->cycles -= cycles; + cpu->nextEvent = INT_MAX; #ifndef NDEBUG if (cycles < 0) {

@@ -247,10 +249,7 @@ }

#endif mTimingTick(&gba->timing, cycles); - testEvent = mTimingNextEvent(&gba->timing); - if (testEvent < nextEvent) { - nextEvent = testEvent; - } + nextEvent = cpu->nextEvent; testEvent = GBAVideoProcessEvents(&gba->video, cycles); if (testEvent < nextEvent) {