Example #1
0
/****************************************************************************
 * UpdatePadsCB
 *
 * called by postRetraceCallback in InitGCVideo - scans gcpad and wpad
 ***************************************************************************/
static void
UpdatePadsCB ()
{
	#ifdef HW_RVL
	WPAD_ScanPads();
	#endif
	PAD_ScanPads();

	for(int i=3; i >= 0; i--)
	{
		#ifdef HW_RVL
		memcpy(&userInput[i].wpad, WPAD_Data(i), sizeof(WPADData));
		#endif

		userInput[i].chan = 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);
	}
}
Example #2
0
void
UpdatePads()
{
	#ifdef HW_RVL
	WPAD_ScanPads();
	#endif

	now = gettime();

	if(!padsConnected && diff_sec(prev, now) < 2)
		return;

	prev = now;

	padsConnected = PAD_ScanPads();

	if(!padsConnected)
		return;

	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);
	}
}
Example #3
0
void
UpdatePads()
{
	#ifdef HW_RVL
	WiiDRC_ScanPads();
	WPAD_ScanPads();
	#endif
	
	PAD_ScanPads();

	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);
	}
#ifdef HW_RVL
	if(WiiDRC_Inited() && WiiDRC_Connected())
	{
		userInput[0].wiidrcdata.btns_d = WiiDRC_ButtonsDown();
		userInput[0].wiidrcdata.btns_u = WiiDRC_ButtonsUp();
		userInput[0].wiidrcdata.btns_h = WiiDRC_ButtonsHeld();
		userInput[0].wiidrcdata.stickX = WiiDRC_lStickX();
		userInput[0].wiidrcdata.stickY = WiiDRC_lStickY();
		userInput[0].wiidrcdata.substickX = WiiDRC_rStickX();
		userInput[0].wiidrcdata.substickY = WiiDRC_rStickY();
	}
#endif
}
Example #4
0
u32 InputDevices::GetPadButtonStatus(int channel)
{
    u32 extensions;
    WPADData data;
    u32 buttons, gcbuttons;
    PAD2WPAD *p2w;
    joystick_t padjoy;

    // Check standard buttons
    buttons = WPAD_ButtonsHeld(channel);

    // Add GameCube buttons
    gcbuttons = PAD_ButtonsHeld(channel);
    p2w = pad2wpad;
    while( p2w->pad ) {
        if( gcbuttons & p2w->pad ) {
            buttons |= p2w->wpad;
        }
        p2w++;
    }

    // Key translations for default WiiMote buttons
    ProcessWPadButtons(channel, wpad_default);

    // Check extensions
    WPAD_Probe(channel, &extensions);
    if( extensions == WPAD_EXP_NUNCHUK ) {
      // Nunchuk stick
      WPAD_Expansion(channel, &data.exp);
      buttons |= GetJoystickDirection(&data.exp.nunchuk.js);
      // Nunchuck key translations
      ProcessWPadButtons(channel, wpad_nunchuk);
    } else if( extensions == WPAD_EXP_CLASSIC ) {
      // Both classic controller sticks
      WPAD_Expansion(channel, &data.exp);
      buttons |= GetJoystickDirection(&data.exp.classic.ljs);
      buttons |= GetJoystickDirection(&data.exp.classic.rjs);
      // Classic controller key translations
      ProcessWPadButtons(channel, wpad_classic);
    }

    // Scan GameCube sticks
    padjoy.min.x = 0;
    padjoy.min.y = 0;
    padjoy.max.x = 255;
    padjoy.max.y = 255;
    padjoy.center.x = 128;
    padjoy.center.y = 128;

    padjoy.pos.x = (int)PAD_StickX(channel) + 128;
    padjoy.pos.y = (int)PAD_StickY(channel) + 128;
    buttons |= GetJoystickDirection(&padjoy);

    padjoy.pos.x = (int)PAD_SubStickX(channel) + 128;
    padjoy.pos.y = (int)PAD_SubStickY(channel) + 128;
    buttons |= GetJoystickDirection(&padjoy);

    return buttons;
}
Example #5
0
/****************************************************************************
 * NGCReportButtons
 *
 * Called on each rendered frame
 * Our way of putting controller input into Snes9x
 ***************************************************************************/
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 < -36 || gc_py > 36)
			zoom ((float) gc_py / -36);
#ifdef HW_RVL
		if (wm_sy < -36 || wm_sy > 36)
			zoom ((float) wm_sy / -36);
#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);
    }
}
Example #6
0
qboolean IN_GetGCPadCursorPos(incursorcoords_t* p)
{
	PAD_ScanPads();
	p->x = window_center_x + PAD_SubStickX(0);
	p->y = window_center_y + PAD_SubStickY(0);
	if((p->x != window_center_x)||(p->y != window_center_y))
		return true;

	return false;
}
Example #7
0
u32 OnePieceInput(unsigned short pad) {
	// Only Nunchuk and Gamecube controls available
	// Wiimote and Classic controls depend on user configuration
	u32 J = StandardMovement(pad) 
		    | DecodeWiimote(pad) | DecodeClassic(pad);
	static u32 LastDir = VBA_RIGHT;
	bool JumpButton=0, AttackButton=0, ViewButton=0, CharacterButton=0, PauseButton=0,
	DashButton=0, GrabButton=0, SpeedButton=0, AttackUpButton = 0;
#ifdef HW_RVL
	WPADData * wp = WPAD_Data(pad);
	// Nunchuk controls are based on One Piece: Unlimited Adventure for the Wii
	if (wp->exp.type == WPAD_EXP_NUNCHUK) {
		J |= StandardDPad(pad);
		JumpButton = wp->btns_h & WPAD_BUTTON_B;
		AttackButton = wp->btns_h & WPAD_BUTTON_A;
		CharacterButton = wp->btns_h & WPAD_BUTTON_MINUS;
		PauseButton = wp->btns_h & WPAD_BUTTON_PLUS;
		DashButton = wp->btns_h & WPAD_NUNCHUK_BUTTON_C;
		GrabButton = wp->btns_h & WPAD_NUNCHUK_BUTTON_Z;
		ViewButton = wp->btns_h & WPAD_BUTTON_1; // doesn't do anything?
		SpeedButton = wp->btns_h & WPAD_BUTTON_2;
	}
#endif
	// Gamecube controls are based on One Piece Grand Adventure
	{
		u32 gc = PAD_ButtonsHeld(pad);
		signed char gc_px = PAD_SubStickX(pad);
		if (gc_px > 70) J |= VBA_SPEED;
		JumpButton = JumpButton || gc & PAD_BUTTON_Y;
		AttackButton = AttackButton || gc & PAD_BUTTON_A;
		GrabButton = GrabButton || gc & PAD_BUTTON_B;
		AttackUpButton = AttackUpButton || gc & PAD_BUTTON_X;
		DashButton = DashButton || gc & PAD_TRIGGER_L;
		PauseButton = PauseButton || gc & PAD_BUTTON_START;
		CharacterButton = CharacterButton || gc & PAD_TRIGGER_R; // supposed to be block
	}
	
	if (JumpButton) J |= VBA_BUTTON_A;
	if (AttackButton) J |= VBA_BUTTON_B;
	if (AttackUpButton) J |= VBA_UP | VBA_BUTTON_B;
	if (CharacterButton) J |= VBA_BUTTON_L;
	if (DashButton) J |= LastDir;
	if (PauseButton) J |= VBA_BUTTON_START;
	if (GrabButton) J |= VBA_BUTTON_R;
	if (SpeedButton) J |= VBA_SPEED;
	if (ViewButton) J |= VBA_BUTTON_SELECT; // doesn't do anything?

	if (J & VBA_RIGHT) LastDir = VBA_RIGHT;
	else if (J & VBA_LEFT) LastDir = VBA_LEFT;
	
	return J;
}
/****************************************************************************
 * UpdatePads
 *
 * Scans pad and wpad
 ***************************************************************************/
void UpdatePads() {
    XenonInputUpdate();

    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);
    }
}
Example #9
0
/****************************************************************************
 * Controller Configuration
 *
 * Snes9x 1.51 uses a cmd system to work out which button has been pressed.
 * Here, I simply move the designated value to the gcpadmaps array, which
 * saves on updating the cmd sequences.
 ***************************************************************************/
u32
GetInput (u16 ctrlr_type)
{
	//u32 exp_type;
	u32 pressed;
	pressed=0;
	s8 gc_px = 0;

	while( PAD_ButtonsHeld(0)
#ifdef HW_RVL
	| WPAD_ButtonsHeld(0)
#endif
	) VIDEO_WaitVSync();	// button 'debounce'

	while (pressed == 0)
	{
		VIDEO_WaitVSync();
		// get input based on controller type
		if (ctrlr_type == CTRLR_GCPAD)
		{
			pressed = PAD_ButtonsHeld (0);
			gc_px = PAD_SubStickX (0);
		}
#ifdef HW_RVL
		else
		{
		//	if ( WPAD_Probe( 0, &exp_type) == 0)	// check wiimote and expansion status (first if wiimote is connected & no errors)
		//	{
				pressed = WPAD_ButtonsHeld (0);

		//		if (ctrlr_type != CTRLR_WIIMOTE && exp_type != ctrlr_type+1)	// if we need input from an expansion, and its not connected...
		//			pressed = 0;
		//	}
		}
#endif
		/*** check for exit sequence (c-stick left OR home button) ***/
		if ( (gc_px < -70) || (pressed & WPAD_BUTTON_HOME) || (pressed & WPAD_CLASSIC_BUTTON_HOME) )
			return 0;
	}	// end while
	while( pressed == (PAD_ButtonsHeld(0)
#ifdef HW_RVL
						| WPAD_ButtonsHeld(0)
#endif
						) ) VIDEO_WaitVSync();

	return pressed;
}	// end GetInput()
Example #10
0
u32 GetJoy(int pad)
{
    pad = 0;

    s8 gc_px = PAD_SubStickX (0);
    s8 gc_py = PAD_SubStickY (0);

    #ifdef HW_RVL
    s8 wm_sx = WPAD_Stick (0,1,0);
    s8 wm_sy = WPAD_Stick (0,1,1);
    u32 wm_pb = WPAD_ButtonsHeld (0); // wiimote / expansion button info
    #endif

    // Check for video zoom
	if (GCSettings.Zoom)
	{
		if (gc_py < -36 || gc_py > 36)
			zoom ((float) gc_py / -36);
		#ifdef HW_RVL
			if (wm_sy < -36 || wm_sy > 36)
				zoom ((float) wm_sy / -36);
		#endif
	}

    // request to go back to menu
    if ((gc_px < -70)
    #ifdef HW_RVL
    		 || (wm_pb & WPAD_BUTTON_HOME)
    		 || (wm_pb & WPAD_CLASSIC_BUTTON_HOME)
    		 || (wm_sx < -70)
    #endif
    )
	{
    	StopAudio();
    	ConfigRequested = 1;
		return 0;
	}
	else
	{
		return DecodeJoy(pad);
	}
}
Example #11
0
/****************************************************************************
 * Controller Configuration
 ***************************************************************************/
u32
GetInput (u16 ctrlr_type)
{
	//u32 exp_type;
	u32 pressed;
	pressed=0;
	s8 gc_px = 0;

	while( PAD_ButtonsHeld(0)
#ifdef HW_RVL
	| WPAD_ButtonsHeld(0)
#endif
	) VIDEO_WaitVSync();	// button 'debounce'

	while (pressed == 0)
	{
		VIDEO_WaitVSync();
		// get input based on controller type
		if (ctrlr_type == CTRLR_GCPAD)
		{
			pressed = PAD_ButtonsHeld (0);
			gc_px = PAD_SubStickX (0);
		}
#ifdef HW_RVL
		else
		{
			pressed = WPAD_ButtonsHeld (0);
		}
#endif
		/*** check for exit sequence (c-stick left OR home button) ***/
		if ( (gc_px < -70) || (pressed & WPAD_BUTTON_HOME) || (pressed & WPAD_CLASSIC_BUTTON_HOME) )
			return 0;
	}	// end while
	while( pressed == (PAD_ButtonsHeld(0)
#ifdef HW_RVL
						| WPAD_ButtonsHeld(0)
#endif
						) ) VIDEO_WaitVSync();

	return pressed;
}	// end GetInput()
Example #12
0
static unsigned int getButtons(int Control)
{
    unsigned int b = PAD_ButtonsHeld(Control);
    s8 stickX      = PAD_StickX(Control);
    s8 stickY      = PAD_StickY(Control);
    s8 substickX   = PAD_SubStickX(Control);
    s8 substickY   = PAD_SubStickY(Control);

    if(stickX    < -48) b |= ANALOG_L;
    if(stickX    >  48) b |= ANALOG_R;
    if(stickY    >  48) b |= ANALOG_U;
    if(stickY    < -48) b |= ANALOG_D;

    if(substickX < -48) b |= C_STICK_L;
    if(substickX >  48) b |= C_STICK_R;
    if(substickY >  48) b |= C_STICK_U;
    if(substickY < -48) b |= C_STICK_D;

    if(!(b & PAD_TRIGGER_Z)) b |= PAD_TRIGGER_Z_UP;

    return b;
}
Example #13
0
static void gx_input_poll(void *data)
{
   (void)data;

   pad_state[0] = 0;
   pad_state[1] = 0;
   pad_state[2] = 0;
   pad_state[3] = 0;

   PAD_ScanPads();

#ifdef HW_RVL
   WPAD_ReadPending(WPAD_CHAN_ALL, NULL);
#endif

   for (unsigned port = 0; port < MAX_PADS; port++)
   {
      uint32_t down = 0;
      uint64_t *state_cur = &pad_state[port];
      bool dpad_emulation = (g_settings.input.dpad_emulation[port] != ANALOG_DPAD_NONE);

#ifdef HW_RVL
      uint32_t type = 0;
      
      if (WPAD_Probe(port, &type) == WPAD_ERR_NONE)
      {
         WPADData *wpaddata = WPAD_Data(port);

         down = wpaddata->btns_h;

         *state_cur |= (down & WPAD_BUTTON_A) ? GX_WIIMOTE_A : 0;
         *state_cur |= (down & WPAD_BUTTON_B) ? GX_WIIMOTE_B : 0;
         *state_cur |= (down & WPAD_BUTTON_1) ? GX_WIIMOTE_1 : 0;
         *state_cur |= (down & WPAD_BUTTON_2) ? GX_WIIMOTE_2 : 0;
         *state_cur |= (down & WPAD_BUTTON_PLUS) ? GX_WIIMOTE_PLUS : 0;
         *state_cur |= (down & WPAD_BUTTON_MINUS) ? GX_WIIMOTE_MINUS : 0;
         *state_cur |= (down & WPAD_BUTTON_HOME) ? GX_WIIMOTE_HOME : 0;
         // rotated d-pad on Wiimote
         *state_cur |= (down & WPAD_BUTTON_UP) ? GX_WIIMOTE_LEFT : 0;
         *state_cur |= (down & WPAD_BUTTON_DOWN) ? GX_WIIMOTE_RIGHT : 0;
         *state_cur |= (down & WPAD_BUTTON_LEFT) ? GX_WIIMOTE_DOWN : 0;
         *state_cur |= (down & WPAD_BUTTON_RIGHT) ? GX_WIIMOTE_UP : 0;

         expansion_t *exp = &wpaddata->exp;

         if (type == WPAD_EXP_CLASSIC)
         {
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_A) ? GX_CLASSIC_A : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_B) ? GX_CLASSIC_B : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_X) ? GX_CLASSIC_X : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_Y) ? GX_CLASSIC_Y : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_UP) ? GX_CLASSIC_UP : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_DOWN) ? GX_CLASSIC_DOWN : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_LEFT) ? GX_CLASSIC_LEFT : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_RIGHT) ? GX_CLASSIC_RIGHT : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_PLUS) ? GX_CLASSIC_PLUS : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_MINUS) ? GX_CLASSIC_MINUS : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_HOME) ? GX_CLASSIC_HOME : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_FULL_L) ? GX_CLASSIC_L_TRIGGER : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_FULL_R) ? GX_CLASSIC_R_TRIGGER : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_ZL) ? GX_CLASSIC_ZL_TRIGGER : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_ZR) ? GX_CLASSIC_ZR_TRIGGER : 0;

            if (dpad_emulation)
            {
               float ljs_mag = exp->classic.ljs.mag;
               float ljs_ang = exp->classic.ljs.ang;

               float rjs_mag = exp->classic.rjs.mag;
               float rjs_ang = exp->classic.rjs.ang;

               if (ljs_mag > 1.0f)
                  ljs_mag = 1.0f;
               else if (ljs_mag < -1.0f)
                  ljs_mag = -1.0f;

               if (rjs_mag > 1.0f)
                  rjs_mag = 1.0f;
               else if (rjs_mag < -1.0f)
                  rjs_mag = -1.0f;

               double ljs_val_x = -ljs_mag * sin(M_PI * ljs_ang / 180.0);
               double ljs_val_y = -ljs_mag * cos(M_PI * ljs_ang / 180.0);

               double rjs_val_x = -rjs_mag * sin(M_PI * rjs_ang / 180.0);
               double rjs_val_y = -rjs_mag * cos(M_PI * rjs_ang / 180.0);

               s8 ls_x = (s8)(ljs_val_x * 127.0f);
               s8 ls_y = (s8)(ljs_val_y * 127.0f);

               s8 rs_x = (s8)(rjs_val_x * 127.0f);
               s8 rs_y = (s8)(rjs_val_y * 127.0f);

               *state_cur |= (ls_x < -WII_JOYSTICK_THRESHOLD) ? GX_CLASSIC_LSTICK_RIGHT : 0;
               *state_cur |= (ls_x > WII_JOYSTICK_THRESHOLD) ? GX_CLASSIC_LSTICK_LEFT : 0;
               *state_cur |= (ls_y < -WII_JOYSTICK_THRESHOLD) ? GX_CLASSIC_LSTICK_UP : 0;
               *state_cur |= (ls_y > WII_JOYSTICK_THRESHOLD) ? GX_CLASSIC_LSTICK_DOWN : 0;

               *state_cur |= (rs_x < -WII_JOYSTICK_THRESHOLD) ? GX_CLASSIC_RSTICK_RIGHT : 0;
               *state_cur |= (rs_x > WII_JOYSTICK_THRESHOLD) ? GX_CLASSIC_RSTICK_LEFT: 0;
               *state_cur |= (rs_y < -WII_JOYSTICK_THRESHOLD) ? GX_CLASSIC_RSTICK_UP : 0;
               *state_cur |= (rs_y > WII_JOYSTICK_THRESHOLD) ? GX_CLASSIC_RSTICK_DOWN : 0;
            }
         }
         else if (type == WPAD_EXP_NUNCHUK)
         {
            // wiimote is held upright with nunchuk, do not change d-pad orientation
            *state_cur |= (down & WPAD_BUTTON_UP) ? GX_WIIMOTE_UP : 0;
            *state_cur |= (down & WPAD_BUTTON_DOWN) ? GX_WIIMOTE_DOWN : 0;
            *state_cur |= (down & WPAD_BUTTON_LEFT) ? GX_WIIMOTE_LEFT : 0;
            *state_cur |= (down & WPAD_BUTTON_RIGHT) ? GX_WIIMOTE_RIGHT : 0;

            *state_cur |= (down & WPAD_NUNCHUK_BUTTON_Z) ? GX_NUNCHUK_Z : 0;
            *state_cur |= (down & WPAD_NUNCHUK_BUTTON_C) ? GX_NUNCHUK_C : 0;

            if (dpad_emulation)
            {
               float js_mag = exp->nunchuk.js.mag;
               float js_ang = exp->nunchuk.js.ang;

               if (js_mag > 1.0f)
                  js_mag = 1.0f;
               else if (js_mag < -1.0f)
                  js_mag = -1.0f;

               double js_val_x = -js_mag * sin(M_PI * js_ang / 180.0);
               double js_val_y = -js_mag * cos(M_PI * js_ang / 180.0);

               s8 x = (s8)(js_val_x * 127.0f);
               s8 y = (s8)(js_val_y * 127.0f);

               *state_cur |= (x < -WII_JOYSTICK_THRESHOLD) ? GX_NUNCHUK_RIGHT : 0;
               *state_cur |= (x > WII_JOYSTICK_THRESHOLD) ? GX_NUNCHUK_LEFT : 0;
               *state_cur |= (y < -WII_JOYSTICK_THRESHOLD) ? GX_NUNCHUK_UP : 0;
               *state_cur |= (y > WII_JOYSTICK_THRESHOLD) ? GX_NUNCHUK_DOWN : 0;
            }
         }
      }

