all repos — mgba @ a1e43c91a1aa67509ddb59b127375aa2edbbe385

mGBA Game Boy Advance Emulator

GB Serialize: Fix some deserialization bugs
Vicki Pfau vi@endrift.com
Mon, 10 Aug 2020 17:24:50 -0700
commit

a1e43c91a1aa67509ddb59b127375aa2edbbe385

parent

549787227a488a4f52e30ee0b14cb9bf331b327c

6 files changed, 19 insertions(+), 4 deletions(-)

jump to
M src/gb/io.csrc/gb/io.c

@@ -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]);
M src/gb/mbc.csrc/gb/mbc.c

@@ -440,6 +440,7 @@ GBMBCSwitchBank0(gb, 0);

GBMBCSwitchSramBank(gb, 0); } if (!(state->bankLo & 0x1F)) { + ++state->bankLo; ++bank; } GBMBCSwitchBank(gb, bank);
M src/gb/memory.csrc/gb/memory.c

@@ -211,6 +211,7 @@ GBMBCInit(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 @@ uint32_t when;

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;
M src/gb/serialize.csrc/gb/serialize.c

@@ -188,6 +188,8 @@ uint32_t when;

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;
M src/gb/timer.csrc/gb/timer.c

@@ -140,8 +140,10 @@ mTimingSchedule(&timer->p->timing, &timer->event, when);

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); } }
M src/gb/video.csrc/gb/video.c

@@ -904,13 +904,17 @@ break;

} 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);