all repos — mgba @ 25beafcc11af80cdd3192ec3a363ba5e45f4d9b2

mGBA Game Boy Advance Emulator

GB, GBA Core: Only deserialize needed parts of savestates for mVL
Vicki Pfau vi@endrift.com
Mon, 24 Apr 2017 12:43:12 -0700
commit

25beafcc11af80cdd3192ec3a363ba5e45f4d9b2

parent

63ed7421ce05174608dd1799f8e7b0a5f01d5c3d

2 files changed, 41 insertions(+), 20 deletions(-)

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

@@ -8,6 +8,7 @@

#include <mgba/core/core.h> #include <mgba/internal/gb/cheats.h> #include <mgba/internal/gb/extra/cli.h> +#include <mgba/internal/gb/io.h> #include <mgba/internal/gb/gb.h> #include <mgba/internal/gb/mbc.h> #include <mgba/internal/gb/overrides.h>

@@ -752,11 +753,6 @@ if (!mVideoLoggerRendererRun(gbcore->proxyRenderer.logger, true)) {

GBVideoProxyRendererUnshim(&gb->video, &gbcore->proxyRenderer); mVideoLogContextRewind(gbcore->logContext, core); GBVideoProxyRendererShim(&gb->video, &gbcore->proxyRenderer); - - // Make sure CPU loop never spins - GBHalt(gb->cpu); - gb->memory.ie = 0; - gb->memory.ime = false; } }

@@ -796,11 +792,6 @@

LR35902Reset(core->cpu); mVideoLogContextRewind(gbcore->logContext, core); GBVideoProxyRendererShim(&gb->video, &gbcore->proxyRenderer); - - // Make sure CPU loop never spins - GBHalt(gb->cpu); - gb->memory.ie = 0; - gb->memory.ime = false; } static bool _GBVLPLoadROM(struct mCore* core, struct VFile* vf) {

@@ -815,6 +806,27 @@ mVideoLoggerAttachChannel(gbcore->proxyRenderer.logger, gbcore->logContext, 0);

return true; } +static bool _GBVLPLoadState(struct mCore* core, const void* buffer) { + struct GB* gb = (struct GB*) core->board; + const struct GBSerializedState* state = buffer; + + gb->timing.root = NULL; + gb->model = state->model; + + gb->cpu->pc = GB_BASE_HRAM; + gb->cpu->memory.setActiveRegion(gb->cpu, gb->cpu->pc); + + GBVideoDeserialize(&gb->video, state); + GBIODeserialize(gb, state); + + // Make sure CPU loop never spins + GBHalt(gb->cpu); + gb->memory.ie = 0; + gb->memory.ime = false; + + return true; +} + static bool _returnTrue(struct VFile* vf) { UNUSED(vf); return true;

@@ -826,6 +838,7 @@ core->init = _GBVLPInit;

core->deinit = _GBVLPDeinit; core->reset = _GBVLPReset; core->loadROM = _GBVLPLoadROM; + core->loadState = _GBVLPLoadState; core->isROM = _returnTrue; return core; }
M src/gba/core.csrc/gba/core.c

@@ -772,11 +772,6 @@ if (!mVideoLoggerRendererRun(gbacore->proxyRenderer.logger, true)) {

GBAVideoProxyRendererUnshim(&gba->video, &gbacore->proxyRenderer); mVideoLogContextRewind(gbacore->logContext, core); GBAVideoProxyRendererShim(&gba->video, &gbacore->proxyRenderer); - - // Make sure CPU loop never spins - GBAHalt(gba); - gba->cpu->memory.store16(gba->cpu, BASE_IO | REG_IME, 0, NULL); - gba->cpu->memory.store16(gba->cpu, BASE_IO | REG_IE, 0, NULL); } }

@@ -816,11 +811,6 @@

ARMReset(core->cpu); mVideoLogContextRewind(gbacore->logContext, core); GBAVideoProxyRendererShim(&gba->video, &gbacore->proxyRenderer); - - // Make sure CPU loop never spins - GBAHalt(gba); - gba->cpu->memory.store16(gba->cpu, BASE_IO | REG_IME, 0, NULL); - gba->cpu->memory.store16(gba->cpu, BASE_IO | REG_IE, 0, NULL); } static bool _GBAVLPLoadROM(struct mCore* core, struct VFile* vf) {

@@ -835,6 +825,23 @@ mVideoLoggerAttachChannel(gbacore->proxyRenderer.logger, gbacore->logContext, 0);

return true; } +static bool _GBAVLPLoadState(struct mCore* core, const void* state) { + struct GBA* gba = (struct GBA*) core->board; + + gba->timing.root = NULL; + gba->cpu->gprs[ARM_PC] = BASE_WORKING_RAM; + gba->cpu->memory.setActiveRegion(gba->cpu, gba->cpu->gprs[ARM_PC]); + + // Make sure CPU loop never spins + GBAHalt(gba); + gba->cpu->memory.store16(gba->cpu, BASE_IO | REG_IME, 0, NULL); + gba->cpu->memory.store16(gba->cpu, BASE_IO | REG_IE, 0, NULL); + GBAVideoDeserialize(&gba->video, state); + GBAIODeserialize(gba, state); + + return true; +} + static bool _returnTrue(struct VFile* vf) { UNUSED(vf); return true;

@@ -846,6 +853,7 @@ core->init = _GBAVLPInit;

core->deinit = _GBAVLPDeinit; core->reset = _GBAVLPReset; core->loadROM = _GBAVLPLoadROM; + core->loadState = _GBAVLPLoadState; core->isROM = _returnTrue; return core; }