#endif

      if (SI_GetType(port) & SI_TYPE_GC)
      {
         down = PAD_ButtonsHeld(port);

         *state_cur |= (down & PAD_BUTTON_A) ? GX_GC_A : 0;
         *state_cur |= (down & PAD_BUTTON_B) ? GX_GC_B : 0;
         *state_cur |= (down & PAD_BUTTON_X) ? GX_GC_X : 0;
         *state_cur |= (down & PAD_BUTTON_Y) ? GX_GC_Y : 0;
         *state_cur |= (down & PAD_BUTTON_UP) ? GX_GC_UP : 0;
         *state_cur |= (down & PAD_BUTTON_DOWN) ? GX_GC_DOWN : 0;
         *state_cur |= (down & PAD_BUTTON_LEFT) ? GX_GC_LEFT : 0;
         *state_cur |= (down & PAD_BUTTON_RIGHT) ? GX_GC_RIGHT : 0;
         *state_cur |= (down & PAD_BUTTON_START) ? GX_GC_START : 0;
         *state_cur |= (down & PAD_TRIGGER_Z) ? GX_GC_Z_TRIGGER : 0;
         *state_cur |= ((down & PAD_TRIGGER_L) || PAD_TriggerL(port) > 127) ? GX_GC_L_TRIGGER : 0;
         *state_cur |= ((down & PAD_TRIGGER_R) || PAD_TriggerR(port) > 127) ? GX_GC_R_TRIGGER : 0;

         if (dpad_emulation)
         {
            s8 x = PAD_StickX(port);
            s8 y = PAD_StickY(port);

            *state_cur |= (x < -GC_JOYSTICK_THRESHOLD) ? GX_GC_LSTICK_LEFT : 0;
            *state_cur |= (x > GC_JOYSTICK_THRESHOLD) ? GX_GC_LSTICK_RIGHT : 0;
            *state_cur |= (y < -GC_JOYSTICK_THRESHOLD) ? GX_GC_LSTICK_DOWN : 0;
            *state_cur |= (y > GC_JOYSTICK_THRESHOLD) ? GX_GC_LSTICK_UP : 0;

            x = PAD_SubStickX(port);
            y = PAD_SubStickY(port);

            *state_cur |= (x < -GC_JOYSTICK_THRESHOLD) ? GX_GC_RSTICK_LEFT : 0;
            *state_cur |= (x > GC_JOYSTICK_THRESHOLD) ? GX_GC_RSTICK_RIGHT : 0;
            *state_cur |= (y < -GC_JOYSTICK_THRESHOLD) ? GX_GC_RSTICK_DOWN : 0;
            *state_cur |= (y > GC_JOYSTICK_THRESHOLD) ? GX_GC_RSTICK_UP : 0;
         }

         if ((*state_cur & (GX_GC_LSTICK_UP | GX_GC_RSTICK_UP | GX_GC_L_TRIGGER | GX_GC_R_TRIGGER)) == (GX_GC_LSTICK_UP | GX_GC_RSTICK_UP | GX_GC_L_TRIGGER | GX_GC_R_TRIGGER))
            *state_cur |= GX_WIIMOTE_HOME;
      }
   }

   uint64_t *state_p1 = &pad_state[0];
   uint64_t *lifecycle_state = &g_extern.lifecycle_state;
   bool dpad_emulation = (g_settings.input.dpad_emulation[0] != ANALOG_DPAD_NONE);

   *lifecycle_state &= ~(
         (1ULL << RARCH_FAST_FORWARD_HOLD_KEY) | 
         (1ULL << RARCH_LOAD_STATE_KEY) | 
         (1ULL << RARCH_SAVE_STATE_KEY) | 
         (1ULL << RARCH_STATE_SLOT_PLUS) | 
         (1ULL << RARCH_STATE_SLOT_MINUS) | 
         (1ULL << RARCH_REWIND) |
         (1ULL << RARCH_QUIT_KEY) |
         (1ULL << RARCH_MENU_TOGGLE));

   if (dpad_emulation)
   {
      if (
#ifdef HW_RVL
            ((*state_p1 & GX_CLASSIC_RSTICK_DOWN) && !(*state_p1 & GX_CLASSIC_ZR_TRIGGER)) ||
#endif
            ((*state_p1 & GX_GC_RSTICK_DOWN) && !(*state_p1 & GX_GC_Z_TRIGGER))
         )
         *lifecycle_state |= (1ULL << RARCH_FAST_FORWARD_HOLD_KEY);
      if (
#ifdef HW_RVL
            ((*state_p1 & GX_CLASSIC_RSTICK_UP) && (*state_p1 & GX_CLASSIC_ZR_TRIGGER)) ||
#endif
            ((*state_p1 & GX_GC_RSTICK_UP) && (*state_p1 & GX_GC_Z_TRIGGER))
         )
         *lifecycle_state |= (1ULL << RARCH_LOAD_STATE_KEY);
      if (
#ifdef HW_RVL
            ((*state_p1 & GX_CLASSIC_RSTICK_DOWN) && (*state_p1 & GX_CLASSIC_ZR_TRIGGER)) ||
#endif
            ((*state_p1 & GX_GC_RSTICK_DOWN) && (*state_p1 & GX_GC_Z_TRIGGER))
         )
         *lifecycle_state |= (1ULL << RARCH_SAVE_STATE_KEY);
      if (
#ifdef HW_RVL
            ((*state_p1 & GX_CLASSIC_RSTICK_RIGHT) && (*state_p1 & GX_CLASSIC_ZR_TRIGGER)) ||
#endif
            ((*state_p1 & GX_GC_RSTICK_RIGHT) && (*state_p1 & GX_GC_Z_TRIGGER))
         )
         *lifecycle_state |= (1ULL << RARCH_STATE_SLOT_PLUS);
      if (
#ifdef HW_RVL
            ((*state_p1 & GX_CLASSIC_RSTICK_LEFT) && (*state_p1 & GX_CLASSIC_ZR_TRIGGER)) ||
#endif
            ((*state_p1 & GX_GC_RSTICK_LEFT) && (*state_p1 & GX_GC_Z_TRIGGER))
         )
         *lifecycle_state |= (1ULL << RARCH_STATE_SLOT_MINUS);
      if (
#ifdef HW_RVL
            ((*state_p1 & GX_CLASSIC_RSTICK_UP) && !(*state_p1 & GX_CLASSIC_ZR_TRIGGER)) ||
#endif
            ((*state_p1 & GX_GC_RSTICK_UP) && !(*state_p1 & GX_GC_Z_TRIGGER))
         )
         *lifecycle_state |= (1ULL << RARCH_REWIND);
   }

   if (g_menu)
   {
      *state_p1 |= GX_WIIMOTE_HOME;
      g_menu = false;
   }

   if (*state_p1 & (GX_WIIMOTE_HOME
#ifdef HW_RVL
            | GX_CLASSIC_HOME
#endif
            ))
      *lifecycle_state |= (1ULL << RARCH_MENU_TOGGLE);
}
Example #14
0
/*
 * Updates the joystick state
 *
 * joyIndex         The joystick index
 * keyboard_data    The keyboard (controls) state
 */
static void wii_atari_update_joystick( int joyIndex, unsigned char keyboard_data[19] )
{
  // Check the state of the controllers
  u32 down = WPAD_ButtonsDown( joyIndex );
  u32 held = WPAD_ButtonsHeld( joyIndex );
  u32 gcDown = PAD_ButtonsDown( joyIndex );
  u32 gcHeld = PAD_ButtonsHeld( joyIndex );

  // Check to see if the lightgun is enabled (lightgun only works for
  // joystick index 0).
  bool lightgun = ( lightgun_enabled && ( joyIndex == 0 ) );

  if( lightgun )
  {
    // Determine the Y offset of the lightgun location
    int yoffset = ( cartridge_region == REGION_NTSC ? 
      ( NTSC_ATARI_BLIT_TOP_Y ) : ( PAL_ATARI_BLIT_TOP_Y - 28 ) );

    // The number of scanlines for the current cartridge
    int scanlines = ( cartridge_region == REGION_NTSC ? 
                        NTSC_ATARI_HEIGHT : PAL_ATARI_HEIGHT );
    wii_dbg_scanlines = scanlines;

    // We track the first time the lightgun is fired due to the fact that
    // when a catridge is launched (via the Wii7800 menu) the state of the
    // fire button (down) is used to determine whether the console has a
    // joystick or lightgun plugged in.
    if( lightgun_first_fire )
    {
      if( !( held & ( WPAD_BUTTON_B | WPAD_BUTTON_A ) ) )
      {
        // The button is not down, enable lightgun firing.
        lightgun_first_fire = false;
      }            
      keyboard_data[3] = true;
    }
    else
    {
      keyboard_data[3] = !( held & ( WPAD_BUTTON_B | WPAD_BUTTON_A ) );
    }

    //
    // TODO: These values should be cached
    //
    float yratio = ( (float)scanlines / (float)WII_HEIGHT );
    float xratio = ( (float)LG_CYCLES_PER_SCANLINE / (float)WII_WIDTH );
    lightgun_scanline = ( ( (float)wii_ir_y * yratio ) + 
      ( maria_visibleArea.top - maria_displayArea.top + 1 ) + yoffset );
    lightgun_cycle = ( HBLANK_CYCLES + LG_CYCLES_INDENT + 
      ( (float)wii_ir_x * xratio ) );
    if( lightgun_cycle > CYCLES_PER_SCANLINE )
    {
      lightgun_scanline++;
      lightgun_cycle -= CYCLES_PER_SCANLINE; 
    }
  }
  else
  {
    expansion_t exp;
    WPAD_Expansion( joyIndex, &exp );
    bool isClassic = ( exp.type == WPAD_EXP_CLASSIC );

    float expX = wii_exp_analog_val( &exp, TRUE, FALSE );
    float expY = wii_exp_analog_val( &exp, FALSE, FALSE );
    s8 gcX = PAD_StickX( joyIndex );
    s8 gcY = PAD_StickY( joyIndex );

    float expRjsX = 0, expRjsY = 0;
    s8 gcRjsX = 0, gcRjsY = 0;

    // Dual analog support
    if( cartridge_dualanalog && joyIndex == 1  )
    {
      expansion_t exp0;
      WPAD_Expansion( 0, &exp0 );
      if( exp0.type == WPAD_EXP_CLASSIC  )
      {
        expRjsX = wii_exp_analog_val( &exp0, TRUE, TRUE );
        expRjsY = wii_exp_analog_val( &exp0, FALSE, TRUE );
      }

      gcRjsX = PAD_SubStickX( 0 );
      gcRjsY = PAD_SubStickY( 0 );
    }

    int offset = ( joyIndex == 0 ? 0 : 6 );

    // | 00 06     | Joystick 1 2 | Right
    keyboard_data[0 + offset] = 
      ( held & WII_BUTTON_ATARI_RIGHT || gcHeld & GC_BUTTON_ATARI_RIGHT ||
      wii_analog_right( expX, gcX ) || wii_analog_right( expRjsX, gcRjsX ) );
    // | 01 07     | Joystick 1 2 | Left
    keyboard_data[1 + offset] = 
      ( held & ( WII_BUTTON_ATARI_LEFT | ( isClassic ? WII_CLASSIC_ATARI_LEFT : 0 ) ) || 
      gcHeld & GC_BUTTON_ATARI_LEFT || wii_analog_left( expX, gcX ) ||
      wii_analog_left( expRjsX, gcRjsX ) );
    // | 02 08     | Joystick 1 2 | Down
    keyboard_data[2 + offset] = 
      ( held & WII_BUTTON_ATARI_DOWN || gcHeld & GC_BUTTON_ATARI_DOWN || 
      wii_analog_down( expY, gcY ) || wii_analog_down( expRjsY, gcRjsY ) );
    // | 03 09     | Joystick 1 2 | Up
    keyboard_data[3 + offset] = 
      ( held & ( WII_BUTTON_ATARI_UP | ( isClassic ? WII_CLASSIC_ATARI_UP : 0 ) ) || 
      gcHeld & GC_BUTTON_ATARI_UP || wii_analog_up( expY, gcY ) ||
      wii_analog_up( expRjsY, gcRjsY ) );
    // | 04 10     | Joystick 1 2 | Button 1
    keyboard_data[wii_swap_buttons ? 4 + offset : 5 + offset] = 
      ( held & ( WII_BUTTON_ATARI_FIRE | 
      ( isClassic ? WII_CLASSIC_ATARI_FIRE : WII_NUNCHECK_ATARI_FIRE ) ) || 
      gcHeld & GC_BUTTON_ATARI_FIRE );
    // | 05 11     | Joystick 1 2 | Button 2
    keyboard_data[wii_swap_buttons ? 5 + offset : 4 + offset] = 
      ( held & ( WII_BUTTON_ATARI_FIRE_2 | 
      ( isClassic ? WII_CLASSIC_ATARI_FIRE_2 : WII_NUNCHECK_ATARI_FIRE_2 ) ) || 
      gcHeld & GC_BUTTON_ATARI_FIRE_2 );
  }

  if( joyIndex == 0 )
  {
    // | 12       | Console      | Reset
    keyboard_data[12] = ( held & WII_BUTTON_ATARI_RESET || gcHeld & GC_BUTTON_ATARI_RESET );
    // | 13       | Console      | Select
    keyboard_data[13] = ( held & WII_BUTTON_ATARI_SELECT || gcHeld & GC_BUTTON_ATARI_SELECT );
    // | 14       | Console      | Pause               
    keyboard_data[14] = ( held & WII_BUTTON_ATARI_PAUSE || gcHeld & GC_BUTTON_ATARI_PAUSE );

    if( wii_diff_switch_enabled )
    {
      // | 15       | Console      | Left Difficulty
      if( ( diff_wait_count == 0 ) && 
        ( ( gcDown & GC_BUTTON_ATARI_DIFFICULTY_LEFT ) ||
        ( ( !lightgun && ( down & WII_BUTTON_ATARI_DIFFICULTY_LEFT ) ) ||
        ( lightgun && ( down & WII_BUTTON_ATARI_DIFFICULTY_LEFT_LG ) ) ) ) )
      {
        if( !left_difficulty_down )
        {
          keyboard_data[15] = !keyboard_data[15];
          left_difficulty_down = true;   
          diff_display_count = prosystem_frequency * DIFF_DISPLAY_LENGTH;
        }
      }
      else
      {
        left_difficulty_down = false;
      }
      // | 16       | Console      | Right Difficulty        
      if( ( diff_wait_count == 0 ) && 
        ( ( gcDown & GC_BUTTON_ATARI_DIFFICULTY_RIGHT ) ||
        ( ( !lightgun && ( down & WII_BUTTON_ATARI_DIFFICULTY_RIGHT ) ) ||
        ( lightgun && ( down & WII_BUTTON_ATARI_DIFFICULTY_RIGHT_LG ) ) ) ) )                  
      {
        if( !right_difficulty_down )
        {
          keyboard_data[16] = !keyboard_data[16];
          right_difficulty_down = true;    
          diff_display_count = prosystem_frequency * DIFF_DISPLAY_LENGTH;
        }
      }
      else
      {
        right_difficulty_down = false;
      }
    }

    if( ( down & WII_BUTTON_HOME ) || ( gcDown & GC_BUTTON_HOME ) || wii_hw_button )
    {
      wii_atari_pause( true );
    }
  }    
}
bool CMenu::rStick_Left(void)
{
	for(int chan = WPAD_MAX_WIIMOTES-1; chan >= 0; chan--)
	{
		if((RIGHT_STICK_ANG_LEFT && right_stick_mag[chan] > 0.15 && right_stick_skip[chan] == 0) || PAD_SubStickX(chan) < -20 || WUPC_rStickX(chan) < -160)
			return true;
	}
	return false;
}
Example #16
0
/* Function to update the state of a joystick - called as a device poll.
 * This function shouldn't update the joystick structure directly,
 * but instead should call SDL_PrivateJoystick*() to deliver events
 * and update joystick device state.
 */
