void FPAD_Update( void ) { if (WPAD_ScanPads() > WPAD_ERR_NONE) { WPAD_Pressed = WPAD_ButtonsDown(0) | WPAD_ButtonsDown(1) | WPAD_ButtonsDown(2) | WPAD_ButtonsDown(3); WPAD_Pressed |= WPAD_ButtonsHeld(0) | WPAD_ButtonsHeld(1) | WPAD_ButtonsHeld(2) | WPAD_ButtonsHeld(3); } else { // No Wii remotes are connected WPAD_Pressed = 0; } if (PAD_ScanPads() > PAD_ERR_NONE) { PAD_Pressed = PAD_ButtonsDown(0) | PAD_ButtonsDown(1) | PAD_ButtonsDown(2) | PAD_ButtonsDown(3); PAD_Pressed |= PAD_ButtonsHeld(0) | PAD_ButtonsHeld(1) | PAD_ButtonsHeld(2) | PAD_ButtonsHeld(3); PAD_Stick_Y = PAD_StickY(0) | PAD_StickY(1) | PAD_StickY(2) | PAD_StickY(3); PAD_Stick_X = PAD_StickX(0) | PAD_StickX(1) | PAD_StickX(2) | PAD_StickX(3); } else { // No GC controllers are connected PAD_Pressed = 0; PAD_Stick_Y = 0; PAD_Stick_X = 0; } if( WPAD_Pressed == 0 && PAD_Pressed == 0 && ( PAD_Stick_Y < 25 && PAD_Stick_Y > -25 ) && ( PAD_Stick_X < 25 && PAD_Stick_X > -25 ) ) { SLock = false; SpeedX= DELAY_START; } }
void CMenu::LeftStick() { u8 speed = 0, pSpeed = 0; for(int chan = WPAD_MAX_WIIMOTES-1; chan >= 0; chan--) { if(left_stick_mag[chan] > 0.15 || abs(PAD_StickX(chan)) > 20 || abs(PAD_StickY(chan)) > 20 || (chan == 0 && (abs(DS3_StickX()) > 20 || abs(DS3_StickY()) > 20)) || abs(WUPC_lStickX(chan)) > 160 || abs(WUPC_lStickY(chan)) > 160) { m_show_pointer[chan] = true; if(LEFT_STICK_LEFT) { speed = (u8)(left_stick_mag[chan] * 10.00); pSpeed = (u8)((abs(PAD_StickX(chan))/10)|(abs(DS3_StickX()/10))|(abs(WUPC_lStickX(chan))/80)); if(stickPointer_x[chan] > m_cursor[chan].width()/2) stickPointer_x[chan] = stickPointer_x[chan]-speed-pSpeed; pointerhidedelay[chan] = 150; } if(LEFT_STICK_DOWN) { speed = (u8)(left_stick_mag[chan] * 10.00); pSpeed = (u8)((abs(PAD_StickY(chan))/10)|(abs(DS3_StickY()/10))|(abs(WUPC_lStickY(chan))/80)); if(stickPointer_y[chan] < (m_vid.height() + (m_cursor[chan].height()/2))) stickPointer_y[chan] = stickPointer_y[chan]+speed+pSpeed; pointerhidedelay[chan] = 150; } if(LEFT_STICK_RIGHT) { speed = (u8)(left_stick_mag[chan] * 10.00); pSpeed = (u8)((abs(PAD_StickX(chan))/10)|(abs(DS3_StickX()/10))|(abs(WUPC_lStickX(chan))/80)); if(stickPointer_x[chan] < (m_vid.width() + (m_cursor[chan].width()/2))) stickPointer_x[chan] = stickPointer_x[chan]+speed+pSpeed; pointerhidedelay[chan] = 150; } if(LEFT_STICK_UP) { speed = (u8)(left_stick_mag[chan] * 10.00); pSpeed = (u8)((abs(PAD_StickY(chan))/10)|(abs(DS3_StickY()/10))|(abs(WUPC_lStickY(chan))/80)); if(stickPointer_y[chan] > m_cursor[chan].height()/2) stickPointer_y[chan] = stickPointer_y[chan]-speed-pSpeed; pointerhidedelay[chan] = 150; } } else { if(pointerhidedelay[chan] > 0 && !wii_btnsHeld[chan] && !wii_btnsPressed[chan] && !gc_btnsHeld && !gc_btnsPressed) pointerhidedelay[chan]--; } if (pointerhidedelay[chan] == 0) m_show_pointer[chan] = false; } }
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 }
void UpdateCursorPosition (int pad, int &pos_x, int &pos_y) { #define SCOPEPADCAL 20 // gc left joystick signed char pad_x = PAD_StickX (pad); signed char pad_y = PAD_StickY (pad); if (pad_x > SCOPEPADCAL){ pos_x += (pad_x*1.0)/SCOPEPADCAL; if (pos_x > 256) pos_x = 256; } if (pad_x < -SCOPEPADCAL){ pos_x -= (pad_x*-1.0)/SCOPEPADCAL; if (pos_x < 0) pos_x = 0; } if (pad_y < -SCOPEPADCAL){ pos_y += (pad_y*-1.0)/SCOPEPADCAL; if (pos_y > 224) pos_y = 224; } if (pad_y > SCOPEPADCAL){ pos_y -= (pad_y*1.0)/SCOPEPADCAL; if (pos_y < 0) pos_y = 0; } #ifdef HW_RVL struct ir_t ir; // wiimote ir WPAD_IR(pad, &ir); if (ir.valid) { pos_x = (ir.x * 256) / 640; pos_y = (ir.y * 224) / 480; } else { signed char wm_ax = WPAD_StickX (pad, 0); signed char wm_ay = WPAD_StickY (pad, 0); if (wm_ax > SCOPEPADCAL){ pos_x += (wm_ax*1.0)/SCOPEPADCAL; if (pos_x > 256) pos_x = 256; } if (wm_ax < -SCOPEPADCAL){ pos_x -= (wm_ax*-1.0)/SCOPEPADCAL; if (pos_x < 0) pos_x = 0; } if (wm_ay < -SCOPEPADCAL){ pos_y += (wm_ay*-1.0)/SCOPEPADCAL; if (pos_y > 224) pos_y = 224; } if (wm_ay > SCOPEPADCAL){ pos_y -= (wm_ay*1.0)/SCOPEPADCAL; if (pos_y < 0) pos_y = 0; } } #endif }
/**************************************************************************** * 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); } }
static void XenonInputUpdate() { for (int i = 0; i < MAX_INPUTS; i++) { old_ctrl[i] = ctrl[i]; usb_do_poll(); get_controller_data(&ctrl[i], i); } // update wpad for (int i = 0; i < MAX_INPUTS; i++) { wpad_xenon[i].btns_d = WPAD_ButtonsDown(i); wpad_xenon[i].btns_u = WPAD_ButtonsUp(i); wpad_xenon[i].btns_h = WPAD_ButtonsHeld(i); //float irx = (float)((float)PAD_StickX(i)/128.f); //float iry = (float)(-(float)PAD_StickY(i)/128.f)-0.5f; // float iry = 0.5f-((float)PAD_StickY(i)/128.f); float iry = 0.5f + ((float) -PAD_StickY(i) / 128.f); float irx = 0.5f + ((float) PAD_StickX(i) / 128.f); irx *= screenwidth; iry *= screenheight; wpad_xenon[i].ir.x = irx; wpad_xenon[i].ir.y = iry; wpad_xenon[i].ir.valid = 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); } }
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; }
bool CMenu::lStick_Left(void) { for(int chan = WPAD_MAX_WIIMOTES-1; chan >= 0; chan--) { if((LEFT_STICK_ANG_LEFT && left_stick_mag[chan] > 0.15) || PAD_StickX(chan) < -20 || DS3_StickX() < -20 || WUPC_lStickX(chan) < -160) return true; } return false; }
void IN_GCPadMainStickMove (usercmd_t *cmd) { int gx; int gy; PAD_ScanPads(); gx = PAD_StickX(0); gy = PAD_StickY(0); if((gx > -in_gcpadmovmin->value)&&(gx < in_gcpadmovmin->value)) gx = 0; if((gy > -in_gcpadmovmin->value)&&(gy < in_gcpadmovmin->value)) gy = 0; if((gx == 0)&&(gy == 0)) return; cmd->sidemove += m_side->value * gx * in_gcpadmovscale->value; cmd->forwardmove += m_forward->value * gy * in_gcpadmovscale->value; }
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_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); }
int grlib_GetUserInput (void) { u32 wbtn, gcbtn, cbtn; s8 gcX, gcY; int nX, nY; int cX, cY; static float g[MAXG]; static int gidx = -1; static u32 gestureDisable = 0; u32 ms = ticks_to_millisecs(gettime()); u32 mstout = ms+200; struct expansion_t e; //nunchuk if (gidx == -1) { memset (&g, 0, sizeof(g)); gidx = 0; } WPAD_ScanPads(); // Scan the Wiimotes wbtn = WPAD_ButtonsDown(0); if (grlibSettings.usesGestures && ms > gestureDisable) { WPADData *wp = WPAD_Data (0); g[gidx] = wp->gforce.x; /* int gidx2 = gidx - 10; int gidx3 = gidx - 20; if (gidx2 < 0) gidx2 = (MAXG-1) - gidx2; if (gidx3 < 0) gidx3 = (MAXG-1) - gidx3; if (g[gidx2] < -2.0 && g[gidx] > -1.5 && g[gidx3] > -1.5) { memset (&g, 0, sizeof(g)); return WPAD_BUTTON_MINUS; //Debug ("left"); } if (g[gidx2] > 2.0 && g[gidx] < 1.5 && g[gidx3] < 1.5) { memset (&g, 0, sizeof(g)); return WPAD_BUTTON_PLUS; //Debug ("right"); } */ int i; float mean = 0; for (i = 0; i < MAXG; i++) mean+=g[i]; mean /= (float) MAXG; // gprintf ("%.2f\n", mean); if (mean < -1.5) { memset (&g, 0, sizeof(g)); gestureDisable = ms+1000; return WPAD_BUTTON_MINUS; } if (mean > 1.5) { memset (&g, 0, sizeof(g)); gestureDisable = ms+1000; return WPAD_BUTTON_PLUS; } if (++gidx >= MAXG) gidx = 0; } //Debug ("wm = %.1f,%.1f,%.1f", wp->gforce.x,wp->gforce.y,wp->gforce.z); //Debug ("wm = %.1f,%.1f,%.1f", wp->orient.roll,wp->orient.pitch,wp->orient.yaw); WPAD_Expansion( 0, &e ); if (e.type != WPAD_EXP_NUNCHUK) { nX = 0; nY = 0; } else { nX = e.nunchuk.js.pos.x - e.nunchuk.js.center.x; nY = e.nunchuk.js.pos.y - e.nunchuk.js.center.y; } if (e.type != WPAD_EXP_CLASSIC) { cX = 0; cY = 0; cbtn = 0; } else { cX = e.classic.ljs.pos.x - e.classic.ljs.center.x; cY = e.classic.ljs.pos.y - e.classic.ljs.center.y; cbtn = e.classic.btns; } PAD_ScanPads(); gcX = PAD_StickX(0); gcY = PAD_StickY(0); gcbtn = PAD_ButtonsDown(0); // sticks if (abs (nX) > 10) {grlib_irPos.x += (nX / 16); grlibSettings.cursorActivity++;} if (abs (nY) > 10) {grlib_irPos.y -= (nY / 16); grlibSettings.cursorActivity++;} if (abs (gcX) > 10) {grlib_irPos.x += (gcX / 16); grlibSettings.cursorActivity++;} if (abs (gcY) > 10) {grlib_irPos.y -= (gcY / 16); grlibSettings.cursorActivity++;} if (abs (cX) > 10) {grlib_irPos.x += (cX / 4); grlibSettings.cursorActivity++;} if (abs (cY) > 10) {grlib_irPos.y -= (cY / 4); grlibSettings.cursorActivity++;} // Check limits if (grlib_irPos.x < 0) grlib_irPos.x = 0; if (grlib_irPos.x > 640) grlib_irPos.x = 640; if (grlib_irPos.y < 0) grlib_irPos.y = 0; if (grlib_irPos.y > 480) grlib_irPos.y = 480; // As usual wiimotes will have priority if (wbtn) { grlibSettings.buttonActivity ++; // Wait until button is released while (WPAD_ButtonsDown(0) && ticks_to_millisecs(gettime()) < mstout) WPAD_ScanPads(); return wbtn; } // Then gc if (gcbtn) { grlibSettings.buttonActivity ++; // Wait until button is released while (PAD_ButtonsDown(0) && ticks_to_millisecs(gettime()) < mstout) PAD_ScanPads(); // Convert to wiimote values if (gcbtn & PAD_TRIGGER_R) return WPAD_BUTTON_PLUS; if (gcbtn & PAD_TRIGGER_L) return WPAD_BUTTON_MINUS; if (gcbtn & PAD_BUTTON_A) return WPAD_BUTTON_A; if (gcbtn & PAD_BUTTON_B) return WPAD_BUTTON_B; if (gcbtn & PAD_BUTTON_X) return WPAD_BUTTON_1; if (gcbtn & PAD_BUTTON_Y) return WPAD_BUTTON_2; if (gcbtn & PAD_BUTTON_MENU) return WPAD_BUTTON_HOME; if (gcbtn & PAD_BUTTON_UP) return WPAD_BUTTON_UP; if (gcbtn & PAD_BUTTON_LEFT) return WPAD_BUTTON_LEFT; if (gcbtn & PAD_BUTTON_DOWN) return WPAD_BUTTON_DOWN; if (gcbtn & PAD_BUTTON_RIGHT) return WPAD_BUTTON_RIGHT; } // Classic if (cbtn) { grlibSettings.buttonActivity ++; while (e.classic.btns && ticks_to_millisecs(gettime()) < mstout) { WPAD_ScanPads(); // Scan the Wiimotes WPAD_Expansion( 0, &e ); } // Convert to wiimote values if (cbtn & CLASSIC_CTRL_BUTTON_ZR) return WPAD_BUTTON_PLUS; if (cbtn & CLASSIC_CTRL_BUTTON_ZL) return WPAD_BUTTON_MINUS; if (cbtn & CLASSIC_CTRL_BUTTON_PLUS) return WPAD_BUTTON_PLUS; if (cbtn & CLASSIC_CTRL_BUTTON_MINUS) return WPAD_BUTTON_MINUS; if (cbtn & CLASSIC_CTRL_BUTTON_A) return WPAD_BUTTON_A; if (cbtn & CLASSIC_CTRL_BUTTON_B) return WPAD_BUTTON_B; if (cbtn & CLASSIC_CTRL_BUTTON_X) return WPAD_BUTTON_1; if (cbtn & CLASSIC_CTRL_BUTTON_Y) return WPAD_BUTTON_2; if (cbtn & CLASSIC_CTRL_BUTTON_HOME) return WPAD_BUTTON_HOME; } return 0; }
void CMenu::ScanInput() { m_show_zone_main = false; m_show_zone_main2 = false; m_show_zone_main3 = false; m_show_zone_prev = false; m_show_zone_next = false; WUPC_UpdateButtonStats(); WPAD_ScanPads(); PAD_ScanPads(); DS3_ScanPads(); ButtonsPressed(); ButtonsHeld(); LeftStick(); for(int chan = WPAD_MAX_WIIMOTES-1; chan >= 0; chan--) { wd[chan] = WPAD_Data(chan); left_stick_angle[chan] = 0; left_stick_mag[chan] = 0; right_stick_angle[chan] = 0; right_stick_mag[chan] = 0; switch(wd[chan]->exp.type) { case WPAD_EXP_NUNCHUK: right_stick_mag[chan] = wd[chan]->exp.nunchuk.js.mag; right_stick_angle[chan] = wd[chan]->exp.nunchuk.js.ang; break; case WPAD_EXP_GUITARHERO3: left_stick_mag[chan] = wd[chan]->exp.nunchuk.js.mag; left_stick_angle[chan] = wd[chan]->exp.nunchuk.js.ang; break; case WPAD_EXP_CLASSIC: left_stick_mag[chan] = wd[chan]->exp.classic.ljs.mag; left_stick_angle[chan] = wd[chan]->exp.classic.ljs.ang; right_stick_mag[chan] = wd[chan]->exp.classic.rjs.mag; right_stick_angle[chan] = wd[chan]->exp.classic.rjs.ang; break; default: break; } if(enable_wmote_roll) { wmote_roll[chan] = wd[chan]->orient.roll; // Use wd[chan]->ir.angle if you only want this to work when pointing at the screen wmote_roll_skip[chan] = CalculateRepeatSpeed(wmote_roll[chan] / 45.f, wmote_roll_skip[chan]); } right_stick_skip[chan] = CalculateRepeatSpeed(right_stick_mag[chan], right_stick_skip[chan]); } for(int chan = WPAD_MAX_WIIMOTES-1; chan >= 0; chan--) { m_btnMgr.setRumble(chan, WPadIR_Valid(chan), PAD_StickX(chan) < -20 || PAD_StickX(chan) > 20 || PAD_StickY(chan) < -20 || PAD_StickY(chan) > 20, WUPC_lStickX(chan) < -160 || WUPC_lStickX(chan) > 160 || WUPC_lStickY(chan) < -160 || WUPC_lStickY(chan) > 160); m_btnMgr.setMouse(WPadIR_Valid(chan) || m_show_pointer[chan]); if(WPadIR_Valid(chan)) { m_cursor[chan].draw(wd[chan]->ir.x, wd[chan]->ir.y, wd[chan]->ir.angle); m_btnMgr.mouse(chan, wd[chan]->ir.x - m_cursor[chan].width() / 2, wd[chan]->ir.y - m_cursor[chan].height() / 2); } else if(m_show_pointer[chan]) { m_cursor[chan].draw(stickPointer_x[chan], stickPointer_y[chan], 0); m_btnMgr.mouse(chan, stickPointer_x[chan] - m_cursor[chan].width() / 2, stickPointer_y[chan] - m_cursor[chan].height() / 2); } } ShowMainZone(); ShowMainZone2(); ShowMainZone3(); ShowPrevZone(); ShowNextZone(); ShowGameZone(); }
/* * 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 ); } } }
static void pad_update(s8 num, u8 i) { /* get PAD status */ s8 x = PAD_StickX (num); s8 y = PAD_StickY (num); u16 p = PAD_ButtonsHeld(num); u8 sensitivity = 30; /* get current key config */ u16 pad_keymap[MAX_KEYS]; memcpy(pad_keymap, config.pad_keymap[num], MAX_KEYS * sizeof(u16)); /* SOFTRESET */ if ((p & PAD_TRIGGER_L) && (p & PAD_TRIGGER_Z)) { set_softreset(); } /* BUTTONS */ if (p & pad_keymap[KEY_BUTTONA]) input.pad[i] |= INPUT_A; if (p & pad_keymap[KEY_BUTTONB]) input.pad[i] |= INPUT_B; if (p & pad_keymap[KEY_BUTTONC]) input.pad[i] |= INPUT_C; if (p & pad_keymap[KEY_BUTTONX]) input.pad[i] |= INPUT_X; if (p & pad_keymap[KEY_BUTTONY]) input.pad[i] |= INPUT_Y; if (p & pad_keymap[KEY_BUTTONZ]) input.pad[i] |= INPUT_Z; /* MODE/START */ if ((p & PAD_BUTTON_START) && (p & PAD_TRIGGER_Z)) input.pad[i] |= INPUT_MODE; else if (p & pad_keymap[KEY_START]) input.pad[i] |= INPUT_START; /* MENU */ if (p & pad_keymap[KEY_MENU]) { ConfigRequested = 1; } /* LIGHTGUN screen position (x,y) */ if (input.dev[i] == DEVICE_LIGHTGUN) { input.analog[i-4][0] += x / sensitivity; input.analog[i-4][1] -= y / sensitivity; if (input.analog[i-4][0] < 0) input.analog[i-4][0] = 0; else if (input.analog[i-4][0] > bitmap.viewport.w) input.analog[i-4][0] = bitmap.viewport.w; if (input.analog[i-4][1] < 0) input.analog[i-4][1] = 0; else if (input.analog[i-4][1] > bitmap.viewport.h) input.analog[i-4][1] = bitmap.viewport.h; } /* PEN tablet position (x,y) */ else if ((system_hw == SYSTEM_PICO) && (i == 0)) { input.analog[0][0] += x / sensitivity; input.analog[0][1] -= y / sensitivity; if (input.analog[0][0] < 0x17c) input.analog[0][0] = 0x17c; else if (input.analog[0][0] > 0x3c) input.analog[0][0] = 0x3c; if (input.analog[0][1] < 0x1fc) input.analog[0][1] = 0x1fc; else if (input.analog[0][1] > 0x3f3) input.analog[0][1] = 0x3f3; } /* MOUSE quantity of movement (-256,256) */ else if (input.dev[i] == DEVICE_MOUSE) { input.analog[2][0] = (x / sensitivity) * 2; input.analog[2][1] = (y / sensitivity) * 2; if (config.invert_mouse) input.analog[2][1] = 0 - input.analog[2][1]; } /* GAMEPAD directional buttons */ else { if ((p & PAD_BUTTON_UP) || (y > sensitivity)) input.pad[i] |= INPUT_UP; else if ((p & PAD_BUTTON_DOWN) || (y < -sensitivity)) input.pad[i] |= INPUT_DOWN; if ((p & PAD_BUTTON_LEFT) || (x < -sensitivity)) input.pad[i] |= INPUT_LEFT; else if ((p & PAD_BUTTON_RIGHT) || (x > sensitivity)) input.pad[i] |= INPUT_RIGHT; } }
// 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; } }
u32 StandardMovement(unsigned short pad) { u32 J = 0; signed char pad_x = PAD_StickX (pad); signed char pad_y = PAD_StickY (pad); #ifdef HW_RVL signed char wm_ax = WPAD_Stick ((u8)pad, 0, 0); signed char wm_ay = WPAD_Stick ((u8)pad, 0, 1); #endif /*** Gamecube Joystick input, same as normal ***/ // 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; } } } // Turbo feature, keyboard or gamecube only if(DownUsbKeys[KB_SPACE]) J |= VBA_SPEED; // Capture feature if(DownUsbKeys[KB_PRTSC] | DownUsbKeys[KB_F12]) J |= VBA_CAPTURE; #endif return J; }
/* 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 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; }
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); }
void decodepad (int pad) { int i, offset; float t; signed char pad_x = PAD_StickX (pad); signed char pad_y = PAD_StickY (pad); u32 jp = PAD_ButtonsHeld (pad); #ifdef HW_RVL signed char wm_ax = 0; signed char wm_ay = 0; u32 wp = 0; wm_ax = WPAD_StickX ((u8)pad, 0); wm_ay = WPAD_StickY ((u8)pad, 0); wp = WPAD_ButtonsHeld (pad); u32 exp_type; if ( WPAD_Probe(pad, &exp_type) != 0 ) exp_type = WPAD_EXP_NONE; #endif /*** Gamecube Joystick input ***/ // Is XY inside the "zone"? if (pad_x * pad_x + pad_y * pad_y > PADCAL * PADCAL) { /*** we don't want division by zero ***/ if (pad_x > 0 && pad_y == 0) jp |= PAD_BUTTON_RIGHT; if (pad_x < 0 && pad_y == 0) jp |= PAD_BUTTON_LEFT; if (pad_x == 0 && pad_y > 0) jp |= PAD_BUTTON_UP; if (pad_x == 0 && pad_y < 0) jp |= PAD_BUTTON_DOWN; if (pad_x != 0 && pad_y != 0) { /*** Recalc left / right ***/ t = (float) pad_y / pad_x; if (t >= -2.41421356237 && t < 2.41421356237) { if (pad_x >= 0) jp |= PAD_BUTTON_RIGHT; else jp |= PAD_BUTTON_LEFT; } /*** Recalc up / down ***/ t = (float) pad_x / pad_y; if (t >= -2.41421356237 && t < 2.41421356237) { if (pad_y >= 0) jp |= PAD_BUTTON_UP; else jp |= PAD_BUTTON_DOWN; } } } #ifdef HW_RVL /*** Wii Joystick (classic, nunchuk) input ***/ // Is XY inside the "zone"? if (wm_ax * wm_ax + wm_ay * wm_ay > PADCAL * PADCAL) { /*** we don't want division by zero ***/ if (wm_ax > 0 && wm_ay == 0) wp |= WPAD_BUTTON_RIGHT | WPAD_CLASSIC_BUTTON_RIGHT; if (wm_ax < 0 && wm_ay == 0) wp |= WPAD_BUTTON_LEFT | WPAD_CLASSIC_BUTTON_LEFT; if (wm_ax == 0 && wm_ay > 0) wp |= WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP; if (wm_ax == 0 && wm_ay < 0) wp |= WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN; if (wm_ax != 0 && wm_ay != 0) { /*** Recalc left / right ***/ t = (float) wm_ay / wm_ax; if (t >= -2.41421356237 && t < 2.41421356237) { if (wm_ax >= 0) wp |= WPAD_BUTTON_RIGHT | WPAD_CLASSIC_BUTTON_RIGHT; else wp |= WPAD_BUTTON_LEFT | WPAD_CLASSIC_BUTTON_LEFT; } /*** Recalc up / down ***/ t = (float) wm_ax / wm_ay; if (t >= -2.41421356237 && t < 2.41421356237) { if (wm_ay >= 0) wp |= WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP; else wp |= WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN; } } } #endif /*** Fix offset to pad ***/ offset = ((pad + 1) << 4); /*** Report pressed buttons (gamepads) ***/ for (i = 0; i < MAXJP; i++) { if ( (jp & gcpadmap[i]) // gamecube controller #ifdef HW_RVL || ( (exp_type == WPAD_EXP_NONE) && (wp & wmpadmap[i]) ) // wiimote || ( (exp_type == WPAD_EXP_CLASSIC) && (wp & ccpadmap[i]) ) // classic controller || ( (exp_type == WPAD_EXP_NUNCHUK) && (wp & ncpadmap[i]) ) // nunchuk + wiimote #endif ) S9xReportButton (offset + i, true); else S9xReportButton (offset + i, false); } /*** Superscope ***/ if (Settings.SuperScopeMaster && pad == GCSettings.Superscope-1) // report only once { // buttons offset = 0x50; for (i = 0; i < 6; i++) { if ( jp & gcscopemap[i] #ifdef HW_RVL || wp & wmscopemap[i] #endif ) S9xReportButton (offset + i, true); else S9xReportButton (offset + i, false); } // pointer offset = 0x80; UpdateCursorPosition (pad, cursor_x[0], cursor_y[0]); S9xReportPointer(offset, (u16)cursor_x[0], (u16)cursor_y[0]); } /*** Mouse ***/ else if (Settings.MouseMaster && pad < GCSettings.Mouse) { // buttons offset = 0x60+(2*pad); for (i = 0; i < 2; i++) { if ( jp & gcmousemap[i] #ifdef HW_RVL || wp & wmmousemap[i] #endif ) S9xReportButton (offset + i, true); else S9xReportButton (offset + i, false); } // pointer offset = 0x81; UpdateCursorPosition (pad, cursor_x[1+pad], cursor_y[1+pad]); S9xReportPointer(offset+pad, (u16)cursor_x[1+pad], (u16)cursor_y[1+pad]); } /*** Justifier ***/ else if (Settings.JustifierMaster && pad < GCSettings.Justifier) { // buttons offset = 0x70+(3*pad); for (i = 0; i < 3; i++) { if ( jp & gcjustmap[i] #ifdef HW_RVL || wp & wmjustmap[i] #endif ) S9xReportButton (offset + i, true); else S9xReportButton (offset + i, false); } // pointer offset = 0x83; UpdateCursorPosition (pad, cursor_x[3+pad], cursor_y[3+pad]); S9xReportPointer(offset+pad, (u16)cursor_x[3+pad], (u16)cursor_y[3+pad]); } }
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; } } }
int main (int argc, char **argv) { // init SDL (Video only) if (SDL_Init(SDL_INIT_VIDEO) < 0) { fprintf(stderr, "Couldn't initialise SDL: %s", SDL_GetError()); return 1; } atexit(SDL_Quit); screen = SDL_SetVideoMode(320, 240, 8, SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_FULLSCREEN); if (!screen) { fprintf(stderr, "Couldn't set video mode: %s\n", SDL_GetError()); return 1; } SDL_ShowCursor(SDL_DISABLE); Game.InitSoundDriver(); Game.InitGame(); Game.LoadScores(); Game.StartGame(); int run = 1; int game_paused = 0; int game_speed = 55; int last_time = SDL_GetTicks(); // load Menu images SDL_Surface *menu_logo = load_menu_bitmap(menu_logo_bmp, menu_logo_bmp_size); SDL_Surface *menu_pointer = load_menu_bitmap(menu_pointer_bmp, menu_pointer_bmp_size); SDL_Surface *menu_1player = load_menu_bitmap(menu_1player_bmp, menu_1player_bmp_size); SDL_Surface *menu_2players = load_menu_bitmap(menu_2players_bmp, menu_2players_bmp_size); SDL_Surface *menu_start = load_menu_bitmap(menu_start_bmp, menu_start_bmp_size); SDL_Surface *menu_widescreen = load_menu_bitmap(menu_widescreen_bmp, menu_widescreen_bmp_size); SDL_Surface *menu_music = load_menu_bitmap(menu_music_bmp, menu_music_bmp_size); SDL_Surface *menu_sound = load_menu_bitmap(menu_sound_bmp, menu_sound_bmp_size); SDL_Surface *menu_i = load_menu_bitmap(menu_i_bmp, menu_i_bmp_size); SDL_Surface *menu_exit = load_menu_bitmap(menu_exit_bmp, menu_exit_bmp_size); SDL_Surface *menu_yes = load_menu_bitmap(menu_yes_bmp, menu_yes_bmp_size); SDL_Surface *menu_no = load_menu_bitmap(menu_no_bmp, menu_no_bmp_size); // Some globals int active_menu_item = 0; // Start int widescreen_enabled = 0; //nope int music_volume = 10; // max int sound_volume = 10; // max int i; int players = 1; // load config here :) while(run) { // Get Controller state JOYSTICK *jptr1 = &Game.m_GameTarget.m_Joy1; JOYSTICK *jptr2 = &Game.m_GameTarget.m_Joy2; PAD_ScanPads(); int bu_down, bu_up = 0; // Player 1 bu_down = PAD_ButtonsDown(0); bu_up = PAD_ButtonsUp(0); // left if (PAD_StickX(0) <= -58) jptr1->left = 1; else jptr1->left = 0; // right if (PAD_StickX(0) >= 58) jptr1->right = 1; else jptr1->right = 0; // down if (PAD_StickY(0) <= -58) jptr1->down = 1; else jptr1->down = 0; // up if (PAD_StickY(0) >= 58) jptr1->up = 1; else jptr1->up = 0; // fire if (bu_down & PAD_BUTTON_A) jptr1->fire = 1; if (bu_up & PAD_BUTTON_A) jptr1->fire = 0; // Switch Player sprites if (bu_down & PAD_TRIGGER_Z) Game.m_GameTarget.m_Game.TogglePuffBlow(); // Only Player 1 can Pause the Game if (bu_down & PAD_BUTTON_START) game_paused ^= 1; /* DEBUG: alter game speed + warp levels if (bu_down & PAD_TRIGGER_L) { game_speed += 5; if (game_speed > 100) game_speed = 100; } if (bu_down & PAD_TRIGGER_R) { game_speed -= 5; if (game_speed < 10) game_speed = 10; } if ((PAD_SubStickX(0) > 60) && (PAD_SubStickY(0) <= -60)) jptr1->next_level = 1; else jptr1->next_level = 0; // DEBUG: end */ // Player 2 bu_down = PAD_ButtonsDown(1); bu_up = PAD_ButtonsUp(1); // left if (PAD_StickX(1) <= -58) jptr2->left = 1; else jptr2->left = 0; // right if (PAD_StickX(1) >= 58) jptr2->right = 1; else jptr2->right = 0; // down if (PAD_StickY(1) <= -58) jptr2->down = 1; else jptr2->down = 0; // up if (PAD_StickY(1) >= 58) jptr2->up = 1; else jptr2->up = 0; // fire if (bu_down & PAD_BUTTON_A) jptr2->fire = 1; if (bu_up & PAD_BUTTON_A) jptr2->fire = 0; // Fake a key press (to pass getPlayerName screen) jptr1->key = 13; // Add a delay int time_diff = 0; do { int time_now = SDL_GetTicks(); time_diff = time_now - last_time; time_diff = game_speed - time_diff; if (time_diff > 50) SDL_Delay(20); } while(time_diff > 0); last_time = last_time + game_speed; // Execute game logic Game.MainLoop(NULL, game_paused); // Display menu if (game_paused == 1) { // Draw logo + items SDL_Rect menu_pos; menu_pos.x = 16; menu_pos.y = 3; menu_pos.w = 0; menu_pos.h = 0; SDL_BlitSurface(menu_logo, NULL, screen, &menu_pos); menu_pos.x = 70; menu_pos.y = 120; menu_pos.w = 0; menu_pos.h = 0; SDL_BlitSurface(menu_start, NULL, screen, &menu_pos); menu_pos.x = 70; menu_pos.y = 140; menu_pos.w = 0; menu_pos.h = 0; if(players == 1) SDL_BlitSurface(menu_1player, NULL, screen, &menu_pos); else SDL_BlitSurface(menu_2players, NULL, screen, &menu_pos); menu_pos.x = 70; menu_pos.y = 160; menu_pos.w = 0; menu_pos.h = 0; SDL_BlitSurface(menu_widescreen, NULL, screen, &menu_pos); // Widescreen Indicator menu_pos.x = 255; menu_pos.y = 160; menu_pos.w = 0; menu_pos.h = 0; if(widescreen_enabled) SDL_BlitSurface(menu_yes, NULL, screen, &menu_pos); else SDL_BlitSurface(menu_no, NULL, screen, &menu_pos); menu_pos.x = 70; menu_pos.y = 180; menu_pos.w = 0; menu_pos.h = 0; SDL_BlitSurface(menu_sound, NULL, screen, &menu_pos); // Sound volume bar for (i = 1; i <= sound_volume; i++) { menu_pos.x = 160 + (i * 9); menu_pos.y = 180; menu_pos.w = 0; menu_pos.h = 0; SDL_BlitSurface(menu_i, NULL, screen, &menu_pos); } menu_pos.x = 70; menu_pos.y = 200; menu_pos.w = 0; menu_pos.h = 0; SDL_BlitSurface(menu_music, NULL, screen, &menu_pos); // Music volume bar for (i = 1; i <= music_volume; i++) { menu_pos.x = 160 + (i * 9); menu_pos.y = 200; menu_pos.w = 0; menu_pos.h = 0; SDL_BlitSurface(menu_i, NULL, screen, &menu_pos); } menu_pos.x = 70; menu_pos.y = 220; menu_pos.w = 0; menu_pos.h = 0; SDL_BlitSurface(menu_exit, NULL, screen, &menu_pos); // Pointer if((jptr1->down == 1) && (active_menu_item < 5)) active_menu_item++; if((jptr1->up == 1) && (active_menu_item > 0)) active_menu_item--; menu_pos.x = 30; menu_pos.y = 105 + (active_menu_item * 20); menu_pos.w = 0; menu_pos.h = 0; SDL_BlitSurface(menu_pointer, NULL, screen, &menu_pos); // React on items if((active_menu_item == 0) && (jptr1->fire)) // Start { game_paused = 0; Game.m_GameTarget.m_Game.InitGetPlayerNameScreen(players == 2); } if(active_menu_item == 1) // Players { if (jptr1->left) players = 1; if (jptr1->right) players = 2; } if(active_menu_item == 2) // Widescreen { if (jptr1->left) { widescreen_enabled = 0; CUBE_ChangeSquare(320, 240, 0, 0); // no padding } if (jptr1->right) { widescreen_enabled = 1; CUBE_ChangeSquare(280, 240, 0, 0); // add some padding } } if(active_menu_item == 3) // Sound { if((jptr1->right) && (sound_volume < 10)) sound_volume++; if((jptr1->left) && (sound_volume > 0)) sound_volume--; Game.ChangeVolume(sound_volume, music_volume); } if(active_menu_item == 4) // Music { if((jptr1->right) && (music_volume < 10)) music_volume++; if((jptr1->left) && (music_volume > 0)) music_volume--; Game.ChangeVolume(sound_volume, music_volume); } if((active_menu_item == 5) && (jptr1->fire)) //EXIT run = 0; // Show all SDL_Flip (screen); // Wait for buttonpresses SDL_Delay(60); // Fix delay timer last_time = SDL_GetTicks(); } } Game.SaveScores(); // save config here :) Game.RemoveSoundDriver(); SDL_FreeSurface(screen); SDL_QuitSubSystem(SDL_INIT_VIDEO); //return 0; exit(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); }
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); }
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); }
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; }
void refreshInput() { unsigned long btns = 0; unsigned short gcbtns; WPADData *wpad; PAD_Init(); PAD_ScanPads(); gcbtns = PAD_ButtonsDown(0) | PAD_ButtonsHeld(0); WPAD_ScanPads(); wpad = WPAD_Data(0); if(wpad->exp.type == WPAD_EXP_CLASSIC) { // Left thumb stick if(wpad->exp.classic.ljs.mag >= 0.3) { if (wpad->exp.classic.ljs.ang >= 310 || wpad->exp.classic.ljs.ang <= 50) btns |= DIR_UP; if (wpad->exp.classic.ljs.ang >= 130 && wpad->exp.classic.ljs.ang <= 230) btns |= DIR_DOWN; if (wpad->exp.classic.ljs.ang >= 220 && wpad->exp.classic.ljs.ang <= 320) btns |= DIR_LEFT; if (wpad->exp.classic.ljs.ang >= 40 && wpad->exp.classic.ljs.ang <= 140) btns |= DIR_RIGHT; } // D-pad if(wpad->btns_h & WPAD_CLASSIC_BUTTON_UP) btns |= DIR_UP; if(wpad->btns_h & WPAD_CLASSIC_BUTTON_DOWN) btns |= DIR_DOWN; if(wpad->btns_h & WPAD_CLASSIC_BUTTON_LEFT) btns |= DIR_LEFT; if(wpad->btns_h & WPAD_CLASSIC_BUTTON_RIGHT) btns |= DIR_RIGHT; } else if(wpad->exp.type == WPAD_EXP_NUNCHUK) // Wiimote + Nunchuk { if(wpad->exp.nunchuk.js.pos.y >= 0xB0) btns |= DIR_UP; if(wpad->exp.nunchuk.js.pos.y <= 0x40) btns |= DIR_DOWN; if(wpad->exp.nunchuk.js.pos.x <= 0x40) btns |= DIR_LEFT; if(wpad->exp.nunchuk.js.pos.x >= 0xB0) btns |= DIR_RIGHT; if(wpad->btns_h & WPAD_BUTTON_UP) btns |= DIR_UP; if(wpad->btns_h & WPAD_BUTTON_DOWN) btns |= DIR_DOWN; if(wpad->btns_h & WPAD_BUTTON_LEFT) btns |= DIR_LEFT; if(wpad->btns_h & WPAD_BUTTON_RIGHT) btns |= DIR_RIGHT; } else // Wiimote held sideways { if(wpad->btns_h & WPAD_BUTTON_UP) btns |= DIR_LEFT; if(wpad->btns_h & WPAD_BUTTON_DOWN) btns |= DIR_RIGHT; if(wpad->btns_h & WPAD_BUTTON_LEFT) btns |= DIR_DOWN; if(wpad->btns_h & WPAD_BUTTON_RIGHT) btns |= DIR_UP; } // GameCube analog stick and D-pad if(PAD_StickY(0) > 18) btns |= DIR_UP; if(PAD_StickY(0) < -18) btns |= DIR_DOWN; if(PAD_StickX(0) < -18) btns |= DIR_LEFT; if(PAD_StickX(0) > 18) btns |= DIR_RIGHT; if(gcbtns & PAD_BUTTON_UP) btns |= DIR_UP; if(gcbtns & PAD_BUTTON_DOWN) btns |= DIR_DOWN; if(gcbtns & PAD_BUTTON_LEFT) btns |= DIR_LEFT; if(gcbtns & PAD_BUTTON_RIGHT) btns |= DIR_RIGHT; // Controller buttons if(wpad->btns_h & WPAD_BUTTON_1) btns |= WIIMOTE_1; if(wpad->btns_h & WPAD_BUTTON_2) btns |= WIIMOTE_2; if(wpad->btns_h & WPAD_BUTTON_A) btns |= WIIMOTE_A; if(wpad->btns_h & WPAD_BUTTON_B) btns |= WIIMOTE_B; if(wpad->btns_h & WPAD_BUTTON_MINUS) btns |= WIIMOTE_MINUS; if(wpad->btns_h & WPAD_BUTTON_PLUS) btns |= WIIMOTE_PLUS; if(wpad->btns_h & WPAD_BUTTON_HOME) btns |= WIIMOTE_HOME; if(wpad->btns_h & WPAD_NUNCHUK_BUTTON_Z) btns |= NUNCHUK_Z; if(wpad->btns_h & WPAD_NUNCHUK_BUTTON_C) btns |= NUNCHUK_C; if(wpad->btns_h & WPAD_CLASSIC_BUTTON_A) btns |= CC_A; if(wpad->btns_h & WPAD_CLASSIC_BUTTON_B) btns |= CC_B; if(wpad->btns_h & WPAD_CLASSIC_BUTTON_Y) btns |= CC_Y; if(wpad->btns_h & WPAD_CLASSIC_BUTTON_X) btns |= CC_X; if(wpad->btns_h & WPAD_CLASSIC_BUTTON_MINUS) btns |= CC_MINUS; if(wpad->btns_h & WPAD_CLASSIC_BUTTON_PLUS) btns |= CC_PLUS; if(wpad->btns_h & WPAD_CLASSIC_BUTTON_HOME) btns |= CC_HOME; if(wpad->btns_h & WPAD_CLASSIC_BUTTON_FULL_R) btns |= CC_R; if(wpad->btns_h & WPAD_CLASSIC_BUTTON_FULL_L) btns |= CC_L; if(wpad->btns_h & WPAD_CLASSIC_BUTTON_ZL) btns |= CC_ZL; if(wpad->btns_h & WPAD_CLASSIC_BUTTON_ZR) btns |= CC_ZR; if(gcbtns & PAD_BUTTON_X) btns |= GC_X; if(gcbtns & PAD_BUTTON_Y) btns |= GC_Y; if(gcbtns & PAD_BUTTON_A) btns |= GC_A; if(gcbtns & PAD_BUTTON_B) btns |= GC_B; if(gcbtns & PAD_TRIGGER_R) btns |= GC_R; if(gcbtns & PAD_TRIGGER_L) btns |= GC_L; if(gcbtns & PAD_TRIGGER_Z) btns |= GC_Z; if(gcbtns & PAD_BUTTON_START) btns |= GC_START; // update buttons pressed (not held) buttonsPressed = btns & ~buttonsHeld; buttonsHeld = btns; }
u16 ogc_input__getMenuButtons(void) { /* slowdown input updates */ VIDEO_WaitVSync(); /* get gamepad inputs */ PAD_ScanPads(); u16 p = PAD_ButtonsDown(0); s8 x = PAD_StickX(0); s8 y = PAD_StickY(0); if (x > 70) p |= PAD_BUTTON_RIGHT; else if (x < -70) p |= PAD_BUTTON_LEFT; if (y > 60) p |= PAD_BUTTON_UP; else if (y < -60) p |= PAD_BUTTON_DOWN; #ifdef HW_RVL /* get wiimote + expansions inputs */ WPAD_ScanPads(); u32 q = WPAD_ButtonsDown(0); u32 h = WPAD_ButtonsHeld(0); x = WPAD_StickX(0, 0); y = WPAD_StickY(0, 0); /* is Wiimote directed toward screen (horizontal/vertical orientation) ? */ struct ir_t ir; WPAD_IR(0, &ir); /* wiimote directions */ if (q & WPAD_BUTTON_UP) p |= ir.valid ? PAD_BUTTON_UP : PAD_BUTTON_LEFT; else if (q & WPAD_BUTTON_DOWN) p |= ir.valid ? PAD_BUTTON_DOWN : PAD_BUTTON_RIGHT; else if (q & WPAD_BUTTON_LEFT) p |= ir.valid ? PAD_BUTTON_LEFT : PAD_BUTTON_DOWN; else if (q & WPAD_BUTTON_RIGHT) p |= ir.valid ? PAD_BUTTON_RIGHT : PAD_BUTTON_UP; if (h & WPAD_BUTTON_UP) { held_cnt ++; if (held_cnt == MAX_HELD_CNT) { held_cnt = MAX_HELD_CNT - 2; p |= ir.valid ? PAD_BUTTON_UP : PAD_BUTTON_LEFT; } } else if (h & WPAD_BUTTON_DOWN) { held_cnt ++; if (held_cnt == MAX_HELD_CNT) { held_cnt = MAX_HELD_CNT - 2; p |= ir.valid ? PAD_BUTTON_DOWN : PAD_BUTTON_RIGHT; } } else if (h & WPAD_BUTTON_LEFT) { held_cnt ++; if (held_cnt == MAX_HELD_CNT) { held_cnt = MAX_HELD_CNT - 2; p |= ir.valid ? PAD_BUTTON_LEFT : PAD_BUTTON_DOWN; } } else if (h & WPAD_BUTTON_RIGHT) { held_cnt ++; if (held_cnt == MAX_HELD_CNT) { held_cnt = MAX_HELD_CNT - 2; p |= ir.valid ? PAD_BUTTON_RIGHT : PAD_BUTTON_UP; } } else { held_cnt = 0; } /* analog sticks */ if (y > 70) p |= PAD_BUTTON_UP; else if (y < -70) p |= PAD_BUTTON_DOWN; if (x < -60) p |= PAD_BUTTON_LEFT; else if (x > 60) p |= PAD_BUTTON_RIGHT; /* classic controller directions */ if (q & WPAD_CLASSIC_BUTTON_UP) p |= PAD_BUTTON_UP; else if (q & WPAD_CLASSIC_BUTTON_DOWN) p |= PAD_BUTTON_DOWN; if (q & WPAD_CLASSIC_BUTTON_LEFT) p |= PAD_BUTTON_LEFT; else if (q & WPAD_CLASSIC_BUTTON_RIGHT) p |= PAD_BUTTON_RIGHT; /* wiimote keys */ if (q & WPAD_BUTTON_MINUS) p |= PAD_TRIGGER_L; if (q & WPAD_BUTTON_PLUS) p |= PAD_TRIGGER_R; if (q & WPAD_BUTTON_A) p |= PAD_BUTTON_A; if (q & WPAD_BUTTON_B) p |= PAD_BUTTON_B; if (q & WPAD_BUTTON_2) p |= PAD_BUTTON_A; if (q & WPAD_BUTTON_1) p |= PAD_BUTTON_B; if (q & WPAD_BUTTON_HOME) p |= PAD_TRIGGER_Z; /* classic controller keys */ if (q & WPAD_CLASSIC_BUTTON_FULL_L) p |= PAD_TRIGGER_L; if (q & WPAD_CLASSIC_BUTTON_FULL_R) p |= PAD_TRIGGER_R; if (q & WPAD_CLASSIC_BUTTON_A) p |= PAD_BUTTON_A; if (q & WPAD_CLASSIC_BUTTON_B) p |= PAD_BUTTON_B; if (q & WPAD_CLASSIC_BUTTON_HOME) p |= PAD_TRIGGER_Z; #endif return p; }