GB, GBA Serialize: Restore master cycles

This commit is contained in:
Vicki Pfau 2017-08-05 20:48:18 -07:00
parent 4a83ae2007
commit ff272a5f1d
4 changed files with 18 additions and 0 deletions

View File

@ -23,6 +23,7 @@ struct mTimingEvent {
struct mTiming {
struct mTimingEvent* root;
struct mTimingEvent* reroot;
uint32_t masterCycles;
int32_t* relativeCycles;

View File

@ -7,6 +7,7 @@
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 mTimingDeinit(struct mTiming* timing) {
void mTimingClear(struct mTiming* timing) {
timing->root = NULL;
timing->reroot = NULL;
timing->masterCycles = 0;
}
@ -77,6 +79,11 @@ int32_t mTimingTick(struct mTiming* timing, int32_t cycles) {
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;
}

View File

@ -134,6 +134,7 @@ bool GBDeserialize(struct GB* gb, const struct GBSerializedState* state) {
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;
@ -188,6 +189,9 @@ bool GBDeserialize(struct GB* gb, const struct GBSerializedState* state) {
gb->cpu->memory.setActiveRegion(gb->cpu, gb->cpu->pc);
gb->timing.reroot = gb->timing.root;
gb->timing.root = NULL;
return true;
}

View File

@ -128,6 +128,8 @@ bool GBADeserialize(struct GBA* gba, const struct GBASerializedState* state) {
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 @@ bool GBADeserialize(struct GBA* gba, const struct GBASerializedState* state) {
if (gba->rr) {
gba->rr->stateLoaded(gba->rr, state);
}
gba->timing.reroot = gba->timing.root;
gba->timing.root = NULL;
return true;
}