void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
{
	if(!joystick || !joystick->hwdata)
		return;

	u16 buttons, prev_buttons, changed;
	int i, axis;
	joystick_hwdata *prev_state;

	PAD_ScanPads();

	buttons = PAD_ButtonsHeld(joystick->index);
	prev_state = (joystick_hwdata *)joystick->hwdata;
	prev_buttons = prev_state->gamecube.prev_buttons;
	changed = buttons ^ prev_buttons;

	/* D-Pad */
	if(changed & (PAD_BUTTON_LEFT | PAD_BUTTON_RIGHT |
					PAD_BUTTON_DOWN | PAD_BUTTON_UP))
	{
		int hat = SDL_HAT_CENTERED;
		if(buttons & PAD_BUTTON_UP) hat |= SDL_HAT_UP;
		if(buttons & PAD_BUTTON_DOWN) hat |= SDL_HAT_DOWN;
		if(buttons & PAD_BUTTON_LEFT) hat |= SDL_HAT_LEFT;
		if(buttons & PAD_BUTTON_RIGHT) hat |= SDL_HAT_RIGHT;
		SDL_PrivateJoystickHat(joystick, 0, hat);
	}

	/* All Buttons and trigger presses */
	for(i = 0; i < MAX_GC_BUTTONS; i++)
	{
		if (changed & sdl_buttons_gc[i])
			SDL_PrivateJoystickButton(joystick, i,
				(buttons & sdl_buttons_gc[i]) ? SDL_PRESSED : SDL_RELEASED);
	}

	/* Analog stick */
	prev_state->gamecube.prev_buttons = buttons;
	axis = PAD_StickX(joystick->index);
	if(prev_state->gamecube.stickX != axis)
	{
		SDL_PrivateJoystickAxis(joystick, 0, axis << 8);
		prev_state->gamecube.stickX = axis;
	}

	axis = PAD_StickY(joystick->index);
	if(prev_state->gamecube.stickY != axis)
	{
		SDL_PrivateJoystickAxis(joystick, 1, (-axis) << 8);
		prev_state->gamecube.stickY = axis;
	}

	/* C-Stick */
	axis = PAD_SubStickX(joystick->index);
	if(prev_state->gamecube.substickX != axis)
	{
		SDL_PrivateJoystickAxis(joystick, 2, axis << 8);
		prev_state->gamecube.substickX = axis;
	}

	axis = PAD_SubStickY(joystick->index);
	if(prev_state->gamecube.substickY != axis)
	{
		SDL_PrivateJoystickAxis(joystick, 3, (-axis) << 8); //FABIO
		prev_state->gamecube.substickY = axis;
	}

	/* L-Trigger */
	axis = PAD_TriggerL(joystick->index);
	if(prev_state->gamecube.triggerL != axis)
	{
		SDL_PrivateJoystickAxis(joystick, 4, axis << 7); //FABIO
		prev_state->gamecube.triggerL = axis;
	}

	/* R-Trigger */
	axis = PAD_TriggerR(joystick->index);
	if(prev_state->gamecube.triggerR != axis)
	{
		SDL_PrivateJoystickAxis(joystick, 5, axis << 7); //FABIO
		prev_state->gamecube.triggerR = axis;
	}

	/* done */
	return;
}
Example #17
0
static void gx_joypad_poll(void)
{
   unsigned i, j, port;
   uint8_t gcpad    = 0;
   global_t *global = global_get_ptr();

   pad_state[0] = 0;
   pad_state[1] = 0;
   pad_state[2] = 0;
   pad_state[3] = 0;

   gcpad = PAD_ScanPads();

#ifdef HW_RVL
   WPAD_ReadPending(WPAD_CHAN_ALL, NULL);
#endif

   for (port = 0; port < MAX_PADS; port++)
   {
      uint32_t down = 0, ptype = WPAD_EXP_NOCONTROLLER;
      uint64_t *state_cur = &pad_state[port];

#ifdef HW_RVL
      if (WPADProbe(port, &ptype) == WPAD_ERR_NONE)
      {
         WPADData *wpaddata = (WPADData*)WPAD_Data(port);
         expansion_t *exp = NULL;

         down = wpaddata->btns_h;

         exp = (expansion_t*)&wpaddata->exp;

         *state_cur |= (down & WPAD_BUTTON_A) ? (1ULL << GX_WIIMOTE_A) : 0;
         *state_cur |= (down & WPAD_BUTTON_B) ? (1ULL << GX_WIIMOTE_B) : 0;
         *state_cur |= (down & WPAD_BUTTON_1) ? (1ULL << GX_WIIMOTE_1) : 0;
         *state_cur |= (down & WPAD_BUTTON_2) ? (1ULL << GX_WIIMOTE_2) : 0;
         *state_cur |= (down & WPAD_BUTTON_PLUS) ? (1ULL << GX_WIIMOTE_PLUS) : 0;
         *state_cur |= (down & WPAD_BUTTON_MINUS) ? (1ULL << GX_WIIMOTE_MINUS) : 0;
         *state_cur |= (down & WPAD_BUTTON_HOME) ? (1ULL << GX_WIIMOTE_HOME) : 0;

         if (ptype != WPAD_EXP_NUNCHUK)
         {
            /* Rotated d-pad on Wiimote. */
            *state_cur |= (down & WPAD_BUTTON_UP) ? (1ULL << GX_WIIMOTE_LEFT) : 0;
            *state_cur |= (down & WPAD_BUTTON_DOWN) ? (1ULL << GX_WIIMOTE_RIGHT) : 0;
            *state_cur |= (down & WPAD_BUTTON_LEFT) ? (1ULL << GX_WIIMOTE_DOWN) : 0;
            *state_cur |= (down & WPAD_BUTTON_RIGHT) ? (1ULL << GX_WIIMOTE_UP) : 0;
         }


         if (ptype == WPAD_EXP_CLASSIC)
         {
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_A) ? (1ULL << GX_CLASSIC_A) : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_B) ? (1ULL << GX_CLASSIC_B) : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_X) ? (1ULL << GX_CLASSIC_X) : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_Y) ? (1ULL << GX_CLASSIC_Y) : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_UP) ? (1ULL << GX_CLASSIC_UP) : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_DOWN) ? (1ULL << GX_CLASSIC_DOWN) : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_LEFT) ? (1ULL << GX_CLASSIC_LEFT) : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_RIGHT) ? (1ULL << GX_CLASSIC_RIGHT) : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_PLUS) ? (1ULL << GX_CLASSIC_PLUS) : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_MINUS) ? (1ULL << GX_CLASSIC_MINUS) : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_HOME) ? (1ULL << GX_CLASSIC_HOME) : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_FULL_L) ? (1ULL << GX_CLASSIC_L_TRIGGER) : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_FULL_R) ? (1ULL << GX_CLASSIC_R_TRIGGER) : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_ZL) ? (1ULL << GX_CLASSIC_ZL_TRIGGER) : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_ZR) ? (1ULL << GX_CLASSIC_ZR_TRIGGER) : 0;

            analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_X]  = WPAD_StickX(wpaddata, port, 0);
            analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_Y]  = WPAD_StickY(wpaddata, port, 0);
            analog_state[port][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_X] = WPAD_StickX(wpaddata, port, 1);
            analog_state[port][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_Y] = WPAD_StickY(wpaddata, port, 1);
         }
         else if (ptype == WPAD_EXP_NUNCHUK)
         {
            /* Wiimote is held upright with nunchuk,
             * do not change d-pad orientation. */
            *state_cur |= (down & WPAD_BUTTON_UP) ? (1ULL << GX_WIIMOTE_UP) : 0;
            *state_cur |= (down & WPAD_BUTTON_DOWN) ? (1ULL << GX_WIIMOTE_DOWN) : 0;
            *state_cur |= (down & WPAD_BUTTON_LEFT) ? (1ULL << GX_WIIMOTE_LEFT) : 0;
            *state_cur |= (down & WPAD_BUTTON_RIGHT) ? (1ULL << GX_WIIMOTE_RIGHT) : 0;

            *state_cur |= (down & WPAD_NUNCHUK_BUTTON_Z) ? (1ULL << GX_NUNCHUK_Z) : 0;
            *state_cur |= (down & WPAD_NUNCHUK_BUTTON_C) ? (1ULL << GX_NUNCHUK_C) : 0;

            float js_mag = exp->nunchuk.js.mag;
            float js_ang = exp->nunchuk.js.ang;

            if (js_mag > 1.0f)
               js_mag = 1.0f;
            else if (js_mag < -1.0f)
               js_mag = -1.0f;

            double js_val_x = js_mag * sin(M_PI * js_ang / 180.0);
            double js_val_y = -js_mag * cos(M_PI * js_ang / 180.0);

            int16_t x = (int16_t)(js_val_x * 32767.0f);
            int16_t y = (int16_t)(js_val_y * 32767.0f);

            analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_X] = x;
            analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_Y] = y;

         }
      }
      else
#endif
      {
         if (gcpad & (1 << port))
         {
            int16_t ls_x, ls_y, rs_x, rs_y;
            uint64_t menu_combo = 0;

            down = PAD_ButtonsHeld(port);

            *state_cur |= (down & PAD_BUTTON_A) ? (1ULL << GX_GC_A) : 0;
            *state_cur |= (down & PAD_BUTTON_B) ? (1ULL << GX_GC_B) : 0;
            *state_cur |= (down & PAD_BUTTON_X) ? (1ULL << GX_GC_X) : 0;
            *state_cur |= (down & PAD_BUTTON_Y) ? (1ULL << GX_GC_Y) : 0;
            *state_cur |= (down & PAD_BUTTON_UP) ? (1ULL << GX_GC_UP) : 0;
            *state_cur |= (down & PAD_BUTTON_DOWN) ? (1ULL << GX_GC_DOWN) : 0;
            *state_cur |= (down & PAD_BUTTON_LEFT) ? (1ULL << GX_GC_LEFT) : 0;
            *state_cur |= (down & PAD_BUTTON_RIGHT) ? (1ULL << GX_GC_RIGHT) : 0;
            *state_cur |= (down & PAD_BUTTON_START) ? (1ULL << GX_GC_START) : 0;
            *state_cur |= (down & PAD_TRIGGER_Z) ? (1ULL << GX_GC_Z_TRIGGER) : 0;
            *state_cur |= ((down & PAD_TRIGGER_L) || PAD_TriggerL(port) > 127) ? (1ULL << GX_GC_L_TRIGGER) : 0;
            *state_cur |= ((down & PAD_TRIGGER_R) || PAD_TriggerR(port) > 127) ? (1ULL << GX_GC_R_TRIGGER) : 0;

            ls_x = (int16_t)PAD_StickX(port) * 256;
            ls_y = (int16_t)PAD_StickY(port) * -256;
            rs_x = (int16_t)PAD_SubStickX(port) * 256;
            rs_y = (int16_t)PAD_SubStickY(port) * -256;

            analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_X] = ls_x;
            analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_Y] = ls_y;
            analog_state[port][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_X] = rs_x;
            analog_state[port][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_Y] = rs_y;

            menu_combo = (1ULL << GX_GC_START) | (1ULL << GX_GC_Z_TRIGGER) |
               (1ULL << GX_GC_L_TRIGGER) | (1ULL << GX_GC_R_TRIGGER);

            if ((*state_cur & menu_combo) == menu_combo)
               *state_cur |= (1ULL << GX_WIIMOTE_HOME);

            ptype = WPAD_EXP_GAMECUBE;
         }
