- gc and wm analogs now use the same algorithm (thanks eke eke)

- moved controller stuff to new file
This commit is contained in:
michniewski 2008-08-20 04:07:38 +00:00
parent 4d372ffa07
commit 6d0f044f40
7 changed files with 798 additions and 622 deletions

View File

@ -35,6 +35,7 @@
#include "smbop.h"
#include "fileop.h"
#include "memcardop.h"
#include "input.h"
int offset;
int selection;
@ -219,18 +220,21 @@ void StripExt(char* returnstring, char * inputstring)
*
* Let user select a file from the listing
****************************************************************************/
#define PADCAL 40
int
FileSelector (int method)
int FileSelector (int method)
{
u32 p, wp, ph, wh;
signed char a, c;
u32 p = 0;
u32 wp = 0;
u32 ph = 0;
u32 wh = 0;
signed char gc_ay = 0;
signed char gc_sx = 0;
signed char wm_ay = 0;
signed char wm_sx = 0;
int haverom = 0;
int redraw = 1;
int selectit = 0;
float mag, mag2;
u16 ang, ang2;
int scroll_delay = 0;
bool move_selection = 0;
#define SCROLL_INITIAL_DELAY 15
@ -244,25 +248,21 @@ FileSelector (int method)
VIDEO_WaitVSync(); // slow things down a bit so we don't overread the pads
gc_ay = PAD_StickY (0);
gc_sx = PAD_SubStickX (0);
p = PAD_ButtonsDown (0);
ph = PAD_ButtonsHeld (0);
#ifdef HW_RVL
wm_ay = WPAD_StickY (0, 0);
wm_sx = WPAD_StickX (0, 1);
wp = WPAD_ButtonsDown (0);
wh = WPAD_ButtonsHeld (0);
wpad_get_analogues(0, &mag, &ang, &mag2, &ang2); // get joystick info from wii expansions
#else
wp = 0;
wh = 0;
ang = 0;
ang2 = 0;
mag = 0;
mag2 = 0;
#endif
a = PAD_StickY (0);
c = PAD_SubStickX (0);
/*** Check for exit combo ***/
if ( (c < -70) || (wp & WPAD_BUTTON_HOME) || (wp & WPAD_CLASSIC_BUTTON_HOME) )
if ( (gc_sx < -70) || (wm_sx < -70) || (wp & WPAD_BUTTON_HOME) || (wp & WPAD_CLASSIC_BUTTON_HOME) )
return 0;
/*** Check buttons, perform actions ***/
@ -366,7 +366,7 @@ FileSelector (int method)
return 0;
}
} // End of B
if ( ((p | ph) & PAD_BUTTON_DOWN) || ((wp | wh) & (WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN)) || (a < -PADCAL) || (mag>JOY_THRESHOLD && (ang>130 && ang<230)) )
if ( ((p | ph) & PAD_BUTTON_DOWN) || ((wp | wh) & (WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN)) || (gc_ay < -PADCAL) || (wm_ay < -PADCAL) )
{
if ( (p & PAD_BUTTON_DOWN) || (wp & (WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN)) ) { /*** Button just pressed ***/
scroll_delay = SCROLL_INITIAL_DELAY; // reset scroll delay.
@ -390,7 +390,7 @@ FileSelector (int method)
move_selection = 0;
}
} // End of down
if ( ((p | ph) & PAD_BUTTON_UP) || ((wp | wh) & (WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP)) || (a > PADCAL) || (mag>JOY_THRESHOLD && (ang>300 || ang<50)) )
if ( ((p | ph) & PAD_BUTTON_UP) || ((wp | wh) & (WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP)) || (gc_ay > PADCAL) || (wm_ay > PADCAL) )
{
if ( (p & PAD_BUTTON_UP) || (wp & (WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP)) ) { /*** Button just pressed***/
scroll_delay = SCROLL_INITIAL_DELAY; // reset scroll delay.

664
source/ngc/input.cpp Normal file
View File

@ -0,0 +1,664 @@
#include <gccore.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ogcsys.h>
#include <unistd.h>
#include <wiiuse/wpad.h>
#include "snes9x.h"
#include "memmap.h"
#include "controls.h"
#include "snes9xGX.h"
#include "button_mapping.h"
#include "s9xconfig.h"
#include "menu.h"
#include "video.h"
#include "input.h"
#include "menudraw.h"
extern int ConfigRequested;
/****************************************************************************
* Controller Functions
*
* The following map the NGC Pads to the *NEW* controller system.
****************************************************************************/
#define ASSIGN_BUTTON_TRUE( keycode, snescmd ) \
S9xMapButton( keycode, cmd = S9xGetCommandT(snescmd), true)
#define ASSIGN_BUTTON_FALSE( keycode, snescmd ) \
S9xMapButton( keycode, cmd = S9xGetCommandT(snescmd), false)
#define MAXJP 12
/*** Gamecube controller Padmap ***/
unsigned int gcpadmap[] = { PAD_BUTTON_A, PAD_BUTTON_B,
PAD_BUTTON_X, PAD_BUTTON_Y,
PAD_TRIGGER_L, PAD_TRIGGER_R,
PAD_TRIGGER_Z, PAD_BUTTON_START,
PAD_BUTTON_UP, PAD_BUTTON_DOWN,
PAD_BUTTON_LEFT, PAD_BUTTON_RIGHT
};
/*** Wiimote Padmap ***/
unsigned int wmpadmap[] = { WPAD_BUTTON_B, WPAD_BUTTON_2,
WPAD_BUTTON_1, WPAD_BUTTON_A,
0x0000, 0x0000,
WPAD_BUTTON_MINUS, WPAD_BUTTON_PLUS,
WPAD_BUTTON_RIGHT, WPAD_BUTTON_LEFT,
WPAD_BUTTON_UP, WPAD_BUTTON_DOWN
};
/*** Classic Controller Padmap ***/
unsigned int ccpadmap[] = { WPAD_CLASSIC_BUTTON_A, WPAD_CLASSIC_BUTTON_B,
WPAD_CLASSIC_BUTTON_X, WPAD_CLASSIC_BUTTON_Y,
WPAD_CLASSIC_BUTTON_FULL_L, WPAD_CLASSIC_BUTTON_FULL_R,
WPAD_CLASSIC_BUTTON_MINUS, WPAD_CLASSIC_BUTTON_PLUS,
WPAD_CLASSIC_BUTTON_UP, WPAD_CLASSIC_BUTTON_DOWN,
WPAD_CLASSIC_BUTTON_LEFT, WPAD_CLASSIC_BUTTON_RIGHT
};
/*** Nunchuk + wiimote Padmap ***/
unsigned int ncpadmap[] = { WPAD_BUTTON_A, WPAD_BUTTON_B,
WPAD_NUNCHUK_BUTTON_C, WPAD_NUNCHUK_BUTTON_Z,
WPAD_BUTTON_MINUS, WPAD_BUTTON_PLUS,
WPAD_BUTTON_2, WPAD_BUTTON_1,
WPAD_BUTTON_UP, WPAD_BUTTON_DOWN,
WPAD_BUTTON_LEFT, WPAD_BUTTON_RIGHT
};
/*** Superscope : GC controller button mapping ***/
unsigned int gcscopemap[] = { PAD_TRIGGER_Z, PAD_BUTTON_B,
PAD_BUTTON_A, PAD_BUTTON_Y, PAD_BUTTON_START
};
/*** Superscope : wiimote button mapping ***/
unsigned int wmscopemap[] = { WPAD_BUTTON_MINUS, WPAD_BUTTON_B,
WPAD_BUTTON_A, WPAD_BUTTON_DOWN, WPAD_BUTTON_PLUS
};
/*** Mouse : GC controller button mapping ***/
unsigned int gcmousemap[] = { PAD_BUTTON_A, PAD_BUTTON_B };
/*** Mouse : wiimote button mapping ***/
unsigned int wmmousemap[] = { WPAD_BUTTON_A, WPAD_BUTTON_B };
/*** Justifier : GC controller button mapping ***/
unsigned int gcjustmap[] = { PAD_BUTTON_A, PAD_BUTTON_B, PAD_BUTTON_START };
/*** Justifier : wiimote button mapping ***/
unsigned int wmjustmap[] = { WPAD_BUTTON_A, WPAD_BUTTON_B, WPAD_BUTTON_PLUS };
s8 WPAD_StickX(u8 chan,u8 right)
{
float mag = 0.0;
float ang = 0.0;
WPADData *data = WPAD_Data(chan);
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;
double val = mag * sin((PI * ang)/180.0f);
return (s8)(val * 128.0f);
}
s8 WPAD_StickY(u8 chan, u8 right)
{
float mag = 0.0;
float ang = 0.0;
WPADData *data = WPAD_Data(chan);
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;
double val = mag * cos((PI * ang)/180.0f);
return (s8)(val * 128.0f);
}
// hold superscope/mouse/justifier cursor positions
static int cursor_x[5] = {0,0,0,0,0};
static int cursor_y[5] = {0,0,0,0,0};
void UpdateCursorPosition (int pad, int &pos_x, int &pos_y)
{
#define SCOPEPADCAL 20
// gc left joystick
signed char pad_x = PAD_StickX (pad);
signed char pad_y = PAD_StickY (pad);
if (pad_x > SCOPEPADCAL){
pos_x += (pad_x*1.0)/SCOPEPADCAL;
if (pos_x > 256) pos_x = 256;
}
if (pad_x < -SCOPEPADCAL){
pos_x -= (pad_x*-1.0)/SCOPEPADCAL;
if (pos_x < 0) pos_x = 0;
}
if (pad_y < -SCOPEPADCAL){
pos_y += (pad_y*-1.0)/SCOPEPADCAL;
if (pos_y > 224) pos_y = 224;
}
if (pad_y > SCOPEPADCAL){
pos_y -= (pad_y*1.0)/SCOPEPADCAL;
if (pos_y < 0) pos_y = 0;
}
#ifdef HW_RVL
struct ir_t ir; // wiimote ir
WPAD_IR(pad, &ir);
if (ir.valid)
{
pos_x = (ir.x * 256) / 640;
pos_y = (ir.y * 224) / 480;
}
else
{
signed char wm_ax = WPAD_StickX (pad, 0);
signed char wm_ay = WPAD_StickY (pad, 0);
if (wm_ax > SCOPEPADCAL){
pos_x += (wm_ax*1.0)/SCOPEPADCAL;
if (pos_x > 256) pos_x = 256;
}
if (wm_ax < -SCOPEPADCAL){
pos_x -= (wm_ax*-1.0)/SCOPEPADCAL;
if (pos_x < 0) pos_x = 0;
}
if (wm_ay < -SCOPEPADCAL){
pos_y += (wm_ay*-1.0)/SCOPEPADCAL;
if (pos_y > 224) pos_y = 224;
}
if (wm_ay > SCOPEPADCAL){
pos_y -= (wm_ay*1.0)/SCOPEPADCAL;
if (pos_y < 0) pos_y = 0;
}
}
#endif
}
/****************************************************************************
* This is the joypad algorithm submitted by Krullo.
****************************************************************************/
void decodepad (int pad)
{
int i, offset;
float t;
signed char wm_ax = 0;
signed char wm_ay = 0;
u32 wp = 0;
signed char pad_x = PAD_StickX (pad);
signed char pad_y = PAD_StickY (pad);
u32 jp = PAD_ButtonsHeld (pad);
#ifdef HW_RVL
wm_ax = WPAD_StickX ((u8)pad, 0);
wm_ay = WPAD_StickY ((u8)pad, 0);
wp = WPAD_ButtonsHeld (pad);
u32 exp_type;
if ( WPAD_Probe(pad, &exp_type) != 0 ) exp_type = WPAD_EXP_NONE;
#endif
/***
Gamecube Joystick input
***/
// Is XY inside the "zone"?
if (pad_x * pad_x + pad_y * pad_y > PADCAL * PADCAL)
{
/*** we don't want division by zero ***/
if (pad_x > 0 && pad_y == 0)
jp |= PAD_BUTTON_RIGHT;
if (pad_x < 0 && pad_y == 0)
jp |= PAD_BUTTON_LEFT;
if (pad_x == 0 && pad_y > 0)
jp |= PAD_BUTTON_UP;
if (pad_x == 0 && pad_y < 0)
jp |= PAD_BUTTON_DOWN;
if (pad_x != 0 && pad_y != 0)
{
/*** Recalc left / right ***/
t = (float) pad_y / pad_x;
if (t >= -2.41421356237 && t < 2.41421356237)
{
if (pad_x >= 0)
jp |= PAD_BUTTON_RIGHT;
else
jp |= PAD_BUTTON_LEFT;
}
/*** Recalc up / down ***/
t = (float) pad_x / pad_y;
if (t >= -2.41421356237 && t < 2.41421356237)
{
if (pad_y >= 0)
jp |= PAD_BUTTON_UP;
else
jp |= PAD_BUTTON_DOWN;
}
}
}
#ifdef HW_RVL
/***
Wii Joystick (classic, nunchuk) input
***/
// Is XY inside the "zone"?
if (wm_ax * wm_ax + wm_ay * wm_ay > PADCAL * PADCAL)
{
/*** we don't want division by zero ***/
if (wm_ax > 0 && wm_ay == 0)
wp |= WPAD_BUTTON_RIGHT | WPAD_CLASSIC_BUTTON_RIGHT;
if (wm_ax < 0 && wm_ay == 0)
wp |= WPAD_BUTTON_LEFT | WPAD_CLASSIC_BUTTON_LEFT;
if (wm_ax == 0 && wm_ay > 0)
wp |= WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP;
if (wm_ax == 0 && wm_ay < 0)
wp |= WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN;
if (wm_ax != 0 && wm_ay != 0)
{
/*** Recalc left / right ***/
t = (float) wm_ay / wm_ax;
if (t >= -2.41421356237 && t < 2.41421356237)
{
if (wm_ax >= 0)
wp |= WPAD_BUTTON_RIGHT | WPAD_CLASSIC_BUTTON_RIGHT;
else
wp |= WPAD_BUTTON_LEFT | WPAD_CLASSIC_BUTTON_LEFT;
}
/*** Recalc up / down ***/
t = (float) wm_ax / wm_ay;
if (t >= -2.41421356237 && t < 2.41421356237)
{
if (wm_ay >= 0)
wp |= WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP;
else
wp |= WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN;
}
}
}
#endif
/*** Fix offset to pad ***/
offset = ((pad + 1) << 4);
/*** Report pressed buttons (gamepads) ***/
for (i = 0; i < MAXJP; i++)
{
if ( (jp & gcpadmap[i]) // gamecube controller
#ifdef HW_RVL
|| ( (exp_type == WPAD_EXP_NONE) && (wp & wmpadmap[i]) ) // wiimote
|| ( (exp_type == WPAD_EXP_CLASSIC) && (wp & ccpadmap[i]) ) // classic controller
|| ( (exp_type == WPAD_EXP_NUNCHUK) && (wp & ncpadmap[i]) ) // nunchuk + wiimote
#endif
)
S9xReportButton (offset + i, true);
else
S9xReportButton (offset + i, false);
}
/*** Superscope ***/
if (Settings.SuperScopeMaster && pad == GCSettings.Superscope-1) // report only once
{
// buttons
offset = 0x50;
for (i = 0; i < 6; i++)
{
if ( jp & gcscopemap[i]
#ifdef HW_RVL
|| wp & wmscopemap[i]
#endif
)
S9xReportButton (offset + i, true);
else
S9xReportButton (offset + i, false);
}
// pointer
offset = 0x80;
UpdateCursorPosition (pad, cursor_x[0], cursor_y[0]);
S9xReportPointer(offset, (u16)cursor_x[0], (u16)cursor_y[0]);
}
/*** Mouse ***/
else if (Settings.MouseMaster && pad < GCSettings.Mouse)
{
// buttons
offset = 0x60+(2*pad);
for (i = 0; i < 2; i++)
{
if ( jp & gcmousemap[i]
#ifdef HW_RVL
|| wp & wmmousemap[i]
#endif
)
S9xReportButton (offset + i, true);
else
S9xReportButton (offset + i, false);
}
// pointer
offset = 0x81;
UpdateCursorPosition (pad, cursor_x[1+pad], cursor_y[1+pad]);
S9xReportPointer(offset+pad, (u16)cursor_x[1+pad], (u16)cursor_y[1+pad]);
}
/*** Justifier ***/
else if (Settings.JustifierMaster && pad < GCSettings.Justifier)
{
// buttons
offset = 0x70+(3*pad);
for (i = 0; i < 3; i++)
{
if ( jp & gcjustmap[i]
#ifdef HW_RVL
|| wp & wmjustmap[i]
#endif
)
S9xReportButton (offset + i, true);
else
S9xReportButton (offset + i, false);
}
// pointer
offset = 0x83;
UpdateCursorPosition (pad, cursor_x[3+pad], cursor_y[3+pad]);
S9xReportPointer(offset+pad, (u16)cursor_x[3+pad], (u16)cursor_y[3+pad]);
}
}
/****************************************************************************
* NGCReportButtons
* Called on each rendered frame
****************************************************************************/
void NGCReportButtons ()
{
s8 gc_px = PAD_SubStickX (0);
s8 gc_py = PAD_SubStickY (0);
u16 gc_pb = PAD_ButtonsHeld (0);
#ifdef HW_RVL
s8 wm_sx = WPAD_StickX (0,1);
s8 wm_sy = WPAD_StickY (0,1);
u32 wm_pb = WPAD_ButtonsHeld (0); // wiimote / expansion button info
#endif
/*** Check for video zoom ***/
if (GCSettings.NGCZoom)
{
if (gc_py < -18 || gc_py > 18)
zoom ((float) gc_py / -18);
#ifdef HW_RVL
if (wm_sy < -18 || wm_sy > 18)
zoom ((float) wm_sy / -18);
#endif
}
Settings.TurboMode = ( (gc_px > 70)
#ifdef HW_RVL
|| (wm_sx > 70)
#endif
); // RIGHT on c-stick and on classic ctrlr right joystick
/*** Check for menu:
CStick left
OR "L+R+X+Y" (eg. Hombrew/Adapted SNES controllers)
OR "Home" on the wiimote or classic controller
OR LEFT on classic right analog stick***/
if ((gc_px < -70) ||
((gc_pb & PAD_TRIGGER_L) &&
(gc_pb & PAD_TRIGGER_R ) &&
(gc_pb & PAD_BUTTON_X) &&
(gc_pb & PAD_BUTTON_Y ))
#ifdef HW_RVL
|| (wm_pb & WPAD_BUTTON_HOME)
|| (wm_pb & WPAD_CLASSIC_BUTTON_HOME)
|| (wm_sx < -70)
#endif
)
{
ConfigRequested = 1; // go to the menu
}
else
{
int j = (Settings.MultiPlayer5Master == true ? 4 : 2);
for (int i = 0; i < j; i++)
decodepad (i);
}
}
/****************************************************************************
* wpad_get_analogues()
*
* gets the analogue stick magnitude and angle values (
* from classic or nunchuk expansions)
***************************************************************************
u32 wpad_get_analogues(int pad, float* mag1, u16* ang1, float* mag2, u16* ang2)
{
*mag1 = *ang1 = *mag2 = *ang2 = 0;
u32 exp_type = 0;
#ifdef HW_RVL
struct expansion_t exp;
memset( &exp, 0, sizeof(exp) );
if ( WPAD_Probe( pad, &exp_type) == 0) // check wiimote and expansion status (first if wiimote is connected & no errors)
{
WPAD_Expansion(pad, &exp); // expansion connected. get info
if (exp_type == WPAD_EXP_CLASSIC)
{
*ang1 = exp.classic.ljs.ang; // left cc joystick
*mag1 = exp.classic.ljs.mag;
*ang2 = exp.classic.rjs.ang; // right cc joystick
*mag2 = exp.classic.rjs.mag;
}
else if (exp_type == WPAD_EXP_NUNCHUK)
{
*ang1 = exp.nunchuk.js.ang; // nunchuk joystick
*mag1 = exp.nunchuk.js.mag;
}
}
#endif
return exp_type; // return expansion type
}
*/
void SetControllers ()
{
if (Settings.MultiPlayer5Master == true)
{
S9xSetController (0, CTL_JOYPAD, 0, 0, 0, 0);
S9xSetController (1, CTL_MP5, 1, 2, 3, -1);
}
else if (Settings.SuperScopeMaster == true)
{
S9xSetController (0, CTL_JOYPAD, 0, 0, 0, 0);
S9xSetController (1, CTL_SUPERSCOPE, 1, 0, 0, 0);
}
else if (Settings.MouseMaster == true)
{
S9xSetController (0, CTL_MOUSE, 0, 0, 0, 0);
if (GCSettings.Mouse == 2)
S9xSetController (1, CTL_MOUSE, 1, 0, 0, 0);
else
S9xSetController (1, CTL_JOYPAD, 1, 0, 0, 0);
}
else if (Settings.JustifierMaster == true)
{
S9xSetController(0, CTL_JUSTIFIER, 0, 0, 0, 0);
if(GCSettings.Justifier == 2)
S9xSetController(1, CTL_JUSTIFIER, 1, 0, 0, 0);
else
S9xSetController (1, CTL_JOYPAD, 1, 0, 0, 0);
}
else
{
// Plugin 2 Joypads by default
S9xSetController (0, CTL_JOYPAD, 0, 0, 0, 0);
S9xSetController (1, CTL_JOYPAD, 1, 0, 0, 0);
}
}
/****************************************************************************
* Set the default mapping for NGC
****************************************************************************/
void SetDefaultButtonMap ()
{
int maxcode = 0x10;
s9xcommand_t cmd;
/*** Joypad 1 ***/
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 A");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 B");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 X");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 Y");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 L");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 R");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 Select");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 Start");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 Up");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 Down");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 Left");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 Right");
maxcode = 0x20;
/*** Joypad 2 ***/
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 A");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 B");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 X");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 Y");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 L");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 R");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 Select");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 Start");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 Up");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 Down");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 Left");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 Right");
maxcode = 0x30;
/*** Joypad 3 ***/
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 A");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 B");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 X");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 Y");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 L");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 R");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 Select");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 Start");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 Up");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 Down");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 Left");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 Right");
maxcode = 0x40;
/*** Joypad 4 ***/
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 A");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 B");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 X");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 Y");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 L");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 R");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 Select");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 Start");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 Up");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 Down");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 Left");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 Right");
maxcode = 0x50;
/*** Superscope ***/
ASSIGN_BUTTON_FALSE (maxcode++, "Superscope AimOffscreen");
ASSIGN_BUTTON_FALSE (maxcode++, "Superscope Fire");
ASSIGN_BUTTON_FALSE (maxcode++, "Superscope Cursor");
ASSIGN_BUTTON_FALSE (maxcode++, "Superscope ToggleTurbo");
ASSIGN_BUTTON_FALSE (maxcode++, "Superscope Pause");
maxcode = 0x60;
/*** Mouse ***/
ASSIGN_BUTTON_FALSE (maxcode++, "Mouse1 L");
ASSIGN_BUTTON_FALSE (maxcode++, "Mouse1 R");
ASSIGN_BUTTON_FALSE (maxcode++, "Mouse2 L");
ASSIGN_BUTTON_FALSE (maxcode++, "Mouse2 R");
maxcode = 0x70;
/*** Justifier ***/
ASSIGN_BUTTON_FALSE (maxcode++, "Justifier1 AimOffscreen");
ASSIGN_BUTTON_FALSE (maxcode++, "Justifier1 Trigger");
ASSIGN_BUTTON_FALSE (maxcode++, "Justifier1 Start");
ASSIGN_BUTTON_FALSE (maxcode++, "Justifier2 AimOffscreen");
ASSIGN_BUTTON_FALSE (maxcode++, "Justifier2 Trigger");
ASSIGN_BUTTON_FALSE (maxcode++, "Justifier2 Start");
maxcode = 0x80;
S9xMapPointer( maxcode++, S9xGetCommandT("Pointer Superscope"), false);
S9xMapPointer( maxcode++, S9xGetCommandT("Pointer Mouse1"), false);
S9xMapPointer( maxcode++, S9xGetCommandT("Pointer Mouse2"), false);
S9xMapPointer( maxcode++, S9xGetCommandT("Pointer Justifier1"), false);
S9xMapPointer( maxcode++, S9xGetCommandT("Pointer Justifier2"), false);
SetControllers ();
}

