/**************************************************************************** * 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); } }
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); } }
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 }
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; }
/**************************************************************************** * 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); } }
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; }
/**************************************************************************** * 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); } }
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); } }
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; }
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); }
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); }
/* * 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_Down(void) { for(int chan = WPAD_MAX_WIIMOTES-1; chan >= 0; chan--) { if((RIGHT_STICK_ANG_DOWN && right_stick_mag[chan] > 0.15 && right_stick_skip[chan] == 0) || PAD_SubStickY(chan) < -20 || WUPC_rStickY(chan) < -160) return true; } return false; }
//--------------------------------------------------------------------------------- int main( int argc, char **argv ){ //--------------------------------------------------------------------------------- f32 yscale; u32 xfbHeight; // various matrices for things like view Mtx view,mv,mr; Mtx44 perspective; // the texure we're going to paint GXTexObj texture; TPLFile mudTPL; u32 fb = 0; // initial framebuffer index GXColor background = {0, 0, 0, 0xff}; // init the vi. VIDEO_Init(); rmode = VIDEO_GetPreferredMode(NULL); WPAD_Init(); // allocate 2 framebuffers for double buffering frameBuffer[0] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); frameBuffer[1] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); // configure video and wait for the screen to blank VIDEO_Configure(rmode); VIDEO_SetNextFramebuffer(frameBuffer[fb]); VIDEO_SetBlack(FALSE); VIDEO_Flush(); VIDEO_WaitVSync(); if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); // setup the fifo... void *gp_fifo = NULL; gp_fifo = memalign(32,DEFAULT_FIFO_SIZE); memset(gp_fifo,0,DEFAULT_FIFO_SIZE); // ...then init the flipper GX_Init(gp_fifo,DEFAULT_FIFO_SIZE); // clears the bg to color and clears the z buffer GX_SetCopyClear(background, 0x00ffffff); // other gx setup GX_SetViewport(0,0,rmode->fbWidth,rmode->efbHeight,0,1); yscale = GX_GetYScaleFactor(rmode->efbHeight,rmode->xfbHeight); xfbHeight = GX_SetDispCopyYScale(yscale); GX_SetScissor(0,0,rmode->fbWidth,rmode->efbHeight); GX_SetDispCopySrc(0,0,rmode->fbWidth,rmode->efbHeight); GX_SetDispCopyDst(rmode->fbWidth,xfbHeight); GX_SetCopyFilter(rmode->aa,rmode->sample_pattern,GX_TRUE,rmode->vfilter); GX_SetFieldMode(rmode->field_rendering,((rmode->viHeight==2*rmode->xfbHeight)?GX_ENABLE:GX_DISABLE)); if (rmode->aa) GX_SetPixelFmt(GX_PF_RGB565_Z16, GX_ZC_LINEAR); else GX_SetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR); GX_SetCullMode(GX_CULL_NONE); GX_CopyDisp(frameBuffer[fb],GX_TRUE); GX_SetDispCopyGamma(GX_GM_1_0); // setup the vertex attribute table // describes the data // args: vat location 0-7, type of data, data format, size, scale // so for ex. in the first call we are sending position data with // 3 values X,Y,Z of size F32. scale sets the number of fractional // bits for non float data. GX_InvVtxCache(); GX_ClearVtxDesc(); GX_SetVtxDesc(GX_VA_POS, GX_DIRECT); GX_SetVtxDesc(GX_VA_NRM, GX_DIRECT); GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT); GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0); GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_NRM, GX_NRM_XYZ, GX_F32, 0); GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0); // setup texture coordinate generation // args: texcoord slot 0-7, matrix type, source to generate texture coordinates from, matrix to use GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX3x4, GX_TG_TEX0, GX_IDENTITY); f32 w = rmode->viWidth; f32 h = rmode->viHeight; guLightPerspective(mv,45, (f32)w/h, 1.05F, 1.0F, 0.0F, 0.0F); guMtxTrans(mr, 0.0F, 0.0F, -1.0F); guMtxConcat(mv, mr, mv); GX_LoadTexMtxImm(mv, GX_TEXMTX0, GX_MTX3x4); GX_InvalidateTexAll(); TPL_OpenTPLFromMemory(&mudTPL, (void *)mud_tpl,mud_tpl_size); TPL_GetTexture(&mudTPL,mud,&texture); // setup our camera at the origin // looking down the -z axis with y up guVector cam = {0.0F, 0.0F, 0.0F}, up = {0.0F, 1.0F, 0.0F}, look = {0.0F, 0.0F, -1.0F}; guLookAt(view, &cam, &up, &look); // setup our projection matrix // this creates a perspective matrix with a view angle of 90, // and aspect ratio based on the display resolution guPerspective(perspective, 45, (f32)w/h, 0.1F, 300.0F); GX_LoadProjectionMtx(perspective, GX_PERSPECTIVE); // get the room ready to render SetupWorld(); while(1) { WPAD_ScanPads(); s8 tpad = PAD_StickX(0); // Rotate left or right. if ((tpad < -8) || (tpad > 8)) yrot -= (float)tpad / 50.f; // NOTE: walkbiasangle = head bob tpad = PAD_StickY(0); // Go forward. if(tpad > 50) { xpos -= (float)sin(DegToRad(yrot)) * 0.05f; // Move on the x-plane based on player direction zpos -= (float)cos(DegToRad(yrot)) * 0.05f; // Move on the z-plane based on player direction if (walkbiasangle >= 359.0f) walkbiasangle = 0.0f; // Bring walkbiasangle back around else walkbiasangle += 10; // if walkbiasangle < 359 increase it by 10 walkbias = (float)sin(DegToRad(walkbiasangle))/20.0f; } // Go backward if(tpad < -50) { xpos += (float)sin(DegToRad(yrot)) * 0.05f; zpos += (float)cos(DegToRad(yrot)) * 0.05f; if (walkbiasangle <= 1.0f) walkbiasangle = 359.0f; else walkbiasangle -= 10; walkbias = (float)sin(DegToRad(walkbiasangle))/20.0f; } tpad = PAD_SubStickY(0); // Tilt up/down if (((tpad > 8) || (tpad < -8)) && ((90 >= lookupdown) && (lookupdown >= -90))) { zdepth -= ((f32)tpad * 0.01f); lookupdown -= ((f32)tpad * 0.01f); if (lookupdown > 90) lookupdown = 90.0F; if (lookupdown < -90) lookupdown = -90.0F; } if ( PAD_ButtonsDown(0) & PAD_BUTTON_START) { exit(0); } // do this before drawing GX_SetViewport(0,0,rmode->fbWidth,rmode->efbHeight,0,1); //set number of textures to generate GX_SetNumTexGens(1); // Draw things DrawScene(view,texture); GX_SetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE); GX_SetColorUpdate(GX_TRUE); GX_CopyDisp(frameBuffer[fb],GX_TRUE); // do this stuff after drawing GX_DrawDone(); fb ^= 1; // flip framebuffer VIDEO_SetNextFramebuffer(frameBuffer[fb]); VIDEO_Flush(); VIDEO_WaitVSync(); } return 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); }
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; }
/* 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; }
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); }
// 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; } }
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); }
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; } } }
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; }