2012-07-08 19:42:26 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2014-01-01 00:50:59 +00:00
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
|
|
|
* Copyright (C) 2011-2014 - Daniel De Matteis
|
2012-07-08 19:42:26 +00:00
|
|
|
*
|
|
|
|
* 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>
|
|
|
|
|
|
|
|
#ifdef _XBOX
|
|
|
|
#include <xtl.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "../driver.h"
|
|
|
|
#include "../general.h"
|
|
|
|
#include "../libretro.h"
|
2013-01-22 00:05:48 +00:00
|
|
|
|
2014-04-17 18:47:11 +00:00
|
|
|
#define MAX_PADS 4
|
|
|
|
|
2013-11-01 16:11:58 +00:00
|
|
|
typedef struct xdk_input
|
|
|
|
{
|
2014-06-09 16:28:33 +00:00
|
|
|
const rarch_joypad_driver_t *joypad;
|
2013-11-01 16:11:58 +00:00
|
|
|
} xdk_input_t;
|
|
|
|
|
2012-12-02 05:01:39 +00:00
|
|
|
static void xdk_input_poll(void *data)
|
2012-07-08 19:42:26 +00:00
|
|
|
{
|
2013-11-01 16:11:58 +00:00
|
|
|
xdk_input_t *xdk = (xdk_input_t*)data;
|
2013-01-09 06:27:05 +00:00
|
|
|
|
2014-10-05 15:39:54 +00:00
|
|
|
if (xdk && xdk->joypad)
|
|
|
|
xdk->joypad->poll();
|
2012-07-08 19:42:26 +00:00
|
|
|
}
|
|
|
|
|
2012-12-02 05:01:39 +00:00
|
|
|
static int16_t xdk_input_state(void *data, const struct retro_keybind **binds,
|
2012-07-08 19:42:26 +00:00
|
|
|
unsigned port, unsigned device,
|
|
|
|
unsigned index, unsigned id)
|
|
|
|
{
|
2013-11-01 16:11:58 +00:00
|
|
|
xdk_input_t *xdk = (xdk_input_t*)data;
|
2012-07-14 15:47:30 +00:00
|
|
|
|
2014-05-29 23:48:55 +00:00
|
|
|
if (port >= MAX_PADS)
|
2013-12-26 21:17:31 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
switch (device)
|
|
|
|
{
|
|
|
|
case RETRO_DEVICE_JOYPAD:
|
2014-06-09 16:17:37 +00:00
|
|
|
return input_joypad_pressed(xdk->joypad, port, binds[port], id);
|
2013-12-28 03:01:58 +00:00
|
|
|
case RETRO_DEVICE_ANALOG:
|
2014-06-09 16:17:37 +00:00
|
|
|
return input_joypad_analog(xdk->joypad, port, index, id, binds[port]);
|
2013-12-26 21:17:31 +00:00
|
|
|
}
|
2014-10-05 15:39:54 +00:00
|
|
|
|
|
|
|
return 0;
|
2012-07-08 19:42:26 +00:00
|
|
|
}
|
|
|
|
|
2012-12-02 05:01:39 +00:00
|
|
|
static void xdk_input_free_input(void *data)
|
2012-07-08 19:42:26 +00:00
|
|
|
{
|
2014-06-09 16:17:37 +00:00
|
|
|
xdk_input_t *xdk = (xdk_input_t*)data;
|
|
|
|
|
2014-09-15 12:17:16 +00:00
|
|
|
if (!xdk)
|
|
|
|
return;
|
|
|
|
|
2014-06-09 16:17:37 +00:00
|
|
|
if (xdk->joypad)
|
|
|
|
xdk->joypad->destroy();
|
|
|
|
|
2014-09-15 12:17:16 +00:00
|
|
|
free(xdk);
|
2012-07-08 19:42:26 +00:00
|
|
|
}
|
|
|
|
|
2012-12-02 05:01:39 +00:00
|
|
|
static void *xdk_input_init(void)
|
2012-07-08 19:42:26 +00:00
|
|
|
{
|
2013-11-01 16:11:58 +00:00
|
|
|
xdk_input_t *xdk = (xdk_input_t*)calloc(1, sizeof(*xdk));
|
|
|
|
if (!xdk)
|
|
|
|
return NULL;
|
|
|
|
|
2014-06-09 16:17:37 +00:00
|
|
|
xdk->joypad = input_joypad_init_driver(g_settings.input.joypad_driver);
|
2014-10-05 15:39:54 +00:00
|
|
|
|
2013-11-01 16:11:58 +00:00
|
|
|
return xdk;
|
2012-07-27 13:46:15 +00:00
|
|
|
}
|
|
|
|
|
2012-12-02 05:01:39 +00:00
|
|
|
static bool xdk_input_key_pressed(void *data, int key)
|
2012-07-08 19:42:26 +00:00
|
|
|
{
|
2014-06-09 16:17:37 +00:00
|
|
|
xdk_input_t *xdk = (xdk_input_t*)data;
|
2014-09-09 16:15:17 +00:00
|
|
|
return (g_extern.lifecycle_state & (1ULL << key)) ||
|
|
|
|
input_joypad_pressed(xdk->joypad, 0, g_settings.input.binds[0], key);
|
2012-07-08 19:42:26 +00:00
|
|
|
}
|
|
|
|
|
2013-11-02 20:16:57 +00:00
|
|
|
static uint64_t xdk_input_get_capabilities(void *data)
|
|
|
|
{
|
2014-10-05 15:39:54 +00:00
|
|
|
(void)data;
|
2013-11-02 20:16:57 +00:00
|
|
|
|
2014-10-05 15:39:54 +00:00
|
|
|
return (1 << RETRO_DEVICE_JOYPAD) | (1 << RETRO_DEVICE_ANALOG);
|
2013-11-02 20:16:57 +00:00
|
|
|
}
|
|
|
|
|
2014-09-09 16:15:17 +00:00
|
|
|
/* FIXME - are we sure about treating low frequency motor as the
|
|
|
|
* "strong" motor? Does it apply for Xbox too? */
|
2013-11-03 20:32:16 +00:00
|
|
|
|
2014-09-09 16:15:17 +00:00
|
|
|
static bool xdk_input_set_rumble(void *data, unsigned port,
|
|
|
|
enum retro_rumble_effect effect, uint16_t strength)
|
2013-11-03 20:32:16 +00:00
|
|
|
{
|
2013-11-03 23:13:09 +00:00
|
|
|
xdk_input_t *xdk = (xdk_input_t*)data;
|
2014-05-29 23:48:55 +00:00
|
|
|
(void)xdk;
|
2013-11-03 20:32:16 +00:00
|
|
|
bool val = false;
|
|
|
|
|
2014-05-29 23:48:55 +00:00
|
|
|
|
2014-02-28 15:36:03 +00:00
|
|
|
#if 0
|
2013-11-03 20:32:16 +00:00
|
|
|
#if defined(_XBOX360)
|
|
|
|
XINPUT_VIBRATION rumble_state;
|
|
|
|
|
|
|
|
if (effect == RETRO_RUMBLE_STRONG)
|
|
|
|
rumble_state.wLeftMotorSpeed = strength;
|
|
|
|
else if (effect == RETRO_RUMBLE_WEAK)
|
|
|
|
rumble_state.wRightMotorSpeed = strength;
|
|
|
|
val = XInputSetState(port, &rumble_state) == ERROR_SUCCESS;
|
|
|
|
#elif defined(_XBOX1)
|
2013-11-11 02:36:30 +00:00
|
|
|
#if 0
|
2013-11-03 20:32:16 +00:00
|
|
|
XINPUT_FEEDBACK rumble_state;
|
|
|
|
|
|
|
|
if (effect == RETRO_RUMBLE_STRONG)
|
|
|
|
rumble_state.Rumble.wLeftMotorSpeed = strength;
|
|
|
|
else if (effect == RETRO_RUMBLE_WEAK)
|
|
|
|
rumble_state.Rumble.wRightMotorSpeed = strength;
|
2013-11-03 20:37:31 +00:00
|
|
|
val = XInputSetState(xdk->gamepads[port], &rumble_state) == ERROR_SUCCESS;
|
2013-11-11 02:36:30 +00:00
|
|
|
#endif
|
2014-02-28 15:36:03 +00:00
|
|
|
#endif
|
2013-11-03 20:32:16 +00:00
|
|
|
#endif
|
2013-11-03 20:37:31 +00:00
|
|
|
return val;
|
2013-11-03 20:32:16 +00:00
|
|
|
}
|
|
|
|
|
2013-12-26 21:17:31 +00:00
|
|
|
static const rarch_joypad_driver_t *xdk_input_get_joypad_driver(void *data)
|
|
|
|
{
|
2014-06-09 16:17:37 +00:00
|
|
|
xdk_input_t *xdk = (xdk_input_t*)data;
|
2014-10-05 15:39:54 +00:00
|
|
|
if (xdk)
|
|
|
|
return xdk->joypad;
|
|
|
|
return NULL;
|
2013-12-26 21:17:31 +00:00
|
|
|
}
|
|
|
|
|
2014-09-11 05:06:20 +00:00
|
|
|
input_driver_t input_xinput = {
|
2012-12-02 05:01:39 +00:00
|
|
|
xdk_input_init,
|
|
|
|
xdk_input_poll,
|
|
|
|
xdk_input_state,
|
|
|
|
xdk_input_key_pressed,
|
|
|
|
xdk_input_free_input,
|
2014-06-09 16:17:37 +00:00
|
|
|
NULL,
|
2013-11-02 23:27:58 +00:00
|
|
|
NULL,
|
2013-11-02 20:16:57 +00:00
|
|
|
xdk_input_get_capabilities,
|
2013-11-03 20:32:16 +00:00
|
|
|
"xinput",
|
|
|
|
|
|
|
|
NULL,
|
|
|
|
xdk_input_set_rumble,
|
2013-12-26 21:17:31 +00:00
|
|
|
xdk_input_get_joypad_driver,
|
2012-07-08 19:42:26 +00:00
|
|
|
};
|