diff --git a/include/mgba/core/core.h b/include/mgba/core/core.h index 82ee3d6d6..e382a7beb 100644 --- a/include/mgba/core/core.h +++ b/include/mgba/core/core.h @@ -110,8 +110,7 @@ struct mCore { void (*getGameTitle)(const struct mCore*, char* title); void (*getGameCode)(const struct mCore*, char* title); - void (*setRotation)(struct mCore*, struct mRotationSource*); - void (*setRumble)(struct mCore*, struct mRumble*); + void (*setPeripheral)(struct mCore*, int type, void*); uint32_t (*busRead8)(struct mCore*, uint32_t address); uint32_t (*busRead16)(struct mCore*, uint32_t address); diff --git a/include/mgba/core/interface.h b/include/mgba/core/interface.h index 3a702c1f1..acaa930cd 100644 --- a/include/mgba/core/interface.h +++ b/include/mgba/core/interface.h @@ -54,6 +54,12 @@ struct mKeyCallback { uint16_t (*readKeys)(struct mKeyCallback*); }; +enum mPeripheral { + mPERIPH_ROTATION = 1, + mPERIPH_RUMBLE, + mPERIPH_CUSTOM = 0x1000 +}; + struct mRotationSource { void (*sample)(struct mRotationSource*); diff --git a/src/gb/core.c b/src/gb/core.c index 8263696f1..c3eb1b22a 100644 --- a/src/gb/core.c +++ b/src/gb/core.c @@ -408,14 +408,18 @@ static void _GBCoreGetGameCode(const struct mCore* core, char* title) { GBGetGameCode(core->board, title); } -static void _GBCoreSetRotation(struct mCore* core, struct mRotationSource* rotation) { +static void _GBCoreSetPeripheral(struct mCore* core, int type, void* periph) { struct GB* gb = core->board; - gb->memory.rotation = rotation; -} - -static void _GBCoreSetRumble(struct mCore* core, struct mRumble* rumble) { - struct GB* gb = core->board; - gb->memory.rumble = rumble; + switch (type) { + case mPERIPH_ROTATION: + gb->memory.rotation = periph; + break; + case mPERIPH_RUMBLE: + gb->memory.rumble = periph; + break; + default: + return; + } } static uint32_t _GBCoreBusRead8(struct mCore* core, uint32_t address) { @@ -620,8 +624,7 @@ struct mCore* GBCoreCreate(void) { core->frequency = _GBCoreFrequency; core->getGameTitle = _GBCoreGetGameTitle; core->getGameCode = _GBCoreGetGameCode; - core->setRotation = _GBCoreSetRotation; - core->setRumble = _GBCoreSetRumble; + core->setPeripheral = _GBCoreSetPeripheral; core->busRead8 = _GBCoreBusRead8; core->busRead16 = _GBCoreBusRead16; core->busRead32 = _GBCoreBusRead32; diff --git a/src/gba/core.c b/src/gba/core.c index 2ed68e435..2d653deca 100644 --- a/src/gba/core.c +++ b/src/gba/core.c @@ -405,14 +405,18 @@ static void _GBACoreGetGameCode(const struct mCore* core, char* title) { GBAGetGameCode(core->board, title); } -static void _GBACoreSetRotation(struct mCore* core, struct mRotationSource* rotation) { +static void _GBACoreSetPeripheral(struct mCore* core, int type, void* periph) { struct GBA* gba = core->board; - gba->rotationSource = rotation; -} - -static void _GBACoreSetRumble(struct mCore* core, struct mRumble* rumble) { - struct GBA* gba = core->board; - gba->rumble = rumble; + switch (type) { + case mPERIPH_ROTATION: + gba->rotationSource = periph; + break; + case mPERIPH_RUMBLE: + gba->rumble = periph; + break; + default: + return; + } } static uint32_t _GBACoreBusRead8(struct mCore* core, uint32_t address) { @@ -619,8 +623,7 @@ struct mCore* GBACoreCreate(void) { core->frequency = _GBACoreFrequency; core->getGameTitle = _GBACoreGetGameTitle; core->getGameCode = _GBACoreGetGameCode; - core->setRotation = _GBACoreSetRotation; - core->setRumble = _GBACoreSetRumble; + core->setPeripheral = _GBACoreSetPeripheral; core->busRead8 = _GBACoreBusRead8; core->busRead16 = _GBACoreBusRead16; core->busRead32 = _GBACoreBusRead32; diff --git a/src/platform/3ds/main.c b/src/platform/3ds/main.c index 0d17ba9fa..da0954a21 100644 --- a/src/platform/3ds/main.c +++ b/src/platform/3ds/main.c @@ -242,7 +242,7 @@ static void _setup(struct mGUIRunner* runner) { mCoreLoadForeignConfig(runner->core, &runner->config); } - runner->core->setRotation(runner->core, &rotation.d); + runner->core->setPeripheral(runner->core, mPERIPH_ROTATION, &rotation.d); if (hasSound != NO_SOUND) { runner->core->setAVStream(runner->core, &stream); } diff --git a/src/platform/libretro/libretro.c b/src/platform/libretro/libretro.c index 95f3f8e24..e640a91f0 100644 --- a/src/platform/libretro/libretro.c +++ b/src/platform/libretro/libretro.c @@ -398,7 +398,7 @@ bool retro_load_game(const struct retro_game_info* game) { blip_set_rates(core->getAudioChannel(core, 0), core->frequency(core), 32768); blip_set_rates(core->getAudioChannel(core, 1), core->frequency(core), 32768); - core->setRumble(core, &rumble); + core->setPeripheral(core, mPERIPH_RUMBLE, &rumble); savedata = anonymousMemoryMap(SIZE_CART_FLASH1M); struct VFile* save = VFileFromMemory(savedata, SIZE_CART_FLASH1M); diff --git a/src/platform/psp2/psp2-context.c b/src/platform/psp2/psp2-context.c index f58ee6a1d..b3aba3593 100644 --- a/src/platform/psp2/psp2-context.c +++ b/src/platform/psp2/psp2-context.c @@ -203,11 +203,11 @@ void mPSP2Setup(struct mGUIRunner* runner) { rotation.d.readTiltX = _readTiltX; rotation.d.readTiltY = _readTiltY; rotation.d.readGyroZ = _readGyroZ; - runner->core->setRotation(runner->core, &rotation.d); + runner->core->setPeripheral(runner->core, mPERIPH_ROTATION, &rotation.d); rumble.d.setRumble = _setRumble; CircleBufferInit(&rumble.history, RUMBLE_PWM); - runner->core->setRumble(runner->core, &rumble.d); + runner->core->setPeripheral(runner->core, mPERIPH_RUMBLE, &rumble.d); frameLimiter = true; backdrop = vita2d_load_PNG_buffer(_binary_backdrop_png_start); diff --git a/src/platform/qt/GameController.cpp b/src/platform/qt/GameController.cpp index 72f7b75b1..7d8484b84 100644 --- a/src/platform/qt/GameController.cpp +++ b/src/platform/qt/GameController.cpp @@ -87,8 +87,8 @@ GameController::GameController(QObject* parent) m_threadContext.startCallback = [](mCoreThread* context) { GameController* controller = static_cast(context->userData); - context->core->setRotation(context->core, controller->m_inputController->rotationSource()); - context->core->setRumble(context->core, controller->m_inputController->rumble()); + context->core->setPeripheral(context->core, mPERIPH_ROTATION, controller->m_inputController->rotationSource()); + context->core->setPeripheral(context->core, mPERIPH_RUMBLE, controller->m_inputController->rumble()); #ifdef M_CORE_GBA GBA* gba = static_cast(context->core->board); diff --git a/src/platform/sdl/main.c b/src/platform/sdl/main.c index 33aaf0b01..f5ec5fe53 100644 --- a/src/platform/sdl/main.c +++ b/src/platform/sdl/main.c @@ -130,7 +130,7 @@ int main(int argc, char** argv) { mSDLPlayerLoadConfig(&renderer.player, mCoreConfigGetInput(&renderer.core->config)); #if SDL_VERSION_ATLEAST(2, 0, 0) - renderer.core->setRumble(renderer.core, &renderer.player.rumble.d); + renderer.core->setPeripheral(renderer.core, mPERIPH_RUMBLE, &renderer.player.rumble.d); #endif int ret; diff --git a/src/platform/wii/main.c b/src/platform/wii/main.c index 29096042e..f7561f018 100644 --- a/src/platform/wii/main.c +++ b/src/platform/wii/main.c @@ -641,8 +641,8 @@ void _guiPrepare(void) { } void _setup(struct mGUIRunner* runner) { - runner->core->setRotation(runner->core, &rotation); - runner->core->setRumble(runner->core, &rumble); + runner->core->setPeripheral(runner->core, mPERIPH_ROTATION, &rotation); + runner->core->setPeripheral(runner->core, mPERIPH_RUMBLE, &rumble); _mapKey(&runner->core->inputMap, GCN1_INPUT, PAD_BUTTON_A, GBA_KEY_A); _mapKey(&runner->core->inputMap, GCN1_INPUT, PAD_BUTTON_B, GBA_KEY_B);