mirror of
https://github.com/libretro/RetroArch.git
synced 2024-11-24 08:30:16 +00:00
(360/Xbox 1) Use the same input driver now for both 360 and Xbox 1
This commit is contained in:
parent
ff54bc6c0f
commit
bc8675f711
@ -1,260 +0,0 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
|
||||
* Copyright (C) 2011-2012 - Daniel De Matteis
|
||||
*
|
||||
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with RetroArch.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <xtl.h>
|
||||
|
||||
#define MAX_PADS 4
|
||||
|
||||
#include "../driver.h"
|
||||
#include "../general.h"
|
||||
#include "../libretro.h"
|
||||
#include "xinput_360_input.h"
|
||||
|
||||
static uint64_t state[MAX_PADS];
|
||||
static unsigned pads_connected;
|
||||
|
||||
const struct platform_bind platform_keys[] = {
|
||||
{ XINPUT1_GAMEPAD_B, "B button" },
|
||||
{ XINPUT1_GAMEPAD_A, "A button" },
|
||||
{ XINPUT1_GAMEPAD_Y, "Y button" },
|
||||
{ XINPUT1_GAMEPAD_X, "X button" },
|
||||
{ XINPUT1_GAMEPAD_DPAD_UP, "D-Pad Up" },
|
||||
{ XINPUT1_GAMEPAD_DPAD_DOWN, "D-Pad Down" },
|
||||
{ XINPUT1_GAMEPAD_DPAD_LEFT, "D-Pad Left" },
|
||||
{ XINPUT1_GAMEPAD_DPAD_RIGHT, "D-Pad Right" },
|
||||
{ XINPUT1_GAMEPAD_BACK, "Back button" },
|
||||
{ XINPUT1_GAMEPAD_START, "Start button" },
|
||||
{ XINPUT1_GAMEPAD_WHITE, "Right shoulder" },
|
||||
{ XINPUT1_GAMEPAD_LEFT_TRIGGER, "Left Trigger" },
|
||||
{ XINPUT1_GAMEPAD_LEFT_THUMB, "Left Thumb" },
|
||||
{ XINPUT1_GAMEPAD_BLACK, "Left shoulder" },
|
||||
{ XINPUT1_GAMEPAD_RIGHT_TRIGGER, "Right Trigger" },
|
||||
{ XINPUT1_GAMEPAD_RIGHT_THUMB, "Right Thumb" },
|
||||
{ XINPUT1_GAMEPAD_LSTICK_LEFT_MASK, "LStick Left" },
|
||||
{ XINPUT1_GAMEPAD_LSTICK_RIGHT_MASK, "LStick Right" },
|
||||
{ XINPUT1_GAMEPAD_LSTICK_UP_MASK, "LStick Up" },
|
||||
{ XINPUT1_GAMEPAD_LSTICK_DOWN_MASK, "LStick Down" },
|
||||
{ XINPUT1_GAMEPAD_DPAD_LEFT | XINPUT1_GAMEPAD_LSTICK_LEFT_MASK, "LStick D-Pad Left" },
|
||||
{ XINPUT1_GAMEPAD_DPAD_RIGHT | XINPUT1_GAMEPAD_LSTICK_RIGHT_MASK, "LStick D-Pad Right" },
|
||||
{ XINPUT1_GAMEPAD_DPAD_UP | XINPUT1_GAMEPAD_LSTICK_UP_MASK, "LStick D-Pad Up" },
|
||||
{ XINPUT1_GAMEPAD_DPAD_DOWN | XINPUT1_GAMEPAD_LSTICK_DOWN_MASK, "LStick D-Pad Down" },
|
||||
{ XINPUT1_GAMEPAD_RSTICK_LEFT_MASK, "RStick Left" },
|
||||
{ XINPUT1_GAMEPAD_RSTICK_RIGHT_MASK, "RStick Right" },
|
||||
{ XINPUT1_GAMEPAD_RSTICK_UP_MASK, "RStick Up" },
|
||||
{ XINPUT1_GAMEPAD_RSTICK_DOWN_MASK, "RStick Down" },
|
||||
{ XINPUT1_GAMEPAD_DPAD_LEFT | XINPUT1_GAMEPAD_RSTICK_LEFT_MASK, "RStick D-Pad Left" },
|
||||
{ XINPUT1_GAMEPAD_DPAD_RIGHT | XINPUT1_GAMEPAD_RSTICK_RIGHT_MASK, "RStick D-Pad Right" },
|
||||
{ XINPUT1_GAMEPAD_DPAD_UP | XINPUT1_GAMEPAD_RSTICK_UP_MASK, "RStick D-Pad Up" },
|
||||
{ XINPUT1_GAMEPAD_DPAD_DOWN | XINPUT1_GAMEPAD_RSTICK_DOWN_MASK, "RStick D-Pad Down" },
|
||||
};
|
||||
|
||||
const unsigned int platform_keys_size = sizeof(platform_keys);
|
||||
|
||||
static void xinput_input_poll(void *data)
|
||||
{
|
||||
(void)data;
|
||||
|
||||
pads_connected = 0;
|
||||
|
||||
for (unsigned i = 0; i < MAX_PADS; i++)
|
||||
{
|
||||
XINPUT_STATE state_tmp;
|
||||
unsigned long retval;
|
||||
{
|
||||
retval = XInputGetState(i, &state_tmp);
|
||||
pads_connected += (retval == ERROR_DEVICE_NOT_CONNECTED) ? 0 : 1;
|
||||
state[i] = 0;
|
||||
state[i] |= ((state_tmp.Gamepad.wButtons & XINPUT_GAMEPAD_B) ? XINPUT1_GAMEPAD_B : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.wButtons & XINPUT_GAMEPAD_A) ? XINPUT1_GAMEPAD_A : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.wButtons & XINPUT_GAMEPAD_Y) ? XINPUT1_GAMEPAD_Y : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.wButtons & XINPUT_GAMEPAD_X) ? XINPUT1_GAMEPAD_X : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_LEFT) ? XINPUT1_GAMEPAD_DPAD_LEFT : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_RIGHT) ? XINPUT1_GAMEPAD_DPAD_RIGHT : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_UP) ? XINPUT1_GAMEPAD_DPAD_UP : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_DOWN) ? XINPUT1_GAMEPAD_DPAD_DOWN : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.sThumbLX < -DEADZONE) ? XINPUT1_GAMEPAD_LSTICK_LEFT_MASK : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.sThumbLX > DEADZONE) ? XINPUT1_GAMEPAD_LSTICK_RIGHT_MASK : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.sThumbLY > DEADZONE) ? XINPUT1_GAMEPAD_LSTICK_UP_MASK : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.sThumbLY < -DEADZONE) ? XINPUT1_GAMEPAD_LSTICK_DOWN_MASK : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.sThumbRX < -DEADZONE) ? XINPUT1_GAMEPAD_RSTICK_LEFT_MASK : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.sThumbRX > DEADZONE) ? XINPUT1_GAMEPAD_RSTICK_RIGHT_MASK : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.sThumbRY > DEADZONE) ? XINPUT1_GAMEPAD_RSTICK_UP_MASK : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.sThumbRY < -DEADZONE) ? XINPUT1_GAMEPAD_RSTICK_DOWN_MASK : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.wButtons & XINPUT_GAMEPAD_START) ? XINPUT1_GAMEPAD_START : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.wButtons & XINPUT_GAMEPAD_BACK) ? XINPUT1_GAMEPAD_BACK : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.bLeftTrigger > 128) ? XINPUT1_GAMEPAD_LEFT_TRIGGER : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.bRightTrigger > 128) ? XINPUT1_GAMEPAD_RIGHT_TRIGGER : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER) ? XINPUT1_GAMEPAD_WHITE : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER) ? XINPUT1_GAMEPAD_BLACK : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_THUMB) ? XINPUT1_GAMEPAD_LEFT_THUMB : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB) ? XINPUT1_GAMEPAD_RIGHT_THUMB : 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int16_t xinput_input_state(void *data, const struct retro_keybind **binds,
|
||||
unsigned port, unsigned device,
|
||||
unsigned index, unsigned id)
|
||||
{
|
||||
(void)data;
|
||||
unsigned player = port;
|
||||
uint64_t button = binds[player][id].joykey;
|
||||
|
||||
return (state[player] & button) ? 1 : 0;
|
||||
}
|
||||
|
||||
static void xinput_input_free_input(void *data)
|
||||
{
|
||||
(void)data;
|
||||
}
|
||||
|
||||
static void xinput_input_set_analog_dpad_mapping(unsigned device, unsigned map_dpad_enum, unsigned controller_id)
|
||||
{
|
||||
(void)device;
|
||||
|
||||
switch(map_dpad_enum)
|
||||
{
|
||||
case DPAD_EMULATION_NONE:
|
||||
g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_UP].joykey = platform_keys[XDK_DEVICE_ID_JOYPAD_UP].joykey;
|
||||
g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_DOWN].joykey = platform_keys[XDK_DEVICE_ID_JOYPAD_DOWN].joykey;
|
||||
g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_LEFT].joykey = platform_keys[XDK_DEVICE_ID_JOYPAD_LEFT].joykey;
|
||||
g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_RIGHT].joykey = platform_keys[XDK_DEVICE_ID_JOYPAD_RIGHT].joykey;
|
||||
break;
|
||||
case DPAD_EMULATION_LSTICK:
|
||||
g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_UP].joykey = platform_keys[XDK_DEVICE_ID_LSTICK_UP_DPAD].joykey;
|
||||
g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_DOWN].joykey = platform_keys[XDK_DEVICE_ID_LSTICK_DOWN_DPAD].joykey;
|
||||
g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_LEFT].joykey = platform_keys[XDK_DEVICE_ID_LSTICK_LEFT_DPAD].joykey;
|
||||
g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_RIGHT].joykey = platform_keys[XDK_DEVICE_ID_LSTICK_RIGHT_DPAD].joykey;
|
||||
break;
|
||||
case DPAD_EMULATION_RSTICK:
|
||||
g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_UP].joykey = platform_keys[XDK_DEVICE_ID_RSTICK_UP_DPAD].joykey;
|
||||
g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_DOWN].joykey = platform_keys[XDK_DEVICE_ID_RSTICK_DOWN_DPAD].joykey;
|
||||
g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_LEFT].joykey = platform_keys[XDK_DEVICE_ID_RSTICK_LEFT_DPAD].joykey;
|
||||
g_settings.input.binds[controller_id][RETRO_DEVICE_ID_JOYPAD_RIGHT].joykey = platform_keys[XDK_DEVICE_ID_RSTICK_RIGHT_DPAD].joykey;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void* xinput_input_init(void)
|
||||
{
|
||||
return (void*)-1;
|
||||
}
|
||||
|
||||
#define STUB_DEVICE 0
|
||||
|
||||
static void xinput_input_post_init(void)
|
||||
{
|
||||
for(unsigned i = 0; i < MAX_PADS; i++)
|
||||
xinput_input_set_analog_dpad_mapping(STUB_DEVICE, g_settings.input.dpad_emulation[i], i);
|
||||
}
|
||||
|
||||
static bool xinput_input_key_pressed(void *data, int key)
|
||||
{
|
||||
(void)data;
|
||||
bool retval = false;
|
||||
xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)driver.video_data;
|
||||
|
||||
switch(key)
|
||||
{
|
||||
case RARCH_FAST_FORWARD_HOLD_KEY:
|
||||
return ((state[0] & XINPUT1_GAMEPAD_RSTICK_DOWN_MASK) && !(state[0] & XINPUT1_GAMEPAD_RIGHT_TRIGGER));
|
||||
case RARCH_LOAD_STATE_KEY:
|
||||
return ((state[0] & XINPUT1_GAMEPAD_RSTICK_UP_MASK) && (state[0] & XINPUT1_GAMEPAD_RIGHT_TRIGGER));
|
||||
case RARCH_SAVE_STATE_KEY:
|
||||
return ((state[0] & XINPUT1_GAMEPAD_RSTICK_DOWN_MASK) && (state[0] & XINPUT1_GAMEPAD_RIGHT_TRIGGER));
|
||||
case RARCH_STATE_SLOT_PLUS:
|
||||
return ((state[0] & XINPUT1_GAMEPAD_RSTICK_RIGHT_MASK) && (state[0] & XINPUT1_GAMEPAD_RIGHT_TRIGGER));
|
||||
case RARCH_STATE_SLOT_MINUS:
|
||||
return ((state[0] & XINPUT1_GAMEPAD_RSTICK_LEFT_MASK) && (state[0] & XINPUT1_GAMEPAD_RIGHT_TRIGGER));
|
||||
case RARCH_FRAMEADVANCE:
|
||||
if(g_console.frame_advance_enable)
|
||||
{
|
||||
g_console.menu_enable = true;
|
||||
g_console.ingame_menu_enable = true;
|
||||
g_console.mode_switch = MODE_MENU;
|
||||
}
|
||||
return false;
|
||||
case RARCH_REWIND:
|
||||
return ((state[0] & XINPUT1_GAMEPAD_RSTICK_UP_MASK) && !(state[0] & XINPUT1_GAMEPAD_RIGHT_TRIGGER));
|
||||
case RARCH_QUIT_KEY:
|
||||
if(IS_TIMER_EXPIRED(d3d))
|
||||
{
|
||||
uint32_t left_thumb_pressed = (state[0] & XINPUT1_GAMEPAD_LEFT_THUMB);
|
||||
uint32_t right_thumb_pressed = (state[0] & XINPUT1_GAMEPAD_RIGHT_THUMB);
|
||||
|
||||
g_console.menu_enable = right_thumb_pressed && left_thumb_pressed && IS_TIMER_EXPIRED(d3d);
|
||||
g_console.ingame_menu_enable = right_thumb_pressed && !left_thumb_pressed;
|
||||
|
||||
if(g_console.menu_enable || (g_console.ingame_menu_enable && !g_console.menu_enable))
|
||||
{
|
||||
g_console.mode_switch = MODE_MENU;
|
||||
SET_TIMER_EXPIRATION(d3d, 30);
|
||||
retval = g_console.menu_enable;
|
||||
}
|
||||
retval = g_console.ingame_menu_enable ? g_console.ingame_menu_enable : g_console.menu_enable;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
static void xinput_set_default_keybind_lut(unsigned device, unsigned port)
|
||||
{
|
||||
(void)device;
|
||||
(void)port;
|
||||
|
||||
rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_B] = platform_keys[XDK_DEVICE_ID_JOYPAD_A].joykey;
|
||||
rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_Y] = platform_keys[XDK_DEVICE_ID_JOYPAD_X].joykey;
|
||||
rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_SELECT] = platform_keys[XDK_DEVICE_ID_JOYPAD_BACK].joykey;
|
||||
rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_START] = platform_keys[XDK_DEVICE_ID_JOYPAD_START].joykey;
|
||||
rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_UP] = platform_keys[XDK_DEVICE_ID_JOYPAD_UP].joykey;
|
||||
rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_DOWN] = platform_keys[XDK_DEVICE_ID_JOYPAD_DOWN].joykey;
|
||||
rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_LEFT] = platform_keys[XDK_DEVICE_ID_JOYPAD_LEFT].joykey;
|
||||
rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_RIGHT] = platform_keys[XDK_DEVICE_ID_JOYPAD_RIGHT].joykey;
|
||||
rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_A] = platform_keys[XDK_DEVICE_ID_JOYPAD_B].joykey;
|
||||
rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_X] = platform_keys[XDK_DEVICE_ID_JOYPAD_Y].joykey;
|
||||
#if defined(_XBOX1)
|
||||
rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_L] = platform_keys[XDK_DEVICE_ID_JOYPAD_LEFT_TRIGGER].joykey;
|
||||
rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_R] = platform_keys[XDK_DEVICE_ID_JOYPAD_RIGHT_TRIGGER].joykey;
|
||||
rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_L2] = platform_keys[XDK_DEVICE_ID_JOYPAD_LB].joykey;
|
||||
rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_R2] = platform_keys[XDK_DEVICE_ID_JOYPAD_RB].joykey;
|
||||
#elif defined(_XBOX360)
|
||||
rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_L] = platform_keys[XDK_DEVICE_ID_JOYPAD_LB].joykey;
|
||||
rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_R] = platform_keys[XDK_DEVICE_ID_JOYPAD_RB].joykey;
|
||||
rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_L2] = platform_keys[XDK_DEVICE_ID_JOYPAD_LEFT_TRIGGER].joykey;
|
||||
rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_R2] = platform_keys[XDK_DEVICE_ID_JOYPAD_RIGHT_TRIGGER].joykey;
|
||||
#endif
|
||||
rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_L3] = platform_keys[XDK_DEVICE_ID_LSTICK_THUMB].joykey;
|
||||
rarch_default_keybind_lut[RETRO_DEVICE_ID_JOYPAD_R3] = platform_keys[XDK_DEVICE_ID_RSTICK_THUMB].joykey;
|
||||
}
|
||||
|
||||
const input_driver_t input_xinput =
|
||||
{
|
||||
xinput_input_init,
|
||||
xinput_input_poll,
|
||||
xinput_input_state,
|
||||
xinput_input_key_pressed,
|
||||
xinput_input_free_input,
|
||||
xinput_set_default_keybind_lut,
|
||||
xinput_input_set_analog_dpad_mapping,
|
||||
xinput_input_post_init,
|
||||
MAX_PADS,
|
||||
"xinput"
|
||||
};
|
@ -1,87 +0,0 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
|
||||
* Copyright (C) 2011-2012 - Daniel De Matteis
|
||||
*
|
||||
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with RetroArch.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _XDK360_XINPUT2_H
|
||||
#define _XDK360_XINPUT2_H
|
||||
|
||||
enum {
|
||||
XINPUT1_GAMEPAD_B = 1 << 0,
|
||||
XINPUT1_GAMEPAD_A = 1 << 1,
|
||||
XINPUT1_GAMEPAD_Y = 1 << 2,
|
||||
XINPUT1_GAMEPAD_X = 1 << 3,
|
||||
XINPUT1_GAMEPAD_DPAD_UP = 1 << 4,
|
||||
XINPUT1_GAMEPAD_DPAD_DOWN = 1 << 5,
|
||||
XINPUT1_GAMEPAD_DPAD_LEFT = 1 << 6,
|
||||
XINPUT1_GAMEPAD_DPAD_RIGHT = 1 << 7,
|
||||
XINPUT1_GAMEPAD_BACK = 1 << 8,
|
||||
XINPUT1_GAMEPAD_START = 1 << 9,
|
||||
XINPUT1_GAMEPAD_WHITE = 1 << 10,
|
||||
XINPUT1_GAMEPAD_LEFT_TRIGGER = 1 << 11,
|
||||
XINPUT1_GAMEPAD_LEFT_THUMB = 1 << 12,
|
||||
XINPUT1_GAMEPAD_BLACK = 1 << 13,
|
||||
XINPUT1_GAMEPAD_RIGHT_TRIGGER = 1 << 14,
|
||||
XINPUT1_GAMEPAD_RIGHT_THUMB = 1 << 15,
|
||||
XINPUT1_GAMEPAD_LSTICK_LEFT_MASK = 1 << 16,
|
||||
XINPUT1_GAMEPAD_LSTICK_RIGHT_MASK = 1 << 17,
|
||||
XINPUT1_GAMEPAD_LSTICK_UP_MASK = 1 << 18,
|
||||
XINPUT1_GAMEPAD_LSTICK_DOWN_MASK = 1 << 19,
|
||||
XINPUT1_GAMEPAD_RSTICK_LEFT_MASK = 1 << 20,
|
||||
XINPUT1_GAMEPAD_RSTICK_RIGHT_MASK = 1 << 21,
|
||||
XINPUT1_GAMEPAD_RSTICK_UP_MASK = 1 << 22,
|
||||
XINPUT1_GAMEPAD_RSTICK_DOWN_MASK = 1 << 23,
|
||||
};
|
||||
|
||||
enum xdk_device_id
|
||||
{
|
||||
XDK_DEVICE_ID_JOYPAD_B = 0,
|
||||
XDK_DEVICE_ID_JOYPAD_A,
|
||||
XDK_DEVICE_ID_JOYPAD_Y,
|
||||
XDK_DEVICE_ID_JOYPAD_X,
|
||||
XDK_DEVICE_ID_JOYPAD_UP,
|
||||
XDK_DEVICE_ID_JOYPAD_DOWN,
|
||||
XDK_DEVICE_ID_JOYPAD_LEFT,
|
||||
XDK_DEVICE_ID_JOYPAD_RIGHT,
|
||||
XDK_DEVICE_ID_JOYPAD_BACK,
|
||||
XDK_DEVICE_ID_JOYPAD_START,
|
||||
XDK_DEVICE_ID_JOYPAD_LB,
|
||||
XDK_DEVICE_ID_JOYPAD_LEFT_TRIGGER,
|
||||
XDK_DEVICE_ID_LSTICK_THUMB,
|
||||
XDK_DEVICE_ID_JOYPAD_RB,
|
||||
XDK_DEVICE_ID_JOYPAD_RIGHT_TRIGGER,
|
||||
XDK_DEVICE_ID_RSTICK_THUMB,
|
||||
XDK_DEVICE_ID_LSTICK_LEFT,
|
||||
XDK_DEVICE_ID_LSTICK_RIGHT,
|
||||
XDK_DEVICE_ID_LSTICK_UP,
|
||||
XDK_DEVICE_ID_LSTICK_DOWN,
|
||||
XDK_DEVICE_ID_LSTICK_LEFT_DPAD,
|
||||
XDK_DEVICE_ID_LSTICK_RIGHT_DPAD,
|
||||
XDK_DEVICE_ID_LSTICK_UP_DPAD,
|
||||
XDK_DEVICE_ID_LSTICK_DOWN_DPAD,
|
||||
XDK_DEVICE_ID_RSTICK_LEFT,
|
||||
XDK_DEVICE_ID_RSTICK_RIGHT,
|
||||
XDK_DEVICE_ID_RSTICK_UP,
|
||||
XDK_DEVICE_ID_RSTICK_DOWN,
|
||||
XDK_DEVICE_ID_RSTICK_LEFT_DPAD,
|
||||
XDK_DEVICE_ID_RSTICK_RIGHT_DPAD,
|
||||
XDK_DEVICE_ID_RSTICK_UP_DPAD,
|
||||
XDK_DEVICE_ID_RSTICK_DOWN_DPAD,
|
||||
|
||||
RARCH_LAST_PLATFORM_KEY
|
||||
};
|
||||
|
||||
#define DEADZONE (16000)
|
||||
|
||||
#endif
|
@ -156,14 +156,8 @@ INPUT
|
||||
#include "../../ps3/ps3_input.c"
|
||||
#elif defined(GEKKO)
|
||||
#include "../../wii/gx_input.c"
|
||||
#endif
|
||||
|
||||
#ifdef _XBOX
|
||||
#if defined(HAVE_XINPUT_XBOX1)
|
||||
#include "../../xbox1/xinput_xbox_input.c"
|
||||
#elif defined(HAVE_XINPUT2)
|
||||
#include "../../360/xinput_360_input.c"
|
||||
#endif
|
||||
#elif defined(_XBOX)
|
||||
#include "../../xdk/xdk_xinput_input.c"
|
||||
#endif
|
||||
|
||||
#include "../../input/null.c"
|
||||
|
@ -26,13 +26,17 @@
|
||||
#include "../driver.h"
|
||||
#include "../general.h"
|
||||
#include "../libretro.h"
|
||||
#include "xinput_xbox_input.h"
|
||||
#include "xdk_xinput_input.h"
|
||||
|
||||
static uint64_t state[MAX_PADS];
|
||||
static unsigned pads_connected;
|
||||
|
||||
#ifdef _XBOX1
|
||||
HANDLE gamepads[MAX_PADS];
|
||||
DWORD dwDeviceMask;
|
||||
bool bInserted[MAX_PADS];
|
||||
bool bRemoved[MAX_PADS];
|
||||
#endif
|
||||
|
||||
const struct platform_bind platform_keys[] = {
|
||||
{ XINPUT1_GAMEPAD_B, "B button" },
|
||||
@ -45,10 +49,18 @@ const struct platform_bind platform_keys[] = {
|
||||
{ XINPUT1_GAMEPAD_DPAD_RIGHT, "D-Pad Right" },
|
||||
{ XINPUT1_GAMEPAD_BACK, "Back button" },
|
||||
{ XINPUT1_GAMEPAD_START, "Start button" },
|
||||
#if defined(_XBOX1)
|
||||
{ XINPUT1_GAMEPAD_WHITE, "White button" },
|
||||
#elif defined(_XBOX360)
|
||||
{ XINPUT1_GAMEPAD_WHITE, "Right shoulder" },
|
||||
#endif
|
||||
{ XINPUT1_GAMEPAD_LEFT_TRIGGER, "Left Trigger" },
|
||||
{ XINPUT1_GAMEPAD_LEFT_THUMB, "Left Thumb" },
|
||||
#if defined(_XBOX1)
|
||||
{ XINPUT1_GAMEPAD_BLACK, "Black button" },
|
||||
#elif defined(_XBOX360)
|
||||
{ XINPUT1_GAMEPAD_BLACK, "Left shoulder" },
|
||||
#endif
|
||||
{ XINPUT1_GAMEPAD_RIGHT_TRIGGER, "Right Trigger" },
|
||||
{ XINPUT1_GAMEPAD_RIGHT_THUMB, "Right Thumb" },
|
||||
{ XINPUT1_GAMEPAD_LSTICK_LEFT_MASK, "LStick Left" },
|
||||
@ -71,19 +83,17 @@ const struct platform_bind platform_keys[] = {
|
||||
|
||||
const unsigned int platform_keys_size = sizeof(platform_keys);
|
||||
|
||||
#define DEADZONE (16000)
|
||||
|
||||
static unsigned pads_connected;
|
||||
|
||||
static void xinput_input_poll(void *data)
|
||||
{
|
||||
(void)data;
|
||||
|
||||
pads_connected = 0;
|
||||
|
||||
#if defined(_XBOX1)
|
||||
unsigned int dwInsertions, dwRemovals;
|
||||
|
||||
XGetDeviceChanges(XDEVICE_TYPE_GAMEPAD, reinterpret_cast<PDWORD>(&dwInsertions), reinterpret_cast<PDWORD>(&dwRemovals));
|
||||
|
||||
pads_connected = 0;
|
||||
|
||||
for (unsigned i = 0; i < MAX_PADS; i++)
|
||||
{
|
||||
XINPUT_CAPABILITIES caps[MAX_PADS];
|
||||
@ -153,6 +163,42 @@ static void xinput_input_poll(void *data)
|
||||
}
|
||||
}
|
||||
}
|
||||
#elif defined(_XBOX360)
|
||||
for (unsigned i = 0; i < MAX_PADS; i++)
|
||||
{
|
||||
XINPUT_STATE state_tmp;
|
||||
unsigned long retval;
|
||||
{
|
||||
retval = XInputGetState(i, &state_tmp);
|
||||
pads_connected += (retval == ERROR_DEVICE_NOT_CONNECTED) ? 0 : 1;
|
||||
state[i] = 0;
|
||||
state[i] |= ((state_tmp.Gamepad.wButtons & XINPUT_GAMEPAD_B) ? XINPUT1_GAMEPAD_B : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.wButtons & XINPUT_GAMEPAD_A) ? XINPUT1_GAMEPAD_A : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.wButtons & XINPUT_GAMEPAD_Y) ? XINPUT1_GAMEPAD_Y : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.wButtons & XINPUT_GAMEPAD_X) ? XINPUT1_GAMEPAD_X : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_LEFT) ? XINPUT1_GAMEPAD_DPAD_LEFT : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_RIGHT) ? XINPUT1_GAMEPAD_DPAD_RIGHT : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_UP) ? XINPUT1_GAMEPAD_DPAD_UP : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_DOWN) ? XINPUT1_GAMEPAD_DPAD_DOWN : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.sThumbLX < -DEADZONE) ? XINPUT1_GAMEPAD_LSTICK_LEFT_MASK : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.sThumbLX > DEADZONE) ? XINPUT1_GAMEPAD_LSTICK_RIGHT_MASK : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.sThumbLY > DEADZONE) ? XINPUT1_GAMEPAD_LSTICK_UP_MASK : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.sThumbLY < -DEADZONE) ? XINPUT1_GAMEPAD_LSTICK_DOWN_MASK : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.sThumbRX < -DEADZONE) ? XINPUT1_GAMEPAD_RSTICK_LEFT_MASK : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.sThumbRX > DEADZONE) ? XINPUT1_GAMEPAD_RSTICK_RIGHT_MASK : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.sThumbRY > DEADZONE) ? XINPUT1_GAMEPAD_RSTICK_UP_MASK : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.sThumbRY < -DEADZONE) ? XINPUT1_GAMEPAD_RSTICK_DOWN_MASK : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.wButtons & XINPUT_GAMEPAD_START) ? XINPUT1_GAMEPAD_START : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.wButtons & XINPUT_GAMEPAD_BACK) ? XINPUT1_GAMEPAD_BACK : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.bLeftTrigger > 128) ? XINPUT1_GAMEPAD_LEFT_TRIGGER : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.bRightTrigger > 128) ? XINPUT1_GAMEPAD_RIGHT_TRIGGER : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER) ? XINPUT1_GAMEPAD_WHITE : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER) ? XINPUT1_GAMEPAD_BLACK : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_THUMB) ? XINPUT1_GAMEPAD_LEFT_THUMB : 0);
|
||||
state[i] |= ((state_tmp.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB) ? XINPUT1_GAMEPAD_RIGHT_THUMB : 0);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static int16_t xinput_input_state(void *data, const struct retro_keybind **binds,
|
||||
@ -230,6 +276,7 @@ static void xinput_input_set_analog_dpad_mapping(unsigned device, unsigned map_d
|
||||
|
||||
static void* xinput_input_init(void)
|
||||
{
|
||||
#ifdef _XBOX1
|
||||
XInitDevices(0, NULL);
|
||||
|
||||
dwDeviceMask = XGetDevices(XDEVICE_TYPE_GAMEPAD);
|
||||
@ -246,6 +293,7 @@ static void* xinput_input_init(void)
|
||||
}
|
||||
|
||||
while(XGetDeviceEnumerationStatus() == XDEVICE_ENUMERATION_BUSY) {}
|
||||
#endif
|
||||
|
||||
return (void*)-1;
|
||||
}
|
@ -14,8 +14,8 @@
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _XDK_XINPUT1_H
|
||||
#define _XDK_XINPUT1_H
|
||||
#ifndef _XDK_XINPUT_H
|
||||
#define _XDK_XINPUT_H
|
||||
|
||||
enum {
|
||||
XINPUT1_GAMEPAD_B = 1 << 0,
|
||||
@ -82,4 +82,6 @@ enum xdk_device_id
|
||||
RARCH_LAST_PLATFORM_KEY
|
||||
};
|
||||
|
||||
#define DEADZONE (16000)
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user