Skip to content

Commit 2b77841

Browse files
committed
GB: Add interrupt function for early exit
1 parent 2c44767 commit 2b77841

File tree

6 files changed

+12
-5
lines changed

6 files changed

+12
-5
lines changed

include/mgba/internal/gb/gb.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ void GBTestKeypadIRQ(struct GB* gb);
197197
void GBFrameStarted(struct GB* gb);
198198
void GBFrameEnded(struct GB* gb);
199199

200+
void GBInterrupt(struct GB* gb);
201+
200202
CXX_GUARD_END
201203

202204
#endif

src/gb/audio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ static void _sample(struct mTiming* timing, void* user, uint32_t cyclesLate) {
840840
}
841841
if (!mCoreSyncProduceAudio(audio->p->sync, &audio->buffer)) {
842842
// Interrupted
843-
audio->p->earlyExit = true;
843+
GBInterrupt(audio->p);
844844
}
845845
mTimingSchedule(timing, &audio->sampleEvent, audio->sampleInterval * audio->timingFactor - cyclesLate);
846846
}

src/gb/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1431,7 +1431,7 @@ static void _GBVLPStartFrameCallback(void *context) {
14311431
GBVideoProxyRendererUnshim(&gb->video, &gbcore->proxyRenderer);
14321432
mVideoLogContextRewind(gbcore->logContext, core);
14331433
GBVideoProxyRendererShim(&gb->video, &gbcore->proxyRenderer);
1434-
gb->earlyExit = true;
1434+
GBInterrupt(gb);
14351435
}
14361436
}
14371437

src/gb/gb.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ void GBProcessEvents(struct SM83Core* cpu) {
976976
gb->timing.globalCycles += nextEvent;
977977
#endif
978978
nextEvent = mTimingTick(&gb->timing, nextEvent);
979-
} while (gb->cpuBlocked);
979+
} while (gb->cpuBlocked && !gb->earlyExit);
980980
// This loop cannot early exit until the SM83 run loop properly handles mid-M-cycle-exits
981981
cpu->nextEvent = nextEvent;
982982

@@ -1219,6 +1219,11 @@ void GBFrameEnded(struct GB* gb) {
12191219
}
12201220
}
12211221

1222+
void GBInterrupt(struct GB* gb) {
1223+
gb->earlyExit = true;
1224+
mTimingInterrupt(&gb->timing);
1225+
}
1226+
12221227
enum GBModel GBNameToModel(const char* model) {
12231228
if (strcasecmp(model, "DMG") == 0 || strcasecmp(model, "GB") == 0) {
12241229
return GB_MODEL_DMG;

src/gb/sio/lockstep.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ static void _GBSIOLockstepNodeProcessEvents(struct mTiming* timing, void* user,
237237
mTimingDeschedule(timing, &node->event);
238238
mTimingSchedule(timing, &node->event, cycles);
239239
} else {
240-
node->d.p->p->earlyExit = true;
240+
GBInterrupt(node->d.p->p);
241241
mTimingSchedule(timing, &node->event, cyclesLate + 1);
242242
}
243243
}

src/gb/video.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ void _updateFrameCount(struct mTiming* timing, void* context, uint32_t cyclesLat
686686
GBFrameEnded(video->p);
687687
mCoreSyncPostFrame(video->p->sync);
688688
++video->frameCounter;
689-
video->p->earlyExit = true;
689+
GBInterrupt(video->p);
690690

691691
GBFrameStarted(video->p);
692692
}

0 commit comments

Comments
 (0)