Core: Add keysRead callback
Vicki Pfau vi@endrift.com
Fri, 08 Mar 2019 09:55:51 -0800
4 files changed,
20 insertions(+),
0 deletions(-)
M
include/mgba/core/interface.h
→
include/mgba/core/interface.h
@@ -86,6 +86,7 @@ void (*videoFrameStarted)(void* context);
void (*videoFrameEnded)(void* context); void (*coreCrashed)(void* context); void (*sleep)(void* context); + void (*keysRead)(void* context); }; DECLARE_VECTOR(mCoreCallbacksList, struct mCoreCallbacks);
M
src/gb/io.c
→
src/gb/io.c
@@ -576,6 +576,15 @@
uint8_t GBIORead(struct GB* gb, unsigned address) { switch (address) { case REG_JOYP: + { + size_t c; + for (c = 0; c < mCoreCallbacksListSize(&gb->coreCallbacks); ++c) { + struct mCoreCallbacks* callbacks = mCoreCallbacksListGetPointer(&gb->coreCallbacks, c); + if (callbacks->keysRead) { + callbacks->keysRead(callbacks->context); + } + } + } return _readKeysFiltered(gb); case REG_IE: return gb->memory.ie;
M
src/gba/io.c
→
src/gba/io.c
@@ -725,6 +725,15 @@ GBATimerUpdateRegister(gba, 3, 4);
break; case REG_KEYINPUT: + { + size_t c; + for (c = 0; c < mCoreCallbacksListSize(&gba->coreCallbacks); ++c) { + struct mCoreCallbacks* callbacks = mCoreCallbacksListGetPointer(&gba->coreCallbacks, c); + if (callbacks->keysRead) { + callbacks->keysRead(callbacks->context); + } + } + } if (gba->rr && gba->rr->isPlaying(gba->rr)) { return 0x3FF ^ gba->rr->queryInput(gba->rr); } else {