From f137f680c3875ca971ad66fd25f4c43872900fe4 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Tue, 30 Sep 2014 15:03:22 +0200 Subject: [PATCH] (Apple) Refactor apple_input_data_t --- apple/common/apple_gamecontroller.m | 64 ++++++++++++++--------------- input/apple_input.c | 6 +-- input/apple_input.h | 9 +++- input/apple_joypad.c | 6 +-- input/apple_joypad_ps3.c | 4 +- input/apple_joypad_ps4.c | 4 +- input/apple_joypad_wii.c | 4 +- input/hid/apple_input_hid.c | 12 +++--- 8 files changed, 57 insertions(+), 52 deletions(-) diff --git a/apple/common/apple_gamecontroller.m b/apple/common/apple_gamecontroller.m index 740be9315d..34e65ec7d6 100644 --- a/apple/common/apple_gamecontroller.m +++ b/apple/common/apple_gamecontroller.m @@ -35,47 +35,47 @@ static void apple_gamecontroller_poll(GCController *controller) uint32_t slot = (uint32_t)controller.playerIndex; /* retain the start (pause) value */ - uint32_t pause = g_current_input_data.pad_buttons[slot] & (1 << RETRO_DEVICE_ID_JOYPAD_START); + uint32_t pause = g_current_input_data.buttons[slot] & (1 << RETRO_DEVICE_ID_JOYPAD_START); - g_current_input_data.pad_buttons[slot] = 0; - memset(g_current_input_data.pad_axis[slot], 0, sizeof(g_current_input_data.pad_axis[0])); + g_current_input_data.buttons[slot] = 0; + memset(g_current_input_data.axes[slot], 0, sizeof(g_current_input_data.axes[0])); - g_current_input_data.pad_buttons[slot] |= pause; + g_current_input_data.buttons[slot] |= pause; if (controller.extendedGamepad) { GCExtendedGamepad *gp = (GCExtendedGamepad *)controller.extendedGamepad; - g_current_input_data.pad_buttons[slot] |= gp.dpad.up.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_UP) : 0; - g_current_input_data.pad_buttons[slot] |= gp.dpad.down.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0; - g_current_input_data.pad_buttons[slot] |= gp.dpad.left.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0; - g_current_input_data.pad_buttons[slot] |= gp.dpad.right.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0; - g_current_input_data.pad_buttons[slot] |= gp.buttonA.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_B) : 0; - g_current_input_data.pad_buttons[slot] |= gp.buttonB.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_A) : 0; - g_current_input_data.pad_buttons[slot] |= gp.buttonX.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_Y) : 0; - g_current_input_data.pad_buttons[slot] |= gp.buttonY.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_X) : 0; - g_current_input_data.pad_buttons[slot] |= gp.leftShoulder.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_L) : 0; - g_current_input_data.pad_buttons[slot] |= gp.rightShoulder.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_R) : 0; + g_current_input_data.buttons[slot] |= gp.dpad.up.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_UP) : 0; + g_current_input_data.buttons[slot] |= gp.dpad.down.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0; + g_current_input_data.buttons[slot] |= gp.dpad.left.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0; + g_current_input_data.buttons[slot] |= gp.dpad.right.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0; + g_current_input_data.buttons[slot] |= gp.buttonA.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_B) : 0; + g_current_input_data.buttons[slot] |= gp.buttonB.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_A) : 0; + g_current_input_data.buttons[slot] |= gp.buttonX.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_Y) : 0; + g_current_input_data.buttons[slot] |= gp.buttonY.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_X) : 0; + g_current_input_data.buttons[slot] |= gp.leftShoulder.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_L) : 0; + g_current_input_data.buttons[slot] |= gp.rightShoulder.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_R) : 0; - g_current_input_data.pad_buttons[slot] |= gp.leftTrigger.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_L2) : 0; - g_current_input_data.pad_buttons[slot] |= gp.rightTrigger.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_R2) : 0; - g_current_input_data.pad_axis[slot][0] = gp.leftThumbstick.xAxis.value * 32767.0f; - g_current_input_data.pad_axis[slot][1] = gp.leftThumbstick.yAxis.value * 32767.0f; - g_current_input_data.pad_axis[slot][2] = gp.rightThumbstick.xAxis.value * 32767.0f; - g_current_input_data.pad_axis[slot][3] = gp.rightThumbstick.yAxis.value * 32767.0f; + g_current_input_data.buttons[slot] |= gp.leftTrigger.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_L2) : 0; + g_current_input_data.buttons[slot] |= gp.rightTrigger.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_R2) : 0; + g_current_input_data.axes[slot][0] = gp.leftThumbstick.xAxis.value * 32767.0f; + g_current_input_data.axes[slot][1] = gp.leftThumbstick.yAxis.value * 32767.0f; + g_current_input_data.axes[slot][2] = gp.rightThumbstick.xAxis.value * 32767.0f; + g_current_input_data.axes[slot][3] = gp.rightThumbstick.yAxis.value * 32767.0f; } else if (controller.gamepad) { GCGamepad *gp = (GCGamepad *)controller.gamepad; - g_current_input_data.pad_buttons[slot] |= gp.dpad.up.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_UP) : 0; - g_current_input_data.pad_buttons[slot] |= gp.dpad.down.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0; - g_current_input_data.pad_buttons[slot] |= gp.dpad.left.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0; - g_current_input_data.pad_buttons[slot] |= gp.dpad.right.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0; - g_current_input_data.pad_buttons[slot] |= gp.buttonA.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_B) : 0; - g_current_input_data.pad_buttons[slot] |= gp.buttonB.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_A) : 0; - g_current_input_data.pad_buttons[slot] |= gp.buttonX.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_Y) : 0; - g_current_input_data.pad_buttons[slot] |= gp.buttonY.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_X) : 0; - g_current_input_data.pad_buttons[slot] |= gp.leftShoulder.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_L) : 0; - g_current_input_data.pad_buttons[slot] |= gp.rightShoulder.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_R) : 0; + g_current_input_data.buttons[slot] |= gp.dpad.up.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_UP) : 0; + g_current_input_data.buttons[slot] |= gp.dpad.down.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0; + g_current_input_data.buttons[slot] |= gp.dpad.left.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0; + g_current_input_data.buttons[slot] |= gp.dpad.right.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0; + g_current_input_data.buttons[slot] |= gp.buttonA.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_B) : 0; + g_current_input_data.buttons[slot] |= gp.buttonB.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_A) : 0; + g_current_input_data.buttons[slot] |= gp.buttonX.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_Y) : 0; + g_current_input_data.buttons[slot] |= gp.buttonY.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_X) : 0; + g_current_input_data.buttons[slot] |= gp.leftShoulder.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_L) : 0; + g_current_input_data.buttons[slot] |= gp.rightShoulder.pressed ? (1 << RETRO_DEVICE_ID_JOYPAD_R) : 0; } } @@ -98,10 +98,10 @@ static void apple_gamecontroller_register(GCGamepad *gamepad) uint32_t slot = (uint32_t)controller.playerIndex; - g_current_input_data.pad_buttons[slot] |= (1 << RETRO_DEVICE_ID_JOYPAD_START); + g_current_input_data.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(), ^{ - g_current_input_data.pad_buttons[slot] &= ~(1 << RETRO_DEVICE_ID_JOYPAD_START); + g_current_input_data.buttons[slot] &= ~(1 << RETRO_DEVICE_ID_JOYPAD_START); }); }; diff --git a/input/apple_input.c b/input/apple_input.c index 84b9a018bf..755ae3ca8a 100644 --- a/input/apple_input.c +++ b/input/apple_input.c @@ -439,7 +439,7 @@ int32_t apple_input_find_any_button(uint32_t port) apple_gamecontroller_poll_all(); #endif - buttons = g_current_input_data.pad_buttons[port] | + buttons = g_current_input_data.buttons[port] | ((port == 0) ? apple_input_get_icade_buttons() : 0); if (buttons) @@ -458,7 +458,7 @@ int32_t apple_input_find_any_axis(uint32_t port) for (int i = 0; i < 4; i++) { - int16_t value = g_current_input_data.pad_axis[port][i]; + int16_t value = g_current_input_data.axes[port][i]; if (abs(value) > 0x4000) return (value < 0) ? -(i + 1) : i + 1; @@ -515,7 +515,7 @@ static void apple_input_poll(void *data) if (joypad) joypad->poll(); - g_current_input_data.pad_buttons[0] |= apple_input_get_icade_buttons(); + g_current_input_data.buttons[0] |= apple_input_get_icade_buttons(); g_current_input_data.mouse_delta[0] = 0; g_current_input_data.mouse_delta[1] = 0; diff --git a/input/apple_input.h b/input/apple_input.h index d20247e234..53178db349 100644 --- a/input/apple_input.h +++ b/input/apple_input.h @@ -23,6 +23,10 @@ #define MAX_TOUCHES 16 #define MAX_KEYS 256 +#ifndef NUM_HATS +#define NUM_HATS 4 +#endif + typedef struct { int16_t screen_x, screen_y; @@ -40,8 +44,9 @@ typedef struct uint32_t keys[MAX_KEYS]; - uint32_t pad_buttons[MAX_PLAYERS]; - int16_t pad_axis[MAX_PLAYERS][4]; + uint32_t buttons[MAX_PLAYERS]; + int16_t axes[MAX_PLAYERS][4]; + int8_t hats[NUM_HATS][2]; } apple_input_data_t; struct apple_pad_connection; diff --git a/input/apple_joypad.c b/input/apple_joypad.c index c23d6438b0..013bda7b5f 100644 --- a/input/apple_joypad.c +++ b/input/apple_joypad.c @@ -180,7 +180,7 @@ static bool apple_joypad_button(unsigned port, uint16_t joykey) return false; // Check the button return (port < MAX_PLAYERS && joykey < 32) ? - (g_current_input_data.pad_buttons[port] & (1 << joykey)) != 0 : false; + (g_current_input_data.buttons[port] & (1 << joykey)) != 0 : false; } static int16_t apple_joypad_axis(unsigned port, uint32_t joyaxis) @@ -194,12 +194,12 @@ static int16_t apple_joypad_axis(unsigned port, uint32_t joyaxis) if (AXIS_NEG_GET(joyaxis) < 4) { - val = g_current_input_data.pad_axis[port][AXIS_NEG_GET(joyaxis)]; + val = g_current_input_data.axes[port][AXIS_NEG_GET(joyaxis)]; val = (val < 0) ? val : 0; } else if(AXIS_POS_GET(joyaxis) < 4) { - val = g_current_input_data.pad_axis[port][AXIS_POS_GET(joyaxis)]; + val = g_current_input_data.axes[port][AXIS_POS_GET(joyaxis)]; val = (val > 0) ? val : 0; } diff --git a/input/apple_joypad_ps3.c b/input/apple_joypad_ps3.c index d872c79092..058910eb2f 100644 --- a/input/apple_joypad_ps3.c +++ b/input/apple_joypad_ps3.c @@ -151,9 +151,9 @@ static void hidpad_ps3_packet_handler(void *data, uint8_t *packet, uint16_t size memcpy(device->data, packet, size); - g_current_input_data.pad_buttons[device->slot] = hidpad_ps3_get_buttons(device); + g_current_input_data.buttons[device->slot] = hidpad_ps3_get_buttons(device); for (i = 0; i < 4; i ++) - g_current_input_data.pad_axis[device->slot][i] = hidpad_ps3_get_axis(device, i); + g_current_input_data.axes[device->slot][i] = hidpad_ps3_get_axis(device, i); } static void hidpad_ps3_set_rumble(void *data, diff --git a/input/apple_joypad_ps4.c b/input/apple_joypad_ps4.c index e16866185e..75b90f4078 100644 --- a/input/apple_joypad_ps4.c +++ b/input/apple_joypad_ps4.c @@ -155,10 +155,10 @@ static void hidpad_ps4_packet_handler(void *data, uint8_t *packet, uint16_t size memcpy(device->data, packet, size); - g_current_input_data.pad_buttons[device->slot] = hidpad_ps4_get_buttons(device); + g_current_input_data.buttons[device->slot] = hidpad_ps4_get_buttons(device); #if 0 for (i = 0; i < 4; i ++) - g_current_input_data.pad_axis[device->slot][i] = hidpad_ps4_get_axis(device, i); + g_current_input_data.axes[device->slot][i] = hidpad_ps4_get_axis(device, i); #endif } diff --git a/input/apple_joypad_wii.c b/input/apple_joypad_wii.c index 2e0450018b..ab219b1196 100644 --- a/input/apple_joypad_wii.c +++ b/input/apple_joypad_wii.c @@ -100,11 +100,11 @@ static void hidpad_wii_packet_handler(void *data, break; } - g_current_input_data.pad_buttons[device->unid] = device->btns | + g_current_input_data.buttons[device->unid] = device->btns | (device->exp.cc.classic.btns << 16); for (i = 0; i < 4; i++) - g_current_input_data.pad_axis[device->unid][i] = + g_current_input_data.axes[device->unid][i] = hidpad_wii_get_axis(device, i); } diff --git a/input/hid/apple_input_hid.c b/input/hid/apple_input_hid.c index 7a8de475e0..03c4009b17 100644 --- a/input/hid/apple_input_hid.c +++ b/input/hid/apple_input_hid.c @@ -89,7 +89,7 @@ static void hid_device_input_callback(void* context, IOReturn result, state = IOHIDValueGetIntegerValue(value) - min; val = (float)state / (float)max; - g_current_input_data.pad_axis[connection->slot][i] = + g_current_input_data.axes[connection->slot][i] = ((val * 2.0f) - 1.0f) * 32767.0f; } } @@ -107,9 +107,9 @@ static void hid_device_input_callback(void* context, IOReturn result, CFIndex state = IOHIDValueGetIntegerValue(value); if (state) - g_current_input_data.pad_buttons[connection->slot] |= (1 << (use - 1)); + g_current_input_data.buttons[connection->slot] |= (1 << (use - 1)); else - g_current_input_data.pad_buttons[connection->slot] &= ~(1 << (use - 1)); + g_current_input_data.buttons[connection->slot] &= ~(1 << (use - 1)); } break; } @@ -131,9 +131,9 @@ static void hid_device_removed(void* context, IOReturn result, void* sender) msg_queue_push(g_extern.msg_queue, msg, 0, 60); RARCH_LOG("[apple_input]: %s\n", msg); - g_current_input_data.pad_buttons[connection->slot] = 0; - memset(g_current_input_data.pad_axis[connection->slot], - 0, sizeof(g_current_input_data.pad_axis)); + g_current_input_data.buttons[connection->slot] = 0; + memset(g_current_input_data.axes[connection->slot], + 0, sizeof(g_current_input_data.axes)); apple_joypad_disconnect(connection->slot); free(connection);