From 65665324ef9124280a8a310ab9cea048d519a5a9 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Tue, 17 Oct 2017 21:23:00 -0700 Subject: [PATCH] GB Serialize: Partially fix loading SGB states from a GB game --- src/gb/serialize.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/gb/serialize.c b/src/gb/serialize.c index c37b3872b..4c54c3e59 100644 --- a/src/gb/serialize.c +++ b/src/gb/serialize.c @@ -9,6 +9,8 @@ #include #include +#include + mLOG_DEFINE_CATEGORY(GB_STATE, "GB Savestate", "gb.serialize"); const uint32_t GB_SAVESTATE_MAGIC = 0x00400000; @@ -171,6 +173,7 @@ bool GBDeserialize(struct GB* gb, const struct GBSerializedState* state) { mTimingSchedule(&gb->timing, &gb->eiPending, when); } + enum GBModel oldModel = gb->model; gb->model = state->model; if (gb->model < GB_MODEL_CGB) { @@ -179,6 +182,10 @@ bool GBDeserialize(struct GB* gb, const struct GBSerializedState* state) { gb->audio.style = GB_AUDIO_CGB; } + if (gb->model != GB_MODEL_SGB || oldModel != GB_MODEL_SGB) { + gb->video.sgbBorders = false; + } + GBMemoryDeserialize(gb, state); GBVideoDeserialize(&gb->video, state); GBIODeserialize(gb, state); @@ -237,22 +244,28 @@ void GBSGBDeserialize(struct GB* gb, const struct GBSerializedState* state) { memcpy(gb->sgbPacket, state->sgb.packet, sizeof(state->sgb.packet)); - if (gb->video.renderer->sgbCharRam) { - memcpy(gb->video.renderer->sgbCharRam, state->sgb.charRam, sizeof(state->sgb.charRam)); + if (!gb->video.renderer->sgbCharRam) { + gb->video.renderer->sgbCharRam = anonymousMemoryMap(SGB_SIZE_CHAR_RAM); } - if (gb->video.renderer->sgbMapRam) { - memcpy(gb->video.renderer->sgbMapRam, state->sgb.mapRam, sizeof(state->sgb.mapRam)); + if (!gb->video.renderer->sgbMapRam) { + gb->video.renderer->sgbMapRam = anonymousMemoryMap(SGB_SIZE_MAP_RAM); } - if (gb->video.renderer->sgbPalRam) { - memcpy(gb->video.renderer->sgbPalRam, state->sgb.palRam, sizeof(state->sgb.palRam)); + if (!gb->video.renderer->sgbPalRam) { + gb->video.renderer->sgbPalRam = anonymousMemoryMap(SGB_SIZE_PAL_RAM); } - if (gb->video.renderer->sgbAttributeFiles) { - memcpy(gb->video.renderer->sgbAttributeFiles, state->sgb.atfRam, sizeof(state->sgb.atfRam)); + if (!gb->video.renderer->sgbAttributeFiles) { + gb->video.renderer->sgbAttributeFiles = anonymousMemoryMap(SGB_SIZE_ATF_RAM); } - if (gb->video.renderer->sgbAttributes) { - memcpy(gb->video.renderer->sgbAttributes, state->sgb.attributes, sizeof(state->sgb.attributes)); + if (!gb->video.renderer->sgbAttributes) { + gb->video.renderer->sgbAttributes = malloc(90 * 45); } + memcpy(gb->video.renderer->sgbCharRam, state->sgb.charRam, sizeof(state->sgb.charRam)); + memcpy(gb->video.renderer->sgbMapRam, state->sgb.mapRam, sizeof(state->sgb.mapRam)); + memcpy(gb->video.renderer->sgbPalRam, state->sgb.palRam, sizeof(state->sgb.palRam)); + memcpy(gb->video.renderer->sgbAttributeFiles, state->sgb.atfRam, sizeof(state->sgb.atfRam)); + memcpy(gb->video.renderer->sgbAttributes, state->sgb.attributes, sizeof(state->sgb.attributes)); + GBVideoWriteSGBPacket(&gb->video, (uint8_t[16]) { (SGB_ATRC_EN << 3) | 1, 0 }); GBVideoWriteSGBPacket(&gb->video, gb->sgbPacket); }