diff --git a/src/gb/core.c b/src/gb/core.c index 756c9e19d..6707b8416 100644 --- a/src/gb/core.c +++ b/src/gb/core.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -752,11 +753,6 @@ static void _GBVLPStartFrameCallback(void *context) { 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 @@ static void _GBVLPReset(struct mCore* core) { 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 @@ static bool _GBVLPLoadROM(struct mCore* core, struct VFile* vf) { 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 @@ struct mCore* GBVideoLogPlayerCreate(void) { core->deinit = _GBVLPDeinit; core->reset = _GBVLPReset; core->loadROM = _GBVLPLoadROM; + core->loadState = _GBVLPLoadState; core->isROM = _returnTrue; return core; } diff --git a/src/gba/core.c b/src/gba/core.c index ea09e4d85..185598e53 100644 --- a/src/gba/core.c +++ b/src/gba/core.c @@ -772,11 +772,6 @@ static void _GBAVLPStartFrameCallback(void *context) { 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 @@ static void _GBAVLPReset(struct mCore* core) { 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 @@ static bool _GBAVLPLoadROM(struct mCore* core, struct VFile* vf) { 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 @@ struct mCore* GBAVideoLogPlayerCreate(void) { core->deinit = _GBAVLPDeinit; core->reset = _GBAVLPReset; core->loadROM = _GBAVLPLoadROM; + core->loadState = _GBAVLPLoadState; core->isROM = _returnTrue; return core; }