#ifdef HAVE_LIBSICKSAXIS
         else
         {
            USB_DeviceChangeNotifyAsync(USB_CLASS_HID, change_cb, (void*)&lol);

            if (ss_is_connected(&dev[port]))
            {
               ptype = WPAD_EXP_SICKSAXIS;
               *state_cur |= (dev[port].pad.buttons.PS)       ? (1ULL << RARCH_MENU_TOGGLE) : 0;
               *state_cur |= (dev[port].pad.buttons.cross)    ? (1ULL << RETRO_DEVICE_ID_JOYPAD_B) : 0;
               *state_cur |= (dev[port].pad.buttons.square)   ? (1ULL << RETRO_DEVICE_ID_JOYPAD_Y) : 0;
               *state_cur |= (dev[port].pad.buttons.select)   ? (1ULL << RETRO_DEVICE_ID_JOYPAD_SELECT) : 0;
               *state_cur |= (dev[port].pad.buttons.start)    ? (1ULL << RETRO_DEVICE_ID_JOYPAD_START) : 0;
               *state_cur |= (dev[port].pad.buttons.up)       ? (1ULL << RETRO_DEVICE_ID_JOYPAD_UP) : 0;
               *state_cur |= (dev[port].pad.buttons.down)     ? (1ULL << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0;
               *state_cur |= (dev[port].pad.buttons.left)     ? (1ULL << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0;
               *state_cur |= (dev[port].pad.buttons.right)    ? (1ULL << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0;
               *state_cur |= (dev[port].pad.buttons.circle)   ? (1ULL << RETRO_DEVICE_ID_JOYPAD_A) : 0;
               *state_cur |= (dev[port].pad.buttons.triangle) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_X) : 0;
               *state_cur |= (dev[port].pad.buttons.L1)       ? (1ULL << RETRO_DEVICE_ID_JOYPAD_L) : 0;
               *state_cur |= (dev[port].pad.buttons.R1)       ? (1ULL << RETRO_DEVICE_ID_JOYPAD_R) : 0;
               *state_cur |= (dev[port].pad.buttons.L2)       ? (1ULL << RETRO_DEVICE_ID_JOYPAD_L2) : 0;
               *state_cur |= (dev[port].pad.buttons.R2)       ? (1ULL << RETRO_DEVICE_ID_JOYPAD_R2) : 0;
               *state_cur |= (dev[port].pad.buttons.L3)       ? (1ULL << RETRO_DEVICE_ID_JOYPAD_L3) : 0;
               *state_cur |= (dev[port].pad.buttons.R3)       ? (1ULL << RETRO_DEVICE_ID_JOYPAD_R3) : 0;
            }
            else
            {
               if (ss_open(&dev[port]) > 0)
               {
                  ptype = WPAD_EXP_SICKSAXIS;
                  ss_start_reading(&dev[port]);
                  ss_set_removal_cb(&dev[port], removal_cb, (void*)1);
               }
            }
         }
#endif
      }

      if (ptype != pad_type[port])
         handle_hotplug(port, ptype);

      for (i = 0; i < 2; i++)
         for (j = 0; j < 2; j++)
            if (analog_state[port][i][j] == -0x8000)
               analog_state[port][i][j] = -0x7fff;
   }

   uint64_t *state_p1        = &pad_state[0];
   uint64_t *lifecycle_state = &global->lifecycle_state;

   *lifecycle_state &= ~((1ULL << RARCH_MENU_TOGGLE));

   if (g_menu)
   {
      *state_p1 |= (1ULL << GX_WIIMOTE_HOME);
      g_menu = false;
   }

   if (*state_p1 & ((1ULL << GX_WIIMOTE_HOME)
#ifdef HW_RVL
            | (1ULL << GX_CLASSIC_HOME)
#endif
            ))
      *lifecycle_state |= (1ULL << RARCH_MENU_TOGGLE);
}
Example #18
0
static void gx_input_poll(void *data)
{
   (void)data;

   pad_state[0] = 0;
   pad_state[1] = 0;
   pad_state[2] = 0;
   pad_state[3] = 0;
   analog_state[0][0][0] = analog_state[0][0][1] = analog_state[0][1][0] = analog_state[0][1][1] = 0;
   analog_state[1][0][0] = analog_state[1][0][1] = analog_state[1][1][0] = analog_state[1][1][1] = 0;
   analog_state[2][0][0] = analog_state[2][0][1] = analog_state[2][1][0] = analog_state[2][1][1] = 0;
   analog_state[3][0][0] = analog_state[3][0][1] = analog_state[3][1][0] = analog_state[3][1][1] = 0;

   PAD_ScanPads();

#ifdef HW_RVL
   WPAD_ReadPending(WPAD_CHAN_ALL, NULL);
#endif

   for (unsigned port = 0; port < MAX_PADS; port++)
   {
      uint32_t down = 0;
      uint64_t *state_cur = &pad_state[port];

#ifdef HW_RVL
      if (pad_detect_pending[port])
      {
         u32 *ptype = &pad_type[port];
         pad_connect[port] = WPAD_Probe(port, ptype);
         pad_detect_pending[port] = 0;
      }

      uint32_t connected = pad_connect[port];
      uint32_t type = pad_type[port];
      
      if (connected == WPAD_ERR_NONE)
      {
         WPADData *wpaddata = WPAD_Data(port);

         down = wpaddata->btns_h;

         *state_cur |= (down & WPAD_BUTTON_A) ? GX_WIIMOTE_A : 0;
         *state_cur |= (down & WPAD_BUTTON_B) ? GX_WIIMOTE_B : 0;
         *state_cur |= (down & WPAD_BUTTON_1) ? GX_WIIMOTE_1 : 0;
         *state_cur |= (down & WPAD_BUTTON_2) ? GX_WIIMOTE_2 : 0;
         *state_cur |= (down & WPAD_BUTTON_PLUS) ? GX_WIIMOTE_PLUS : 0;
         *state_cur |= (down & WPAD_BUTTON_MINUS) ? GX_WIIMOTE_MINUS : 0;
         *state_cur |= (down & WPAD_BUTTON_HOME) ? GX_WIIMOTE_HOME : 0;
         // rotated d-pad on Wiimote
         *state_cur |= (down & WPAD_BUTTON_UP) ? GX_WIIMOTE_LEFT : 0;
         *state_cur |= (down & WPAD_BUTTON_DOWN) ? GX_WIIMOTE_RIGHT : 0;
         *state_cur |= (down & WPAD_BUTTON_LEFT) ? GX_WIIMOTE_DOWN : 0;
         *state_cur |= (down & WPAD_BUTTON_RIGHT) ? GX_WIIMOTE_UP : 0;

         expansion_t *exp = &wpaddata->exp;

         if (type == WPAD_EXP_CLASSIC)
         {
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_A) ? GX_CLASSIC_A : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_B) ? GX_CLASSIC_B : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_X) ? GX_CLASSIC_X : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_Y) ? GX_CLASSIC_Y : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_UP) ? GX_CLASSIC_UP : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_DOWN) ? GX_CLASSIC_DOWN : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_LEFT) ? GX_CLASSIC_LEFT : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_RIGHT) ? GX_CLASSIC_RIGHT : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_PLUS) ? GX_CLASSIC_PLUS : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_MINUS) ? GX_CLASSIC_MINUS : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_HOME) ? GX_CLASSIC_HOME : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_FULL_L) ? GX_CLASSIC_L_TRIGGER : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_FULL_R) ? GX_CLASSIC_R_TRIGGER : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_ZL) ? GX_CLASSIC_ZL_TRIGGER : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_ZR) ? GX_CLASSIC_ZR_TRIGGER : 0;

            float ljs_mag = exp->classic.ljs.mag;
            float ljs_ang = exp->classic.ljs.ang;

            float rjs_mag = exp->classic.rjs.mag;
            float rjs_ang = exp->classic.rjs.ang;

            if (ljs_mag > 1.0f)
               ljs_mag = 1.0f;
            else if (ljs_mag < -1.0f)
               ljs_mag = -1.0f;

            if (rjs_mag > 1.0f)
               rjs_mag = 1.0f;
            else if (rjs_mag < -1.0f)
               rjs_mag = -1.0f;

            double ljs_val_x = ljs_mag * sin(M_PI * ljs_ang / 180.0);
            double ljs_val_y = -ljs_mag * cos(M_PI * ljs_ang / 180.0);

            double rjs_val_x = rjs_mag * sin(M_PI * rjs_ang / 180.0);
            double rjs_val_y = -rjs_mag * cos(M_PI * rjs_ang / 180.0);

            int16_t ls_x = (int16_t)(ljs_val_x * 32767.0f);
            int16_t ls_y = (int16_t)(ljs_val_y * 32767.0f);

            int16_t rs_x = (int16_t)(rjs_val_x * 32767.0f);
            int16_t rs_y = (int16_t)(rjs_val_y * 32767.0f);

            analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_X] = ls_x;
            analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_Y] = ls_y;
            analog_state[port][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_X] = rs_x;
            analog_state[port][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_Y] = rs_y;
         }
         else if (type == WPAD_EXP_NUNCHUK)
         {
            // wiimote is held upright with nunchuk, do not change d-pad orientation
            *state_cur |= (down & WPAD_BUTTON_UP) ? GX_WIIMOTE_UP : 0;
            *state_cur |= (down & WPAD_BUTTON_DOWN) ? GX_WIIMOTE_DOWN : 0;
            *state_cur |= (down & WPAD_BUTTON_LEFT) ? GX_WIIMOTE_LEFT : 0;
            *state_cur |= (down & WPAD_BUTTON_RIGHT) ? GX_WIIMOTE_RIGHT : 0;

            *state_cur |= (down & WPAD_NUNCHUK_BUTTON_Z) ? GX_NUNCHUK_Z : 0;
            *state_cur |= (down & WPAD_NUNCHUK_BUTTON_C) ? GX_NUNCHUK_C : 0;

            float js_mag = exp->nunchuk.js.mag;
            float js_ang = exp->nunchuk.js.ang;

            if (js_mag > 1.0f)
               js_mag = 1.0f;
            else if (js_mag < -1.0f)
               js_mag = -1.0f;

            double js_val_x = js_mag * sin(M_PI * js_ang / 180.0);
            double js_val_y = -js_mag * cos(M_PI * js_ang / 180.0);

            int16_t x = (int16_t)(js_val_x * 32767.0f);
            int16_t y = (int16_t)(js_val_y * 32767.0f);

            analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_X] = x;
            analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_Y] = y;
         }
      }