36
source/ngc/input.h Normal file
View File

@ -0,0 +1,36 @@
#ifndef _INPUT_H_
#define _INPUT_H_
#include <gccore.h>
#define PI 3.14159265f
#define PADCAL 50
extern unsigned int gcpadmap[];
extern unsigned int wmpadmap[];
extern unsigned int ccpadmap[];
extern unsigned int ncpadmap[];
extern unsigned int gcscopemap[];
extern unsigned int wmscopemap[];
extern unsigned int gcmousemap[];
extern unsigned int wmmousemap[];
extern unsigned int gcjustmap[];
extern unsigned int wmjustmap[];
START_EXTERN_C
s8 WPAD_StickX(u8 chan,u8 right);
s8 WPAD_StickY(u8 chan, u8 right);
void UpdateCursorPosition (int pad, int &pos_x, int &pos_y);
void decodepad (int pad);
void NGCReportButtons ();
void SetControllers ();
void SetDefaultButtonMap ();
//extern u32 wpad_get_analogues(int pad, float* mag1, u16* ang1, float* mag2, u16* ang2);
END_EXTERN_C
#endif

View File

@ -52,6 +52,7 @@
#include "button_mapping.h"
#include "menudraw.h"
#include "cheatmgr.h"
#include "input.h"
extern void DrawMenu (char items[][50], char *title, int maxitems, int selected, int fontsize);
@ -316,8 +317,6 @@ static int cheatmenuCount = 0;
static char cheatmenu[MAX_CHEATS][50];
static char cheatmenuvalue[MAX_CHEATS][50];
#define PADCAL 40
void CheatMenu()
{
int ret = -1;
@ -326,12 +325,18 @@ void CheatMenu()
int selection = 0;
int offset = 0;
u32 p, wp, ph, wh;
signed char a, c;
int redraw = 1;
int selectit = 0;
float mag, mag2;
u16 ang, ang2;
u32 p = 0;
u32 wp = 0;
u32 ph = 0;
u32 wh = 0;
signed char gc_ay = 0;
signed char gc_sx = 0;
signed char wm_ay = 0;
signed char wm_sx = 0;
int scroll_delay = 0;
bool move_selection = 0;
#define SCROLL_INITIAL_DELAY 15
@ -368,25 +373,20 @@ void CheatMenu()
VIDEO_WaitVSync(); // slow things down a bit so we don't overread the pads
p = PAD_ButtonsDown (0);
gc_ay = PAD_StickY (0);
gc_sx = PAD_SubStickX (0);
p = PAD_ButtonsDown (0);
ph = PAD_ButtonsHeld (0);
#ifdef HW_RVL
#ifdef HW_RVL
wm_ay = WPAD_StickY (0, 0);
wm_sx = WPAD_StickX (0, 1);
wp = WPAD_ButtonsDown (0);
wh = WPAD_ButtonsHeld (0);
wpad_get_analogues(0, &mag, &ang, &mag2, &ang2); // get joystick info from wii expansions
#else
wp = 0;
wh = 0;
ang = 0;
ang2 = 0;
mag = 0;
mag2 = 0;
#endif
a = PAD_StickY (0);
c = PAD_SubStickX (0);
#endif
/*** Check for exit combo ***/
if ( (c < -70) || (wp & WPAD_BUTTON_HOME) || (wp & WPAD_CLASSIC_BUTTON_HOME) )
if ( (gc_sx < -70) || (wm_sx < -70) || (wp & WPAD_BUTTON_HOME) || (wp & WPAD_CLASSIC_BUTTON_HOME) )
break;
/*** Check buttons, perform actions ***/
@ -399,7 +399,7 @@ void CheatMenu()
ret = selection;
} // End of A
if ( ((p | ph) & PAD_BUTTON_DOWN) || ((wp | wh) & (WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN)) || (a < -PADCAL) || (mag>JOY_THRESHOLD && (ang>130 && ang<230)) )
if ( ((p | ph) & PAD_BUTTON_DOWN) || ((wp | wh) & (WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN)) || (gc_ay < -PADCAL) || (wm_ay < -PADCAL) )
{
if ( (p & PAD_BUTTON_DOWN) || (wp & (WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN)) ) { /*** Button just pressed ***/
scroll_delay = SCROLL_INITIAL_DELAY; // reset scroll delay.
@ -423,7 +423,7 @@ void CheatMenu()
move_selection = 0;
}
} // End of down
if ( ((p | ph) & PAD_BUTTON_UP) || ((wp | wh) & (WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP)) || (a > PADCAL) || (mag>JOY_THRESHOLD && (ang>300 || ang<50)) )
if ( ((p | ph) & PAD_BUTTON_UP) || ((wp | wh) & (WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP)) || (gc_ay > PADCAL) || (wm_ay > PADCAL) )
{
if ( (p & PAD_BUTTON_UP) || (wp & (WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP)) ) { /*** Button just pressed***/
scroll_delay = SCROLL_INITIAL_DELAY; // reset scroll delay.
@ -1006,11 +1006,4 @@ mainmenu (int selectedMenu)
while( PAD_ButtonsHeld(0) )
VIDEO_WaitVSync();
#endif
ReInitGCVideo(); // update video after reading settings
Settings.SuperScopeMaster = (GCSettings.Superscope > 0 ? true : false);
Settings.MouseMaster = (GCSettings.Mouse > 0 ? true : false);
Settings.JustifierMaster = (GCSettings.Justifier > 0 ? true : false);
SetControllers();
}

View File

@ -38,6 +38,7 @@
#include "dvd.h"
#include "aram.h"
#include "images/gfx_bg.h"
#include "input.h"
/*** Globals ***/
FT_Library ftlibrary;
@ -559,11 +560,12 @@ RunMenu (char items[][50], int maxitems, char *title, int fontsize, int x)
{
int redraw = 1;
int quit = 0;
u32 p, wp;
int ret = 0;
signed char a;
float mag, mag2;
u16 ang, ang2;
u32 p = 0;
u32 wp = 0;
signed char gc_ay = 0;
signed char wm_ay = 0;
while (quit == 0)
{
@ -573,30 +575,25 @@ RunMenu (char items[][50], int maxitems, char *title, int fontsize, int x)
redraw = 0;
}
gc_ay = PAD_StickY (0);
p = PAD_ButtonsDown (0);
#ifdef HW_RVL
wm_ay = WPAD_StickY (0,0);
wp = WPAD_ButtonsDown (0);
wpad_get_analogues(0, &mag, &ang, &mag2, &ang2); // get joystick info from wii expansions
#else
wp = 0;
ang = 0;
ang2 = 0;
mag = 0;
mag2 = 0;
#endif
a = PAD_StickY (0);
VIDEO_WaitVSync(); // slow things down a bit so we don't overread the pads
/*** Look for up ***/
if ( (p & PAD_BUTTON_UP) || (wp & (WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP)) || (a > 70) || (mag>JOY_THRESHOLD && (ang>300 || ang<50)) )
if ( (p & PAD_BUTTON_UP) || (wp & (WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP)) || (gc_ay > PADCAL) || (wm_ay > PADCAL) )
{
redraw = 1;
menu = FindMenuItem(&items[0], maxitems, menu, -1);
}
/*** Look for down ***/
if ( (p & PAD_BUTTON_DOWN) || (wp & (WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN)) || (a < -70) || (mag>JOY_THRESHOLD && (ang>130 && ang<230)) )
if ( (p & PAD_BUTTON_DOWN) || (wp & (WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN)) || (gc_ay < -PADCAL) || (wm_ay < -PADCAL) )
{
redraw = 1;
menu = FindMenuItem(&items[0], maxitems, menu, +1);

View File

@ -196,6 +196,7 @@
#include "gctime.h"
#include "button_mapping.h"
#include "fileop.h"
#include "input.h"
unsigned long ARAM_ROMSIZE = 0;
int ConfigRequested = 0;
@ -204,296 +205,9 @@ extern int FrameTimer;
extern long long prev;
extern unsigned int timediffallowed;
// hold superscope/mouse/justifier cursor positions
int cursor_x[5] = {0,0,0,0,0};
int cursor_y[5] = {0,0,0,0,0};
extern void fat_enable_readahead_all();
/****************************************************************************
* Controller Functions
*
* The following map the NGC Pads to the *NEW* controller system.
****************************************************************************/
#define ASSIGN_BUTTON_TRUE( keycode, snescmd ) \
S9xMapButton( keycode, cmd = S9xGetCommandT(snescmd), true)
#define ASSIGN_BUTTON_FALSE( keycode, snescmd ) \
S9xMapButton( keycode, cmd = S9xGetCommandT(snescmd), false)
#define MAXJP 12
int padcal = 50;
/*** Gamecube controller Padmap ***/
unsigned int gcpadmap[] = { PAD_BUTTON_A, PAD_BUTTON_B,
PAD_BUTTON_X, PAD_BUTTON_Y,
PAD_TRIGGER_L, PAD_TRIGGER_R,
PAD_TRIGGER_Z, PAD_BUTTON_START,
PAD_BUTTON_UP, PAD_BUTTON_DOWN,
PAD_BUTTON_LEFT, PAD_BUTTON_RIGHT
};
/*** Wiimote Padmap ***/
unsigned int wmpadmap[] = { WPAD_BUTTON_B, WPAD_BUTTON_2,
WPAD_BUTTON_1, WPAD_BUTTON_A,
0x0000, 0x0000,
WPAD_BUTTON_MINUS, WPAD_BUTTON_PLUS,
WPAD_BUTTON_RIGHT, WPAD_BUTTON_LEFT,
WPAD_BUTTON_UP, WPAD_BUTTON_DOWN
};
/*** Classic Controller Padmap ***/
unsigned int ccpadmap[] = { WPAD_CLASSIC_BUTTON_A, WPAD_CLASSIC_BUTTON_B,
WPAD_CLASSIC_BUTTON_X, WPAD_CLASSIC_BUTTON_Y,
WPAD_CLASSIC_BUTTON_FULL_L, WPAD_CLASSIC_BUTTON_FULL_R,
WPAD_CLASSIC_BUTTON_MINUS, WPAD_CLASSIC_BUTTON_PLUS,
WPAD_CLASSIC_BUTTON_UP, WPAD_CLASSIC_BUTTON_DOWN,
WPAD_CLASSIC_BUTTON_LEFT, WPAD_CLASSIC_BUTTON_RIGHT
};
/*** Nunchuk + wiimote Padmap ***/
unsigned int ncpadmap[] = { WPAD_BUTTON_A, WPAD_BUTTON_B,
WPAD_NUNCHUK_BUTTON_C, WPAD_NUNCHUK_BUTTON_Z,
WPAD_BUTTON_MINUS, WPAD_BUTTON_PLUS,
WPAD_BUTTON_2, WPAD_BUTTON_1,
WPAD_BUTTON_UP, WPAD_BUTTON_DOWN,
WPAD_BUTTON_LEFT, WPAD_BUTTON_RIGHT
};
/*** Superscope : GC controller button mapping ***/
unsigned int gcscopemap[] = { PAD_TRIGGER_Z, PAD_BUTTON_B,
PAD_BUTTON_A, PAD_BUTTON_Y, PAD_BUTTON_START
};
/*** Superscope : wiimote button mapping ***/
unsigned int wmscopemap[] = { WPAD_BUTTON_MINUS, WPAD_BUTTON_B,
WPAD_BUTTON_A, WPAD_BUTTON_DOWN, WPAD_BUTTON_PLUS
};
/*** Mouse : GC controller button mapping ***/
unsigned int gcmousemap[] = { PAD_BUTTON_A, PAD_BUTTON_B };
/*** Mouse : wiimote button mapping ***/
unsigned int wmmousemap[] = { WPAD_BUTTON_A, WPAD_BUTTON_B };
/*** Justifier : GC controller button mapping ***/
unsigned int gcjustmap[] = { PAD_BUTTON_A, PAD_BUTTON_B, PAD_BUTTON_START };
/*** Justifier : wiimote button mapping ***/
unsigned int wmjustmap[] = { WPAD_BUTTON_A, WPAD_BUTTON_B, WPAD_BUTTON_PLUS };
void UpdateCursorPosition (int pad, int &pos_x, int &pos_y)
{
// gc left joystick
signed char pad_x = PAD_StickX (pad);
signed char pad_y = PAD_StickY (pad);
int SCOPEPADCAL = 20;
#ifdef HW_RVL
// wiimote ir
struct ir_t ir;
#endif
if (pad_x > SCOPEPADCAL){
pos_x += (pad_x*1.0)/SCOPEPADCAL;
if (pos_x > 256) pos_x = 256;
}
if (pad_x < -SCOPEPADCAL){
pos_x -= (pad_x*-1.0)/SCOPEPADCAL;
if (pos_x < 0) pos_x = 0;
}
if (pad_y < -SCOPEPADCAL){
pos_y += (pad_y*-1.0)/SCOPEPADCAL;
if (pos_y > 224) pos_y = 224;
}
if (pad_y > SCOPEPADCAL){
pos_y -= (pad_y*1.0)/SCOPEPADCAL;
if (pos_y < 0) pos_y = 0;
}
#ifdef HW_RVL
// read wiimote IR
WPAD_IR(pad, &ir);
if (ir.valid)
{
pos_x = (ir.x * 256) / 640;
pos_y = (ir.y * 224) / 480;
}
#endif
}
/****************************************************************************
* This is the joypad algorithm submitted by Krullo.
****************************************************************************/
void
decodepad (int pad)
{
int i, offset;
signed char pad_x, pad_y;
//unsigned short jp, wp; //
u32 jp, wp;
float t;
float mag, mag2;
u16 ang, ang2;
u32 exp_type;
/*** Do analogue updates ***/
pad_x = PAD_StickX (pad);
pad_y = PAD_StickY (pad);
jp = PAD_ButtonsHeld (pad);
#ifdef HW_RVL
exp_type = wpad_get_analogues(pad, &mag, &ang, &mag2, &ang2); // get joystick info from wii expansions
wp = WPAD_ButtonsHeld (pad); // wiimote
#else
exp_type = 0;
wp = 0;
ang = 0;
ang2 = 0;
mag = 0;
mag2 = 0;
#endif
/***
Gamecube Joystick input
***/
// Is XY inside the "zone"?
if (pad_x * pad_x + pad_y * pad_y > padcal * padcal)
{
/*** we don't want division by ZERO ***/
if (pad_x > 0 && pad_y == 0)
jp |= PAD_BUTTON_RIGHT;
if (pad_x < 0 && pad_y == 0)
jp |= PAD_BUTTON_LEFT;
if (pad_x == 0 && pad_y > 0)
jp |= PAD_BUTTON_UP;
if (pad_x == 0 && pad_y < 0)
jp |= PAD_BUTTON_DOWN;
if (pad_x != 0 && pad_y != 0)
{
/*** Recalc left / right ***/
t = (float) pad_y / pad_x;
if (t >= -2.41421356237 && t < 2.41421356237)
{
if (pad_x >= 0)
jp |= PAD_BUTTON_RIGHT;
else
jp |= PAD_BUTTON_LEFT;
}
/*** Recalc up / down ***/
t = (float) pad_x / pad_y;
if (t >= -2.41421356237 && t < 2.41421356237)
{
if (pad_y >= 0)
jp |= PAD_BUTTON_UP;
else
jp |= PAD_BUTTON_DOWN;
}
}
}
#ifdef HW_RVL
/***
Wii Joystick (classic, nunchuk) input
***/
if (exp_type == WPAD_EXP_NUNCHUK)
{
if ( mag>JOY_THRESHOLD && (ang>300 || ang<50) )
wp |= WPAD_BUTTON_UP;
if ( mag>JOY_THRESHOLD && (ang>130 && ang<230) )
wp |= WPAD_BUTTON_DOWN;
if ( mag>JOY_THRESHOLD && (ang>220 && ang<320) )
wp |= WPAD_BUTTON_LEFT;
if ( mag>JOY_THRESHOLD && (ang>40 && ang<140) )
wp |= WPAD_BUTTON_RIGHT;
} else if (exp_type == WPAD_EXP_CLASSIC)
{
if ( mag>JOY_THRESHOLD && (ang>300 || ang<50) )
wp |= WPAD_CLASSIC_BUTTON_UP;
if ( mag>JOY_THRESHOLD && (ang>130 && ang<230) )
wp |= WPAD_CLASSIC_BUTTON_DOWN;
if ( mag>JOY_THRESHOLD && (ang>220 && ang<320) )
wp |= WPAD_CLASSIC_BUTTON_LEFT;
if ( mag>JOY_THRESHOLD && (ang>40 && ang<140) )
wp |= WPAD_CLASSIC_BUTTON_RIGHT;
}
#endif
/*** Fix offset to pad ***/
offset = ((pad + 1) << 4);
/*** Report pressed buttons (gamepads) ***/
for (i = 0; i < MAXJP; i++)
{
if ( (jp & gcpadmap[i]) // gamecube controller
#ifdef HW_RVL
|| ( (exp_type == WPAD_EXP_NONE) && (wp & wmpadmap[i]) ) // wiimote
|| ( (exp_type == WPAD_EXP_CLASSIC) && (wp & ccpadmap[i]) ) // classic controller
|| ( (exp_type == WPAD_EXP_NUNCHUK) && (wp & ncpadmap[i]) ) // nunchuk + wiimote
#endif
)
S9xReportButton (offset + i, true);
else
S9xReportButton (offset + i, false);
}
/*** Superscope ***/
if (pad == GCSettings.Superscope-1) // report only once
{
// buttons
offset = 0x50;
for (i = 0; i < 6; i++)
{
if ( jp & gcscopemap[i]
#ifdef HW_RVL
|| wp & wmscopemap[i]
#endif
)
S9xReportButton (offset + i, true);
else
S9xReportButton (offset + i, false);
}
// pointer
offset = 0x80;
UpdateCursorPosition (pad, cursor_x[0], cursor_y[0]);
S9xReportPointer(offset, (u16)cursor_x[0], (u16)cursor_y[0]);
}
/*** Mouse ***/
else if (Settings.MouseMaster && pad < GCSettings.Mouse)
{
// buttons
offset = 0x60+(2*pad);
for (i = 0; i < 2; i++)
{
if ( jp & gcmousemap[i]
#ifdef HW_RVL
|| wp & wmmousemap[i]
#endif
)
S9xReportButton (offset + i, true);
else
S9xReportButton (offset + i, false);
}
// pointer
offset = 0x81;
UpdateCursorPosition (pad, cursor_x[1+pad], cursor_y[1+pad]);
S9xReportPointer(offset+pad, (u16)cursor_x[1+pad], (u16)cursor_y[1+pad]);
}
/*** Justifier ***/
else if (Settings.JustifierMaster && pad < GCSettings.Justifier)
{
// buttons
offset = 0x70+(3*pad);
for (i = 0; i < 3; i++)
{
if ( jp & gcjustmap[i]
#ifdef HW_RVL
|| wp & wmjustmap[i]
#endif
)
S9xReportButton (offset + i, true);
else
S9xReportButton (offset + i, false);
}
// pointer
offset = 0x83;
UpdateCursorPosition (pad, cursor_x[3+pad], cursor_y[3+pad]);
S9xReportPointer(offset+pad, (u16)cursor_x[3+pad], (u16)cursor_y[3+pad]);
}
}
/****************************************************************************
* setFrameTimerMethod()
* change frametimer method depending on whether ROM is NTSC or PAL
@ -522,270 +236,6 @@ void setFrameTimerMethod()
}
return;
}
/****************************************************************************
* NGCReportButtons
* Called on each rendered frame
****************************************************************************/
void
NGCReportButtons ()
{
s8 gc_px = PAD_SubStickX (0);
s8 gc_py = PAD_SubStickY (0);
u16 gc_pb = PAD_ButtonsHeld (0);
#ifdef HW_RVL
float mag1 = 0;
float mag2 = 0;
u16 ang1 = 0;
u16 ang2 = 0;
u32 wm_pb = WPAD_ButtonsHeld (0); // wiimote / expansion button info
wpad_get_analogues(0, &mag1, &ang1, &mag2, &ang2); // get joystick info from wii expansions
#endif
/*** Check for video zoom ***/
if (GCSettings.NGCZoom)
{
if (gc_py < -18 || gc_py > 18)
zoom ((float) gc_py / -18);
#ifdef HW_RVL
if ( mag2>0.2 && (ang2>340 || ang2<20) ) // classic rjs up
zoom ((float) mag2 / -0.2);
if ( mag2>0.2 && (ang2>160 && ang2<200) ) // classic rjs down
zoom ((float) mag2 / 0.2);
#endif
}
Settings.TurboMode = ( (gc_px > 70)
#ifdef HW_RVL
|| (mag2>JOY_THRESHOLD && ang2>75 && ang2<115)
#endif
); // RIGHT on c-stick and on classic ctrlr right joystick
/*** Check for menu:
CStick left
OR "L+R+X+Y" (eg. Hombrew/Adapted SNES controllers)
OR "Home" on the wiimote or classic controller ***/
if ((gc_px < -70) ||
((gc_pb & PAD_TRIGGER_L) &&
(gc_pb & PAD_TRIGGER_R ) &&
(gc_pb & PAD_BUTTON_X) &&
(gc_pb & PAD_BUTTON_Y ))
#ifdef HW_RVL
|| (wm_pb & WPAD_BUTTON_HOME)
|| (wm_pb & WPAD_CLASSIC_BUTTON_HOME)
#endif
)
{
ConfigRequested = 1;
VIDEO_WaitVSync ();
if ( GCSettings.AutoSave == 1 )
{
SaveSRAM ( GCSettings.SaveMethod, SILENT );
}
else if ( GCSettings.AutoSave == 2 )
{
if ( WaitPromptChoice ((char*)"Save Freeze State?", (char*)"Don't Save", (char*)"Save") )
NGCFreezeGame ( GCSettings.SaveMethod, SILENT );
}
else if ( GCSettings.AutoSave == 3 )
{
if ( WaitPromptChoice ((char*)"Save SRAM and Freeze State?", (char*)"Don't Save", (char*)"Save") )
{
SaveSRAM(GCSettings.SaveMethod, SILENT );
NGCFreezeGame ( GCSettings.SaveMethod, SILENT );
}
}
mainmenu (3); // go to game menu
FrameTimer = 0;
ConfigRequested = 0;
setFrameTimerMethod(); // set frametimer method every time a ROM is loaded
S9xReportControllers(); // FIX
}
else
{
int j = (Settings.MultiPlayer5Master == true ? 4 : 2);
for (int i = 0; i < j; i++)
decodepad (i);
}
}
/****************************************************************************
* wpad_get_analogues()
*
* gets the analogue stick magnitude and angle values (
* from classic or nunchuk expansions)
****************************************************************************/
u32 wpad_get_analogues(int pad, float* mag1, u16* ang1, float* mag2, u16* ang2)
{
*mag1 = *ang1 = *mag2 = *ang2 = 0;
u32 exp_type = 0;
#ifdef HW_RVL
struct expansion_t exp;
memset( &exp, 0, sizeof(exp) );
if ( WPAD_Probe( pad, &exp_type) == 0) // check wiimote and expansion status (first if wiimote is connected & no errors)
{
WPAD_Expansion(pad, &exp); // expansion connected. get info
if (exp_type == WPAD_EXP_CLASSIC)
{
*ang1 = exp.classic.ljs.ang; // left cc joystick
*mag1 = exp.classic.ljs.mag;
*ang2 = exp.classic.rjs.ang; // right cc joystick
*mag2 = exp.classic.rjs.mag;
}
else if (exp_type == WPAD_EXP_NUNCHUK)
{
*ang1 = exp.nunchuk.js.ang; // nunchuk joystick
*mag1 = exp.nunchuk.js.mag;
}
}
#endif
return exp_type; // return expansion type
}
void SetControllers ()
{
if (Settings.MultiPlayer5Master == true)
{
S9xSetController (0, CTL_JOYPAD, 0, 0, 0, 0);
S9xSetController (1, CTL_MP5, 1, 2, 3, -1);
}
else if (Settings.SuperScopeMaster == true)
{
S9xSetController (0, CTL_JOYPAD, 0, 0, 0, 0);
S9xSetController (1, CTL_SUPERSCOPE, 1, 0, 0, 0);
}
else if (Settings.MouseMaster == true)
{
S9xSetController (0, CTL_MOUSE, 0, 0, 0, 0);
if (GCSettings.Mouse == 2)
S9xSetController (1, CTL_MOUSE, 1, 0, 0, 0);
else
S9xSetController (1, CTL_JOYPAD, 1, 0, 0, 0);
}
else if (Settings.JustifierMaster == true)
{
S9xSetController(0, CTL_JUSTIFIER, 0, 0, 0, 0);
if(GCSettings.Justifier == 2)
S9xSetController(1, CTL_JUSTIFIER, 1, 0, 0, 0);
else
S9xSetController (1, CTL_JOYPAD, 1, 0, 0, 0);
}
else
{
// Plugin 2 Joypads by default
S9xSetController (0, CTL_JOYPAD, 0, 0, 0, 0);
S9xSetController (1, CTL_JOYPAD, 1, 0, 0, 0);
}
}
/****************************************************************************
* Set the default mapping for NGC
****************************************************************************/
void
SetDefaultButtonMap ()
{
int maxcode = 0x10;
s9xcommand_t cmd;
/*** Joypad 1 ***/
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 A");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 B");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 X");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 Y");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 L");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 R");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 Select");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 Start");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 Up");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 Down");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 Left");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad1 Right");
maxcode = 0x20;
/*** Joypad 2 ***/
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 A");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 B");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 X");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 Y");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 L");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 R");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 Select");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 Start");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 Up");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 Down");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 Left");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad2 Right");
maxcode = 0x30;
/*** Joypad 3 ***/
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 A");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 B");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 X");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 Y");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 L");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 R");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 Select");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 Start");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 Up");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 Down");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 Left");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad3 Right");
maxcode = 0x40;
/*** Joypad 4 ***/
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 A");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 B");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 X");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 Y");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 L");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 R");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 Select");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 Start");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 Up");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 Down");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 Left");
ASSIGN_BUTTON_FALSE (maxcode++, "Joypad4 Right");
maxcode = 0x50;
/*** Superscope ***/
ASSIGN_BUTTON_FALSE (maxcode++, "Superscope AimOffscreen");
ASSIGN_BUTTON_FALSE (maxcode++, "Superscope Fire");
ASSIGN_BUTTON_FALSE (maxcode++, "Superscope Cursor");
ASSIGN_BUTTON_FALSE (maxcode++, "Superscope ToggleTurbo");
ASSIGN_BUTTON_FALSE (maxcode++, "Superscope Pause");
maxcode = 0x60;
/*** Mouse ***/
ASSIGN_BUTTON_FALSE (maxcode++, "Mouse1 L");
ASSIGN_BUTTON_FALSE (maxcode++, "Mouse1 R");
ASSIGN_BUTTON_FALSE (maxcode++, "Mouse2 L");
ASSIGN_BUTTON_FALSE (maxcode++, "Mouse2 R");
maxcode = 0x70;
/*** Justifier ***/
ASSIGN_BUTTON_FALSE (maxcode++, "Justifier1 AimOffscreen");
ASSIGN_BUTTON_FALSE (maxcode++, "Justifier1 Trigger");
ASSIGN_BUTTON_FALSE (maxcode++, "Justifier1 Start");
ASSIGN_BUTTON_FALSE (maxcode++, "Justifier2 AimOffscreen");
ASSIGN_BUTTON_FALSE (maxcode++, "Justifier2 Trigger");
ASSIGN_BUTTON_FALSE (maxcode++, "Justifier2 Start");
maxcode = 0x80;
S9xMapPointer( maxcode++, S9xGetCommandT("Pointer Superscope"), false);
S9xMapPointer( maxcode++, S9xGetCommandT("Pointer Mouse1"), false);
S9xMapPointer( maxcode++, S9xGetCommandT("Pointer Mouse2"), false);
S9xMapPointer( maxcode++, S9xGetCommandT("Pointer Justifier1"), false);
S9xMapPointer( maxcode++, S9xGetCommandT("Pointer Justifier2"), false);
SetControllers ();
}
/****************************************************************************
* Emulation loop
@ -807,9 +257,48 @@ emulate ()
while (1)
{
S9xMainLoop ();
NGCReportButtons ();
}
S9xMainLoop ();
NGCReportButtons ();
if (ConfigRequested)
{
VIDEO_WaitVSync ();
if ( GCSettings.AutoSave == 1 )
{
SaveSRAM ( GCSettings.SaveMethod, SILENT );
}
else if ( GCSettings.AutoSave == 2 )
{
if ( WaitPromptChoice ((char*)"Save Freeze State?", (char*)"Don't Save", (char*)"Save") )
NGCFreezeGame ( GCSettings.SaveMethod, SILENT );
}
else if ( GCSettings.AutoSave == 3 )
{
if ( WaitPromptChoice ((char*)"Save SRAM and Freeze State?", (char*)"Don't Save", (char*)"Save") )
{
SaveSRAM(GCSettings.SaveMethod, SILENT );
NGCFreezeGame ( GCSettings.SaveMethod, SILENT );
}
}
mainmenu (3); // go to game menu
/*** Update any emulation settings changed in the menu ***/
ReInitGCVideo(); // update video after reading settings
FrameTimer = 0;
setFrameTimerMethod(); // set frametimer method every time a ROM is loaded
Settings.SuperScopeMaster = (GCSettings.Superscope > 0 ? true : false);
Settings.MouseMaster = (GCSettings.Mouse > 0 ? true : false);
Settings.JustifierMaster = (GCSettings.Justifier > 0 ? true : false);
SetControllers();
S9xReportControllers(); // FIX
ConfigRequested = 0;
}//if ConfigRequested
}//while
}
/****************************************************************************

View File

@ -202,13 +202,10 @@ struct SGCSettings{
};
START_EXTERN_C
extern struct SGCSettings GCSettings;
extern bool8 isWii;
extern u32 wpad_get_analogues(int pad, float* mag1, u16* ang1, float* mag2, u16* ang2);
extern void SetControllers ();
END_EXTERN_C
#define JOY_THRESHOLD 0.70 // for wii (expansion) analogues
#endif