2012-07-08 21:42:26 +02:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2014-01-01 01:50:59 +01:00
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
2016-01-10 04:33:01 +01:00
|
|
|
* Copyright (C) 2011-2016 - Daniel De Matteis
|
2012-07-08 21:42:26 +02: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>
|
|
|
|
|
2016-09-11 13:21:56 +02:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "../../config.h"
|
|
|
|
#endif
|
|
|
|
|
2012-07-08 21:42:26 +02:00
|
|
|
#ifdef _XBOX
|
|
|
|
#include <xtl.h>
|
|
|
|
#endif
|
|
|
|
|
2016-05-10 19:03:53 +02:00
|
|
|
#include <boolean.h>
|
|
|
|
#include <libretro.h>
|
|
|
|
|
2016-09-11 16:24:02 +02:00
|
|
|
#include "../input_joypad_driver.h"
|
2016-09-05 18:31:32 +02:00
|
|
|
#include "../../configuration.h"
|
2013-01-22 01:05:48 +01:00
|
|
|
|
2014-04-17 20:47:11 +02:00
|
|
|
#define MAX_PADS 4
|
|
|
|
|
2013-11-01 17:11:58 +01:00
|
|
|
typedef struct xdk_input
|
|
|
|
{
|
2015-06-19 03:45:23 +02:00
|
|
|
bool blocked;
|
2015-04-14 16:37:59 +02:00
|
|
|
const input_device_driver_t *joypad;
|
2013-11-01 17:11:58 +01:00
|
|
|
} xdk_input_t;
|
|
|
|
|
2012-12-02 06:01:39 +01:00
|
|
|
static void xdk_input_poll(void *data)
|
2012-07-08 21:42:26 +02:00
|
|
|
{
|
2013-11-01 17:11:58 +01:00
|
|
|
xdk_input_t *xdk = (xdk_input_t*)data;
|
2013-01-09 07:27:05 +01:00
|
|
|
|
2014-10-05 17:39:54 +02:00
|
|
|
if (xdk && xdk->joypad)
|
|
|
|
xdk->joypad->poll();
|
2012-07-08 21:42:26 +02:00
|
|
|
}
|
|
|
|
|
2012-12-02 06:01:39 +01:00
|
|
|
static int16_t xdk_input_state(void *data, const struct retro_keybind **binds,
|
2012-07-08 21:42:26 +02:00
|
|
|
unsigned port, unsigned device,
|
|
|
|
unsigned index, unsigned id)
|
|
|
|
{
|
2017-01-10 03:44:53 +01:00
|
|
|
rarch_joypad_info_t joypad_info;
|
|
|
|
xdk_input_t *xdk = (xdk_input_t*)data;
|
|
|
|
settings_t *settings = config_get_ptr();
|
2012-07-14 17:47:30 +02:00
|
|
|
|
2014-05-30 01:48:55 +02:00
|
|
|
if (port >= MAX_PADS)
|
2013-12-26 22:17:31 +01:00
|
|
|
return 0;
|
|
|
|
|
2017-01-10 03:44:53 +01:00
|
|
|
joypad_info.joy_idx = port;
|
|
|
|
joypad_info.auto_binds = settings->input.autoconf_binds[port];
|
|
|
|
joypad_info.axis_threshold = settings->input.axis_threshold;
|
|
|
|
|
2013-12-26 22:17:31 +01:00
|
|
|
switch (device)
|
|
|
|
{
|
|
|
|
case RETRO_DEVICE_JOYPAD:
|
2017-01-10 17:05:04 +01:00
|
|
|
return input_joypad_pressed(xdk->joypad, joypad_info, port, binds[port], id);
|
2013-12-28 04:01:58 +01:00
|
|
|
case RETRO_DEVICE_ANALOG:
|
2016-10-26 10:29:26 +02:00
|
|
|
if (binds[port])
|
2017-01-10 03:53:57 +01:00
|
|
|
return input_joypad_analog(xdk->joypad, joypad_info, port, index, id, binds[port]);
|
2016-10-26 10:29:26 +02:00
|
|
|
break;
|
2013-12-26 22:17:31 +01:00
|
|
|
}
|
2014-10-05 17:39:54 +02:00
|
|
|
|
|
|
|
return 0;
|
2012-07-08 21:42:26 +02:00
|
|
|
}
|
|
|
|
|
2012-12-02 06:01:39 +01:00
|
|
|
static void xdk_input_free_input(void *data)
|
2012-07-08 21:42:26 +02:00
|
|
|
{
|
2014-06-09 18:17:37 +02:00
|
|
|
xdk_input_t *xdk = (xdk_input_t*)data;
|
|
|
|
|
2014-09-15 08:17:16 -04:00
|
|
|
if (!xdk)
|
|
|
|
return;
|
|
|
|
|
2014-06-09 18:17:37 +02:00
|
|
|
if (xdk->joypad)
|
|
|
|
xdk->joypad->destroy();
|
|
|
|
|
2014-09-15 08:17:16 -04:00
|
|
|
free(xdk);
|
2012-07-08 21:42:26 +02:00
|
|
|
}
|
|
|
|
|
2012-12-02 06:01:39 +01:00
|
|
|
static void *xdk_input_init(void)
|
2012-07-08 21:42:26 +02:00
|
|
|
{
|
2015-03-20 22:32:09 +01:00
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
xdk_input_t *xdk = (xdk_input_t*)calloc(1, sizeof(*xdk));
|
2013-11-01 17:11:58 +01:00
|
|
|
if (!xdk)
|
|
|
|
return NULL;
|
|
|
|
|
2015-06-03 18:22:54 +02:00
|
|
|
xdk->joypad = input_joypad_init_driver(settings->input.joypad_driver, xdk);
|
2014-10-05 17:39:54 +02:00
|
|
|
|
2013-11-01 17:11:58 +01:00
|
|
|
return xdk;
|
2012-07-27 15:46:15 +02:00
|
|
|
}
|
|
|
|
|
2015-11-07 20:59:12 +01:00
|
|
|
static bool xdk_input_meta_key_pressed(void *data, int key)
|
2015-07-17 03:31:51 +02:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-11-02 21:16:57 +01:00
|
|
|
static uint64_t xdk_input_get_capabilities(void *data)
|
|
|
|
{
|
2014-10-05 17:39:54 +02:00
|
|
|
(void)data;
|
2013-11-02 21:16:57 +01:00
|
|
|
|
2014-10-05 17:39:54 +02:00
|
|
|
return (1 << RETRO_DEVICE_JOYPAD) | (1 << RETRO_DEVICE_ANALOG);
|
2013-11-02 21:16:57 +01:00
|
|
|
}
|
|
|
|
|
2014-09-09 18:15:17 +02:00
|
|
|
/* FIXME - are we sure about treating low frequency motor as the
|
|
|
|
* "strong" motor? Does it apply for Xbox too? */
|
2013-11-03 21:32:16 +01:00
|
|
|
|
2014-09-09 18:15:17 +02:00
|
|
|
static bool xdk_input_set_rumble(void *data, unsigned port,
|
|
|
|
enum retro_rumble_effect effect, uint16_t strength)
|
2013-11-03 21:32:16 +01:00
|
|
|
{
|
2013-11-04 00:13:09 +01:00
|
|
|
xdk_input_t *xdk = (xdk_input_t*)data;
|
2014-05-30 01:48:55 +02:00
|
|
|
(void)xdk;
|
2013-11-03 21:32:16 +01:00
|
|
|
bool val = false;
|
|
|
|
|
2014-05-30 01:48:55 +02:00
|
|
|
|
2014-02-28 16:36:03 +01:00
|
|
|
#if 0
|
2013-11-03 21:32:16 +01: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 03:36:30 +01:00
|
|
|
#if 0
|
2013-11-03 21:32:16 +01: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 21:37:31 +01:00
|
|
|
val = XInputSetState(xdk->gamepads[port], &rumble_state) == ERROR_SUCCESS;
|
2013-11-11 03:36:30 +01:00
|
|
|
#endif
|
2014-02-28 16:36:03 +01:00
|
|
|
#endif
|
2013-11-03 21:32:16 +01:00
|
|
|
#endif
|
2013-11-03 21:37:31 +01:00
|
|
|
return val;
|
2013-11-03 21:32:16 +01:00
|
|
|
}
|
|
|
|
|
2015-04-14 16:37:59 +02:00
|
|
|
static const input_device_driver_t *xdk_input_get_joypad_driver(void *data)
|
2013-12-26 22:17:31 +01:00
|
|
|
{
|
2014-06-09 18:17:37 +02:00
|
|
|
xdk_input_t *xdk = (xdk_input_t*)data;
|
2015-03-09 19:00:01 +01:00
|
|
|
if (!xdk)
|
|
|
|
return NULL;
|
|
|
|
return xdk->joypad;
|
2013-12-26 22:17:31 +01:00
|
|
|
}
|
|
|
|
|
2015-03-24 07:51:50 +01:00
|
|
|
static void xdk_input_grab_mouse(void *data, bool state)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
(void)state;
|
|
|
|
}
|
|
|
|
|
2015-06-19 03:45:23 +02:00
|
|
|
static bool xdk_keyboard_mapping_is_blocked(void *data)
|
|
|
|
{
|
|
|
|
xdk_input_t *xdk = (xdk_input_t*)data;
|
|
|
|
if (!xdk)
|
|
|
|
return false;
|
|
|
|
return xdk->blocked;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xdk_keyboard_mapping_set_block(void *data, bool value)
|
|
|
|
{
|
|
|
|
xdk_input_t *xdk = (xdk_input_t*)data;
|
|
|
|
if (!xdk)
|
|
|
|
return;
|
|
|
|
xdk->blocked = value;
|
|
|
|
}
|
|
|
|
|
2014-09-11 07:06:20 +02:00
|
|
|
input_driver_t input_xinput = {
|
2012-12-02 06:01:39 +01:00
|
|
|
xdk_input_init,
|
|
|
|
xdk_input_poll,
|
|
|
|
xdk_input_state,
|
2015-07-17 03:31:51 +02:00
|
|
|
xdk_input_meta_key_pressed,
|
2012-12-02 06:01:39 +01:00
|
|
|
xdk_input_free_input,
|
2014-06-09 18:17:37 +02:00
|
|
|
NULL,
|
2013-11-03 00:27:58 +01:00
|
|
|
NULL,
|
2013-11-02 21:16:57 +01:00
|
|
|
xdk_input_get_capabilities,
|
2013-11-03 21:32:16 +01:00
|
|
|
"xinput",
|
2015-03-24 07:51:50 +01:00
|
|
|
xdk_input_grab_mouse,
|
2015-05-19 19:33:58 +02:00
|
|
|
NULL,
|
2013-11-03 21:32:16 +01:00
|
|
|
xdk_input_set_rumble,
|
2013-12-26 22:17:31 +01:00
|
|
|
xdk_input_get_joypad_driver,
|
2015-11-16 02:39:38 +01:00
|
|
|
NULL,
|
2015-06-19 03:45:23 +02:00
|
|
|
xdk_keyboard_mapping_is_blocked,
|
|
|
|
xdk_keyboard_mapping_set_block,
|
2012-07-08 21:42:26 +02:00
|
|
|
};
|