#endif

      if (SI_GetType(port) & SI_TYPE_GC)
      {
         down = PAD_ButtonsHeld(port);

         *state_cur |= (down & PAD_BUTTON_A) ? GX_GC_A : 0;
         *state_cur |= (down & PAD_BUTTON_B) ? GX_GC_B : 0;
         *state_cur |= (down & PAD_BUTTON_X) ? GX_GC_X : 0;
         *state_cur |= (down & PAD_BUTTON_Y) ? GX_GC_Y : 0;
         *state_cur |= (down & PAD_BUTTON_UP) ? GX_GC_UP : 0;
         *state_cur |= (down & PAD_BUTTON_DOWN) ? GX_GC_DOWN : 0;
         *state_cur |= (down & PAD_BUTTON_LEFT) ? GX_GC_LEFT : 0;
         *state_cur |= (down & PAD_BUTTON_RIGHT) ? GX_GC_RIGHT : 0;
         *state_cur |= (down & PAD_BUTTON_START) ? GX_GC_START : 0;
         *state_cur |= (down & PAD_TRIGGER_Z) ? GX_GC_Z_TRIGGER : 0;
         *state_cur |= ((down & PAD_TRIGGER_L) || PAD_TriggerL(port) > 127) ? GX_GC_L_TRIGGER : 0;
         *state_cur |= ((down & PAD_TRIGGER_R) || PAD_TriggerR(port) > 127) ? GX_GC_R_TRIGGER : 0;

         int16_t ls_x = (int16_t)PAD_StickX(port) * 256;
         int16_t ls_y = (int16_t)PAD_StickY(port) * -256;
         int16_t rs_x = (int16_t)PAD_SubStickX(port) * 256;
         int16_t rs_y = (int16_t)PAD_SubStickY(port) * -256;

         analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_X] = ls_x;
         analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_Y] = ls_y;
         analog_state[port][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_X] = rs_x;
         analog_state[port][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_Y] = rs_y;

         if ((*state_cur & (GX_GC_START | GX_GC_Z_TRIGGER | GX_GC_L_TRIGGER | GX_GC_R_TRIGGER)) == (GX_GC_START | GX_GC_Z_TRIGGER | GX_GC_L_TRIGGER | GX_GC_R_TRIGGER))
            *state_cur |= GX_WIIMOTE_HOME;
      }
   }

   uint64_t *state_p1 = &pad_state[0];
   uint64_t *lifecycle_state = &g_extern.lifecycle_state;

   *lifecycle_state &= ~(
         (1ULL << RARCH_FAST_FORWARD_HOLD_KEY) | 
         (1ULL << RARCH_LOAD_STATE_KEY) | 
         (1ULL << RARCH_SAVE_STATE_KEY) | 
         (1ULL << RARCH_STATE_SLOT_PLUS) | 
         (1ULL << RARCH_STATE_SLOT_MINUS) | 
         (1ULL << RARCH_REWIND) |
         (1ULL << RARCH_QUIT_KEY) |
         (1ULL << RARCH_MENU_TOGGLE));

   if (g_menu)
   {
      *state_p1 |= GX_WIIMOTE_HOME;
      g_menu = false;
   }

   if (*state_p1 & (GX_WIIMOTE_HOME
#ifdef HW_RVL
            | GX_CLASSIC_HOME
#endif
            ))
      *lifecycle_state |= (1ULL << RARCH_MENU_TOGGLE);
}
Example #19
0
static s32 read_keys(u8 port, PadDataS* pad)
{
    CHECK_POWER_BUTTONS();
    u32 b;
    uint16_t pad_status = 0xFFFF;				//bit pointless why is this done this way?
    pad_t *cpad = &pads[port];
    u8 pad_port = cpad->num;
#ifdef HW_RVL
    WPADData *data;

    if(pads[0].type != pads[1].type
            && (pads[0].type == GCPAD || pads[1].type == GCPAD))
    {
        pad_port = 0;							// If Wii Remote and GC pad, then we must read from 0 on both.
    }
    if(cpad->type != GCPAD)
    {
        data = WPAD_Data(pad_port);
        b = WPAD_ButtonsHeld(pad_port);
    }
    else
#endif
        b = PAD_ButtonsHeld(pad_port);

    if (b & cpad->R2) {
        pad_status &= PSX_BUTTON_R2;
        //b &= ~(cpad->R2);
    }
    if (b & cpad->L2) {
        pad_status &= PSX_BUTTON_L2;
        //b &= ~(cpad->L2);
    }
    if (b & cpad->R1) {
        pad_status &= PSX_BUTTON_R1;
        //b &= ~(cpad->R1);
    }
    if (b & cpad->L1) {
        pad_status &= PSX_BUTTON_L1;
        //b &= ~(cpad->L1);
    }

    if (b & cpad->START)
        pad_status &= PSX_BUTTON_START;
    if (b & cpad->SELECT)
        pad_status &= PSX_BUTTON_SELECT;
    if (b & cpad->CROSS)
        pad_status &= PSX_BUTTON_CROSS;
    if (b & cpad->CIRCLE)
        pad_status &= PSX_BUTTON_CIRCLE;
    if (b & cpad->SQUARE)
        pad_status &= PSX_BUTTON_SQUARE;
    if (b & cpad->TRIANGLE)
        pad_status &= PSX_BUTTON_TRIANGLE;

#ifdef HW_RVL
    if(data->exp.type == WPAD_EXP_NUNCHUK && cpad->analog == PAD_STANDARD)
    {
        if(data->exp.nunchuk.js.pos.y > 140)
            pad_status &= PSX_BUTTON_DUP;
        if(data->exp.nunchuk.js.pos.y < 110)
            pad_status &= PSX_BUTTON_DDOWN;
        if(data->exp.nunchuk.js.pos.x < 110)
            pad_status &= PSX_BUTTON_DLEFT;
        if(data->exp.nunchuk.js.pos.x > 140)
            pad_status &= PSX_BUTTON_DRIGHT;
    }
    else
#endif
    {
        if (b & cpad->UP)
            pad_status &= PSX_BUTTON_DUP;
        if (b & cpad->DOWN)
            pad_status &= PSX_BUTTON_DDOWN;
        if (b & cpad->LEFT)
            pad_status &= PSX_BUTTON_DLEFT;
        if (b & cpad->RIGHT)
            pad_status &= PSX_BUTTON_DRIGHT;
    }

    if (b & cpad->MENU)
    {
        ClosePlugins();
        SysRunGui();
    }

    if(cpad->analog == PAD_ANALOG)
    {
        switch(cpad->type)
        {
        case GCPAD:
            pad->leftJoyX  = (u8)(PAD_StickX(pad_port)+128);
            pad->leftJoyY  = (u8)(PAD_StickY(pad_port)+128);
            pad->rightJoyX = (u8)(PAD_SubStickX(pad_port)+128);
            pad->rightJoyY = (u8)(PAD_SubStickY(pad_port)+128);
            break;
#ifdef HW_RVL
        case NUNCHAK:	// or Classic
            if(data->exp.type == WPAD_EXP_NUNCHUK)
            {
                //TODO: Check this
                gforce_t gforce;
                WPAD_GForce(pad_port, &gforce);
                pad->leftJoyX  = data->exp.nunchuk.js.pos.x;
                pad->leftJoyY  = data->exp.nunchuk.js.pos.y;
                pad->rightJoyX = gforce.x;
                pad->rightJoyY = gforce.y;
            }
            else
            {
                pad->leftJoyX  = (u8)(data->exp.classic.ljs.pos.x+128);
                pad->leftJoyY  = (u8)(data->exp.classic.ljs.pos.y+128);
                pad->rightJoyX = (u8)(data->exp.classic.rjs.pos.x+128);
                pad->rightJoyY = (u8)(data->exp.classic.rjs.pos.y+128);
            }
            break;
#endif
        }
    }
    pad->controllerType = cpad->analog;
    pad->buttonStatus = pad_status;									// Copy Buttons
    return PSE_PAD_ERR_SUCCESS;
}
Example #20
0
void getGamecubePadInput() 
{
   u32 pressed;
   int dpadPressed = 0;
   int virtualJoyIndex=0;
   int physicalJoyIndex=0;
   SDL_Event keyDownEvent[MAX_EVENTS_PER_CYCLE];
   
   //************************************************
   // Buttons PRESSED
   //************************************************
   for (virtualJoyIndex=0; virtualJoyIndex<2; virtualJoyIndex++)
   {
      if (joyGcUsed[virtualJoyIndex]==0) continue;
      physicalJoyIndex = virtualJoyIndex;
      if (joyGcUsed[0]==0)
      {
         physicalJoyIndex=0;
      }
      pressed = PAD_ButtonsDown(physicalJoyIndex);
      int keyDownIndex=0;
      
      if (pressed & PAD_BUTTON_A)
      {
         keyDownEvent[keyDownIndex].jbutton.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].jbutton.type=SDL_JOYBUTTONDOWN;
         keyDownEvent[keyDownIndex].jbutton.button=JOY_BTN_09;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]); 
      }
      
      if (pressed & PAD_BUTTON_Y)
      {
         keyDownEvent[keyDownIndex].jbutton.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].jbutton.type=SDL_JOYBUTTONDOWN;
         keyDownEvent[keyDownIndex].jbutton.button=JOY_BTN_10;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]); 
      }
      
      if (pressed & PAD_BUTTON_X)
      {
         keyDownEvent[keyDownIndex].jbutton.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].jbutton.type=SDL_JOYBUTTONDOWN;
         keyDownEvent[keyDownIndex].jbutton.button=JOY_BTN_11;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]);
      }
      
      if (pressed & PAD_BUTTON_B)
      {
         keyDownEvent[keyDownIndex].jbutton.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].jbutton.type=SDL_JOYBUTTONDOWN;
         keyDownEvent[keyDownIndex].jbutton.button=JOY_BTN_12;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]);
      }
      
      if (pressed & PAD_BUTTON_START)
      {
         keyDownEvent[keyDownIndex].key.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].key.type=SDL_KEYDOWN;
         keyDownEvent[keyDownIndex].key.keysym.sym=SDLK_F1;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]); 
      }
      
      if (pressed & PAD_TRIGGER_R)
      {
         keyDownEvent[keyDownIndex].jbutton.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].jbutton.type=SDL_JOYBUTTONDOWN;
         keyDownEvent[keyDownIndex].jbutton.button=JOY_BTN_02;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]); 
      }
      
      if (pressed & PAD_TRIGGER_Z)
      {
         keyDownEvent[keyDownIndex].jbutton.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].jbutton.type=SDL_JOYBUTTONDOWN;
         keyDownEvent[keyDownIndex].jbutton.button=JOY_BTN_00;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]);  
      }
      
      if (pressed & PAD_TRIGGER_L)
      {
         keyDownEvent[keyDownIndex].jbutton.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].jbutton.type=SDL_JOYBUTTONDOWN;
         keyDownEvent[keyDownIndex].jbutton.button=JOY_BTN_01;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]); 
      }
      
      //************************************************
      // Buttons PRESSED --> D-Pads
      //************************************************
      
       if (
          (pressed & PAD_BUTTON_RIGHT)
         )
      {
         //x
         keyDownEvent[keyDownIndex].type = SDL_JOYAXISMOTION;
         keyDownEvent[keyDownIndex].jaxis.axis = 0;
         keyDownEvent[keyDownIndex].jaxis.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].jaxis.value=10000;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]);
         dpadPressed=1;
      }
      
      if (
          (pressed & PAD_BUTTON_DOWN)
         )
      {
         //y
         keyDownEvent[keyDownIndex].type = SDL_JOYAXISMOTION;
         keyDownEvent[keyDownIndex].jaxis.axis = 1;
         keyDownEvent[keyDownIndex].jaxis.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].jaxis.value=10000;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]);
         dpadPressed=1;      
      }
       
      if (
          (pressed & PAD_BUTTON_LEFT)
         )
      {
         //x
         keyDownEvent[keyDownIndex].type = SDL_JOYAXISMOTION;
         keyDownEvent[keyDownIndex].jaxis.axis = 0;
         keyDownEvent[keyDownIndex].jaxis.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].jaxis.value=-10000;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]);
         dpadPressed=1;      
      }
       
      if (
          (pressed & PAD_BUTTON_UP)
         )
      {
         //x
         keyDownEvent[keyDownIndex].type = SDL_JOYAXISMOTION;
         keyDownEvent[keyDownIndex].jaxis.axis = 1;
         keyDownEvent[keyDownIndex].jaxis.which=virtualJoyIndex;
         keyDownEvent[keyDownIndex].jaxis.value=-10000;
         SDL_PushEvent(&keyDownEvent[keyDownIndex++]);
         dpadPressed=1;      
      }
      
      //************************************************
      // Buttons Held --> D-Pads
      //************************************************
      

      pressed = PAD_ButtonsHeld(physicalJoyIndex);
      int keyHeldIndex=0;
      SDL_Event keyHeldEvent[MAX_EVENTS_PER_CYCLE];
      
      if (
          (pressed & PAD_BUTTON_RIGHT)
         )
      {
         //x
         keyHeldEvent[keyHeldIndex].type = SDL_JOYAXISMOTION;
         keyHeldEvent[keyHeldIndex].jaxis.axis = 0;
         keyHeldEvent[keyHeldIndex].jaxis.which=virtualJoyIndex;
         keyHeldEvent[keyHeldIndex].jaxis.value=10000;
         SDL_PushEvent(&keyHeldEvent[keyHeldIndex++]);  
         dpadPressed=1;
      }
    
      if (
          (pressed & PAD_BUTTON_DOWN)
         )
      {
         //y
         keyHeldEvent[keyHeldIndex].type = SDL_JOYAXISMOTION;
         keyHeldEvent[keyHeldIndex].jaxis.axis = 1;
         keyHeldEvent[keyHeldIndex].jaxis.which=virtualJoyIndex;
         keyHeldEvent[keyHeldIndex].jaxis.value=10000;
         SDL_PushEvent(&keyHeldEvent[keyHeldIndex++]);
         dpadPressed=1;
      }
      
      if (
          (pressed & PAD_BUTTON_LEFT)
         )
      {
         //x
         keyHeldEvent[keyHeldIndex].type = SDL_JOYAXISMOTION;
         keyHeldEvent[keyHeldIndex].jaxis.axis = 0;
         keyHeldEvent[keyHeldIndex].jaxis.which=virtualJoyIndex;
         keyHeldEvent[keyHeldIndex].jaxis.value=-10000;
         SDL_PushEvent(&keyHeldEvent[keyHeldIndex++]);
         dpadPressed=1;         
      }
    
      if (
          (pressed & PAD_BUTTON_UP)
         )
      {
         //x
         keyHeldEvent[keyHeldIndex].type = SDL_JOYAXISMOTION;
         keyHeldEvent[keyHeldIndex].jaxis.axis = 1;
         keyHeldEvent[keyHeldIndex].jaxis.which=virtualJoyIndex;
         keyHeldEvent[keyHeldIndex].jaxis.value=-10000;
         SDL_PushEvent(&keyHeldEvent[keyHeldIndex++]);
         dpadPressed=1;         
      }
      
      //************************************************
      // Buttons RELEASED
      //************************************************
      
      pressed = PAD_ButtonsUp(physicalJoyIndex);
      int keyUpIndex=0;
      SDL_Event keyUpEvent[MAX_EVENTS_PER_CYCLE];
      
      if (pressed & PAD_BUTTON_A)
      {
         keyUpEvent[keyUpIndex].jbutton.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].jbutton.type=SDL_JOYBUTTONUP;
         keyUpEvent[keyUpIndex].jbutton.button=JOY_BTN_09;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]); 
      }
      
      if (pressed & PAD_BUTTON_Y)
      {
         keyUpEvent[keyUpIndex].jbutton.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].jbutton.type=SDL_JOYBUTTONUP;
         keyUpEvent[keyUpIndex].jbutton.button=JOY_BTN_10;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]); 
      }
      
      if (pressed & PAD_BUTTON_X)
      {
         keyUpEvent[keyUpIndex].jbutton.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].jbutton.type=SDL_JOYBUTTONUP;
         keyUpEvent[keyUpIndex].jbutton.button=JOY_BTN_11;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]);
      }
      
      if (pressed & PAD_BUTTON_B)
      {
         keyUpEvent[keyUpIndex].jbutton.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].jbutton.type=SDL_JOYBUTTONUP;
         keyUpEvent[keyUpIndex].jbutton.button=JOY_BTN_12;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]); 
      }
      
      if (pressed & PAD_TRIGGER_R)
      {
         keyUpEvent[keyUpIndex].jbutton.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].jbutton.type=SDL_JOYBUTTONUP;
         keyUpEvent[keyUpIndex].jbutton.button=JOY_BTN_02;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]); 
      }
      
      if (pressed & PAD_TRIGGER_Z)
      {
         keyUpEvent[keyUpIndex].jbutton.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].jbutton.type=SDL_JOYBUTTONUP;
         keyUpEvent[keyUpIndex].jbutton.button=JOY_BTN_00;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]); 
      }
      
      if (pressed & PAD_TRIGGER_L)
      {
         keyUpEvent[keyUpIndex].jbutton.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].jbutton.type=SDL_JOYBUTTONUP;
         keyUpEvent[keyUpIndex].jbutton.button=JOY_BTN_01;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]);
      }
      
      //************************************************
      // Buttons RELEASED --> D-Pads
      //************************************************
      
      if (
          (pressed & PAD_BUTTON_RIGHT)
         )
      {
         //x
         keyUpEvent[keyUpIndex].type = SDL_JOYAXISMOTION;
         keyUpEvent[keyUpIndex].jaxis.axis = 0;
         keyUpEvent[keyUpIndex].jaxis.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].jaxis.value=0;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]);
         dpadPressed=1;
      }
    
      if (
          (pressed & PAD_BUTTON_DOWN)
         )
      {
         //y
         keyUpEvent[keyUpIndex].type = SDL_JOYAXISMOTION;
         keyUpEvent[keyUpIndex].jaxis.axis = 1;
         keyUpEvent[keyUpIndex].jaxis.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].jaxis.value=0;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]);
         dpadPressed=1;
      }
    
      if (
          (pressed & PAD_BUTTON_LEFT)
         )
      {
         //x
         keyUpEvent[keyUpIndex].type = SDL_JOYAXISMOTION;
         keyUpEvent[keyUpIndex].jaxis.axis = 0;
         keyUpEvent[keyUpIndex].jaxis.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].jaxis.value=0;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]);
         dpadPressed=1;
      }
    
      if (
          (pressed & PAD_BUTTON_UP)
         )
      {
         //x
         keyUpEvent[keyUpIndex].type = SDL_JOYAXISMOTION;
         keyUpEvent[keyUpIndex].jaxis.axis = 1;
         keyUpEvent[keyUpIndex].jaxis.which=virtualJoyIndex;
         keyUpEvent[keyUpIndex].jaxis.value=0;
         SDL_PushEvent(&keyUpEvent[keyUpIndex++]);
         dpadPressed=1;
      }
      
      //************************************************
      // Left stick --> JoyAXIS
      //************************************************
      int x = 0;
      int y = 0;
      int angleIndex = 0;
      s8 X1=0, Y1=0, X2=0, Y2=0;
      X1 = PAD_StickX(physicalJoyIndex);
      Y1 = PAD_StickY(physicalJoyIndex);	
      X2 = PAD_SubStickX(physicalJoyIndex);
      Y2 = PAD_SubStickY(physicalJoyIndex);
      
      if (!dpadPressed)
      {
         x = X1-DEFAULT_GC_LEFT_X_CENTER;
         y = Y1-DEFAULT_GC_LEFT_Y_CENTER;
         angleIndex = getAngleIndex(x,y);
           
         SDL_Event xevent;
         xevent.type = SDL_JOYAXISMOTION;
         xevent.jaxis.which=virtualJoyIndex;
         xevent.jaxis.axis = 0;
         
         SDL_Event yevent;
         yevent.type = SDL_JOYAXISMOTION;
         yevent.jaxis.which=virtualJoyIndex;
         yevent.jaxis.axis = 1;
         
         getSDLJoyAxisEvent(&xevent, &yevent, angleIndex);
         
         if ( 
             (x < GC_LEFT_X_TOLERANCE) &&
             (x > -GC_LEFT_X_TOLERANCE)
             )
         {
            xevent.jaxis.value = 0;
         }
          
         if (
             (y < GC_LEFT_Y_TOLERANCE) &&
             (y > -GC_LEFT_Y_TOLERANCE)
            )
         {
            yevent.jaxis.value = 0;
         }
         
         SDL_PushEvent(&xevent); 
         SDL_PushEvent(&yevent); 
      }
      
      //************************************************
      // Right stick --> HAT
      //************************************************
      
      x = X2-DEFAULT_GC_RIGHT_X_CENTER;
      y = Y2-DEFAULT_GC_RIGHT_Y_CENTER;
      angleIndex = getAngleIndex(x,y);
      
      SDL_Event hatEvent;
      hatEvent.type = SDL_JOYHATMOTION;
      hatEvent.jhat.which=virtualJoyIndex;
      hatEvent.jhat.hat = 0;
      hatEvent.jhat.value = SDL_HAT_CENTERED;
      
      if ( 
          (x > GC_RIGHT_X_TOLERANCE) ||
          (x < -GC_RIGHT_X_TOLERANCE)||
          (y > GC_RIGHT_Y_TOLERANCE) ||
          (y < -GC_RIGHT_Y_TOLERANCE)
         )
      {
         getHatEvent(&hatEvent, angleIndex);
      }
      if (lastHatSent[hatEvent.jhat.which] != hatEvent.jhat.value)
      {
        SDL_PushEvent(&hatEvent);
        lastHatSent[hatEvent.jhat.which] = hatEvent.jhat.value;
      }
   }
}
Example #21
0
// Some things here rely upon IN_Move always being called after IN_Commands on the same frame
void IN_Move (usercmd_t *cmd)
{
	const float dead_zone = 0.1f;

	float x1;
	float y1;
	float x2;
	float y2;

	// TODO: sensor bar position correct? aspect ratio correctly set? etc...
	int last_wiimote_ir_x = pointer.x;
	int last_wiimote_ir_y = pointer.y;
	int wiimote_ir_x = 0, wiimote_ir_y = 0;


	if (pointer.x < 1 || (unsigned int)pointer.x > pointer.vres[0] - 1)
		wiimote_ir_x = last_wiimote_ir_x;
	else
		wiimote_ir_x = pointer.x;
	if (pointer.y < 1 || (unsigned int)pointer.y > pointer.vres[1] - 1)
		wiimote_ir_y = last_wiimote_ir_y;
	else
		wiimote_ir_y = pointer.y;

	last_wiimote_ir_x = wiimote_ir_x;
	last_wiimote_ir_y = wiimote_ir_y;

	if (in_osk || (cls.state == ca_connected && key_dest != key_game))
	{
		last_irx = wiimote_ir_x;
		last_iry = wiimote_ir_y;
		return;
	}

	if(nunchuk_connected)
	{
		const s8 nunchuk_stick_x = WPAD_StickX(0);
		const s8 nunchuk_stick_y = WPAD_StickY(0);

		x1 = clamp(((float)nunchuk_stick_x / 128.0f) * 1.5, -1.0f, 1.0f);
		y1 = clamp(((float)nunchuk_stick_y / (-128.0f)) * 1.5, -1.0f, 1.0f);

		x2 = clamp((float)wiimote_ir_x / (pointer.vres[0] / 2.0f) - 1.0f, -1.0f, 1.0f);
		Cvar_SetValue("cl_crossx", scr_vrect.width / 2 * x2);

		y2 = clamp((float)wiimote_ir_y / (pointer.vres[1] / 2.0f) - 1.0f, -1.0f, 1.0f);
		Cvar_SetValue("cl_crossy", scr_vrect.height / 2 * y2);
	}

	else if(classic_connected)
	{
		const s8 left_stick_x = WPAD_StickX(0);
		const s8 left_stick_y = WPAD_StickY(0);

		const s8 right_stick_x = WPAD_StickX(1);
		const s8 right_stick_y = WPAD_StickY(1);

		x1 = clamp(((float)left_stick_x / 128.0f) * 1.5, -1.0f, 1.0f);
		y1 = clamp(((float)left_stick_y / (-128.0f)) * 1.5, -1.0f, 1.0f);

		x2 = clamp(((float)right_stick_x / 128.0f) * 1.5, -1.0f, 1.0f);
		Cvar_SetValue("cl_crossx", (in_mlook.state & 1) ? scr_vrect.width / 2 * x2 : 0);
		y2 = clamp(((float)right_stick_y / (-128.0f)) * 1.5, -1.0f, 1.0f);
		Cvar_SetValue("cl_crossy", (in_mlook.state & 1) ? scr_vrect.height / 2 * y2 : 0);
	}

	else
	{
		const s8 stick_x = PAD_StickX(0);
		const s8 stick_y = PAD_StickY(0);

		const s8 sub_stick_x = PAD_SubStickX(0);
		const s8 sub_stick_y = PAD_SubStickY(0);

		x1 = clamp(stick_x / 90.0f, -1.0f, 1.0f);
		y1 = clamp(stick_y / -90.0f, -1.0f, 1.0f);

		x2 = clamp(sub_stick_x / 80.0f, -1.0f, 1.0f);
		Cvar_SetValue("cl_crossx", (in_mlook.state & 1) ? scr_vrect.width / 2 * x2 : 0);

		y2 = clamp(sub_stick_y / -80.0f, -1.0f, 1.0f);
		Cvar_SetValue("cl_crossy", (in_mlook.state & 1) ? scr_vrect.height / 2 * y2 : 0);
	}

	last_irx = wiimote_ir_x;
	last_iry = wiimote_ir_y;

	// Apply the dead zone.
	apply_dead_zone(&x1, &y1, dead_zone);
	apply_dead_zone(&x2, &y2, dead_zone);

	// Don't let the pitch drift back to centre if mouse look is on or the right stick is being used.
	//if ((in_mlook.state & 1) || (fabsf(y2) >= dead_zone)) Disabled, always very convenient with a gamepad or wiimote
	{
		V_StopPitchDrift();
	}

	// Lock view?
	if (in_mlook.state & 1)
	{
		x2 = 0;
		y2 = 0;
	}

	float yaw_rate;
	float pitch_rate;

	yaw_rate = x2;
	pitch_rate = y2;

	// Move using the main stick.
	cmd->sidemove += cl_sidespeed.value * x1;
	cmd->forwardmove -= cl_forwardspeed.value * y1; /* TODO: use cl_backspeed when going backwards? */

	if (in_speed.state & 1)
	{
		if (cl_forwardspeed.value > 200)
		{
			cmd->forwardmove /= cl_movespeedkey.value;
			cmd->sidemove /= cl_movespeedkey.value;
		}
		else
		{
			cmd->forwardmove *= cl_movespeedkey.value;
			cmd->sidemove *= cl_movespeedkey.value; /* TODO: always seem to be at the max and I'm too sleepy now to figure out why */
		}
	}

	// TODO: Use yawspeed and pitchspeed

	// Adjust the yaw.
	const float turn_rate = sensitivity.value * 50.0f;
	if (in_speed.state & 1)
	{
		if (cl_forwardspeed.value > 200)
			cl.viewangles[YAW] -= turn_rate * yaw_rate * host_frametime / cl_anglespeedkey.value;
		else
			cl.viewangles[YAW] -= turn_rate * yaw_rate * host_frametime * cl_anglespeedkey.value;
	}
	else
		cl.viewangles[YAW] -= turn_rate * yaw_rate * host_frametime;

	// How fast to pitch?
	float pitch_offset;
	if (in_speed.state & 1)
	{
		if (cl_forwardspeed.value > 200)
			pitch_offset = turn_rate * pitch_rate * host_frametime / cl_anglespeedkey.value;
		else
			pitch_offset = turn_rate * pitch_rate * host_frametime * cl_anglespeedkey.value;
	}
	else
		pitch_offset = turn_rate * pitch_rate * host_frametime;

	// Do the pitch.
	const bool	invert_pitch = m_pitch.value < 0;
	if (invert_pitch)
	{
		cl.viewangles[PITCH] -= pitch_offset;
	}
	else
	{
		cl.viewangles[PITCH] += pitch_offset;
	}

	// Don't look too far up or down.
	if (cl.viewangles[PITCH] > 80.0f)
	{
		cl.viewangles[PITCH] = 80.0f;
	}
	else if (cl.viewangles[PITCH] < -70.0f)
	{
		cl.viewangles[PITCH] = -70.0f;
	}

	if (wiimote_connected && nunchuk_connected)
	{
		in_pitchangle = orientation.pitch;
		in_yawangle = orientation.yaw;
		in_rollangle = orientation.roll;
	}
	else
	{
		in_pitchangle = .0f;
		in_yawangle = .0f;
		in_rollangle = .0f;
	}
}
Example #22
0
u32 DecodeJoy(unsigned short pad)
{
	signed char pad_x = PAD_StickX (pad);
	signed char pad_y = PAD_StickY (pad);
	signed char gc_px = PAD_SubStickX (0);
	u32 jp = PAD_ButtonsHeld (pad);
	u32 J = 0;

	#ifdef HW_RVL
	signed char wm_ax = WPAD_Stick ((u8)pad, 0, 0);
	signed char wm_ay = WPAD_Stick ((u8)pad, 0, 1);
	u32 wp = WPAD_ButtonsHeld (pad);
	signed char wm_sx = WPAD_Stick (0,1,0); // CC right joystick

	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)
	{
		if (pad_x > 0 && pad_y == 0) J |= VBA_RIGHT;
		if (pad_x < 0 && pad_y == 0) J |= VBA_LEFT;
		if (pad_x == 0 && pad_y > 0) J |= VBA_UP;
		if (pad_x == 0 && pad_y < 0) J |= VBA_DOWN;

		if (pad_x != 0 && pad_y != 0)
		{
			if ((float)pad_y / pad_x >= -2.41421356237 && (float)pad_y / pad_x < 2.41421356237)
			{
				if (pad_x >= 0)
					J |= VBA_RIGHT;
				else
					J |= VBA_LEFT;
			}

			if ((float)pad_x / pad_y >= -2.41421356237 && (float)pad_x / pad_y < 2.41421356237)
			{
				if (pad_y >= 0)
					J |= VBA_UP;
				else
					J |= VBA_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)
			J |= VBA_RIGHT;
		if (wm_ax < 0 && wm_ay == 0)
			J |= VBA_LEFT;
		if (wm_ax == 0 && wm_ay > 0)
			J |= VBA_UP;
		if (wm_ax == 0 && wm_ay < 0)
			J |= VBA_DOWN;

		if (wm_ax != 0 && wm_ay != 0)
		{

			/*** Recalc left / right ***/
			float t;

			t = (float) wm_ay / wm_ax;
			if (t >= -2.41421356237 && t < 2.41421356237)
			{
				if (wm_ax >= 0)
					J |= VBA_RIGHT;
				else
					J |= VBA_LEFT;
			}

			/*** Recalc up / down ***/
			t = (float) wm_ax / wm_ay;
			if (t >= -2.41421356237 && t < 2.41421356237)
			{
				if (wm_ay >= 0)
					J |= VBA_UP;
				else
					J |= VBA_DOWN;
			}
		}
	}
#endif

	// Turbo feature
	if(
	(gc_px > 70)
	#ifdef HW_RVL
	|| (wm_sx > 70)
	|| ((wp & WPAD_BUTTON_A) && (wp & WPAD_BUTTON_B))
	#endif
	)
		J |= VBA_SPEED;

	/*** Report pressed buttons (gamepads) ***/
	int i;

	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
		)
			J |= vbapadmap[i];
	}

	if ((J & 48) == 48)
		J &= ~16;
	if ((J & 192) == 192)
		J &= ~128;

	return J;
}
Example #23
0
static void gx_joypad_poll(void)
{
   unsigned i, j, port;
   uint8_t gcpad    = 0;

   pad_state[0] = 0;
   pad_state[1] = 0;
   pad_state[2] = 0;
   pad_state[3] = 0;

   gcpad = PAD_ScanPads();

#ifdef HW_RVL
   WPAD_ReadPending(WPAD_CHAN_ALL, NULL);
#endif

   for (port = 0; port < MAX_PADS; port++)
   {
      uint32_t down = 0, ptype = WPAD_EXP_NOCONTROLLER;
      uint64_t *state_cur = &pad_state[port];

      if (gcpad & (1 << port))
      {
         int16_t ls_x, ls_y, rs_x, rs_y;
         uint64_t menu_combo = 0;

         down = PAD_ButtonsHeld(port);

         *state_cur |= (down & PAD_BUTTON_A) ? (UINT64_C(1) << GX_GC_A) : 0;
         *state_cur |= (down & PAD_BUTTON_B) ? (UINT64_C(1) << GX_GC_B) : 0;
         *state_cur |= (down & PAD_BUTTON_X) ? (UINT64_C(1) << GX_GC_X) : 0;
         *state_cur |= (down & PAD_BUTTON_Y) ? (UINT64_C(1) << GX_GC_Y) : 0;
         *state_cur |= (down & PAD_BUTTON_UP) ? (UINT64_C(1) << GX_GC_UP) : 0;
         *state_cur |= (down & PAD_BUTTON_DOWN) ? (UINT64_C(1) << GX_GC_DOWN) : 0;
         *state_cur |= (down & PAD_BUTTON_LEFT) ? (UINT64_C(1) << GX_GC_LEFT) : 0;
         *state_cur |= (down & PAD_BUTTON_RIGHT) ? (UINT64_C(1) << GX_GC_RIGHT) : 0;
         *state_cur |= (down & PAD_BUTTON_START) ? (UINT64_C(1) << GX_GC_START) : 0;
         *state_cur |= (down & PAD_TRIGGER_Z) ? (UINT64_C(1) << GX_GC_Z_TRIGGER) : 0;
         *state_cur |= ((down & PAD_TRIGGER_L) || PAD_TriggerL(port) > 127) ? (UINT64_C(1) << GX_GC_L_TRIGGER) : 0;
         *state_cur |= ((down & PAD_TRIGGER_R) || PAD_TriggerR(port) > 127) ? (UINT64_C(1) << GX_GC_R_TRIGGER) : 0;

         ls_x = (int16_t)PAD_StickX(port) * 256;
         ls_y = (int16_t)PAD_StickY(port) * -256;
         rs_x = (int16_t)PAD_SubStickX(port) * 256;
         rs_y = (int16_t)PAD_SubStickY(port) * -256;

         analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_X] = ls_x;
         analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_Y] = ls_y;
         analog_state[port][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_X] = rs_x;
         analog_state[port][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_Y] = rs_y;

         menu_combo = (UINT64_C(1) << GX_GC_START) | (UINT64_C(1) << GX_GC_Z_TRIGGER) |
                      (UINT64_C(1) << GX_GC_L_TRIGGER) | (UINT64_C(1) << GX_GC_R_TRIGGER);

         if ((*state_cur & menu_combo) == menu_combo)
            *state_cur |= (UINT64_C(1) << GX_GC_HOME);

         ptype = WPAD_EXP_GAMECUBE;
      }
