Core: Add shutdown callback

This commit is contained in:
Vicki Pfau 2020-09-09 22:48:07 -07:00
parent ad7146a801
commit a8999958da
4 changed files with 17 additions and 1 deletions

View File

@ -71,6 +71,8 @@ Other fixes:
- 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

View File

@ -107,6 +107,7 @@ struct mCoreCallbacks {
void (*videoFrameEnded)(void* context);
void (*coreCrashed)(void* context);
void (*sleep)(void* context);
void (*shutdown)(void* context);
void (*keysRead)(void* context);
void (*savedataUpdated)(void* context);
};

View File

@ -139,6 +139,14 @@ void _coreSleep(void* context) {
}
}
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 @@ static THREAD_ENTRY _mCoreThreadRun(void* context) {
.videoFrameEnded = _frameEnded,
.coreCrashed = _crashed,
.sleep = _coreSleep,
.shutdown = _coreShutdown,
.context = threadContext
};
core->addCoreCallbacks(core, &callbacks);

View File

@ -525,11 +525,15 @@ void GBAHalt(struct GBA* gba) {
}
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;