diff --git a/CHANGES b/CHANGES index 52b42650c..eb0a4e69d 100644 --- a/CHANGES +++ b/CHANGES @@ -26,6 +26,7 @@ Misc: - LR35902: Support PC-relative opcode decoding - Qt: Improve camera initialization - Qt: Support switching webcams + - Core: Add keysRead callback 0.7.1: (2019-02-24) Bugfixes: diff --git a/include/mgba/core/interface.h b/include/mgba/core/interface.h index 0581c0bf2..2e9ff63a7 100644 --- a/include/mgba/core/interface.h +++ b/include/mgba/core/interface.h @@ -86,6 +86,7 @@ struct mCoreCallbacks { void (*videoFrameEnded)(void* context); void (*coreCrashed)(void* context); void (*sleep)(void* context); + void (*keysRead)(void* context); }; DECLARE_VECTOR(mCoreCallbacksList, struct mCoreCallbacks); diff --git a/src/gb/io.c b/src/gb/io.c index 84b3a35bc..beecce12a 100644 --- a/src/gb/io.c +++ b/src/gb/io.c @@ -576,6 +576,15 @@ static uint8_t _readKeysFiltered(struct GB* gb) { 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; diff --git a/src/gba/io.c b/src/gba/io.c index 68c77c8d5..2946e6ab7 100644 --- a/src/gba/io.c +++ b/src/gba/io.c @@ -725,6 +725,15 @@ uint16_t GBAIORead(struct GBA* gba, uint32_t address) { 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 {