From f4715d3c26b0a1b536815b344d27ab076fe43541 Mon Sep 17 00:00:00 2001 From: "Carl.Kenner" Date: Fri, 20 Mar 2009 20:22:22 +0000 Subject: [PATCH] =?UTF-8?q?Rumble=20for=20all=20GBC=20rumble=20games=20and?= =?UTF-8?q?=20Drill=20Dozer.=20Rumble=20should=20work=20on=20Gamecube=20co?= =?UTF-8?q?ntroller=20too.=20The=20following=20games=20have=20native=20rum?= =?UTF-8?q?ble=20support:=20WarioWare=20Twisted,=20Drill=20Dozer,=2010=20P?= =?UTF-8?q?in=20Bowling,=203-D=20Ultra=20Pinball=20Thrillride,=20Disney's?= =?UTF-8?q?=20The=20Little=20Mermaid=20II:=20Pinball=20Frenzy,=20Hole=20in?= =?UTF-8?q?=20One=20Golf,=20Missile=20Command,=20NASCAR=20Challenge,=20Per?= =?UTF-8?q?fect=20Dark,=20Pok=C3=A9mon=20Pinball,=20Polaris=20SnoCross,=20?= =?UTF-8?q?Ready=202=20Rumble=20Boxing,=20Star=20Wars=20Episode=20I:=20Rac?= =?UTF-8?q?er,=20Test=20Drive=20Off-Road=203,=20Tonka=20Raceway,=20Top=20G?= =?UTF-8?q?ear=20Pocket\Top=20Gear=20Rally,=20Vigilante=208,=20Zebco=20Fis?= =?UTF-8?q?hing,=20and=20maybe=20some=20other=20games.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also, rumble and wii-control code has been cleaned up a bit. --- source/ngc/filesel.cpp | 5 +- source/ngc/gameinput.cpp | 451 ++++--------------------------------- source/ngc/input.cpp | 74 +++++- source/ngc/input.h | 3 + source/ngc/memcardop.cpp | 2 + source/ngc/menu.cpp | 14 +- source/ngc/menudraw.cpp | 34 ++- source/ngc/vba.cpp | 4 + source/ngc/vbasupport.cpp | 5 +- source/ngc/video.cpp | 1 + source/vba/System.h | 4 + source/vba/gb/GB.cpp | 3 + source/vba/gb/gbMemory.cpp | 8 +- source/vba/gba/GBA.cpp | 1 + source/vba/gba/RTC.cpp | 18 +- source/vba/gba/RTC.h | 1 + 16 files changed, 185 insertions(+), 443 deletions(-) diff --git a/source/ngc/filesel.cpp b/source/ngc/filesel.cpp index 3079675..de7c862 100644 --- a/source/ngc/filesel.cpp +++ b/source/ngc/filesel.cpp @@ -327,6 +327,7 @@ int FileSelector (int method) ShowFiles (browserList, browser.numEntries, browser.pageIndex, browser.selIndex); redraw = 0; + updateRumbleFrame(); VIDEO_WaitVSync(); // slow things down a bit so we don't overread the pads gc_ay = PAD_StickY (0); @@ -441,8 +442,10 @@ int FileSelector (int method) #ifdef HW_RVL || (WPAD_ButtonsDown(0) & (WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B)) #endif - ) + ) { + updateRumbleFrame(); VIDEO_WaitVSync(); + } if ( strcmp(browserList[0].filename,"..") == 0 ) { browser.selIndex = 0; diff --git a/source/ngc/gameinput.cpp b/source/ngc/gameinput.cpp index bb7fa38..8306921 100644 --- a/source/ngc/gameinput.cpp +++ b/source/ngc/gameinput.cpp @@ -31,8 +31,6 @@ #include "gba/bios.h" #include "gba/GBAinline.h" -extern int WarioRumbleMotor; - u8 ZeldaDxLeftPos = 2, ZeldaDxRightPos = 3, ZeldaDxDownPos = 4; u8 ZeldaDxShieldPos = 5, ZeldaDxSwordPos = 5; @@ -164,11 +162,9 @@ u32 LinksAwakeningInput(unsigned short pad) SelItem = gbReadMemory(0xDB00 + CursorPos); static u8 OldHealth = 0; - static int RumbleCount = 0; // Rumble when they lose health! - if (Health < OldHealth) - if (RumbleCount < 20) - RumbleCount = 20; + if (Health < OldHealth) + systemGameRumble(20); OldHealth = Health; WPADData * wp = WPAD_Data(pad); @@ -184,7 +180,8 @@ u32 LinksAwakeningInput(unsigned short pad) { if (!OnItemScreen) ZeldaDxSheathSword(); - else if (RumbleCount<5) RumbleCount=5; + else + systemGameRumble(5); J |= VBA_BUTTON_A; } } @@ -210,7 +207,7 @@ u32 LinksAwakeningInput(unsigned short pad) if (SwordCount>0) { if (SwordCount == 50) - RumbleCount = 50; + systemGameRumbleOnlyFor(50); if (!OnItemScreen) J |= VBA_BUTTON_A; SwordCount--; @@ -220,7 +217,7 @@ u32 LinksAwakeningInput(unsigned short pad) if (wp->btns_h & WPAD_BUTTON_UP) { J |= VBA_BUTTON_A | VBA_BUTTON_B | VBA_BUTTON_START | VBA_BUTTON_SELECT; - RumbleCount = 5; + systemGameRumbleOnlyFor(5); QuestScreen = false; } @@ -229,7 +226,7 @@ u32 LinksAwakeningInput(unsigned short pad) { if (OnItemScreen) ZeldaDxSwap(ZeldaDxLeftPos, CursorPos); else ZeldaDxSwapBItem(ZeldaDxLeftPos); - RumbleCount = 5; + systemGameRumbleOnlyFor(5); QuestScreen = false; } // Right Item @@ -237,7 +234,7 @@ u32 LinksAwakeningInput(unsigned short pad) { if (OnItemScreen) ZeldaDxSwap(ZeldaDxRightPos, CursorPos); else ZeldaDxSwapBItem(ZeldaDxRightPos); - RumbleCount = 5; + systemGameRumbleOnlyFor(5); QuestScreen = false; } // Down Item @@ -245,7 +242,7 @@ u32 LinksAwakeningInput(unsigned short pad) { if (OnItemScreen) ZeldaDxSwap(ZeldaDxDownPos, CursorPos); else ZeldaDxSwapBItem(ZeldaDxDownPos); - RumbleCount = 5; + systemGameRumbleOnlyFor(5); QuestScreen = false; } // B Item @@ -265,8 +262,8 @@ u32 LinksAwakeningInput(unsigned short pad) BombArrows = false; } }*/ - if (RumbleCount<5) RumbleCount=5; - DelayCount = 10; + systemGameRumble(5); + DelayCount = 10; } else { @@ -346,14 +343,15 @@ u32 LinksAwakeningInput(unsigned short pad) if (SelItem==2 || SelItem==5) { // toggle bomb arrows BombArrows = !BombArrows; - RumbleCount = BombArrows?16:4; + if (BombArrows) systemGameRumbleOnlyFor(16); + else systemGameRumbleOnlyFor(4); if (SelItem==2 && BombArrows) J |= VBA_BUTTON_A; } else if (BombArrows) { // switch off bomb arrows BombArrows = false; - RumbleCount = 4; + systemGameRumbleOnlyFor(4); J |= VBA_BUTTON_A; } QuestScreen = false; @@ -365,19 +363,6 @@ u32 LinksAwakeningInput(unsigned short pad) QuestScreen = false; } - if (RumbleCount>0) - { - WPAD_Rumble(pad, 1); - RumbleCount--; - } - else WPAD_Rumble(pad, 0); - - - if ((J & 48) == 48) - J &= ~16; - if ((J & 192) == 192) - J &= ~128; - return J; } @@ -403,11 +388,9 @@ u32 OracleOfAgesInput(unsigned short pad) //else if (AButtonItem>=0xD && AButtonItem<=0xE) ZTargetButton = VBA_BUTTON_A; ZTargetButton = VBA_BUTTON_A; - static int RumbleCount = 0; // Rumble when they lose health! if (Health < OldHealth) - if (RumbleCount < 20) - RumbleCount = 20; + systemGameRumble(20); OldHealth = Health; WPADData * wp = WPAD_Data(pad); @@ -487,19 +470,6 @@ u32 OracleOfAgesInput(unsigned short pad) if (jp & PAD_TRIGGER_L) J |= ZTargetButton; - if (RumbleCount>0) - { - WPAD_Rumble(pad, 1); - RumbleCount--; - } - else WPAD_Rumble(pad, 0); - - - if ((J & 48) == 48) - J &= ~16; - if ((J & 192) == 192) - J &= ~128; - return J; } @@ -555,11 +525,9 @@ u32 MinishCapInput(unsigned short pad) else ZTargetButton = 0; - static int RumbleCount = 0; // Rumble when they lose health! if (Health < OldHealth) - if (RumbleCount < 20) - RumbleCount = 20; + systemGameRumble(20); OldHealth = Health; int cx, cy, SelRow, SelCol, CursorRow = 0xFF, CursorCol = 0xFF; @@ -797,8 +765,7 @@ u32 MinishCapInput(unsigned short pad) != OldCursorCol)) { // Cursor changed buttons, so rumble - if (RumbleCount < 5) - RumbleCount = 5; + systemGameRumble(5); } OldCursorRow = CursorRow; OldCursorCol = CursorCol; @@ -957,8 +924,7 @@ u32 MinishCapInput(unsigned short pad) if (wp->btns_h & WPAD_BUTTON_A) { J |= VBA_BUTTON_A; - if (RumbleCount<12) - RumbleCount=12; + systemGameRumble(12); } } else if (Subscreen==0x2c) @@ -968,7 +934,6 @@ u32 MinishCapInput(unsigned short pad) { // Sleep button returns to menu instead of sleep if (wp->btns_h & WPAD_BUTTON_A) { - WPAD_Rumble(pad, 0); ConfigRequested = 1; return 0; } @@ -983,7 +948,7 @@ u32 MinishCapInput(unsigned short pad) if (fabs(wp->exp.nunchuk.gforce.y)> 0.6) { J |= VBA_BUTTON_R; - if (RumbleCount<5) RumbleCount=5; + systemGameRumble(5); } } else if (wp->exp.type == WPAD_EXP_NUNCHUK) @@ -991,7 +956,7 @@ u32 MinishCapInput(unsigned short pad) if (fabs(wp->exp.nunchuk.gforce.x)> 0.6) { // Wiiuse bug!!! Not correct values J |= SwordButton; - if (RumbleCount<20) RumbleCount=20; + systemGameRumble(20); } // CAKTODO hold down attack button to do spin attack @@ -1003,7 +968,7 @@ u32 MinishCapInput(unsigned short pad) J |= VBA_BUTTON_A; if (Subscreen==0x2c) { - if (RumbleCount<10) RumbleCount=10; + systemGameRumble(10); } } // Down Item @@ -1017,7 +982,7 @@ u32 MinishCapInput(unsigned short pad) J |= VBA_BUTTON_B; if (Subscreen==0x2c) { - if (RumbleCount<10) RumbleCount=10; + systemGameRumble(10); } } } @@ -1026,7 +991,7 @@ u32 MinishCapInput(unsigned short pad) J |= VBA_BUTTON_B; if (Subscreen==0x2c) { - if (RumbleCount<10) RumbleCount=10; + systemGameRumble(10); } } // Kinstone (doesn't work in items screen) @@ -1078,18 +1043,6 @@ u32 MinishCapInput(unsigned short pad) if (jp & PAD_TRIGGER_L) J |= VBA_BUTTON_A; - if (RumbleCount>0) - { - WPAD_Rumble(pad, 1); - RumbleCount--; - } - else WPAD_Rumble(pad, 0); - - if ((J & 48) == 48) - J &= ~16; - if ((J & 192) == 192) - J &= ~128; - return J; } @@ -1099,11 +1052,9 @@ u32 ALinkToThePastInput(unsigned short pad) u8 Health = 0; static u8 OldHealth = 0; - static int RumbleCount = 0; // Rumble when they lose health! if (Health < OldHealth) - if (RumbleCount < 20) - RumbleCount = 20; + systemGameRumble(20); OldHealth = Health; WPADData * wp = WPAD_Data(pad); @@ -1120,7 +1071,7 @@ u32 ALinkToThePastInput(unsigned short pad) if (fabs(wp->exp.nunchuk.gforce.x)> 0.6) { // Wiiuse bug!!! Not correct values J |= VBA_BUTTON_B; - if (RumbleCount<20) RumbleCount=20; + systemGameRumble(20); } // CAKTODO hold down attack button to do spin attack @@ -1161,19 +1112,6 @@ u32 ALinkToThePastInput(unsigned short pad) if ((wp->exp.type == WPAD_EXP_NUNCHUK) && (wp->btns_h & WPAD_NUNCHUK_BUTTON_C)) J |= VBA_SPEED; - if (RumbleCount>0) - { - WPAD_Rumble(pad, 1); - RumbleCount--; - } - else - WPAD_Rumble(pad, 0); - - if ((J & 48) == 48) - J &= ~16; - if ((J & 192) == 192) - J &= ~128; - return J; } @@ -1183,11 +1121,9 @@ u32 Zelda1Input(unsigned short pad) u8 Health = 0; static u8 OldHealth = 0; - static int RumbleCount = 0; // Rumble when they lose health! if (Health < OldHealth) - if (RumbleCount < 20) - RumbleCount = 20; + systemGameRumble(20); OldHealth = Health; WPADData * wp = WPAD_Data(pad); @@ -1204,7 +1140,7 @@ u32 Zelda1Input(unsigned short pad) if (fabs(wp->exp.nunchuk.gforce.x)> 0.6) { // Wiiuse bug!!! Not correct values J |= VBA_BUTTON_A; - if (RumbleCount<20) RumbleCount=20; + systemGameRumble(20); } } // Use item @@ -1241,19 +1177,6 @@ u32 Zelda1Input(unsigned short pad) if ((wp->exp.type == WPAD_EXP_NUNCHUK) && (wp->btns_h & WPAD_NUNCHUK_BUTTON_C)) J |= VBA_SPEED; - if (RumbleCount>0) - { - WPAD_Rumble(pad, 1); - RumbleCount--; - } - else WPAD_Rumble(pad, 0); - - - if ((J & 48) == 48) - J &= ~16; - if ((J & 192) == 192) - J &= ~128; - return J; } @@ -1263,11 +1186,9 @@ u32 Zelda2Input(unsigned short pad) u8 Health = 0; static u8 OldHealth = 0; - static int RumbleCount = 0; // Rumble when they lose health! if (Health < OldHealth) - if (RumbleCount < 20) - RumbleCount = 20; + systemGameRumble(20); OldHealth = Health; WPADData * wp = WPAD_Data(pad); @@ -1285,7 +1206,7 @@ u32 Zelda2Input(unsigned short pad) if (fabs(wp->exp.nunchuk.gforce.x)> 0.6) { // Wiiuse bug!!! Not correct values J |= VBA_BUTTON_B; - if (RumbleCount<20) RumbleCount=20; + systemGameRumble(20); } } // Use item @@ -1324,18 +1245,6 @@ u32 Zelda2Input(unsigned short pad) if ((wp->exp.type == WPAD_EXP_NUNCHUK) && (wp->btns_h & WPAD_NUNCHUK_BUTTON_C)) J |= VBA_SPEED; - if (RumbleCount>0) - { - WPAD_Rumble(pad, 1); - RumbleCount--; - } - else WPAD_Rumble(pad, 0); - - - if ((J & 48) == 48) - J &= ~16; - if ((J & 192) == 192) - J &= ~128; return J; } @@ -1346,11 +1255,9 @@ u32 MK1Input(unsigned short pad) u8 Health = gbReadMemory(0xc695); static u8 OldHealth = 0; - static int RumbleCount = 0; // Rumble when they lose health! if (Health < OldHealth) - if (RumbleCount < 5) - RumbleCount = 5; + systemGameRumble(5); OldHealth = Health; WPADData * wp = WPAD_Data(pad); @@ -1379,19 +1286,6 @@ u32 MK1Input(unsigned short pad) // CAKTODO } - if (RumbleCount>0) - { - WPAD_Rumble(pad, 1); - RumbleCount--; - } - else WPAD_Rumble(pad, 0); - - - if ((J & 48) == 48) - J &= ~16; - if ((J & 192) == 192) - J &= ~128; - return J; } @@ -1401,11 +1295,9 @@ u32 MK4Input(unsigned short pad) u8 Health = 0; static u8 OldHealth = 0; - static int RumbleCount = 0; // Rumble when they lose health! if (Health < OldHealth) - if (RumbleCount < 20) - RumbleCount = 20; + systemGameRumble(20); OldHealth = Health; WPADData * wp = WPAD_Data(pad); @@ -1434,19 +1326,6 @@ u32 MK4Input(unsigned short pad) // CAKTODO } - if (RumbleCount>0) - { - WPAD_Rumble(pad, 1); - RumbleCount--; - } - else WPAD_Rumble(pad, 0); - - - if ((J & 48) == 48) - J &= ~16; - if ((J & 192) == 192) - J &= ~128; - return J; } @@ -1456,11 +1335,9 @@ u32 MKAInput(unsigned short pad) u8 Health = 0; static u8 OldHealth = 0; - static int RumbleCount = 0; // Rumble when they lose health! if (Health < OldHealth) - if (RumbleCount < 20) - RumbleCount = 20; + systemGameRumble(20); OldHealth = Health; WPADData * wp = WPAD_Data(pad); @@ -1489,19 +1366,6 @@ u32 MKAInput(unsigned short pad) // CAKTODO } - if (RumbleCount>0) - { - WPAD_Rumble(pad, 1); - RumbleCount--; - } - else - WPAD_Rumble(pad, 0); - - if ((J & 48) == 48) - J &= ~16; - if ((J & 192) == 192) - J &= ~128; - return J; } @@ -1524,11 +1388,9 @@ u32 MKTEInput(unsigned short pad) } static u8 OldHealth = 0; - static int RumbleCount = 0; // Rumble when they lose health! if (Health < OldHealth) - if (RumbleCount < 20) - RumbleCount = 20; + systemGameRumble(20); OldHealth = Health; u32 Forwards, Back; @@ -1588,14 +1450,6 @@ u32 MKTEInput(unsigned short pad) J |= VBA_SPEED; } - if (RumbleCount>0) - { - WPAD_Rumble(pad, 1); - RumbleCount--; - } - else - WPAD_Rumble(pad, 0); - if ((J & 48) == 48) J &= ~16; if ((J & 192) == 192) @@ -1617,11 +1471,9 @@ u32 MarioKartInput(unsigned short pad) static u8 OldHealth = 0; float fraction; - static int RumbleCount = 0; // Rumble when they lose health! if (Health < OldHealth) - if (RumbleCount < 20) - RumbleCount = 20; + systemGameRumble(20); OldHealth = Health; // Start/Select @@ -1727,19 +1579,6 @@ u32 MarioKartInput(unsigned short pad) || jp & PAD_BUTTON_RIGHT) J |= VBA_BUTTON_R; - if (RumbleCount>0) - { - WPAD_Rumble(pad, 1); - RumbleCount--; - } - else WPAD_Rumble(pad, 0); - - - if ((J & 48) == 48) - J &= ~16; - if ((J & 192) == 192) - J &= ~128; - frame++; return J; @@ -1752,11 +1591,9 @@ u32 LegoStarWars1Input(unsigned short pad) u8 Health = 0; static u8 OldHealth = 0; - static int RumbleCount = 0; // Rumble when they lose health! if (Health < OldHealth) - if (RumbleCount < 20) - RumbleCount = 20; + systemGameRumble(20); OldHealth = Health; WPADData * wp = WPAD_Data(pad); @@ -1802,20 +1639,6 @@ u32 LegoStarWars1Input(unsigned short pad) // CAKTODO same as game boy for now J |= StandardGamecube(pad) | StandardKeyboard(pad); - - if (RumbleCount>0) - { - WPAD_Rumble(pad, 1); - RumbleCount--; - } - else WPAD_Rumble(pad, 0); - - - if ((J & 48) == 48) - J &= ~16; - if ((J & 192) == 192) - J &= ~128; - return J; } @@ -1825,11 +1648,9 @@ u32 LegoStarWars2Input(unsigned short pad) u8 Health = 0; static u8 OldHealth = 0; - static int RumbleCount = 0; // Rumble when they lose health! if (Health < OldHealth) - if (RumbleCount < 20) - RumbleCount = 20; + systemGameRumble(20); OldHealth = Health; WPADData * wp = WPAD_Data(pad); @@ -1878,20 +1699,6 @@ u32 LegoStarWars2Input(unsigned short pad) // CAKTODO same as game boy for now J |= StandardGamecube(pad) | StandardKeyboard(pad); - - if (RumbleCount>0) - { - WPAD_Rumble(pad, 1); - RumbleCount--; - } - else - WPAD_Rumble(pad, 0); - - if ((J & 48) == 48) - J &= ~16; - if ((J & 192) == 192) - J &= ~128; - return J; } @@ -1903,11 +1710,9 @@ u32 MetroidZeroInput(unsigned short pad) u16 Health = CPUReadByte(0x3001536); // 0 = stand, 1 = crouch, 2 = ball static u16 OldHealth = 0; - static int RumbleCount = 0; // Rumble when they lose health! if (Health < OldHealth) - if (RumbleCount < 20) - RumbleCount = 20; + systemGameRumble(20); OldHealth = Health; static int Morph = 0; @@ -2110,18 +1915,6 @@ u32 MetroidZeroInput(unsigned short pad) if (jp & PAD_BUTTON_START) J |= VBA_BUTTON_START; - if (RumbleCount>0) - { - WPAD_Rumble(pad, 1); - RumbleCount--; - } - else WPAD_Rumble(pad, 0); - - if ((J & 48) == 48) - J &= ~16; - if ((J & 192) == 192) - J &= ~128; - return J; } @@ -2133,11 +1926,9 @@ u32 MetroidFusionInput(unsigned short pad) u16 Health = CPUReadHalfWord(0x3001310); static u16 OldHealth = 0; - static int RumbleCount = 0; // Rumble when they lose health! if (Health < OldHealth) - if (RumbleCount < 20) - RumbleCount = 20; + systemGameRumble(20); OldHealth = Health; static int Morph = 0; @@ -2328,18 +2119,6 @@ u32 MetroidFusionInput(unsigned short pad) if (jp & PAD_BUTTON_START) J |= VBA_BUTTON_START; - if (RumbleCount>0) - { - WPAD_Rumble(pad, 1); - RumbleCount--; - } - else WPAD_Rumble(pad, 0); - - if ((J & 48) == 48) - J &= ~16; - if ((J & 192) == 192) - J &= ~128; - return J; } @@ -2352,11 +2131,9 @@ u32 Metroid1Input(unsigned short pad) u16 Health = CPUReadHalfWord(0x3007306); // Binary Coded Decimal static u16 OldHealth = 0; - static int RumbleCount = 0; // Rumble when they lose health! if (Health < OldHealth) - if (RumbleCount < 20) - RumbleCount = 20; + systemGameRumble(20); OldHealth = Health; static int Morph = 0; @@ -2469,18 +2246,6 @@ u32 Metroid1Input(unsigned short pad) if (jp & PAD_BUTTON_START) J |= VBA_BUTTON_START; - if (RumbleCount>0) - { - WPAD_Rumble(pad, 1); - RumbleCount--; - } - else WPAD_Rumble(pad, 0); - - if ((J & 48) == 48) - J &= ~16; - if ((J & 192) == 192) - J &= ~128; - return J; } @@ -2493,11 +2258,9 @@ u32 Metroid2Input(unsigned short pad) u8 Health = gbReadMemory(0xD051); // Binary Coded Decimal static u8 OldHealth = 0; - static int RumbleCount = 0; // Rumble when they lose (or gain) health! (since I'm not checking energy tanks) if (Health != OldHealth) - if (RumbleCount < 20) - RumbleCount = 20; + systemGameRumble(20); OldHealth = Health; static int Morph = 0; @@ -2636,18 +2399,6 @@ u32 Metroid2Input(unsigned short pad) if (jp & PAD_BUTTON_START) J |= VBA_BUTTON_START; - if (RumbleCount>0) - { - WPAD_Rumble(pad, 1); - RumbleCount--; - } - else WPAD_Rumble(pad, 0); - - if ((J & 48) == 48) - J &= ~16; - if ((J & 192) == 192) - J &= ~128; - return J; } @@ -2686,11 +2437,6 @@ u32 TMNTInput(unsigned short pad) J |= 0; // Double tap D-Pad to roll CAKTODO // CAKTODO - if ((J & 48) == 48) - J &= ~16; - if ((J & 192) == 192) - J &= ~128; - return J; } @@ -2733,11 +2479,6 @@ u32 HarryPotter1GBCInput(unsigned short pad) // CAKTODO spell gestures - if ((J & 48) == 48) - J &= ~16; - if ((J & 192) == 192) - J &= ~128; - return J; } @@ -2777,11 +2518,6 @@ u32 HarryPotter2GBCInput(unsigned short pad) // CAKTODO spell gestures - if ((J & 48) == 48) - J &= ~16; - if ((J & 192) == 192) - J &= ~128; - return J; } @@ -2829,11 +2565,6 @@ u32 HarryPotter1Input(unsigned short pad) // CAKTODO spell gestures - if ((J & 48) == 48) - J &= ~16; - if ((J & 192) == 192) - J &= ~128; - return J; } @@ -2883,11 +2614,6 @@ u32 HarryPotter2Input(unsigned short pad) // CAKTODO spell gestures - if ((J & 48) == 48) - J &= ~16; - if ((J & 192) == 192) - J &= ~128; - return J; } @@ -2937,11 +2663,6 @@ u32 HarryPotter3Input(unsigned short pad) // point at ceiling for Lumos - if ((J & 48) == 48) - J &= ~16; - if ((J & 192) == 192) - J &= ~128; - return J; } @@ -2991,11 +2712,6 @@ u32 HarryPotter4Input(unsigned short pad) // point at ceiling for Lumos - if ((J & 48) == 48) - J &= ~16; - if ((J & 192) == 192) - J &= ~128; - return J; } @@ -3054,11 +2770,6 @@ u32 HarryPotter5Input(unsigned short pad) // CAKTODO spell gestures - if ((J & 48) == 48) - J &= ~16; - if ((J & 192) == 192) - J &= ~128; - return J; } @@ -3155,11 +2866,6 @@ u32 Mario1DXInput(unsigned short pad) J |= StandardGamecube(pad) | StandardKeyboard(pad); - if ((J & 48) == 48) - J &= ~16; - if ((J & 192) == 192) - J &= ~128; - return J; } @@ -3245,11 +2951,6 @@ u32 Mario1ClassicInput(unsigned short pad) J |= StandardGamecube(pad) | StandardKeyboard(pad); - if ((J & 48) == 48) - J &= ~16; - if ((J & 192) == 192) - J &= ~128; - return J; } @@ -3329,11 +3030,6 @@ u32 MarioLand1Input(unsigned short pad) J |= StandardGamecube(pad) | StandardKeyboard(pad); - if ((J & 48) == 48) - J &= ~16; - if ((J & 192) == 192) - J &= ~128; - return J; } @@ -3439,11 +3135,6 @@ u32 MarioLand2Input(unsigned short pad) J |= StandardGamecube(pad) | StandardKeyboard(pad); - if ((J & 48) == 48) - J &= ~16; - if ((J & 192) == 192) - J &= ~128; - return J; } @@ -3490,13 +3181,6 @@ u32 Mario2Input(unsigned short pad) if (wp->btns_h & WPAD_BUTTON_2) J |= VBA_BUTTON_R; - - - if ((J & 48) == 48) - J &= ~16; - if ((J & 192) == 192) - J &= ~128; - return J; } @@ -3631,11 +3315,6 @@ u32 MarioWorldInput(unsigned short pad) J |= StandardKeyboard(pad); - if ((J & 48) == 48) - J &= ~16; - if ((J & 192) == 192) - J &= ~128; - return J; } @@ -3725,11 +3404,6 @@ u32 Mario3Input(unsigned short pad) J |= StandardGamecube(pad) | StandardKeyboard(pad); - if ((J & 48) == 48) - J &= ~16; - if ((J & 192) == 192) - J &= ~128; - return J; } @@ -3838,11 +3512,6 @@ u32 YoshiIslandInput(unsigned short pad) // NeedStomp = false; //} - if ((J & 48) == 48) - J &= ~16; - if ((J & 192) == 192) - J &= ~128; - return J; } @@ -3926,11 +3595,6 @@ u32 UniversalGravitationInput(unsigned short pad) // A bit stupid playing with keyboard or gamecube pad when you need to tilt the wiimote... J |= StandardKeyboard(pad) | StandardGamecube(pad); - if ((J & 48) == 48) - J &= ~16; - if ((J & 192) == 192) - J &= ~128; - return J; } @@ -3941,11 +3605,6 @@ u32 TwistedInput(unsigned short pad) u32 J = StandardMovement(pad); WPADData * wp = WPAD_Data(pad); - if (WarioRumbleMotor) - WPAD_Rumble(pad, 1); - else - WPAD_Rumble(pad, 0); - if (wp->exp.type == WPAD_EXP_NUNCHUK) { TiltSideways = false; @@ -3991,11 +3650,6 @@ u32 TwistedInput(unsigned short pad) // A bit stupid playing with keyboard or gamecube pad when you need to tilt the wiimote... J |= StandardKeyboard(pad) | StandardGamecube(pad); - if ((J & 48) == 48) - J &= ~16; - if ((J & 192) == 192) - J &= ~128; - return J; } @@ -4051,11 +3705,6 @@ u32 KirbyTntInput(unsigned short pad) // A bit stupid playing with keyboard or gamecube pad when you need to tilt the wiimote... J |= StandardKeyboard(pad) | StandardGamecube(pad); - if ((J & 48) == 48) - J &= ~16; - if ((J & 192) == 192) - J &= ~128; - return J; } @@ -4104,11 +3753,6 @@ u32 MohInfiltratorInput(unsigned short pad) J |= StandardGamecube(pad) | StandardKeyboard(pad); - if ((J & 48) == 48) - J &= ~16; - if ((J & 192) == 192) - J &= ~128; - return J; } @@ -4181,11 +3825,6 @@ u32 MohUndergroundInput(unsigned short pad) if (crouched && (!(J & VBA_BUTTON_L)) && (!(J & VBA_BUTTON_R))) J |= VBA_BUTTON_L | VBA_BUTTON_R; - if ((J & 48) == 48) - J &= ~16; - if ((J & 192) == 192) - J &= ~128; - return J; } @@ -4248,11 +3887,6 @@ u32 BoktaiInput(unsigned short pad) J |= StandardGamecube(pad) | StandardKeyboard(pad); - if ((J & 48) == 48) - J &= ~16; - if ((J & 192) == 192) - J &= ~128; - return J; } @@ -4318,11 +3952,6 @@ u32 Boktai2Input(unsigned short pad) J |= StandardGamecube(pad) | StandardKeyboard(pad); - if ((J & 48) == 48) - J &= ~16; - if ((J & 192) == 192) - J &= ~128; - return J; } diff --git a/source/ngc/input.cpp b/source/ngc/input.cpp index 2238da1..63b9997 100644 --- a/source/ngc/input.cpp +++ b/source/ngc/input.cpp @@ -29,8 +29,11 @@ #include "gba/bios.h" #include "gba/GBAinline.h" +extern bool InMenu; int rumbleRequest[4] = {0,0,0,0}; static int rumbleCount[4] = {0,0,0,0}; +bool cartridgeRumble = false; +int gameRumbleCount = 0, menuRumbleCount = 0, rumbleCountAlready = 0; unsigned int vbapadmap[10]; // VBA controller buttons unsigned int gcpadmap[10]; // Gamecube controller Padmap @@ -161,6 +164,57 @@ void DoRumble(int i) } } +static void updateRumble() { + bool r = false; + if (InMenu) r = (menuRumbleCount > 0); + else r = cartridgeRumble || (gameRumbleCount > 0) || (menuRumbleCount > 0); + +#ifdef HW_RVL + // Rumble wii remote 0 + WPAD_Rumble(0, r); +#endif + PAD_ControlMotor(PAD_CHAN0, PAD_MOTOR_RUMBLE); +} + +void updateRumbleFrame() { + // If we already rumbled continuously for more than 50 frames, + // then disable rumbling for a while. + if (rumbleCountAlready > 50) { + gameRumbleCount = 0; + menuRumbleCount = 0; + // disable rumbling for 10 more frames + if (rumbleCountAlready > 50+10) + rumbleCountAlready = 0; + else rumbleCountAlready++; + } else if (InMenu) { + if (menuRumbleCount>0) + rumbleCountAlready++; + } else { + if (gameRumbleCount>0 || menuRumbleCount>0 || cartridgeRumble) + rumbleCountAlready++; + } + updateRumble(); + if (gameRumbleCount>0 && !InMenu) gameRumbleCount--; + if (menuRumbleCount>0) menuRumbleCount--; +} + +void systemCartridgeRumble(bool RumbleOn) { + cartridgeRumble = RumbleOn; + updateRumble(); +} + +void systemGameRumble(int RumbleForFrames) { + if (RumbleForFrames > gameRumbleCount) gameRumbleCount = RumbleForFrames; +} + +void systemGameRumbleOnlyFor(int OnlyRumbleForFrames) { + gameRumbleCount = OnlyRumbleForFrames; +} + +void systemMenuRumble(int RumbleForFrames) { + if (RumbleForFrames > menuRumbleCount) menuRumbleCount = RumbleForFrames; +} + /**************************************************************************** * WPAD_Stick * @@ -617,10 +671,6 @@ static u32 DecodeJoy(unsigned short pad) return Boktai2Input(pad); } } - else - { - ShutoffRumble(); - } #endif // the function result, J, is a combination of flags for all the VBA buttons that are down @@ -659,13 +709,9 @@ static u32 DecodeJoy(unsigned short pad) J |= vbapadmap[i]; } - if ((J & 48) == 48) - J &= ~16; - if ((J & 192) == 192) - J &= ~128; - return J; } + u32 GetJoy(int pad) { pad = 0; @@ -699,10 +745,18 @@ u32 GetJoy(int pad) ) { ConfigRequested = 1; + updateRumbleFrame(); return 0; } else { - return DecodeJoy(pad); + u32 J = DecodeJoy(pad); + // don't allow up+down or left+right + if ((J & 48) == 48) + J &= ~16; + if ((J & 192) == 192) + J &= ~128; + updateRumbleFrame(); + return J; } } diff --git a/source/ngc/input.h b/source/ngc/input.h index c64a462..cc5a259 100644 --- a/source/ngc/input.h +++ b/source/ngc/input.h @@ -41,6 +41,9 @@ extern unsigned int kbpadmap[]; void ResetControls(); void ShutoffRumble(); void DoRumble(int i); +void systemGameRumble(int RumbleForFrames); +void systemGameRumbleOnlyFor(int OnlyRumbleForFrames); +void updateRumbleFrame(); s8 WPAD_Stick(u8 chan,u8 right, int axis); u32 GetJoy(int which); diff --git a/source/ngc/memcardop.cpp b/source/ngc/memcardop.cpp index d758c17..d4a61a4 100644 --- a/source/ngc/memcardop.cpp +++ b/source/ngc/memcardop.cpp @@ -15,6 +15,7 @@ #include #include +#include "system.h" #include "vba.h" #include "video.h" #include "menudraw.h" @@ -62,6 +63,7 @@ static int MountCard(int cslot, bool silent, u8 * SysArea) { EXI_ProbeReset (); ret = CARD_Mount (cslot, &SysArea, NULL); + updateRumbleFrame (); VIDEO_WaitVSync (); tries++; } diff --git a/source/ngc/menu.cpp b/source/ngc/menu.cpp index cb06f11..c826dae 100644 --- a/source/ngc/menu.cpp +++ b/source/ngc/menu.cpp @@ -394,10 +394,14 @@ GetInput (u16 ctrlr_type) | WPAD_ButtonsHeld(0) | AnyKeyDown() #endif - ) VIDEO_WaitVSync(); // button 'debounce' + ) { + updateRumbleFrame(); + VIDEO_WaitVSync(); // button 'debounce' + } while (pressed == 0 && !AnyKeyDown()) { + updateRumbleFrame(); VIDEO_WaitVSync(); // get input based on controller type if (ctrlr_type == CTRLR_GCPAD) @@ -424,6 +428,7 @@ GetInput (u16 ctrlr_type) for (int i=4; i<=231; i++) { if (DownUsbKeys[i]) { while (DownUsbKeys[i]) { + updateRumbleFrame(); VIDEO_WaitVSync(); } return i; @@ -434,7 +439,10 @@ GetInput (u16 ctrlr_type) #ifdef HW_RVL | WPAD_ButtonsHeld(0) #endif - ) ) VIDEO_WaitVSync(); + ) ) { + updateRumbleFrame(); + VIDEO_WaitVSync(); + } return pressed; } // end GetInput() @@ -723,6 +731,7 @@ MainMenu (int selectedMenu) else sprintf (menuitems[3], "Game Menu"); + updateRumbleFrame(); VIDEO_WaitVSync (); while (quit == 0) @@ -798,6 +807,7 @@ MainMenu (int selectedMenu) #endif )) { + updateRumbleFrame(); VIDEO_WaitVSync(); count++; } diff --git a/source/ngc/menudraw.cpp b/source/ngc/menudraw.cpp index c5fc2b8..a71943e 100644 --- a/source/ngc/menudraw.cpp +++ b/source/ngc/menudraw.cpp @@ -260,6 +260,7 @@ Credits () DrawText (-1, ypos += 15, "the GNU General Public License (GPL) Version 2."); DrawVersion(); + updateRumbleFrame(); showscreen (); } @@ -306,13 +307,25 @@ WaitButtonA () #ifdef HW_RVL while ( (PAD_ButtonsDown (0) & PAD_BUTTON_A) || (WPAD_ButtonsDown(0) & (WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A)) - || (DownUsbKeys[KB_ENTER])) VIDEO_WaitVSync(); + || (DownUsbKeys[KB_ENTER])) { + updateRumbleFrame(); + VIDEO_WaitVSync(); + } while (!(PAD_ButtonsDown (0) & PAD_BUTTON_A) && !(WPAD_ButtonsDown(0) & (WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A)) - && !(DownUsbKeys[KB_ENTER])) VIDEO_WaitVSync(); + && !(DownUsbKeys[KB_ENTER])) { + updateRumbleFrame(); + VIDEO_WaitVSync(); + } #else - while ( PAD_ButtonsDown (0) & PAD_BUTTON_A ) VIDEO_WaitVSync(); - while (!(PAD_ButtonsDown (0) & PAD_BUTTON_A) ) VIDEO_WaitVSync(); + while ( PAD_ButtonsDown (0) & PAD_BUTTON_A ) { + updateRumbleFrame(); + VIDEO_WaitVSync(); + } + while (!(PAD_ButtonsDown (0) & PAD_BUTTON_A) ) { + updateRumbleFrame(); + VIDEO_WaitVSync(); + } #endif } @@ -329,7 +342,10 @@ WaitButtonAB () while ( (PAD_ButtonsDown (0) & (PAD_BUTTON_A | PAD_BUTTON_B)) || (WPAD_ButtonsDown(0) & (WPAD_BUTTON_A | WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_A | WPAD_CLASSIC_BUTTON_B)) || (DownUsbKeys[KB_ENTER]) || (DownUsbKeys[KB_ESC]) - ) VIDEO_WaitVSync(); + ) { + updateRumbleFrame(); + VIDEO_WaitVSync(); + } while ( TRUE ) { @@ -347,7 +363,10 @@ WaitButtonAB () #else u32 gc_btns; - while ( (PAD_ButtonsDown (0) & (PAD_BUTTON_A | PAD_BUTTON_B)) ) VIDEO_WaitVSync(); + while ( (PAD_ButtonsDown (0) & (PAD_BUTTON_A | PAD_BUTTON_B)) ) { + updateRumbleFrame(); + VIDEO_WaitVSync(); + } while ( TRUE ) { @@ -563,7 +582,7 @@ RunMenu (char items[][50], int maxitems, const char *title, int fontsize, int x) wp = WPAD_ButtonsDown (0); #endif - + updateRumbleFrame(); VIDEO_WaitVSync(); // slow things down a bit so we don't overread the pads /*** Look for up ***/ @@ -620,6 +639,7 @@ RunMenu (char items[][50], int maxitems, const char *title, int fontsize, int x) ) { ret = -1; + updateRumbleFrame(); VIDEO_WaitVSync(); } diff --git a/source/ngc/vba.cpp b/source/ngc/vba.cpp index f7ddf97..c93e62b 100644 --- a/source/ngc/vba.cpp +++ b/source/ngc/vba.cpp @@ -40,6 +40,7 @@ extern "C" { extern bool ROMLoaded; extern int emulating; +bool InMenu = true; int ConfigRequested = 0; int ShutdownRequested = 0; int ResetRequested = 0; @@ -241,6 +242,7 @@ int main(int argc, char *argv[]) while(1) // main loop { + InMenu = true; #ifdef HW_RVL if(ShutdownRequested) ShutdownWii(); @@ -258,6 +260,7 @@ int main(int argc, char *argv[]) LWP_SuspendThread (devicethread); ResetVideo_Emu(); + InMenu = false; while (emulating) // emulation loop { @@ -271,6 +274,7 @@ int main(int argc, char *argv[]) if(ConfigRequested) { + InMenu = true; ShutoffRumble(); StopAudio(); ResetVideo_Menu (); // change to menu video mode diff --git a/source/ngc/vbasupport.cpp b/source/ngc/vbasupport.cpp index 1530c0d..cf8d7ac 100644 --- a/source/ngc/vbasupport.cpp +++ b/source/ngc/vbasupport.cpp @@ -755,10 +755,11 @@ static void ApplyPerImagePreferences() cpuSaveType = 4; // EEPROM + sensor break; case 'R': // WarioWare Twisted style sensors - rtcEnable(1); + case 'V': // Drill Dozer + rtcEnableWarioRumble(true); break; case 'U': // Boktai solar sensor and clock - rtcEnable(1); + rtcEnable(true); break; } } diff --git a/source/ngc/video.cpp b/source/ngc/video.cpp index 7967de2..5320387 100644 --- a/source/ngc/video.cpp +++ b/source/ngc/video.cpp @@ -180,6 +180,7 @@ showscreen () { VIDEO_SetNextFramebuffer (xfb[whichfb]); VIDEO_Flush (); + updateRumbleFrame(); VIDEO_WaitVSync (); } diff --git a/source/vba/System.h b/source/vba/System.h index a81889a..64cd0b6 100644 --- a/source/vba/System.h +++ b/source/vba/System.h @@ -48,6 +48,10 @@ extern void systemDrawScreen(); extern bool systemReadJoypads(); // return information about the given joystick, -1 for default joystick extern u32 systemReadJoypad(int); +// this function should turn on or off rumble on the gamepad +extern void systemCartridgeRumble(bool); +// This should be called once per frame +extern void updateRumbleFrame(); extern u32 systemGetClock(); extern void systemMessage(int, const char *, ...); extern void systemSetTitle(const char *); diff --git a/source/vba/gb/GB.cpp b/source/vba/gb/GB.cpp index 094d304..d3f622e 100644 --- a/source/vba/gb/GB.cpp +++ b/source/vba/gb/GB.cpp @@ -2143,6 +2143,7 @@ void gbGetHardwareType() void gbReset() { + systemCartridgeRumble(false); gbGetHardwareType(); oldRegister_WY = 146; @@ -2616,6 +2617,8 @@ void gbReset() memset(&gbDataMBC5, 0, sizeof(gbDataMBC5)); gbDataMBC5.mapperROMBank = 1; + if (gbRomType >= 0x1c && gbRomType<=0x1e) + gbDataMBC5.isRumbleCartridge = 1; memset(&gbDataHuC1, 0, sizeof(gbDataHuC1)); gbDataHuC1.mapperROMBank = 1; diff --git a/source/vba/gb/gbMemory.cpp b/source/vba/gb/gbMemory.cpp index e7061b9..3c508e6 100644 --- a/source/vba/gb/gbMemory.cpp +++ b/source/vba/gb/gbMemory.cpp @@ -540,6 +540,7 @@ mapperMBC5 gbDataMBC5 = { 0 // is rumble cartridge? }; +extern int ConfigRequested; // MBC5 ROM write registers void mapperMBC5ROM(u16 address, u8 value) { @@ -580,10 +581,11 @@ void mapperMBC5ROM(u16 address, u8 value) gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000]; } break; - case 0x4000: // RAM bank select - if(gbDataMBC5.isRumbleCartridge) + case 0x4000: // RAM bank select, plus rumble + if(gbDataMBC5.isRumbleCartridge) { + systemCartridgeRumble(value & 0x08); value &= 0x07; - else + } else value &= 0x0f; if(value == gbDataMBC5.mapperRAMBank) break; diff --git a/source/vba/gba/GBA.cpp b/source/vba/gba/GBA.cpp index b20b630..002acd6 100644 --- a/source/vba/gba/GBA.cpp +++ b/source/vba/gba/GBA.cpp @@ -3052,6 +3052,7 @@ void CPUInit(const char *biosFileName, bool useBiosFile) void CPUReset() { + systemCartridgeRumble(false); if(gbaSaveType == 0) { if(eepromInUse) gbaSaveType = 3; diff --git a/source/vba/gba/RTC.cpp b/source/vba/gba/RTC.cpp index 5335ad2..3d00003 100644 --- a/source/vba/gba/RTC.cpp +++ b/source/vba/gba/RTC.cpp @@ -32,8 +32,7 @@ typedef struct { static RTCCLOCKDATA rtcClockData; static bool rtcEnabled = false; - -int WarioRumbleMotor = 0; +static bool rtcWarioRumbleEnabled = false; void rtcEnable(bool e) { @@ -45,6 +44,12 @@ bool rtcIsEnabled() return rtcEnabled; } +void rtcEnableWarioRumble(bool e) +{ + if (e) rtcEnable(true); + rtcWarioRumbleEnabled = e; +} + u16 rtcRead(u32 address) { if(rtcEnabled) { @@ -103,14 +108,13 @@ bool rtcWrite(u32 address, u16 value) rtcClockData.byte2 = (u8)value; // bit 0 = enable reading from 0x80000c4 c6 and c8 } else if(address == 0x80000c6) { rtcClockData.byte1 = (u8)value; // 0=read/1=write (for each of 4 low bits) - if (!(value & 8)) WarioRumbleMotor = 0; + // rumble is off when not writing to that pin + if (rtcWarioRumbleEnabled && !(value & 8)) systemCartridgeRumble(false); } else if(address == 0x80000c4) { // 4 bits of I/O Port Data (upper bits not used) // WarioWare Twisted rumble - if(rtcClockData.byte1 & 8) { - WarioRumbleMotor = value & 8; - } else { - WarioRumbleMotor = 0; // rumble is off when not writing to that pin + if(rtcWarioRumbleEnabled && (rtcClockData.byte1 & 8)) { + systemCartridgeRumble(value & 8); } // Boktai solar sensor diff --git a/source/vba/gba/RTC.h b/source/vba/gba/RTC.h index ea43b83..dfcec65 100644 --- a/source/vba/gba/RTC.h +++ b/source/vba/gba/RTC.h @@ -4,6 +4,7 @@ u16 rtcRead(u32 address); bool rtcWrite(u32 address, u16 value); void rtcEnable(bool); +void rtcEnableWarioRumble(bool); bool rtcIsEnabled(); void rtcReset();