GB: Fix savestates being taken at non-CORE_FETCH times
Jeffrey Pfau jeffrey@endrift.com
Mon, 29 Aug 2016 23:24:03 -0700
2 files changed,
9 insertions(+),
4 deletions(-)
M
src/gb/core.c
→
src/gb/core.c
@@ -230,6 +230,10 @@ return GBDeserialize(core->board, state);
} static bool _GBCoreSaveState(struct mCore* core, void* state) { + struct LR35902Core* cpu = core->cpu; + while (cpu->executionState != LR35902_CORE_FETCH) { + LR35902Tick(cpu); + } GBSerialize(core->board, state); return true; }
M
src/gb/video.c
→
src/gb/video.c
@@ -136,6 +136,9 @@ if (GBRegisterSTATIsVblankIRQ(video->stat) || GBRegisterSTATIsOAMIRQ(video->stat)) {
video->p->memory.io[REG_IF] |= (1 << GB_IRQ_LCDSTAT); } video->p->memory.io[REG_IF] |= (1 << GB_IRQ_VBLANK); + + struct mCoreThread* thread = mCoreThreadGet(); + mCoreThreadFrameEnded(thread); } if (GBRegisterSTATIsLYCIRQ(video->stat) && lyc == video->ly) { video->p->memory.io[REG_IF] |= (1 << GB_IRQ_LCDSTAT);@@ -158,8 +161,6 @@ video->renderer->finishFrame(video->renderer);
if (video->p->memory.mbcType == GB_MBC7 && video->p->memory.rotation && video->p->memory.rotation->sample) { video->p->memory.rotation->sample(video->p->memory.rotation); } - struct mCoreThread* thread = mCoreThreadGet(); - mCoreThreadFrameStarted(thread); break; } else if (video->ly == GB_VIDEO_VERTICAL_TOTAL_PIXELS) { video->p->memory.io[REG_LY] = 0;@@ -205,9 +206,9 @@ }
if (video->nextFrame <= 0) { if (video->p->cpu->executionState == LR35902_CORE_FETCH) { GBFrameEnded(video->p); - struct mCoreThread* thread = mCoreThreadGet(); - mCoreThreadFrameEnded(thread); video->nextFrame = GB_VIDEO_TOTAL_LENGTH; + struct mCoreThread* thread = mCoreThreadGet(); + mCoreThreadFrameStarted(thread); } else { video->nextFrame = 4 - ((video->p->cpu->executionState + 1) & 3); if (video->nextFrame < video->nextEvent) {