From 346f44a7dadfcfcea7e67210f818cc3b0c2da024 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Wed, 16 Sep 2015 03:29:38 +0200 Subject: [PATCH] (MFI) Start adding own button state --- input/drivers/cocoa_input.c | 32 ++++++++++++---- input/drivers/cocoa_input.h | 1 + input/drivers_hid/btstack_hid.c | 6 ++- input/drivers_hid/mfi_hid.m | 65 ++++++++++++++++++--------------- 4 files changed, 65 insertions(+), 39 deletions(-) diff --git a/input/drivers/cocoa_input.c b/input/drivers/cocoa_input.c index cb7ff9ab0e..fedf28fd25 100644 --- a/input/drivers/cocoa_input.c +++ b/input/drivers/cocoa_input.c @@ -173,9 +173,22 @@ int32_t cocoa_input_find_any_key(void) return 0; } +static int cocoa_input_find_any_button_ret(unsigned buttons) +{ + unsigned i; + if (port == 0 && apple->icade_enabled) + BIT32_SET(buttons, apple->icade_buttons); + + if (buttons) + for (i = 0; i < 32; i++) + if (buttons & (1 << i)) + return i; + return -1; +} + int32_t cocoa_input_find_any_button(uint32_t port) { - unsigned i, buttons = 0; + int ret; driver_t *driver = driver_get_ptr(); cocoa_input_data_t *apple = (cocoa_input_data_t*)driver->input_data; @@ -185,14 +198,17 @@ int32_t cocoa_input_find_any_button(uint32_t port) if (apple->joypad) apple->joypad->poll(); - buttons = apple->buttons[port]; - if (port == 0 && apple->icade_enabled) - BIT32_SET(buttons, apple->icade_buttons); + ret = cocoa_input_find_any_button_ret(apple->buttons[port]); - if (buttons) - for (i = 0; i < 32; i++) - if (buttons & (1 << i)) - return i; + if (ret != -1) + return ret; + +#ifdef HAVE_MFI + ret = cocoa_input_find_any_button_ret(apple->mfi_buttons[port]); + + if (ret != -1) + return ret; +#endif return -1; } diff --git a/input/drivers/cocoa_input.h b/input/drivers/cocoa_input.h index e64f9b0fa7..8a3009a671 100644 --- a/input/drivers/cocoa_input.h +++ b/input/drivers/cocoa_input.h @@ -51,6 +51,7 @@ typedef struct uint32_t key_state[MAX_KEYS]; uint32_t buttons[MAX_USERS]; + uint32_t mfi_buttons[MAX_USERS]; int16_t axes[MAX_USERS][4]; int8_t hats[NUM_HATS][2]; diff --git a/input/drivers_hid/btstack_hid.c b/input/drivers_hid/btstack_hid.c index bc84fdf20f..8306769d33 100644 --- a/input/drivers_hid/btstack_hid.c +++ b/input/drivers_hid/btstack_hid.c @@ -775,7 +775,11 @@ static bool btstack_hid_joypad_button(void *data, unsigned port, uint16_t joykey /* Check the button. */ if ((port < MAX_USERS) && (joykey < 32)) - return ((buttons & (1 << joykey)) != 0); + return ((buttons & (1 << joykey)) != 0) +#ifdef HAVE_MFI + || ((apple->mfi_buttons[port] & (1 << joykey)) != 0) +#endif + ; return false; } diff --git a/input/drivers_hid/mfi_hid.m b/input/drivers_hid/mfi_hid.m index 3dd7cef91f..65f46bff2c 100644 --- a/input/drivers_hid/mfi_hid.m +++ b/input/drivers_hid/mfi_hid.m @@ -39,36 +39,40 @@ static bool apple_gamecontroller_available(void) static void apple_gamecontroller_poll(GCController *controller) { - uint32_t slot, pause; - driver_t *driver = driver_get_ptr(); + uint32_t i, slot, pause; + uint32_t *buttons; + driver_t *driver = driver_get_ptr(); cocoa_input_data_t *apple = (cocoa_input_data_t*)driver->input_data; - if (!apple || !controller || controller.playerIndex == MAX_USERS) + if (!apple || !controller) return; slot = (uint32_t)controller.playerIndex; /* retain the start (pause) value */ - pause = apple->buttons[slot] & (1 << RETRO_DEVICE_ID_JOYPAD_START); + pause = apple->mfi_buttons[slot] & (1 << RETRO_DEVICE_ID_JOYPAD_START); - apple->buttons[slot] = 0; + apple->mfi_buttons[slot] = 0; memset(apple->axes[slot], 0, sizeof(apple->axes[0])); - apple->buttons[slot] |= pause; + apple->mfi_buttons[slot] |= pause; + + buttons = &apple->mfi_buttons[slot]; if (controller.extendedGamepad) { GCExtendedGamepad *gp = (GCExtendedGamepad *)controller.extendedGamepad; - apple->buttons[slot] |= gp.dpad.up.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_UP) : 0; - apple->buttons[slot] |= gp.dpad.down.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0; - apple->buttons[slot] |= gp.dpad.left.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0; - apple->buttons[slot] |= gp.dpad.right.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0; - apple->buttons[slot] |= gp.buttonA.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_B) : 0; - apple->buttons[slot] |= gp.buttonB.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_A) : 0; - apple->buttons[slot] |= gp.buttonX.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_Y) : 0; - apple->buttons[slot] |= gp.buttonY.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_X) : 0; - apple->buttons[slot] |= gp.leftShoulder.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_L) : 0; - apple->buttons[slot] |= gp.rightShoulder.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_R) : 0; - apple->buttons[slot] |= gp.leftTrigger.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_L2) : 0; - apple->buttons[slot] |= gp.rightTrigger.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_R2) : 0; + + *buttons |= gp.dpad.up.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_UP) : 0; + *buttons |= gp.dpad.down.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0; + *buttons |= gp.dpad.left.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0; + *buttons |= gp.dpad.right.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0; + *buttons |= gp.buttonA.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_B) : 0; + *buttons |= gp.buttonB.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_A) : 0; + *buttons |= gp.buttonX.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_Y) : 0; + *buttons |= gp.buttonY.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_X) : 0; + *buttons |= gp.leftShoulder.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_L) : 0; + *buttons |= gp.rightShoulder.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_R) : 0; + *buttons |= gp.leftTrigger.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_L2) : 0; + *buttons |= gp.rightTrigger.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_R2) : 0; apple->axes[slot][0] = gp.leftThumbstick.xAxis.value * 32767.0f; apple->axes[slot][1] = gp.leftThumbstick.yAxis.value * 32767.0f; apple->axes[slot][2] = gp.rightThumbstick.xAxis.value * 32767.0f; @@ -77,16 +81,17 @@ static void apple_gamecontroller_poll(GCController *controller) else if (controller.gamepad) { GCGamepad *gp = (GCGamepad *)controller.gamepad; - apple->buttons[slot] |= gp.dpad.up.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_UP) : 0; - apple->buttons[slot] |= gp.dpad.down.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0; - apple->buttons[slot] |= gp.dpad.left.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0; - apple->buttons[slot] |= gp.dpad.right.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0; - apple->buttons[slot] |= gp.buttonA.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_B) : 0; - apple->buttons[slot] |= gp.buttonB.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_A) : 0; - apple->buttons[slot] |= gp.buttonX.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_Y) : 0; - apple->buttons[slot] |= gp.buttonY.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_X) : 0; - apple->buttons[slot] |= gp.leftShoulder.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_L) : 0; - apple->buttons[slot] |= gp.rightShoulder.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_R) : 0; + + *buttons |= gp.dpad.up.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_UP) : 0; + *buttons |= gp.dpad.down.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0; + *buttons |= gp.dpad.left.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0; + *buttons |= gp.dpad.right.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0; + *buttons |= gp.buttonA.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_B) : 0; + *buttons |= gp.buttonB.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_A) : 0; + *buttons |= gp.buttonX.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_Y) : 0; + *buttons |= gp.buttonY.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_X) : 0; + *buttons |= gp.leftShoulder.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_L) : 0; + *buttons |= gp.rightShoulder.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_R) : 0; } } @@ -111,10 +116,10 @@ static void apple_gamecontroller_register(GCGamepad *gamepad) uint32_t slot = (uint32_t)controller.playerIndex; - apple->buttons[slot] |= (1 << RETRO_DEVICE_ID_JOYPAD_START); + apple->mfi_buttons[slot] |= (1 << RETRO_DEVICE_ID_JOYPAD_START); dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - apple->buttons[slot] &= ~(1 << RETRO_DEVICE_ID_JOYPAD_START); + apple->mfi_buttons[slot] &= ~(1 << RETRO_DEVICE_ID_JOYPAD_START); }); };