2012-04-21 21:13:50 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2014-01-01 00:50:59 +00:00
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
2015-01-07 16:46:50 +00:00
|
|
|
* Copyright (C) 2011-2015 - Daniel De Matteis
|
|
|
|
* Copyright (C) 2012-2015 - Michael Lelli
|
2011-12-14 12:20:22 +00:00
|
|
|
*
|
2012-04-21 21:13:50 +00:00
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
2011-12-14 12:20:22 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2012-04-21 21:13:50 +00:00
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
2011-12-14 12:20:22 +00:00
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
2012-04-21 21:31:57 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
2011-12-14 12:20:22 +00:00
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2015-06-19 01:45:23 +00:00
|
|
|
#include <stdlib.h>
|
2012-01-03 11:11:02 +00:00
|
|
|
#include <string.h>
|
2012-07-26 05:28:57 +00:00
|
|
|
#include <math.h>
|
2011-12-14 12:20:22 +00:00
|
|
|
|
2015-06-19 01:45:23 +00:00
|
|
|
#include <boolean.h>
|
|
|
|
|
2012-07-26 05:28:57 +00:00
|
|
|
#ifndef M_PI
|
|
|
|
#define M_PI 3.14159265358979323846264338327
|
|
|
|
#endif
|
|
|
|
|
2015-01-12 05:16:52 +00:00
|
|
|
#include "../../driver.h"
|
|
|
|
#include "../../libretro.h"
|
2011-12-14 12:20:22 +00:00
|
|
|
|
2014-10-05 16:00:43 +00:00
|
|
|
#ifndef MAX_PADS
|
2013-03-16 16:51:45 +00:00
|
|
|
#define MAX_PADS 4
|
2014-10-05 16:00:43 +00:00
|
|
|
#endif
|
2013-03-16 16:51:45 +00:00
|
|
|
|
2013-11-01 15:33:32 +00:00
|
|
|
typedef struct gx_input
|
|
|
|
{
|
2015-06-19 01:45:23 +00:00
|
|
|
bool blocked;
|
2015-04-14 14:37:59 +00:00
|
|
|
const input_device_driver_t *joypad;
|
2013-11-01 15:33:32 +00:00
|
|
|
} gx_input_t;
|
2012-04-11 02:22:41 +00:00
|
|
|
|
2012-08-09 01:54:27 +00:00
|
|
|
static int16_t gx_input_state(void *data, const struct retro_keybind **binds,
|
2012-04-09 23:00:25 +00:00
|
|
|
unsigned port, unsigned device,
|
2014-10-20 18:31:00 +00:00
|
|
|
unsigned idx, unsigned id)
|
2011-12-14 12:20:22 +00:00
|
|
|
{
|
2014-06-09 19:17:43 +00:00
|
|
|
gx_input_t *gx = (gx_input_t*)data;
|
|
|
|
if (port >= MAX_PADS || !gx)
|
2012-07-26 05:28:57 +00:00
|
|
|
return 0;
|
2011-12-14 12:20:22 +00:00
|
|
|
|
2013-07-04 18:52:53 +00:00
|
|
|
switch (device)
|
|
|
|
{
|
|
|
|
case RETRO_DEVICE_JOYPAD:
|
2014-06-09 19:17:43 +00:00
|
|
|
return input_joypad_pressed(gx->joypad, port, binds[port], id);;
|
2013-07-04 18:52:53 +00:00
|
|
|
case RETRO_DEVICE_ANALOG:
|
2014-10-20 18:31:00 +00:00
|
|
|
return input_joypad_analog(gx->joypad, port, idx, id, binds[port]);
|
2013-07-04 18:52:53 +00:00
|
|
|
}
|
2014-10-05 16:00:43 +00:00
|
|
|
|
|
|
|
return 0;
|
2011-12-14 12:20:22 +00:00
|
|
|
}
|
|
|
|
|
2012-11-27 00:23:10 +00:00
|
|
|
static void gx_input_free_input(void *data)
|
2011-12-14 12:20:22 +00:00
|
|
|
{
|
2014-06-09 19:17:43 +00:00
|
|
|
gx_input_t *gx = (gx_input_t*)data;
|
2011-12-14 12:20:22 +00:00
|
|
|
|
2014-09-15 12:17:16 +00:00
|
|
|
if (!gx)
|
|
|
|
return;
|
|
|
|
|
2014-06-09 19:17:43 +00:00
|
|
|
if (gx->joypad)
|
|
|
|
gx->joypad->destroy();
|
2014-05-29 21:49:33 +00:00
|
|
|
|
2014-09-15 12:17:16 +00:00
|
|
|
free(gx);
|
2012-08-29 02:58:21 +00:00
|
|
|
}
|
|
|
|
|
2014-06-09 21:50:59 +00:00
|
|
|
static void *gx_input_init(void)
|
2014-06-09 19:17:43 +00:00
|
|
|
{
|
2015-03-20 21:32:09 +00:00
|
|
|
settings_t *settings = config_get_ptr();
|
2014-06-09 21:50:59 +00:00
|
|
|
gx_input_t *gx = (gx_input_t*)calloc(1, sizeof(*gx));
|
|
|
|
if (!gx)
|
|
|
|
return NULL;
|
|
|
|
|
2015-06-03 16:22:54 +00:00
|
|
|
gx->joypad = input_joypad_init_driver(settings->input.joypad_driver, gx);
|
2014-06-09 21:50:59 +00:00
|
|
|
|
|
|
|
return gx;
|
|
|
|
}
|
|
|
|
|
2012-08-09 01:54:27 +00:00
|
|
|
static void gx_input_poll(void *data)
|
2012-07-26 05:28:57 +00:00
|
|
|
{
|
2013-11-01 15:33:32 +00:00
|
|
|
gx_input_t *gx = (gx_input_t*)data;
|
2012-12-15 04:46:49 +00:00
|
|
|
|
2014-10-05 16:00:43 +00:00
|
|
|
if (gx && gx->joypad)
|
|
|
|
gx->joypad->poll();
|
2011-12-14 12:20:22 +00:00
|
|
|
}
|
|
|
|
|
2013-01-06 22:45:09 +00:00
|
|
|
static bool gx_input_key_pressed(void *data, int key)
|
|
|
|
{
|
2015-03-20 21:32:09 +00:00
|
|
|
settings_t *settings = config_get_ptr();
|
2015-03-21 04:42:49 +00:00
|
|
|
global_t *global = global_get_ptr();
|
|
|
|
gx_input_t *gx = (gx_input_t*)data;
|
|
|
|
return (global->lifecycle_state & (1ULL << key)) ||
|
2015-03-20 21:32:09 +00:00
|
|
|
input_joypad_pressed(gx->joypad, 0, settings->input.binds[0], key);
|
2013-01-06 22:45:09 +00:00
|
|
|
}
|
|
|
|
|
2013-11-02 20:16:57 +00:00
|
|
|
static uint64_t gx_input_get_capabilities(void *data)
|
|
|
|
{
|
2014-10-05 16:00:43 +00:00
|
|
|
(void)data;
|
2013-11-02 20:16:57 +00:00
|
|
|
|
2014-10-05 16:00:43 +00:00
|
|
|
return (1 << RETRO_DEVICE_JOYPAD) | (1 << RETRO_DEVICE_ANALOG);
|
2013-11-02 20:16:57 +00:00
|
|
|
}
|
|
|
|
|
2015-04-14 14:37:59 +00:00
|
|
|
static const input_device_driver_t *gx_input_get_joypad_driver(void *data)
|
2013-12-23 00:47:33 +00:00
|
|
|
{
|
2014-10-18 05:53:56 +00:00
|
|
|
gx_input_t *gx = (gx_input_t*)data;
|
2015-01-11 00:29:19 +00:00
|
|
|
if (!gx)
|
|
|
|
return NULL;
|
|
|
|
return gx->joypad;
|
2013-12-23 00:47:33 +00:00
|
|
|
}
|
2012-07-25 19:02:01 +00:00
|
|
|
|
2015-03-24 06:51:50 +00:00
|
|
|
static void gx_input_grab_mouse(void *data, bool state)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
(void)state;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool gx_input_set_rumble(void *data, unsigned port,
|
|
|
|
enum retro_rumble_effect effect, uint16_t strength)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
(void)port;
|
|
|
|
(void)effect;
|
|
|
|
(void)strength;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-06-19 01:45:23 +00:00
|
|
|
static bool gx_input_keyboard_mapping_is_blocked(void *data)
|
|
|
|
{
|
|
|
|
gx_input_t *gx = (gx_input_t*)data;
|
|
|
|
if (!gx)
|
|
|
|
return false;
|
|
|
|
return gx->blocked;
|
|
|
|
}
|
|
|
|
|
2015-06-22 06:01:13 +00:00
|
|
|
static void gx_input_keyboard_mapping_set_block(void *data, bool value)
|
2015-06-19 01:45:23 +00:00
|
|
|
{
|
|
|
|
gx_input_t *gx = (gx_input_t*)data;
|
|
|
|
if (!gx)
|
|
|
|
return;
|
|
|
|
gx->blocked = value;
|
|
|
|
}
|
|
|
|
|
2014-09-11 05:06:20 +00:00
|
|
|
input_driver_t input_gx = {
|
2013-11-02 20:16:57 +00:00
|
|
|
gx_input_init,
|
|
|
|
gx_input_poll,
|
|
|
|
gx_input_state,
|
|
|
|
gx_input_key_pressed,
|
|
|
|
gx_input_free_input,
|
2014-06-09 21:21:48 +00:00
|
|
|
NULL,
|
2013-11-02 23:27:58 +00:00
|
|
|
NULL,
|
2013-11-02 20:16:57 +00:00
|
|
|
gx_input_get_capabilities,
|
|
|
|
"gx",
|
2013-12-23 00:47:33 +00:00
|
|
|
|
2015-03-24 06:51:50 +00:00
|
|
|
gx_input_grab_mouse,
|
2015-05-19 17:33:58 +00:00
|
|
|
NULL,
|
2015-03-24 06:51:50 +00:00
|
|
|
gx_input_set_rumble,
|
2013-12-23 00:47:33 +00:00
|
|
|
gx_input_get_joypad_driver,
|
2015-06-19 01:45:23 +00:00
|
|
|
gx_input_keyboard_mapping_is_blocked,
|
|
|
|
gx_input_keyboard_mapping_set_block,
|
2013-12-23 00:47:33 +00:00
|
|
|
};
|