2008-09-02 03:57:21 +02:00
|
|
|
/****************************************************************************
|
2009-07-22 04:05:49 +02:00
|
|
|
* FCE Ultra
|
2008-09-02 03:57:21 +02:00
|
|
|
* Nintendo Wii/Gamecube Port
|
|
|
|
*
|
2009-04-13 10:43:20 +02:00
|
|
|
* Tantric 2008-2009
|
2008-09-02 03:57:21 +02:00
|
|
|
*
|
2009-04-13 10:43:20 +02:00
|
|
|
* pad.cpp
|
2008-09-02 03:57:21 +02:00
|
|
|
*
|
|
|
|
* Controller input
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <gccore.h>
|
|
|
|
#include <math.h>
|
2010-03-31 04:47:52 +02:00
|
|
|
#include <ogc/lwp_watchdog.h>
|
2008-09-02 03:57:21 +02:00
|
|
|
|
2008-11-17 01:09:31 +01:00
|
|
|
#include "fceugx.h"
|
2009-07-17 19:27:04 +02:00
|
|
|
#include "fceusupport.h"
|
2008-09-02 03:57:21 +02:00
|
|
|
#include "pad.h"
|
2008-09-04 04:46:04 +02:00
|
|
|
#include "gcaudio.h"
|
2008-09-02 03:57:21 +02:00
|
|
|
#include "menu.h"
|
2008-10-08 06:53:06 +02:00
|
|
|
#include "gcvideo.h"
|
2009-03-28 18:23:08 +01:00
|
|
|
#include "filebrowser.h"
|
|
|
|
#include "button_mapping.h"
|
|
|
|
#include "fceuload.h"
|
2010-03-22 00:49:24 +01:00
|
|
|
#include "gui/gui.h"
|
2008-10-01 08:03:16 +02:00
|
|
|
|
2009-03-28 18:23:08 +01:00
|
|
|
int rumbleRequest[4] = {0,0,0,0};
|
|
|
|
GuiTrigger userInput[4];
|
|
|
|
|
|
|
|
#ifdef HW_RVL
|
|
|
|
static int rumbleCount[4] = {0,0,0,0};
|
|
|
|
#endif
|
2008-09-02 03:57:21 +02:00
|
|
|
|
|
|
|
static uint32 JSReturn = 0;
|
2008-09-04 04:46:04 +02:00
|
|
|
void *InputDPR;
|
|
|
|
|
2008-12-30 01:05:57 +01:00
|
|
|
static INPUTC *zapperdata[2];
|
|
|
|
static unsigned int myzappers[2][3];
|
2008-09-04 04:46:04 +02:00
|
|
|
|
2009-03-28 18:23:08 +01:00
|
|
|
u32 nespadmap[11]; // Original NES controller buttons
|
|
|
|
u32 zapperpadmap[11]; // Original NES Zapper controller buttons
|
|
|
|
u32 btnmap[2][4][12]; // button mapping
|
2008-12-19 23:04:55 +01:00
|
|
|
|
2009-06-22 21:57:33 +02:00
|
|
|
void ResetControls(int consoleCtrl, int wiiCtrl)
|
2008-12-19 23:04:55 +01:00
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
// Original NES controller buttons
|
|
|
|
// All other pads are mapped to this
|
|
|
|
i=0;
|
|
|
|
nespadmap[i++] = JOY_B;
|
|
|
|
nespadmap[i++] = JOY_A;
|
|
|
|
nespadmap[i++] = RAPID_B;
|
|
|
|
nespadmap[i++] = RAPID_A; // rapid press A/B buttons
|
|
|
|
nespadmap[i++] = JOY_SELECT;
|
|
|
|
nespadmap[i++] = JOY_START;
|
|
|
|
nespadmap[i++] = JOY_UP;
|
|
|
|
nespadmap[i++] = JOY_DOWN;
|
|
|
|
nespadmap[i++] = JOY_LEFT;
|
|
|
|
nespadmap[i++] = JOY_RIGHT;
|
|
|
|
nespadmap[i++] = 0; // insert coin for VS games, insert/eject/select disk for FDS
|
|
|
|
|
|
|
|
/*** Gamecube controller Padmap ***/
|
2009-07-01 19:16:27 +02:00
|
|
|
if(consoleCtrl == -1 || (consoleCtrl == CTRL_PAD && wiiCtrl == CTRLR_GCPAD))
|
2009-06-22 21:57:33 +02:00
|
|
|
{
|
|
|
|
i=0;
|
|
|
|
btnmap[CTRL_PAD][CTRLR_GCPAD][i++] = PAD_BUTTON_B;
|
|
|
|
btnmap[CTRL_PAD][CTRLR_GCPAD][i++] = PAD_BUTTON_A;
|
|
|
|
btnmap[CTRL_PAD][CTRLR_GCPAD][i++] = PAD_BUTTON_Y;
|
|
|
|
btnmap[CTRL_PAD][CTRLR_GCPAD][i++] = PAD_BUTTON_X;
|
|
|
|
btnmap[CTRL_PAD][CTRLR_GCPAD][i++] = PAD_TRIGGER_Z;
|
|
|
|
btnmap[CTRL_PAD][CTRLR_GCPAD][i++] = PAD_BUTTON_START;
|
|
|
|
btnmap[CTRL_PAD][CTRLR_GCPAD][i++] = PAD_BUTTON_UP;
|
|
|
|
btnmap[CTRL_PAD][CTRLR_GCPAD][i++] = PAD_BUTTON_DOWN;
|
|
|
|
btnmap[CTRL_PAD][CTRLR_GCPAD][i++] = PAD_BUTTON_LEFT;
|
|
|
|
btnmap[CTRL_PAD][CTRLR_GCPAD][i++] = PAD_BUTTON_RIGHT;
|
|
|
|
btnmap[CTRL_PAD][CTRLR_GCPAD][i++] = PAD_TRIGGER_L;
|
|
|
|
}
|
2008-12-19 23:04:55 +01:00
|
|
|
|
|
|
|
/*** Wiimote Padmap ***/
|
2009-07-01 19:16:27 +02:00
|
|
|
if(consoleCtrl == -1 || (consoleCtrl == CTRL_PAD && wiiCtrl == CTRLR_WIIMOTE))
|
2009-06-22 21:57:33 +02:00
|
|
|
{
|
|
|
|
i=0;
|
|
|
|
btnmap[CTRL_PAD][CTRLR_WIIMOTE][i++] = WPAD_BUTTON_1;
|
|
|
|
btnmap[CTRL_PAD][CTRLR_WIIMOTE][i++] = WPAD_BUTTON_2;
|
|
|
|
btnmap[CTRL_PAD][CTRLR_WIIMOTE][i++] = 0;
|
|
|
|
btnmap[CTRL_PAD][CTRLR_WIIMOTE][i++] = 0;
|
|
|
|
btnmap[CTRL_PAD][CTRLR_WIIMOTE][i++] = WPAD_BUTTON_MINUS;
|
|
|
|
btnmap[CTRL_PAD][CTRLR_WIIMOTE][i++] = WPAD_BUTTON_PLUS;
|
|
|
|
btnmap[CTRL_PAD][CTRLR_WIIMOTE][i++] = WPAD_BUTTON_RIGHT;
|
|
|
|
btnmap[CTRL_PAD][CTRLR_WIIMOTE][i++] = WPAD_BUTTON_LEFT;
|
|
|
|
btnmap[CTRL_PAD][CTRLR_WIIMOTE][i++] = WPAD_BUTTON_UP;
|
|
|
|
btnmap[CTRL_PAD][CTRLR_WIIMOTE][i++] = WPAD_BUTTON_DOWN;
|
|
|
|
btnmap[CTRL_PAD][CTRLR_WIIMOTE][i++] = WPAD_BUTTON_A;
|
|
|
|
}
|
2008-12-19 23:04:55 +01:00
|
|
|
|
|
|
|
/*** Classic Controller Padmap ***/
|
2009-07-01 19:16:27 +02:00
|
|
|
if(consoleCtrl == -1 || (consoleCtrl == CTRL_PAD && wiiCtrl == CTRLR_CLASSIC))
|
2009-06-22 21:57:33 +02:00
|
|
|
{
|
|
|
|
i=0;
|
|
|
|
btnmap[CTRL_PAD][CTRLR_CLASSIC][i++] = WPAD_CLASSIC_BUTTON_Y;
|
|
|
|
btnmap[CTRL_PAD][CTRLR_CLASSIC][i++] = WPAD_CLASSIC_BUTTON_B;
|
|
|
|
btnmap[CTRL_PAD][CTRLR_CLASSIC][i++] = WPAD_CLASSIC_BUTTON_X;
|
|
|
|
btnmap[CTRL_PAD][CTRLR_CLASSIC][i++] = WPAD_CLASSIC_BUTTON_A;
|
|
|
|
btnmap[CTRL_PAD][CTRLR_CLASSIC][i++] = WPAD_CLASSIC_BUTTON_MINUS;
|
|
|
|
btnmap[CTRL_PAD][CTRLR_CLASSIC][i++] = WPAD_CLASSIC_BUTTON_PLUS;
|
|
|
|
btnmap[CTRL_PAD][CTRLR_CLASSIC][i++] = WPAD_CLASSIC_BUTTON_UP;
|
|
|
|
btnmap[CTRL_PAD][CTRLR_CLASSIC][i++] = WPAD_CLASSIC_BUTTON_DOWN;
|
|
|
|
btnmap[CTRL_PAD][CTRLR_CLASSIC][i++] = WPAD_CLASSIC_BUTTON_LEFT;
|
|
|
|
btnmap[CTRL_PAD][CTRLR_CLASSIC][i++] = WPAD_CLASSIC_BUTTON_RIGHT;
|
|
|
|
btnmap[CTRL_PAD][CTRLR_CLASSIC][i++] = WPAD_CLASSIC_BUTTON_FULL_L;
|
|
|
|
}
|
2008-12-19 23:04:55 +01:00
|
|
|
|
|
|
|
/*** Nunchuk + wiimote Padmap ***/
|
2009-07-01 19:16:27 +02:00
|
|
|
if(consoleCtrl == -1 || (consoleCtrl == CTRL_PAD && wiiCtrl == CTRLR_NUNCHUK))
|
2009-06-22 21:57:33 +02:00
|
|
|
{
|
|
|
|
i=0;
|
|
|
|
btnmap[CTRL_PAD][CTRLR_NUNCHUK][i++] = WPAD_NUNCHUK_BUTTON_C;
|
|
|
|
btnmap[CTRL_PAD][CTRLR_NUNCHUK][i++] = WPAD_NUNCHUK_BUTTON_Z;
|
|
|
|
btnmap[CTRL_PAD][CTRLR_NUNCHUK][i++] = 0;
|
|
|
|
btnmap[CTRL_PAD][CTRLR_NUNCHUK][i++] = 0;
|
|
|
|
btnmap[CTRL_PAD][CTRLR_NUNCHUK][i++] = WPAD_BUTTON_MINUS;
|
|
|
|
btnmap[CTRL_PAD][CTRLR_NUNCHUK][i++] = WPAD_BUTTON_PLUS;
|
|
|
|
btnmap[CTRL_PAD][CTRLR_NUNCHUK][i++] = WPAD_BUTTON_UP;
|
|
|
|
btnmap[CTRL_PAD][CTRLR_NUNCHUK][i++] = WPAD_BUTTON_DOWN;
|
|
|
|
btnmap[CTRL_PAD][CTRLR_NUNCHUK][i++] = WPAD_BUTTON_LEFT;
|
|
|
|
btnmap[CTRL_PAD][CTRLR_NUNCHUK][i++] = WPAD_BUTTON_RIGHT;
|
|
|
|
btnmap[CTRL_PAD][CTRLR_NUNCHUK][i++] = WPAD_BUTTON_A;
|
|
|
|
}
|
2009-03-28 18:23:08 +01:00
|
|
|
|
|
|
|
/*** Zapper : GC controller button mapping ***/
|
2009-07-01 19:16:27 +02:00
|
|
|
if(consoleCtrl == -1 || (consoleCtrl == CTRL_ZAPPER && wiiCtrl == CTRLR_GCPAD))
|
2009-06-22 21:57:33 +02:00
|
|
|
{
|
|
|
|
i=0;
|
|
|
|
btnmap[CTRL_ZAPPER][CTRLR_GCPAD][i++] = PAD_BUTTON_A; // shoot
|
|
|
|
btnmap[CTRL_ZAPPER][CTRLR_GCPAD][i++] = PAD_BUTTON_B; // insert coin
|
|
|
|
}
|
2009-03-28 18:23:08 +01:00
|
|
|
|
|
|
|
/*** Zapper : wiimote button mapping ***/
|
2009-07-01 19:16:27 +02:00
|
|
|
if(consoleCtrl == -1 || (consoleCtrl == CTRL_ZAPPER && wiiCtrl == CTRLR_WIIMOTE))
|
2009-06-22 21:57:33 +02:00
|
|
|
{
|
|
|
|
i=0;
|
|
|
|
btnmap[CTRL_ZAPPER][CTRLR_WIIMOTE][i++] = WPAD_BUTTON_B; // shoot
|
|
|
|
btnmap[CTRL_ZAPPER][CTRLR_WIIMOTE][i++] = WPAD_BUTTON_A; // insert coin
|
|
|
|
}
|
2009-03-28 18:23:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* SetControllers
|
|
|
|
***************************************************************************/
|
|
|
|
void SetControllers()
|
|
|
|
{
|
|
|
|
if(!romLoaded)
|
|
|
|
return;
|
|
|
|
|
2009-04-01 10:02:59 +02:00
|
|
|
InputDPR = &JSReturn;
|
|
|
|
|
2009-03-28 18:23:08 +01:00
|
|
|
if(GCSettings.Controller == CTRL_PAD4)
|
2009-07-17 19:27:04 +02:00
|
|
|
FCEUI_SetInputFourscore(1);
|
2009-03-28 18:23:08 +01:00
|
|
|
else
|
2009-07-17 19:27:04 +02:00
|
|
|
FCEUI_SetInputFourscore(0);
|
2009-03-28 18:23:08 +01:00
|
|
|
|
|
|
|
// set defaults
|
|
|
|
zapperdata[0]=NULL;
|
|
|
|
zapperdata[1]=NULL;
|
|
|
|
myzappers[0][0]=myzappers[1][0]=128;
|
|
|
|
myzappers[0][1]=myzappers[1][1]=120;
|
|
|
|
myzappers[0][2]=myzappers[1][2]=0;
|
|
|
|
|
|
|
|
// Default ports back to gamepad
|
|
|
|
FCEUI_SetInput(0, SI_GAMEPAD, InputDPR, 0);
|
|
|
|
FCEUI_SetInput(1, SI_GAMEPAD, InputDPR, 0);
|
|
|
|
|
|
|
|
if(GCSettings.Controller == CTRL_ZAPPER)
|
|
|
|
{
|
2009-04-01 10:02:59 +02:00
|
|
|
int p;
|
2009-07-20 08:18:06 +02:00
|
|
|
if(GameInfo->type == GIT_VSUNI) p = 0;
|
2009-04-01 10:02:59 +02:00
|
|
|
else p = 1;
|
|
|
|
zapperdata[p] = FCEU_InitZapper(p);
|
|
|
|
FCEUI_SetInput(p, SI_ZAPPER, myzappers[p], 1);
|
2009-03-28 18:23:08 +01:00
|
|
|
}
|
2008-12-19 23:04:55 +01:00
|
|
|
}
|
|
|
|
|
2009-06-27 22:05:45 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* UpdatePads
|
|
|
|
*
|
2009-10-13 02:40:02 +02:00
|
|
|
* Scans pad and wpad
|
2009-06-27 22:05:45 +02:00
|
|
|
***************************************************************************/
|
2010-03-31 04:47:52 +02:00
|
|
|
|
2009-10-13 02:40:02 +02:00
|
|
|
void
|
|
|
|
UpdatePads()
|
2009-06-27 22:05:45 +02:00
|
|
|
{
|
|
|
|
#ifdef HW_RVL
|
2016-09-18 05:43:24 +02:00
|
|
|
WUPC_UpdateButtonStats();
|
2009-06-27 22:05:45 +02:00
|
|
|
WPAD_ScanPads();
|
|
|
|
#endif
|
2012-10-04 02:34:08 +02:00
|
|
|
|
|
|
|
PAD_ScanPads();
|
2009-06-27 22:05:45 +02:00
|
|
|
|
|
|
|
for(int i=3; i >= 0; i--)
|
|
|
|
{
|
|
|
|
userInput[i].pad.btns_d = PAD_ButtonsDown(i);
|
|
|
|
userInput[i].pad.btns_u = PAD_ButtonsUp(i);
|
|
|
|
userInput[i].pad.btns_h = PAD_ButtonsHeld(i);
|
|
|
|
userInput[i].pad.stickX = PAD_StickX(i);
|
|
|
|
userInput[i].pad.stickY = PAD_StickY(i);
|
|
|
|
userInput[i].pad.substickX = PAD_SubStickX(i);
|
|
|
|
userInput[i].pad.substickY = PAD_SubStickY(i);
|
|
|
|
userInput[i].pad.triggerL = PAD_TriggerL(i);
|
|
|
|
userInput[i].pad.triggerR = PAD_TriggerR(i);
|
2016-09-18 05:43:24 +02:00
|
|
|
#ifdef HW_RVL
|
|
|
|
userInput[i].wupcdata.btns_d = WUPC_ButtonsDown(i);
|
|
|
|
userInput[i].wupcdata.btns_u = WUPC_ButtonsUp(i);
|
|
|
|
userInput[i].wupcdata.btns_h = WUPC_ButtonsHeld(i);
|
|
|
|
userInput[i].wupcdata.stickX = WUPC_lStickX(i);
|
|
|
|
userInput[i].wupcdata.stickY = WUPC_lStickY(i);
|
|
|
|
userInput[i].wupcdata.substickX = WUPC_rStickX(i);
|
|
|
|
userInput[i].wupcdata.substickY = WUPC_rStickY(i);
|
|
|
|
#endif
|
2009-06-27 22:05:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-13 02:40:02 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* SetupPads
|
|
|
|
*
|
|
|
|
* Sets up userInput triggers for use
|
|
|
|
***************************************************************************/
|
|
|
|
void
|
|
|
|
SetupPads()
|
|
|
|
{
|
|
|
|
PAD_Init();
|
|
|
|
|
|
|
|
#ifdef HW_RVL
|
|
|
|
// read wiimote accelerometer and IR data
|
|
|
|
WPAD_SetDataFormat(WPAD_CHAN_ALL,WPAD_FMT_BTNS_ACC_IR);
|
|
|
|
WPAD_SetVRes(WPAD_CHAN_ALL, screenwidth, screenheight);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for(int i=0; i < 4; i++)
|
|
|
|
{
|
|
|
|
userInput[i].chan = i;
|
|
|
|
#ifdef HW_RVL
|
|
|
|
userInput[i].wpad = WPAD_Data(i);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-28 18:23:08 +01:00
|
|
|
#ifdef HW_RVL
|
|
|
|
/****************************************************************************
|
|
|
|
* ShutoffRumble
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
void ShutoffRumble()
|
2008-09-04 04:46:04 +02:00
|
|
|
{
|
2010-04-17 05:04:21 +02:00
|
|
|
if(CONF_GetPadMotorMode() == 0)
|
|
|
|
return;
|
|
|
|
|
2009-03-28 18:23:08 +01:00
|
|
|
for(int i=0;i<4;i++)
|
|
|
|
{
|
|
|
|
WPAD_Rumble(i, 0);
|
|
|
|
rumbleCount[i] = 0;
|
2009-10-27 22:49:55 +01:00
|
|
|
rumbleRequest[i] = 0;
|
2009-03-28 18:23:08 +01:00
|
|
|
}
|
2008-09-04 04:46:04 +02:00
|
|
|
}
|
|
|
|
|
2009-03-28 18:23:08 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* DoRumble
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
void DoRumble(int i)
|
2008-09-04 04:46:04 +02:00
|
|
|
{
|
2010-04-17 05:04:21 +02:00
|
|
|
if(CONF_GetPadMotorMode() == 0 || !GCSettings.Rumble)
|
|
|
|
return;
|
|
|
|
|
2009-03-28 18:23:08 +01:00
|
|
|
if(rumbleRequest[i] && rumbleCount[i] < 3)
|
2008-10-01 08:03:16 +02:00
|
|
|
{
|
2009-03-28 18:23:08 +01:00
|
|
|
WPAD_Rumble(i, 1); // rumble on
|
|
|
|
rumbleCount[i]++;
|
|
|
|
}
|
|
|
|
else if(rumbleRequest[i])
|
|
|
|
{
|
|
|
|
rumbleCount[i] = 12;
|
|
|
|
rumbleRequest[i] = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(rumbleCount[i])
|
|
|
|
rumbleCount[i]--;
|
|
|
|
WPAD_Rumble(i, 0); // rumble off
|
2008-09-04 04:46:04 +02:00
|
|
|
}
|
2008-09-02 03:57:21 +02:00
|
|
|
}
|
2009-03-28 18:23:08 +01:00
|
|
|
#endif
|
2008-09-02 03:57:21 +02:00
|
|
|
|
2008-09-04 04:46:04 +02:00
|
|
|
// hold zapper cursor positions
|
2008-12-30 01:05:57 +01:00
|
|
|
static int pos_x = 0;
|
|
|
|
static int pos_y = 0;
|
2008-09-04 04:46:04 +02:00
|
|
|
|
2009-10-15 09:36:33 +02:00
|
|
|
static void UpdateCursorPosition (int chan)
|
2008-09-04 04:46:04 +02:00
|
|
|
{
|
|
|
|
#define ZAPPERPADCAL 20
|
2016-09-18 05:43:24 +02:00
|
|
|
#define WUPCZAPPERPADCAL 160
|
2008-09-04 04:46:04 +02:00
|
|
|
// gc left joystick
|
|
|
|
|
2009-10-15 09:36:33 +02:00
|
|
|
if (userInput[chan].pad.stickX > ZAPPERPADCAL)
|
|
|
|
{
|
|
|
|
pos_x += (userInput[chan].pad.stickX*1.0)/ZAPPERPADCAL;
|
2008-09-04 04:46:04 +02:00
|
|
|
if (pos_x > 256) pos_x = 256;
|
|
|
|
}
|
2009-10-15 09:36:33 +02:00
|
|
|
if (userInput[chan].pad.stickX < -ZAPPERPADCAL)
|
|
|
|
{
|
|
|
|
pos_x -= (userInput[chan].pad.stickX*-1.0)/ZAPPERPADCAL;
|
2008-09-04 04:46:04 +02:00
|
|
|
if (pos_x < 0) pos_x = 0;
|
|
|
|
}
|
|
|
|
|
2009-10-15 09:36:33 +02:00
|
|
|
if (userInput[chan].pad.stickY < -ZAPPERPADCAL)
|
|
|
|
{
|
|
|
|
pos_y += (userInput[chan].pad.stickY*-1.0)/ZAPPERPADCAL;
|
2008-09-04 04:46:04 +02:00
|
|
|
if (pos_y > 224) pos_y = 224;
|
|
|
|
}
|
2009-10-15 09:36:33 +02:00
|
|
|
if (userInput[chan].pad.stickY > ZAPPERPADCAL)
|
|
|
|
{
|
|
|
|
pos_y -= (userInput[chan].pad.stickY*1.0)/ZAPPERPADCAL;
|
2008-09-04 04:46:04 +02:00
|
|
|
if (pos_y < 0) pos_y = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HW_RVL
|
2009-10-15 09:36:33 +02:00
|
|
|
if (userInput[chan].wpad->ir.valid)
|
2008-09-04 04:46:04 +02:00
|
|
|
{
|
2009-10-15 09:36:33 +02:00
|
|
|
pos_x = (userInput[chan].wpad->ir.x * 256) / 640;
|
|
|
|
pos_y = (userInput[chan].wpad->ir.y * 224) / 480;
|
2008-09-04 04:46:04 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-10-15 09:36:33 +02:00
|
|
|
s8 wm_ax = userInput[chan].WPAD_StickX(0);
|
|
|
|
s8 wm_ay = userInput[chan].WPAD_StickY(0);
|
2008-09-04 04:46:04 +02:00
|
|
|
|
2009-10-15 09:36:33 +02:00
|
|
|
if (wm_ax > ZAPPERPADCAL)
|
|
|
|
{
|
2008-09-04 04:46:04 +02:00
|
|
|
pos_x += (wm_ax*1.0)/ZAPPERPADCAL;
|
|
|
|
if (pos_x > 256) pos_x = 256;
|
|
|
|
}
|
2009-10-15 09:36:33 +02:00
|
|
|
if (wm_ax < -ZAPPERPADCAL)
|
|
|
|
{
|
2008-09-04 04:46:04 +02:00
|
|
|
pos_x -= (wm_ax*-1.0)/ZAPPERPADCAL;
|
|
|
|
if (pos_x < 0) pos_x = 0;
|
|
|
|
}
|
2009-10-15 09:36:33 +02:00
|
|
|
if (wm_ay < -ZAPPERPADCAL)
|
|
|
|
{
|
2008-09-04 04:46:04 +02:00
|
|
|
pos_y += (wm_ay*-1.0)/ZAPPERPADCAL;
|
|
|
|
if (pos_y > 224) pos_y = 224;
|
|
|
|
}
|
2009-10-15 09:36:33 +02:00
|
|
|
if (wm_ay > ZAPPERPADCAL)
|
|
|
|
{
|
2008-09-04 04:46:04 +02:00
|
|
|
pos_y -= (wm_ay*1.0)/ZAPPERPADCAL;
|
|
|
|
if (pos_y < 0) pos_y = 0;
|
|
|
|
}
|
2016-09-18 05:43:24 +02:00
|
|
|
|
|
|
|
/* WiiU Pro Controller */
|
|
|
|
s8 wupc_ax = userInput[chan].wupcdata.stickX;
|
|
|
|
s8 wupc_ay = userInput[chan].wupcdata.stickX;
|
|
|
|
|
|
|
|
if (wupc_ax > WUPCZAPPERPADCAL)
|
|
|
|
{
|
|
|
|
pos_x += (wupc_ax*1.0)/WUPCZAPPERPADCAL;
|
|
|
|
if (pos_x > 256) pos_x = 256;
|
|
|
|
}
|
|
|
|
if (wupc_ax < -WUPCZAPPERPADCAL)
|
|
|
|
{
|
|
|
|
pos_x -= (wupc_ax*-1.0)/WUPCZAPPERPADCAL;
|
|
|
|
if (pos_x < 0) pos_x = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wupc_ay < -WUPCZAPPERPADCAL)
|
|
|
|
{
|
|
|
|
pos_y += (wupc_ay*-1.0)/WUPCZAPPERPADCAL;
|
|
|
|
if (pos_y > 224) pos_y = 224;
|
|
|
|
}
|
|
|
|
if (wupc_ay > WUPCZAPPERPADCAL)
|
|
|
|
{
|
|
|
|
pos_y -= (wupc_ay*1.0)/WUPCZAPPERPADCAL;
|
|
|
|
if (pos_y < 0) pos_y = 0;
|
|
|
|
}
|
2008-09-04 04:46:04 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-09-02 03:57:21 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Convert GC Joystick Readings to JOY
|
|
|
|
****************************************************************************/
|
2009-09-28 09:05:10 +02:00
|
|
|
|
|
|
|
extern int rapidAlternator;
|
2008-09-02 03:57:21 +02:00
|
|
|
|
2009-10-15 09:36:33 +02:00
|
|
|
static unsigned char DecodeJoy(unsigned short chan)
|
2008-09-02 03:57:21 +02:00
|
|
|
{
|
2009-10-15 09:36:33 +02:00
|
|
|
s8 pad_x = userInput[chan].pad.stickX;
|
|
|
|
s8 pad_y = userInput[chan].pad.stickY;
|
|
|
|
u32 jp = userInput[chan].pad.btns_h;
|
2008-09-02 03:57:21 +02:00
|
|
|
unsigned char J = 0;
|
2012-01-27 03:34:53 +01:00
|
|
|
double angle;
|
2012-03-18 18:38:57 +01:00
|
|
|
static const double THRES = 0.38268343236508984; // cos(67.5)
|
2008-09-02 03:57:21 +02:00
|
|
|
|
|
|
|
#ifdef HW_RVL
|
2009-10-28 01:11:43 +01:00
|
|
|
s8 wm_ax = userInput[chan].WPAD_StickX(0);
|
|
|
|
s8 wm_ay = userInput[chan].WPAD_StickY(0);
|
|
|
|
u32 wp = userInput[chan].wpad->btns_h;
|
2008-09-02 03:57:21 +02:00
|
|
|
|
|
|
|
u32 exp_type;
|
2016-09-18 05:43:24 +02:00
|
|
|
if ( WPAD_Probe(chan, &exp_type) != 0 )
|
|
|
|
exp_type = WPAD_EXP_NONE;
|
|
|
|
|
|
|
|
s16 wupc_ax = userInput[chan].wupcdata.stickX;
|
|
|
|
s16 wupc_ay = userInput[chan].wupcdata.stickY;
|
|
|
|
u32 wupcp = userInput[chan].wupcdata.btns_h;
|
2008-09-02 03:57:21 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/***
|
|
|
|
Gamecube Joystick input
|
|
|
|
***/
|
|
|
|
// Is XY inside the "zone"?
|
|
|
|
if (pad_x * pad_x + pad_y * pad_y > PADCAL * PADCAL)
|
|
|
|
{
|
2012-01-27 03:34:53 +01:00
|
|
|
angle = atan2(pad_y, pad_x);
|
|
|
|
|
|
|
|
if(cos(angle) > THRES)
|
|
|
|
J |= JOY_RIGHT;
|
|
|
|
else if(cos(angle) < -THRES)
|
|
|
|
J |= JOY_LEFT;
|
|
|
|
if(sin(angle) > THRES)
|
|
|
|
J |= JOY_UP;
|
|
|
|
else if(sin(angle) < -THRES)
|
|
|
|
J |= JOY_DOWN;
|
2008-09-02 03:57:21 +02:00
|
|
|
}
|
|
|
|
#ifdef HW_RVL
|
|
|
|
/***
|
|
|
|
Wii Joystick (classic, nunchuk) input
|
|
|
|
***/
|
|
|
|
// Is XY inside the "zone"?
|
|
|
|
if (wm_ax * wm_ax + wm_ay * wm_ay > PADCAL * PADCAL)
|
|
|
|
{
|
2012-01-27 03:34:53 +01:00
|
|
|
angle = atan2(wm_ay, wm_ax);
|
|
|
|
|
|
|
|
if(cos(angle) > THRES)
|
2008-09-02 03:57:21 +02:00
|
|
|
J |= JOY_RIGHT;
|
2012-01-27 03:34:53 +01:00
|
|
|
else if(cos(angle) < -THRES)
|
2008-09-02 03:57:21 +02:00
|
|
|
J |= JOY_LEFT;
|
2012-01-27 03:34:53 +01:00
|
|
|
if(sin(angle) > THRES)
|
2008-09-02 03:57:21 +02:00
|
|
|
J |= JOY_UP;
|
2012-01-27 03:34:53 +01:00
|
|
|
else if(sin(angle) < -THRES)
|
2008-09-02 03:57:21 +02:00
|
|
|
J |= JOY_DOWN;
|
|
|
|
}
|
2016-09-18 05:43:24 +02:00
|
|
|
|
|
|
|
/* WiiU Pro Controller */
|
|
|
|
if (wupc_ax * wupc_ax + wupc_ay * wupc_ay > WUPCCAL * WUPCCAL)
|
|
|
|
{
|
|
|
|
angle = atan2(wupc_ay, wupc_ax);
|
|
|
|
if(cos(angle) > THRES)
|
|
|
|
J |= JOY_RIGHT;
|
|
|
|
else if(cos(angle) < -THRES)
|
|
|
|
J |= JOY_LEFT;
|
|
|
|
if(sin(angle) > THRES)
|
|
|
|
J |= JOY_UP;
|
|
|
|
else if(sin(angle) < -THRES)
|
|
|
|
J |= JOY_DOWN;
|
|
|
|
}
|
2008-09-02 03:57:21 +02:00
|
|
|
#endif
|
|
|
|
|
2008-10-08 06:53:06 +02:00
|
|
|
// Report pressed buttons (gamepads)
|
2008-09-02 03:57:21 +02:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < MAXJP; i++)
|
|
|
|
{
|
2016-09-18 05:43:24 +02:00
|
|
|
if ( (jp & btnmap[CTRL_PAD][CTRLR_GCPAD][i]) // gamecube controller
|
2008-09-02 03:57:21 +02:00
|
|
|
#ifdef HW_RVL
|
2016-09-18 05:43:24 +02:00
|
|
|
|| ( (exp_type == WPAD_EXP_NONE) && (wp & btnmap[CTRL_PAD][CTRLR_WIIMOTE][i]) ) // wiimote
|
2009-03-28 18:23:08 +01:00
|
|
|
|| ( (exp_type == WPAD_EXP_CLASSIC) && (wp & btnmap[CTRL_PAD][CTRLR_CLASSIC][i]) ) // classic controller
|
|
|
|
|| ( (exp_type == WPAD_EXP_NUNCHUK) && (wp & btnmap[CTRL_PAD][CTRLR_NUNCHUK][i]) ) // nunchuk + wiimote
|
2016-09-18 05:43:24 +02:00
|
|
|
|| ( (wupcp & btnmap[CTRL_PAD][CTRLR_CLASSIC][i]) ) // WiiU Pro Controller
|
2008-09-02 03:57:21 +02:00
|
|
|
#endif
|
2008-09-04 04:46:04 +02:00
|
|
|
)
|
2008-10-01 07:16:59 +02:00
|
|
|
{
|
2008-10-08 06:53:06 +02:00
|
|
|
// if zapper is on, ignore all buttons except START and SELECT
|
2016-12-10 20:37:33 +01:00
|
|
|
if(GCSettings.Controller != CTRL_ZAPPER || nespadmap[i] == JOY_START || nespadmap[i] == JOY_SELECT)
|
2008-10-01 23:00:12 +02:00
|
|
|
{
|
2009-09-28 09:05:10 +02:00
|
|
|
if(rapidAlternator && nespadmap[i] == RAPID_A)
|
2008-11-04 09:28:52 +01:00
|
|
|
{
|
|
|
|
// activate rapid fire for A button
|
2009-09-28 09:05:10 +02:00
|
|
|
J |= JOY_A;
|
2008-11-04 09:28:52 +01:00
|
|
|
}
|
2009-09-28 09:05:10 +02:00
|
|
|
else if(rapidAlternator && nespadmap[i] == RAPID_B)
|
2008-11-04 09:28:52 +01:00
|
|
|
{
|
|
|
|
// activate rapid fire for B button
|
2009-09-28 09:05:10 +02:00
|
|
|
J |= JOY_B;
|
2008-11-04 09:28:52 +01:00
|
|
|
}
|
|
|
|
else if(nespadmap[i] > 0)
|
2008-10-01 23:00:12 +02:00
|
|
|
{
|
2008-10-08 06:53:06 +02:00
|
|
|
J |= nespadmap[i];
|
2008-10-01 23:00:12 +02:00
|
|
|
}
|
|
|
|
else
|
2008-10-08 06:53:06 +02:00
|
|
|
{
|
2009-07-20 08:18:06 +02:00
|
|
|
if(GameInfo->type == GIT_FDS) // FDS
|
2008-10-08 06:53:06 +02:00
|
|
|
{
|
|
|
|
/* the commands shouldn't be issued in parallel so
|
|
|
|
* we'll delay them so the virtual FDS has a chance
|
|
|
|
* to process them
|
|
|
|
*/
|
2009-07-20 10:23:16 +02:00
|
|
|
if(FDSSwitchRequested == 0)
|
|
|
|
FDSSwitchRequested = 1;
|
2008-10-08 06:53:06 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
FCEUI_VSUniCoin(); // insert coin for VS Games
|
|
|
|
}
|
2008-10-01 23:00:12 +02:00
|
|
|
}
|
2008-10-01 07:16:59 +02:00
|
|
|
}
|
2008-09-02 03:57:21 +02:00
|
|
|
}
|
2008-11-04 09:28:52 +01:00
|
|
|
|
2016-12-10 20:37:33 +01:00
|
|
|
// zapper enabled
|
|
|
|
if(GCSettings.Controller == CTRL_ZAPPER)
|
|
|
|
{
|
|
|
|
int z; // NES port # (0 or 1)
|
|
|
|
|
|
|
|
if(GameInfo->type == GIT_VSUNI)
|
|
|
|
z = 0;
|
|
|
|
else
|
|
|
|
z = 1;
|
2008-09-04 04:46:04 +02:00
|
|
|
|
2016-12-10 20:37:33 +01:00
|
|
|
myzappers[z][2] = 0; // reset trigger to not pressed
|
|
|
|
|
|
|
|
// is trigger pressed?
|
|
|
|
if ( (jp & btnmap[CTRL_ZAPPER][CTRLR_GCPAD][0]) // gamecube controller
|
|
|
|
#ifdef HW_RVL
|
|
|
|
|| ( (exp_type == WPAD_EXP_NONE) && (wp & btnmap[CTRL_ZAPPER][CTRLR_WIIMOTE][0]) ) // wiimote
|
|
|
|
#endif
|
|
|
|
)
|
|
|
|
{
|
|
|
|
// report trigger press
|
|
|
|
myzappers[z][2] |= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
// VS zapper games
|
|
|
|
if ( (jp & btnmap[CTRL_ZAPPER][CTRLR_GCPAD][1]) // gamecube controller
|
|
|
|
#ifdef HW_RVL
|
|
|
|
|| ( (exp_type == WPAD_EXP_NONE) && (wp & btnmap[CTRL_ZAPPER][CTRLR_WIIMOTE][1]) ) // wiimote
|
|
|
|
#endif
|
|
|
|
)
|
|
|
|
{
|
|
|
|
FCEUI_VSUniCoin(); // insert coin for VS zapper games
|
|
|
|
}
|
|
|
|
|
|
|
|
// cursor position
|
|
|
|
UpdateCursorPosition(0); // update cursor for wiimote 1
|
|
|
|
myzappers[z][0] = pos_x;
|
|
|
|
myzappers[z][1] = pos_y;
|
|
|
|
|
|
|
|
// Report changes to FCE Ultra
|
|
|
|
zapperdata[z]->Update(z,myzappers[z],0);
|
|
|
|
}
|
2008-09-04 04:46:04 +02:00
|
|
|
|
|
|
|
return J;
|
2008-09-02 03:57:21 +02:00
|
|
|
}
|
|
|
|
|
2009-05-28 06:16:11 +02:00
|
|
|
bool MenuRequested()
|
2008-09-02 03:57:21 +02:00
|
|
|
{
|
2009-05-28 06:16:11 +02:00
|
|
|
for(int i=0; i<4; i++)
|
2008-09-02 03:57:21 +02:00
|
|
|
{
|
2009-04-13 10:43:20 +02:00
|
|
|
if (
|
|
|
|
(userInput[i].pad.substickX < -70) ||
|
2009-04-14 05:21:21 +02:00
|
|
|
(userInput[i].pad.btns_h & PAD_BUTTON_START &&
|
|
|
|
userInput[i].pad.btns_h & PAD_BUTTON_A &&
|
|
|
|
userInput[i].pad.btns_h & PAD_BUTTON_B &&
|
|
|
|
userInput[i].pad.btns_h & PAD_TRIGGER_Z
|
2016-09-18 05:43:24 +02:00
|
|
|
)
|
|
|
|
#ifdef HW_RVL
|
|
|
|
|| (userInput[i].wpad->btns_h & WPAD_BUTTON_HOME) ||
|
|
|
|
(userInput[i].wpad->btns_h & WPAD_CLASSIC_BUTTON_HOME) ||
|
|
|
|
(userInput[i].wupcdata.btns_h & WPAD_CLASSIC_BUTTON_HOME)
|
|
|
|
#endif
|
2009-04-13 10:43:20 +02:00
|
|
|
)
|
|
|
|
{
|
2009-05-28 06:16:11 +02:00
|
|
|
return true;
|
2009-04-13 10:43:20 +02:00
|
|
|
}
|
2008-09-02 03:57:21 +02:00
|
|
|
}
|
2009-05-28 06:16:11 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GetJoy()
|
|
|
|
{
|
|
|
|
JSReturn = 0; // reset buttons pressed
|
|
|
|
unsigned char pad[4];
|
|
|
|
short i;
|
|
|
|
|
2009-06-27 22:05:45 +02:00
|
|
|
UpdatePads();
|
|
|
|
|
2016-12-10 20:37:33 +01:00
|
|
|
// Turbo mode
|
|
|
|
// RIGHT on c-stick and on classic ctrlr right joystick
|
|
|
|
if(userInput[0].pad.substickX > 70 || userInput[0].WPAD_StickX(1) > 70 || userInput[0].wupcdata.substickX > 560)
|
|
|
|
turbomode = 1;
|
|
|
|
else
|
|
|
|
turbomode = 0;
|
2009-05-28 06:16:11 +02:00
|
|
|
|
|
|
|
// request to go back to menu
|
|
|
|
if(MenuRequested())
|
|
|
|
ScreenshotRequested = 1; // go to the menu
|
2008-09-02 03:57:21 +02:00
|
|
|
|
2009-04-13 10:43:20 +02:00
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
pad[i] = DecodeJoy(i);
|
|
|
|
|
|
|
|
JSReturn = pad[0] | pad[1] << 8 | pad[2] << 16 | pad[3] << 24;
|
2008-09-02 03:57:21 +02:00
|
|
|
}
|