#ifdef HW_RVL
#ifdef HAVE_LIBSICKSAXIS
      else if (port < USB_SLOTS && ss_is_ready(&sixaxis[port]))/* Only defined 1 port for now */
      {
         int16_t ls_x, ls_y, rs_x, rs_y;

         ss_read_pad(&sixaxis[port]);

         *state_cur |= (sixaxis[port].pad.buttons.PS)       ? (UINT64_C(1) << GX_SIXAXIS_PS) : 0;
         *state_cur |= (sixaxis[port].pad.buttons.cross)    ? (UINT64_C(1) << GX_SIXAXIS_CROSS) : 0;
         *state_cur |= (sixaxis[port].pad.buttons.square)   ? (UINT64_C(1) << GX_SIXAXIS_SQUARE) : 0;
         *state_cur |= (sixaxis[port].pad.buttons.select)   ? (UINT64_C(1) << GX_SIXAXIS_SELECT) : 0;
         *state_cur |= (sixaxis[port].pad.buttons.start)    ? (UINT64_C(1) << GX_SIXAXIS_START) : 0;
         *state_cur |= (sixaxis[port].pad.buttons.up)       ? (UINT64_C(1) << GX_SIXAXIS_UP) : 0;
         *state_cur |= (sixaxis[port].pad.buttons.down)     ? (UINT64_C(1) << GX_SIXAXIS_DOWN) : 0;
         *state_cur |= (sixaxis[port].pad.buttons.left)     ? (UINT64_C(1) << GX_SIXAXIS_LEFT) : 0;
         *state_cur |= (sixaxis[port].pad.buttons.right)    ? (UINT64_C(1) << GX_SIXAXIS_RIGHT) : 0;
         *state_cur |= (sixaxis[port].pad.buttons.circle)   ? (UINT64_C(1) << GX_SIXAXIS_CIRCLE) : 0;
         *state_cur |= (sixaxis[port].pad.buttons.triangle) ? (UINT64_C(1) << GX_SIXAXIS_TRIANGLE) : 0;
         *state_cur |= (sixaxis[port].pad.buttons.L1)       ? (UINT64_C(1) << GX_SIXAXIS_L1) : 0;
         *state_cur |= (sixaxis[port].pad.buttons.R1)       ? (UINT64_C(1) << GX_SIXAXIS_R1) : 0;
         *state_cur |= (sixaxis[port].pad.buttons.L2)       ? (UINT64_C(1) << GX_SIXAXIS_L2) : 0;
         *state_cur |= (sixaxis[port].pad.buttons.R2)       ? (UINT64_C(1) << GX_SIXAXIS_R2) : 0;
         *state_cur |= (sixaxis[port].pad.buttons.L3)       ? (UINT64_C(1) << GX_SIXAXIS_L3) : 0;
         *state_cur |= (sixaxis[port].pad.buttons.R3)       ? (UINT64_C(1) << GX_SIXAXIS_R3) : 0;

         ls_x = (int16_t)(sixaxis[port].pad.left_analog.x - 128) << 8;
         ls_y = (int16_t)(sixaxis[port].pad.left_analog.y - 128) << 8;
         rs_x = (int16_t)(sixaxis[port].pad.right_analog.x - 128) << 8;
         rs_y = (int16_t)(sixaxis[port].pad.right_analog.y - 128) << 8;

         analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_X] = ls_x;
         analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_Y] = ls_y;
         analog_state[port][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_X] = rs_x;
         analog_state[port][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_Y] = rs_y;

         ptype = WPAD_EXP_SICKSAXIS;
      }
#endif
      else if (WPADProbe(port, &ptype) == WPAD_ERR_NONE)
      {
         WPADData *wpaddata = (WPADData*)WPAD_Data(port);

         down = wpaddata->btns_h;

         *state_cur |= (down & WPAD_BUTTON_A) ? (UINT64_C(1) << GX_WIIMOTE_A) : 0;
         *state_cur |= (down & WPAD_BUTTON_B) ? (UINT64_C(1) << GX_WIIMOTE_B) : 0;
         *state_cur |= (down & WPAD_BUTTON_1) ? (UINT64_C(1) << GX_WIIMOTE_1) : 0;
         *state_cur |= (down & WPAD_BUTTON_2) ? (UINT64_C(1) << GX_WIIMOTE_2) : 0;
         *state_cur |= (down & WPAD_BUTTON_PLUS) ? (UINT64_C(1) << GX_WIIMOTE_PLUS) : 0;
         *state_cur |= (down & WPAD_BUTTON_MINUS) ? (UINT64_C(1) << GX_WIIMOTE_MINUS) : 0;
         *state_cur |= (down & WPAD_BUTTON_HOME) ? (UINT64_C(1) << GX_WIIMOTE_HOME) : 0;

         if (ptype != WPAD_EXP_NUNCHUK)
         {
            /* Rotated d-pad on Wiimote. */
            *state_cur |= (down & WPAD_BUTTON_UP) ? (UINT64_C(1) << GX_WIIMOTE_LEFT) : 0;
            *state_cur |= (down & WPAD_BUTTON_DOWN) ? (UINT64_C(1) << GX_WIIMOTE_RIGHT) : 0;
            *state_cur |= (down & WPAD_BUTTON_LEFT) ? (UINT64_C(1) << GX_WIIMOTE_DOWN) : 0;
            *state_cur |= (down & WPAD_BUTTON_RIGHT) ? (UINT64_C(1) << GX_WIIMOTE_UP) : 0;
         }

         if (ptype == WPAD_EXP_CLASSIC)
         {
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_A) ? (UINT64_C(1) << GX_CLASSIC_A) : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_B) ? (UINT64_C(1) << GX_CLASSIC_B) : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_X) ? (UINT64_C(1) << GX_CLASSIC_X) : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_Y) ? (UINT64_C(1) << GX_CLASSIC_Y) : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_UP) ? (UINT64_C(1) << GX_CLASSIC_UP) : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_DOWN) ? (UINT64_C(1) << GX_CLASSIC_DOWN) : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_LEFT) ? (UINT64_C(1) << GX_CLASSIC_LEFT) : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_RIGHT) ? (UINT64_C(1) << GX_CLASSIC_RIGHT) : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_PLUS) ? (UINT64_C(1) << GX_CLASSIC_PLUS) : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_MINUS) ? (UINT64_C(1) << GX_CLASSIC_MINUS) : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_HOME) ? (UINT64_C(1) << GX_CLASSIC_HOME) : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_FULL_L) ? (UINT64_C(1) << GX_CLASSIC_L_TRIGGER) : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_FULL_R) ? (UINT64_C(1) << GX_CLASSIC_R_TRIGGER) : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_ZL) ? (UINT64_C(1) << GX_CLASSIC_ZL_TRIGGER) : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_ZR) ? (UINT64_C(1) << GX_CLASSIC_ZR_TRIGGER) : 0;

            analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_X]  = WPAD_StickX(wpaddata, 0);
            analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_Y]  = WPAD_StickY(wpaddata, 0);
            analog_state[port][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_X] = WPAD_StickX(wpaddata, 1);
            analog_state[port][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_Y] = WPAD_StickY(wpaddata, 1);
         }
         else if (ptype == WPAD_EXP_NUNCHUK)
         {
            /* Wiimote is held upright with nunchuk,
             * do not change d-pad orientation. */
            *state_cur |= (down & WPAD_BUTTON_UP) ? (UINT64_C(1) << GX_WIIMOTE_UP) : 0;
            *state_cur |= (down & WPAD_BUTTON_DOWN) ? (UINT64_C(1) << GX_WIIMOTE_DOWN) : 0;
            *state_cur |= (down & WPAD_BUTTON_LEFT) ? (UINT64_C(1) << GX_WIIMOTE_LEFT) : 0;
            *state_cur |= (down & WPAD_BUTTON_RIGHT) ? (UINT64_C(1) << GX_WIIMOTE_RIGHT) : 0;

            *state_cur |= (down & WPAD_NUNCHUK_BUTTON_Z) ? (UINT64_C(1) << GX_NUNCHUK_Z) : 0;
            *state_cur |= (down & WPAD_NUNCHUK_BUTTON_C) ? (UINT64_C(1) << GX_NUNCHUK_C) : 0;

            analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_X] = WPAD_StickX(wpaddata, 0);
            analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_Y] = WPAD_StickY(wpaddata, 0);
         }
      }
