all repos — mgba @ 65665324ef9124280a8a310ab9cea048d519a5a9

mGBA Game Boy Advance Emulator

GB Serialize: Partially fix loading SGB states from a GB game
Vicki Pfau vi@endrift.com
Tue, 17 Oct 2017 21:23:00 -0700
commit

65665324ef9124280a8a310ab9cea048d519a5a9

parent

acbd8a3688703772861241a9b87f08cf91a0f66d

1 files changed, 23 insertions(+), 10 deletions(-)

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

@@ -9,6 +9,8 @@ #include <mgba/internal/gb/io.h>

#include <mgba/internal/gb/timer.h> #include <mgba/internal/lr35902/lr35902.h> +#include <mgba-util/memory.h> + mLOG_DEFINE_CATEGORY(GB_STATE, "GB Savestate", "gb.serialize"); const uint32_t GB_SAVESTATE_MAGIC = 0x00400000;

@@ -171,12 +173,17 @@ if (GBSerializedCpuFlagsIsEiPending(flags)) {

mTimingSchedule(&gb->timing, &gb->eiPending, when); } + enum GBModel oldModel = gb->model; gb->model = state->model; if (gb->model < GB_MODEL_CGB) { gb->audio.style = GB_AUDIO_DMG; } else { gb->audio.style = GB_AUDIO_CGB; + } + + if (gb->model != GB_MODEL_SGB || oldModel != GB_MODEL_SGB) { + gb->video.sgbBorders = false; } GBMemoryDeserialize(gb, state);

@@ -237,21 +244,27 @@ gb->video.renderer->sgbRenderMode = GBSerializedSGBFlagsGetRenderMode(flags);

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