all repos — mgba @ a8999958dafb0486c4d5474ed13d21e36e17cc3c

mGBA Game Boy Advance Emulator

Core: Add shutdown callback
Vicki Pfau vi@endrift.com
Wed, 09 Sep 2020 22:48:07 -0700
commit

a8999958dafb0486c4d5474ed13d21e36e17cc3c

parent

ad7146a801324caee68c5bbef25ea448bc962fa1

4 files changed, 17 insertions(+), 1 deletions(-)

jump to
M CHANGESCHANGES

@@ -71,6 +71,8 @@ - SM83: Simplify register pair access on big endian

- VFS: Fix directory node listing on some filesystems Misc: - 3DS: Use "wide mode" where applicable for slightly better filtering + - Core: Add savedataUpdated callback + - Core: Add shutdown callback - GB: Allow pausing event loop while CPU is blocked - GBA: Allow pausing event loop while CPU is blocked - Debugger: Keep track of global cycle count
M include/mgba/core/interface.hinclude/mgba/core/interface.h

@@ -107,6 +107,7 @@ void (*videoFrameStarted)(void* context);

void (*videoFrameEnded)(void* context); void (*coreCrashed)(void* context); void (*sleep)(void* context); + void (*shutdown)(void* context); void (*keysRead)(void* context); void (*savedataUpdated)(void* context); };
M src/core/thread.csrc/core/thread.c

@@ -139,6 +139,14 @@ thread->sleepCallback(thread);

} } +void _coreShutdown(void* context) { + struct mCoreThread* thread = context; + if (!thread) { + return; + } + _changeState(thread->impl, THREAD_EXITING, true); +} + static THREAD_ENTRY _mCoreThreadRun(void* context) { struct mCoreThread* threadContext = context; #ifdef USE_PTHREADS

@@ -162,6 +170,7 @@ .videoFrameStarted = _frameStarted,

.videoFrameEnded = _frameEnded, .coreCrashed = _crashed, .sleep = _coreSleep, + .shutdown = _coreShutdown, .context = threadContext }; core->addCoreCallbacks(core, &callbacks);
M src/gba/gba.csrc/gba/gba.c

@@ -525,11 +525,15 @@ gba->cpu->halted = 1;

} void GBAStop(struct GBA* gba) { + int validIrqs = (1 << IRQ_GAMEPAK) | (1 << IRQ_KEYPAD) | (1 << IRQ_SIO); + int sleep = gba->memory.io[REG_IE >> 1] & validIrqs; size_t c; for (c = 0; c < mCoreCallbacksListSize(&gba->coreCallbacks); ++c) { struct mCoreCallbacks* callbacks = mCoreCallbacksListGetPointer(&gba->coreCallbacks, c); - if (callbacks->sleep) { + if (sleep && callbacks->sleep) { callbacks->sleep(callbacks->context); + } else if (callbacks->shutdown) { + callbacks->shutdown(callbacks->context); } } gba->cpu->nextEvent = gba->cpu->cycles;