GB, GBA: Improve savestate loading in new timing system

This commit is contained in:
Vicki Pfau 2017-02-04 12:50:09 -08:00
parent 30ec43741b
commit d2016e382a
10 changed files with 2 additions and 18 deletions

View File

@ -964,7 +964,6 @@ void GBAudioPSGDeserialize(struct GBAudio* audio, const struct GBSerializedPSGSt
audio->ch1.envelope.nextStep = GBSerializedAudioEnvelopeGetNextStep(ch1Flags); audio->ch1.envelope.nextStep = GBSerializedAudioEnvelopeGetNextStep(ch1Flags);
audio->ch1.sweep.realFrequency = GBSerializedAudioEnvelopeGetFrequency(ch1Flags); audio->ch1.sweep.realFrequency = GBSerializedAudioEnvelopeGetFrequency(ch1Flags);
LOAD_32LE(when, 0, &state->ch1.nextEvent); LOAD_32LE(when, 0, &state->ch1.nextEvent);
mTimingDeschedule(audio->timing, &audio->ch1Event);
if (audio->ch1.envelope.dead < 2 && audio->playingCh1) { if (audio->ch1.envelope.dead < 2 && audio->playingCh1) {
mTimingSchedule(audio->timing, &audio->ch1Event, when); mTimingSchedule(audio->timing, &audio->ch1Event, when);
} }
@ -976,7 +975,6 @@ void GBAudioPSGDeserialize(struct GBAudio* audio, const struct GBSerializedPSGSt
audio->ch2.control.length = GBSerializedAudioEnvelopeGetLength(ch2Flags); audio->ch2.control.length = GBSerializedAudioEnvelopeGetLength(ch2Flags);
audio->ch2.envelope.nextStep = GBSerializedAudioEnvelopeGetNextStep(ch2Flags); audio->ch2.envelope.nextStep = GBSerializedAudioEnvelopeGetNextStep(ch2Flags);
LOAD_32LE(when, 0, &state->ch2.nextEvent); LOAD_32LE(when, 0, &state->ch2.nextEvent);
mTimingDeschedule(audio->timing, &audio->ch2Event);
if (audio->ch2.envelope.dead < 2 && audio->playingCh2) { if (audio->ch2.envelope.dead < 2 && audio->playingCh2) {
mTimingSchedule(audio->timing, &audio->ch2Event, when); mTimingSchedule(audio->timing, &audio->ch2Event, when);
} }
@ -986,7 +984,6 @@ void GBAudioPSGDeserialize(struct GBAudio* audio, const struct GBSerializedPSGSt
memcpy(audio->ch3.wavedata32, state->ch3.wavebanks, sizeof(audio->ch3.wavedata32)); memcpy(audio->ch3.wavedata32, state->ch3.wavebanks, sizeof(audio->ch3.wavedata32));
LOAD_16LE(audio->ch3.length, 0, &state->ch3.length); LOAD_16LE(audio->ch3.length, 0, &state->ch3.length);
LOAD_32LE(when, 0, &state->ch3.nextEvent); LOAD_32LE(when, 0, &state->ch3.nextEvent);
mTimingDeschedule(audio->timing, &audio->ch3Event);
if (audio->playingCh3) { if (audio->playingCh3) {
mTimingSchedule(audio->timing, &audio->ch3Event, when); mTimingSchedule(audio->timing, &audio->ch3Event, when);
} }
@ -1002,7 +999,6 @@ void GBAudioPSGDeserialize(struct GBAudio* audio, const struct GBSerializedPSGSt
audio->ch4.envelope.nextStep = GBSerializedAudioEnvelopeGetNextStep(ch4Flags); audio->ch4.envelope.nextStep = GBSerializedAudioEnvelopeGetNextStep(ch4Flags);
LOAD_32LE(audio->ch4.lfsr, 0, &state->ch4.lfsr); LOAD_32LE(audio->ch4.lfsr, 0, &state->ch4.lfsr);
LOAD_32LE(when, 0, &state->ch4.nextEvent); LOAD_32LE(when, 0, &state->ch4.nextEvent);
mTimingDeschedule(audio->timing, &audio->ch4Event);
if (audio->ch4.envelope.dead < 2 && audio->playingCh4) { if (audio->ch4.envelope.dead < 2 && audio->playingCh4) {
mTimingSchedule(audio->timing, &audio->ch4Event, when); mTimingSchedule(audio->timing, &audio->ch4Event, when);
} }
@ -1017,6 +1013,5 @@ void GBAudioDeserialize(struct GBAudio* audio, const struct GBSerializedState* s
GBAudioPSGDeserialize(audio, &state->audio.psg, &state->audio.flags); GBAudioPSGDeserialize(audio, &state->audio.psg, &state->audio.flags);
uint32_t when; uint32_t when;
LOAD_32LE(when, 0, &state->audio.nextSample); LOAD_32LE(when, 0, &state->audio.nextSample);
mTimingDeschedule(audio->timing, &audio->sampleEvent);
mTimingSchedule(audio->timing, &audio->sampleEvent, when); mTimingSchedule(audio->timing, &audio->sampleEvent, when);
} }

View File

@ -630,12 +630,10 @@ void GBMemoryDeserialize(struct GB* gb, const struct GBSerializedState* state) {
uint32_t when; uint32_t when;
LOAD_32LE(when, 0, &state->memory.dmaNext); LOAD_32LE(when, 0, &state->memory.dmaNext);
mTimingDeschedule(&gb->timing, &memory->dmaEvent);
if (memory->dmaRemaining) { if (memory->dmaRemaining) {
mTimingSchedule(&gb->timing, &memory->dmaEvent, when); mTimingSchedule(&gb->timing, &memory->dmaEvent, when);
} }
LOAD_32LE(when, 0, &state->memory.hdmaNext); LOAD_32LE(when, 0, &state->memory.hdmaNext);
mTimingDeschedule(&gb->timing, &memory->hdmaEvent);
if (memory->hdmaRemaining) { if (memory->hdmaRemaining) {
mTimingSchedule(&gb->timing, &memory->hdmaEvent, when); mTimingSchedule(&gb->timing, &memory->hdmaEvent, when);
} }

View File

@ -170,14 +170,13 @@ bool GBDeserialize(struct GB* gb, const struct GBSerializedState* state) {
uint32_t when; uint32_t when;
LOAD_32LE(when, 0, &state->cpu.eiPending); LOAD_32LE(when, 0, &state->cpu.eiPending);
mTimingDeschedule(&gb->timing, &gb->eiPending);
if (GBSerializedCpuFlagsIsEiPending(flags)) { if (GBSerializedCpuFlagsIsEiPending(flags)) {
mTimingSchedule(&gb->timing, &gb->eiPending, when); mTimingSchedule(&gb->timing, &gb->eiPending, when);
} }
LOAD_32LE(gb->cpu->cycles, 0, &state->cpu.cycles); LOAD_32LE(gb->cpu->cycles, 0, &state->cpu.cycles);
LOAD_32LE(gb->cpu->nextEvent, 0, &state->cpu.nextEvent); 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; gb->model = state->model;

View File

@ -109,13 +109,11 @@ void GBTimerDeserialize(struct GBTimer* timer, const struct GBSerializedState* s
uint32_t when; uint32_t when;
LOAD_32LE(when, 0, &state->timer.nextEvent); LOAD_32LE(when, 0, &state->timer.nextEvent);
mTimingDeschedule(&timer->p->timing, &timer->event);
mTimingSchedule(&timer->p->timing, &timer->event, when); mTimingSchedule(&timer->p->timing, &timer->event, when);
GBSerializedTimerFlags flags; GBSerializedTimerFlags flags;
LOAD_32LE(flags, 0, &state->timer.flags); LOAD_32LE(flags, 0, &state->timer.flags);
mTimingDeschedule(&timer->p->timing, &timer->irq);
if (GBSerializedTimerFlagsIsIrqPending(flags)) { if (GBSerializedTimerFlagsIsIrqPending(flags)) {
LOAD_32LE(when, 0, &state->timer.nextIRQ); LOAD_32LE(when, 0, &state->timer.nextIRQ);
mTimingSchedule(&timer->p->timing, &timer->irq, when); mTimingSchedule(&timer->p->timing, &timer->irq, when);

View File

@ -550,12 +550,10 @@ void GBVideoDeserialize(struct GBVideo* video, const struct GBSerializedState* s
} }
uint32_t when; uint32_t when;
mTimingDeschedule(&video->p->timing, &video->modeEvent);
if (!GBSerializedVideoFlagsIsNotModeEventScheduled(flags)) { if (!GBSerializedVideoFlagsIsNotModeEventScheduled(flags)) {
LOAD_32LE(when, 0, &state->video.nextMode); LOAD_32LE(when, 0, &state->video.nextMode);
mTimingSchedule(&video->p->timing, &video->modeEvent, when); mTimingSchedule(&video->p->timing, &video->modeEvent, when);
} }
mTimingDeschedule(&video->p->timing, &video->frameEvent);
if (!GBSerializedVideoFlagsIsNotFrameEventScheduled(flags)) { if (!GBSerializedVideoFlagsIsNotFrameEventScheduled(flags)) {
LOAD_32LE(when, 0, &state->video.nextFrame); LOAD_32LE(when, 0, &state->video.nextFrame);
mTimingSchedule(&video->p->timing, &video->frameEvent, when); mTimingSchedule(&video->p->timing, &video->frameEvent, when);

View File

@ -344,7 +344,6 @@ void GBAAudioDeserialize(struct GBAAudio* audio, const struct GBASerializedState
uint32_t when; uint32_t when;
LOAD_32(when, 0, &state->audio.nextSample); LOAD_32(when, 0, &state->audio.nextSample);
mTimingDeschedule(&audio->p->timing, &audio->sampleEvent);
mTimingSchedule(&audio->p->timing, &audio->sampleEvent, when); mTimingSchedule(&audio->p->timing, &audio->sampleEvent, when);
} }

View File

@ -956,7 +956,6 @@ void GBAIODeserialize(struct GBA* gba, const struct GBASerializedState* state) {
gba->timers[i].lastEvent = when + mTimingCurrentTime(&gba->timing); gba->timers[i].lastEvent = when + mTimingCurrentTime(&gba->timing);
} }
LOAD_32(when, 0, &state->timers[i].nextEvent); LOAD_32(when, 0, &state->timers[i].nextEvent);
mTimingDeschedule(&gba->timing, &gba->timers[i].event);
if (GBATimerFlagsIsEnable(gba->timers[i].flags)) { if (GBATimerFlagsIsEnable(gba->timers[i].flags)) {
mTimingSchedule(&gba->timing, &gba->timers[i].event, when); mTimingSchedule(&gba->timing, &gba->timers[i].event, when);
} }

View File

@ -548,7 +548,6 @@ void GBASavedataDeserialize(struct GBASavedata* savedata, const struct GBASerial
if (GBASerializedSavedataFlagsIsDustSettling(flags)) { if (GBASerializedSavedataFlagsIsDustSettling(flags)) {
uint32_t when; uint32_t when;
LOAD_32(when, 0, &state->savedata.settlingDust); LOAD_32(when, 0, &state->savedata.settlingDust);
mTimingDeschedule(savedata->timing, &savedata->dust);
mTimingSchedule(savedata->timing, &savedata->dust, when); mTimingSchedule(savedata->timing, &savedata->dust, when);
} }
} }

View File

@ -146,7 +146,7 @@ bool GBADeserialize(struct GBA* gba, const struct GBASerializedState* state) {
if (error) { if (error) {
return false; return false;
} }
LOAD_32(gba->timing.masterCycles, 0, &state->masterCycles); gba->timing.root = NULL;
size_t i; size_t i;
for (i = 0; i < 16; ++i) { for (i = 0; i < 16; ++i) {
LOAD_32(gba->cpu->gprs[i], i * sizeof(gba->cpu->gprs[0]), state->cpu.gprs); LOAD_32(gba->cpu->gprs[i], i * sizeof(gba->cpu->gprs[0]), state->cpu.gprs);

View File

@ -324,7 +324,6 @@ void GBAVideoDeserialize(struct GBAVideo* video, const struct GBASerializedState
} else { } else {
video->event.callback = _startHblank; video->event.callback = _startHblank;
} }
mTimingDeschedule(&video->p->timing, &video->event);
mTimingSchedule(&video->p->timing, &video->event, when); mTimingSchedule(&video->p->timing, &video->event, when);
LOAD_16(video->vcount, REG_VCOUNT, state->io); LOAD_16(video->vcount, REG_VCOUNT, state->io);