GB, GBA: Improve savestate loading in new timing system
@@ -964,7 +964,6 @@ audio->ch1.control.length = GBSerializedAudioEnvelopeGetLength(ch1Flags);
audio->ch1.envelope.nextStep = GBSerializedAudioEnvelopeGetNextStep(ch1Flags); audio->ch1.sweep.realFrequency = GBSerializedAudioEnvelopeGetFrequency(ch1Flags); LOAD_32LE(when, 0, &state->ch1.nextEvent); - mTimingDeschedule(audio->timing, &audio->ch1Event); if (audio->ch1.envelope.dead < 2 && audio->playingCh1) { mTimingSchedule(audio->timing, &audio->ch1Event, when); }@@ -976,7 +975,6 @@ audio->ch2.control.hi = GBSerializedAudioFlagsGetCh2Hi(flags);
audio->ch2.control.length = GBSerializedAudioEnvelopeGetLength(ch2Flags); audio->ch2.envelope.nextStep = GBSerializedAudioEnvelopeGetNextStep(ch2Flags); LOAD_32LE(when, 0, &state->ch2.nextEvent); - mTimingDeschedule(audio->timing, &audio->ch2Event); if (audio->ch2.envelope.dead < 2 && audio->playingCh2) { mTimingSchedule(audio->timing, &audio->ch2Event, when); }@@ -986,7 +984,6 @@ // TODO: Big endian?
memcpy(audio->ch3.wavedata32, state->ch3.wavebanks, sizeof(audio->ch3.wavedata32)); LOAD_16LE(audio->ch3.length, 0, &state->ch3.length); LOAD_32LE(when, 0, &state->ch3.nextEvent); - mTimingDeschedule(audio->timing, &audio->ch3Event); if (audio->playingCh3) { mTimingSchedule(audio->timing, &audio->ch3Event, when); }@@ -1002,7 +999,6 @@ audio->ch4.length = GBSerializedAudioEnvelopeGetLength(ch4Flags);
audio->ch4.envelope.nextStep = GBSerializedAudioEnvelopeGetNextStep(ch4Flags); LOAD_32LE(audio->ch4.lfsr, 0, &state->ch4.lfsr); LOAD_32LE(when, 0, &state->ch4.nextEvent); - mTimingDeschedule(audio->timing, &audio->ch4Event); if (audio->ch4.envelope.dead < 2 && audio->playingCh4) { mTimingSchedule(audio->timing, &audio->ch4Event, when); }@@ -1017,6 +1013,5 @@ void GBAudioDeserialize(struct GBAudio* audio, const struct GBSerializedState* state) {
GBAudioPSGDeserialize(audio, &state->audio.psg, &state->audio.flags); uint32_t when; LOAD_32LE(when, 0, &state->audio.nextSample); - mTimingDeschedule(audio->timing, &audio->sampleEvent); mTimingSchedule(audio->timing, &audio->sampleEvent, when); }
@@ -630,12 +630,10 @@ memcpy(memory->rtcRegs, state->memory.rtcRegs, sizeof(state->memory.rtcRegs));
uint32_t when; LOAD_32LE(when, 0, &state->memory.dmaNext); - mTimingDeschedule(&gb->timing, &memory->dmaEvent); if (memory->dmaRemaining) { mTimingSchedule(&gb->timing, &memory->dmaEvent, when); } LOAD_32LE(when, 0, &state->memory.hdmaNext); - mTimingDeschedule(&gb->timing, &memory->hdmaEvent); if (memory->hdmaRemaining) { mTimingSchedule(&gb->timing, &memory->hdmaEvent, when); }
@@ -170,14 +170,13 @@ gb->audio.timingFactor = gb->doubleSpeed + 1;
uint32_t when; LOAD_32LE(when, 0, &state->cpu.eiPending); - mTimingDeschedule(&gb->timing, &gb->eiPending); if (GBSerializedCpuFlagsIsEiPending(flags)) { mTimingSchedule(&gb->timing, &gb->eiPending, when); } LOAD_32LE(gb->cpu->cycles, 0, &state->cpu.cycles); LOAD_32LE(gb->cpu->nextEvent, 0, &state->cpu.nextEvent); - LOAD_32LE(gb->timing.masterCycles, 0, &state->masterCycles); + gb->timing.root = NULL; gb->model = state->model;
@@ -109,13 +109,11 @@ LOAD_32LE(timer->timaPeriod, 0, &state->timer.timaPeriod);
uint32_t when; LOAD_32LE(when, 0, &state->timer.nextEvent); - mTimingDeschedule(&timer->p->timing, &timer->event); mTimingSchedule(&timer->p->timing, &timer->event, when); GBSerializedTimerFlags flags; LOAD_32LE(flags, 0, &state->timer.flags); - mTimingDeschedule(&timer->p->timing, &timer->irq); if (GBSerializedTimerFlagsIsIrqPending(flags)) { LOAD_32LE(when, 0, &state->timer.nextIRQ); mTimingSchedule(&timer->p->timing, &timer->irq, when);
@@ -550,12 +550,10 @@ break;
} uint32_t when; - mTimingDeschedule(&video->p->timing, &video->modeEvent); if (!GBSerializedVideoFlagsIsNotModeEventScheduled(flags)) { LOAD_32LE(when, 0, &state->video.nextMode); mTimingSchedule(&video->p->timing, &video->modeEvent, when); } - mTimingDeschedule(&video->p->timing, &video->frameEvent); if (!GBSerializedVideoFlagsIsNotFrameEventScheduled(flags)) { LOAD_32LE(when, 0, &state->video.nextFrame); mTimingSchedule(&video->p->timing, &video->frameEvent, when);
@@ -344,7 +344,6 @@ }
uint32_t when; LOAD_32(when, 0, &state->audio.nextSample); - mTimingDeschedule(&audio->p->timing, &audio->sampleEvent); mTimingSchedule(&audio->p->timing, &audio->sampleEvent, when); }
@@ -956,7 +956,6 @@ LOAD_32(when, 0, &state->timers[i].lastEvent);
gba->timers[i].lastEvent = when + mTimingCurrentTime(&gba->timing); } LOAD_32(when, 0, &state->timers[i].nextEvent); - mTimingDeschedule(&gba->timing, &gba->timers[i].event); if (GBATimerFlagsIsEnable(gba->timers[i].flags)) { mTimingSchedule(&gba->timing, &gba->timers[i].event, when); }
@@ -548,7 +548,6 @@
if (GBASerializedSavedataFlagsIsDustSettling(flags)) { uint32_t when; LOAD_32(when, 0, &state->savedata.settlingDust); - mTimingDeschedule(savedata->timing, &savedata->dust); mTimingSchedule(savedata->timing, &savedata->dust, when); } }
@@ -146,7 +146,7 @@ }
if (error) { return false; } - LOAD_32(gba->timing.masterCycles, 0, &state->masterCycles); + gba->timing.root = NULL; size_t i; for (i = 0; i < 16; ++i) { LOAD_32(gba->cpu->gprs[i], i * sizeof(gba->cpu->gprs[0]), state->cpu.gprs);
@@ -324,7 +324,6 @@ video->event.callback = _startHdraw;
} else { video->event.callback = _startHblank; } - mTimingDeschedule(&video->p->timing, &video->event); mTimingSchedule(&video->p->timing, &video->event, when); LOAD_16(video->vcount, REG_VCOUNT, state->io);