2008-12-11 18:38:29 +01:00
|
|
|
/****************************************************************************
|
2009-04-15 17:33:51 +02:00
|
|
|
* gx_input.c
|
2008-08-07 14:26:07 +02:00
|
|
|
*
|
2008-12-11 18:38:29 +01:00
|
|
|
* Genesis Plus GX input support
|
2008-08-07 14:26:07 +02:00
|
|
|
*
|
2009-05-13 16:26:55 +02:00
|
|
|
* Eke-Eke (2008,2009)
|
2008-08-07 14:26:07 +02:00
|
|
|
*
|
2008-12-11 18:38:29 +01:00
|
|
|
* This program 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 Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
2008-08-07 14:26:07 +02:00
|
|
|
*
|
2008-12-11 18:38:29 +01:00
|
|
|
* This program 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 this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2008-08-07 14:26:07 +02:00
|
|
|
*
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include "shared.h"
|
|
|
|
#include "font.h"
|
2009-05-13 16:26:55 +02:00
|
|
|
#include "gui.h"
|
2008-08-07 14:26:07 +02:00
|
|
|
|
2009-04-24 01:24:40 +02:00
|
|
|
/* Analog sticks sensitivity */
|
2009-04-23 03:01:07 +02:00
|
|
|
#define ANALOG_SENSITIVITY 30
|
|
|
|
|
2009-04-24 01:24:40 +02:00
|
|
|
/* Delay before held keys triggering */
|
|
|
|
#define HELD_DELAY 18
|
|
|
|
|
|
|
|
/* Direction & selection update speed when a key is being held */
|
|
|
|
/* the less is the value, faster is the key update */
|
|
|
|
#define HELD_SPEED 4
|
|
|
|
|
2009-04-23 03:01:07 +02:00
|
|
|
/* Menu request flag */
|
|
|
|
u8 ConfigRequested = 0;
|
|
|
|
|
2009-04-24 01:24:40 +02:00
|
|
|
/* Configurable Genesis keys */
|
|
|
|
#define KEY_BUTTONA 0
|
2008-08-07 14:26:07 +02:00
|
|
|
#define KEY_BUTTONB 1
|
|
|
|
#define KEY_BUTTONC 2
|
|
|
|
#define KEY_START 3
|
2009-05-03 20:55:01 +02:00
|
|
|
#define KEY_BUTTONX 4 /* 6-buttons only */
|
|
|
|
#define KEY_BUTTONY 5 /* 6-buttons only */
|
|
|
|
#define KEY_BUTTONZ 6 /* 6-buttons only */
|
|
|
|
#define KEY_MODE 7 /* 6-buttons only */
|
2008-08-07 14:26:07 +02:00
|
|
|
|
|
|
|
static const char *keys_name[MAX_KEYS] =
|
|
|
|
{
|
|
|
|
"Button A",
|
|
|
|
"Button B",
|
|
|
|
"Button C",
|
2009-04-24 01:24:40 +02:00
|
|
|
"START Button",
|
2008-08-07 14:26:07 +02:00
|
|
|
"Button X",
|
|
|
|
"Button Y",
|
|
|
|
"Button Z",
|
2009-04-24 01:24:40 +02:00
|
|
|
"MODE Button"
|
2008-08-07 14:26:07 +02:00
|
|
|
};
|
|
|
|
|
2009-04-24 01:24:40 +02:00
|
|
|
static int held_cnt = 0;
|
|
|
|
|
|
|
|
|
2008-08-07 14:26:07 +02:00
|
|
|
#ifdef HW_RVL
|
|
|
|
|
|
|
|
#define PAD_UP 0
|
|
|
|
#define PAD_DOWN 1
|
|
|
|
#define PAD_LEFT 2
|
|
|
|
#define PAD_RIGHT 3
|
|
|
|
|
2009-04-24 01:24:40 +02:00
|
|
|
/* default directions mapping */
|
2008-08-07 14:26:07 +02:00
|
|
|
static u32 wpad_dirmap[3][4] =
|
|
|
|
{
|
2009-05-04 23:43:16 +02:00
|
|
|
{WPAD_BUTTON_RIGHT, WPAD_BUTTON_LEFT, WPAD_BUTTON_UP, WPAD_BUTTON_DOWN}, /* WIIMOTE */
|
|
|
|
{WPAD_BUTTON_UP, WPAD_BUTTON_DOWN, WPAD_BUTTON_LEFT, WPAD_BUTTON_RIGHT}, /* WIIMOTE + NUNCHUK */
|
2008-12-10 19:16:30 +01:00
|
|
|
{WPAD_CLASSIC_BUTTON_UP, WPAD_CLASSIC_BUTTON_DOWN, WPAD_CLASSIC_BUTTON_LEFT, WPAD_CLASSIC_BUTTON_RIGHT} /* CLASSIC */
|
2008-08-07 14:26:07 +02:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2009-04-23 03:01:07 +02:00
|
|
|
/***************************************************************************************/
|
|
|
|
/* Gamecube PAD support */
|
|
|
|
/***************************************************************************************/
|
|
|
|
static void pad_config(int chan, int max_keys)
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
2009-04-23 03:01:07 +02:00
|
|
|
int i;
|
|
|
|
u16 p,key;
|
2008-08-07 14:26:07 +02:00
|
|
|
char msg[30];
|
|
|
|
|
2009-05-19 18:14:43 +02:00
|
|
|
/* reset VSYNC callback */
|
2009-05-07 15:00:57 +02:00
|
|
|
VIDEO_SetPostRetraceCallback(NULL);
|
|
|
|
VIDEO_Flush();
|
|
|
|
|
2009-04-23 03:01:07 +02:00
|
|
|
/* Check if PAD is connected */
|
|
|
|
if (!(PAD_ScanPads() & (1<<chan)))
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
2009-05-19 18:14:43 +02:00
|
|
|
/* restore inputs update callback */
|
|
|
|
VIDEO_SetPostRetraceCallback(gx_input_UpdateMenu);
|
|
|
|
VIDEO_Flush();
|
2009-04-23 03:01:07 +02:00
|
|
|
sprintf(msg, "PAD #%d is not connected !", chan+1);
|
2009-05-20 17:11:06 +02:00
|
|
|
GUI_WaitPrompt("Error",msg);
|
2009-05-19 18:14:43 +02:00
|
|
|
return;
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
|
|
|
|
2009-04-23 03:01:07 +02:00
|
|
|
/* Configure each keys */
|
|
|
|
for (i=0; i<max_keys; i++)
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
|
|
|
/* remove any pending keys */
|
2009-04-23 03:01:07 +02:00
|
|
|
while (PAD_ButtonsHeld(chan))
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
|
|
|
VIDEO_WaitVSync();
|
|
|
|
PAD_ScanPads();
|
|
|
|
}
|
|
|
|
|
2009-04-23 03:01:07 +02:00
|
|
|
/* wait for user input */
|
2009-05-19 18:14:43 +02:00
|
|
|
sprintf(msg,"Press key for %s\n(Z to return)",keys_name[i]);
|
2009-05-26 15:14:33 +02:00
|
|
|
GUI_MsgBoxUpdate(0,msg);
|
2008-08-07 14:26:07 +02:00
|
|
|
|
2009-04-23 03:01:07 +02:00
|
|
|
key = 0;
|
|
|
|
while (!key)
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
2009-04-23 03:01:07 +02:00
|
|
|
/* update PAD status */
|
2008-08-07 14:26:07 +02:00
|
|
|
VIDEO_WaitVSync();
|
|
|
|
PAD_ScanPads();
|
2009-04-23 03:01:07 +02:00
|
|
|
p = PAD_ButtonsDown(chan);
|
|
|
|
|
|
|
|
/* find pressed key */
|
|
|
|
if (p & PAD_TRIGGER_Z) key = 0xff;
|
|
|
|
else if (p & PAD_BUTTON_A) key = PAD_BUTTON_A;
|
|
|
|
else if (p & PAD_BUTTON_B) key = PAD_BUTTON_B;
|
|
|
|
else if (p & PAD_BUTTON_X) key = PAD_BUTTON_X;
|
|
|
|
else if (p & PAD_BUTTON_Y) key = PAD_BUTTON_Y;
|
|
|
|
else if (p & PAD_TRIGGER_R) key = PAD_TRIGGER_R;
|
|
|
|
else if (p & PAD_TRIGGER_L) key = PAD_TRIGGER_L;
|
|
|
|
else if (p & PAD_BUTTON_START) key = PAD_BUTTON_START;
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
2009-04-23 03:01:07 +02:00
|
|
|
|
|
|
|
/* update key mapping */
|
|
|
|
if (key !=0xff) config.pad_keymap[chan][i] = key;
|
2009-05-07 15:00:57 +02:00
|
|
|
else break;
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
2009-04-23 03:01:07 +02:00
|
|
|
|
2009-05-02 17:00:13 +02:00
|
|
|
/* remove any pending keys */
|
|
|
|
while (PAD_ButtonsHeld(chan))
|
|
|
|
{
|
|
|
|
VIDEO_WaitVSync();
|
|
|
|
PAD_ScanPads();
|
|
|
|
}
|
|
|
|
|
2009-04-24 01:24:40 +02:00
|
|
|
/* restore inputs update callback */
|
|
|
|
VIDEO_SetPostRetraceCallback(gx_input_UpdateMenu);
|
2009-04-23 03:01:07 +02:00
|
|
|
VIDEO_Flush();
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
|
|
|
|
2009-04-23 03:01:07 +02:00
|
|
|
static void pad_update(s8 chan, u8 i)
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
|
|
|
/* get PAD status */
|
2009-04-23 03:01:07 +02:00
|
|
|
s8 x = PAD_StickX (chan);
|
|
|
|
s8 y = PAD_StickY (chan);
|
|
|
|
u16 p = PAD_ButtonsHeld(chan);
|
2008-08-10 22:40:04 +02:00
|
|
|
|
2009-04-23 03:01:07 +02:00
|
|
|
/* Soft RESET */
|
2008-08-07 14:26:07 +02:00
|
|
|
if ((p & PAD_TRIGGER_L) && (p & PAD_TRIGGER_Z))
|
|
|
|
{
|
|
|
|
set_softreset();
|
|
|
|
}
|
|
|
|
|
2009-04-23 03:01:07 +02:00
|
|
|
/* Retrieve current key mapping */
|
|
|
|
u16 pad_keymap[MAX_KEYS];
|
|
|
|
memcpy(pad_keymap, config.pad_keymap[chan], MAX_KEYS * sizeof(u16));
|
|
|
|
|
|
|
|
/* Generic buttons */
|
2008-08-07 14:26:07 +02:00
|
|
|
if (p & pad_keymap[KEY_BUTTONA]) input.pad[i] |= INPUT_A;
|
|
|
|
if (p & pad_keymap[KEY_BUTTONB]) input.pad[i] |= INPUT_B;
|
|
|
|
if (p & pad_keymap[KEY_BUTTONC]) input.pad[i] |= INPUT_C;
|
|
|
|
if (p & pad_keymap[KEY_BUTTONX]) input.pad[i] |= INPUT_X;
|
|
|
|
if (p & pad_keymap[KEY_BUTTONY]) input.pad[i] |= INPUT_Y;
|
|
|
|
if (p & pad_keymap[KEY_BUTTONZ]) input.pad[i] |= INPUT_Z;
|
2009-04-23 03:01:07 +02:00
|
|
|
if (p & pad_keymap[KEY_START]) input.pad[i] |= INPUT_START;
|
2008-08-07 14:26:07 +02:00
|
|
|
|
2009-04-23 03:01:07 +02:00
|
|
|
/* Analog devices */
|
2008-08-07 14:26:07 +02:00
|
|
|
if (input.dev[i] == DEVICE_LIGHTGUN)
|
|
|
|
{
|
2009-04-23 03:01:07 +02:00
|
|
|
/* Lightgun cursor position (x,y) */
|
|
|
|
input.analog[i-4][0] += x / ANALOG_SENSITIVITY;
|
|
|
|
input.analog[i-4][1] -= y / ANALOG_SENSITIVITY;
|
2008-08-10 22:40:04 +02:00
|
|
|
if (input.analog[i-4][0] < 0) input.analog[i-4][0] = 0;
|
|
|
|
else if (input.analog[i-4][0] > bitmap.viewport.w) input.analog[i-4][0] = bitmap.viewport.w;
|
|
|
|
if (input.analog[i-4][1] < 0) input.analog[i-4][1] = 0;
|
|
|
|
else if (input.analog[i-4][1] > bitmap.viewport.h) input.analog[i-4][1] = bitmap.viewport.h;
|
|
|
|
}
|
2008-08-07 14:26:07 +02:00
|
|
|
else if ((system_hw == SYSTEM_PICO) && (i == 0))
|
|
|
|
{
|
2009-04-23 03:01:07 +02:00
|
|
|
/* PEN tablet position (x,y) */
|
|
|
|
input.analog[0][0] += x / ANALOG_SENSITIVITY;
|
|
|
|
input.analog[0][1] -= y / ANALOG_SENSITIVITY;
|
2008-08-10 22:40:04 +02:00
|
|
|
if (input.analog[0][0] < 0x17c) input.analog[0][0] = 0x17c;
|
|
|
|
else if (input.analog[0][0] > 0x3c) input.analog[0][0] = 0x3c;
|
|
|
|
if (input.analog[0][1] < 0x1fc) input.analog[0][1] = 0x1fc;
|
|
|
|
else if (input.analog[0][1] > 0x3f3) input.analog[0][1] = 0x3f3;
|
|
|
|
}
|
|
|
|
else if (input.dev[i] == DEVICE_MOUSE)
|
|
|
|
{
|
2009-04-23 03:01:07 +02:00
|
|
|
/* MOUSE relative movement (-255,255) */
|
|
|
|
input.analog[2][0] = (x / ANALOG_SENSITIVITY) * 2;
|
|
|
|
input.analog[2][1] = (y / ANALOG_SENSITIVITY) * 2;
|
|
|
|
if (config.invert_mouse) input.analog[2][1] = -input.analog[2][1];
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
|
|
|
|
2009-04-23 03:01:07 +02:00
|
|
|
/* Gamepad device */
|
2008-08-10 22:40:04 +02:00
|
|
|
else
|
|
|
|
{
|
2009-04-23 03:01:07 +02:00
|
|
|
if ((p & PAD_BUTTON_UP) || (y > ANALOG_SENSITIVITY)) input.pad[i] |= INPUT_UP;
|
|
|
|
else if ((p & PAD_BUTTON_DOWN) || (y < -ANALOG_SENSITIVITY)) input.pad[i] |= INPUT_DOWN;
|
|
|
|
if ((p & PAD_BUTTON_LEFT) || (x < -ANALOG_SENSITIVITY)) input.pad[i] |= INPUT_LEFT;
|
|
|
|
else if ((p & PAD_BUTTON_RIGHT) || (x > ANALOG_SENSITIVITY)) input.pad[i] |= INPUT_RIGHT;
|
2008-08-10 22:40:04 +02:00
|
|
|
}
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
|
|
|
|
2009-04-23 03:01:07 +02:00
|
|
|
|
|
|
|
/***************************************************************************************/
|
|
|
|
/* Wii WPAD support */
|
|
|
|
/***************************************************************************************/
|
2008-08-07 14:26:07 +02:00
|
|
|
#ifdef HW_RVL
|
|
|
|
|
2009-04-23 03:01:07 +02:00
|
|
|
static s8 WPAD_StickX(WPADData *data,u8 right)
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
|
|
|
float mag = 0.0;
|
|
|
|
float ang = 0.0;
|
|
|
|
|
|
|
|
switch (data->exp.type)
|
|
|
|
{
|
|
|
|
case WPAD_EXP_NUNCHUK:
|
|
|
|
case WPAD_EXP_GUITARHERO3:
|
|
|
|
if (right == 0)
|
|
|
|
{
|
|
|
|
mag = data->exp.nunchuk.js.mag;
|
|
|
|
ang = data->exp.nunchuk.js.ang;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WPAD_EXP_CLASSIC:
|
|
|
|
if (right == 0)
|
|
|
|
{
|
|
|
|
mag = data->exp.classic.ljs.mag;
|
|
|
|
ang = data->exp.classic.ljs.ang;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mag = data->exp.classic.rjs.mag;
|
|
|
|
ang = data->exp.classic.rjs.ang;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* calculate X value (angle need to be converted into radian) */
|
|
|
|
if (mag > 1.0) mag = 1.0;
|
|
|
|
else if (mag < -1.0) mag = -1.0;
|
2009-04-21 17:20:15 +02:00
|
|
|
double val = mag * sin(M_PI * ang/180.0f);
|
2008-08-07 14:26:07 +02:00
|
|
|
|
|
|
|
return (s8)(val * 128.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-23 03:01:07 +02:00
|
|
|
static s8 WPAD_StickY(WPADData *data, u8 right)
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
|
|
|
float mag = 0.0;
|
|
|
|
float ang = 0.0;
|
|
|
|
|
|
|
|
switch (data->exp.type)
|
|
|
|
{
|
|
|
|
case WPAD_EXP_NUNCHUK:
|
|
|
|
case WPAD_EXP_GUITARHERO3:
|
|
|
|
if (right == 0)
|
|
|
|
{
|
|
|
|
mag = data->exp.nunchuk.js.mag;
|
|
|
|
ang = data->exp.nunchuk.js.ang;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WPAD_EXP_CLASSIC:
|
|
|
|
if (right == 0)
|
|
|
|
{
|
|
|
|
mag = data->exp.classic.ljs.mag;
|
|
|
|
ang = data->exp.classic.ljs.ang;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mag = data->exp.classic.rjs.mag;
|
|
|
|
ang = data->exp.classic.rjs.ang;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* calculate X value (angle need to be converted into radian) */
|
|
|
|
if (mag > 1.0) mag = 1.0;
|
|
|
|
else if (mag < -1.0) mag = -1.0;
|
2009-04-21 17:20:15 +02:00
|
|
|
double val = mag * cos(M_PI * ang/180.0f);
|
2008-08-07 14:26:07 +02:00
|
|
|
|
|
|
|
return (s8)(val * 128.0f);
|
|
|
|
}
|
|
|
|
|
2009-04-23 03:01:07 +02:00
|
|
|
static void wpad_config(u8 chan, u8 exp, u8 max_keys)
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
2009-04-23 03:01:07 +02:00
|
|
|
int i;
|
2008-08-07 14:26:07 +02:00
|
|
|
char msg[30];
|
2009-04-23 03:01:07 +02:00
|
|
|
u32 key,p = 255;
|
2008-08-07 14:26:07 +02:00
|
|
|
|
2009-05-19 18:14:43 +02:00
|
|
|
/* remove inputs update callback */
|
2009-05-07 15:00:57 +02:00
|
|
|
VIDEO_SetPostRetraceCallback(NULL);
|
|
|
|
VIDEO_Flush();
|
|
|
|
|
2009-04-23 03:01:07 +02:00
|
|
|
/* Check if device is connected */
|
|
|
|
WPAD_Probe(chan, &p);
|
|
|
|
if (((exp > WPAD_EXP_NONE) && (p != exp)) || (p == 255))
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
2009-05-19 18:14:43 +02:00
|
|
|
/* restore inputs update callback */
|
|
|
|
VIDEO_SetPostRetraceCallback(gx_input_UpdateMenu);
|
|
|
|
VIDEO_Flush();
|
|
|
|
|
2009-04-23 03:01:07 +02:00
|
|
|
if (exp == WPAD_EXP_NONE) sprintf(msg, "WIIMOTE #%d is not connected !", chan+1);
|
|
|
|
if (exp == WPAD_EXP_NUNCHUK) sprintf(msg, "NUNCHUK #%d is not connected !", chan+1);
|
|
|
|
if (exp == WPAD_EXP_CLASSIC) sprintf(msg, "CLASSIC #%d is not connected !", chan+1);
|
2009-05-20 17:11:06 +02:00
|
|
|
GUI_WaitPrompt("Error",msg);
|
2009-05-19 18:14:43 +02:00
|
|
|
return;
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* loop on each mapped keys */
|
2009-04-23 03:01:07 +02:00
|
|
|
for (i=0; i<max_keys; i++)
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
|
|
|
/* remove any pending buttons */
|
2009-04-23 03:01:07 +02:00
|
|
|
while (WPAD_ButtonsHeld(chan))
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
|
|
|
WPAD_ScanPads();
|
|
|
|
VIDEO_WaitVSync();
|
|
|
|
}
|
|
|
|
|
2009-04-23 03:01:07 +02:00
|
|
|
/* wait for user input */
|
2009-05-19 18:14:43 +02:00
|
|
|
sprintf(msg,"Press key for %s\n(HOME to return)",keys_name[i]);
|
2009-05-26 15:14:33 +02:00
|
|
|
GUI_MsgBoxUpdate(0,msg);
|
2008-08-07 14:26:07 +02:00
|
|
|
|
|
|
|
/* wait for input */
|
2009-04-23 03:01:07 +02:00
|
|
|
key = 0;
|
|
|
|
while (!key)
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
2009-04-23 03:01:07 +02:00
|
|
|
VIDEO_WaitVSync();
|
2008-08-07 14:26:07 +02:00
|
|
|
WPAD_ScanPads();
|
2009-04-23 03:01:07 +02:00
|
|
|
p = WPAD_ButtonsDown(chan);
|
2008-08-07 14:26:07 +02:00
|
|
|
|
2009-04-23 03:01:07 +02:00
|
|
|
switch (exp)
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
2009-04-24 01:24:40 +02:00
|
|
|
/* Wiimote (TODO: add motion sensing !) */
|
2009-04-23 03:01:07 +02:00
|
|
|
case WPAD_EXP_NONE:
|
|
|
|
if (p & WPAD_BUTTON_HOME) key = 0xff;
|
|
|
|
else if (p & WPAD_BUTTON_2) key = WPAD_BUTTON_2;
|
|
|
|
else if (p & WPAD_BUTTON_1) key = WPAD_BUTTON_1;
|
|
|
|
else if (p & WPAD_BUTTON_B) key = WPAD_BUTTON_B;
|
|
|
|
else if (p & WPAD_BUTTON_A) key = WPAD_BUTTON_A;
|
|
|
|
else if (p & WPAD_BUTTON_PLUS) key = WPAD_BUTTON_PLUS;
|
|
|
|
else if (p & WPAD_BUTTON_MINUS) key = WPAD_BUTTON_MINUS;
|
|
|
|
break;
|
|
|
|
|
2009-04-24 01:24:40 +02:00
|
|
|
/* Wiimote + Nunchuk (TODO: add motion sensing !) */
|
2009-04-23 03:01:07 +02:00
|
|
|
case WPAD_EXP_NUNCHUK:
|
|
|
|
if (p & WPAD_BUTTON_HOME) key = 0xff;
|
|
|
|
else if (p & WPAD_BUTTON_2) key = WPAD_BUTTON_2;
|
|
|
|
else if (p & WPAD_BUTTON_1) key = WPAD_BUTTON_1;
|
|
|
|
else if (p & WPAD_BUTTON_B) key = WPAD_BUTTON_B;
|
|
|
|
else if (p & WPAD_BUTTON_A) key = WPAD_BUTTON_A;
|
|
|
|
else if (p & WPAD_BUTTON_PLUS) key = WPAD_BUTTON_PLUS;
|
|
|
|
else if (p & WPAD_BUTTON_MINUS) key = WPAD_BUTTON_MINUS;
|
|
|
|
else if (p & WPAD_NUNCHUK_BUTTON_Z) key = WPAD_NUNCHUK_BUTTON_Z;
|
|
|
|
else if (p & WPAD_NUNCHUK_BUTTON_C) key = WPAD_NUNCHUK_BUTTON_C;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Classic Controller */
|
|
|
|
case WPAD_EXP_CLASSIC:
|
|
|
|
if (p & WPAD_CLASSIC_BUTTON_HOME) key = 0xff;
|
|
|
|
else if (p & WPAD_CLASSIC_BUTTON_X) key = WPAD_CLASSIC_BUTTON_X;
|
|
|
|
else if (p & WPAD_CLASSIC_BUTTON_A) key = WPAD_CLASSIC_BUTTON_A;
|
|
|
|
else if (p & WPAD_CLASSIC_BUTTON_Y) key = WPAD_CLASSIC_BUTTON_Y;
|
|
|
|
else if (p & WPAD_CLASSIC_BUTTON_B) key = WPAD_CLASSIC_BUTTON_B;
|
|
|
|
else if (p & WPAD_CLASSIC_BUTTON_ZL) key = WPAD_CLASSIC_BUTTON_ZL;
|
|
|
|
else if (p & WPAD_CLASSIC_BUTTON_ZR) key = WPAD_CLASSIC_BUTTON_ZR;
|
|
|
|
else if (p & WPAD_CLASSIC_BUTTON_PLUS) key = WPAD_CLASSIC_BUTTON_PLUS;
|
|
|
|
else if (p & WPAD_CLASSIC_BUTTON_MINUS) key = WPAD_CLASSIC_BUTTON_MINUS;
|
|
|
|
else if (p & WPAD_CLASSIC_BUTTON_FULL_L) key = WPAD_CLASSIC_BUTTON_FULL_L;
|
|
|
|
else if (p & WPAD_CLASSIC_BUTTON_FULL_R) key = WPAD_CLASSIC_BUTTON_FULL_R;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
key = 0xff;
|
|
|
|
break;
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
2009-04-23 03:01:07 +02:00
|
|
|
}
|
2008-08-07 14:26:07 +02:00
|
|
|
|
2009-04-23 03:01:07 +02:00
|
|
|
/* update key mapping */
|
|
|
|
if (key != 0xff) config.wpad_keymap[exp + (chan * 3)][i] = key;
|
2009-05-07 15:00:57 +02:00
|
|
|
else break;
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
2009-04-23 03:01:07 +02:00
|
|
|
|
2009-05-02 17:00:13 +02:00
|
|
|
/* remove any pending buttons */
|
|
|
|
while (WPAD_ButtonsHeld(chan))
|
|
|
|
{
|
|
|
|
WPAD_ScanPads();
|
|
|
|
VIDEO_WaitVSync();
|
|
|
|
}
|
|
|
|
|
2009-04-24 01:24:40 +02:00
|
|
|
/* restore inputs update callback */
|
|
|
|
VIDEO_SetPostRetraceCallback(gx_input_UpdateMenu);
|
2009-04-23 03:01:07 +02:00
|
|
|
VIDEO_Flush();
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
|
|
|
|
2009-04-23 03:01:07 +02:00
|
|
|
static float old_x = 0.0;
|
|
|
|
static float old_y = 0.0;
|
2008-08-13 14:47:56 +02:00
|
|
|
|
2009-04-23 03:01:07 +02:00
|
|
|
static void wpad_update(s8 chan, u8 i, u32 exp)
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
2009-04-23 03:01:07 +02:00
|
|
|
/* WPAD data */
|
|
|
|
WPADData *data = WPAD_Data(chan);
|
2008-08-07 14:26:07 +02:00
|
|
|
|
2009-04-23 03:01:07 +02:00
|
|
|
/* WPAD buttons */
|
|
|
|
u32 p = data->btns_h;
|
|
|
|
|
|
|
|
/* Soft RESET */
|
|
|
|
if (((p & WPAD_CLASSIC_BUTTON_PLUS) && (p & WPAD_CLASSIC_BUTTON_MINUS)) ||
|
|
|
|
((p & WPAD_BUTTON_PLUS) && (p & WPAD_BUTTON_MINUS)))
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
2009-04-23 03:01:07 +02:00
|
|
|
set_softreset();
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
|
|
|
|
2009-04-23 03:01:07 +02:00
|
|
|
/* Retrieve current key mapping */
|
|
|
|
u32 *wpad_keymap = config.wpad_keymap[exp + (3 * chan)];
|
2008-08-07 14:26:07 +02:00
|
|
|
|
2009-04-23 03:01:07 +02:00
|
|
|
/* Generic buttons */
|
2008-08-07 14:26:07 +02:00
|
|
|
if (p & wpad_keymap[KEY_BUTTONA]) input.pad[i] |= INPUT_A;
|
|
|
|
if (p & wpad_keymap[KEY_BUTTONB]) input.pad[i] |= INPUT_B;
|
|
|
|
if (p & wpad_keymap[KEY_BUTTONC]) input.pad[i] |= INPUT_C;
|
|
|
|
if (p & wpad_keymap[KEY_BUTTONX]) input.pad[i] |= INPUT_X;
|
|
|
|
if (p & wpad_keymap[KEY_BUTTONY]) input.pad[i] |= INPUT_Y;
|
|
|
|
if (p & wpad_keymap[KEY_BUTTONZ]) input.pad[i] |= INPUT_Z;
|
|
|
|
if (p & wpad_keymap[KEY_START]) input.pad[i] |= INPUT_START;
|
2009-04-23 03:01:07 +02:00
|
|
|
if (p & wpad_keymap[KEY_MODE]) input.pad[i] |= INPUT_MODE;
|
|
|
|
|
|
|
|
/* Analog sticks */
|
|
|
|
s8 x = 0;
|
|
|
|
s8 y = 0;
|
|
|
|
if (exp != WPAD_EXP_NONE)
|
|
|
|
{
|
|
|
|
x = WPAD_StickX(data,0);
|
|
|
|
y = WPAD_StickY(data,0);
|
|
|
|
}
|
2008-08-07 14:26:07 +02:00
|
|
|
|
2009-04-23 03:01:07 +02:00
|
|
|
/* IR structure */
|
|
|
|
struct ir_t ir;
|
2008-08-07 14:26:07 +02:00
|
|
|
|
2009-04-23 03:01:07 +02:00
|
|
|
/* Analog devices */
|
2008-08-07 14:26:07 +02:00
|
|
|
if (input.dev[i] == DEVICE_LIGHTGUN)
|
|
|
|
{
|
2009-04-23 03:01:07 +02:00
|
|
|
/* Lightgun cursor position (x,y) */
|
2008-08-10 22:40:04 +02:00
|
|
|
if (x || y)
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
2009-04-23 03:01:07 +02:00
|
|
|
/* analog stick relative positions */
|
|
|
|
input.analog[i-4][0] += x / ANALOG_SENSITIVITY;
|
|
|
|
input.analog[i-4][1] -= y / ANALOG_SENSITIVITY;
|
2008-08-10 22:40:04 +02:00
|
|
|
if (input.analog[i-4][0] < 0) input.analog[i-4][0] = 0;
|
|
|
|
else if (input.analog[i-4][0] > bitmap.viewport.w) input.analog[i-4][0] = bitmap.viewport.w;
|
|
|
|
if (input.analog[i-4][1] < 0) input.analog[i-4][1] = 0;
|
|
|
|
else if (input.analog[i-4][1] > bitmap.viewport.h) input.analog[i-4][1] = bitmap.viewport.h;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (exp != WPAD_EXP_CLASSIC)
|
|
|
|
{
|
2009-04-23 03:01:07 +02:00
|
|
|
/* IR tracking */
|
|
|
|
WPAD_IR(chan, &ir);
|
2008-08-10 22:40:04 +02:00
|
|
|
if (ir.valid)
|
|
|
|
{
|
|
|
|
input.analog[i-4][0] = (ir.x * bitmap.viewport.w) / 640;
|
|
|
|
input.analog[i-4][1] = (ir.y * bitmap.viewport.h) / 480;
|
2009-04-23 03:01:07 +02:00
|
|
|
|
|
|
|
/* default button */
|
2008-08-26 18:00:43 +02:00
|
|
|
if (p & WPAD_BUTTON_B) input.pad[i] |= INPUT_B;
|
2008-08-10 22:40:04 +02:00
|
|
|
}
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ((system_hw == SYSTEM_PICO) && (i == 0))
|
|
|
|
{
|
2009-04-23 03:01:07 +02:00
|
|
|
/* PEN tablet position (x,y) */
|
2008-08-10 22:40:04 +02:00
|
|
|
if (x || y)
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
2009-04-23 03:01:07 +02:00
|
|
|
/* analog stick relative positions */
|
|
|
|
input.analog[0][0] += x / ANALOG_SENSITIVITY;
|
|
|
|
input.analog[0][1] -= y / ANALOG_SENSITIVITY;
|
2008-08-10 22:40:04 +02:00
|
|
|
if (input.analog[0][0] < 0x17c) input.analog[0][0] = 0x17c;
|
|
|
|
else if (input.analog[0][0] > 0x3c) input.analog[0][0] = 0x3c;
|
|
|
|
if (input.analog[0][1] < 0x1fc) input.analog[0][1] = 0x1fc;
|
|
|
|
else if (input.analog[0][1] > 0x3f3) input.analog[0][1] = 0x3f3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (exp != WPAD_EXP_CLASSIC)
|
|
|
|
{
|
2009-04-23 03:01:07 +02:00
|
|
|
/* IR tracking */
|
|
|
|
WPAD_IR(chan, &ir);
|
2008-08-10 22:40:04 +02:00
|
|
|
if (ir.valid)
|
|
|
|
{
|
|
|
|
input.analog[0][0] = 0x3c + (ir.x * (0x17c - 0x3c + 1)) / 640;
|
|
|
|
input.analog[0][1] = 0x1fc + (ir.y * (0x3f3 - 0x1fc + 1)) / 480;
|
2009-04-23 03:01:07 +02:00
|
|
|
|
|
|
|
/* default button */
|
2008-08-26 18:00:43 +02:00
|
|
|
if (p & WPAD_BUTTON_B) input.pad[i] |= INPUT_B;
|
2008-08-10 22:40:04 +02:00
|
|
|
}
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
|
|
|
}
|
2008-08-10 22:40:04 +02:00
|
|
|
else if (input.dev[i] == DEVICE_MOUSE)
|
|
|
|
{
|
2009-04-23 03:01:07 +02:00
|
|
|
/* Mouse relative movement (-255,255) */
|
|
|
|
if (x || y)
|
|
|
|
{
|
|
|
|
/* analog stick relative positions */
|
|
|
|
input.analog[2][0] = (x * 2) / ANALOG_SENSITIVITY;
|
|
|
|
input.analog[2][1] = -(y * 2) / ANALOG_SENSITIVITY;
|
|
|
|
}
|
|
|
|
|
2008-08-13 14:47:56 +02:00
|
|
|
if (exp != WPAD_EXP_CLASSIC)
|
|
|
|
{
|
2009-04-23 03:01:07 +02:00
|
|
|
/* IR tracking */
|
|
|
|
WPAD_IR(chan, &ir);
|
2008-08-14 13:54:37 +02:00
|
|
|
if (ir.valid)
|
2008-08-13 14:47:56 +02:00
|
|
|
{
|
2009-04-23 03:01:07 +02:00
|
|
|
/* calculate mouse values */
|
|
|
|
input.analog[2][0] = (ir.x - old_x);
|
|
|
|
input.analog[2][1] = (ir.y - old_y);
|
|
|
|
old_x = ir.x;
|
|
|
|
old_y = ir.y;
|
|
|
|
if (input.analog[2][0] > 255) input.analog[2][0] = 255;
|
|
|
|
else if (input.analog[2][0] < -255) input.analog[2][0] = -255;
|
|
|
|
if (input.analog[2][1] > 255) input.analog[2][1] = 255;
|
|
|
|
else if (input.analog[2][1] < -255) input.analog[2][1] = -255;
|
|
|
|
|
|
|
|
/* default button */
|
2008-08-26 18:00:43 +02:00
|
|
|
if (p & WPAD_BUTTON_B) input.pad[i] |= INPUT_B;
|
2008-08-13 14:47:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-21 17:20:15 +02:00
|
|
|
/* Invert Y coordinate */
|
2009-04-23 03:01:07 +02:00
|
|
|
if (!config.invert_mouse) input.analog[2][1] = -input.analog[2][1];
|
2008-08-10 22:40:04 +02:00
|
|
|
}
|
|
|
|
|
2009-04-23 03:01:07 +02:00
|
|
|
/* Gamepad device */
|
2008-08-10 22:40:04 +02:00
|
|
|
else
|
|
|
|
{
|
2009-04-23 03:01:07 +02:00
|
|
|
if ((p & wpad_dirmap[exp][PAD_UP]) || (y > ANALOG_SENSITIVITY)) input.pad[i] |= INPUT_UP;
|
|
|
|
else if ((p & wpad_dirmap[exp][PAD_DOWN]) || (y < -ANALOG_SENSITIVITY)) input.pad[i] |= INPUT_DOWN;
|
|
|
|
if ((p & wpad_dirmap[exp][PAD_LEFT]) || (x < -ANALOG_SENSITIVITY)) input.pad[i] |= INPUT_LEFT;
|
|
|
|
else if ((p & wpad_dirmap[exp][PAD_RIGHT]) || (x > ANALOG_SENSITIVITY)) input.pad[i] |= INPUT_RIGHT;
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2009-04-23 03:01:07 +02:00
|
|
|
/***************************************************************************************/
|
|
|
|
/* GX Input interface */
|
|
|
|
/***************************************************************************************/
|
2009-04-24 01:24:40 +02:00
|
|
|
void gx_input_Init(void)
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
|
|
|
PAD_Init ();
|
|
|
|
|
|
|
|
#ifdef HW_RVL
|
|
|
|
WPAD_Init();
|
2008-12-10 19:16:30 +01:00
|
|
|
WPAD_SetIdleTimeout(60);
|
2008-08-07 14:26:07 +02:00
|
|
|
WPAD_SetDataFormat(WPAD_CHAN_ALL,WPAD_FMT_BTNS_ACC_IR);
|
|
|
|
WPAD_SetVRes(WPAD_CHAN_ALL,640,480);
|
|
|
|
#endif
|
2009-04-23 03:01:07 +02:00
|
|
|
|
2009-04-24 01:24:40 +02:00
|
|
|
VIDEO_SetPostRetraceCallback(gx_input_UpdateMenu);
|
2009-04-05 20:20:43 +02:00
|
|
|
VIDEO_Flush();
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
|
|
|
|
2009-04-24 01:24:40 +02:00
|
|
|
void gx_input_SetDefault(void)
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* set default key mapping for each type of devices */
|
|
|
|
for (i=0; i<4; i++)
|
|
|
|
{
|
|
|
|
config.pad_keymap[i][KEY_BUTTONA] = PAD_BUTTON_B;
|
|
|
|
config.pad_keymap[i][KEY_BUTTONB] = PAD_BUTTON_A;
|
|
|
|
config.pad_keymap[i][KEY_BUTTONC] = PAD_BUTTON_X;
|
|
|
|
config.pad_keymap[i][KEY_START] = PAD_BUTTON_START;
|
|
|
|
config.pad_keymap[i][KEY_BUTTONX] = PAD_TRIGGER_L;
|
|
|
|
config.pad_keymap[i][KEY_BUTTONY] = PAD_BUTTON_Y;
|
|
|
|
config.pad_keymap[i][KEY_BUTTONZ] = PAD_TRIGGER_R;
|
2009-04-24 01:24:40 +02:00
|
|
|
config.pad_keymap[i][KEY_MODE] = 0;
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HW_RVL
|
|
|
|
for (i=0; i<4; i++)
|
|
|
|
{
|
2009-04-23 03:01:07 +02:00
|
|
|
/* Wiimote */
|
2008-08-07 14:26:07 +02:00
|
|
|
config.wpad_keymap[i*3 + WPAD_EXP_NONE][KEY_BUTTONA] = WPAD_BUTTON_A;
|
|
|
|
config.wpad_keymap[i*3 + WPAD_EXP_NONE][KEY_BUTTONB] = WPAD_BUTTON_2;
|
|
|
|
config.wpad_keymap[i*3 + WPAD_EXP_NONE][KEY_BUTTONC] = WPAD_BUTTON_1;
|
|
|
|
config.wpad_keymap[i*3 + WPAD_EXP_NONE][KEY_START] = WPAD_BUTTON_PLUS;
|
|
|
|
config.wpad_keymap[i*3 + WPAD_EXP_NONE][KEY_BUTTONX] = 0;
|
|
|
|
config.wpad_keymap[i*3 + WPAD_EXP_NONE][KEY_BUTTONY] = 0;
|
|
|
|
config.wpad_keymap[i*3 + WPAD_EXP_NONE][KEY_BUTTONZ] = 0;
|
2009-04-23 03:01:07 +02:00
|
|
|
config.wpad_keymap[i*3 + WPAD_EXP_NONE][KEY_MODE] = 0;
|
2008-08-07 14:26:07 +02:00
|
|
|
|
2009-04-23 03:01:07 +02:00
|
|
|
/* Wiimote + Nunchuk */
|
2008-08-07 14:26:07 +02:00
|
|
|
config.wpad_keymap[i*3 + WPAD_EXP_NUNCHUK][KEY_BUTTONA] = WPAD_NUNCHUK_BUTTON_Z;
|
|
|
|
config.wpad_keymap[i*3 + WPAD_EXP_NUNCHUK][KEY_BUTTONB] = WPAD_BUTTON_A;
|
|
|
|
config.wpad_keymap[i*3 + WPAD_EXP_NUNCHUK][KEY_BUTTONC] = WPAD_BUTTON_B;
|
|
|
|
config.wpad_keymap[i*3 + WPAD_EXP_NUNCHUK][KEY_START] = WPAD_BUTTON_PLUS;
|
|
|
|
config.wpad_keymap[i*3 + WPAD_EXP_NUNCHUK][KEY_BUTTONX] = WPAD_NUNCHUK_BUTTON_C;
|
|
|
|
config.wpad_keymap[i*3 + WPAD_EXP_NUNCHUK][KEY_BUTTONY] = WPAD_BUTTON_1;
|
|
|
|
config.wpad_keymap[i*3 + WPAD_EXP_NUNCHUK][KEY_BUTTONZ] = WPAD_BUTTON_2;
|
2009-04-23 03:01:07 +02:00
|
|
|
config.wpad_keymap[i*3 + WPAD_EXP_NUNCHUK][KEY_MODE] = WPAD_BUTTON_MINUS;
|
2008-08-07 14:26:07 +02:00
|
|
|
|
2009-04-23 03:01:07 +02:00
|
|
|
/* Classic Controller */
|
2008-08-07 14:26:07 +02:00
|
|
|
config.wpad_keymap[i*3 + WPAD_EXP_CLASSIC][KEY_BUTTONA] = WPAD_CLASSIC_BUTTON_Y;
|
|
|
|
config.wpad_keymap[i*3 + WPAD_EXP_CLASSIC][KEY_BUTTONB] = WPAD_CLASSIC_BUTTON_B;
|
|
|
|
config.wpad_keymap[i*3 + WPAD_EXP_CLASSIC][KEY_BUTTONC] = WPAD_CLASSIC_BUTTON_A;
|
|
|
|
config.wpad_keymap[i*3 + WPAD_EXP_CLASSIC][KEY_START] = WPAD_CLASSIC_BUTTON_PLUS;
|
|
|
|
config.wpad_keymap[i*3 + WPAD_EXP_CLASSIC][KEY_BUTTONX] = WPAD_CLASSIC_BUTTON_ZL;
|
|
|
|
config.wpad_keymap[i*3 + WPAD_EXP_CLASSIC][KEY_BUTTONY] = WPAD_CLASSIC_BUTTON_X;
|
|
|
|
config.wpad_keymap[i*3 + WPAD_EXP_CLASSIC][KEY_BUTTONZ] = WPAD_CLASSIC_BUTTON_ZR;
|
2009-04-23 03:01:07 +02:00
|
|
|
config.wpad_keymap[i*3 + WPAD_EXP_CLASSIC][KEY_MODE] = WPAD_CLASSIC_BUTTON_MINUS;
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-04-24 01:24:40 +02:00
|
|
|
/* Default device assignation */
|
2008-09-09 12:33:43 +02:00
|
|
|
for (i=0; i<MAX_DEVICES; i++)
|
|
|
|
{
|
2009-04-24 01:24:40 +02:00
|
|
|
/* set gamepad by default */
|
2009-05-02 17:00:13 +02:00
|
|
|
config.input[i].device = (i < 4) ? 0 : -1;
|
|
|
|
config.input[i].port = i%4;
|
|
|
|
config.input[i].padtype = 0;
|
2008-10-24 18:14:54 +02:00
|
|
|
}
|
|
|
|
|
2008-08-07 14:26:07 +02:00
|
|
|
#ifdef HW_RVL
|
2008-12-04 20:32:22 +01:00
|
|
|
u32 exp;
|
|
|
|
VIDEO_WaitVSync();
|
2008-10-24 18:14:54 +02:00
|
|
|
int j;
|
|
|
|
for (i=0; i<4; i++)
|
|
|
|
{
|
2008-12-12 14:27:38 +01:00
|
|
|
/* try to autodetect connected controller */
|
2008-10-24 18:14:54 +02:00
|
|
|
exp = 255;
|
|
|
|
WPAD_Probe(i, &exp);
|
|
|
|
if (exp <= WPAD_EXP_CLASSIC)
|
2008-09-09 12:33:43 +02:00
|
|
|
{
|
2008-10-24 18:14:54 +02:00
|
|
|
/* set expansion controller (or wiimote if no expansion) as default */
|
|
|
|
config.input[i].device = exp + 1;
|
|
|
|
config.input[i].port = i;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* look for unassigned wiimotes */
|
|
|
|
for (j=0; j<i; j++)
|
2008-10-03 16:49:01 +02:00
|
|
|
{
|
2008-10-24 18:14:54 +02:00
|
|
|
/* classic is used, wiimote is free */
|
|
|
|
if (config.input[j].device == (WPAD_EXP_CLASSIC + 1))
|
2008-10-03 16:49:01 +02:00
|
|
|
{
|
2008-10-24 18:14:54 +02:00
|
|
|
/* assign wiimote */
|
|
|
|
config.input[i].device = 1;
|
|
|
|
config.input[i].port = j;
|
2008-10-03 16:49:01 +02:00
|
|
|
}
|
2008-09-09 12:33:43 +02:00
|
|
|
}
|
|
|
|
}
|
2008-10-24 18:14:54 +02:00
|
|
|
}
|
2008-09-09 12:33:43 +02:00
|
|
|
|
2008-10-24 18:14:54 +02:00
|
|
|
for (i=4; i<MAX_DEVICES; i++)
|
|
|
|
{
|
|
|
|
/* set gamepad if not assigned */
|
|
|
|
config.input[i].device = (config.input[i%4].device == 0) ? -1 : 0;
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
2008-10-24 18:14:54 +02:00
|
|
|
#endif
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
|
|
|
|
2009-04-24 01:24:40 +02:00
|
|
|
void gx_input_Config(u8 chan, u8 type, u8 max)
|
2009-04-15 17:33:51 +02:00
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case 0:
|
2009-04-23 03:01:07 +02:00
|
|
|
pad_config(chan, max);
|
2009-04-15 17:33:51 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
#ifdef HW_RVL
|
2009-04-23 03:01:07 +02:00
|
|
|
wpad_config(chan,type-1, max);
|
2009-04-15 17:33:51 +02:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-24 01:24:40 +02:00
|
|
|
void gx_input_UpdateEmu(void)
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
|
|
|
int i;
|
2009-04-23 03:01:07 +02:00
|
|
|
int player = 0;
|
2008-08-07 14:26:07 +02:00
|
|
|
|
2009-04-23 03:01:07 +02:00
|
|
|
/* update controllers */
|
2008-08-07 14:26:07 +02:00
|
|
|
PAD_ScanPads();
|
|
|
|
#ifdef HW_RVL
|
|
|
|
WPAD_ScanPads();
|
|
|
|
#endif
|
|
|
|
|
2009-05-07 15:00:57 +02:00
|
|
|
/* Menu Request */
|
|
|
|
if (PAD_ButtonsHeld(0) & PAD_TRIGGER_Z)
|
|
|
|
{
|
|
|
|
ConfigRequested = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HW_RVL
|
|
|
|
if ((WPAD_ButtonsHeld(0) & WPAD_BUTTON_HOME) || (WPAD_ButtonsHeld(0) & WPAD_CLASSIC_BUTTON_HOME))
|
|
|
|
{
|
|
|
|
ConfigRequested = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-05-02 17:00:13 +02:00
|
|
|
for (i=0; i<MAX_DEVICES; i++)
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
2009-04-23 03:01:07 +02:00
|
|
|
/* clear key status */
|
2008-08-07 14:26:07 +02:00
|
|
|
input.pad[i] = 0;
|
|
|
|
|
2009-04-23 03:01:07 +02:00
|
|
|
/* update inputs */
|
2008-08-07 14:26:07 +02:00
|
|
|
if (input.dev[i] != NO_DEVICE)
|
|
|
|
{
|
2009-04-23 03:01:07 +02:00
|
|
|
if (config.input[player].device == 0)
|
|
|
|
pad_update(config.input[player].port, i);
|
2008-08-07 14:26:07 +02:00
|
|
|
|
|
|
|
#ifdef HW_RVL
|
2009-04-23 03:01:07 +02:00
|
|
|
else if (config.input[player].device > 0)
|
|
|
|
wpad_update(config.input[player].port,i, config.input[player].device - 1);
|
2008-08-07 14:26:07 +02:00
|
|
|
#endif
|
2009-05-07 15:00:57 +02:00
|
|
|
|
2009-04-23 03:01:07 +02:00
|
|
|
player ++;
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-15 17:33:51 +02:00
|
|
|
/* Menu inputs update function (done by Video Interrupt callback) */
|
2009-04-24 01:24:40 +02:00
|
|
|
void gx_input_UpdateMenu(u32 cnt)
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
2009-04-24 01:24:40 +02:00
|
|
|
/* PAD status update */
|
2009-05-07 15:00:57 +02:00
|
|
|
m_input.connected = PAD_ScanPads();
|
2009-04-24 01:24:40 +02:00
|
|
|
|
|
|
|
/* PAD pressed keys */
|
|
|
|
s16 pp = PAD_ButtonsDown(0);
|
|
|
|
|
|
|
|
/* PAD held keys (direction/selection) */
|
|
|
|
s16 hp = PAD_ButtonsHeld(0) & (PAD_BUTTON_UP|PAD_BUTTON_DOWN|PAD_BUTTON_LEFT|PAD_BUTTON_RIGHT|PAD_BUTTON_A);
|
|
|
|
|
|
|
|
/* PAD analog sticks (handled as PAD held direction keys) */
|
2009-04-15 17:33:51 +02:00
|
|
|
s8 x = PAD_StickX(0);
|
|
|
|
s8 y = PAD_StickY(0);
|
2009-04-24 01:24:40 +02:00
|
|
|
if (x > ANALOG_SENSITIVITY) hp |= PAD_BUTTON_RIGHT;
|
|
|
|
else if (x < -ANALOG_SENSITIVITY) hp |= PAD_BUTTON_LEFT;
|
|
|
|
else if (y > ANALOG_SENSITIVITY) hp |= PAD_BUTTON_UP;
|
|
|
|
else if (y < -ANALOG_SENSITIVITY) hp |= PAD_BUTTON_DOWN;
|
2009-04-15 17:33:51 +02:00
|
|
|
|
2008-08-07 14:26:07 +02:00
|
|
|
#ifdef HW_RVL
|
2009-04-24 01:24:40 +02:00
|
|
|
/* WPAD status update */
|
2009-04-15 17:33:51 +02:00
|
|
|
WPAD_ScanPads();
|
2009-04-23 03:01:07 +02:00
|
|
|
WPADData *data = WPAD_Data(0);
|
2009-04-24 01:24:40 +02:00
|
|
|
|
|
|
|
/* WPAD pressed keys */
|
|
|
|
u32 pw = data->btns_d;
|
|
|
|
|
|
|
|
/* WPAD held keys (direction/selection) */
|
|
|
|
u32 hw = data->btns_h & (WPAD_BUTTON_UP|WPAD_BUTTON_DOWN|WPAD_BUTTON_LEFT|WPAD_BUTTON_RIGHT|WPAD_BUTTON_A|WPAD_BUTTON_2);
|
|
|
|
|
|
|
|
/* WPAD analog sticks (handled as PAD held direction keys) */
|
|
|
|
x = WPAD_StickX(data, 0);
|
|
|
|
y = WPAD_StickY(data, 0);
|
|
|
|
if (x > ANALOG_SENSITIVITY) hp |= PAD_BUTTON_RIGHT;
|
|
|
|
else if (x < -ANALOG_SENSITIVITY) hp |= PAD_BUTTON_LEFT;
|
|
|
|
else if (y > ANALOG_SENSITIVITY) hp |= PAD_BUTTON_UP;
|
|
|
|
else if (y < -ANALOG_SENSITIVITY) hp |= PAD_BUTTON_DOWN;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* check if any direction/selection key is being held or just being pressed/released */
|
|
|
|
#ifdef HW_RVL
|
|
|
|
if (pp||pw) held_cnt = 0;
|
|
|
|
else if (hp||hw) held_cnt++;
|
|
|
|
else held_cnt = 0;
|
|
|
|
#else
|
|
|
|
if (pp) held_cnt = 0;
|
|
|
|
else if (hp) held_cnt++;
|
2009-04-21 03:05:56 +02:00
|
|
|
else held_cnt = 0;
|
2009-04-24 01:24:40 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* initial delay (prevents triggering to start immediately) */
|
|
|
|
if (held_cnt > HELD_DELAY)
|
2009-04-21 03:05:56 +02:00
|
|
|
{
|
2009-04-24 01:24:40 +02:00
|
|
|
/* key triggering */
|
|
|
|
pp |= hp;
|
|
|
|
#ifdef HW_RVL
|
|
|
|
pw |= hw;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* delay until next triggering (adjusts direction/selection update speed) */
|
|
|
|
held_cnt -= HELD_SPEED;
|
2009-04-21 03:05:56 +02:00
|
|
|
}
|
|
|
|
|
2009-04-24 01:24:40 +02:00
|
|
|
#ifdef HW_RVL
|
|
|
|
/* Wiimote direction keys */
|
2009-04-23 03:01:07 +02:00
|
|
|
WPAD_IR(0, &m_input.ir);
|
2009-04-15 17:33:51 +02:00
|
|
|
if (m_input.ir.valid)
|
|
|
|
{
|
2009-04-24 01:24:40 +02:00
|
|
|
/* Wiimote is handled vertically */
|
|
|
|
if (pw & WPAD_BUTTON_UP) pp |= PAD_BUTTON_UP;
|
|
|
|
else if (pw & WPAD_BUTTON_DOWN) pp |= PAD_BUTTON_DOWN;
|
|
|
|
else if (pw & WPAD_BUTTON_LEFT) pp |= PAD_BUTTON_LEFT;
|
|
|
|
else if (pw & WPAD_BUTTON_RIGHT) pp |= PAD_BUTTON_RIGHT;
|
2009-04-15 17:33:51 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-04-24 01:24:40 +02:00
|
|
|
/* Wiimote is handled horizontally */
|
|
|
|
if (pw & WPAD_BUTTON_UP) pp |= PAD_BUTTON_LEFT;
|
|
|
|
else if (pw & WPAD_BUTTON_DOWN) pp |= PAD_BUTTON_RIGHT;
|
|
|
|
else if (pw & WPAD_BUTTON_LEFT) pp |= PAD_BUTTON_DOWN;
|
|
|
|
else if (pw & WPAD_BUTTON_RIGHT) pp |= PAD_BUTTON_UP;
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
2009-04-15 17:33:51 +02:00
|
|
|
|
2009-04-24 01:24:40 +02:00
|
|
|
/* Classic Controller direction keys */
|
|
|
|
if (pw & WPAD_CLASSIC_BUTTON_UP) pp |= PAD_BUTTON_UP;
|
|
|
|
else if (pw & WPAD_CLASSIC_BUTTON_DOWN) pp |= PAD_BUTTON_DOWN;
|
|
|
|
else if (pw & WPAD_CLASSIC_BUTTON_LEFT) pp |= PAD_BUTTON_LEFT;
|
|
|
|
else if (pw & WPAD_CLASSIC_BUTTON_RIGHT) pp |= PAD_BUTTON_RIGHT;
|
|
|
|
|
|
|
|
/* WPAD buttons */
|
|
|
|
if (pw & WPAD_BUTTON_MINUS) pp |= PAD_TRIGGER_L;
|
|
|
|
if (pw & WPAD_BUTTON_PLUS) pp |= PAD_TRIGGER_R;
|
|
|
|
if (pw & WPAD_BUTTON_A) pp |= PAD_BUTTON_A;
|
|
|
|
if (pw & WPAD_BUTTON_B) pp |= PAD_BUTTON_B;
|
|
|
|
if (pw & WPAD_BUTTON_2) pp |= PAD_BUTTON_A;
|
|
|
|
if (pw & WPAD_BUTTON_1) pp |= PAD_BUTTON_B;
|
|
|
|
if (pw & WPAD_BUTTON_HOME) pp |= PAD_TRIGGER_Z;
|
|
|
|
if (pw & WPAD_CLASSIC_BUTTON_FULL_L) pp |= PAD_TRIGGER_L;
|
|
|
|
if (pw & WPAD_CLASSIC_BUTTON_FULL_R) pp |= PAD_TRIGGER_R;
|
|
|
|
if (pw & WPAD_CLASSIC_BUTTON_A) pp |= PAD_BUTTON_A;
|
|
|
|
if (pw & WPAD_CLASSIC_BUTTON_B) pp |= PAD_BUTTON_B;
|
|
|
|
if (pw & WPAD_CLASSIC_BUTTON_HOME) pp |= PAD_TRIGGER_Z;
|
2009-04-15 17:33:51 +02:00
|
|
|
#endif
|
|
|
|
|
2009-04-23 03:01:07 +02:00
|
|
|
/* Update menu inputs */
|
2009-04-24 01:24:40 +02:00
|
|
|
m_input.keys = pp;
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|