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; } } }
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; }
void CheatMenu() { int ret = -1; int oldmenu = menu; menu = 0; int selection = 0; int offset = 0; int redraw = 1; int selectit = 0; u32 p = 0; u32 wp = 0; u32 ph = 0; u32 wh = 0; signed char gc_ay = 0; signed char gc_sx = 0; signed char wm_ay = 0; signed char wm_sx = 0; int scroll_delay = 0; bool move_selection = 0; #define SCROLL_INITIAL_DELAY 15 #define SCROLL_LOOP_DELAY 2 if(Cheat.num_cheats > 0) { cheatmenuCount = Cheat.num_cheats + 1; for(uint16 i=0; i < Cheat.num_cheats; i++) sprintf (cheatmenu[i], "%s", Cheat.c[i].name); sprintf (cheatmenu[cheatmenuCount-1], "Back to Game Menu"); while(ret != cheatmenuCount-1) { if(ret >= 0) { if(Cheat.c[ret].enabled) S9xDisableCheat(ret); else S9xEnableCheat(ret); ret = -1; } for(uint16 i=0; i < Cheat.num_cheats; i++) sprintf (cheatmenuvalue[i], "%s", Cheat.c[i].enabled == true ? "ON" : "OFF"); if (redraw) ShowCheats (cheatmenu, cheatmenuvalue, cheatmenuCount, offset, selection); redraw = 0; VIDEO_WaitVSync(); // slow things down a bit so we don't overread the pads gc_ay = PAD_StickY (0); gc_sx = PAD_SubStickX (0); p = PAD_ButtonsDown (0); ph = PAD_ButtonsHeld (0); #ifdef HW_RVL wm_ay = WPAD_Stick (0, 0, 1); wm_sx = WPAD_Stick (0, 1, 0); wp = WPAD_ButtonsDown (0); wh = WPAD_ButtonsHeld (0); #endif /*** Check for exit combo ***/ if ( (gc_sx < -70) || (wm_sx < -70) || (wp & WPAD_BUTTON_HOME) || (wp & WPAD_CLASSIC_BUTTON_HOME) ) break; if ( (p & PAD_BUTTON_B) || (wp & (WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B)) ) break; /*** Check buttons, perform actions ***/ if ( (p & PAD_BUTTON_A) || selectit || (wp & (WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A)) ) { if ( selectit ) selectit = 0; redraw = 1; ret = selection; } // End of A if ( ((p | ph) & PAD_BUTTON_DOWN) || ((wp | wh) & (WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN)) || (gc_ay < -PADCAL) || (wm_ay < -PADCAL) ) { if ( (p & PAD_BUTTON_DOWN) || (wp & (WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN)) ) { /*** Button just pressed ***/ scroll_delay = SCROLL_INITIAL_DELAY; // reset scroll delay. move_selection = 1; //continue (move selection) } else if (scroll_delay == 0) { /*** Button is held ***/ scroll_delay = SCROLL_LOOP_DELAY; move_selection = 1; //continue (move selection) } else { scroll_delay--; // wait } if (move_selection) { selection++; if (selection == cheatmenuCount) selection = offset = 0; if ((selection - offset) >= PAGESIZE) offset += PAGESIZE; redraw = 1; move_selection = 0; } } // End of down if ( ((p | ph) & PAD_BUTTON_UP) || ((wp | wh) & (WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP)) || (gc_ay > PADCAL) || (wm_ay > PADCAL) ) { if ( (p & PAD_BUTTON_UP) || (wp & (WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP)) ) { /*** Button just pressed***/ scroll_delay = SCROLL_INITIAL_DELAY; // reset scroll delay. move_selection = 1; //continue (move selection) } else if (scroll_delay == 0) { /*** Button is held ***/ scroll_delay = SCROLL_LOOP_DELAY; move_selection = 1; //continue (move selection) } else { scroll_delay--; // wait } if (move_selection) { selection--; if (selection < 0) { selection = cheatmenuCount - 1; offset = selection - PAGESIZE + 1; } if (selection < offset) offset -= PAGESIZE; if (offset < 0) offset = 0; redraw = 1; move_selection = 0; } } // End of Up if ( (p & PAD_BUTTON_LEFT) || (wp & (WPAD_BUTTON_LEFT | WPAD_CLASSIC_BUTTON_LEFT)) ) { /*** Go back a page ***/ selection -= PAGESIZE; if (selection < 0) { selection = cheatmenuCount - 1; offset = selection - PAGESIZE + 1; } if (selection < offset) offset -= PAGESIZE; if (offset < 0) offset = 0; redraw = 1; } if ( (p & PAD_BUTTON_RIGHT) || (wp & (WPAD_BUTTON_RIGHT | WPAD_CLASSIC_BUTTON_RIGHT)) ) { /*** Go forward a page ***/ selection += PAGESIZE; if (selection > cheatmenuCount - 1) selection = offset = 0; if ((selection - offset) >= PAGESIZE) offset += PAGESIZE; redraw = 1; } } } else { WaitPrompt((char*)"No cheats found!"); } menu = oldmenu; }
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); }
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; } }
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]); } }
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); }
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; }
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); }
// 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; } }
/* 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; }
//--------------------------------------------------------------------------------- int main( int argc, char **argv ){ //--------------------------------------------------------------------------------- f32 yscale; u32 xfbHeight; // various matrices for things like view Mtx view,mv,mr; Mtx44 perspective; // the texure we're going to paint GXTexObj texture; TPLFile mudTPL; u32 fb = 0; // initial framebuffer index GXColor background = {0, 0, 0, 0xff}; // init the vi. VIDEO_Init(); rmode = VIDEO_GetPreferredMode(NULL); WPAD_Init(); // allocate 2 framebuffers for double buffering frameBuffer[0] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); frameBuffer[1] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); // configure video and wait for the screen to blank VIDEO_Configure(rmode); VIDEO_SetNextFramebuffer(frameBuffer[fb]); VIDEO_SetBlack(FALSE); VIDEO_Flush(); VIDEO_WaitVSync(); if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); // setup the fifo... void *gp_fifo = NULL; gp_fifo = memalign(32,DEFAULT_FIFO_SIZE); memset(gp_fifo,0,DEFAULT_FIFO_SIZE); // ...then init the flipper GX_Init(gp_fifo,DEFAULT_FIFO_SIZE); // clears the bg to color and clears the z buffer GX_SetCopyClear(background, 0x00ffffff); // other gx setup GX_SetViewport(0,0,rmode->fbWidth,rmode->efbHeight,0,1); yscale = GX_GetYScaleFactor(rmode->efbHeight,rmode->xfbHeight); xfbHeight = GX_SetDispCopyYScale(yscale); GX_SetScissor(0,0,rmode->fbWidth,rmode->efbHeight); GX_SetDispCopySrc(0,0,rmode->fbWidth,rmode->efbHeight); GX_SetDispCopyDst(rmode->fbWidth,xfbHeight); GX_SetCopyFilter(rmode->aa,rmode->sample_pattern,GX_TRUE,rmode->vfilter); GX_SetFieldMode(rmode->field_rendering,((rmode->viHeight==2*rmode->xfbHeight)?GX_ENABLE:GX_DISABLE)); if (rmode->aa) GX_SetPixelFmt(GX_PF_RGB565_Z16, GX_ZC_LINEAR); else GX_SetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR); GX_SetCullMode(GX_CULL_NONE); GX_CopyDisp(frameBuffer[fb],GX_TRUE); GX_SetDispCopyGamma(GX_GM_1_0); // setup the vertex attribute table // describes the data // args: vat location 0-7, type of data, data format, size, scale // so for ex. in the first call we are sending position data with // 3 values X,Y,Z of size F32. scale sets the number of fractional // bits for non float data. GX_InvVtxCache(); GX_ClearVtxDesc(); GX_SetVtxDesc(GX_VA_POS, GX_DIRECT); GX_SetVtxDesc(GX_VA_NRM, GX_DIRECT); GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT); GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0); GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_NRM, GX_NRM_XYZ, GX_F32, 0); GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0); // setup texture coordinate generation // args: texcoord slot 0-7, matrix type, source to generate texture coordinates from, matrix to use GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX3x4, GX_TG_TEX0, GX_IDENTITY); f32 w = rmode->viWidth; f32 h = rmode->viHeight; guLightPerspective(mv,45, (f32)w/h, 1.05F, 1.0F, 0.0F, 0.0F); guMtxTrans(mr, 0.0F, 0.0F, -1.0F); guMtxConcat(mv, mr, mv); GX_LoadTexMtxImm(mv, GX_TEXMTX0, GX_MTX3x4); GX_InvalidateTexAll(); TPL_OpenTPLFromMemory(&mudTPL, (void *)mud_tpl,mud_tpl_size); TPL_GetTexture(&mudTPL,mud,&texture); // setup our camera at the origin // looking down the -z axis with y up guVector cam = {0.0F, 0.0F, 0.0F}, up = {0.0F, 1.0F, 0.0F}, look = {0.0F, 0.0F, -1.0F}; guLookAt(view, &cam, &up, &look); // setup our projection matrix // this creates a perspective matrix with a view angle of 90, // and aspect ratio based on the display resolution guPerspective(perspective, 45, (f32)w/h, 0.1F, 300.0F); GX_LoadProjectionMtx(perspective, GX_PERSPECTIVE); // get the room ready to render SetupWorld(); while(1) { WPAD_ScanPads(); s8 tpad = PAD_StickX(0); // Rotate left or right. if ((tpad < -8) || (tpad > 8)) yrot -= (float)tpad / 50.f; // NOTE: walkbiasangle = head bob tpad = PAD_StickY(0); // Go forward. if(tpad > 50) { xpos -= (float)sin(DegToRad(yrot)) * 0.05f; // Move on the x-plane based on player direction zpos -= (float)cos(DegToRad(yrot)) * 0.05f; // Move on the z-plane based on player direction if (walkbiasangle >= 359.0f) walkbiasangle = 0.0f; // Bring walkbiasangle back around else walkbiasangle += 10; // if walkbiasangle < 359 increase it by 10 walkbias = (float)sin(DegToRad(walkbiasangle))/20.0f; } // Go backward if(tpad < -50) { xpos += (float)sin(DegToRad(yrot)) * 0.05f; zpos += (float)cos(DegToRad(yrot)) * 0.05f; if (walkbiasangle <= 1.0f) walkbiasangle = 359.0f; else walkbiasangle -= 10; walkbias = (float)sin(DegToRad(walkbiasangle))/20.0f; } tpad = PAD_SubStickY(0); // Tilt up/down if (((tpad > 8) || (tpad < -8)) && ((90 >= lookupdown) && (lookupdown >= -90))) { zdepth -= ((f32)tpad * 0.01f); lookupdown -= ((f32)tpad * 0.01f); if (lookupdown > 90) lookupdown = 90.0F; if (lookupdown < -90) lookupdown = -90.0F; } if ( PAD_ButtonsDown(0) & PAD_BUTTON_START) { exit(0); } // do this before drawing GX_SetViewport(0,0,rmode->fbWidth,rmode->efbHeight,0,1); //set number of textures to generate GX_SetNumTexGens(1); // Draw things DrawScene(view,texture); GX_SetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE); GX_SetColorUpdate(GX_TRUE); GX_CopyDisp(frameBuffer[fb],GX_TRUE); // do this stuff after drawing GX_DrawDone(); fb ^= 1; // flip framebuffer VIDEO_SetNextFramebuffer(frameBuffer[fb]); VIDEO_Flush(); VIDEO_WaitVSync(); } return 0; }
static void pad_update() { int i; u16 p; s8 x,y; /* update PAD status */ PAD_ScanPads(); for (i=0; i<MAX_INPUTS; i++) { x = PAD_StickX (i); y = PAD_StickY (i); p = PAD_ButtonsHeld(i); /* MENU */ if (p & pad_keymap[i][KEY_MENU]) { ConfigRequested = 1; return; } /* PAUSE & START button */ if (p & pad_keymap[i][KEY_PAUSE]) input.system |= (sms.console == CONSOLE_GG) ? INPUT_START : INPUT_PAUSE; /* SOFT RESET */ if (((p & PAD_TRIGGER_R) && (p & PAD_TRIGGER_L)) || softreset) { input.system |= INPUT_RESET; softreset = 0; SYS_SetResetCallback(set_softreset); } /* BUTTONS 1&2 */ if (p & pad_keymap[i][KEY_BUTTON1]) input.pad[i] |= INPUT_BUTTON1; if (p & pad_keymap[i][KEY_BUTTON2]) input.pad[i] |= INPUT_BUTTON2; /* check emulated device type */ switch (sms.device[i]) { /* digital gamepad */ case DEVICE_PAD2B: /* directional buttons */ if ((p & PAD_BUTTON_UP) || (y > 70)) input.pad[i] |= INPUT_UP; else if ((p & PAD_BUTTON_DOWN) || (y < -70)) input.pad[i] |= INPUT_DOWN; if ((p & PAD_BUTTON_LEFT) || (x < -60)) input.pad[i] |= INPUT_LEFT; else if ((p & PAD_BUTTON_RIGHT) || (x > 60)) input.pad[i] |= INPUT_RIGHT; break; /* analog devices */ case DEVICE_LIGHTGUN: case DEVICE_SPORTSPAD: case DEVICE_PADDLE: /* X position */ if (p & PAD_BUTTON_LEFT) input.analog[i][0] --; else if (p & PAD_BUTTON_RIGHT) input.analog[i][0] ++; else if (x) input.analog[i][0] = (u8)(x + 128); /* Y position */ if (p & PAD_BUTTON_UP) input.analog[i][1] --; else if (p & PAD_BUTTON_DOWN) input.analog[i][1] ++; else if (y) input.analog[i][1] = (u8)(128 - y); /* Limiters */ if (input.analog[i][0] < 0) input.analog[i][0] = 0; else if (input.analog[i][0] > 0xFF) input.analog[i][0] = 0xFF; if (input.analog[i][1] < 0) input.analog[i][1] = 0; else if (input.analog[i][1] > 0xFF) input.analog[i][1] = 0xFF; break; /* none */ default: break; } /* Colecovision support */ if (sms.console == CONSOLE_COLECO) { u16 pad; u16 d = PAD_ButtonsDown(i); input.system = 0; if (d & PAD_TRIGGER_R) { pad = (coleco.keypad[i] & 0x0f) + 1; if (pad > 11) pad = 0; if (pad == 11) sprintf(osd.msg,"KeyPad(%d) #",i+1); else if (pad == 10) sprintf(osd.msg,"KeyPad(%d) *",i+1); else sprintf(osd.msg,"KeyPad(%d) %d",i+1,pad); osd.frames = 30; coleco.keypad[i] = (coleco.keypad[i] & 0xf0) | pad; } if (p & PAD_TRIGGER_L) coleco.keypad[i] &= 0x0f; } } }
static int _GetKeys(int Control, BUTTONS * Keys, controller_config_t* config) { if(padNeedScan) { gc_connected = PAD_ScanPads(); padNeedScan = 0; } BUTTONS* c = Keys; memset(c, 0, sizeof(BUTTONS)); //Reset buttons & sticks c->btns.All = 0xFFFF; c->leftStickX = c->leftStickY = c->rightStickX = c->rightStickY = 128; controller_GC.available[Control] = (gc_connected & (1<<Control)) ? 1 : 0; if (!controller_GC.available[Control]) return 0; unsigned int b = getButtons(Control); inline int isHeld(button_tp button) { return (b & button->mask) == button->mask ? 0 : 1; } c->btns.SQUARE_BUTTON = isHeld(config->SQU); c->btns.CROSS_BUTTON = isHeld(config->CRO); c->btns.CIRCLE_BUTTON = isHeld(config->CIR); c->btns.TRIANGLE_BUTTON = isHeld(config->TRI); c->btns.R1_BUTTON = isHeld(config->R1); c->btns.L1_BUTTON = isHeld(config->L1); c->btns.R2_BUTTON = isHeld(config->R2); c->btns.L2_BUTTON = isHeld(config->L2); c->btns.L_DPAD = isHeld(config->DL); c->btns.R_DPAD = isHeld(config->DR); c->btns.U_DPAD = isHeld(config->DU); c->btns.D_DPAD = isHeld(config->DD); c->btns.START_BUTTON = isHeld(config->START); c->btns.R3_BUTTON = isHeld(config->R3); c->btns.L3_BUTTON = isHeld(config->L3); c->btns.SELECT_BUTTON = isHeld(config->SELECT); //adjust values by 128 cause PSX sticks range 0-255 with a 128 center pos int stickX = 0, stickY = 0; if(config->analogL->mask == ANALOG_AS_ANALOG) { stickX = PAD_StickX(Control); stickY = PAD_StickY(Control); } else if(config->analogL->mask == C_STICK_AS_ANALOG) { stickX = PAD_SubStickX(Control); stickY = PAD_SubStickY(Control); } c->leftStickX = GCtoPSXAnalog(stickX); c->leftStickY = GCtoPSXAnalog(config->invertedYL ? stickY : -stickY); if(config->analogR->mask == ANALOG_AS_ANALOG) { stickX = PAD_StickX(Control); stickY = PAD_StickY(Control); } else if(config->analogR->mask == C_STICK_AS_ANALOG) { stickX = PAD_SubStickX(Control); stickY = PAD_SubStickY(Control); } c->rightStickX = GCtoPSXAnalog(stickX); c->rightStickY = GCtoPSXAnalog(config->invertedYR ? stickY : -stickY); // Return 1 if whether the exit button(s) are pressed return isHeld(config->exit) ? 0 : 1; }