RetroArch/input/drivers/gx_input.c

127 lines
2.9 KiB
C
Raw Normal View History

2012-04-21 23:13:50 +02:00
/* RetroArch - A frontend for libretro.
2014-01-01 01:50:59 +01:00
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
2015-01-07 17:46:50 +01:00
* Copyright (C) 2011-2015 - Daniel De Matteis
* Copyright (C) 2012-2015 - Michael Lelli
2011-12-14 13:20:22 +01:00
*
2012-04-21 23:13:50 +02:00
* RetroArch is free software: you can redistribute it and/or modify it under the terms
2011-12-14 13:20:22 +01: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 23:13:50 +02:00
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
2011-12-14 13:20:22 +01: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 23:31:57 +02:00
* You should have received a copy of the GNU General Public License along with RetroArch.
2011-12-14 13:20:22 +01:00
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdint.h>
2012-01-03 12:11:02 +01:00
#include <string.h>
#include <math.h>
2011-12-14 13:20:22 +01:00
#ifndef M_PI
#define M_PI 3.14159265358979323846264338327
#endif
2015-01-12 06:16:52 +01:00
#include "../../driver.h"
#include "../../libretro.h"
2011-12-14 13:20:22 +01:00
#include <stdlib.h>
#ifndef MAX_PADS
#define MAX_PADS 4
#endif
typedef struct gx_input
{
2014-06-09 21:17:43 +02:00
const rarch_joypad_driver_t *joypad;
} gx_input_t;
2012-04-11 04:22:41 +02:00
static int16_t gx_input_state(void *data, const struct retro_keybind **binds,
unsigned port, unsigned device,
2014-10-20 20:31:00 +02:00
unsigned idx, unsigned id)
2011-12-14 13:20:22 +01:00
{
2014-06-09 21:17:43 +02:00
gx_input_t *gx = (gx_input_t*)data;
if (port >= MAX_PADS || !gx)
return 0;
2011-12-14 13:20:22 +01:00
2013-07-04 14:52:53 -04:00
switch (device)
{
case RETRO_DEVICE_JOYPAD:
2014-06-09 21:17:43 +02:00
return input_joypad_pressed(gx->joypad, port, binds[port], id);;
2013-07-04 14:52:53 -04:00
case RETRO_DEVICE_ANALOG:
2014-10-20 20:31:00 +02:00
return input_joypad_analog(gx->joypad, port, idx, id, binds[port]);
2013-07-04 14:52:53 -04:00
}
return 0;
2011-12-14 13:20:22 +01:00
}
static void gx_input_free_input(void *data)
2011-12-14 13:20:22 +01:00
{
2014-06-09 21:17:43 +02:00
gx_input_t *gx = (gx_input_t*)data;
2011-12-14 13:20:22 +01:00
if (!gx)
return;
2014-06-09 21:17:43 +02:00
if (gx->joypad)
gx->joypad->destroy();
free(gx);
}
static void *gx_input_init(void)
2014-06-09 21:17:43 +02:00
{
gx_input_t *gx = (gx_input_t*)calloc(1, sizeof(*gx));
if (!gx)
return NULL;
gx->joypad = input_joypad_init_driver(g_settings.input.joypad_driver);
return gx;
}
static void gx_input_poll(void *data)
{
gx_input_t *gx = (gx_input_t*)data;
2012-12-15 05:46:49 +01:00
if (gx && gx->joypad)
gx->joypad->poll();
2011-12-14 13:20:22 +01:00
}
2013-01-06 23:45:09 +01:00
static bool gx_input_key_pressed(void *data, int key)
{
gx_input_t *gx = (gx_input_t*)data;
return (g_extern.lifecycle_state & (1ULL << key)) ||
input_joypad_pressed(gx->joypad, 0, g_settings.input.binds[0], key);
2013-01-06 23:45:09 +01:00
}
static uint64_t gx_input_get_capabilities(void *data)
{
(void)data;
return (1 << RETRO_DEVICE_JOYPAD) | (1 << RETRO_DEVICE_ANALOG);
}
static const rarch_joypad_driver_t *gx_input_get_joypad_driver(void *data)
{
gx_input_t *gx = (gx_input_t*)data;
if (!gx)
return NULL;
return gx->joypad;
}
2014-09-11 07:06:20 +02:00
input_driver_t input_gx = {
gx_input_init,
gx_input_poll,
gx_input_state,
gx_input_key_pressed,
gx_input_free_input,
NULL,
NULL,
gx_input_get_capabilities,
"gx",
NULL,
NULL,
gx_input_get_joypad_driver,
};