RetroArch/input/drivers/ctr_input.c

172 lines
3.8 KiB
C
Raw Normal View History

2015-04-01 21:14:13 +00:00
/* RetroArch - A frontend for libretro.
2015-04-01 23:43:28 +00:00
* Copyright (C) 2014-2015 - Ali Bouhlel
2015-04-01 21:14:13 +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/>.
*/
2015-04-08 20:35:10 +00:00
#include <stdint.h>
#include <stdlib.h>
#include <boolean.h>
2015-04-01 21:14:13 +00:00
#include "../../driver.h"
2015-04-08 20:35:10 +00:00
#include "../../libretro.h"
#include "../../general.h"
#include "../input_config.h"
#include "../input_joypad_driver.h"
2015-04-08 20:35:10 +00:00
#define MAX_PADS 1
2015-04-08 20:35:10 +00:00
typedef struct ctr_input
2015-04-01 21:14:13 +00:00
{
bool blocked;
const input_device_driver_t *joypad;
2015-04-08 20:35:10 +00:00
} ctr_input_t;
2015-04-01 21:14:13 +00:00
uint64_t lifecycle_state;
static void ctr_input_poll(void *data)
2015-04-08 20:35:10 +00:00
{
ctr_input_t *ctr = (ctr_input_t*)data;
2015-04-08 20:35:10 +00:00
if (ctr->joypad)
ctr->joypad->poll();
2015-04-01 21:14:13 +00:00
}
2015-04-08 20:35:10 +00:00
static int16_t ctr_input_state(void *data, const struct retro_keybind **binds,
unsigned port, unsigned device,
unsigned idx, unsigned id)
2015-04-01 21:14:13 +00:00
{
2015-04-08 20:35:10 +00:00
ctr_input_t *ctr = (ctr_input_t*)data;
2015-04-01 21:14:13 +00:00
if (port > 0)
return 0;
switch (device)
{
case RETRO_DEVICE_JOYPAD:
2015-04-08 20:35:10 +00:00
return input_joypad_pressed(ctr->joypad, port, binds[port], id);
case RETRO_DEVICE_ANALOG:
2015-04-08 20:35:10 +00:00
return input_joypad_analog(ctr->joypad, port, idx, id, binds[port]);
}
2015-04-01 21:14:13 +00:00
return 0;
}
2015-04-08 20:35:10 +00:00
static void ctr_input_free_input(void *data)
2015-04-01 21:14:13 +00:00
{
2015-04-08 20:35:10 +00:00
ctr_input_t *ctr = (ctr_input_t*)data;
if (ctr && ctr->joypad)
ctr->joypad->destroy();
2015-04-01 21:14:13 +00:00
2015-04-08 20:35:10 +00:00
free(data);
2015-04-01 21:14:13 +00:00
}
2015-04-08 20:35:10 +00:00
static void* ctr_input_initialize(void)
2015-04-01 21:14:13 +00:00
{
2015-04-08 20:35:10 +00:00
settings_t *settings = config_get_ptr();
ctr_input_t *ctr = (ctr_input_t*)calloc(1, sizeof(*ctr));
if (!ctr)
return NULL;
ctr->joypad = input_joypad_init_driver(settings->input.joypad_driver, ctr);
2015-04-08 20:35:10 +00:00
return ctr;
2015-04-01 21:14:13 +00:00
}
2015-11-07 19:59:12 +00:00
static bool ctr_input_key_pressed(void *data, int key)
2015-04-01 21:14:13 +00:00
{
2015-04-08 20:35:10 +00:00
settings_t *settings = config_get_ptr();
ctr_input_t *ctr = (ctr_input_t*)data;
2015-04-01 21:14:13 +00:00
2015-10-23 06:34:15 +00:00
if (input_joypad_pressed(ctr->joypad, 0, settings->input.binds[0], key))
return true;
2015-10-23 06:34:15 +00:00
return false;
2015-07-17 01:31:51 +00:00
}
2015-11-07 19:59:12 +00:00
static bool ctr_input_meta_key_pressed(void *data, int key)
2015-07-17 01:31:51 +00:00
{
2015-10-23 06:34:15 +00:00
if (BIT64_GET(lifecycle_state, key))
return true;
2015-10-23 06:34:15 +00:00
return false;
2015-04-08 20:35:10 +00:00
}
2015-04-01 21:14:13 +00:00
2015-04-08 20:35:10 +00:00
static uint64_t ctr_input_get_capabilities(void *data)
{
(void)data;
return (1 << RETRO_DEVICE_JOYPAD) | (1 << RETRO_DEVICE_ANALOG);
2015-04-01 21:14:13 +00:00
}
static const input_device_driver_t *ctr_input_get_joypad_driver(void *data)
2015-04-01 21:14:13 +00:00
{
2015-04-08 20:35:10 +00:00
ctr_input_t *ctr = (ctr_input_t*)data;
if (ctr)
return ctr->joypad;
return NULL;
2015-04-01 21:14:13 +00:00
}
static void ctr_input_grab_mouse(void *data, bool state)
2015-04-01 21:14:13 +00:00
{
(void)data;
(void)state;
}
static bool ctr_input_set_rumble(void *data, unsigned port,
2015-04-01 21:14:13 +00:00
enum retro_rumble_effect effect, uint16_t strength)
{
(void)data;
(void)port;
(void)effect;
(void)strength;
return false;
}
static bool ctr_input_keyboard_mapping_is_blocked(void *data)
{
ctr_input_t *ctr = (ctr_input_t*)data;
if (!ctr)
return false;
return ctr->blocked;
}
static void ctr_input_keyboard_mapping_set_block(void *data, bool value)
{
ctr_input_t *ctr = (ctr_input_t*)data;
if (!ctr)
return;
ctr->blocked = value;
}
2015-04-01 21:14:13 +00:00
input_driver_t input_ctr = {
2015-04-08 20:35:10 +00:00
ctr_input_initialize,
ctr_input_poll,
ctr_input_state,
ctr_input_key_pressed,
2015-07-17 01:31:51 +00:00
ctr_input_meta_key_pressed,
ctr_input_free_input,
2015-04-08 20:35:10 +00:00
NULL,
2015-04-01 21:14:13 +00:00
NULL,
ctr_input_get_capabilities,
2015-04-01 21:14:13 +00:00
"ctr",
ctr_input_grab_mouse,
NULL,
ctr_input_set_rumble,
2015-04-08 20:35:10 +00:00
ctr_input_get_joypad_driver,
2015-11-16 01:39:38 +00:00
NULL,
ctr_input_keyboard_mapping_is_blocked,
ctr_input_keyboard_mapping_set_block,
2015-04-01 21:14:13 +00:00
};