GB, GBA Serialize: Restore master cycles
Vicki Pfau vi@endrift.com
Sat, 05 Aug 2017 20:48:18 -0700
4 files changed,
18 insertions(+),
0 deletions(-)
M
include/mgba/core/timing.h
→
include/mgba/core/timing.h
@@ -23,6 +23,7 @@ };
struct mTiming { struct mTimingEvent* root; + struct mTimingEvent* reroot; uint32_t masterCycles; int32_t* relativeCycles;
M
src/core/timing.c
→
src/core/timing.c
@@ -7,6 +7,7 @@ #include <mgba/core/timing.h>
void mTimingInit(struct mTiming* timing, int32_t* relativeCycles, int32_t* nextEvent) { timing->root = NULL; + timing->reroot = NULL; timing->masterCycles = 0; timing->relativeCycles = relativeCycles; timing->nextEvent = nextEvent;@@ -17,6 +18,7 @@ }
void mTimingClear(struct mTiming* timing) { timing->root = NULL; + timing->reroot = NULL; timing->masterCycles = 0; }@@ -76,6 +78,11 @@ return nextWhen;
} timing->root = next->next; next->callback(timing, next->context, -nextWhen); + } + if (timing->reroot) { + timing->root = timing->reroot; + timing->reroot = NULL; + *timing->nextEvent = mTimingNextEvent(timing); } return *timing->nextEvent; }
M
src/gb/serialize.c
→
src/gb/serialize.c
@@ -134,6 +134,7 @@ if (error) {
return false; } gb->timing.root = NULL; + LOAD_32LE(gb->timing.masterCycles, 0, &state->masterCycles); gb->cpu->a = state->cpu.a; gb->cpu->f.packed = state->cpu.f;@@ -187,6 +188,9 @@ GBSGBDeserialize(gb, state);
} gb->cpu->memory.setActiveRegion(gb->cpu, gb->cpu->pc); + + gb->timing.reroot = gb->timing.root; + gb->timing.root = NULL; return true; }
M
src/gba/serialize.c
→
src/gba/serialize.c
@@ -128,6 +128,8 @@ if (error) {
return false; } gba->timing.root = NULL; + LOAD_32(gba->timing.masterCycles, 0, &state->masterCycles); + size_t i; for (i = 0; i < 16; ++i) { LOAD_32(gba->cpu->gprs[i], i * sizeof(gba->cpu->gprs[0]), state->cpu.gprs);@@ -185,5 +187,9 @@
if (gba->rr) { gba->rr->stateLoaded(gba->rr, state); } + + gba->timing.reroot = gba->timing.root; + gba->timing.root = NULL; + return true; }