From 4ff865198d354f9484b47beba564a061af038808 Mon Sep 17 00:00:00 2001 From: John Peterson Date: Fri, 28 Nov 2008 19:02:42 +0000 Subject: [PATCH] Added analog sticks to emulated Classic Controller, the left analog stick is JKLI, the right stick is FGHT, the home button is U, the + and - buttons are O and N git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1322 8ced0084-cf51-0410-be5f-012b33b47a6e --- .../Plugin_Wiimote/Src/DataReports.cpp | 8 +- Source/Plugins/Plugin_Wiimote/Src/EmuMain.cpp | 10 +- .../Plugin_Wiimote/Src/EmuSubroutines.cpp | 5 +- .../Plugin_Wiimote/Src/EmuSubroutines.h | 5 +- .../Plugins/Plugin_Wiimote/Src/FillReport.cpp | 97 ++++++++++++------- Source/Plugins/Plugin_Wiimote/Src/main.cpp | 4 +- 6 files changed, 81 insertions(+), 48 deletions(-) diff --git a/Source/Plugins/Plugin_Wiimote/Src/DataReports.cpp b/Source/Plugins/Plugin_Wiimote/Src/DataReports.cpp index c57f8592d9..3c482983ce 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/DataReports.cpp +++ b/Source/Plugins/Plugin_Wiimote/Src/DataReports.cpp @@ -223,11 +223,11 @@ void SendReportCoreAccelExt16(u16 _channelID) // Debugging #ifdef _WIN32 - /**/if(GetAsyncKeyState('V')) + /*if(GetAsyncKeyState('V')) { std::string Temp = WiiMoteEmu::ArrayToString(DataFrame, Offset, 0, 30); wprintf("DataFrame: %s\n", Temp.c_str()); - } + }*/ #endif g_WiimoteInitialize.pWiimoteInput(_channelID, DataFrame, Offset); } @@ -268,11 +268,11 @@ void SendReportCoreAccelIr10Ext(u16 _channelID) // Debugging #ifdef _WIN32 - /**/if(GetAsyncKeyState('V')) + /*if(GetAsyncKeyState('V')) { std::string Temp = WiiMoteEmu::ArrayToString(DataFrame, Offset, 0, 30); wprintf("DataFrame: %s\n", Temp.c_str()); - } + }*/ #endif g_WiimoteInitialize.pWiimoteInput(_channelID, DataFrame, Offset); } diff --git a/Source/Plugins/Plugin_Wiimote/Src/EmuMain.cpp b/Source/Plugins/Plugin_Wiimote/Src/EmuMain.cpp index 46042d8089..43b11059f3 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/EmuMain.cpp +++ b/Source/Plugins/Plugin_Wiimote/Src/EmuMain.cpp @@ -239,10 +239,10 @@ void WmReadData(u16 _channelID, wm_read_data* rd) wprintf("\n\nWmReadData Address: %08x Offset: %08x Size: %i byte\n", address, address & 0xffff, (u8)size); - // Debugging - // u32 offset = address & 0xffff; - //std::string Temp = WiiMoteEmu::ArrayToString(g_RegExt, size, offset); - //wprintf("Unencrypted data:\n%s\n", Temp.c_str()); + /* Debugging + u32 offset = address & 0xffff; + std::string Temp = WiiMoteEmu::ArrayToString(g_RegExt, size, offset); + wprintf("Unencrypted data:\n%s\n", Temp.c_str());*/ // Check if encrypted reads is on if(g_RegExt[0xf0] == 0xaa) @@ -369,7 +369,7 @@ void WmWriteData(u16 _channelID, wm_write_data* wd) // ------------- if(blockSize == WIIMOTE_REG_EXT_SIZE) { - /* Debugging. Write the data. + /* Debugging. Write the data. wprintf("Data: %s\n", Temp.c_str()); wprintf("Current address: %08x\n", address); */ diff --git a/Source/Plugins/Plugin_Wiimote/Src/EmuSubroutines.cpp b/Source/Plugins/Plugin_Wiimote/Src/EmuSubroutines.cpp index e60780dd7f..5587532f52 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/EmuSubroutines.cpp +++ b/Source/Plugins/Plugin_Wiimote/Src/EmuSubroutines.cpp @@ -133,14 +133,15 @@ void Initialize() //WriteCrypted16(g_RegExt, 0xfe, 0x0000); // Fully inserted Nunchuk - // Copy extension id and calibration to its register - memcpy(g_RegExt + 0x20, nunchuck_calibration, sizeof(nunchuck_calibration)); + // Copy extension id and calibration to its register if(g_Config.bNunchuckConnected) { + memcpy(g_RegExt + 0x20, nunchuck_calibration, sizeof(nunchuck_calibration)); memcpy(g_RegExt + 0xfa, nunchuck_id, sizeof(nunchuck_id)); } else if(g_Config.bClassicControllerConnected) { + memcpy(g_RegExt + 0x20, classic_calibration, sizeof(classic_calibration)); memcpy(g_RegExt + 0xfa, classic_id, sizeof(classic_id)); } diff --git a/Source/Plugins/Plugin_Wiimote/Src/EmuSubroutines.h b/Source/Plugins/Plugin_Wiimote/Src/EmuSubroutines.h index e792def5e2..f86bfef07c 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/EmuSubroutines.h +++ b/Source/Plugins/Plugin_Wiimote/Src/EmuSubroutines.h @@ -83,7 +83,9 @@ static const u8 nunchuck_calibration[] = 0xe0,0x20,0x80,0xe0, 0x20,0x80,0xee,0x43 }; -/* Classic Controller calibration */ +/* Classic Controller calibration. 0x80 is the neutral for the analog triggers and + sticks. The left analog range is 0x1c - 0xe4 and the right is 0x28 - 0xd8. + We use this range because it's closest to the GC controller range. */ static const u8 classic_calibration[] = { 0xe4,0x1c,0x80,0xe4, 0x1c,0x80,0xd8,0x28, @@ -94,7 +96,6 @@ static const u8 classic_calibration[] = - /* The Nunchuck id. It should be written to the last bytes of the extension register */ static const u8 nunchuck_id[] = diff --git a/Source/Plugins/Plugin_Wiimote/Src/FillReport.cpp b/Source/Plugins/Plugin_Wiimote/Src/FillReport.cpp index 9abcb7f435..645aee9682 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/FillReport.cpp +++ b/Source/Plugins/Plugin_Wiimote/Src/FillReport.cpp @@ -488,20 +488,21 @@ void FillReportExtension(wm_extension& _ext) #ifdef _WIN32 - if(GetAsyncKeyState(VK_NUMPAD4)) + /* We use a 192 range (32 to 224) that match our calibration values in + nunchuck_calibration */ + if(GetAsyncKeyState(VK_NUMPAD4)) // left _ext.jx = 0x20; if(GetAsyncKeyState(VK_NUMPAD8)) _ext.jy = 0xe0; - if(GetAsyncKeyState(VK_NUMPAD6)) + if(GetAsyncKeyState(VK_NUMPAD6)) // right _ext.jx = 0xe0; if(GetAsyncKeyState(VK_NUMPAD5)) _ext.jy = 0x20; - if(GetAsyncKeyState('C')) _ext.bt = 0x01; @@ -519,26 +520,13 @@ void FillReportExtension(wm_extension& _ext) /* Write the nunchuck inputs to it. We begin writing at 0x08, but it could also be 0x00, the important thing is that we begin at an address evenly divisible - by 0x08 - g_RegExtTmp[0x08] = _ext.jx; - g_RegExtTmp[0x09] = _ext.jy; - g_RegExtTmp[0x0a] = _ext.ax; - g_RegExtTmp[0x0b] = _ext.ay; - g_RegExtTmp[0x0c] = _ext.az; - g_RegExtTmp[0x0d] = _ext.bt; */ + by 0x08 */ memcpy(g_RegExtTmp + 0x08, &_ext, sizeof(_ext)); // Encrypt it wiimote_encrypt(&g_ExtKey, &g_RegExtTmp[0x08], 0x08, sizeof(_ext)); // Write it back - /* - _ext.jx = g_RegExtTmp[0x08]; - _ext.jy = g_RegExtTmp[0x09]; - _ext.ax = g_RegExtTmp[0x0a]; - _ext.ay = g_RegExtTmp[0x0b]; - _ext.az = g_RegExtTmp[0x0c]; - _ext.bt = g_RegExtTmp[0x0d];*/ memcpy(&_ext, &g_RegExtTmp[0x08], sizeof(_ext)); } @@ -550,13 +538,10 @@ void FillReportExtension(wm_extension& _ext) void FillReportClassicExtension(wm_classic_extension& _ext) { - /* These are the default neutral values for the nunchuck accelerometer according - to a source. - _ext.ax = 0x80; - _ext.ay = 0x80; - _ext.az = 0xb3; */ + /* These are the default neutral values for the analog triggers and sticks */ + u8 Rx = 0x80, Ry = 0x80, Lx = 0x80, Ly = 0x80, lT = 0x80, rT = 0x80; - _ext.b1.padding = 0x01; // these are the default values unless we use them + _ext.b1.padding = 0x01; // 0x01 means not pressed _ext.b1.bRT = 0x01; _ext.b1.bP = 0x01; _ext.b1.bH = 0x01; @@ -574,15 +559,53 @@ void FillReportClassicExtension(wm_classic_extension& _ext) _ext.b2.bB = 0x01; _ext.b2.bZL = 0x01; - //_ext.bt = 0x03; // 0x03 means no button pressed, the button is zero active + // -------------------------------------- + /* Left and right analog sticks - /* - _ir0.y2 = y2 & 0xff; - _ir0.x2Hi = (x2 >> 8); - _ir0.y2Hi = (y2 >> 8); + u8 Lx : 6; // byte 0 + u8 Rx : 2; + u8 Ly : 6; // byte 1 + u8 Rx2 : 2; + u8 Ry : 5; // byte 2 + u8 lT : 2; + u8 Rx3 : 1; + u8 rT : 5; // byte 3 + u8 lT2 : 3; + */ +#ifdef _WIN32 + /* We use a 200 range (28 to 228) for the left analog stick and a 176 range + (40 to 216) for the right analog stick to match our calibration values + in classic_calibration */ + if(GetAsyncKeyState('J')) // left analog left + Lx = 0x1c; + if(GetAsyncKeyState('I')) // up + Ly = 0xe4; + if(GetAsyncKeyState('L')) // right + Lx = 0xe4; + if(GetAsyncKeyState('K')) // down + Ly = 0x1c; + + if(GetAsyncKeyState('F')) // right analog left + Rx = 0x28; + if(GetAsyncKeyState('T')) // up + Ry = 0xd8; + if(GetAsyncKeyState('H')) // right + Rx = 0xd8; + if(GetAsyncKeyState('G')) // down + Ry = 0x28; + + _ext.Lx = (Lx >> 2); + _ext.Ly = (Ly >> 2); + _ext.Rx = (Rx >> 3); // this may be wrong + _ext.Rx2 = (Rx >> 5); + _ext.Rx3 = (Rx >> 7); + _ext.Ry = (Ry >> 2); + + _ext.lT = (Ry >> 2); + _ext.lT2 = (Ry >> 3); + _ext.rT = (Ry >> 4); + // -------------- - // I don't understand't the & 0x03, should we do that? - //_ir1.x1Hi = (x1 >> 8) & 0x3;*/ @@ -598,7 +621,6 @@ void FillReportClassicExtension(wm_classic_extension& _ext) 0: bdU 1: bdL */ -#ifdef _WIN32 if(GetAsyncKeyState(VK_NUMPAD4)) // left _ext.b2.bdL = 0x00; @@ -642,6 +664,15 @@ void FillReportClassicExtension(wm_classic_extension& _ext) if(GetAsyncKeyState('X')) _ext.b2.bX = 0x00; + if(GetAsyncKeyState('O')) // O instead of P + _ext.b1.bP = 0x00; + + if(GetAsyncKeyState('N')) // N instead of M + _ext.b1.bM = 0x00; + + if(GetAsyncKeyState('U')) // Home button + _ext.b1.bH = 0x00; + if(GetAsyncKeyState('7')) // digital left trigger _ext.b1.bLT = 0x00; @@ -655,8 +686,8 @@ void FillReportClassicExtension(wm_classic_extension& _ext) _ext.b1.bRT = 0x00; // All buttons pressed - if(GetAsyncKeyState('C') && GetAsyncKeyState('Z')) - { _ext.b2.bA = 0x01; _ext.b2.bB = 0x01; } + //if(GetAsyncKeyState('C') && GetAsyncKeyState('Z')) + // { _ext.b2.bA = 0x01; _ext.b2.bB = 0x01; } // -------------- #else // TODO linux port diff --git a/Source/Plugins/Plugin_Wiimote/Src/main.cpp b/Source/Plugins/Plugin_Wiimote/Src/main.cpp index 0ecb9f6396..ac0b5433ef 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/main.cpp +++ b/Source/Plugins/Plugin_Wiimote/Src/main.cpp @@ -130,10 +130,10 @@ extern "C" void Wiimote_Initialize(SWiimoteInitialize _WiimoteInitialize) for it in that case */ g_UseRealWiiMote = WiiMoteReal::Initialize() > 0; - WiiMoteEmu::Initialize(); - g_Config.Load(); // load config settings + WiiMoteEmu::Initialize(); + // Debugging window /*startConsoleWin(100, 750, "Wiimote"); // give room for 20 rows wprintf("Wiimote console opened\n");