GB: Fix savestates being taken at non-CORE_FETCH times

This commit is contained in:
Jeffrey Pfau 2016-08-29 23:24:03 -07:00
parent 9464ec2afa
commit bdf647db42
2 changed files with 9 additions and 4 deletions

View File

@ -230,6 +230,10 @@ static bool _GBCoreLoadState(struct mCore* core, const void* state) {
} }
static bool _GBCoreSaveState(struct mCore* core, void* 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); GBSerialize(core->board, state);
return true; return true;
} }

View File

@ -136,6 +136,9 @@ int32_t GBVideoProcessEvents(struct GBVideo* video, int32_t cycles) {
video->p->memory.io[REG_IF] |= (1 << GB_IRQ_LCDSTAT); video->p->memory.io[REG_IF] |= (1 << GB_IRQ_LCDSTAT);
} }
video->p->memory.io[REG_IF] |= (1 << GB_IRQ_VBLANK); video->p->memory.io[REG_IF] |= (1 << GB_IRQ_VBLANK);
struct mCoreThread* thread = mCoreThreadGet();
mCoreThreadFrameEnded(thread);
} }
if (GBRegisterSTATIsLYCIRQ(video->stat) && lyc == video->ly) { if (GBRegisterSTATIsLYCIRQ(video->stat) && lyc == video->ly) {
video->p->memory.io[REG_IF] |= (1 << GB_IRQ_LCDSTAT); video->p->memory.io[REG_IF] |= (1 << GB_IRQ_LCDSTAT);
@ -158,8 +161,6 @@ int32_t GBVideoProcessEvents(struct GBVideo* video, int32_t cycles) {
if (video->p->memory.mbcType == GB_MBC7 && video->p->memory.rotation && video->p->memory.rotation->sample) { 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); video->p->memory.rotation->sample(video->p->memory.rotation);
} }
struct mCoreThread* thread = mCoreThreadGet();
mCoreThreadFrameStarted(thread);
break; break;
} else if (video->ly == GB_VIDEO_VERTICAL_TOTAL_PIXELS) { } else if (video->ly == GB_VIDEO_VERTICAL_TOTAL_PIXELS) {
video->p->memory.io[REG_LY] = 0; video->p->memory.io[REG_LY] = 0;
@ -205,9 +206,9 @@ int32_t GBVideoProcessEvents(struct GBVideo* video, int32_t cycles) {
if (video->nextFrame <= 0) { if (video->nextFrame <= 0) {
if (video->p->cpu->executionState == LR35902_CORE_FETCH) { if (video->p->cpu->executionState == LR35902_CORE_FETCH) {
GBFrameEnded(video->p); GBFrameEnded(video->p);
struct mCoreThread* thread = mCoreThreadGet();
mCoreThreadFrameEnded(thread);
video->nextFrame = GB_VIDEO_TOTAL_LENGTH; video->nextFrame = GB_VIDEO_TOTAL_LENGTH;
struct mCoreThread* thread = mCoreThreadGet();
mCoreThreadFrameStarted(thread);
} else { } else {
video->nextFrame = 4 - ((video->p->cpu->executionState + 1) & 3); video->nextFrame = 4 - ((video->p->cpu->executionState + 1) & 3);
if (video->nextFrame < video->nextEvent) { if (video->nextFrame < video->nextEvent) {