Core: Add shutdown callback
Vicki Pfau vi@endrift.com
Wed, 09 Sep 2020 22:48:07 -0700
4 files changed,
17 insertions(+),
1 deletions(-)
M
CHANGES
→
CHANGES
@@ -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.h
→
include/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.c
→
src/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.c
→
src/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;