/**************************************************************************** * libwiigui Template * Tantric 2009 * Modified by Ced2911, 2011 * * input.cpp * Wii/GameCube controller management ***************************************************************************/ #include #include #include #include #include #include #include #include //#include "menu.h" #include "video.h" #include "input.h" #include "gui/gui.h" #include "snes9xgx.h" #include "button_mapping.h" extern "C" void doScreenCapture(); extern "C" void enableCapture(); #define MAX_INPUTS 4 int rumbleRequest[4] = {0, 0, 0, 0}; GuiTrigger userInput[4]; //static int rumbleCount[4] = {0, 0, 0, 0}; static WPADData wpad_xenon[MAX_INPUTS]; static struct controller_data_s ctrl[MAX_INPUTS]; static struct controller_data_s old_ctrl[MAX_INPUTS]; #define ASSIGN_BUTTON_TRUE( keycode, snescmd ) \ S9xMapButton( keycode, cmd = S9xGetCommandT(snescmd), true) #define ASSIGN_BUTTON_FALSE( keycode, snescmd ) \ S9xMapButton( keycode, cmd = S9xGetCommandT(snescmd), false) #define STICK_DEAD_ZONE (13107) #define HANDLE_STICK_DEAD_ZONE(x) ((((x)>-STICK_DEAD_ZONE) && (x)> 8; } s8 PAD_StickY(int i) { return HANDLE_STICK_DEAD_ZONE(ctrl[i].s1_y) >> 8; } s8 PAD_SubStickX(int i) { return HANDLE_STICK_DEAD_ZONE(ctrl[i].s2_y) >> 8; } s8 PAD_SubStickY(int i) { return HANDLE_STICK_DEAD_ZONE(ctrl[i].s2_y) >> 8; } u8 PAD_TriggerL(int i) { return ctrl[i].lt; } u8 PAD_TriggerR(int i) { return ctrl[i].rt; } static void XenonInputUpdate() { usb_do_poll(); for (int i = 0; i < MAX_INPUTS; i++) { old_ctrl[i] = ctrl[i]; 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; } } /**************************************************************************** * UpdatePads * * Scans pad and wpad ***************************************************************************/ void UpdatePads() { XenonInputUpdate(); for (int i = 3; i >= 0; i--) { userInput[i].pad.btns_d = PAD_ButtonsDown(i); userInput[i].pad.btns_u = PAD_ButtonsUp(i); userInput[i].pad.btns_h = PAD_ButtonsHeld(i); // userInput[i].pad.stickX = PAD_StickX(i); // userInput[i].pad.stickY = PAD_StickY(i); userInput[i].pad.substickX = PAD_SubStickX(i); userInput[i].pad.substickY = PAD_SubStickY(i); userInput[i].pad.triggerL = PAD_TriggerL(i); userInput[i].pad.triggerR = PAD_TriggerR(i); } } /**************************************************************************** * SetupPads * * Sets up userInput triggers for use ***************************************************************************/ void SetupPads() { XenonInputInit(); for (int i = 0; i < 4; i++) { userInput[i].chan = i; userInput[i].wpad = &wpad_xenon[i]; userInput[i].wpad->exp.type = EXP_CLASSIC; } } /**************************************************************************** * ShutoffRumble ***************************************************************************/ void ShutoffRumble() { } /**************************************************************************** * DoRumble ***************************************************************************/ void DoRumble(int i) { } /**************************************************************************** * Set the default mapping ***************************************************************************/ void SetDefaultButtonMap() { } void ResetControls(int consoleCtrl, int wiiCtrl) { } bool MenuRequested() { for (int i = 0; i < 4; i++) { if ( (userInput[i].pad.substickX < -70) || (userInput[i].pad.btns_h & PAD_TRIGGER_L && userInput[i].pad.btns_h & PAD_TRIGGER_R && userInput[i].pad.btns_h & PAD_BUTTON_X && userInput[i].pad.btns_h & PAD_BUTTON_Y ) || userInput[i].pad.btns_h & PAD_BUTTON_LOGO ) { return true; } } return false; } /**************************************************************************** * ReportButtons * * Called on each rendered frame * Our way of putting controller input into Snes9x ***************************************************************************/ void ReportButtons() { // int i, j; UpdatePads(); /* Check for menu: * CStick left * OR "L+R+X+Y" (eg. Homebrew/Adapted SNES controllers) * OR "Home" on the wiimote or classic controller * OR Left on classic right analog stick */ if (MenuRequested()) ScreenshotRequested = 1; // go to the menu } void SetControllers() { }