#endif

      if (ptype != pad_type[port])
         handle_hotplug(port, ptype);

      for (i = 0; i < 2; i++)
         for (j = 0; j < 2; j++)
            if (analog_state[port][i][j] == -0x8000)
               analog_state[port][i][j] = -0x7fff;
   }

   uint64_t *state_p1 = &pad_state[0];


   BIT64_CLEAR(lifecycle_state, RARCH_MENU_TOGGLE);
   if (g_menu)
   {
      *state_p1 |= (UINT64_C(1) << GX_GC_HOME);
      g_menu = false;
   }

   if (*state_p1 & ((UINT64_C(1) << GX_GC_HOME)
#ifdef HW_RVL
            | (UINT64_C(1) << GX_WIIMOTE_HOME)
            | (UINT64_C(1) << GX_CLASSIC_HOME)
#ifdef HAVE_LIBSICKSAXIS
            | (UINT64_C(1) << GX_SIXAXIS_PS)
#endif
#endif
            ))
    
   BIT64_SET(lifecycle_state, RARCH_MENU_TOGGLE);
}
Example #24
0
static void gx_joypad_poll(void)
{
   unsigned i, j, port;
   uint8_t gcpad = 0;
   uint64_t state_p1;
   uint64_t check_menu_toggle;

   pad_state[0] = 0;
   pad_state[1] = 0;
   pad_state[2] = 0;
   pad_state[3] = 0;

   gcpad = PAD_ScanPads();

#ifdef HW_RVL
   if (g_quit)
   {
      runloop_ctl(RUNLOOP_CTL_SET_SHUTDOWN, NULL);
      return;
   }

   WPAD_ReadPending(WPAD_CHAN_ALL, NULL);
#endif

   for (port = 0; port < MAX_PADS; port++)
   {
      uint32_t down = 0, ptype = WPAD_EXP_NOCONTROLLER;
      uint64_t *state_cur = &pad_state[port];

      if (gcpad & (1 << port))
      {
         int16_t ls_x, ls_y, rs_x, rs_y;
         uint64_t menu_combo = 0;

         down = PAD_ButtonsHeld(port);

         *state_cur |= (down & PAD_BUTTON_A) ? (UINT64_C(1) << GX_GC_A) : 0;
         *state_cur |= (down & PAD_BUTTON_B) ? (UINT64_C(1) << GX_GC_B) : 0;
         *state_cur |= (down & PAD_BUTTON_X) ? (UINT64_C(1) << GX_GC_X) : 0;
         *state_cur |= (down & PAD_BUTTON_Y) ? (UINT64_C(1) << GX_GC_Y) : 0;
         *state_cur |= (down & PAD_BUTTON_UP) ? (UINT64_C(1) << GX_GC_UP) : 0;
         *state_cur |= (down & PAD_BUTTON_DOWN) ? (UINT64_C(1) << GX_GC_DOWN) : 0;
         *state_cur |= (down & PAD_BUTTON_LEFT) ? (UINT64_C(1) << GX_GC_LEFT) : 0;
         *state_cur |= (down & PAD_BUTTON_RIGHT) ? (UINT64_C(1) << GX_GC_RIGHT) : 0;
         *state_cur |= (down & PAD_BUTTON_START) ? (UINT64_C(1) << GX_GC_START) : 0;
         *state_cur |= (down & PAD_TRIGGER_Z) ? (UINT64_C(1) << GX_GC_Z_TRIGGER) : 0;
         *state_cur |= ((down & PAD_TRIGGER_L) || PAD_TriggerL(port) > 127) ? (UINT64_C(1) << GX_GC_L_TRIGGER) : 0;
         *state_cur |= ((down & PAD_TRIGGER_R) || PAD_TriggerR(port) > 127) ? (UINT64_C(1) << GX_GC_R_TRIGGER) : 0;

         ls_x = (int16_t)PAD_StickX(port) * 256;
         ls_y = (int16_t)PAD_StickY(port) * -256;
         rs_x = (int16_t)PAD_SubStickX(port) * 256;
         rs_y = (int16_t)PAD_SubStickY(port) * -256;

         analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_X] = ls_x;
         analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_Y] = ls_y;
         analog_state[port][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_X] = rs_x;
         analog_state[port][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_Y] = rs_y;

         menu_combo = (UINT64_C(1) << GX_GC_START) | (UINT64_C(1) << GX_GC_Z_TRIGGER) |
                      (UINT64_C(1) << GX_GC_L_TRIGGER) | (UINT64_C(1) << GX_GC_R_TRIGGER);

         if ((*state_cur & menu_combo) == menu_combo)
            *state_cur |= (UINT64_C(1) << GX_GC_HOME);

         ptype = WPAD_EXP_GAMECUBE;
      }
#ifdef HW_RVL
      else if (WPADProbe(port, &ptype) == WPAD_ERR_NONE)
      {
         WPADData *wpaddata = (WPADData*)WPAD_Data(port);

         down = wpaddata->btns_h;

         *state_cur |= (down & WPAD_BUTTON_A) ? (UINT64_C(1) << GX_WIIMOTE_A) : 0;
         *state_cur |= (down & WPAD_BUTTON_B) ? (UINT64_C(1) << GX_WIIMOTE_B) : 0;
         *state_cur |= (down & WPAD_BUTTON_1) ? (UINT64_C(1) << GX_WIIMOTE_1) : 0;
         *state_cur |= (down & WPAD_BUTTON_2) ? (UINT64_C(1) << GX_WIIMOTE_2) : 0;
         *state_cur |= (down & WPAD_BUTTON_PLUS) ? (UINT64_C(1) << GX_WIIMOTE_PLUS) : 0;
         *state_cur |= (down & WPAD_BUTTON_MINUS) ? (UINT64_C(1) << GX_WIIMOTE_MINUS) : 0;
         *state_cur |= (down & WPAD_BUTTON_HOME) ? (UINT64_C(1) << GX_WIIMOTE_HOME) : 0;

         if (ptype != WPAD_EXP_NUNCHUK)
         {
            /* Rotated d-pad on Wiimote. */
            *state_cur |= (down & WPAD_BUTTON_UP) ? (UINT64_C(1) << GX_WIIMOTE_LEFT) : 0;
            *state_cur |= (down & WPAD_BUTTON_DOWN) ? (UINT64_C(1) << GX_WIIMOTE_RIGHT) : 0;
            *state_cur |= (down & WPAD_BUTTON_LEFT) ? (UINT64_C(1) << GX_WIIMOTE_DOWN) : 0;
            *state_cur |= (down & WPAD_BUTTON_RIGHT) ? (UINT64_C(1) << GX_WIIMOTE_UP) : 0;
         }

         if (ptype == WPAD_EXP_CLASSIC)
         {
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_A) ? (UINT64_C(1) << GX_CLASSIC_A) : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_B) ? (UINT64_C(1) << GX_CLASSIC_B) : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_X) ? (UINT64_C(1) << GX_CLASSIC_X) : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_Y) ? (UINT64_C(1) << GX_CLASSIC_Y) : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_UP) ? (UINT64_C(1) << GX_CLASSIC_UP) : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_DOWN) ? (UINT64_C(1) << GX_CLASSIC_DOWN) : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_LEFT) ? (UINT64_C(1) << GX_CLASSIC_LEFT) : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_RIGHT) ? (UINT64_C(1) << GX_CLASSIC_RIGHT) : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_PLUS) ? (UINT64_C(1) << GX_CLASSIC_PLUS) : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_MINUS) ? (UINT64_C(1) << GX_CLASSIC_MINUS) : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_HOME) ? (UINT64_C(1) << GX_CLASSIC_HOME) : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_FULL_L) ? (UINT64_C(1) << GX_CLASSIC_L_TRIGGER) : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_FULL_R) ? (UINT64_C(1) << GX_CLASSIC_R_TRIGGER) : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_ZL) ? (UINT64_C(1) << GX_CLASSIC_ZL_TRIGGER) : 0;
            *state_cur |= (down & WPAD_CLASSIC_BUTTON_ZR) ? (UINT64_C(1) << GX_CLASSIC_ZR_TRIGGER) : 0;

            analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_X]  = WPAD_StickX(wpaddata, 0);
            analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_Y]  = WPAD_StickY(wpaddata, 0);
            analog_state[port][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_X] = WPAD_StickX(wpaddata, 1);
            analog_state[port][RETRO_DEVICE_INDEX_ANALOG_RIGHT][RETRO_DEVICE_ID_ANALOG_Y] = WPAD_StickY(wpaddata, 1);
         }
         else if (ptype == WPAD_EXP_NUNCHUK)
         {
            /* Wiimote is held upright with nunchuk,
             * do not change d-pad orientation. */
            *state_cur |= (down & WPAD_BUTTON_UP) ? (UINT64_C(1) << GX_WIIMOTE_UP) : 0;
            *state_cur |= (down & WPAD_BUTTON_DOWN) ? (UINT64_C(1) << GX_WIIMOTE_DOWN) : 0;
            *state_cur |= (down & WPAD_BUTTON_LEFT) ? (UINT64_C(1) << GX_WIIMOTE_LEFT) : 0;
            *state_cur |= (down & WPAD_BUTTON_RIGHT) ? (UINT64_C(1) << GX_WIIMOTE_RIGHT) : 0;

            *state_cur |= (down & WPAD_NUNCHUK_BUTTON_Z) ? (UINT64_C(1) << GX_NUNCHUK_Z) : 0;
            *state_cur |= (down & WPAD_NUNCHUK_BUTTON_C) ? (UINT64_C(1) << GX_NUNCHUK_C) : 0;

            analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_X] = WPAD_StickX(wpaddata, 0);
            analog_state[port][RETRO_DEVICE_INDEX_ANALOG_LEFT][RETRO_DEVICE_ID_ANALOG_Y] = WPAD_StickY(wpaddata, 0);
         }
      }
#endif

      if (ptype != pad_type[port])
         handle_hotplug(port, ptype);

      for (i = 0; i < 2; i++)
         for (j = 0; j < 2; j++)
            if (analog_state[port][i][j] == -0x8000)
               analog_state[port][i][j] = -0x7fff;
   }

   state_p1 = pad_state[0];

   BIT64_CLEAR(lifecycle_state, RARCH_MENU_TOGGLE);
   if (g_menu)
   {
      state_p1 |= (UINT64_C(1) << GX_GC_HOME);
      g_menu = false;
   }

   check_menu_toggle = UINT64_C(1) << GX_GC_HOME;
#ifdef HW_RVL
   check_menu_toggle |= (UINT64_C(1) << GX_WIIMOTE_HOME) | (UINT64_C(1) << GX_CLASSIC_HOME);
#endif

   if (check_menu_toggle & state_p1)
      BIT64_SET(lifecycle_state, RARCH_MENU_TOGGLE);
}
Example #25
0
int
FileSelector ()
{
    u32 p, wp, ph, wh;
    signed char a, c;
    int haverom = 0;
    int redraw = 1;
    int selectit = 0;
	float mag = 0;
	float mag2 = 0;
	u16 ang = 0;
	u16 ang2 = 0;
	int scroll_delay = 0;
	bool move_selection = 0;
	#define SCROLL_INITIAL_DELAY	15
	#define SCROLL_LOOP_DELAY		4
    
    while (haverom == 0)    
    {
        if (redraw)
            ShowFiles (offset, selection);
        redraw = 0;

		VIDEO_WaitVSync();	// slow things down a bit so we don't overread the pads
		
        p = PAD_ButtonsDown (0);
		ph = PAD_ButtonsHeld (0);
#ifdef HW_RVL
		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;
#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) ) return 0;
		
		/*** Check buttons, perform actions ***/
        if ( (p & PAD_BUTTON_A) || selectit || (wp & (WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A)) )
        {
            if ( selectit )
                selectit = 0;
            if (filelist[selection].flags)                        /*** This is directory ***/
            {
                if (loadtype == LOAD_SDC || loadtype == LOAD_USB)
                {
                    /* memorize last entries list, actual root directory and selection for next access */
					if (loadtype == LOAD_SDC)
						haveSDdir = 1;
					else
						haveUSBdir = 1;
                    
                    /* update current directory and set new entry list if directory has changed */
                    int status = updateFATdirname();
                    if (status == 1)	// ok, open directory
                    {
                        maxfiles = parseFATdirectory();
                        if (!maxfiles)
                        {
                            WaitPrompt ((char*) "Error reading directory !");
                            haverom   = 1; // quit SD menu
                            if (loadtype == LOAD_SDC)  // reset everything at next access
								haveSDdir = 0;
							else
								haveUSBdir = 0;
                        }
                    }
                    else if (status == -1)	// directory name too long
                    {
                        haverom   = 1; // quit SD menu
                        if (loadtype == LOAD_SDC)  // reset everything at next access
							haveSDdir = 0;
						else
							haveUSBdir = 0;
                    }
                }
                else
                {
                    if ( (strcmp (filelist[selection].filename, "..") == 0)
                        &&  ((unsigned int)rootdir == filelist[selection].offset) )
                        return 0;
                    else
                    {
                        rootdir = filelist[selection].offset;
                        rootdirlength = filelist[selection].length;
                        offset = selection = 0;
                        maxfiles = parsedirectory ();
                    }
                }
            }
            else	// this is a file
            {
                rootdir = filelist[selection].offset;
                rootdirlength = filelist[selection].length;
				
				/*** store the filename (used for sram/freeze naming) ***/
				strip_ext(filelist[selection].filename, Memory.ROMFilename);	// store stripped filename in Memory.ROMFilename
                
                switch (loadtype)
                {
                    case LOAD_DVD:
                        /*** Now load the DVD file to it's offset ***/
                        ARAM_ROMSIZE = LoadDVDFile (Memory.ROM);
                        break;
                    
                    case LOAD_SMB:
                        /*** Load from SMB ***/
                        ARAM_ROMSIZE = LoadSMBFile (filelist[selection].filename,
                             filelist[selection].length);
                        break;
                    
					case LOAD_USB:
                    case LOAD_SDC:
                        /*** Load from SD Card ***/
                        /* memorize last entries list, actual root directory and selection for next access */
                        haveSDdir = 1;
                        ARAM_ROMSIZE = LoadSDFile (filelist[selection].filename,
                                         filelist[selection].length);
                        break;
                }
                
                if (ARAM_ROMSIZE > 0)
                {
                    hasloaded = 1;
                    Memory.LoadROM ("BLANK.SMC");
                
                    Memory.LoadSRAM ("BLANK");
                    haverom = 1;
                    
                    return 1;
                }
                else
                {
                    WaitPrompt((char*) "Error loading ROM!");
                }
            }
            redraw = 1;
        }	// End of A
        if ( (p & PAD_BUTTON_B) || (wp & (WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B)) )
        {
            while ( (PAD_ButtonsDown(0) & PAD_BUTTON_B) 
#ifdef HW_RVL
					|| (WPAD_ButtonsDown(0) & (WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B)) 
#endif
					)
                VIDEO_WaitVSync();
            //if ((strcmp(filelist[1].filename,"..") == 0) && (strlen (filelist[0].filename) != 0))
			if ( strcmp(filelist[0].filename,"..") == 0 ) 
			{
				selection = 0;
				selectit = 1;
			}
			else if ( strcmp(filelist[1].filename,"..") == 0 ) 
			{
                selection = selectit = 1;
			} else {
                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 & PAD_BUTTON_DOWN) || (wp & (WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN)) ) { /*** Button just pressed ***/
				scroll_delay = SCROLL_INITIAL_DELAY;	// reset scroll delay.
				move_selection = 1;	//continue (move selection)
			} 
			else if (scroll_delay == 0) { 		/*** Button is held ***/
				scroll_delay = SCROLL_LOOP_DELAY;
				move_selection = 1;	//continue (move selection)
			} else {
				scroll_delay--;	// wait
			}
				
			if (move_selection)
			{
	            selection++;
	            if (selection == maxfiles)
	                selection = offset = 0;
	            if ((selection - offset) >= PAGESIZE)
	                offset += PAGESIZE;
	            redraw = 1;
				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 & PAD_BUTTON_UP) || (wp & (WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP)) ) { /*** Button just pressed***/
				scroll_delay = SCROLL_INITIAL_DELAY;	// reset scroll delay.
				move_selection = 1;	//continue (move selection)
			} 
			else if (scroll_delay == 0) { 		/*** Button is held ***/
				scroll_delay = SCROLL_LOOP_DELAY;
				move_selection = 1;	//continue (move selection)
			} else {
				scroll_delay--;	// wait
			}
			
			if (move_selection)
			{
	            selection--;
	            if (selection < 0) {
	                selection = maxfiles - 1;
	                offset = selection - PAGESIZE + 1;
	            }
	            if (selection < offset)
	                offset -= PAGESIZE;
	            if (offset < 0)
	                offset = 0;
	            redraw = 1;
				move_selection = 0;
			}
        }	// End of Up
        if ( (p & PAD_BUTTON_LEFT) || (wp & (WPAD_BUTTON_LEFT | WPAD_CLASSIC_BUTTON_LEFT)) )
        {
            /*** Go back a page ***/
            selection -= PAGESIZE;
            if (selection < 0)
            {
                selection = maxfiles - 1;
                offset = selection - PAGESIZE + 1;
            }
            if (selection < offset)
                offset -= PAGESIZE;
            if (offset < 0)
                offset = 0;
            redraw = 1;
        }
        if ( (p & PAD_BUTTON_RIGHT) || (wp & (WPAD_BUTTON_RIGHT | WPAD_CLASSIC_BUTTON_RIGHT)) )
        {
            /*** Go forward a page ***/
            selection += PAGESIZE;
            if (selection > maxfiles - 1)
                selection = offset = 0;
            if ((selection - offset) >= PAGESIZE)
                offset += PAGESIZE;
            redraw = 1;
        }
    }
    return 0;
}
Example #26
0
void CheatMenu()
{
	int ret = -1;
	int oldmenu = menu;
	menu = 0;

	int selection = 0;
	int offset = 0;
	int redraw = 1;
	int selectit = 0;

    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
	#define SCROLL_LOOP_DELAY		2

	if(Cheat.num_cheats > 0)
	{
		cheatmenuCount = Cheat.num_cheats + 1;

		for(uint16 i=0; i < Cheat.num_cheats; i++)
			sprintf (cheatmenu[i], "%s", Cheat.c[i].name);

		sprintf (cheatmenu[cheatmenuCount-1], "Back to Game Menu");

		while(ret != cheatmenuCount-1)
		{
			if(ret >= 0)
			{
				if(Cheat.c[ret].enabled)
					S9xDisableCheat(ret);
				else
					S9xEnableCheat(ret);

				ret = -1;
			}

			for(uint16 i=0; i < Cheat.num_cheats; i++)
				sprintf (cheatmenuvalue[i], "%s", Cheat.c[i].enabled == true ? "ON" : "OFF");

			if (redraw)
			    ShowCheats (cheatmenu, cheatmenuvalue, cheatmenuCount, offset, selection);

			redraw = 0;

			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);
			#endif

			/*** Check for exit combo ***/
			if ( (gc_sx < -70) || (wm_sx < -70) || (wp & WPAD_BUTTON_HOME) || (wp & WPAD_CLASSIC_BUTTON_HOME) )
				break;

			if ( (p & PAD_BUTTON_B) || (wp & (WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B)) )
				break;

			/*** Check buttons, perform actions ***/
			if ( (p & PAD_BUTTON_A) || selectit || (wp & (WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A)) )
			{
				if ( selectit )
					selectit = 0;

				redraw = 1;
				ret = selection;
			}	// End of A

			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.
					move_selection = 1;	//continue (move selection)
				}
				else if (scroll_delay == 0) { 		/*** Button is held ***/
					scroll_delay = SCROLL_LOOP_DELAY;
					move_selection = 1;	//continue (move selection)
				} else {
					scroll_delay--;	// wait
				}

				if (move_selection)
				{
					selection++;
					if (selection == cheatmenuCount)
						selection = offset = 0;
					if ((selection - offset) >= PAGESIZE)
						offset += PAGESIZE;
					redraw = 1;
					move_selection = 0;
				}
			}	// End of down
			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.
					move_selection = 1;	//continue (move selection)
				}
				else if (scroll_delay == 0) { 		/*** Button is held ***/
					scroll_delay = SCROLL_LOOP_DELAY;
					move_selection = 1;	//continue (move selection)
				} else {
					scroll_delay--;	// wait
				}

				if (move_selection)
				{
					selection--;
					if (selection < 0) {
						selection = cheatmenuCount - 1;
						offset = selection - PAGESIZE + 1;
					}
					if (selection < offset)
						offset -= PAGESIZE;
					if (offset < 0)
						offset = 0;
					redraw = 1;
					move_selection = 0;
				}
			}	// End of Up
			if ( (p & PAD_BUTTON_LEFT) || (wp & (WPAD_BUTTON_LEFT | WPAD_CLASSIC_BUTTON_LEFT)) )
			{
				/*** Go back a page ***/
				selection -= PAGESIZE;
				if (selection < 0)
				{
					selection = cheatmenuCount - 1;
					offset = selection - PAGESIZE + 1;
				}
				if (selection < offset)
					offset -= PAGESIZE;
				if (offset < 0)
					offset = 0;
				redraw = 1;
			}
			if ( (p & PAD_BUTTON_RIGHT) || (wp & (WPAD_BUTTON_RIGHT | WPAD_CLASSIC_BUTTON_RIGHT)) )
			{
				/*** Go forward a page ***/
				selection += PAGESIZE;
				if (selection > cheatmenuCount - 1)
					selection = offset = 0;
				if ((selection - offset) >= PAGESIZE)
					offset += PAGESIZE;
				redraw = 1;
			}
		}
	}
	else
	{
		WaitPrompt((char*)"No cheats found!");
	}
	menu = oldmenu;
}
Example #27
0
/****************************************************************************
 * FileSelector
 *
 * Let user select a file from the listing
 ***************************************************************************/
