From 306b5437f3524c7017a8026b563349529894c850 Mon Sep 17 00:00:00 2001 From: dborth Date: Thu, 11 Mar 2010 06:04:53 +0000 Subject: [PATCH] add usb2/dvd support via ios 202, kill dvdx/keyboard/mouse support --- Makefile.wii | 9 +- readme.txt | 22 +- source/ngc/button_mapping.c | 76 +----- source/ngc/button_mapping.h | 13 +- source/ngc/filebrowser.cpp | 1 - source/ngc/fileop.cpp | 8 + source/ngc/gameinput.cpp | 136 +++------- source/ngc/gameinput.h | 4 - source/ngc/input.cpp | 116 +------- source/ngc/input.h | 2 +- source/ngc/inputmario.cpp | 19 +- source/ngc/inputmetroid.cpp | 9 +- source/ngc/inputmortalkombat.cpp | 3 +- source/ngc/inputstarwars.cpp | 41 +-- source/ngc/inputzelda.cpp | 15 +- source/ngc/menu.cpp | 54 +--- source/ngc/preferences.cpp | 2 - source/ngc/utils/ehcmodule_elf.h | 3 + source/ngc/utils/mload.c | 276 +++++++++++++++++++ source/ngc/utils/mload.h | 33 +++ source/ngc/utils/usb2storage.c | 451 +++++++++++++++++++++++++++++++ source/ngc/utils/usb2storage.h | 16 ++ source/ngc/vba.cpp | 58 +++- source/ngc/wiiusbsupport.cpp | 119 -------- source/ngc/wiiusbsupport.h | 26 -- 25 files changed, 937 insertions(+), 575 deletions(-) create mode 100644 source/ngc/utils/ehcmodule_elf.h create mode 100644 source/ngc/utils/mload.c create mode 100644 source/ngc/utils/mload.h create mode 100644 source/ngc/utils/usb2storage.c create mode 100644 source/ngc/utils/usb2storage.h delete mode 100644 source/ngc/wiiusbsupport.cpp delete mode 100644 source/ngc/wiiusbsupport.h diff --git a/Makefile.wii b/Makefile.wii index f55d5a6..3f8d71e 100644 --- a/Makefile.wii +++ b/Makefile.wii @@ -19,7 +19,7 @@ TARGET := vbagx_wii TARGETDIR := executables BUILD := build_wii SOURCES := source/ngc/images source/ngc/sounds source/ngc/fonts source/ngc/lang \ - source/ngc/gui source/ngc source/sz source/unzip \ + source/ngc/gui source/ngc/utils source/ngc source/sz source/unzip \ source/vba source/vba/apu source/vba/common \ source/vba/gb source/vba/gba INCLUDES := source/vba source/ngc source/unzip @@ -41,8 +41,8 @@ LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map -Wl,--cref #--------------------------------------------------------------------------------- # any extra libraries we wish to link with #--------------------------------------------------------------------------------- -LIBS := -ldb -ldi -liso9660 -lpng -lmxml -lwiikeyboard \ - -lfat -lwiiuse -lz -lbte -lasnd -logc -lvorbisidec -lfreetype -ltinysmb +LIBS := -ldi -liso9660 -lpng -lmxml -lfat -lwiiuse -lz -lbte -lasnd -logc \ + -lvorbisidec -lfreetype -ltinysmb #--------------------------------------------------------------------------------- # list of directories containing libraries, this must be the top level containing @@ -90,7 +90,8 @@ export OFILES := $(addsuffix .o,$(BINFILES)) \ $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \ $(TTFFILES:.ttf=.ttf.o) $(LANGFILES:.lang=.lang.o) \ $(PNGFILES:.png=.png.o) \ - $(OGGFILES:.ogg=.ogg.o) $(PCMFILES:.pcm=.pcm.o) + $(OGGFILES:.ogg=.ogg.o) $(PCMFILES:.pcm=.pcm.o) \ + $(CURDIR)/source/ngc/utils/ehcmodule.elf.o #--------------------------------------------------------------------------------- # build a list of include paths diff --git a/readme.txt b/readme.txt index 35e1c03..1cc94db 100644 --- a/readme.txt +++ b/readme.txt @@ -12,7 +12,7 @@ With it you can play GBA/Game Boy Color/Game Boy games on your Wii/GameCube. -=[ Features ]=- -* Wiimote, Nunchuk, Classic, Gamecube controller, Keyboard and Mouse support +* Wiimote, Nunchuk, Classic, and Gamecube controller support * Rotation sensors, Solar sensors, and Rumble support * Optional special Wii controls built-in for some games * SRAM and State saving @@ -320,10 +320,6 @@ This document doesn't cover how to do any of that. ח–­—–­—–­—–­ –­—–­—–­—–­—–­—–­—–­—–­—–­—–­— ­—–­—–­—–­—–­—–­—–­—–­—-­—–­-–•Ĵ |0O×ĝo· INSTRUCTIONS ·oĝ×O0| `¨•¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨' -Note! A USB Mouse must be plugged in before starting the emulator, or it -won't be recognised. A mouse or keyboard is not required. Keyboards might or -might not need to be unplugged and replugged to work. - If you have upgraded from a previous version, the emulator may start with a message that your preferences have been reset. You will need to set your preferences how you want them. @@ -337,8 +333,6 @@ with the A button. Press the B button to swap between controlling a list box and controlling the buttons. Pressing the Home button will exit from the main menu. You can choose what exiting will do by using the settings menu. -Keyboard and mouse do not work in the menu yet. - Click on the logo to see the credits. When choosing a file, use left and right to go up or down a page. @@ -424,18 +418,9 @@ B = Gameboy B Button R = Gameboy R Button L = Gameboy L Button -Keyboard: -X = Gameboy A Button -Z = Gameboy B Button -S = Gameboy R Button -A = Gameboy L Button -Enter = Gameboy Start Button -Backspace = Gameboy Select Button -Space = Fast forward - You can configure the controls how you want from the controls menu. Different controls will be used depending on what you have plugged into the Wii Remote. -Nunchuk means Nunchuk + Wii Remote. Gamecube controllers and Keyboards can +Nunchuk means Nunchuk + Wii Remote. Gamecube controllers can be used at the same time as Wii Remotes and all control the same player. When configuring controls, press HOME to cancel. @@ -829,8 +814,7 @@ C = Change characters, talk to people Turn "Match Wii Controls" ON to use these controls. All the Harry Potter games use the same controls as Harry Potter & The Order -Of The Phoenix on the Wii. They also use the keyboard controls from the PC -version of each game. Spell gestures are not supported yet. +Of The Phoenix on the Wii. Spell gestures are not supported yet. The Harry Potter Wii controls are: ================================== diff --git a/source/ngc/button_mapping.c b/source/ngc/button_mapping.c index 3d34293..84543fc 100644 --- a/source/ngc/button_mapping.c +++ b/source/ngc/button_mapping.c @@ -17,7 +17,6 @@ #include #include "button_mapping.h" -#include "wiiusbsupport.h" /**************************************************************************** * Controller Button Descriptions: @@ -25,7 +24,7 @@ * and for displaying the name of said button ***************************************************************************/ -CtrlrMap ctrlr_def[5] = { +CtrlrMap ctrlr_def[4] = { // Gamecube controller btn def { { @@ -113,78 +112,5 @@ CtrlrMap ctrlr_def[5] = { }, 15, CTRLR_CLASSIC -}, -// Keyboard btn def -{ - { - {KS_A, "A"}, - {KS_B, "B"}, - {KS_C, "C"}, - {KS_D, "D"}, - {KS_E, "E"}, - {KS_F, "F"}, - {KS_G, "G"}, - {KS_H, "H"}, - {KS_I, "I"}, - {KS_J, "J"}, - {KS_K, "K"}, - {KS_L, "L"}, - {KS_M, "M"}, - {KS_N, "N"}, - {KS_O, "O"}, - {KS_P, "P"}, - {KS_Q, "Q"}, - {KS_R, "R"}, - {KS_S, "S"}, - {KS_T, "T"}, - {KS_U, "U"}, - {KS_V, "V"}, - {KS_W, "W"}, - {KS_X, "X"}, - {KS_Y, "Y"}, - {KS_Z, "Z"}, - {KS_1, "1"}, - {KS_2, "2"}, - {KS_3, "3"}, - {KS_4, "4"}, - {KS_5, "5"}, - {KS_6, "6"}, - {KS_7, "7"}, - {KS_8, "8"}, - {KS_9, "9"}, - {KS_0, "0"}, - {KS_Return, "ENTER"}, - {KS_Escape, "ESC"}, - {KS_BackSpace, "BKSP"}, - {KS_Tab, "TAB"}, - {KS_space, "SPACE"}, - {KS_F1, "F1"}, - {KS_F2, "F2"}, - {KS_F3, "F3"}, - {KS_F4, "F4"}, - {KS_F5, "F5"}, - {KS_F6, "F6"}, - {KS_F7, "F7"}, - {KS_F8, "F8"}, - {KS_F9, "F9"}, - {KS_F10, "F10"}, - {KS_F11, "F11"}, - {KS_F12, "F12"}, - {KS_Right, "RIGHT"}, - {KS_Left, "LEFT"}, - {KS_Down, "DOWN"}, - {KS_Up, "UP"}, - {KS_Control_L, "LCTRL"}, - {KS_Shift_L, "LSHFT"}, - {KS_Alt_L, "LALT"}, - {KS_Control_R, "RCTRL"}, - {KS_Shift_R, "RSHFT"}, - {KS_Alt_R, "RALT"}, - {MOUSEL, "MOUSEL"}, - {MOUSER, "MOUSER"}, - {MOUSEM, "MOUSEM"} - }, - 66, - CTRLR_KEYBOARD } }; diff --git a/source/ngc/button_mapping.h b/source/ngc/button_mapping.h index 3d430d8..151274a 100644 --- a/source/ngc/button_mapping.h +++ b/source/ngc/button_mapping.h @@ -16,12 +16,11 @@ enum { CTRLR_GCPAD, CTRLR_WIIMOTE, CTRLR_NUNCHUK, - CTRLR_CLASSIC, - CTRLR_KEYBOARD + CTRLR_CLASSIC }; -const char ctrlrName[5][20] = -{ "GameCube Controller", "Wiimote", "Nunchuk + Wiimote", "Classic Controller", "Keyboard & Mouse" }; +const char ctrlrName[4][20] = +{ "GameCube Controller", "Wiimote", "Nunchuk + Wiimote", "Classic Controller" }; typedef struct _btn_map { u32 btn; // button 'id' @@ -29,13 +28,11 @@ typedef struct _btn_map { } BtnMap; typedef struct _ctrlr_map { - BtnMap map[150]; // controller button map + BtnMap map[15]; // controller button map int num_btns; // number of buttons on the controller u16 type; // controller type } CtrlrMap; -// externs: - -extern CtrlrMap ctrlr_def[5]; +extern CtrlrMap ctrlr_def[4]; #endif diff --git a/source/ngc/filebrowser.cpp b/source/ngc/filebrowser.cpp index 2475dcf..49b6a72 100644 --- a/source/ngc/filebrowser.cpp +++ b/source/ngc/filebrowser.cpp @@ -30,7 +30,6 @@ #include "fileop.h" #include "input.h" #include "gcunzip.h" -#include "wiiusbsupport.h" BROWSERINFO browser; BROWSERENTRY * browserList = NULL; // list of files/folders in browser diff --git a/source/ngc/fileop.cpp b/source/ngc/fileop.cpp index 9fbe940..518750f 100644 --- a/source/ngc/fileop.cpp +++ b/source/ngc/fileop.cpp @@ -319,6 +319,14 @@ void MountAllFAT() ***************************************************************************/ bool MountDVD(bool silent) { + #ifdef HW_RVL + if(IOS_GetVersion() != 202) + { + ErrorPrompt("Please install IOS 202 for DVD support."); + return false; + } + #endif + bool mounted = false; int retry = 1; diff --git a/source/ngc/gameinput.cpp b/source/ngc/gameinput.cpp index cdd3fda..29c8cf0 100644 --- a/source/ngc/gameinput.cpp +++ b/source/ngc/gameinput.cpp @@ -17,7 +17,6 @@ #include #include #include -#include #include "vba.h" #include "button_mapping.h" @@ -26,7 +25,6 @@ #include "input.h" #include "gameinput.h" #include "vbasupport.h" -#include "wiiusbsupport.h" #include "gba/GBA.h" #include "gba/bios.h" #include "gba/GBAinline.h" @@ -43,7 +41,7 @@ void DebugPrintf(const char *format, ...) { } u32 TMNTInput(unsigned short pad) { - u32 J = StandardMovement(pad) | StandardDPad(pad) | DecodeKeyboard(pad); + u32 J = StandardMovement(pad) | StandardDPad(pad); static u32 LastDir = VBA_RIGHT; static bool wait = false; static int holdcount = 0; @@ -152,7 +150,7 @@ u32 TMNTInput(unsigned short pad) { } u32 TMNT1Input(unsigned short pad) { - u32 J = StandardMovement(pad) | StandardDPad(pad) | DecodeKeyboard(pad); + u32 J = StandardMovement(pad) | StandardDPad(pad); static u32 LastDir = VBA_RIGHT; bool Jump=0, Attack=0, SpinKick=0, Roll=0, Pause=0, Select=0; @@ -233,7 +231,7 @@ u32 TMNT1Input(unsigned short pad) { } u32 TMNT2Input(unsigned short pad) { - u32 J = StandardMovement(pad) | StandardDPad(pad) | DecodeKeyboard(pad); + u32 J = StandardMovement(pad) | StandardDPad(pad); static u32 LastDir = VBA_RIGHT; bool Jump=0, Attack=0, SpinKick=0, Roll=0, Pause=0, Select=0; @@ -315,7 +313,7 @@ u32 TMNT2Input(unsigned short pad) { } u32 TMNT3Input(unsigned short pad) { - u32 J = StandardMovement(pad) | StandardDPad(pad) | DecodeKeyboard(pad); + u32 J = StandardMovement(pad) | StandardDPad(pad); static u32 LastDir = VBA_RIGHT; bool Jump=0, Attack=0, SpinKick=0, Roll=0, Pause=0, Select=0; @@ -396,7 +394,7 @@ u32 TMNT3Input(unsigned short pad) { } u32 TMNTGBAInput(unsigned short pad) { - u32 J = StandardMovement(pad) | StandardDPad(pad) | DecodeKeyboard(pad); + u32 J = StandardMovement(pad) | StandardDPad(pad); static u32 LastDir = VBA_RIGHT; bool Jump=0, Attack=0, SpinKick=0, SpecialMove=0, Pause=0, Select=0; @@ -480,7 +478,7 @@ u32 TMNTGBAInput(unsigned short pad) { } u32 TMNTGBA2Input(unsigned short pad) { - u32 J = StandardMovement(pad) | StandardDPad(pad) | DecodeKeyboard(pad); + u32 J = StandardMovement(pad) | StandardDPad(pad); static u32 LastDir = VBA_RIGHT; //static bool wait = false; //static int holdcount = 0; @@ -568,7 +566,7 @@ u32 TMNTGBA2Input(unsigned short pad) { } u32 HarryPotter1GBCInput(unsigned short pad) { - u32 J = StandardMovement(pad) | StandardDPad(pad) | DecodeKeyboard(pad) + u32 J = StandardMovement(pad) | StandardDPad(pad) | DecodeGamecube(pad); //u8 ScreenMode = gbReadMemory(0xFFCF); //u8 CursorItem = gbReadMemory(0xFFD5); @@ -612,7 +610,7 @@ u32 HarryPotter1GBCInput(unsigned short pad) { } u32 HarryPotter2GBCInput(unsigned short pad) { - u32 J = StandardMovement(pad) | StandardDPad(pad) | DecodeKeyboard(pad) + u32 J = StandardMovement(pad) | StandardDPad(pad) | DecodeGamecube(pad); #ifdef HW_RVL WPADData * wp = WPAD_Data(pad); @@ -653,7 +651,7 @@ u32 HarryPotter2GBCInput(unsigned short pad) { } u32 HarryPotter1Input(unsigned short pad) { - u32 J = StandardMovement(pad) | DecodeKeyboard(pad) + u32 J = StandardMovement(pad) | DecodeGamecube(pad); #ifdef HW_RVL WPADData * wp = WPAD_Data(pad); @@ -701,7 +699,7 @@ u32 HarryPotter1Input(unsigned short pad) { } u32 HarryPotter2Input(unsigned short pad) { - u32 J = StandardMovement(pad) | DecodeKeyboard(pad) + u32 J = StandardMovement(pad) | DecodeGamecube(pad); #ifdef HW_RVL WPADData * wp = WPAD_Data(pad); @@ -751,7 +749,7 @@ u32 HarryPotter2Input(unsigned short pad) { } u32 HarryPotter3Input(unsigned short pad) { - u32 J = StandardMovement(pad) | DecodeKeyboard(pad) + u32 J = StandardMovement(pad) | DecodeGamecube(pad); #ifdef HW_RVL WPADData * wp = WPAD_Data(pad); @@ -801,16 +799,8 @@ u32 HarryPotter3Input(unsigned short pad) { } u32 HarryPotter4Input(unsigned short pad) { - u32 J = StandardMovement(pad) | DPadArrowKeys(pad) - | DecodeGamecube(pad); + u32 J = StandardMovement(pad) | DecodeGamecube(pad); #ifdef HW_RVL - if (DownUsbKeys[KS_A]) J |= VBA_BUTTON_L; - if (DownUsbKeys[KS_D]) J |= VBA_BUTTON_R; - if (DownUsbKeys[KS_Return] || DownUsbKeys[KS_X]) J |= VBA_BUTTON_A; - if (DownUsbKeys[KS_C]) J |= VBA_BUTTON_B; - if (DownUsbKeys[KS_Tab]) J |= VBA_BUTTON_SELECT; - if (DownUsbKeys[KS_space]) J |= VBA_BUTTON_START; - if (DownUsbKeys[KS_Shift_L] || DownUsbKeys[KS_Shift_R]) J |= VBA_SPEED; WPADData * wp = WPAD_Data(pad); @@ -859,16 +849,8 @@ u32 HarryPotter4Input(unsigned short pad) { } u32 HarryPotter5Input(unsigned short pad) { - u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DPadWASD(pad); + u32 J = StandardMovement(pad) | DecodeGamecube(pad); #ifdef HW_RVL - // Keyboard controls based on Harry Potter 5 for PC - if (DownUsbKeys[KS_Left]) J |= VBA_BUTTON_L; - if (DownUsbKeys[KS_Right]) J |= VBA_BUTTON_R; - if (DownUsbKeys[KS_Up] || DownUsbKeys[KS_Down]) J |= VBA_BUTTON_B; - if (DownUsbKeys[KS_Return]) J |= VBA_BUTTON_A; - if (DownUsbKeys[KS_Tab]) J |= VBA_BUTTON_SELECT; - if (DownUsbKeys[KS_space]) J |= VBA_BUTTON_START; - if (DownUsbKeys[KS_Shift_L] || DownUsbKeys[KS_Shift_R]) J |= VBA_SPEED; WPADData * wp = WPAD_Data(pad); @@ -929,7 +911,7 @@ u32 HarryPotter5Input(unsigned short pad) { u32 TwistedInput(unsigned short pad) { // Change this to true if you want to see the screen tilt. TiltScreen = false; - u32 J = StandardMovement(pad) | DecodeKeyboard(pad) | DecodeGamecube(pad); + u32 J = StandardMovement(pad) | DecodeGamecube(pad); #ifdef HW_RVL WPADData * wp = WPAD_Data(pad); @@ -977,7 +959,7 @@ u32 TwistedInput(unsigned short pad) { u32 KirbyTntInput(unsigned short pad) { TiltScreen = false; - u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DecodeKeyboard(pad); + u32 J = StandardMovement(pad) | DecodeGamecube(pad); #ifdef HW_RVL WPADData * wp = WPAD_Data(pad); if (wp->exp.type == WPAD_EXP_NUNCHUK) { @@ -1021,7 +1003,7 @@ u32 KirbyTntInput(unsigned short pad) { } u32 MohInfiltratorInput(unsigned short pad) { - u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DecodeKeyboard(pad); + u32 J = StandardMovement(pad) | DecodeGamecube(pad); #ifdef HW_RVL WPADData * wp = WPAD_Data(pad); if (wp->exp.type == WPAD_EXP_NONE) @@ -1060,7 +1042,7 @@ u32 MohInfiltratorInput(unsigned short pad) { } u32 MohUndergroundInput(unsigned short pad) { - u32 J = StandardMovement(pad) | DecodeClassic(pad) | DecodeWiimote(pad) | DecodeGamecube(pad) | DecodeKeyboard(pad); + u32 J = StandardMovement(pad) | DecodeClassic(pad) | DecodeWiimote(pad) | DecodeGamecube(pad); static bool crouched = false; #ifdef HW_RVL WPADData * wp = WPAD_Data(pad); @@ -1118,7 +1100,7 @@ u32 MohUndergroundInput(unsigned short pad) { u32 BoktaiInput(unsigned short pad) { u32 J = StandardMovement(pad) | StandardDPad(pad) - | DecodeKeyboard(pad) | DecodeGamecube(pad) | DecodeClassic(pad); + | DecodeGamecube(pad) | DecodeClassic(pad); #ifdef HW_RVL WPADData * wp = WPAD_Data(pad); static bool GunRaised = false; @@ -1167,7 +1149,7 @@ u32 BoktaiInput(unsigned short pad) { u32 Boktai2Input(unsigned short pad) { u32 J = StandardMovement(pad) | StandardDPad(pad) - | DecodeKeyboard(pad) | DecodeGamecube(pad) | DecodeClassic(pad); + | DecodeGamecube(pad) | DecodeClassic(pad); #ifdef HW_RVL WPADData * wp = WPAD_Data(pad); static bool GunRaised = false; @@ -1220,9 +1202,9 @@ u32 Boktai2Input(unsigned short pad) { u32 OnePieceInput(unsigned short pad) { // Only Nunchuk and Gamecube controls available - // Keyboard, Wiimote and Classic controls depend on user configuration + // Wiimote and Classic controls depend on user configuration u32 J = StandardMovement(pad) - | DecodeKeyboard(pad) | DecodeWiimote(pad) | DecodeClassic(pad); + | DecodeWiimote(pad) | DecodeClassic(pad); static u32 LastDir = VBA_RIGHT; bool JumpButton=0, AttackButton=0, ViewButton=0, CharacterButton=0, PauseButton=0, DashButton=0, GrabButton=0, SpeedButton=0, AttackUpButton = 0; @@ -1272,10 +1254,10 @@ u32 OnePieceInput(unsigned short pad) { } u32 HobbitInput(unsigned short pad) { - // Only Nunchuk and Keyboard controls available + // Only Nunchuk controls available // Wiimote, Gamecube and Classic controls depend on user configuration - u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DPadWASD(pad) | - DPadArrowKeys(pad) | DecodeWiimote(pad) | DecodeClassic(pad); + u32 J = StandardMovement(pad) | DecodeGamecube(pad) | + DecodeWiimote(pad) | DecodeClassic(pad); bool AbilityButton=0, AttackButton=0, UseButton=0, ChangeSkillButton=0, PauseButton=0, ItemsButton=0, SpeedButton=0; #ifdef HW_RVL @@ -1292,20 +1274,6 @@ u32 HobbitInput(unsigned short pad) { AttackButton = (fabs(wp->gforce.x)> 1.5); } #endif - if (DownUsbKeys[KS_E]) UseButton = true; - if (DownUsbKeys[KS_Shift_L]) { - if (DownUsbKeys[MOUSEL] || DownUsbKeys[MOUSER]) AbilityButton = true; - } else { - if (DownUsbKeys[MOUSEL] || DownUsbKeys[MOUSER]) AttackButton = true; - } - if (DownUsbKeys[KS_F5]) AbilityButton = true; - if (DownUsbKeys[KS_Control_L]) AttackButton = true; - if (DownUsbKeys[KS_space]) AttackButton = true; - if (DownUsbKeys[KS_Q]) AttackButton = true; - if (DownUsbKeys[KS_C]) ChangeSkillButton = true; - if (DownUsbKeys[KS_Return]) ItemsButton = true; - if (DownUsbKeys[KS_BackSpace]) PauseButton = true; - if (DownUsbKeys[KS_F]) SpeedButton = true; if (AbilityButton) J |= VBA_BUTTON_B; if (AttackButton) J |= VBA_BUTTON_L; @@ -1319,10 +1287,10 @@ u32 HobbitInput(unsigned short pad) { } u32 FellowshipOfTheRingInput(unsigned short pad) { - // Only Nunchuk and Keyboard controls available + // Only Nunchuk controls available // Wiimote, Gamecube and Classic controls depend on user configuration - u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DPadWASD(pad) | - DPadArrowKeys(pad) | DecodeWiimote(pad) | DecodeClassic(pad); + u32 J = StandardMovement(pad) | DecodeGamecube(pad) | + DecodeWiimote(pad) | DecodeClassic(pad); bool CancelButton=0, UseButton=0, ChangeCharButton=0, PauseButton=0, ItemsButton=0, SpeedButton=0, SelectButton=0; #ifdef HW_RVL @@ -1340,19 +1308,7 @@ u32 FellowshipOfTheRingInput(unsigned short pad) { SelectButton = wp->btns_h & WPAD_BUTTON_1; } #endif - if (DownUsbKeys[KS_E]) UseButton = true; - if (DownUsbKeys[KS_Q]) CancelButton = true; - if (DownUsbKeys[MOUSEL]) UseButton = true; - if (DownUsbKeys[MOUSER]) CancelButton = true; - if (DownUsbKeys[KS_C]) ChangeCharButton = true; - if (DownUsbKeys[KS_Return]) PauseButton = true; - if (DownUsbKeys[KS_BackSpace]) ItemsButton = true; - if (DownUsbKeys[KS_Tab]) SelectButton = true; - if (DownUsbKeys[KS_F]) SpeedButton = true; - if (DownUsbKeys[KS_space]) SpeedButton = true; - if (DownUsbKeys[KS_F5]) UseButton = true; - if (DownUsbKeys[KS_Control_L]) UseButton = true; - + if (UseButton) J |= VBA_BUTTON_A; if (CancelButton) J |= VBA_BUTTON_B; if (ChangeCharButton) J |= VBA_BUTTON_L; @@ -1365,10 +1321,10 @@ u32 FellowshipOfTheRingInput(unsigned short pad) { } u32 ReturnOfTheKingInput(unsigned short pad) { - // Only Nunchuk and Keyboard controls available + // Only Nunchuk controls available // Wiimote, Gamecube and Classic controls depend on user configuration - u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DPadWASD(pad) | - DPadArrowKeys(pad) | DecodeWiimote(pad) | DecodeClassic(pad); + u32 J = StandardMovement(pad) | DecodeGamecube(pad) | + DecodeWiimote(pad) | DecodeClassic(pad); bool AbilityButton=0, AttackButton=0, UseButton=0, ChangeSkillButton=0, PauseButton=0, ItemsButton=0, SpeedButton=0; #ifdef HW_RVL @@ -1385,20 +1341,6 @@ u32 ReturnOfTheKingInput(unsigned short pad) { AttackButton = (fabs(wp->gforce.x)> 1.5); } #endif - if (DownUsbKeys[KS_E]) UseButton = true; - if (DownUsbKeys[KS_Shift_L]) { - if (DownUsbKeys[MOUSEL] || DownUsbKeys[MOUSER]) AbilityButton = true; - } else { - if (DownUsbKeys[MOUSEL] || DownUsbKeys[MOUSER]) AttackButton = true; - } - if (DownUsbKeys[KS_F5]) AbilityButton = true; - if (DownUsbKeys[KS_Control_L]) AttackButton = true; - if (DownUsbKeys[KS_space]) AttackButton = true; - if (DownUsbKeys[KS_Q]) AttackButton = true; - if (DownUsbKeys[KS_C]) ChangeSkillButton = true; - if (DownUsbKeys[KS_Return]) ItemsButton = true; - if (DownUsbKeys[KS_BackSpace]) PauseButton = true; - if (DownUsbKeys[KS_F]) SpeedButton = true; if (AbilityButton) J |= VBA_BUTTON_A; if (AttackButton) J |= VBA_BUTTON_B; @@ -1413,8 +1355,8 @@ u32 ReturnOfTheKingInput(unsigned short pad) { u32 CastlevaniaAdventureInput(unsigned short pad) { // Only Nunchuk and Classic controls available - // Wiimote, Gamecube and Keyboard controls depend on user configuration - u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DecodeKeyboard(pad) | DecodeWiimote(pad) | DecodeClassic(pad); + // Wiimote and Gamecube controls depend on user configuration + u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DecodeWiimote(pad) | DecodeClassic(pad); bool JumpButton=0, AttackButton=0, GuardButton=0, PauseButton=0, SelectButton=0, SpeedButton=0; #ifdef HW_RVL WPADData * wp = WPAD_Data(pad); @@ -1452,8 +1394,8 @@ u32 CastlevaniaAdventureInput(unsigned short pad) { u32 CastlevaniaBelmontInput(unsigned short pad) { // Only Nunchuk and Classic controls available - // Wiimote, Gamecube and Keyboard controls depend on user configuration - u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DecodeKeyboard(pad) | DecodeWiimote(pad) | DecodeClassic(pad); + // Wiimote and Gamecube controls depend on user configuration + u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DecodeWiimote(pad) | DecodeClassic(pad); bool JumpButton=0, AttackButton=0, ShootButton=0, GuardButton=0, PauseButton=0, SelectButton=0, SpeedButton=0; #ifdef HW_RVL WPADData * wp = WPAD_Data(pad); @@ -1497,8 +1439,8 @@ u32 CastlevaniaBelmontInput(unsigned short pad) { u32 CastlevaniaLegendsInput(unsigned short pad) { // Only Nunchuk and Classic controls available - // Wiimote, Gamecube and Keyboard controls depend on user configuration - u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DecodeKeyboard(pad) | DecodeWiimote(pad) | DecodeClassic(pad); + // Wiimote and Gamecube controls depend on user configuration + u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DecodeWiimote(pad) | DecodeClassic(pad); bool JumpButton=0, AttackButton=0, ShootButton=0, GuardButton=0, PauseButton=0, SelectButton=0, SpeedButton=0, HyperButton=0; #ifdef HW_RVL WPADData * wp = WPAD_Data(pad); @@ -1545,8 +1487,8 @@ u32 CastlevaniaLegendsInput(unsigned short pad) { u32 CastlevaniaCircleMoonInput(unsigned short pad) { // Only Nunchuk and Classic controls available - // Wiimote, Gamecube and Keyboard controls depend on user configuration - u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DecodeKeyboard(pad) | DecodeWiimote(pad) | DecodeClassic(pad); + // Wiimote and Gamecube controls depend on user configuration + u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DecodeWiimote(pad) | DecodeClassic(pad); bool JumpButton=0, AttackButton=0, ShootButton=0, GuardButton=0, PauseButton=0, SelectButton=0, SpeedButton=0, HyperButton=0, LButton=0, RButton=0; #ifdef HW_RVL diff --git a/source/ngc/gameinput.h b/source/ngc/gameinput.h index 2be9d87..1dfcc7d 100644 --- a/source/ngc/gameinput.h +++ b/source/ngc/gameinput.h @@ -127,10 +127,6 @@ u32 StandardMovement(unsigned short pad); u32 StandardSideways(unsigned short pad); u32 StandardClassic(unsigned short pad); u32 StandardGamecube(unsigned short pad); -u32 StandardKeyboard(unsigned short pad); -u32 DPadWASD(unsigned short pad); -u32 DPadArrowKeys(unsigned short pad); -u32 DecodeKeyboard(unsigned short pad); u32 DecodeWiimote(unsigned short pad); u32 DecodeClassic(unsigned short pad); u32 DecodeGamecube(unsigned short pad); diff --git a/source/ngc/input.cpp b/source/ngc/input.cpp index a189438..5837dc2 100644 --- a/source/ngc/input.cpp +++ b/source/ngc/input.cpp @@ -24,7 +24,6 @@ #include "input.h" #include "gameinput.h" #include "vbasupport.h" -#include "wiiusbsupport.h" #include "gui/gui.h" #include "gba/GBA.h" #include "gba/bios.h" @@ -42,7 +41,7 @@ static bool cartridgeRumble = false, possibleCartridgeRumble = false; static int gameRumbleCount = 0, menuRumbleCount = 0, rumbleCountAlready = 0; static unsigned int vbapadmap[10]; // VBA controller buttons -u32 btnmap[5][10]; // button mapping +u32 btnmap[4][10]; // button mapping void ResetControls(int wiiCtrl) { @@ -125,22 +124,6 @@ void ResetControls(int wiiCtrl) btnmap[CTRLR_NUNCHUK][i++] = WPAD_BUTTON_2; btnmap[CTRLR_NUNCHUK][i++] = WPAD_BUTTON_1; } - - /*** Keyboard map ***/ - if(wiiCtrl == CTRLR_KEYBOARD || wiiCtrl == -1) - { - i=0; - btnmap[CTRLR_KEYBOARD][i++] = KS_X; // VBA stupidly has B on the right instead of left - btnmap[CTRLR_KEYBOARD][i++] = KS_Z; - btnmap[CTRLR_KEYBOARD][i++] = KS_BackSpace; - btnmap[CTRLR_KEYBOARD][i++] = KS_Return; - btnmap[CTRLR_KEYBOARD][i++] = KS_Up; - btnmap[CTRLR_KEYBOARD][i++] = KS_Down; - btnmap[CTRLR_KEYBOARD][i++] = KS_Left; - btnmap[CTRLR_KEYBOARD][i++] = KS_Right; - btnmap[CTRLR_KEYBOARD][i++] = KS_A; - btnmap[CTRLR_KEYBOARD][i++] = KS_S; - } } /**************************************************************************** @@ -418,13 +401,6 @@ u32 StandardMovement(unsigned short chan) } } } - - // Turbo feature, keyboard or gamecube only - if(DownUsbKeys[KS_space]) - J |= VBA_SPEED; - // Capture feature - if(DownUsbKeys[KS_Print_Screen] | DownUsbKeys[KS_F12]) - J |= VBA_CAPTURE; #endif return J; } @@ -573,83 +549,6 @@ u32 StandardGamecube(unsigned short pad) return J; } -u32 StandardKeyboard(unsigned short pad) -{ - u32 J = 0; -#ifdef HW_RVL - if (DownUsbKeys[KS_Up]) - J |= VBA_UP; - if (DownUsbKeys[KS_Down]) - J |= VBA_DOWN; - if (DownUsbKeys[KS_Left]) - J |= VBA_LEFT; - if (DownUsbKeys[KS_Right]) - J |= VBA_RIGHT; - if (DownUsbKeys[KS_space]) - J |= VBA_SPEED; - if (DownUsbKeys[KS_F12] || DownUsbKeys[KS_Print_Screen]) - J |= VBA_CAPTURE; - if (DownUsbKeys[KS_X]) - J |= VBA_BUTTON_A; - if (DownUsbKeys[KS_Z]) - J |= VBA_BUTTON_B; - if (DownUsbKeys[KS_A]) - J |= VBA_BUTTON_L; - if (DownUsbKeys[KS_S]) - J |= VBA_BUTTON_R; - if (DownUsbKeys[KS_Return]) - J |= VBA_BUTTON_START; - if (DownUsbKeys[KS_BackSpace]) - J |= VBA_BUTTON_SELECT; -#endif - return J; -} - -u32 DPadWASD(unsigned short pad) -{ - u32 J = 0; -#ifdef HW_RVL - if (DownUsbKeys[KS_W]) - J |= VBA_UP; - if (DownUsbKeys[KS_S]) - J |= VBA_DOWN; - if (DownUsbKeys[KS_A]) - J |= VBA_LEFT; - if (DownUsbKeys[KS_D]) - J |= VBA_RIGHT; -#endif - return J; -} - -u32 DPadArrowKeys(unsigned short pad) -{ - u32 J = 0; -#ifdef HW_RVL - if (DownUsbKeys[KS_Up]) - J |= VBA_UP; - if (DownUsbKeys[KS_Down]) - J |= VBA_DOWN; - if (DownUsbKeys[KS_Left]) - J |= VBA_LEFT; - if (DownUsbKeys[KS_Right]) - J |= VBA_RIGHT; -#endif - return J; -} - -u32 DecodeKeyboard(unsigned short pad) -{ - u32 J = 0; - #ifdef HW_RVL - for (u32 i = 0; i < MAXJP; ++i) - { - if (DownUsbKeys[btnmap[CTRLR_KEYBOARD][i]]) // keyboard - J |= vbapadmap[i]; - } - #endif - return J; -} - u32 DecodeGamecube(unsigned short pad) { u32 J = 0; @@ -987,8 +886,7 @@ static u32 DecodeJoy(unsigned short pad) for (u32 i =0; i < MAXJP; ++i) { if ((pad_btns_h & btnmap[CTRLR_GCPAD][i]) // gamecube controller - || ( (wpad_btns_h & btnmap[CTRLR_WIIMOTE][i]) ) - || ( (DownUsbKeys[btnmap[CTRLR_KEYBOARD][i]]) ) )// keyboard + || ( (wpad_btns_h & btnmap[CTRLR_WIIMOTE][i]) )) J |= vbapadmap[i]; } @@ -999,8 +897,7 @@ static u32 DecodeJoy(unsigned short pad) for (u32 i =0; i < MAXJP; ++i) { if ((pad_btns_h & btnmap[CTRLR_GCPAD][i]) // gamecube controller - || ( (wpad_btns_h & btnmap[CTRLR_CLASSIC][i]) ) - || ( (DownUsbKeys[btnmap[CTRLR_KEYBOARD][i]]) ) )// keyboard + || ( (wpad_btns_h & btnmap[CTRLR_CLASSIC][i]) )) J |= vbapadmap[i]; } @@ -1011,8 +908,7 @@ static u32 DecodeJoy(unsigned short pad) for (u32 i =0; i < MAXJP; ++i) { if ((pad_btns_h & btnmap[CTRLR_GCPAD][i]) // gamecube controller - || ( (wpad_btns_h & btnmap[CTRLR_NUNCHUK][i]) ) - || ( (DownUsbKeys[btnmap[CTRLR_KEYBOARD][i]]) ) )// keyboard + || ( (wpad_btns_h & btnmap[CTRLR_NUNCHUK][i]) )) J |= vbapadmap[i]; } @@ -1033,9 +929,7 @@ static u32 DecodeJoy(unsigned short pad) bool MenuRequested() { - if( (DownUsbKeys[KS_Escape]) - || - (userInput[0].pad.substickX < -70) || + if( (userInput[0].pad.substickX < -70) || (userInput[0].wpad->btns_h & WPAD_BUTTON_HOME) || (userInput[0].wpad->btns_h & WPAD_CLASSIC_BUTTON_HOME) || diff --git a/source/ngc/input.h b/source/ngc/input.h index 02c442f..5fc20cd 100644 --- a/source/ngc/input.h +++ b/source/ngc/input.h @@ -32,7 +32,7 @@ #define VBA_CAPTURE 2048 extern int rumbleRequest[4]; -extern u32 btnmap[5][10]; +extern u32 btnmap[4][10]; void ResetControls(int wc = -1); void ShutoffRumble(); diff --git a/source/ngc/inputmario.cpp b/source/ngc/inputmario.cpp index c2c61c6..6043a6c 100644 --- a/source/ngc/inputmario.cpp +++ b/source/ngc/inputmario.cpp @@ -25,7 +25,6 @@ #include "input.h" #include "gameinput.h" #include "vbasupport.h" -#include "wiiusbsupport.h" #include "gba/GBA.h" #include "gba/bios.h" #include "gba/GBAinline.h" @@ -147,7 +146,7 @@ u32 MarioKartInput(unsigned short pad) { } u32 Mario1DXInput(unsigned short pad) { - u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DecodeKeyboard(pad); + u32 J = StandardMovement(pad) | DecodeGamecube(pad); #ifdef HW_RVL WPADData * wp = WPAD_Data(pad); @@ -233,7 +232,7 @@ u32 Mario1DXInput(unsigned short pad) { } u32 Mario1ClassicInput(unsigned short pad) { - u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DecodeKeyboard(pad); + u32 J = StandardMovement(pad) | DecodeGamecube(pad); #ifdef HW_RVL WPADData * wp = WPAD_Data(pad); @@ -304,7 +303,7 @@ u32 Mario1ClassicInput(unsigned short pad) { } u32 MarioLand1Input(unsigned short pad) { - u32 J = StandardMovement(pad) | DecodeKeyboard(pad) | DecodeGamecube(pad); + u32 J = StandardMovement(pad) | DecodeGamecube(pad); #ifdef HW_RVL WPADData * wp = WPAD_Data(pad); bool run = false; @@ -371,7 +370,7 @@ u32 MarioLand1Input(unsigned short pad) { } u32 MarioLand2Input(unsigned short pad) { - u32 J = StandardMovement(pad) | DecodeKeyboard(pad) | DecodeGamecube(pad); + u32 J = StandardMovement(pad) | DecodeGamecube(pad); #ifdef HW_RVL WPADData * wp = WPAD_Data(pad); bool run = false; @@ -460,7 +459,7 @@ u32 MarioLand2Input(unsigned short pad) { u32 Mario2Input(unsigned short pad) { - u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DecodeKeyboard(pad) | DecodeWiimote(pad); + u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DecodeWiimote(pad); #ifdef HW_RVL WPADData * wp = WPAD_Data(pad); bool run = false; @@ -539,7 +538,7 @@ u32 Mario2Input(unsigned short pad) } u32 MarioWorldInput(unsigned short pad) { - u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DecodeKeyboard(pad); + u32 J = StandardMovement(pad) | DecodeGamecube(pad); u8 CarryState = CPUReadByte(0x3003F06); // 01 = carrying, 00 = not carrying u8 InYoshisMouth = CPUReadByte(0x3003F53); // FF = nothing, 00 = no level, else thing u8 FallState = CPUReadByte(0x3003FA1); // 0B = jump, 24 = fall @@ -668,7 +667,7 @@ u32 MarioWorldInput(unsigned short pad) { u32 Mario3Input(unsigned short pad) { - u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DecodeKeyboard(pad); + u32 J = StandardMovement(pad) | DecodeGamecube(pad); #ifdef HW_RVL WPADData * wp = WPAD_Data(pad); bool run = false; @@ -745,7 +744,7 @@ u32 Mario3Input(unsigned short pad) u32 YoshiIslandInput(unsigned short pad) { - u32 J = StandardMovement(pad) | DecodeWiimote(pad) | DecodeGamecube(pad) | DecodeKeyboard(pad); + u32 J = StandardMovement(pad) | DecodeWiimote(pad) | DecodeGamecube(pad); #ifdef HW_RVL WPADData * wp = WPAD_Data(pad); @@ -828,7 +827,7 @@ u32 YoshiIslandInput(unsigned short pad) u32 UniversalGravitationInput(unsigned short pad) { TiltScreen = true; - u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DecodeKeyboard(pad); + u32 J = StandardMovement(pad) | DecodeGamecube(pad); #ifdef HW_RVL WPADData * wp = WPAD_Data(pad); if (wp->exp.type == WPAD_EXP_NUNCHUK) { diff --git a/source/ngc/inputmetroid.cpp b/source/ngc/inputmetroid.cpp index 6420e52..9186b83 100644 --- a/source/ngc/inputmetroid.cpp +++ b/source/ngc/inputmetroid.cpp @@ -25,13 +25,12 @@ #include "input.h" #include "gameinput.h" #include "vbasupport.h" -#include "wiiusbsupport.h" #include "gba/GBA.h" #include "gba/bios.h" #include "gba/GBAinline.h" u32 MetroidZeroInput(unsigned short pad) { - u32 J = StandardMovement(pad) | DecodeClassic(pad) | DecodeKeyboard(pad); + u32 J = StandardMovement(pad) | DecodeClassic(pad); u8 BallState = CPUReadByte(0x30015df); // 0 = stand, 1 = crouch, 2 = ball u16 Health = CPUReadByte(0x3001536); // 0 = stand, 1 = crouch, 2 = ball static u16 OldHealth = 0; @@ -240,7 +239,7 @@ u32 MetroidZeroInput(unsigned short pad) { } u32 MetroidFusionInput(unsigned short pad) { - u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DecodeClassic(pad) | DecodeKeyboard(pad); + u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DecodeClassic(pad); u8 BallState = CPUReadByte(0x3001329); // 0 = stand, 2 = crouch, 5 = ball u16 Health = CPUReadHalfWord(0x3001310); static u16 OldHealth = 0; @@ -421,7 +420,7 @@ u32 MetroidFusionInput(unsigned short pad) { } u32 Metroid1Input(unsigned short pad) { - u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DecodeClassic(pad) | DecodeKeyboard(pad); + u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DecodeClassic(pad); u8 BallState = CPUReadByte(0x3007500); // 3 = ball, other = stand u8 MissileState = CPUReadByte(0x300730E); // 1 = missile, 0 = beam u16 Health = CPUReadHalfWord(0x3007306); // Binary Coded Decimal @@ -535,7 +534,7 @@ u32 Metroid1Input(unsigned short pad) { } u32 Metroid2Input(unsigned short pad) { - u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DecodeClassic(pad) | DecodeKeyboard(pad); + u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DecodeClassic(pad); u8 BallState = gbReadMemory(0xD020); // 4 = crouch, 5 = ball, other = stand u8 MissileState = gbReadMemory(0xD04D); // 8 = missile hatch open, 0 = missile closed u8 Health = gbReadMemory(0xD051); // Binary Coded Decimal diff --git a/source/ngc/inputmortalkombat.cpp b/source/ngc/inputmortalkombat.cpp index 22b37dd..bf3224c 100644 --- a/source/ngc/inputmortalkombat.cpp +++ b/source/ngc/inputmortalkombat.cpp @@ -25,7 +25,6 @@ #include "input.h" #include "gameinput.h" #include "vbasupport.h" -#include "wiiusbsupport.h" #include "gba/GBA.h" #include "gba/bios.h" #include "gba/GBAinline.h" @@ -118,7 +117,7 @@ static u32 VBA_FORWARD=VBA_RIGHT, VBA_BACK=VBA_LEFT; static int ChameleonChangeTime = 0; u32 GetMKInput(unsigned short pad, int rumbleTime=4) { - u32 J = StandardMovement(pad) | DecodeKeyboard(pad) | DecodeWiimote(pad); + u32 J = StandardMovement(pad) | DecodeWiimote(pad); HP=0;LP=0;HK=0;LK=0;BL=0;Throw=0;CS=0;F=0;B=0;Select=0;Start=0;SpecialMove=0; // Rumble when they lose health! diff --git a/source/ngc/inputstarwars.cpp b/source/ngc/inputstarwars.cpp index 08802b0..2d881c7 100644 --- a/source/ngc/inputstarwars.cpp +++ b/source/ngc/inputstarwars.cpp @@ -25,13 +25,12 @@ #include "input.h" #include "gameinput.h" #include "vbasupport.h" -#include "wiiusbsupport.h" #include "gba/GBA.h" #include "gba/bios.h" #include "gba/GBAinline.h" u32 LegoStarWars1Input(unsigned short pad) { - u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DPadWASD(pad); + u32 J = StandardMovement(pad) | DecodeGamecube(pad); // Rumble when they lose health! u8 Health = 0; static u8 OldHealth = 0; @@ -40,14 +39,6 @@ u32 LegoStarWars1Input(unsigned short pad) { OldHealth = Health; #ifdef HW_RVL - if (DownUsbKeys[KS_Return]) J |= VBA_BUTTON_START; // start - if (DownUsbKeys[KS_K] || DownUsbKeys[KS_Control_L]) J |= VBA_BUTTON_SELECT; // change chars - if (DownUsbKeys[KS_U]) J |= VBA_BUTTON_A; // jump - if (DownUsbKeys[KS_H]) J |= VBA_BUTTON_B; // attack - if (DownUsbKeys[KS_J]) J |= VBA_BUTTON_R; // force power, special ability - if (DownUsbKeys[KS_I]) J |= VBA_BUTTON_L; // build, use force (supposed to be J too) - if (DownUsbKeys[KS_space]) J |= VBA_SPEED; // fast forward - WPADData * wp = WPAD_Data(pad); // Start/Select @@ -85,7 +76,7 @@ u32 LegoStarWars1Input(unsigned short pad) { } u32 LegoStarWars2Input(unsigned short pad) { - u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DPadWASD(pad); + u32 J = StandardMovement(pad) | DecodeGamecube(pad); // Rumble when they lose health! u8 Health = 0; static u8 OldHealth = 0; @@ -94,14 +85,6 @@ u32 LegoStarWars2Input(unsigned short pad) { OldHealth = Health; #ifdef HW_RVL - if (DownUsbKeys[KS_Return]) J |= VBA_BUTTON_START; // start - if (DownUsbKeys[KS_K] || DownUsbKeys[KS_Control_L]) J |= VBA_BUTTON_SELECT; // change chars - if (DownUsbKeys[KS_U]) J |= VBA_BUTTON_A; // jump - if (DownUsbKeys[KS_H]) J |= VBA_BUTTON_B; // attack - if (DownUsbKeys[KS_J]) J |= VBA_BUTTON_L; // force power, special ability - if (DownUsbKeys[KS_I]) J |= VBA_BUTTON_R; // build, use force (supposed to be J too) - if (DownUsbKeys[KS_space]) J |= VBA_SPEED; // fast forward - WPADData * wp = WPAD_Data(pad); // Start/Select @@ -143,7 +126,7 @@ u32 LegoStarWars2Input(unsigned short pad) { } u32 SWObiWanInput(unsigned short pad) { - u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DecodeKeyboard(pad); + u32 J = StandardMovement(pad) | DecodeGamecube(pad); // Rumble when they lose health! u8 Health = gbReadMemory(0xCFF2); static u8 OldHealth = 0; @@ -191,7 +174,7 @@ u32 SWObiWanInput(unsigned short pad) { } u32 SWEpisode2Input(unsigned short pad) { - u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DecodeKeyboard(pad); + u32 J = StandardMovement(pad) | DecodeGamecube(pad); // Rumble when they lose health! u8 Health = CPUReadByte(0x3002fb3); static u8 OldHealth = 0; @@ -239,7 +222,7 @@ u32 SWEpisode2Input(unsigned short pad) { } u32 SWEpisode3Input(unsigned short pad) { - u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DecodeKeyboard(pad); + u32 J = StandardMovement(pad) | DecodeGamecube(pad); // Rumble when they lose health! u8 Health = 0;//CPUReadByte(0x3002fb3); static u8 OldHealth = 0; @@ -292,7 +275,7 @@ u32 SWEpisode3Input(unsigned short pad) { } u32 SWJediPowerBattlesInput(unsigned short pad) { - u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DecodeKeyboard(pad); + u32 J = StandardMovement(pad) | DecodeGamecube(pad); // Rumble when they lose health! u8 Health = 0;//CPUReadByte(0x3002fb3); static u8 OldHealth = 0; @@ -345,7 +328,7 @@ u32 SWJediPowerBattlesInput(unsigned short pad) { } u32 SWTrilogyInput(unsigned short pad) { - u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DecodeKeyboard(pad); + u32 J = StandardMovement(pad) | DecodeGamecube(pad); // Rumble when they lose health! u8 Health = 0;//CPUReadByte(0x3002fb3); static u8 OldHealth = 0; @@ -398,7 +381,7 @@ u32 SWTrilogyInput(unsigned short pad) { } u32 SWEpisode4Input(unsigned short pad) { - u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DecodeKeyboard(pad); + u32 J = StandardMovement(pad) | DecodeGamecube(pad); // Rumble when they lose health! u8 Health = 0; static u8 OldHealth = 0; @@ -451,7 +434,7 @@ u32 SWEpisode4Input(unsigned short pad) { } u32 SWEpisode5Input(unsigned short pad) { - u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DecodeKeyboard(pad); + u32 J = StandardMovement(pad) | DecodeGamecube(pad); // Rumble when they lose health! u8 Health = 0; static u8 OldHealth = 0; @@ -504,7 +487,7 @@ u32 SWEpisode5Input(unsigned short pad) { } u32 SWEpisode6Input(unsigned short pad) { - u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DecodeKeyboard(pad); + u32 J = StandardMovement(pad) | DecodeGamecube(pad); // Rumble when they lose health! u8 Health = 0; static u8 OldHealth = 0; @@ -557,7 +540,7 @@ u32 SWEpisode6Input(unsigned short pad) { } u32 SWYodaStoriesInput(unsigned short pad) { - u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DecodeKeyboard(pad); + u32 J = StandardMovement(pad) | DecodeGamecube(pad); // Rumble when they lose health! u8 Health = 0;//gbReadMemory(0xD58A); // actually health bar progress static u8 OldHealth = 0; @@ -610,7 +593,7 @@ u32 SWYodaStoriesInput(unsigned short pad) { } u32 SWNDAInput(unsigned short pad) { - u32 J = StandardMovement(pad) | DecodeGamecube(pad) | DecodeKeyboard(pad); + u32 J = StandardMovement(pad) | DecodeGamecube(pad); // Rumble when they lose health! u8 Health = 0; static u8 OldHealth = 0; diff --git a/source/ngc/inputzelda.cpp b/source/ngc/inputzelda.cpp index 077a407..2c0e5d3 100644 --- a/source/ngc/inputzelda.cpp +++ b/source/ngc/inputzelda.cpp @@ -26,7 +26,6 @@ #include "gui/gui.h" #include "gameinput.h" #include "vbasupport.h" -#include "wiiusbsupport.h" #include "gba/GBA.h" #include "gba/bios.h" #include "gba/GBAinline.h" @@ -220,10 +219,9 @@ u32 LinksAwakeningInput(unsigned short pad) // aka Zelda DX static int DelayCount = 0; bool OnItemScreen = gbReadMemory(0xC16C) == 0x20; // 0x20 = items, 0x10 = normal - // There are no Zelda games for PC, so let user choose keyboard 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. - u32 J = StandardMovement(pad) | DecodeKeyboard(pad) | DecodeWiimote(pad); + u32 J = StandardMovement(pad) | DecodeWiimote(pad); u8 CursorPos = gbReadMemory(0xC1B6) + 2; u8 SelItem = 0; @@ -309,7 +307,7 @@ u32 LinksAwakeningInput(unsigned short pad) // aka Zelda DX // Must use Wiimote for these buttons CheatButton = wp->btns_d & WPAD_BUTTON_2; } - CheatButton = CheatButton || DownUsbKeys[KS_C]; + CheatButton = CheatButton; #endif // Gamecube controls are based on Twilight Princess for the Gamecube { @@ -540,10 +538,9 @@ static u32 ZeldaOracleInput(bool Seasons, unsigned short pad) { if (Seasons) ItemsAddr = 0xC680; else ItemsAddr = 0xC688; static u32 OldJ = 0; - // There are no Zelda games for PC, so let user choose keyboard 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. - u32 J = StandardMovement(pad) | DecodeKeyboard(pad) | DecodeWiimote(pad); + u32 J = StandardMovement(pad) | DecodeWiimote(pad); // Rumble when they lose health! u8 Health; @@ -640,7 +637,7 @@ static u32 ZeldaOracleInput(bool Seasons, unsigned short pad) { // Must use Wiimote for these buttons CheatButton = wp->btns_d & WPAD_BUTTON_2; } - CheatButton = CheatButton || DownUsbKeys[KS_C]; + CheatButton = CheatButton; #endif // Gamecube controls are based on Twilight Princess for the Gamecube { @@ -898,7 +895,7 @@ u32 OracleOfSeasonsInput(unsigned short pad) u32 MinishCapInput(unsigned short pad) { - u32 J = StandardMovement(pad) | DecodeKeyboard(pad) | DecodeWiimote(pad); + u32 J = StandardMovement(pad) | DecodeWiimote(pad); // Rumble when they lose health! u8 Health = CPUReadByte(0x2002aea); @@ -1236,7 +1233,7 @@ u32 MinishCapInput(unsigned short pad) // Must use Wiimote for these buttons CheatButton = wp->btns_h & WPAD_BUTTON_2; } - CheatButton = CheatButton || DownUsbKeys[KS_C]; + CheatButton = CheatButton; #endif // Gamecube controls are based on Twilight Princess for the Gamecube { diff --git a/source/ngc/menu.cpp b/source/ngc/menu.cpp index 19e42ee..279cd03 100644 --- a/source/ngc/menu.cpp +++ b/source/ngc/menu.cpp @@ -34,7 +34,6 @@ #include "filelist.h" #include "gui/gui.h" #include "menu.h" -#include "wiiusbsupport.h" #include "gamesettings.h" #define THREAD_SLEEP 100 @@ -2025,7 +2024,7 @@ static int MenuSettingsMappings() GuiImage classicBtnIcon(&iconClassic); GuiButton classicBtn(btnLargeOutline.GetWidth(), btnLargeOutline.GetHeight()); classicBtn.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - classicBtn.SetPosition(0, 250); + classicBtn.SetPosition(-125, 250); classicBtn.SetLabel(&classicBtnTxt); classicBtn.SetImage(&classicBtnImg); classicBtn.SetImageOver(&classicBtnImgOver); @@ -2035,28 +2034,6 @@ static int MenuSettingsMappings() classicBtn.SetTrigger(&trigA); classicBtn.SetEffectGrow(); - GuiText keyboardBtnTxt1("Keyboard", 24, (GXColor){0, 0, 0, 255}); - GuiText keyboardBtnTxt2("&", 18, (GXColor){0, 0, 0, 255}); - GuiText keyboardBtnTxt3("Mouse", 24, (GXColor){0, 0, 0, 255}); - keyboardBtnTxt1.SetPosition(0, -20); - keyboardBtnTxt3.SetPosition(0, +20); - GuiImage keyboardBtnImg(&btnLargeOutline); - GuiImage keyboardBtnImgOver(&btnLargeOutlineOver); - //GuiImage keyboardBtnIcon(&iconkeyboard); - GuiButton keyboardBtn(btnLargeOutline.GetWidth(), btnLargeOutline.GetHeight()); - keyboardBtn.SetAlignment(ALIGN_LEFT, ALIGN_TOP); - keyboardBtn.SetPosition(50, 250); - keyboardBtn.SetLabel(&keyboardBtnTxt1, 0); - keyboardBtn.SetLabel(&keyboardBtnTxt2, 1); - keyboardBtn.SetLabel(&keyboardBtnTxt3, 2); - keyboardBtn.SetImage(&keyboardBtnImg); - keyboardBtn.SetImageOver(&keyboardBtnImgOver); - //keyboardBtn.SetIcon(&keyboardBtnIcon); - keyboardBtn.SetSoundOver(&btnSoundOver); - keyboardBtn.SetSoundClick(&btnSoundClick); - keyboardBtn.SetTrigger(&trigA); - keyboardBtn.SetEffectGrow(); - GuiText nunchukBtnTxt1("Wiimote", 24, (GXColor){0, 0, 0, 255}); GuiText nunchukBtnTxt2("&", 18, (GXColor){0, 0, 0, 255}); GuiText nunchukBtnTxt3("Nunchuk", 24, (GXColor){0, 0, 0, 255}); @@ -2066,8 +2043,8 @@ static int MenuSettingsMappings() GuiImage nunchukBtnImgOver(&btnLargeOutlineOver); GuiImage nunchukBtnIcon(&iconNunchuk); GuiButton nunchukBtn(btnLargeOutline.GetWidth(), btnLargeOutline.GetHeight()); - nunchukBtn.SetAlignment(ALIGN_RIGHT, ALIGN_TOP); - nunchukBtn.SetPosition(-50, 250); + nunchukBtn.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); + nunchukBtn.SetPosition(125, 250); nunchukBtn.SetLabel(&nunchukBtnTxt1, 0); nunchukBtn.SetLabel(&nunchukBtnTxt2, 1); nunchukBtn.SetLabel(&nunchukBtnTxt3, 2); @@ -2102,7 +2079,6 @@ static int MenuSettingsMappings() w.Append(&wiimoteBtn); w.Append(&nunchukBtn); w.Append(&classicBtn); - w.Append(&keyboardBtn); #endif w.Append(&backBtn); @@ -2114,12 +2090,7 @@ static int MenuSettingsMappings() { usleep(THREAD_SLEEP); - if(keyboardBtn.GetState() == STATE_CLICKED) - { - menu = MENU_GAMESETTINGS_MAPPINGS_MAP; - mapMenuCtrl = CTRLR_KEYBOARD; - } - else if(wiimoteBtn.GetState() == STATE_CLICKED) + if(wiimoteBtn.GetState() == STATE_CLICKED) { menu = MENU_GAMESETTINGS_MAPPINGS_MAP; mapMenuCtrl = CTRLR_WIIMOTE; @@ -2232,18 +2203,6 @@ ButtonMappingWindow() if(userInput[0].wpad->btns_d == WPAD_BUTTON_HOME) pressed = WPAD_BUTTON_HOME; } - else if(mapMenuCtrl == CTRLR_KEYBOARD) - { - pressed = 0; - for (int i=4; i<=234; i++) { - if (DownUsbKeys[i]) { - pressed = i; - break; - } - } - if(userInput[0].wpad->btns_d == WPAD_BUTTON_HOME) - pressed = KS_Escape; - } else { pressed = userInput[0].wpad->btns_d; @@ -2274,10 +2233,7 @@ ButtonMappingWindow() } } - if(mapMenuCtrl == CTRLR_KEYBOARD) { - if (pressed == KS_Escape) - pressed = 0; - } else if(pressed == WPAD_BUTTON_HOME || pressed == WPAD_CLASSIC_BUTTON_HOME) + if(pressed == WPAD_BUTTON_HOME || pressed == WPAD_CLASSIC_BUTTON_HOME) pressed = 0; HaltGui(); diff --git a/source/ngc/preferences.cpp b/source/ngc/preferences.cpp index 89debaf..be726b9 100644 --- a/source/ngc/preferences.cpp +++ b/source/ngc/preferences.cpp @@ -205,7 +205,6 @@ preparePrefsData () createXMLController(btnmap[CTRLR_WIIMOTE], "wmpadmap", "Wiimote"); createXMLController(btnmap[CTRLR_CLASSIC], "ccpadmap", "Classic Controller"); createXMLController(btnmap[CTRLR_NUNCHUK], "ncpadmap", "Nunchuk"); - createXMLController(btnmap[CTRLR_KEYBOARD], "kbpadmap", "Keyboard"); int datasize = mxmlSaveString(xml, (char *)savebuffer, SAVEBUFFERSIZE, XMLSaveCallback); @@ -505,7 +504,6 @@ decodePrefsData () loadXMLController(btnmap[CTRLR_WIIMOTE], "wmpadmap"); loadXMLController(btnmap[CTRLR_CLASSIC], "ccpadmap"); loadXMLController(btnmap[CTRLR_NUNCHUK], "ncpadmap"); - loadXMLController(btnmap[CTRLR_KEYBOARD], "kbpadmap"); } mxmlDelete(xml); } diff --git a/source/ngc/utils/ehcmodule_elf.h b/source/ngc/utils/ehcmodule_elf.h new file mode 100644 index 0000000..e2729ca --- /dev/null +++ b/source/ngc/utils/ehcmodule_elf.h @@ -0,0 +1,3 @@ +extern const u8 ehcmodule_elf_end[]; +extern const u8 ehcmodule_elf[]; +extern const u32 ehcmodule_elf_size; diff --git a/source/ngc/utils/mload.c b/source/ngc/utils/mload.c new file mode 100644 index 0000000..4ff589e --- /dev/null +++ b/source/ngc/utils/mload.c @@ -0,0 +1,276 @@ +/* mload.c (for PPC) (c) 2009, Hermes + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include +#include +#include +#include "unistd.h" +#include "ehcmodule_elf.h" + +#define MLOAD_MLOAD_THREAD_ID 0x4D4C4400 +#define MLOAD_LOAD_MODULE 0x4D4C4480 +#define MLOAD_RUN_MODULE 0x4D4C4481 +#define MLOAD_RUN_THREAD 0x4D4C4482 + +#define MLOAD_STOP_THREAD 0x4D4C4484 +#define MLOAD_CONTINUE_THREAD 0x4D4C4485 + +#define MLOAD_GET_LOAD_BASE 0x4D4C4490 +#define MLOAD_MEMSET 0x4D4C4491 + +#define MLOAD_GET_EHCI_DATA 0x4D4C44A0 + +#define MLOAD_SET_ES_IOCTLV 0x4D4C44B0 + +#define getbe32(x) ((adr[x]<<24) | (adr[x+1]<<16) | (adr[x+2]<<8) | (adr[x+3])) + +typedef struct +{ + u32 ident0; + u32 ident1; + u32 ident2; + u32 ident3; + u32 machinetype; + u32 version; + u32 entry; + u32 phoff; + u32 shoff; + u32 flags; + u16 ehsize; + u16 phentsize; + u16 phnum; + u16 shentsize; + u16 shnum; + u16 shtrndx; +} elfheader; + +typedef struct +{ + u32 type; + u32 offset; + u32 vaddr; + u32 paddr; + u32 filesz; + u32 memsz; + u32 flags; + u32 align; +} elfphentry; + +typedef struct +{ + void *start; + int prio; + void *stack; + int size_stack; +} data_elf; + +static const char mload_fs[] ATTRIBUTE_ALIGN(32) = "/dev/mload"; +static s32 mload_fd = -1; + +// to init/test if the device is running +int mload_init() +{ + int n; + + if (mload_fd >= 0) + return 0; + + for (n = 0; n < 10; n++) // try 2.5 seconds + { + mload_fd = IOS_Open(mload_fs, 0); + + if (mload_fd >= 0) + break; + + usleep(250 * 1000); + } + + return mload_fd; +} + +// to close the device (remember call it when rebooting the IOS!) +int mload_close() +{ + int ret; + + if (mload_fd < 0) + return -1; + + ret = IOS_Close(mload_fd); + + mload_fd = -1; + + return ret; +} + +// fix starlet address to read/write (uses SEEK_SET, etc as mode) +static int mload_seek(int offset, int mode) +{ + if (mload_init() < 0) + return -1; + return IOS_Seek(mload_fd, offset, mode); +} + +// write bytes from starlet (it update the offset) +static int mload_write(const void * buf, u32 size) +{ + if (mload_init() < 0) + return -1; + return IOS_Write(mload_fd, buf, size); +} + +// fill a block (similar to memset) +static int mload_memset(void *starlet_addr, int set, int len) +{ + int ret; + s32 hid = -1; + + if (mload_init() < 0) + return -1; + + hid = iosCreateHeap(0x800); + + if (hid < 0) + return hid; + + ret = IOS_IoctlvFormat(hid, mload_fd, MLOAD_MEMSET, "iii:", starlet_addr, + set, len); + + iosDestroyHeap(hid); + + return ret; +} + +// load a module from the PPC +// the module must be a elf made with stripios +static int mload_elf(void *my_elf, data_elf *data_elf) +{ + int n, m; + int p; + u8 *adr; + u32 elf = (u32) my_elf; + + if (elf & 3) + return -1; // aligned to 4 please! + + elfheader *head = (void *) elf; + elfphentry *entries; + + if (head->ident0 != 0x7F454C46) + return -1; + if (head->ident1 != 0x01020161) + return -1; + if (head->ident2 != 0x01000000) + return -1; + + p = head->phoff; + + data_elf->start = (void *) head->entry; + + for (n = 0; n < head->phnum; n++) + { + entries = (void *) (elf + p); + p += sizeof(elfphentry); + + if (entries->type == 4) + { + adr = (void *) (elf + entries->offset); + + if (getbe32(0) != 0) + return -2; // bad info (sure) + + for (m = 4; m < entries->memsz; m += 8) + { + switch (getbe32(m)) + { + case 0x9: + data_elf->start = (void *) getbe32(m+4); + break; + case 0x7D: + data_elf->prio = getbe32(m+4); + break; + case 0x7E: + data_elf->size_stack = getbe32(m+4); + break; + case 0x7F: + data_elf->stack = (void *) (getbe32(m+4)); + break; + + } + } + } + else if (entries->type == 1 && entries->memsz != 0 && entries->vaddr != 0) + { + + if (mload_memset((void *) entries->vaddr, 0, entries->memsz) < 0) + return -1; + if (mload_seek(entries->vaddr, SEEK_SET) < 0) + return -1; + if (mload_write((void *) (elf + entries->offset), entries->filesz) < 0) + return -1; + } + } + + return 0; +} + +// run one thread (you can use to load modules or binary files) +static int mload_run_thread(void *starlet_addr, void *starlet_top_stack, + int stack_size, int priority) +{ + int ret; + s32 hid = -1; + + if (mload_init() < 0) + return -1; + + hid = iosCreateHeap(0x800); + + if (hid < 0) + return hid; + + ret = IOS_IoctlvFormat(hid, mload_fd, MLOAD_RUN_THREAD, "iiii:", + starlet_addr, starlet_top_stack, stack_size, priority); + + iosDestroyHeap(hid); + + return ret; +} + +bool load_ehci_module() +{ + data_elf my_data_elf; + my_data_elf.start = NULL; + my_data_elf.prio = 0; + my_data_elf.stack = NULL; + my_data_elf.size_stack = 0; + + if(mload_elf((void *) ehcmodule_elf, &my_data_elf) != 0) + return false; + + if (mload_run_thread(my_data_elf.start, my_data_elf.stack, + my_data_elf.size_stack, my_data_elf.prio) < 0) + { + usleep(1000); + if (mload_run_thread(my_data_elf.start, my_data_elf.stack, + my_data_elf.size_stack, 0x47) < 0) + return false; + } + return true; +} diff --git a/source/ngc/utils/mload.h b/source/ngc/utils/mload.h new file mode 100644 index 0000000..db6bb5b --- /dev/null +++ b/source/ngc/utils/mload.h @@ -0,0 +1,33 @@ +/* mload.c (for PPC) (c) 2009, Hermes + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef __MLOAD_H__ +#define __MLOAD_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +int mload_init(); +bool load_ehci_module(); +int mload_close(); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/source/ngc/utils/usb2storage.c b/source/ngc/utils/usb2storage.c new file mode 100644 index 0000000..3e49689 --- /dev/null +++ b/source/ngc/utils/usb2storage.c @@ -0,0 +1,451 @@ +/*------------------------------------------------------------- + +usb2storage.c -- USB mass storage support, inside starlet +Copyright (C) 2008 Kwiirk +Improved for homebrew by rodries + +If this driver is linked before libogc, this will replace the original +usbstorage driver by svpe from libogc + +CIOS_usb2 must be loaded! + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you +must not claim that you wrote the original software. If you use +this software in a product, an acknowledgment in the product +documentation would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. + + -------------------------------------------------------------*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//#define DEBUG_USB2 + +#ifdef DEBUG_USB2 +#define debug_printf(fmt, args...) \ + fprintf(stderr, "%s:%d:" fmt, __FUNCTION__, __LINE__, ##args) +#else +#define debug_printf(fmt, args...) +#endif // DEBUG_USB2 + +#define UMS_BASE (('U'<<24)|('M'<<16)|('S'<<8)) +#define USB_IOCTL_UMS_INIT (UMS_BASE+0x1) +#define USB_IOCTL_UMS_GET_CAPACITY (UMS_BASE+0x2) +#define USB_IOCTL_UMS_READ_SECTORS (UMS_BASE+0x3) +#define USB_IOCTL_UMS_WRITE_SECTORS (UMS_BASE+0x4) +#define USB_IOCTL_UMS_READ_STRESS (UMS_BASE+0x5) +#define USB_IOCTL_UMS_SET_VERBOSE (UMS_BASE+0x6) +#define USB_IOCTL_UMS_IS_INSERTED (UMS_BASE+0x7) + +#define USB_IOCTL_UMS_UMOUNT (UMS_BASE+0x10) +#define USB_IOCTL_UMS_START (UMS_BASE+0x11) +#define USB_IOCTL_UMS_STOP (UMS_BASE+0x12) +#define USB_IOCTL_UMS_EXIT (UMS_BASE+0x16) + +#define UMS_HEAPSIZE 2*1024 +#define UMS_MAXPATH 16 + +static s32 hId = -1; +static s32 fd = -1; +static u32 sector_size; +static s32 usb2 = -1; +static mutex_t usb2_mutex = LWP_MUTEX_NULL; +static u8 *fixed_buffer = NULL; +static s32 usb2_inited = 0; + +#define ROUNDDOWN32(v) (((u32)(v)-0x1f)&~0x1f) +#define USB2_BUFFER 128*1024 +static heap_cntrl usb2_heap; +static u8 __usb2_heap_created = 0; + +static DISC_INTERFACE __io_usb1storage; +static int usb1disc_inited = 0; +extern const DISC_INTERFACE __io_usb2storage; +static int currentMode = 2; // 1 = use USB1 interface, 2 = use USB2 interface + +static s32 USB2CreateHeap() +{ + u32 level; + void *usb2_heap_ptr; + + _CPU_ISR_Disable(level); + + if (__usb2_heap_created != 0) + { + _CPU_ISR_Restore(level); + return IPC_OK; + } + + usb2_heap_ptr = (void *) ROUNDDOWN32(((u32)SYS_GetArena2Hi() - (USB2_BUFFER+(4*1024)))); + if ((u32) usb2_heap_ptr < (u32) SYS_GetArena2Lo()) + { + _CPU_ISR_Restore(level); + return IPC_ENOMEM; + } + SYS_SetArena2Hi(usb2_heap_ptr); + __lwp_heap_init(&usb2_heap, usb2_heap_ptr, (USB2_BUFFER + (4 * 1024)), 32); + __usb2_heap_created = 1; + _CPU_ISR_Restore(level); + return IPC_OK; +} + +static s32 USB2Storage_Initialize(int verbose) +{ + s32 ret = USB_OK; + u32 size = 0; + char *devicepath = NULL; + + //if(usb2_inited) return ret; + + if (usb2_mutex == LWP_MUTEX_NULL) + LWP_MutexInit(&usb2_mutex, false); + + LWP_MutexLock(usb2_mutex); + + if (hId == -1) + hId = iosCreateHeap(UMS_HEAPSIZE); + + if (hId < 0) + { + LWP_MutexUnlock(usb2_mutex); + debug_printf("error IPC_ENOMEM\n",fd); + return IPC_ENOMEM; + } + + if (USB2CreateHeap() != IPC_OK) + { + debug_printf("error USB2 IPC_ENOMEM\n",fd); + return IPC_ENOMEM; + } + + if (fixed_buffer == NULL) + fixed_buffer = __lwp_heap_allocate(&usb2_heap, USB2_BUFFER); + + if (fd < 0) + { + devicepath = iosAlloc(hId, UMS_MAXPATH); + if (devicepath == NULL) + { + LWP_MutexUnlock(usb2_mutex); + return IPC_ENOMEM; + } + + snprintf(devicepath, USB_MAXPATH, "/dev/usb2"); + fd = IOS_Open(devicepath, 0); + iosFree(hId, devicepath); + } + + ret = fd; + debug_printf("usb2 fd: %d\n",fd); + usleep(500); + + if (fd > 0) + { + if (verbose) + ret = IOS_IoctlvFormat(hId, fd, USB_IOCTL_UMS_SET_VERBOSE, ":"); + ret = IOS_IoctlvFormat(hId, fd, USB_IOCTL_UMS_INIT, ":"); + debug_printf("usb2 init value: %i\n", ret); + + if (ret < 0) + debug_printf("usb2 error init\n"); + else + size = IOS_IoctlvFormat(hId, fd, USB_IOCTL_UMS_GET_CAPACITY, ":i", + §or_size); + debug_printf("usb2 GET_CAPACITY: %d\n", size); + + if (size == 0) + ret = -2012; + else + ret = 1; + } + else + { + ret = -1; + } + + LWP_MutexUnlock(usb2_mutex); + + if(ret >= 0) + usb2_inited = 1; + + return ret; +} + +static inline int is_MEM2_buffer(const void *buffer) +{ + u32 high_addr = ((u32) buffer) >> 24; + return (high_addr == 0x90) || (high_addr == 0xD0); +} + +void USB2Enable(bool enable) +{ + if(!usb1disc_inited) + { + usb1disc_inited = 1; + memcpy(&__io_usb1storage, &__io_usbstorage, sizeof(DISC_INTERFACE)); + } + + if(!enable) + { + __io_usbstorage = __io_usb1storage; + } + else + { + //USB2Storage_Initialize(0); + __io_usbstorage = __io_usb2storage; + } +} + +/* +static s32 USB2Storage_Get_Capacity(u32*_sector_size) +{ + if(fd>0) + { + LWP_MutexLock(usb2_mutex); + s32 ret = IOS_IoctlvFormat(hId,fd,USB_IOCTL_UMS_GET_CAPACITY,":i",§or_size); + if(_sector_size) + *_sector_size = sector_size; + LWP_MutexUnlock(usb2_mutex); + return ret; + } + else + return IPC_ENOENT; +} + +s32 GetInitValue() +{ + return usb2_init_value; +} + +s32 USB2Unmount() +{ + return IOS_IoctlvFormat(hId, fd, USB_IOCTL_UMS_UMOUNT, ":"); +} +s32 USB2Start() +{ + return IOS_IoctlvFormat(hId, fd, USB_IOCTL_UMS_START, ":"); +} +s32 USB2Stop() +{ + return IOS_IoctlvFormat(hId, fd, USB_IOCTL_UMS_STOP, ":"); +} + +void USB2Close() +{ + if (fd > 0) + IOS_Close(fd); + fd = -1; +} + +int USB2ReadSector(u32 sector) +{ + void *b; + s32 ret; + b = malloc(1024); + ret = USBStorage_Read_Sectors(sector, 1, b); + free(b); + return ret; +} +*/ + +static bool __usb2storage_Startup(void) +{ + bool ret; + + usb2 = USB2Storage_Initialize(0); + + if(usb2 >= 0) + { + currentMode = 2; + ret = true; + } + else if (usb2 < 0) + { + ret = __io_usb1storage.startup(); + + if(ret) + currentMode = 1; + } + return ret; +} + +static bool __usb2storage_IsInserted(void) +{ + int retval; + bool ret = false; + + if (usb2 == -1) + { + retval = __usb2storage_Startup(); + debug_printf("__usb2storage_Startup ret: %d fd: %i\n",retval,fd); + } + //else + LWP_MutexLock(usb2_mutex); + if (fd > 0) + { + + retval = IOS_IoctlvFormat(hId, fd, USB_IOCTL_UMS_IS_INSERTED, ":"); + debug_printf("isinserted usb2 retval: %d ret: %d\n",retval,ret); + + if (retval > 0) + { + currentMode = 2; + ret = true; + debug_printf("isinserted(2) usb2 retval: %d ret: %d\n",retval,ret); + } + + } + if(ret==false) + { + retval = __io_usb1storage.isInserted(); + + if (retval > 0) + { + debug_printf("isinserted usb1 retval: %d\n",retval); + currentMode = 1; + ret = true; + } + } + debug_printf("final isinserted usb2 retval: %d ret: %d\n",retval,ret); + LWP_MutexUnlock(usb2_mutex); + return ret; +} + +static bool __usb2storage_ReadSectors(u32 sector, u32 numSectors, void *buffer) +{ + s32 ret = 1; + u32 sectors = 0; + uint8_t *dest = buffer; + + if (currentMode == 1) + return __io_usb1storage.readSectors(sector, numSectors, buffer); + + if (fd < 1) + return IPC_ENOENT; + + LWP_MutexLock(usb2_mutex); + + while (numSectors > 0) + { + if (numSectors * sector_size > USB2_BUFFER) + sectors = USB2_BUFFER / sector_size; + else + sectors = numSectors; + + if (!is_MEM2_buffer(dest)) //libfat is not providing us good buffers :-( + { + ret = IOS_IoctlvFormat(hId, fd, USB_IOCTL_UMS_READ_SECTORS, "ii:d", + sector, sectors, fixed_buffer, sector_size * sectors); + memcpy(dest, fixed_buffer, sector_size * sectors); + } + else + ret = IOS_IoctlvFormat(hId, fd, USB_IOCTL_UMS_READ_SECTORS, "ii:d", + sector, sectors, dest, sector_size * sectors); + + dest += sector_size * sectors; + if (ret < 1) break; + + sector += sectors; + numSectors -= sectors; + } + if(ret<1)usb2 = -1; + LWP_MutexUnlock(usb2_mutex); + if (ret < 1) return false; + return true; +} + +static bool __usb2storage_WriteSectors(u32 sector, u32 numSectors, const void *buffer) +{ + s32 ret = 1; + u32 sectors = 0; + uint8_t *dest = (uint8_t *) buffer; + + if (currentMode == 1) + return __io_usb1storage.writeSectors(sector, numSectors, buffer); + + if (fd < 1) + return IPC_ENOENT; + + LWP_MutexLock(usb2_mutex); + while (numSectors > 0 && ret > 0) + { + if (numSectors * sector_size > USB2_BUFFER) + sectors = USB2_BUFFER / sector_size; + else + sectors = numSectors; + + numSectors -= sectors; + + if (!is_MEM2_buffer(dest)) // libfat is not providing us good buffers :-( + { + memcpy(fixed_buffer, dest, sector_size * sectors); + ret = IOS_IoctlvFormat(hId, fd, USB_IOCTL_UMS_WRITE_SECTORS, + "ii:d", sector, sectors, fixed_buffer, sector_size + * sectors); + } + else + ret = IOS_IoctlvFormat(hId, fd, USB_IOCTL_UMS_WRITE_SECTORS, + "ii:d", sector, sectors, dest, sector_size * sectors); + if (ret < 1)break; + + dest += sector_size * sectors; + sector += sectors; + } + LWP_MutexUnlock(usb2_mutex); + if(ret < 1 ) return false; + return true; +} + +static bool __usb2storage_ClearStatus(void) +{ + if (currentMode == 1) + return __io_usb1storage.clearStatus(); + + return true; +} + +static bool __usb2storage_Shutdown(void) +{ + if (currentMode == 1) + return __io_usb1storage.shutdown(); + + LWP_MutexLock(usb2_mutex); + debug_printf("__usb2storage_Shutdown\n"); + usb2 = -1; + LWP_MutexUnlock(usb2_mutex); + return true; +} + +const DISC_INTERFACE __io_usb2storage = { + DEVICE_TYPE_WII_USB, + FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE | FEATURE_WII_USB, + (FN_MEDIUM_STARTUP) & __usb2storage_Startup, + (FN_MEDIUM_ISINSERTED) & __usb2storage_IsInserted, + (FN_MEDIUM_READSECTORS) & __usb2storage_ReadSectors, + (FN_MEDIUM_WRITESECTORS) & __usb2storage_WriteSectors, + (FN_MEDIUM_CLEARSTATUS) & __usb2storage_ClearStatus, + (FN_MEDIUM_SHUTDOWN) & __usb2storage_Shutdown +}; diff --git a/source/ngc/utils/usb2storage.h b/source/ngc/utils/usb2storage.h new file mode 100644 index 0000000..7193a30 --- /dev/null +++ b/source/ngc/utils/usb2storage.h @@ -0,0 +1,16 @@ + +#ifndef __USB2STORAGE_H__ +#define __USB2STORAGE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +void USB2Enable(bool enable); + +#ifdef __cplusplus + } +#endif + + +#endif diff --git a/source/ngc/vba.cpp b/source/ngc/vba.cpp index 8bb8c3e..b25af1f 100644 --- a/source/ngc/vba.cpp +++ b/source/ngc/vba.cpp @@ -25,6 +25,8 @@ #include "gba/Sound.h" +#include "utils/usb2storage.h" +#include "utils/mload.h" #include "vba.h" #include "vbasupport.h" #include "preferences.h" @@ -36,7 +38,6 @@ #include "input.h" #include "video.h" #include "gamesettings.h" -#include "wiiusbsupport.h" extern "C" { extern void __exception_setreload(int t); @@ -175,6 +176,48 @@ static void ipl_set_config(unsigned char c) } #endif +/**************************************************************************** + * IOS 202 + ***************************************************************************/ +#ifdef HW_RVL +static bool FindIOS(u32 ios) +{ + s32 ret; + u32 n; + + u64 *titles = NULL; + u32 num_titles=0; + + ret = ES_GetNumTitles(&num_titles); + if (ret < 0) + return false; + + if(num_titles < 1) + return false; + + titles = (u64 *)memalign(32, num_titles * sizeof(u64) + 32); + if (!titles) + return false; + + ret = ES_GetTitles(titles, num_titles); + if (ret < 0) + { + free(titles); + return false; + } + + for(n=0; n < num_titles; n++) + { + if((titles[n] & 0xFFFFFFFF)==ios) + { + free(titles); + return true; + } + } + free(titles); + return false; +} +#endif /**************************************************************************** * USB Gecko Debugging ***************************************************************************/ @@ -244,7 +287,16 @@ int main(int argc, char *argv[]) #endif #ifdef HW_RVL - DI_Init(); // first + // try to load IOS 202 + if(IOS_GetVersion() != 202 && FindIOS(202)) + IOS_ReloadIOS(202); + + DI_LoadDVDX(false); + DI_Init(); + + // load usb2 driver + if(mload_init() >= 0 && load_ehci_module()) + USB2Enable(true); #endif InitDeviceThread(); @@ -281,8 +333,6 @@ int main(int argc, char *argv[]) CreateAppPath(argv[0]); #endif - StartWiiKeyboardMouse(); - while(1) // main loop { // go back to checking if devices were inserted/removed diff --git a/source/ngc/wiiusbsupport.cpp b/source/ngc/wiiusbsupport.cpp deleted file mode 100644 index 528d879..0000000 --- a/source/ngc/wiiusbsupport.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/**************************************************************************** - * Visual Boy Advance GX - * - * Tantric August 2009 - * - * wiiusbsupport.cpp - * - * Wii USB Keyboard and USB Mouse support - ***************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "wiiusbsupport.h" - -u16 DownUsbKeys[65536]; - -#ifdef HW_RVL - -static lwp_t eventthread = LWP_THREAD_NULL; - -u16 DownUsbShiftKeys = 0; - -s32 MouseDirectInputX = 0; -s32 MouseDirectInputY = 0; - -static void KeyPress(u16 key) -{ - if(key >= 0x61 && key <= 0x7a) // lowercase letter - DownUsbKeys[key-32] = 1; // press the uppercase letter too - else if(key >= 0x41 && key <= 0x5a) // uppercase letter - DownUsbKeys[key+32] = 1; // press the lowercase letter too - - DownUsbKeys[key] = 1; -} - -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; -} - -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() -{ - for (int i=0; i<65536; i++) - { - if (DownUsbKeys[i]) - return true; - } - return false; -} - -void StartWiiKeyboardMouse() -{ - memset(DownUsbKeys, 0, sizeof(DownUsbKeys)); - - MOUSE_Init(); - KEYBOARD_Init(NULL); - if(eventthread == LWP_THREAD_NULL) - LWP_CreateThread(&eventthread, eventcallback, NULL, NULL, 0, 80); -} - -#else // GameCube stub - -bool AnyKeyDown() -{ - return false; -} -void StartWiiKeyboardMouse() -{ - memset(DownUsbKeys, 0, sizeof(DownUsbKeys)); -} - -#endif diff --git a/source/ngc/wiiusbsupport.h b/source/ngc/wiiusbsupport.h deleted file mode 100644 index b628f24..0000000 --- a/source/ngc/wiiusbsupport.h +++ /dev/null @@ -1,26 +0,0 @@ -/**************************************************************************** - * Visual Boy Advance GX - * - * Tantric August 2009 - * - * wiiusbsupport.h - * - * Wii USB Keyboard and USB Mouse support - ***************************************************************************/ - -#ifndef _WIIUSBSUPPORT_H_ -#define _WIIUSBSUPPORT_H_ - -#include - -#define MOUSEL 65533 -#define MOUSER 65534 -#define MOUSEM 65535 - -void StartWiiKeyboardMouse(); -bool AnyKeyDown(); - -extern u16 DownUsbKeys[65536]; -extern u16 DownUsbShiftKeys; - -#endif