Skip to content

Commit 2c44767

Browse files
committed
GBA: Add interrupt function for early exit
1 parent e6dd463 commit 2c44767

File tree

6 files changed

+11
-7
lines changed

6 files changed

+11
-7
lines changed

include/mgba/internal/gba/gba.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ void GBAHalt(struct GBA* gba);
154154
void GBAStop(struct GBA* gba);
155155
void GBADebug(struct GBA* gba, uint16_t value);
156156

157+
void GBAInterrupt(struct GBA* gba);
158+
157159
#ifdef USE_ELF
158160
struct ELF;
159161

src/gba/audio.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,9 +424,8 @@ static void _sample(struct mTiming* timing, void* user, uint32_t cyclesLate) {
424424
}
425425
if (!mCoreSyncProduceAudio(audio->p->sync, &audio->psg.buffer)) {
426426
// Interrupted
427-
audio->p->earlyExit = true;
427+
GBAInterrupt(audio->p);
428428
}
429-
430429
mTimingSchedule(timing, &audio->sampleEvent, SAMPLE_INTERVAL - cyclesLate);
431430
}
432431

src/gba/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1722,7 +1722,7 @@ static void _GBAVLPStartFrameCallback(void *context) {
17221722
GBAVideoProxyRendererUnshim(&gba->video, &gbacore->vlProxy);
17231723
mVideoLogContextRewind(gbacore->logContext, core);
17241724
GBAVideoProxyRendererShim(&gba->video, &gbacore->vlProxy);
1725-
gba->earlyExit = true;
1725+
GBAInterrupt(gba);
17261726
}
17271727
}
17281728

src/gba/gba.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,6 @@ static void GBAProcessEvents(struct ARMCore* cpu) {
352352
if (!gba->memory.io[GBA_REG(IME)] || !gba->memory.io[GBA_REG(IE)]) {
353353
break;
354354
}
355-
} else {
356-
mASSERT_DEBUG_LOG(GBA, nextEvent >= 0, "Negative cycles will pass: %i", nextEvent);
357355
}
358356
if (gba->earlyExit) {
359357
break;
@@ -628,6 +626,11 @@ void GBADebug(struct GBA* gba, uint16_t flags) {
628626
gba->debugFlags = GBADebugFlagsClearSend(gba->debugFlags);
629627
}
630628

629+
void GBAInterrupt(struct GBA* gba) {
630+
gba->earlyExit = true;
631+
mTimingInterrupt(&gba->timing);
632+
}
633+
631634
#ifdef USE_ELF
632635
bool GBAVerifyELFEntry(struct ELF* elf, uint32_t target) {
633636
if (ELFEntry(elf) == target) {

src/gba/sio/lockstep.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ void GBASIOLockstepPlayerSleep(struct GBASIOLockstepPlayer* player) {
10521052
player->asleep = true;
10531053
player->driver->user->sleep(player->driver->user);
10541054
player->driver->d.p->p->cpu->nextEvent = 0;
1055-
player->driver->d.p->p->earlyExit = true;
1055+
GBAInterrupt(player->driver->d.p->p);
10561056
}
10571057

10581058
size_t GBASIOLockstepCoordinatorAttached(struct GBASIOLockstepCoordinator* coordinator) {

src/gba/video.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ void _startHdraw(struct mTiming* timing, void* context, uint32_t cyclesLate) {
187187
video->frameskipCounter = video->frameskip;
188188
}
189189
++video->frameCounter;
190-
video->p->earlyExit = true;
190+
GBAInterrupt(video->p);
191191
break;
192192
case VIDEO_VERTICAL_TOTAL_PIXELS - 1:
193193
video->p->memory.io[GBA_REG(DISPSTAT)] = GBARegisterDISPSTATClearInVblank(dispstat);

0 commit comments

Comments
 (0)