int FileSelector (int method)
{
    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;

	int scroll_delay = 0;
	bool move_selection = 0;
	#define SCROLL_INITIAL_DELAY	15
	#define SCROLL_LOOP_DELAY		2

    while (haverom == 0)
    {
        if (redraw)
            ShowFiles (filelist, maxfiles, offset, selection);
        redraw = 0;

		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_Stick (0, 0, 0);
		wm_sx = WPAD_Stick (0, 1, 1);

		wp = WPAD_ButtonsDown (0);
		wh = WPAD_ButtonsHeld (0);
#endif

		/*** Check for exit combo ***/
		if ( (gc_sx < -70) || (wm_sx < -70) || (wp & WPAD_BUTTON_HOME) || (wp & WPAD_CLASSIC_BUTTON_HOME) )
			return 0;

		/*** Check buttons, perform actions ***/
		if ( (p & PAD_BUTTON_A) || selectit || (wp & (WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A)) )
		{
			if ( selectit )
				selectit = 0;
			if (filelist[selection].flags) // This is directory
			{
				/* update current directory and set new entry list if directory has changed */
				int status;

				if(inSz && selection == 0) // inside a 7z, requesting to leave
				{
					if(method == METHOD_DVD)
					{
						// go to directory the 7z was in
						dvddir = filelist[0].offset;
						dvddirlength = filelist[0].length;
					}
					inSz = false;
					status = 1;
					SzClose();
				}
				else
				{
					status = UpdateDirName(method);
				}

				if (status == 1) // ok, open directory
				{
					switch (method)
					{
						case METHOD_SD:
						case METHOD_USB:
						maxfiles = ParseFATdirectory(method);
						break;

						case METHOD_DVD:
						maxfiles = ParseDVDdirectory();
						break;

						case METHOD_SMB:
						maxfiles = ParseSMBdirectory();
						break;
					}

					if (!maxfiles)
					{
						WaitPrompt ((char*) "Error reading directory !");
						haverom = 1; // quit menu
					}
				}
				else if (status == -1)	// directory name too long
				{
					haverom = 1; // quit menu
				}
			}
			else	// this is a file
			{
				// 7z file - let's open it up to select a file inside
				if(IsSz())
				{
					// we'll store the 7z filepath for extraction later
					if(!MakeROMPath(szpath, method))
					{
						WaitPrompt((char*) "Maximum filepath length reached!");
						return -1;
					}
					int szfiles = SzParse(szpath, method);
					if(szfiles)
					{
						maxfiles = szfiles;
						inSz = true;
					}
					else
						WaitPrompt((char*) "Error opening archive!");
				}
				else
				{
					// store the filename (w/o ext) - used for sram/freeze naming
					StripExt(ROMFilename, filelist[selection].filename);

					ShowAction ((char *)"Loading...");

					ROMLoaded = LoadVBAROM(method);
					inSz = false;

					if (ROMLoaded)
					{
						return 1;
					}
					else
					{
						WaitPrompt((char*) "Error loading ROM!");
					}
				}
			}
			redraw = 1;
		}	// End of A
        if ( (p & PAD_BUTTON_B) || (wp & (WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B)) )
        {
            while ( (PAD_ButtonsDown(0) & PAD_BUTTON_B)
#ifdef HW_RVL
					|| (WPAD_ButtonsDown(0) & (WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B))
#endif
					)
                VIDEO_WaitVSync();
			if ( strcmp(filelist[0].filename,"..") == 0 )
			{
				selection = 0;
				selectit = 1;
			}
			else if ( strcmp(filelist[1].filename,"..") == 0 )
			{
                selection = selectit = 1;
			} else {
                return 0;
			}
        }	// End of B
        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.
				move_selection = 1;	//continue (move selection)
			}
			else if (scroll_delay == 0) { 		/*** Button is held ***/
				scroll_delay = SCROLL_LOOP_DELAY;
				move_selection = 1;	//continue (move selection)
			} else {
				scroll_delay--;	// wait
			}

			if (move_selection)
			{
	            selection++;
	            if (selection == maxfiles)
	                selection = offset = 0;
	            if ((selection - offset) >= PAGESIZE)
	                offset += PAGESIZE;
	            redraw = 1;
				move_selection = 0;
			}
        }	// End of down
        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.
				move_selection = 1;	//continue (move selection)
			}
			else if (scroll_delay == 0) { 		/*** Button is held ***/
				scroll_delay = SCROLL_LOOP_DELAY;
				move_selection = 1;	//continue (move selection)
			} else {
				scroll_delay--;	// wait
			}

			if (move_selection)
			{
	            selection--;
	            if (selection < 0) {
	                selection = maxfiles - 1;
	                offset = selection - PAGESIZE + 1;
	            }
	            if (selection < offset)
	                offset -= PAGESIZE;
	            if (offset < 0)
	                offset = 0;
	            redraw = 1;
				move_selection = 0;
			}
        }	// End of Up
        if ( (p & PAD_BUTTON_LEFT) || (wp & (WPAD_BUTTON_LEFT | WPAD_CLASSIC_BUTTON_LEFT)) )
        {
            /*** Go back a page ***/
            selection -= PAGESIZE;
            if (selection < 0)
            {
                selection = maxfiles - 1;
                offset = selection - PAGESIZE + 1;
            }
            if (selection < offset)
                offset -= PAGESIZE;
            if (offset < 0)
                offset = 0;
            redraw = 1;
        }
        if ( (p & PAD_BUTTON_RIGHT) || (wp & (WPAD_BUTTON_RIGHT | WPAD_CLASSIC_BUTTON_RIGHT)) )
        {
            /*** Go forward a page ***/
            selection += PAGESIZE;
            if (selection > maxfiles - 1)
                selection = offset = 0;
            if ((selection - offset) >= PAGESIZE)
                offset += PAGESIZE;
            redraw = 1;
        }
    }
    return 0;
}
Example #28
0
/****************************************************************************
 * FileSelector
 *
 * Let user select a file from the listing
****************************************************************************/
int FileSelector (int method)
{
    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;

	int scroll_delay = 0;
	bool move_selection = 0;
	#define SCROLL_INITIAL_DELAY	15
	#define SCROLL_LOOP_DELAY		2

    while (haverom == 0)
    {
        if (redraw)
            ShowFiles (filelist, maxfiles, offset, selection);
        redraw = 0;

		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);
#endif

		/*** Check for exit combo ***/
		if ( (gc_sx < -70) || (wm_sx < -70) || (wp & WPAD_BUTTON_HOME) || (wp & WPAD_CLASSIC_BUTTON_HOME) )
			return 0;

		/*** Check buttons, perform actions ***/
		if ( (p & PAD_BUTTON_A) || selectit || (wp & (WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A)) )
		{
			if ( selectit )
				selectit = 0;
			if (filelist[selection].flags) // This is directory
			{
				/* update current directory and set new entry list if directory has changed */
				int status = UpdateDirName(method);
				if (status == 1) // ok, open directory
				{
					switch (method)
					{
						case METHOD_SD:
						case METHOD_USB:
						maxfiles = ParseFATdirectory(method);
						break;

						case METHOD_DVD:
						maxfiles = ParseDVDdirectory();
						break;

						case METHOD_SMB:
						maxfiles = ParseSMBdirectory();
						break;
					}

					if (!maxfiles)
					{
						WaitPrompt ((char*) "Error reading directory !");
						haverom = 1; // quit menu
					}
				}
				else if (status == -1)	// directory name too long
				{
					haverom = 1; // quit menu
				}
			}
			else	// this is a file
			{
				// store the filename (w/o ext) - used for state saving
				StripExt(romFilename, filelist[selection].filename);

				ShowAction ((char *)"Loading...");

				switch (method)
				{
					case METHOD_SD:
					case METHOD_USB:
					LoadFATFile (filelist[selection].filename,
					 filelist[selection].length);
					break;

					case METHOD_DVD:
					dvddir = filelist[selection].offset;
					dvddirlength = filelist[selection].length;
					LoadDVDFile (nesromptr);
					break;

					case METHOD_SMB:
					LoadSMBFile (filelist[selection].filename,
					filelist[selection].length);
					break;
				}

				if (GCMemROM() >= 0)
				{
					//hasloaded = 1; // indicator for memmap.cpp
					//Memory.LoadROM ("BLANK.SMC");
					//Memory.LoadSRAM ("BLANK");
					//haverom = 1;
					return 1;
				}
				else
				{
					WaitPrompt((char*) "Error loading ROM!");
				}
			}
			redraw = 1;
		}	// End of A
        if ( (p & PAD_BUTTON_B) || (wp & (WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B)) )
        {
            while ( (PAD_ButtonsDown(0) & PAD_BUTTON_B)
#ifdef HW_RVL
					|| (WPAD_ButtonsDown(0) & (WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B))
#endif
					)
                VIDEO_WaitVSync();
			if ( strcmp(filelist[0].filename,"..") == 0 )
			{
				selection = 0;
				selectit = 1;
			}
			else if ( strcmp(filelist[1].filename,"..") == 0 )
			{
                selection = selectit = 1;
			} else {
                return 0;
			}
        }	// End of B
        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.
				move_selection = 1;	//continue (move selection)
			}
			else if (scroll_delay == 0) { 		/*** Button is held ***/
				scroll_delay = SCROLL_LOOP_DELAY;
				move_selection = 1;	//continue (move selection)
			} else {
				scroll_delay--;	// wait
			}

			if (move_selection)
			{
	            selection++;
	            if (selection == maxfiles)
	                selection = offset = 0;
	            if ((selection - offset) >= PAGESIZE)
	                offset += PAGESIZE;
	            redraw = 1;
				move_selection = 0;
			}
        }	// End of down
        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.
				move_selection = 1;	//continue (move selection)
			}
			else if (scroll_delay == 0) { 		/*** Button is held ***/
				scroll_delay = SCROLL_LOOP_DELAY;
				move_selection = 1;	//continue (move selection)
			} else {
				scroll_delay--;	// wait
			}

			if (move_selection)
			{
	            selection--;
	            if (selection < 0) {
	                selection = maxfiles - 1;
	                offset = selection - PAGESIZE + 1;
	            }
	            if (selection < offset)
	                offset -= PAGESIZE;
	            if (offset < 0)
	                offset = 0;
	            redraw = 1;
				move_selection = 0;
			}
        }	// End of Up
        if ( (p & PAD_BUTTON_LEFT) || (wp & (WPAD_BUTTON_LEFT | WPAD_CLASSIC_BUTTON_LEFT)) )
        {
            /*** Go back a page ***/
            selection -= PAGESIZE;
            if (selection < 0)
            {
                selection = maxfiles - 1;
                offset = selection - PAGESIZE + 1;
            }
            if (selection < offset)
                offset -= PAGESIZE;
            if (offset < 0)
                offset = 0;
            redraw = 1;
        }
        if ( (p & PAD_BUTTON_RIGHT) || (wp & (WPAD_BUTTON_RIGHT | WPAD_CLASSIC_BUTTON_RIGHT)) )
        {
            /*** Go forward a page ***/
            selection += PAGESIZE;
            if (selection > maxfiles - 1)
                selection = offset = 0;
            if ((selection - offset) >= PAGESIZE)
                offset += PAGESIZE;
            redraw = 1;
        }
    }
    return 0;
}
Example #29
0
static int _GetKeys(int Control, BUTTONS * Keys, controller_config_t* config)
{
    if(padNeedScan) {
        gc_connected = PAD_ScanPads();
        padNeedScan = 0;
    }
    BUTTONS* c = Keys;
    memset(c, 0, sizeof(BUTTONS));
    //Reset buttons & sticks
    c->btns.All = 0xFFFF;
    c->leftStickX = c->leftStickY = c->rightStickX = c->rightStickY = 128;

    controller_GC.available[Control] = (gc_connected & (1<<Control)) ? 1 : 0;
    if (!controller_GC.available[Control]) return 0;

    unsigned int b = getButtons(Control);
    inline int isHeld(button_tp button) {
        return (b & button->mask) == button->mask ? 0 : 1;
    }

    c->btns.SQUARE_BUTTON    = isHeld(config->SQU);
    c->btns.CROSS_BUTTON     = isHeld(config->CRO);
    c->btns.CIRCLE_BUTTON    = isHeld(config->CIR);
    c->btns.TRIANGLE_BUTTON  = isHeld(config->TRI);

    c->btns.R1_BUTTON    = isHeld(config->R1);
    c->btns.L1_BUTTON    = isHeld(config->L1);
    c->btns.R2_BUTTON    = isHeld(config->R2);
    c->btns.L2_BUTTON    = isHeld(config->L2);

    c->btns.L_DPAD       = isHeld(config->DL);
    c->btns.R_DPAD       = isHeld(config->DR);
    c->btns.U_DPAD       = isHeld(config->DU);
    c->btns.D_DPAD       = isHeld(config->DD);

    c->btns.START_BUTTON  = isHeld(config->START);
    c->btns.R3_BUTTON    = isHeld(config->R3);
    c->btns.L3_BUTTON    = isHeld(config->L3);
    c->btns.SELECT_BUTTON = isHeld(config->SELECT);

    //adjust values by 128 cause PSX sticks range 0-255 with a 128 center pos
    int stickX = 0, stickY = 0;
    if(config->analogL->mask == ANALOG_AS_ANALOG) {
        stickX = PAD_StickX(Control);
        stickY = PAD_StickY(Control);
    } else if(config->analogL->mask == C_STICK_AS_ANALOG) {
        stickX = PAD_SubStickX(Control);
        stickY = PAD_SubStickY(Control);
    }
    c->leftStickX = GCtoPSXAnalog(stickX);
    c->leftStickY = GCtoPSXAnalog(config->invertedYL ? stickY : -stickY);

    if(config->analogR->mask == ANALOG_AS_ANALOG) {
        stickX = PAD_StickX(Control);
        stickY = PAD_StickY(Control);
    } else if(config->analogR->mask == C_STICK_AS_ANALOG) {
        stickX = PAD_SubStickX(Control);
        stickY = PAD_SubStickY(Control);
    }
    c->rightStickX = GCtoPSXAnalog(stickX);
    c->rightStickY = GCtoPSXAnalog(config->invertedYR ? stickY : -stickY);

    // Return 1 if whether the exit button(s) are pressed
    return isHeld(config->exit) ? 0 : 1;
}