GB Serialize: Fix some deserialization bugs

This commit is contained in:
Vicki Pfau 2020-08-10 17:24:50 -07:00
parent 549787227a
commit a1e43c91a1
6 changed files with 19 additions and 4 deletions

View File

@ -699,7 +699,8 @@ void GBIODeserialize(struct GB* gb, const struct GBSerializedState* state) {
memcpy(gb->memory.io, state->io, GB_SIZE_IO);
gb->memory.ie = state->ie;
if (GBAudioEnableGetEnable(*gb->audio.nr52)) {
gb->audio.enable = GBAudioEnableGetEnable(*gb->audio.nr52);
if (GBAudioEnableGetEnable(gb->audio.enable)) {
GBIOWrite(gb, REG_NR10, gb->memory.io[REG_NR10]);
GBIOWrite(gb, REG_NR11, gb->memory.io[REG_NR11]);
GBIOWrite(gb, REG_NR12, gb->memory.io[REG_NR12]);

View File

@ -440,6 +440,7 @@ static void _GBMBC1Update(struct GB* gb) {
GBMBCSwitchSramBank(gb, 0);
}
if (!(state->bankLo & 0x1F)) {
++state->bankLo;
++bank;
}
GBMBCSwitchBank(gb, bank);

View File

@ -211,6 +211,7 @@ void GBMemoryReset(struct GB* gb) {
switch (gb->memory.mbcType) {
case GB_MBC1:
gb->memory.mbcState.mbc1.mode = 0;
gb->memory.mbcState.mbc1.bankLo = 1;
break;
case GB_MBC6:
GBMBCSwitchHalfBank(gb, 0, 2);
@ -784,10 +785,14 @@ void GBMemoryDeserialize(struct GB* gb, const struct GBSerializedState* state) {
LOAD_32LE(when, 0, &state->memory.dmaNext);
if (memory->dmaRemaining) {
mTimingSchedule(&gb->timing, &memory->dmaEvent, when);
} else {
memory->dmaEvent.when = when + mTimingCurrentTime(&gb->timing);
}
LOAD_32LE(when, 0, &state->memory.hdmaNext);
if (memory->hdmaRemaining) {
mTimingSchedule(&gb->timing, &memory->hdmaEvent, when);
} else {
memory->hdmaEvent.when = when + mTimingCurrentTime(&gb->timing);
}
GBSerializedMemoryFlags flags;

View File

@ -188,6 +188,8 @@ bool GBDeserialize(struct GB* gb, const struct GBSerializedState* state) {
LOAD_32LE(when, 0, &state->cpu.eiPending);
if (GBSerializedCpuFlagsIsEiPending(flags)) {
mTimingSchedule(&gb->timing, &gb->eiPending, when);
} else {
gb->eiPending.when = when + mTimingCurrentTime(&gb->timing);
}
gb->model = state->model;

View File

@ -140,8 +140,10 @@ void GBTimerDeserialize(struct GBTimer* timer, const struct GBSerializedState* s
GBSerializedTimerFlags flags = state->timer.flags;
LOAD_32LE(when, 0, &state->timer.nextIRQ);
if (GBSerializedTimerFlagsIsIrqPending(flags)) {
LOAD_32LE(when, 0, &state->timer.nextIRQ);
mTimingSchedule(&timer->p->timing, &timer->irq, when);
} else {
timer->irq.when = when + mTimingCurrentTime(&timer->p->timing);
}
}

View File

@ -904,13 +904,17 @@ void GBVideoDeserialize(struct GBVideo* video, const struct GBSerializedState* s
}
uint32_t when;
LOAD_32LE(when, 0, &state->video.nextMode);
if (!GBSerializedVideoFlagsIsNotModeEventScheduled(flags)) {
LOAD_32LE(when, 0, &state->video.nextMode);
mTimingSchedule(&video->p->timing, &video->modeEvent, when);
} else {
video->modeEvent.when = when + mTimingCurrentTime(&video->p->timing);
}
LOAD_32LE(when, 0, &state->video.nextFrame);
if (!GBSerializedVideoFlagsIsNotFrameEventScheduled(flags)) {
LOAD_32LE(when, 0, &state->video.nextFrame);
mTimingSchedule(&video->p->timing, &video->frameEvent, when);
} else {
video->frameEvent.when = when + mTimingCurrentTime(&video->p->timing);
}
video->renderer->deinit(video->renderer);