From 1f0f0f4295f968c53155131946aea83c046a481c Mon Sep 17 00:00:00 2001 From: John Peterson Date: Tue, 24 Feb 2009 18:37:53 +0000 Subject: [PATCH] Emulated Wiimote: Fixed the Classic Controller left and right analog triggers, and the right stick git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2417 8ced0084-cf51-0410-be5f-012b33b47a6e --- .../Plugin_Wiimote/Src/EmuDynamics.cpp | 16 ++++ Source/Plugins/Plugin_Wiimote/Src/EmuMain.h | 3 + .../Plugins/Plugin_Wiimote/Src/FillReport.cpp | 32 ++++---- Source/Plugins/Plugin_Wiimote/Src/main.cpp | 77 +++++++++++++------ .../Plugins/Plugin_Wiimote/Src/wiimote_hid.h | 8 +- 5 files changed, 93 insertions(+), 43 deletions(-) diff --git a/Source/Plugins/Plugin_Wiimote/Src/EmuDynamics.cpp b/Source/Plugins/Plugin_Wiimote/Src/EmuDynamics.cpp index 251f0b0ce6..7de00ab0f5 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/EmuDynamics.cpp +++ b/Source/Plugins/Plugin_Wiimote/Src/EmuDynamics.cpp @@ -364,4 +364,20 @@ void IRData2Distance() //////////////////////////////// +//****************************************************************************** +// Classic Controller functions +//****************************************************************************** + +std::string CCData2Values(u8 *Data) +{ + return StringFromFormat( + "Tl:%03i Tr:%03i Lx:%03i Ly:%03i Rx:%03i Ry:%03i", + (((Data[2] & 0x60) >> 2) | ((Data[3] & 0xe0) >> 5)), + (Data[3] & 0x1f), + (Data[0] & 0x3f), + (Data[1] & 0x3f), + ((Data[0] & 0xc0) >> 3) | ((Data[1] & 0xc0) >> 5) | ((Data[2] & 0x80) >> 7), + (Data[2] & 0x1f)); +} + } // WiiMoteEmu \ No newline at end of file diff --git a/Source/Plugins/Plugin_Wiimote/Src/EmuMain.h b/Source/Plugins/Plugin_Wiimote/Src/EmuMain.h index 25195f52c3..ca5fea28c0 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/EmuMain.h +++ b/Source/Plugins/Plugin_Wiimote/Src/EmuMain.h @@ -68,6 +68,9 @@ void IRData2DotsBasic(u8 *Data); void ReorderIRDots(); void IRData2Distance(); +// Classic Controller data +std::string CCData2Values(u8 *Data); + }; // WiiMoteEmu diff --git a/Source/Plugins/Plugin_Wiimote/Src/FillReport.cpp b/Source/Plugins/Plugin_Wiimote/Src/FillReport.cpp index fae5b70791..4663527b6d 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/FillReport.cpp +++ b/Source/Plugins/Plugin_Wiimote/Src/FillReport.cpp @@ -929,9 +929,6 @@ void FillReportIRBasic(wm_ir_basic& _ir0, wm_ir_basic& _ir1) _ir0.x2 = x2 & 0xff; _ir0.x2Hi = (x2 >> 8); _ir0.y2 = y2 & 0xff; _ir0.y2Hi = (y2 >> 8); - // I don't understand't the & 0x03, should we do that? - //_ir1.x1Hi = (x1 >> 8) & 0x3; - //_ir1.y1Hi = (y1 >> 8) & 0x3; // ------------------------------------ // Debugging for calibration @@ -1259,14 +1256,9 @@ void FillReportClassicExtension(wm_classic_extension& _ext) if (_Tl == 0xff) _ext.b1.bLT = 0x00; if (_Tr == 0xff) _ext.b1.bRT = 0x00; - // The reported data is supposed to be divided by 8 so that we return 0x1f at most, I think. But - // I'm not sure about the bit shifts further down. - lT = _Tl / 8; - rT = _Tr / 8; - - // Boundaries - if (lT > 0x1f) lT = 0x1f; - if (rT > 0x1f) rT = 0x1f; + // These can be copied directly, the bitshift further down fix this value to + lT = _Tl; + rT = _Tr; } @@ -1344,15 +1336,21 @@ void FillReportClassicExtension(wm_classic_extension& _ext) // -------------------------------------- // Convert data for reporting + // -------------- _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); + // 5 bit to 1 bit + _ext.Rx = (Rx >> 3) & 0x01; + // 5 bit to the next 2 bit + _ext.Rx2 = ((Rx >> 3) >> 1) & 0x03; + // 5 bit to the next 2 bit + _ext.Rx3 = ((Rx >> 3) >> 3) & 0x03; + _ext.Ry = (Ry >> 3); - _ext.lT = (lT >> 6); // This may be wrong - _ext.lT2 = (lT >> 5); + // 5 bit to 3 bit + _ext.lT = (lT >> 3) & 0x07; + // 5 bit to the highest two bits + _ext.lT2 = (lT >> 3) >> 3; _ext.rT = (rT >> 3); // -------------- diff --git a/Source/Plugins/Plugin_Wiimote/Src/main.cpp b/Source/Plugins/Plugin_Wiimote/Src/main.cpp index 2cd3ad4edf..4cc9779a7a 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/main.cpp +++ b/Source/Plugins/Plugin_Wiimote/Src/main.cpp @@ -617,21 +617,42 @@ void ReadDebugging(bool Emu, const void* _pData, int Size) if(WiiMoteEmu::g_Encryption) wiimote_decrypt(&WiiMoteEmu::g_ExtKey, &data[0x07], 0x00, (data[4] >> 0x04) + 1); - Console::Print("\nGame got the Nunchuck calibration:\n"); - Console::Print("Cal_zero.x: %i\n", data[7 + 0]); - Console::Print("Cal_zero.y: %i\n", data[7 + 1]); - Console::Print("Cal_zero.z: %i\n", data[7 + 2]); - Console::Print("Cal_g.x: %i\n", data[7 + 4]); - Console::Print("Cal_g.y: %i\n", data[7 + 5]); - Console::Print("Cal_g.z: %i\n", data[7 + 6]); - Console::Print("Js.Max.x: %i\n", data[7 + 8]); - Console::Print("Js.Min.x: %i\n", data[7 + 9]); - Console::Print("Js.Center.x: %i\n", data[7 + 10]); - Console::Print("Js.Max.y: %i\n", data[7 + 11]); - Console::Print("Js.Min.y: %i\n", data[7 + 12]); - Console::Print("JS.Center.y: %i\n\n", data[7 + 13]); + if (g_Config.bNunchuckConnected) + { + Console::Print("\nGame got the Nunchuck calibration:\n"); + Console::Print("Cal_zero.x: %i\n", data[7 + 0]); + Console::Print("Cal_zero.y: %i\n", data[7 + 1]); + Console::Print("Cal_zero.z: %i\n", data[7 + 2]); + Console::Print("Cal_g.x: %i\n", data[7 + 4]); + Console::Print("Cal_g.y: %i\n", data[7 + 5]); + Console::Print("Cal_g.z: %i\n", data[7 + 6]); + Console::Print("Js.Max.x: %i\n", data[7 + 8]); + Console::Print("Js.Min.x: %i\n", data[7 + 9]); + Console::Print("Js.Center.x: %i\n", data[7 + 10]); + Console::Print("Js.Max.y: %i\n", data[7 + 11]); + Console::Print("Js.Min.y: %i\n", data[7 + 12]); + Console::Print("JS.Center.y: %i\n\n", data[7 + 13]); + } + else // g_Config.bClassicControllerConnected + { + Console::Print("\nGame got the Classic Controller calibration:\n"); + Console::Print("Lx.Max: %i\n", data[7 + 0]); + Console::Print("Lx.Min: %i\n", data[7 + 1]); + Console::Print("Lx.Center: %i\n", data[7 + 2]); + Console::Print("Ly.Max: %i\n", data[7 + 3]); + Console::Print("Ly.Min: %i\n", data[7 + 4]); + Console::Print("Ly.Center: %i\n", data[7 + 5]); + Console::Print("Rx.Max.x: %i\n", data[7 + 6]); + Console::Print("Rx.Min.x: %i\n", data[7 + 7]); + Console::Print("Rx.Center.x: %i\n", data[7 + 8]); + Console::Print("Ry.Max.y: %i\n", data[7 + 9]); + Console::Print("Ry.Min: %i\n", data[7 + 10]); + Console::Print("Ry.Center: %i\n\n", data[7 + 11]); + Console::Print("Lt.Neutral: %i\n", data[7 + 12]); + Console::Print("Rt.Neutral %i\n\n", data[7 + 13]); + } - // Save the values + // Save the values if they come from the real Wiimote if (!Emu) { // Save the values from the Nunchuck @@ -716,11 +737,13 @@ void ReadDebugging(bool Emu, const void* _pData, int Size) // Decrypt extension data if(WiiMoteEmu::g_ReportingMode == 0x37) wiimote_decrypt(&WiiMoteEmu::g_ExtKey, &data[17], 0x00, 0x06); + if(WiiMoteEmu::g_ReportingMode == 0x35) + wiimote_decrypt(&WiiMoteEmu::g_ExtKey, &data[7], 0x00, 0x06); // Produce string //std::string TmpData = ArrayToString(data, size + 2, 0, 30); //LOGV(WII_IPC_WIIMOTE, 3, " Data: %s", Temp.c_str()); - std::string TmpCore = "", TmpAccel = "", TmpIR = "", TmpExt = ""; + std::string TmpCore = "", TmpAccel = "", TmpIR = "", TmpExt = "", CCData = ""; TmpCore = StringFromFormat( "%02x %02x %02x %02x", data[0], data[1], data[2], data[3]); // Header and core buttons @@ -744,6 +767,8 @@ void ReadDebugging(bool Emu, const void* _pData, int Size) data[7], data[8], // Nunchuck stick data[9], data[10], data[11], // Nunchuck Accelerometer data[12]); // Nunchuck buttons + + CCData = WiiMoteEmu::CCData2Values(&data[7]); } if (data[1] == 0x37) // WM_REPORT_CORE_ACCEL_IR10_EXT6 { @@ -757,6 +782,7 @@ void ReadDebugging(bool Emu, const void* _pData, int Size) data[17], data[18], // Nunchuck stick data[19], data[20], data[21], // Nunchuck Accelerometer data[22]); // Nunchuck buttons + CCData = WiiMoteEmu::CCData2Values(&data[17]); } @@ -813,11 +839,18 @@ void ReadDebugging(bool Emu, const void* _pData, int Size) IRData += StringFromFormat(" | Distance:%i", WiiMoteEmu::g_Wm.IR.Distance); // ------------------------- - //Console::Print("Read[%s]: 0x%02x | %s | %s | %s\n", (Emu ? "Emu" : "Real"), data[1], RollPitch.c_str(), GForce.c_str(), IRData.c_str()); // Formatted data only - //Console::Print("Read[%s]: %s | %s\n", (Emu ? "Emu" : "Real"), TmpData.c_str(), IRData.c_str()); // IR data - Console::Print("Read[%s]: %s | %s | %s | %s | %s | %s\n", (Emu ? "Emu" : "Real"), - TmpCore.c_str(), TmpAccel.c_str(), TmpIR.c_str(), TmpExt.c_str(), RollPitch.c_str(), GForce.c_str()); // Accelerometer - //Console::Print(" (%s): %s\n", Tm(true).c_str(), Temp.c_str()); // Timestamp + // Classic Controller data + Console::Print("Read[%s]: %s | %s | %s | %s | %s\n", (Emu ? "Emu" : "Real"), + TmpCore.c_str(), TmpAccel.c_str(), TmpIR.c_str(), TmpExt.c_str(), CCData.c_str()); + // Formatted data only + //Console::Print("Read[%s]: 0x%02x | %s | %s | %s\n", (Emu ? "Emu" : "Real"), data[1], RollPitch.c_str(), GForce.c_str(), IRData.c_str()); + // IR data + //Console::Print("Read[%s]: %s | %s\n", (Emu ? "Emu" : "Real"), TmpData.c_str(), IRData.c_str()); + // Accelerometer data + //Console::Print("Read[%s]: %s | %s | %s | %s | %s | %s | %s\n", (Emu ? "Emu" : "Real"), + // TmpCore.c_str(), TmpAccel.c_str(), TmpIR.c_str(), TmpExt.c_str(), RollPitch.c_str(), GForce.c_str(), CCData.c_str()); + // Timestamp + //Console::Print(" (%s): %s\n", Tm(true).c_str(), Temp.c_str()); } if(g_DebugAccelerometer) @@ -1058,8 +1091,8 @@ void DoInitialize() to check if there is a real wiimote connected. We will initiate wiiuse.dll, but we will return before creating a new thread for it if we find no real Wiimotes. Then g_RealWiiMotePresent will also be false. This function call will be done - instantly if there is no real Wiimote connected. I'm not sure how long time - it takes if a Wiimote is connected. */ + instantly whether there is a real Wiimote connected or not. It takes no time for + Wiiuse to check for connected Wiimotes. */ #if HAVE_WIIUSE if (g_Config.bConnectRealWiimote) WiiMoteReal::Initialize(); #endif diff --git a/Source/Plugins/Plugin_Wiimote/Src/wiimote_hid.h b/Source/Plugins/Plugin_Wiimote/Src/wiimote_hid.h index 882ea8137f..1a98dff196 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/wiimote_hid.h +++ b/Source/Plugins/Plugin_Wiimote/Src/wiimote_hid.h @@ -214,14 +214,14 @@ struct wm_cc_5 struct wm_classic_extension { u8 Lx : 6; // byte 0 - u8 Rx : 2; + u8 Rx3 : 2; u8 Ly : 6; // byte 1 u8 Rx2 : 2; u8 Ry : 5; // byte 2 - u8 lT : 2; - u8 Rx3 : 1; + u8 lT2 : 2; + u8 Rx : 1; u8 rT : 5; // byte 3 - u8 lT2 : 3; + u8 lT : 3; wm_cc_4 b1; // byte 4 wm_cc_5 b2; // byte 5 };