2012-03-05 01:15:27 +01:00
|
|
|
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
|
2012-01-08 01:08:18 +01:00
|
|
|
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
|
|
|
|
* Copyright (C) 2011-2012 - Daniel De Matteis
|
2012-01-05 12:37:27 +01:00
|
|
|
*
|
|
|
|
* Some code herein may be based on code found in BSNES.
|
|
|
|
*
|
|
|
|
* SSNES 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.
|
|
|
|
*
|
|
|
|
* SSNES 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 SSNES.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
2012-01-05 13:30:13 +01:00
|
|
|
#include <xtl.h>
|
2012-01-05 12:37:27 +01:00
|
|
|
#include "../driver.h"
|
2012-02-08 18:52:42 +01:00
|
|
|
#include "../general.h"
|
2012-01-05 12:37:27 +01:00
|
|
|
#include "../libsnes.hpp"
|
2012-03-05 01:00:09 +01:00
|
|
|
#include "xdk360_input.h"
|
2012-02-11 15:31:11 +01:00
|
|
|
#include "xdk360_video.h"
|
2012-02-08 18:52:42 +01:00
|
|
|
#include "shared.h"
|
2012-01-05 12:37:27 +01:00
|
|
|
|
2012-03-05 01:00:09 +01:00
|
|
|
static uint64_t state[4];
|
2012-02-13 15:53:50 +01:00
|
|
|
static unsigned pads_connected;
|
2012-01-05 12:37:27 +01:00
|
|
|
|
|
|
|
static void xdk360_input_poll(void *data)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
|
2012-02-13 15:53:50 +01:00
|
|
|
pads_connected = 0;
|
|
|
|
|
2012-01-22 22:45:32 +01:00
|
|
|
for (unsigned i = 0; i < 4; i++)
|
2012-02-13 15:53:50 +01:00
|
|
|
{
|
2012-03-05 01:00:09 +01:00
|
|
|
XINPUT_STATE state_tmp;
|
|
|
|
unsigned long retval = XInputGetState(i, &state_tmp);
|
2012-02-13 15:53:50 +01:00
|
|
|
pads_connected += (retval == ERROR_DEVICE_NOT_CONNECTED) ? 0 : 1;
|
2012-03-05 01:00:09 +01:00
|
|
|
state[i] = state_tmp.Gamepad.wButtons;
|
|
|
|
state[i] |= ((state_tmp.Gamepad.sThumbLX < -DEADZONE)) << 16;
|
|
|
|
state[i] |= ((state_tmp.Gamepad.sThumbLX > DEADZONE)) << 17;
|
|
|
|
state[i] |= ((state_tmp.Gamepad.sThumbLY > DEADZONE)) << 18;
|
|
|
|
state[i] |= ((state_tmp.Gamepad.sThumbLY < -DEADZONE)) << 19;
|
|
|
|
state[i] |= ((state_tmp.Gamepad.sThumbRX < -DEADZONE)) << 20;
|
|
|
|
state[i] |= ((state_tmp.Gamepad.sThumbRX > DEADZONE)) << 21;
|
|
|
|
state[i] |= ((state_tmp.Gamepad.sThumbRY > DEADZONE)) << 22;
|
|
|
|
state[i] |= ((state_tmp.Gamepad.sThumbRY < -DEADZONE)) << 23;
|
|
|
|
state[i] |= ((state_tmp.Gamepad.bLeftTrigger > 128 ? 1 : 0)) << 24;
|
|
|
|
state[i] |= ((state_tmp.Gamepad.bRightTrigger > 128 ? 1 : 0)) << 25;
|
2012-02-13 15:53:50 +01:00
|
|
|
}
|
2012-01-05 12:37:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int16_t xdk360_input_state(void *data, const struct snes_keybind **binds,
|
|
|
|
bool port, unsigned device,
|
|
|
|
unsigned index, unsigned id)
|
|
|
|
{
|
|
|
|
(void)data;
|
2012-02-13 15:53:50 +01:00
|
|
|
unsigned player;
|
|
|
|
uint64_t button;
|
|
|
|
|
|
|
|
player = 0;
|
2012-01-05 12:37:27 +01:00
|
|
|
|
|
|
|
if (device != SNES_DEVICE_JOYPAD)
|
|
|
|
return 0;
|
|
|
|
|
2012-02-13 15:53:50 +01:00
|
|
|
if (port == SNES_PORT_2)
|
2012-01-05 12:37:27 +01:00
|
|
|
{
|
2012-02-13 15:53:50 +01:00
|
|
|
if(pads_connected < 2)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
player = 1;
|
|
|
|
|
|
|
|
if (device == SNES_DEVICE_MULTITAP)
|
|
|
|
player += index;
|
2012-01-05 12:37:27 +01:00
|
|
|
}
|
|
|
|
|
2012-02-13 15:53:50 +01:00
|
|
|
button = binds[player][id].joykey;
|
|
|
|
|
2012-03-05 01:00:09 +01:00
|
|
|
return (state[player] & button) ? 1 : 0;
|
2012-01-05 12:37:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void xdk360_free_input(void *data)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void* xdk360_input_init(void)
|
|
|
|
{
|
|
|
|
return (void*)-1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool xdk360_key_pressed(void *data, int key)
|
|
|
|
{
|
|
|
|
(void)data;
|
2012-03-05 01:00:09 +01:00
|
|
|
XINPUT_STATE state;
|
2012-02-13 02:35:01 +01:00
|
|
|
bool retval;
|
|
|
|
|
2012-03-05 01:00:09 +01:00
|
|
|
XInputGetState(0, &state);
|
2012-02-13 02:35:01 +01:00
|
|
|
retval = false;
|
2012-02-08 18:52:42 +01:00
|
|
|
|
|
|
|
switch(key)
|
|
|
|
{
|
2012-02-13 02:35:01 +01:00
|
|
|
case SSNES_FAST_FORWARD_HOLD_KEY:
|
2012-03-05 01:00:09 +01:00
|
|
|
return ((state.Gamepad.sThumbRY < -DEADZONE) && !(state.Gamepad.bRightTrigger > 128));
|
2012-02-13 02:35:01 +01:00
|
|
|
case SSNES_LOAD_STATE_KEY:
|
2012-03-05 01:00:09 +01:00
|
|
|
return ((state.Gamepad.sThumbRY > DEADZONE) && (state.Gamepad.bRightTrigger > 128));
|
2012-02-13 02:35:01 +01:00
|
|
|
case SSNES_SAVE_STATE_KEY:
|
2012-03-05 01:00:09 +01:00
|
|
|
return ((state.Gamepad.sThumbRY < -DEADZONE) && (state.Gamepad.bRightTrigger > 128));
|
2012-02-13 02:35:01 +01:00
|
|
|
case SSNES_STATE_SLOT_PLUS:
|
2012-03-05 01:00:09 +01:00
|
|
|
return ((state.Gamepad.sThumbRX > DEADZONE) && (state.Gamepad.bRightTrigger > 128));
|
2012-02-13 02:35:01 +01:00
|
|
|
case SSNES_STATE_SLOT_MINUS:
|
2012-03-05 01:00:09 +01:00
|
|
|
return ((state.Gamepad.sThumbRX < -DEADZONE) && (state.Gamepad.bRightTrigger > 128));
|
2012-02-13 02:35:01 +01:00
|
|
|
case SSNES_FRAMEADVANCE:
|
|
|
|
if(g_console.frame_advance_enable)
|
|
|
|
{
|
2012-02-13 16:45:08 +01:00
|
|
|
g_console.menu_enable = true;
|
2012-02-13 02:35:01 +01:00
|
|
|
g_console.ingame_menu_enable = true;
|
2012-02-14 02:41:35 +01:00
|
|
|
g_console.mode_switch = MODE_MENU;
|
2012-02-13 02:35:01 +01:00
|
|
|
}
|
2012-02-14 02:41:35 +01:00
|
|
|
return false;
|
2012-02-13 02:35:01 +01:00
|
|
|
case SSNES_REWIND:
|
2012-03-05 01:00:09 +01:00
|
|
|
return ((state.Gamepad.sThumbRY > DEADZONE) && !(state.Gamepad.bRightTrigger > 128));
|
2012-02-13 02:35:01 +01:00
|
|
|
case SSNES_QUIT_KEY:
|
2012-02-13 16:45:08 +01:00
|
|
|
if(IS_TIMER_EXPIRED())
|
2012-02-13 02:35:01 +01:00
|
|
|
{
|
2012-03-05 01:00:09 +01:00
|
|
|
uint32_t left_thumb_pressed = (state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_THUMB);
|
|
|
|
uint32_t right_thumb_pressed = (state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB);
|
2012-02-13 02:35:01 +01:00
|
|
|
|
|
|
|
g_console.menu_enable = right_thumb_pressed && left_thumb_pressed && IS_TIMER_EXPIRED();
|
|
|
|
g_console.ingame_menu_enable = right_thumb_pressed && !left_thumb_pressed;
|
|
|
|
|
2012-02-13 16:45:08 +01:00
|
|
|
if(g_console.menu_enable || (g_console.ingame_menu_enable
|
|
|
|
&& !g_console.menu_enable))
|
2012-02-13 02:35:01 +01:00
|
|
|
{
|
|
|
|
g_console.mode_switch = MODE_MENU;
|
2012-02-13 16:45:08 +01:00
|
|
|
SET_TIMER_EXPIRATION(30);
|
2012-02-13 02:35:01 +01:00
|
|
|
retval = g_console.menu_enable;
|
|
|
|
}
|
2012-02-13 16:45:08 +01:00
|
|
|
|
|
|
|
retval = g_console.ingame_menu_enable ? g_console.ingame_menu_enable : g_console.menu_enable;
|
2012-02-13 02:35:01 +01:00
|
|
|
}
|
2012-02-08 18:52:42 +01:00
|
|
|
}
|
2012-01-05 12:37:27 +01:00
|
|
|
|
2012-02-13 02:35:01 +01:00
|
|
|
return retval;
|
2012-01-05 12:37:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const input_driver_t input_xdk360 = {
|
|
|
|
xdk360_input_init,
|
|
|
|
xdk360_input_poll,
|
|
|
|
xdk360_input_state,
|
|
|
|
xdk360_key_pressed,
|
|
|
|
xdk360_free_input,
|
|
|
|
"xdk360"};
|