diff --git a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device.h b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device.h index e94552d084..bb0c12579f 100644 --- a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device.h +++ b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device.h @@ -64,17 +64,24 @@ protected: for (u32 i=0; i CWII_IPC_HLE_Device_usb_oh1_57e_305::CWII_IPC_HLE_Device_usb_oh1_57e_305(u32 _DeviceID, const std::string& _rDeviceName) @@ -24,6 +25,7 @@ CWII_IPC_HLE_Device_usb_oh1_57e_305::CWII_IPC_HLE_Device_usb_oh1_57e_305(u32 _De , m_pACLBuffer(NULL) , m_pHCIBuffer(NULL) , m_State(STATE_NONE) +, m_UpdateWaitCount(0) , scan_enable(0) , m_DelayedEvent(EVENT_NONE) { @@ -190,8 +192,6 @@ bool CWII_IPC_HLE_Device_usb_oh1_57e_305::IOCtlV(u32 _CommandAddress) return true; } -extern void SendFrame(CWII_IPC_HLE_Device_usb_oh1_57e_305* _pDevice, u16 _ConnectionHandle, u8* _pData, u32 _Size); - void CWII_IPC_HLE_Device_usb_oh1_57e_305::SendToDevice(u16 _ConnectionHandle, u8* _pData, u32 _Size) { CWII_IPC_HLE_WiiMote* pWiiMote = AccessWiiMote(_ConnectionHandle); @@ -234,6 +234,15 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::SendACLFrame(u16 _ConnectionHandle, u8 u32 CWII_IPC_HLE_Device_usb_oh1_57e_305::Update() { +#if 0 + if(m_UpdateWaitCount < 5) { + m_UpdateWaitCount++; + return 0; + } else { + m_UpdateWaitCount = 0; + } +#endif + //LOG(WIIMOTE, "Update() %i 0x%08x", //m_HCICommandMessageQueue.size(), m_pHCIBuffer); // check state machine @@ -366,6 +375,8 @@ u32 CWII_IPC_HLE_Device_usb_oh1_57e_305::Update() return Addr; } + PluginWiimote::Wiimote_Update(); + return 0; } diff --git a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_usb.h b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_usb.h index eaabfa3be9..e73a95c700 100644 --- a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_usb.h +++ b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_usb.h @@ -162,6 +162,7 @@ private: }; EState m_State; + u32 m_UpdateWaitCount; bdaddr_t m_StateTempBD; u16 m_StateTempConnectionHandle; diff --git a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_WiiMote.cpp b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_WiiMote.cpp index 7d4db2a573..14224c27eb 100644 --- a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_WiiMote.cpp +++ b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_WiiMote.cpp @@ -177,10 +177,13 @@ void CWII_IPC_HLE_WiiMote::SendACLFrame(u8* _pData, u32 _Size) u8* pData = _pData + sizeof(SL2CAP_Header); u32 DataSize = _Size - sizeof(SL2CAP_Header); - LOG(WIIMOTE, "L2Cap-SendFrame: Len 0x%x, Channel 0x%04x", - pHeader->Length, pHeader->CID); + LOG(WIIMOTE, "L2Cap-SendFrame: Channel 0x%04x, Len 0x%x, DataSize 0x%x", + pHeader->CID, pHeader->Length, DataSize); - _dbg_assert_(WIIMOTE, pHeader->Length == DataSize); + if(pHeader->Length != DataSize) { + LOG(WIIMOTE, "Faulty packet. It is dropped."); + return; + } switch (pHeader->CID) { diff --git a/Source/Core/Core/Src/Plugins/Plugin_Wiimote.cpp b/Source/Core/Core/Src/Plugins/Plugin_Wiimote.cpp index 5300ab8a3b..c24da0fe5c 100644 --- a/Source/Core/Core/Src/Plugins/Plugin_Wiimote.cpp +++ b/Source/Core/Core/Src/Plugins/Plugin_Wiimote.cpp @@ -29,6 +29,7 @@ namespace PluginWiimote TWiimote_Initialize Wiimote_Initialize = 0; TWiimote_Shutdown Wiimote_Shutdown = 0; TWiimote_Output Wiimote_Output = 0; + TWiimote_Update Wiimote_Update = 0; TWiimote_GetAttachedControllers Wiimote_GetAttachedControllers = 0; TWiimote_DoState Wiimote_DoState = 0; @@ -51,6 +52,7 @@ namespace PluginWiimote Wiimote_Initialize = 0; Wiimote_Shutdown = 0; Wiimote_Output = 0; + Wiimote_Update = 0; Wiimote_GetAttachedControllers = 0; Wiimote_DoState = 0; } @@ -66,6 +68,7 @@ namespace PluginWiimote Wiimote_Initialize = reinterpret_cast (plugin.Get("Wiimote_Initialize")); Wiimote_Shutdown = reinterpret_cast (plugin.Get("Wiimote_Shutdown")); Wiimote_Output = reinterpret_cast (plugin.Get("Wiimote_Output")); + Wiimote_Update = reinterpret_cast (plugin.Get("Wiimote_Update")); Wiimote_GetAttachedControllers = reinterpret_cast (plugin.Get("Wiimote_GetAttachedControllers")); Wiimote_DoState = reinterpret_cast (plugin.Get("Wiimote_DoState")); @@ -75,12 +78,14 @@ namespace PluginWiimote LOG(MASTER_LOG, "%s: 0x%p", "Wiimote_Initialize", Wiimote_Initialize); LOG(MASTER_LOG, "%s: 0x%p", "Wiimote_Shutdown", Wiimote_Shutdown); LOG(MASTER_LOG, "%s: 0x%p", "Wiimote_Output", Wiimote_Output); + LOG(MASTER_LOG, "%s: 0x%p", "Wiimote_Update", Wiimote_Update); LOG(MASTER_LOG, "%s: 0x%p", "Wiimote_GetAttachedControllers", Wiimote_GetAttachedControllers); LOG(MASTER_LOG, "%s: 0x%p", "Wiimote_DoState", Wiimote_DoState); if ((GetDllInfo != 0) && (Wiimote_Initialize != 0) && (Wiimote_Shutdown != 0) && (Wiimote_Output != 0) && + (Wiimote_Update != 0) && (Wiimote_GetAttachedControllers != 0) && (Wiimote_DoState != 0)) { diff --git a/Source/Core/Core/Src/Plugins/Plugin_Wiimote.h b/Source/Core/Core/Src/Plugins/Plugin_Wiimote.h index d076580da2..fe0abea0ea 100644 --- a/Source/Core/Core/Src/Plugins/Plugin_Wiimote.h +++ b/Source/Core/Core/Src/Plugins/Plugin_Wiimote.h @@ -32,6 +32,7 @@ typedef void (__cdecl* TDllAbout)(HWND); typedef void (__cdecl* TDllConfig)(HWND); typedef void (__cdecl* TWiimote_Initialize)(SWiimoteInitialize); typedef void (__cdecl* TWiimote_Shutdown)(); +typedef void (__cdecl* TWiimote_Update)(); typedef void (__cdecl* TWiimote_Output)(const void* _pData, u32 _Size); typedef unsigned int (__cdecl* TWiimote_GetAttachedControllers)(); typedef void (__cdecl* TWiimote_DoState)(void *ptr, int mode); @@ -43,6 +44,7 @@ extern TDllConfig DllConfig; extern TWiimote_Initialize Wiimote_Initialize; extern TWiimote_Shutdown Wiimote_Shutdown; extern TWiimote_Output Wiimote_Output; +extern TWiimote_Update Wiimote_Update; extern TWiimote_GetAttachedControllers Wiimote_GetAttachedControllers; extern TWiimote_DoState Wiimote_DoState; diff --git a/Source/PluginSpecs/pluginspecs_wiimote.h b/Source/PluginSpecs/pluginspecs_wiimote.h index 420656c103..70ff95a63a 100644 --- a/Source/PluginSpecs/pluginspecs_wiimote.h +++ b/Source/PluginSpecs/pluginspecs_wiimote.h @@ -82,6 +82,14 @@ EXPORT void CALL Wiimote_Shutdown(); // EXPORT void CALL Wiimote_Output(const void* _pData, u32 _Size); +// __________________________________________________________________________________________________ +// Function: Wiimote_Update +// Purpose: This function is called periodically by the Core. +// input: none +// output: none +// +EXPORT void CALL Wiimote_Update(); + // __________________________________________________________________________________________________ // Function: PAD_GetAttachedPads // Purpose: Get mask of attached pads (eg: controller 1 & 4 -> 0x9) diff --git a/Source/Plugins/Plugin_Wiimote_Test/Plugin_Wiimote_Test.vcproj b/Source/Plugins/Plugin_Wiimote_Test/Plugin_Wiimote_Test.vcproj index 26b7d957f4..f05e611ca5 100644 --- a/Source/Plugins/Plugin_Wiimote_Test/Plugin_Wiimote_Test.vcproj +++ b/Source/Plugins/Plugin_Wiimote_Test/Plugin_Wiimote_Test.vcproj @@ -512,6 +512,10 @@ + + diff --git a/Source/Plugins/Plugin_Wiimote_Test/Src/Wiimote_Test.cpp b/Source/Plugins/Plugin_Wiimote_Test/Src/Wiimote_Test.cpp index b2b58f6140..2962102067 100644 --- a/Source/Plugins/Plugin_Wiimote_Test/Src/Wiimote_Test.cpp +++ b/Source/Plugins/Plugin_Wiimote_Test/Src/Wiimote_Test.cpp @@ -26,6 +26,8 @@ u8 g_RegSpeaker[WIIMOTE_REG_SPEAKER_SIZE]; u8 g_RegExt[WIIMOTE_REG_EXT_SIZE]; u8 g_RegIr[WIIMOTE_REG_IR_SIZE]; +u8 g_ReportingMode; + static const u8 EepromData_0[] = { 0xA1, 0xAA, 0x8B, 0x99, 0xAE, 0x9E, 0x78, 0x30, 0xA7, 0x74, 0xD3, 0xA1, 0xAA, 0x8B, 0x99, 0xAE, @@ -142,6 +144,7 @@ extern "C" void GetDllInfo (PLUGIN_INFO* _PluginInfo) extern "C" void DllAbout(HWND _hParent) { wxAboutDialogInfo info; + info.SetName("Wiimote test plugin"); info.AddDeveloper(_T("masken (masken3@gmail.com)")); info.SetDescription(_T("Wiimote test plugin")); wxAboutBox(info); @@ -159,9 +162,12 @@ extern "C" void Wiimote_Initialize(SWiimoteInitialize _WiimoteInitialize) memset(g_Eeprom, 0, WIIMOTE_EEPROM_SIZE); memcpy(g_Eeprom, EepromData_0, sizeof(EepromData_0)); memcpy(g_Eeprom + 0x16D0, EepromData_16D0, sizeof(EepromData_16D0)); + + g_ReportingMode = 0; } extern "C" void Wiimote_DoState(void* ptr, int mode) { + //TODO: implement } extern "C" void Wiimote_Shutdown(void) @@ -194,6 +200,14 @@ extern "C" void Wiimote_Output(const void* _pData, u32 _Size) { } } +extern "C" void Wiimote_Update() { + //LOG(WIIMOTE, "Wiimote_Update"); + if(g_ReportingMode == 0x33) + SendReportCoreAccelIr12(); + else if(g_ReportingMode == 0x31) + SendReportCoreAccel(); +} + extern "C" unsigned int Wiimote_GetAttachedControllers() { return 1; } @@ -246,10 +260,7 @@ void WmDataReporting(wm_data_reporting* dr) { LOG(WIIMOTE, " Rumble: %x", dr->rumble); LOG(WIIMOTE, " Mode: 0x%02x", dr->mode); - if(dr->mode == 0x33) - SendReportCoreAccelIr12(); - else if(dr->mode == 0x31) - SendReportCoreAccel(); + g_ReportingMode = dr->mode; } void SendReportCoreAccelIr12() { @@ -265,11 +276,25 @@ void SendReportCoreAccelIr12() { pReport->a.y = 0x78; pReport->a.z = 0xD9; - pReport->ir[0].x = 320 & 0xFF; - pReport->ir[0].y = 240; + int x = 600; + int y = 440; + + x = 1023 - x; + pReport->ir[0].x = x & 0xFF; + pReport->ir[0].y = y & 0xFF; pReport->ir[0].size = 10; - pReport->ir[0].xHi = 320 >> 8; - pReport->ir[0].yHi = 0; + pReport->ir[0].xHi = x >> 8; + pReport->ir[0].yHi = y >> 8; + + x = 100; + y = 450; + + x = 1023 - x; + pReport->ir[1].x = x; + pReport->ir[1].y = y & 0xFF; + pReport->ir[1].size = 5; + pReport->ir[1].xHi = x >> 8; + pReport->ir[1].yHi = y >> 8; LOG(WIIMOTE, " SendReportCoreAccelIr12()");