replace keyboard/mouse code w/ code from libogc

This commit is contained in:
dborth 2009-08-14 07:01:20 +00:00
parent 4dd183302e
commit a155c8105e
10 changed files with 270 additions and 645 deletions

View File

@ -41,7 +41,7 @@ LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map -Wl,--cref
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# any extra libraries we wish to link with # any extra libraries we wish to link with
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
LIBS := -ldb -ldi -lpngu -lpng -lmxml -lmetaphrasis \ LIBS := -ldb -ldi -lpngu -lpng -lmxml -lmetaphrasis -lwiikeyboard \
-lfat -lwiiuse -lz -lbte -logc -lasnd -ltremor -lfreetype -ltinysmb -lfat -lwiiuse -lz -lbte -logc -lasnd -ltremor -lfreetype -ltinysmb
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------

View File

@ -17,6 +17,7 @@
#include <wiiuse/wpad.h> #include <wiiuse/wpad.h>
#include "button_mapping.h" #include "button_mapping.h"
#include "wiiusbsupport.h"
/**************************************************************************** /****************************************************************************
* Controller Button Descriptions: * Controller Button Descriptions:
@ -113,144 +114,77 @@ CtrlrMap ctrlr_def[5] = {
{WPAD_CLASSIC_BUTTON_ZR, "ZR"} {WPAD_CLASSIC_BUTTON_ZR, "ZR"}
} }
}, },
// Keyboard btn def, see http://www.usb.org/developers/devclass_docs/Hut1_12.pdf // Keyboard btn def
{ {
CTRLR_KEYBOARD, CTRLR_KEYBOARD,
150, 66,
{ {
{4, "A"}, {KS_A, "A"},
{5, "B"}, {KS_B, "B"},
{6, "C"}, {KS_C, "C"},
{7, "D"}, {KS_D, "D"},
{8, "E"}, {KS_E, "E"},
{9, "F"}, {KS_F, "F"},
{10, "G"}, {KS_G, "G"},
{11, "H"}, {KS_H, "H"},
{12, "I"}, {KS_I, "I"},
{13, "J"}, {KS_J, "J"},
{14, "K"}, {KS_K, "K"},
{15, "L"}, {KS_L, "L"},
{16, "M"}, {KS_M, "M"},
{17, "N"}, {KS_N, "N"},
{18, "O"}, {KS_O, "O"},
{19, "P"}, {KS_P, "P"},
{20, "Q"}, {KS_Q, "Q"},
{21, "R"}, {KS_R, "R"},
{22, "S"}, {KS_S, "S"},
{23, "T"}, {KS_T, "T"},
{24, "U"}, {KS_U, "U"},
{25, "V"}, {KS_V, "V"},
{26, "W"}, {KS_W, "W"},
{27, "X"}, {KS_X, "X"},
{28, "Y"}, {KS_Y, "Y"},
{29, "Z"}, {KS_Z, "Z"},
{30, "1"}, {KS_1, "1"},
{31, "2"}, {KS_2, "2"},
{32, "3"}, {KS_3, "3"},
{33, "4"}, {KS_4, "4"},
{34, "5"}, {KS_5, "5"},
{35, "6"}, {KS_6, "6"},
{36, "7"}, {KS_7, "7"},
{37, "8"}, {KS_8, "8"},
{38, "9"}, {KS_9, "9"},
{39, "0"}, {KS_0, "0"},
{40, "ENTER"}, {KS_Return, "ENTER"},
{41, "ESC"}, {KS_Escape, "ESC"},
{42, "BKSP"}, {KS_BackSpace, "BKSP"},
{43, "TAB"}, {KS_Tab, "TAB"},
{44, "SPACE"}, {KS_space, "SPACE"},
{45, "-"}, {KS_F1, "F1"},
{46, "="}, {KS_F2, "F2"},
{47, "["}, {KS_F3, "F3"},
{48, "]"}, {KS_F4, "F4"},
{49, "\\"}, {KS_F5, "F5"},
{50, "#"}, {KS_F6, "F6"},
{51, ";"}, {KS_F7, "F7"},
{52, "'"}, {KS_F8, "F8"},
{53, "`"}, {KS_F9, "F9"},
{54, ","}, {KS_F10, "F10"},
{55, "."}, {KS_F11, "F11"},
{56, "/"}, {KS_F12, "F12"},
{57, "CAPLK"}, {KS_Right, "RIGHT"},
{58, "F1"}, {KS_Left, "LEFT"},
{59, "F2"}, {KS_Down, "DOWN"},
{60, "F3"}, {KS_Up, "UP"},
{61, "F4"}, {KS_Control_L, "LCTRL"},
{62, "F5"}, {KS_Shift_L, "LSHFT"},
{63, "F6"}, {KS_Alt_L, "LALT"},
{64, "F7"}, {KS_Control_R, "RCTRL"},
{65, "F8"}, {KS_Shift_R, "RSHFT"},
{66, "F9"}, {KS_Alt_R, "RALT"},
{67, "F10"}, {MOUSEL, "MOUSEL"},
{68, "F11"}, {MOUSER, "MOUSER"},
{69, "F12"}, {MOUSEM, "MOUSEM"}
{70, "PRTSC"},
{71, "SCRLK"},
{72, "PAUSE"},
{73, "INS"},
{74, "HOME"},
{75, "PGUP"},
{76, "DEL"},
{77, "END"},
{78, "PGDN"},
{79, "RIGHT"},
{80, "LEFT"},
{81, "DOWN"},
{82, "UP"},
{83, "NUMLK"},
{84, "NP/"},
{85, "NP*"},
{86, "NP-"},
{87, "NP+"},
{88, "NPENT"},
{89, "NP1"},
{90, "NP2"},
{91, "NP3"},
{92, "NP4"},
{93, "NP5"},
{94, "NP6"},
{95, "NP7"},
{96, "NP8"},
{97, "NP9"},
{98, "NP0"},
{99, "NP."},
{100, "\\|"},
{101, "APP"},
{102, "POWER"},
{103, "NP="},
{104, "F13"},
{105, "F14"},
{106, "F15"},
{107, "F16"},
{108, "F17"},
{109, "F18"},
{110, "F19"},
{111, "F20"},
{112, "F21"},
{113, "F22"},
{114, "F23"},
{115, "F24"},
{127, "MUTE"},
{128, "VOL+"},
{129, "VOL-"},
{144, "HANGL"},
{145, "HANJA"},
{146, "KATA"},
{147, "HIRA"},
{224, "LCTRL"},
{225, "LSHFT"},
{226, "LALT"},
{227, "LWIN"},
{228, "RCTRL"},
{229, "RSHFT"},
{230, "RALT"},
{231, "RWIN"},
{232, "MOUSEL"},
{233, "MOUSER"},
{234, "MOUSEM"}
} }
} }
}; };

View File

@ -20,8 +20,8 @@ enum {
CTRLR_KEYBOARD CTRLR_KEYBOARD
}; };
const char ctrlrName[4][20] = const char ctrlrName[5][20] =
{ "GameCube Controller", "Wiimote", "Nunchuk + Wiimote", "Classic Controller" }; { "GameCube Controller", "Wiimote", "Nunchuk + Wiimote", "Classic Controller", "Keyboard & Mouse" };
typedef struct _btn_map { typedef struct _btn_map {
u32 btn; // button 'id' u32 btn; // button 'id'

View File

@ -17,6 +17,7 @@
#include <ogcsys.h> #include <ogcsys.h>
#include <unistd.h> #include <unistd.h>
#include <wiiuse/wpad.h> #include <wiiuse/wpad.h>
#include <wiikeyboard/wsksymdef.h>
#include "vba.h" #include "vba.h"
#include "button_mapping.h" #include "button_mapping.h"
@ -803,13 +804,13 @@ u32 HarryPotter4Input(unsigned short pad) {
u32 J = StandardMovement(pad) | DPadArrowKeys(pad) u32 J = StandardMovement(pad) | DPadArrowKeys(pad)
| DecodeGamecube(pad); | DecodeGamecube(pad);
#ifdef HW_RVL #ifdef HW_RVL
if (DownUsbKeys[KB_A]) J |= VBA_BUTTON_L; if (DownUsbKeys[KS_A]) J |= VBA_BUTTON_L;
if (DownUsbKeys[KB_D]) J |= VBA_BUTTON_R; if (DownUsbKeys[KS_D]) J |= VBA_BUTTON_R;
if (DownUsbKeys[KB_ENTER] || DownUsbKeys[KB_X]) J |= VBA_BUTTON_A; if (DownUsbKeys[KS_Return] || DownUsbKeys[KS_X]) J |= VBA_BUTTON_A;
if (DownUsbKeys[KB_C]) J |= VBA_BUTTON_B; if (DownUsbKeys[KS_C]) J |= VBA_BUTTON_B;
if (DownUsbKeys[KB_TAB]) J |= VBA_BUTTON_SELECT; if (DownUsbKeys[KS_Tab]) J |= VBA_BUTTON_SELECT;
if (DownUsbKeys[KB_SPACE]) J |= VBA_BUTTON_START; if (DownUsbKeys[KS_space]) J |= VBA_BUTTON_START;
if (DownUsbKeys[KB_LSHIFT] || DownUsbKeys[KB_RSHIFT]) J |= VBA_SPEED; if (DownUsbKeys[KS_Shift_L] || DownUsbKeys[KS_Shift_R]) J |= VBA_SPEED;
WPADData * wp = WPAD_Data(pad); WPADData * wp = WPAD_Data(pad);
@ -861,13 +862,13 @@ u32 HarryPotter5Input(unsigned short pad) {
u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DPadWASD(pad); u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DPadWASD(pad);
#ifdef HW_RVL #ifdef HW_RVL
// Keyboard controls based on Harry Potter 5 for PC // Keyboard controls based on Harry Potter 5 for PC
if (DownUsbKeys[KB_LEFT]) J |= VBA_BUTTON_L; if (DownUsbKeys[KS_Left]) J |= VBA_BUTTON_L;
if (DownUsbKeys[KB_RIGHT]) J |= VBA_BUTTON_R; if (DownUsbKeys[KS_Right]) J |= VBA_BUTTON_R;
if (DownUsbKeys[KB_UP] || DownUsbKeys[KB_DOWN]) J |= VBA_BUTTON_B; if (DownUsbKeys[KS_Up] || DownUsbKeys[KS_Down]) J |= VBA_BUTTON_B;
if (DownUsbKeys[KB_ENTER]) J |= VBA_BUTTON_A; if (DownUsbKeys[KS_Return]) J |= VBA_BUTTON_A;
if (DownUsbKeys[KB_TAB]) J |= VBA_BUTTON_SELECT; if (DownUsbKeys[KS_Tab]) J |= VBA_BUTTON_SELECT;
if (DownUsbKeys[KB_SPACE]) J |= VBA_BUTTON_START; if (DownUsbKeys[KS_space]) J |= VBA_BUTTON_START;
if (DownUsbKeys[KB_LSHIFT] || DownUsbKeys[KB_RSHIFT]) J |= VBA_SPEED; if (DownUsbKeys[KS_Shift_L] || DownUsbKeys[KS_Shift_R]) J |= VBA_SPEED;
WPADData * wp = WPAD_Data(pad); WPADData * wp = WPAD_Data(pad);
@ -1291,20 +1292,20 @@ u32 HobbitInput(unsigned short pad) {
AttackButton = (fabs(wp->gforce.x)> 1.5); AttackButton = (fabs(wp->gforce.x)> 1.5);
} }
#endif #endif
if (DownUsbKeys[KB_E]) UseButton = true; if (DownUsbKeys[KS_E]) UseButton = true;
if (DownUsbKeys[KB_LSHIFT]) { if (DownUsbKeys[KS_Shift_L]) {
if (DownUsbKeys[KB_MOUSEL] || DownUsbKeys[KB_MOUSER]) AbilityButton = true; if (DownUsbKeys[MOUSEL] || DownUsbKeys[MOUSER]) AbilityButton = true;
} else { } else {
if (DownUsbKeys[KB_MOUSEL] || DownUsbKeys[KB_MOUSER]) AttackButton = true; if (DownUsbKeys[MOUSEL] || DownUsbKeys[MOUSER]) AttackButton = true;
} }
if (DownUsbKeys[KB_F5]) AbilityButton = true; if (DownUsbKeys[KS_F5]) AbilityButton = true;
if (DownUsbKeys[KB_LCTRL]) AttackButton = true; if (DownUsbKeys[KS_Control_L]) AttackButton = true;
if (DownUsbKeys[KB_SPACE]) AttackButton = true; if (DownUsbKeys[KS_space]) AttackButton = true;
if (DownUsbKeys[KB_Q]) AttackButton = true; if (DownUsbKeys[KS_Q]) AttackButton = true;
if (DownUsbKeys[KB_C]) ChangeSkillButton = true; if (DownUsbKeys[KS_C]) ChangeSkillButton = true;
if (DownUsbKeys[KB_ENTER]) ItemsButton = true; if (DownUsbKeys[KS_Return]) ItemsButton = true;
if (DownUsbKeys[KB_BKSP]) PauseButton = true; if (DownUsbKeys[KS_BackSpace]) PauseButton = true;
if (DownUsbKeys[KB_F]) SpeedButton = true; if (DownUsbKeys[KS_F]) SpeedButton = true;
if (AbilityButton) J |= VBA_BUTTON_B; if (AbilityButton) J |= VBA_BUTTON_B;
if (AttackButton) J |= VBA_BUTTON_L; if (AttackButton) J |= VBA_BUTTON_L;
@ -1339,18 +1340,18 @@ u32 FellowshipOfTheRingInput(unsigned short pad) {
SelectButton = wp->btns_h & WPAD_BUTTON_1; SelectButton = wp->btns_h & WPAD_BUTTON_1;
} }
#endif #endif
if (DownUsbKeys[KB_E]) UseButton = true; if (DownUsbKeys[KS_E]) UseButton = true;
if (DownUsbKeys[KB_Q]) CancelButton = true; if (DownUsbKeys[KS_Q]) CancelButton = true;
if (DownUsbKeys[KB_MOUSEL]) UseButton = true; if (DownUsbKeys[MOUSEL]) UseButton = true;
if (DownUsbKeys[KB_MOUSER]) CancelButton = true; if (DownUsbKeys[MOUSER]) CancelButton = true;
if (DownUsbKeys[KB_C]) ChangeCharButton = true; if (DownUsbKeys[KS_C]) ChangeCharButton = true;
if (DownUsbKeys[KB_ENTER]) PauseButton = true; if (DownUsbKeys[KS_Return]) PauseButton = true;
if (DownUsbKeys[KB_BKSP]) ItemsButton = true; if (DownUsbKeys[KS_BackSpace]) ItemsButton = true;
if (DownUsbKeys[KB_TAB]) SelectButton = true; if (DownUsbKeys[KS_Tab]) SelectButton = true;
if (DownUsbKeys[KB_F]) SpeedButton = true; if (DownUsbKeys[KS_F]) SpeedButton = true;
if (DownUsbKeys[KB_SPACE]) SpeedButton = true; if (DownUsbKeys[KS_space]) SpeedButton = true;
if (DownUsbKeys[KB_F5]) UseButton = true; if (DownUsbKeys[KS_F5]) UseButton = true;
if (DownUsbKeys[KB_LCTRL]) UseButton = true; if (DownUsbKeys[KS_Control_L]) UseButton = true;
if (UseButton) J |= VBA_BUTTON_A; if (UseButton) J |= VBA_BUTTON_A;
if (CancelButton) J |= VBA_BUTTON_B; if (CancelButton) J |= VBA_BUTTON_B;
@ -1384,20 +1385,20 @@ u32 ReturnOfTheKingInput(unsigned short pad) {
AttackButton = (fabs(wp->gforce.x)> 1.5); AttackButton = (fabs(wp->gforce.x)> 1.5);
} }
#endif #endif
if (DownUsbKeys[KB_E]) UseButton = true; if (DownUsbKeys[KS_E]) UseButton = true;
if (DownUsbKeys[KB_LSHIFT]) { if (DownUsbKeys[KS_Shift_L]) {
if (DownUsbKeys[KB_MOUSEL] || DownUsbKeys[KB_MOUSER]) AbilityButton = true; if (DownUsbKeys[MOUSEL] || DownUsbKeys[MOUSER]) AbilityButton = true;
} else { } else {
if (DownUsbKeys[KB_MOUSEL] || DownUsbKeys[KB_MOUSER]) AttackButton = true; if (DownUsbKeys[MOUSEL] || DownUsbKeys[MOUSER]) AttackButton = true;
} }
if (DownUsbKeys[KB_F5]) AbilityButton = true; if (DownUsbKeys[KS_F5]) AbilityButton = true;
if (DownUsbKeys[KB_LCTRL]) AttackButton = true; if (DownUsbKeys[KS_Control_L]) AttackButton = true;
if (DownUsbKeys[KB_SPACE]) AttackButton = true; if (DownUsbKeys[KS_space]) AttackButton = true;
if (DownUsbKeys[KB_Q]) AttackButton = true; if (DownUsbKeys[KS_Q]) AttackButton = true;
if (DownUsbKeys[KB_C]) ChangeSkillButton = true; if (DownUsbKeys[KS_C]) ChangeSkillButton = true;
if (DownUsbKeys[KB_ENTER]) ItemsButton = true; if (DownUsbKeys[KS_Return]) ItemsButton = true;
if (DownUsbKeys[KB_BKSP]) PauseButton = true; if (DownUsbKeys[KS_BackSpace]) PauseButton = true;
if (DownUsbKeys[KB_F]) SpeedButton = true; if (DownUsbKeys[KS_F]) SpeedButton = true;
if (AbilityButton) J |= VBA_BUTTON_A; if (AbilityButton) J |= VBA_BUTTON_A;
if (AttackButton) J |= VBA_BUTTON_B; if (AttackButton) J |= VBA_BUTTON_B;

View File

@ -129,16 +129,16 @@ void ResetControls(int wiiCtrl)
if(wiiCtrl == CTRLR_KEYBOARD || wiiCtrl == -1) if(wiiCtrl == CTRLR_KEYBOARD || wiiCtrl == -1)
{ {
i=0; i=0;
btnmap[CTRLR_KEYBOARD][i++] = KB_X; // VBA stupidly has B on the right instead of left btnmap[CTRLR_KEYBOARD][i++] = KS_X; // VBA stupidly has B on the right instead of left
btnmap[CTRLR_KEYBOARD][i++] = KB_Z; btnmap[CTRLR_KEYBOARD][i++] = KS_Z;
btnmap[CTRLR_KEYBOARD][i++] = KB_BKSP; btnmap[CTRLR_KEYBOARD][i++] = KS_BackSpace;
btnmap[CTRLR_KEYBOARD][i++] = KB_ENTER; btnmap[CTRLR_KEYBOARD][i++] = KS_Return;
btnmap[CTRLR_KEYBOARD][i++] = KB_UP; btnmap[CTRLR_KEYBOARD][i++] = KS_Up;
btnmap[CTRLR_KEYBOARD][i++] = KB_DOWN; btnmap[CTRLR_KEYBOARD][i++] = KS_Down;
btnmap[CTRLR_KEYBOARD][i++] = KB_LEFT; btnmap[CTRLR_KEYBOARD][i++] = KS_Left;
btnmap[CTRLR_KEYBOARD][i++] = KB_RIGHT; btnmap[CTRLR_KEYBOARD][i++] = KS_Right;
btnmap[CTRLR_KEYBOARD][i++] = KB_A; btnmap[CTRLR_KEYBOARD][i++] = KS_A;
btnmap[CTRLR_KEYBOARD][i++] = KB_S; btnmap[CTRLR_KEYBOARD][i++] = KS_S;
} }
} }
@ -418,10 +418,10 @@ u32 StandardMovement(unsigned short pad)
} }
// Turbo feature, keyboard or gamecube only // Turbo feature, keyboard or gamecube only
if(DownUsbKeys[KB_SPACE]) if(DownUsbKeys[KS_space])
J |= VBA_SPEED; J |= VBA_SPEED;
// Capture feature // Capture feature
if(DownUsbKeys[KB_PRTSC] | DownUsbKeys[KB_F12]) if(DownUsbKeys[KS_Print_Screen] | DownUsbKeys[KS_F12])
J |= VBA_CAPTURE; J |= VBA_CAPTURE;
#endif #endif
return J; return J;
@ -575,29 +575,29 @@ u32 StandardKeyboard(unsigned short pad)
{ {
u32 J = 0; u32 J = 0;
#ifdef HW_RVL #ifdef HW_RVL
if (DownUsbKeys[KB_UP]) if (DownUsbKeys[KS_Up])
J |= VBA_UP; J |= VBA_UP;
if (DownUsbKeys[KB_DOWN]) if (DownUsbKeys[KS_Down])
J |= VBA_DOWN; J |= VBA_DOWN;
if (DownUsbKeys[KB_LEFT]) if (DownUsbKeys[KS_Left])
J |= VBA_LEFT; J |= VBA_LEFT;
if (DownUsbKeys[KB_RIGHT]) if (DownUsbKeys[KS_Right])
J |= VBA_RIGHT; J |= VBA_RIGHT;
if (DownUsbKeys[KB_SPACE]) if (DownUsbKeys[KS_space])
J |= VBA_SPEED; J |= VBA_SPEED;
if (DownUsbKeys[KB_F12] || DownUsbKeys[KB_PRTSC]) if (DownUsbKeys[KS_F12] || DownUsbKeys[KS_Print_Screen])
J |= VBA_CAPTURE; J |= VBA_CAPTURE;
if (DownUsbKeys[KB_X]) if (DownUsbKeys[KS_X])
J |= VBA_BUTTON_A; J |= VBA_BUTTON_A;
if (DownUsbKeys[KB_Z]) if (DownUsbKeys[KS_Z])
J |= VBA_BUTTON_B; J |= VBA_BUTTON_B;
if (DownUsbKeys[KB_A]) if (DownUsbKeys[KS_A])
J |= VBA_BUTTON_L; J |= VBA_BUTTON_L;
if (DownUsbKeys[KB_S]) if (DownUsbKeys[KS_S])
J |= VBA_BUTTON_R; J |= VBA_BUTTON_R;
if (DownUsbKeys[KB_ENTER]) if (DownUsbKeys[KS_Return])
J |= VBA_BUTTON_START; J |= VBA_BUTTON_START;
if (DownUsbKeys[KB_BKSP]) if (DownUsbKeys[KS_BackSpace])
J |= VBA_BUTTON_SELECT; J |= VBA_BUTTON_SELECT;
#endif #endif
return J; return J;
@ -607,13 +607,13 @@ u32 DPadWASD(unsigned short pad)
{ {
u32 J = 0; u32 J = 0;
#ifdef HW_RVL #ifdef HW_RVL
if (DownUsbKeys[KB_W]) if (DownUsbKeys[KS_W])
J |= VBA_UP; J |= VBA_UP;
if (DownUsbKeys[KB_S]) if (DownUsbKeys[KS_S])
J |= VBA_DOWN; J |= VBA_DOWN;
if (DownUsbKeys[KB_A]) if (DownUsbKeys[KS_A])
J |= VBA_LEFT; J |= VBA_LEFT;
if (DownUsbKeys[KB_D]) if (DownUsbKeys[KS_D])
J |= VBA_RIGHT; J |= VBA_RIGHT;
#endif #endif
return J; return J;
@ -623,13 +623,13 @@ u32 DPadArrowKeys(unsigned short pad)
{ {
u32 J = 0; u32 J = 0;
#ifdef HW_RVL #ifdef HW_RVL
if (DownUsbKeys[KB_UP]) if (DownUsbKeys[KS_Up])
J |= VBA_UP; J |= VBA_UP;
if (DownUsbKeys[KB_DOWN]) if (DownUsbKeys[KS_Down])
J |= VBA_DOWN; J |= VBA_DOWN;
if (DownUsbKeys[KB_LEFT]) if (DownUsbKeys[KS_Left])
J |= VBA_LEFT; J |= VBA_LEFT;
if (DownUsbKeys[KB_RIGHT]) if (DownUsbKeys[KS_Right])
J |= VBA_RIGHT; J |= VBA_RIGHT;
#endif #endif
return J; return J;
@ -993,7 +993,7 @@ bool MenuRequested()
(userInput[i].pad.substickX < -70) || (userInput[i].pad.substickX < -70) ||
(userInput[i].wpad.btns_h & WPAD_BUTTON_HOME) || (userInput[i].wpad.btns_h & WPAD_BUTTON_HOME) ||
(userInput[i].wpad.btns_h & WPAD_CLASSIC_BUTTON_HOME) || (userInput[i].wpad.btns_h & WPAD_CLASSIC_BUTTON_HOME) ||
(DownUsbKeys[KB_ESC]) (DownUsbKeys[KS_Escape])
) )
{ {
return true; return true;

View File

@ -40,13 +40,13 @@ u32 LegoStarWars1Input(unsigned short pad) {
OldHealth = Health; OldHealth = Health;
#ifdef HW_RVL #ifdef HW_RVL
if (DownUsbKeys[KB_ENTER]) J |= VBA_BUTTON_START; // start if (DownUsbKeys[KS_Return]) J |= VBA_BUTTON_START; // start
if (DownUsbKeys[KB_K] || DownUsbKeys[KB_LCTRL]) J |= VBA_BUTTON_SELECT; // change chars if (DownUsbKeys[KS_K] || DownUsbKeys[KS_Control_L]) J |= VBA_BUTTON_SELECT; // change chars
if (DownUsbKeys[KB_U]) J |= VBA_BUTTON_A; // jump if (DownUsbKeys[KS_U]) J |= VBA_BUTTON_A; // jump
if (DownUsbKeys[KB_H]) J |= VBA_BUTTON_B; // attack if (DownUsbKeys[KS_H]) J |= VBA_BUTTON_B; // attack
if (DownUsbKeys[KB_J]) J |= VBA_BUTTON_R; // force power, special ability if (DownUsbKeys[KS_J]) J |= VBA_BUTTON_R; // force power, special ability
if (DownUsbKeys[KB_I]) J |= VBA_BUTTON_L; // build, use force (supposed to be J too) if (DownUsbKeys[KS_I]) J |= VBA_BUTTON_L; // build, use force (supposed to be J too)
if (DownUsbKeys[KB_SPACE]) J |= VBA_SPEED; // fast forward if (DownUsbKeys[KS_space]) J |= VBA_SPEED; // fast forward
WPADData * wp = WPAD_Data(pad); WPADData * wp = WPAD_Data(pad);
@ -94,13 +94,13 @@ u32 LegoStarWars2Input(unsigned short pad) {
OldHealth = Health; OldHealth = Health;
#ifdef HW_RVL #ifdef HW_RVL
if (DownUsbKeys[KB_ENTER]) J |= VBA_BUTTON_START; // start if (DownUsbKeys[KS_Return]) J |= VBA_BUTTON_START; // start
if (DownUsbKeys[KB_K] || DownUsbKeys[KB_LCTRL]) J |= VBA_BUTTON_SELECT; // change chars if (DownUsbKeys[KS_K] || DownUsbKeys[KS_Control_L]) J |= VBA_BUTTON_SELECT; // change chars
if (DownUsbKeys[KB_U]) J |= VBA_BUTTON_A; // jump if (DownUsbKeys[KS_U]) J |= VBA_BUTTON_A; // jump
if (DownUsbKeys[KB_H]) J |= VBA_BUTTON_B; // attack if (DownUsbKeys[KS_H]) J |= VBA_BUTTON_B; // attack
if (DownUsbKeys[KB_J]) J |= VBA_BUTTON_L; // force power, special ability if (DownUsbKeys[KS_J]) J |= VBA_BUTTON_L; // force power, special ability
if (DownUsbKeys[KB_I]) J |= VBA_BUTTON_R; // build, use force (supposed to be J too) if (DownUsbKeys[KS_I]) J |= VBA_BUTTON_R; // build, use force (supposed to be J too)
if (DownUsbKeys[KB_SPACE]) J |= VBA_SPEED; // fast forward if (DownUsbKeys[KS_space]) J |= VBA_SPEED; // fast forward
WPADData * wp = WPAD_Data(pad); WPADData * wp = WPAD_Data(pad);
@ -193,7 +193,7 @@ u32 SWObiWanInput(unsigned short pad) {
u32 SWEpisode2Input(unsigned short pad) { u32 SWEpisode2Input(unsigned short pad) {
u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DecodeKeyboard(pad); u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DecodeKeyboard(pad);
// Rumble when they lose health! // Rumble when they lose health!
u8 Health = CPUReadByte(0x3002fb3); u8 Health = CPUReadByte(0x3002fb3);
static u8 OldHealth = 0; static u8 OldHealth = 0;
if (Health < OldHealth) if (Health < OldHealth)
systemGameRumble(6); systemGameRumble(6);
@ -241,7 +241,7 @@ u32 SWEpisode2Input(unsigned short pad) {
u32 SWEpisode3Input(unsigned short pad) { u32 SWEpisode3Input(unsigned short pad) {
u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DecodeKeyboard(pad); u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DecodeKeyboard(pad);
// Rumble when they lose health! // Rumble when they lose health!
u8 Health = 0;//CPUReadByte(0x3002fb3); u8 Health = 0;//CPUReadByte(0x3002fb3);
static u8 OldHealth = 0; static u8 OldHealth = 0;
if (Health < OldHealth) if (Health < OldHealth)
systemGameRumble(6); systemGameRumble(6);
@ -294,7 +294,7 @@ u32 SWEpisode3Input(unsigned short pad) {
u32 SWJediPowerBattlesInput(unsigned short pad) { u32 SWJediPowerBattlesInput(unsigned short pad) {
u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DecodeKeyboard(pad); u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DecodeKeyboard(pad);
// Rumble when they lose health! // Rumble when they lose health!
u8 Health = 0;//CPUReadByte(0x3002fb3); u8 Health = 0;//CPUReadByte(0x3002fb3);
static u8 OldHealth = 0; static u8 OldHealth = 0;
if (Health < OldHealth) if (Health < OldHealth)
systemGameRumble(6); systemGameRumble(6);
@ -347,7 +347,7 @@ u32 SWJediPowerBattlesInput(unsigned short pad) {
u32 SWTrilogyInput(unsigned short pad) { u32 SWTrilogyInput(unsigned short pad) {
u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DecodeKeyboard(pad); u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DecodeKeyboard(pad);
// Rumble when they lose health! // Rumble when they lose health!
u8 Health = 0;//CPUReadByte(0x3002fb3); u8 Health = 0;//CPUReadByte(0x3002fb3);
static u8 OldHealth = 0; static u8 OldHealth = 0;
if (Health < OldHealth) if (Health < OldHealth)
systemGameRumble(6); systemGameRumble(6);
@ -431,7 +431,7 @@ u32 SWEpisode4Input(unsigned short pad) {
} }
// Force // Force
if (wp->btns_h & WPAD_NUNCHUK_BUTTON_Z) { if (wp->btns_h & WPAD_NUNCHUK_BUTTON_Z) {
} }
// Start/Select // Start/Select
if (wp->btns_h & WPAD_BUTTON_PLUS) if (wp->btns_h & WPAD_BUTTON_PLUS)
@ -484,7 +484,7 @@ u32 SWEpisode5Input(unsigned short pad) {
} }
// Force // Force
if (wp->btns_h & WPAD_NUNCHUK_BUTTON_Z) { if (wp->btns_h & WPAD_NUNCHUK_BUTTON_Z) {
} }
// Start/Select // Start/Select
if (wp->btns_h & WPAD_BUTTON_PLUS) if (wp->btns_h & WPAD_BUTTON_PLUS)
@ -537,7 +537,7 @@ u32 SWEpisode6Input(unsigned short pad) {
} }
// Force // Force
if (wp->btns_h & WPAD_NUNCHUK_BUTTON_Z) { if (wp->btns_h & WPAD_NUNCHUK_BUTTON_Z) {
} }
// Start/Select // Start/Select
if (wp->btns_h & WPAD_BUTTON_PLUS) if (wp->btns_h & WPAD_BUTTON_PLUS)
@ -574,7 +574,7 @@ u32 SWYodaStoriesInput(unsigned short pad) {
// Drag object, get out of dialog // Drag object, get out of dialog
if (wp->btns_h & WPAD_BUTTON_A) if (wp->btns_h & WPAD_BUTTON_A)
J |= VBA_BUTTON_B; J |= VBA_BUTTON_B;
// Light saber // Light saber
if (fabs(wp->gforce.x)> 1.5 ) { if (fabs(wp->gforce.x)> 1.5 ) {
// should change weapon here // should change weapon here

View File

@ -153,7 +153,7 @@ void ZeldaAgesCheat()
case 2: case 0xb: case 0x10: case 0x18: case 2: case 0xb: case 0x10: case 0x18:
j++; j++;
break; break;
case 7: case 0x12: case 7: case 0x12:
j+=3; j+=3;
} }
gbWriteMemory(0xC688 + i, j); gbWriteMemory(0xC688 + i, j);
@ -232,14 +232,14 @@ u32 LinksAwakeningInput(unsigned short pad) // aka Zelda DX
// Rumble when they lose health! // Rumble when they lose health!
u8 Health = gbReadMemory(0xDB5A); u8 Health = gbReadMemory(0xDB5A);
static u8 OldHealth = 0; static u8 OldHealth = 0;
if (Health < OldHealth) if (Health < OldHealth)
systemGameRumble(20); systemGameRumble(20);
OldHealth = Health; OldHealth = Health;
bool ActionButton=0, SwordButton=0, ShieldButton=0, PullButton=0, bool ActionButton=0, SwordButton=0, ShieldButton=0, PullButton=0,
ItemsButton=0, QuestButton=0, MapButton=0, SpeedButton=0, CheatButton=0, MidnaButton=0, ItemsButton=0, QuestButton=0, MapButton=0, SpeedButton=0, CheatButton=0, MidnaButton=0,
#ifdef HW_RVL #ifdef HW_RVL
LeftItemButton=0, DownItemButton=0, RightItemButton=0, LeftItemButton=0, DownItemButton=0, RightItemButton=0,
#endif #endif
BItemButton=0, UseLeftItemButton=0, UseRightItemButton=0; BItemButton=0, UseLeftItemButton=0, UseRightItemButton=0;
@ -308,7 +308,7 @@ u32 LinksAwakeningInput(unsigned short pad) // aka Zelda DX
// Must use Wiimote for these buttons // Must use Wiimote for these buttons
CheatButton = wp->btns_d & WPAD_BUTTON_2; CheatButton = wp->btns_d & WPAD_BUTTON_2;
} }
CheatButton = CheatButton || DownUsbKeys[KB_C]; CheatButton = CheatButton || DownUsbKeys[KS_C];
#endif #endif
// Gamecube controls are based on Twilight Princess for the Gamecube // Gamecube controls are based on Twilight Princess for the Gamecube
{ {
@ -498,7 +498,7 @@ u32 LinksAwakeningInput(unsigned short pad) // aka Zelda DX
if (ItemsButton) { if (ItemsButton) {
if (QuestScreen) QuestScreen = false; if (QuestScreen) QuestScreen = false;
else J |= VBA_BUTTON_START; else J |= VBA_BUTTON_START;
} }
// Quest Status // Quest Status
if (QuestButton) { if (QuestButton) {
StartCount = 80; StartCount = 80;
@ -530,7 +530,7 @@ u32 LinksAwakeningInput(unsigned short pad) // aka Zelda DX
J |= VBA_SPEED; J |= VBA_SPEED;
QuestScreen = false; QuestScreen = false;
} }
return J; return J;
} }
@ -543,7 +543,7 @@ static u32 ZeldaOracleInput(bool Seasons, unsigned short pad) {
// There is Zelda 1 & 2 for Wii VC wiimote but it doesn't make sense to use their controls, // There is Zelda 1 & 2 for Wii VC wiimote but it doesn't make sense to use their controls,
// so let user choose sideways wiimote controls. // so let user choose sideways wiimote controls.
u32 J = StandardMovement(pad) | DecodeKeyboard(pad) | DecodeWiimote(pad); u32 J = StandardMovement(pad) | DecodeKeyboard(pad) | DecodeWiimote(pad);
// Rumble when they lose health! // Rumble when they lose health!
u8 Health; u8 Health;
if (Seasons) Health = gbReadMemory(0xC6A2); // health in quarters... note C6A3 is max health if (Seasons) Health = gbReadMemory(0xC6A2); // health in quarters... note C6A3 is max health
@ -556,29 +556,29 @@ static u32 ZeldaOracleInput(bool Seasons, unsigned short pad) {
static int DesiredSubscreen = -1; static int DesiredSubscreen = -1;
int Subscreen = 0; int Subscreen = 0;
switch (gbReadMemory(0xCBCB)) { switch (gbReadMemory(0xCBCB)) {
case 0: case 0:
Subscreen = 0; Subscreen = 0;
break; break;
case 1: case 1:
Subscreen = 1+gbReadMemory(0xCBCF); Subscreen = 1+gbReadMemory(0xCBCF);
break; break;
case 2: case 2:
Subscreen = 4; Subscreen = 4;
break; break;
case 3: case 3:
Subscreen = 5; Subscreen = 5;
break; break;
} }
bool ActionButton=0, SwordButton=0, ShieldButton=0, PullButton=0, bool ActionButton=0, SwordButton=0, ShieldButton=0, PullButton=0,
ItemsButton=0, QuestButton=0, MapButton=0, SpeedButton=0, CheatButton=0, MidnaButton=0, ItemsButton=0, QuestButton=0, MapButton=0, SpeedButton=0, CheatButton=0, MidnaButton=0,
#ifdef HW_RVL #ifdef HW_RVL
LeftItemButton=0, DownItemButton=0, RightItemButton=0, BItemButton=0, LeftItemButton=0, DownItemButton=0, RightItemButton=0, BItemButton=0,
#endif #endif
UseLeftItemButton=0, UseRightItemButton=0; UseLeftItemButton=0, UseRightItemButton=0;
bool OnItemScreen = (Subscreen == 1); bool OnItemScreen = (Subscreen == 1);
#ifdef HW_RVL #ifdef HW_RVL
static int SwordCount = 0; static int SwordCount = 0;
WPADData * wp = WPAD_Data(pad); WPADData * wp = WPAD_Data(pad);
@ -639,7 +639,7 @@ static u32 ZeldaOracleInput(bool Seasons, unsigned short pad) {
// Must use Wiimote for these buttons // Must use Wiimote for these buttons
CheatButton = wp->btns_d & WPAD_BUTTON_2; CheatButton = wp->btns_d & WPAD_BUTTON_2;
} }
CheatButton = CheatButton || DownUsbKeys[KB_C]; CheatButton = CheatButton || DownUsbKeys[KS_C];
#endif #endif
// Gamecube controls are based on Twilight Princess for the Gamecube // Gamecube controls are based on Twilight Princess for the Gamecube
{ {
@ -814,16 +814,16 @@ static u32 ZeldaOracleInput(bool Seasons, unsigned short pad) {
if (Seasons) ZeldaSeasonsCheat(); if (Seasons) ZeldaSeasonsCheat();
else ZeldaAgesCheat(); else ZeldaAgesCheat();
} }
if (DesiredSubscreen == Subscreen) if (DesiredSubscreen == Subscreen)
DesiredSubscreen = -1; DesiredSubscreen = -1;
static int OldSubscreen = 0; static int OldSubscreen = 0;
if (Subscreen != OldSubscreen) { if (Subscreen != OldSubscreen) {
if (Subscreen==1) DelayCount = 80; // wait for items screen to fade in if (Subscreen==1) DelayCount = 80; // wait for items screen to fade in
else DelayCount = 20; // wait to swap subscreens else DelayCount = 20; // wait to swap subscreens
} }
OldSubscreen = Subscreen; OldSubscreen = Subscreen;
if (DelayCount > 0) { if (DelayCount > 0) {
// do nothing // do nothing
DelayCount--; DelayCount--;
@ -951,7 +951,7 @@ u32 MinishCapInput(unsigned short pad)
bool ActionButton=0, SwordButton=0, ShieldButton=0, PullButton=0, bool ActionButton=0, SwordButton=0, ShieldButton=0, PullButton=0,
ItemsButton=0, QuestButton=0, MapButton=0, SpeedButton=0, CheatButton=0, MidnaButton=0, ItemsButton=0, QuestButton=0, MapButton=0, SpeedButton=0, CheatButton=0, MidnaButton=0,
LeftItemButton=0, DownItemButton=0, RightItemButton=0, LeftItemButton=0, DownItemButton=0, RightItemButton=0,
BItemButton=0, UseLeftItemButton=0, UseRightItemButton=0; BItemButton=0, UseLeftItemButton=0, UseRightItemButton=0;
@ -1172,7 +1172,7 @@ u32 MinishCapInput(unsigned short pad)
} }
OldCursorRow = CursorRow; OldCursorRow = CursorRow;
OldCursorCol = CursorCol; OldCursorCol = CursorCol;
static int SwordCount = 0; static int SwordCount = 0;
// Nunchuk controls are based on Twilight Princess for the Wii // Nunchuk controls are based on Twilight Princess for the Wii
if (wp->exp.type == WPAD_EXP_NUNCHUK) { if (wp->exp.type == WPAD_EXP_NUNCHUK) {
@ -1235,7 +1235,7 @@ u32 MinishCapInput(unsigned short pad)
// Must use Wiimote for these buttons // Must use Wiimote for these buttons
CheatButton = wp->btns_h & WPAD_BUTTON_2; CheatButton = wp->btns_h & WPAD_BUTTON_2;
} }
CheatButton = CheatButton || DownUsbKeys[KB_C]; CheatButton = CheatButton || DownUsbKeys[KS_C];
#endif #endif
// Gamecube controls are based on Twilight Princess for the Gamecube // Gamecube controls are based on Twilight Princess for the Gamecube
{ {
@ -1446,7 +1446,7 @@ u32 MinishCapInput(unsigned short pad)
// Camera (use as extra way of pressing A without using DPad) // Camera (use as extra way of pressing A without using DPad)
if (SpeedButton) if (SpeedButton)
J |= VBA_BUTTON_A; J |= VBA_BUTTON_A;
// Pull (I was going to check RButtonAction, but the in-game text always tells you to // Pull (I was going to check RButtonAction, but the in-game text always tells you to
// use R as the action button, so let's just make Gamecube R = Gameboy R) // use R as the action button, so let's just make Gamecube R = Gameboy R)
if (PullButton) if (PullButton)
J |= VBA_BUTTON_R; J |= VBA_BUTTON_R;

View File

@ -2250,7 +2250,7 @@ ButtonMappingWindow()
} }
} }
if(userInput[0].wpad.btns_d == WPAD_BUTTON_HOME) if(userInput[0].wpad.btns_d == WPAD_BUTTON_HOME)
pressed = KB_ESC; pressed = KS_Escape;
} }
else else
{ {
@ -2283,7 +2283,7 @@ ButtonMappingWindow()
} }
if(mapMenuCtrl == CTRLR_KEYBOARD) { if(mapMenuCtrl == CTRLR_KEYBOARD) {
if (pressed == KB_ESC) if (pressed == KS_Escape)
pressed = 0; pressed = 0;
} else if(pressed == WPAD_BUTTON_HOME || pressed == WPAD_CLASSIC_BUTTON_HOME) } else if(pressed == WPAD_BUTTON_HOME || pressed == WPAD_CLASSIC_BUTTON_HOME)
pressed = 0; pressed = 0;

View File

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* Visual Boy Advance GX * Visual Boy Advance GX
* *
* Carl Kenner February 2009 * Tantric August 2009
* *
* wiiusbsupport.cpp * wiiusbsupport.cpp
* *
@ -17,348 +17,96 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <malloc.h> #include <malloc.h>
#include <ogc/usbmouse.h>
#include <wiikeyboard/keyboard.h>
#include "wiiusbsupport.h" #include "wiiusbsupport.h"
u16 DownUsbKeys[65536];
#ifdef HW_RVL #ifdef HW_RVL
#define USB_CLASS_HID 0x03 static lwp_t eventthread = LWP_THREAD_NULL;
#define USB_SUBCLASS_BOOT 0x01
#define USB_PROTOCOL_KEYBOARD 0x01
#define USB_PROTOCOL_MOUSE 0x02
static int mouse_vid = 0; u16 DownUsbShiftKeys = 0;
static int mouse_pid = 0;
#define DEVLIST_MAXSIZE 0x08
#define USB_REQ_GETPROTOCOL 0x03
#define USB_REQ_SETPROTOCOL 0x0B
#define USB_REQ_GETREPORT 0x01
#define USB_REQ_SETREPORT 0x09
#define USB_REPTYPE_INPUT 0x01
#define USB_REPTYPE_OUTPUT 0x02
#define USB_REPTYPE_FEATURE 0x03
#define USB_REQTYPE_GET 0xA1
#define USB_REQTYPE_SET 0x21
static u8 mouseconfiguration = 0;
static u32 mouseinterface = 0;
static u32 mousealtInterface = 0;
u8 DownUsbKeys[256];
u8 DownUsbShiftKeys = 0;
s32 MouseDirectInputX = 0; s32 MouseDirectInputX = 0;
s32 MouseDirectInputY = 0; s32 MouseDirectInputY = 0;
static bool KeyboardStarted=false, MouseStarted=false; static void KeyPress(u16 key)
static s32 KeyboardHandle=0, MouseHandle=0;
typedef struct
{ {
u32 message; if(key >= 0x61 && key <= 0x7a) // lowercase letter
u32 id; // direction DownUsbKeys[key-32] = 1; // press the uppercase letter too
u8 modifiers; else if(key >= 0x41 && key <= 0x5a) // uppercase letter
u8 unknown; DownUsbKeys[key+32] = 1; // press the lowercase letter too
u8 keys[6];
u8 pad[16];
}TKeyData;
static TKeyData KeyData ATTRIBUTE_ALIGN(32);
static signed char *MouseData = NULL;
static u8 OldKeys[6];
static u8 OldShiftKeys;
static bool StopKeyboard = true;
void KeyPress(u8 key)
{
DownUsbKeys[key] = 1; DownUsbKeys[key] = 1;
} }
void KeyRelease(u8 key)
static void KeyRelease(u16 key)
{ {
if(key >= 0x61 && key <= 0x7a) // lowercase letter
DownUsbKeys[key-32] = 0; // unpress the uppercase letter too
else if(key >= 0x41 && key <= 0x5a) // uppercase letter
DownUsbKeys[key+32] = 0; // unpress the lowercase letter too
DownUsbKeys[key] = 0; DownUsbKeys[key] = 0;
} }
static void * eventcallback(void *arg)
{
s32 stat;
s32 mstat;
keyboard_event ke;
mouse_event me;
while(1)
{
stat = KEYBOARD_GetEvent(&ke);
mstat = MOUSE_GetEvent(&me);
if (stat)
{
if(ke.type == KEYBOARD_PRESSED)
KeyPress(ke.symbol);
else if(ke.type == KEYBOARD_RELEASED)
KeyRelease(ke.symbol);
}
if (mstat)
{
MouseDirectInputX += me.rx;
MouseDirectInputY += me.ry;
DownUsbKeys[MOUSEL] = (me.button & 1);
DownUsbKeys[MOUSER] = (me.button & 2);
DownUsbKeys[MOUSEM] = (me.button & 4);
}
usleep(10000);
}
return NULL;
}
bool AnyKeyDown() bool AnyKeyDown()
{ {
int i; for (int i=0; i<65536; i++)
for (i=4; i<=231;i++)
{ {
if (DownUsbKeys[i]) return true; if (DownUsbKeys[i])
return true;
} }
return false; return false;
} }
s32 KeyboardCallback(int ret,void * none)
{
if (KeyboardHandle<0 || KeyData.message==0x7fffffff)
return 0;
if(KeyData.message==0)
{
// keyboard connected!
}
else if(KeyData.message==1)
{
// keyboard disconnected!
}
else if(KeyData.message==2)
{
// key event
DownUsbShiftKeys = KeyData.modifiers;
u8 p = DownUsbShiftKeys & (~OldShiftKeys);
if (p & 0x01) KeyPress(KB_LCTRL);
if (p & 0x02) KeyPress(KB_LSHIFT);
if (p & 0x04) KeyPress(KB_LALT);
if (p & 0x08) KeyPress(KB_LWIN);
if (p & 0x10) KeyPress(KB_RCTRL);
if (p & 0x20) KeyPress(KB_RSHIFT);
if (p & 0x40) KeyPress(KB_RALT);
if (p & 0x80) KeyPress(KB_RWIN);
p = OldShiftKeys & (~DownUsbShiftKeys);
if (p & 0x01) KeyRelease(KB_LCTRL);
if (p & 0x02) KeyRelease(KB_LSHIFT);
if (p & 0x04) KeyRelease(KB_LALT);
if (p & 0x08) KeyRelease(KB_LWIN);
if (p & 0x10) KeyRelease(KB_RCTRL);
if (p & 0x20) KeyRelease(KB_RSHIFT);
if (p & 0x40) KeyRelease(KB_RALT);
if (p & 0x80) KeyRelease(KB_RWIN);
// check each key to see if is in the list of old keys, if not it was pressed
for (int i=0; i<6; i++)
{
if (KeyData.keys[i]==1)
{
break; // too many keys held down at once, so no key data except modifiers
}
else if (KeyData.keys[i])
{
bool found = false;
for (int old=0; old<6; old++)
{
if (OldKeys[old]==KeyData.keys[i])
{
found = true;
break;
}
}
if (!found) KeyPress(KeyData.keys[i]);
}
}
// check each old key to see if is in the list of keys, if not it was released
for (int old=0; old<6; old++)
{
if (OldKeys[old])
{
bool found = false;
for (int i=0; i<6; i++)
{
if (OldKeys[old]==KeyData.keys[i])
{
found = true;
break;
}
}
if (!found) KeyRelease(OldKeys[old]);
}
}
// Update old keys, unless too many keys were held down
if (KeyData.keys[0]!=1)
memcpy(OldKeys, KeyData.keys, 6);
OldShiftKeys = DownUsbShiftKeys;
}
// no keyboard message
KeyData.message=0x7fffffff;
// Request another keyboard message when one is ready
if (!StopKeyboard)
IOS_IoctlAsync(KeyboardHandle,1,(void *) &KeyData, 16,(void *) &KeyData, 16, KeyboardCallback, NULL);
return 0;
}
void StartWiiKeyboardMouse() void StartWiiKeyboardMouse()
{ {
memset(DownUsbKeys, 0, sizeof(DownUsbKeys)); memset(DownUsbKeys, 0, sizeof(DownUsbKeys));
if (!KeyboardStarted) MOUSE_Init();
{ KEYBOARD_Init(NULL);
USB_Initialize(); if(eventthread == LWP_THREAD_NULL)
StartWiiMouse(); LWP_CreateThread(&eventthread, eventcallback, NULL, NULL, 0, 80);
KeyboardHandle=IOS_Open("/dev/usb/kbd", 1);
if (KeyboardHandle<0)
{
// Error!
}
//sleep(2);
KeyData.message=0x7fffffff;
StopKeyboard = false;
if(KeyboardHandle>=0)
IOS_IoctlAsync(KeyboardHandle,1,(void *) &KeyData, 16,(void *) &KeyData, 16, KeyboardCallback, NULL);
KeyboardStarted = true;
}
else
{
if(KeyboardHandle>=0)
IOS_IoctlAsync(KeyboardHandle,1,(void *) &KeyData, 16,(void *) &KeyData, 16, KeyboardCallback, NULL);
}
}
void StopWiiKeyboard()
{
StopKeyboard = true;
IOS_Close(KeyboardHandle);
}
s32 MouseCallback(s32 result, void *usrdata)
{
if (result>0)
{
u8 button = MouseData[0];
int deltax = (s8)MouseData[1];
int deltay = (s8)MouseData[2];
MouseDirectInputX += deltax;
MouseDirectInputY += deltay;
DownUsbKeys[KB_MOUSEL] = (button & 1);
DownUsbKeys[KB_MOUSER] = (button & 2);
DownUsbKeys[KB_MOUSEM] = (button & 4);
USB_ReadIntrMsgAsync(MouseHandle, 0x81, 4, MouseData, MouseCallback, 0);
}
else
{
MouseStarted=0;
MouseHandle=0;
}
return 0;
}
static int wii_find_mouse()
{
s32 fd=0;
static u8 *buffer = 0;
if (!buffer)
{
buffer = (u8*)memalign(32, DEVLIST_MAXSIZE << 3);
}
if(buffer == NULL)
{
return -1;
}
memset(buffer, 0, DEVLIST_MAXSIZE << 3);
u8 dummy;
u16 vid,pid;
if (USB_GetDeviceList("/dev/usb/oh0", buffer, DEVLIST_MAXSIZE, 0, &dummy) < 0)
{
free(buffer);
buffer =0;
return -2;
}
u8 mouseep;
u32 mouseep_size;
int i;
for(i = 0; i < DEVLIST_MAXSIZE; i++)
{
memcpy(&vid, (buffer + (i << 3) + 4), 2);
memcpy(&pid, (buffer + (i << 3) + 6), 2);
if ((vid==0)&&(pid==0))
continue;
fd =0;
int err = USB_OpenDevice("oh0",vid,pid,&fd);
if (err<0)
{
continue;
}
else
{
// error!
}
u32 iConf, iInterface;
usb_devdesc udd;
usb_configurationdesc *ucd;
usb_interfacedesc *uid;
usb_endpointdesc *ued;
USB_GetDescriptors(fd, &udd);
for(iConf = 0; iConf < udd.bNumConfigurations; iConf++)
{
ucd = &udd.configurations[iConf];
for(iInterface = 0; iInterface < ucd->bNumInterfaces; iInterface++)
{
uid = &ucd->interfaces[iInterface];
if ( (uid->bInterfaceClass == USB_CLASS_HID) && (uid->bInterfaceSubClass == USB_SUBCLASS_BOOT) &&
(uid->bInterfaceProtocol== USB_PROTOCOL_MOUSE))
{
int iEp;
for(iEp = 0; iEp < uid->bNumEndpoints; iEp++)
{
ued = &uid->endpoints[iEp];
mouse_vid = vid;
mouse_pid = pid;
mouseep = ued->bEndpointAddress;
mouseep_size = ued->wMaxPacketSize;
mouseconfiguration = ucd->bConfigurationValue;
mouseinterface = uid->bInterfaceNumber;
mousealtInterface = uid->bAlternateSetting;
}
break;
}
}
}
USB_FreeDescriptors(&udd);
USB_CloseDevice(&fd);
}
if (mouse_pid!=0 || mouse_vid!=0) return 0;
return -1;
}
void StartWiiMouse()
{
if (!MouseStarted)
{
if (wii_find_mouse()!=0) return;
if (USB_OpenDevice("oh0", mouse_vid, mouse_pid, &MouseHandle)<0)
{
return;
}
if (!MouseData)
{
MouseData = (signed char*)memalign(32, 20);
}
//set boot protocol
USB_WriteCtrlMsg(MouseHandle,USB_REQTYPE_SET,USB_REQ_SETPROTOCOL,0,0,0,0);
USB_ReadIntrMsgAsync(MouseHandle, 0x81, 4, MouseData, MouseCallback, 0);
MouseStarted=true;
}
} }
#else // GameCube stub #else // GameCube stub
u8 DownUsbKeys[256];
bool AnyKeyDown() bool AnyKeyDown()
{ {
return false; return false;

View File

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* Visual Boy Advance GX * Visual Boy Advance GX
* *
* Carl Kenner Febuary 2009 * Tantric August 2009
* *
* wiiusbsupport.h * wiiusbsupport.h
* *
@ -11,74 +11,16 @@
#ifndef _WIIUSBSUPPORT_H_ #ifndef _WIIUSBSUPPORT_H_
#define _WIIUSBSUPPORT_H_ #define _WIIUSBSUPPORT_H_
#define KB_A 4 #include <wiikeyboard/wsksymdef.h>
#define KB_B 5
#define KB_C 6 #define MOUSEL 65533
#define KB_D 7 #define MOUSER 65534
#define KB_E 8 #define MOUSEM 65535
#define KB_F 9
#define KB_G 10
#define KB_H 11
#define KB_I 12
#define KB_J 13
#define KB_K 14
#define KB_L 15
#define KB_M 16
#define KB_N 17
#define KB_O 18
#define KB_P 19
#define KB_Q 20
#define KB_R 21
#define KB_S 22
#define KB_T 23
#define KB_U 24
#define KB_V 25
#define KB_W 26
#define KB_X 27
#define KB_Y 28
#define KB_Z 29
#define KB_ENTER 40
#define KB_ESC 41
#define KB_BKSP 42
#define KB_TAB 43
#define KB_SPACE 44
#define KB_F1 58
#define KB_F2 59
#define KB_F3 60
#define KB_F4 61
#define KB_F5 62
#define KB_F6 63
#define KB_F7 64
#define KB_F8 65
#define KB_F9 66
#define KB_F10 67
#define KB_F11 68
#define KB_F12 69
#define KB_PRTSC 70
#define KB_SCRLK 71
#define KB_PAUSE 72
#define KB_RIGHT 79
#define KB_LEFT 80
#define KB_DOWN 81
#define KB_UP 82
#define KB_LCTRL 224
#define KB_LSHIFT 225
#define KB_LALT 226
#define KB_LWIN 227
#define KB_RCTRL 228
#define KB_RSHIFT 229
#define KB_RALT 230
#define KB_RWIN 231
#define KB_MOUSEL 232
#define KB_MOUSER 233
#define KB_MOUSEM 234
void StartWiiKeyboardMouse(); void StartWiiKeyboardMouse();
void StopWiiKeyboard();
bool AnyKeyDown(); bool AnyKeyDown();
void StartWiiMouse();
extern u8 DownUsbKeys[256]; extern u16 DownUsbKeys[65536];
extern u8 DownUsbShiftKeys; extern u16 DownUsbShiftKeys;
#endif #endif