diff --git a/Source/Core/AudioCommon/Src/Mixer.h b/Source/Core/AudioCommon/Src/Mixer.h index a3ebf94185..4f8ca421ac 100644 --- a/Source/Core/AudioCommon/Src/Mixer.h +++ b/Source/Core/AudioCommon/Src/Mixer.h @@ -41,7 +41,7 @@ public: // I perfer speed so let's do down-sampling instead of up-sampling // If you like better sound than speed, feel free to implement the up-sampling code m_sampleRate = 32000; - NOTICE_LOG(AUDIO_INTERFACE, "Mixer is initialized (AISampleRate:%i, DACSampleRate:%i)", AISampleRate, DACSampleRate); + INFO_LOG(AUDIO_INTERFACE, "Mixer is initialized (AISampleRate:%i, DACSampleRate:%i)", AISampleRate, DACSampleRate); } // Called from audio threads diff --git a/Source/Core/Common/Src/PluginWiimote.h b/Source/Core/Common/Src/PluginWiimote.h index 53b473550c..ef60c5b8c1 100644 --- a/Source/Core/Common/Src/PluginWiimote.h +++ b/Source/Core/Common/Src/PluginWiimote.h @@ -24,9 +24,9 @@ namespace Common { typedef unsigned int (__cdecl* TPAD_GetAttachedPads)(); -typedef void (__cdecl* TWiimote_Update)(); -typedef void (__cdecl* TWiimote_Output)(u16 _channelID, const void* _pData, u32 _Size); -typedef void (__cdecl* TWiimote_Input)(u16 _channelID, const void* _pData, u32 _Size); +typedef void (__cdecl* TWiimote_Update)(int _number); +typedef void (__cdecl* TWiimote_Output)(int _number, u16 _channelID, const void* _pData, u32 _Size); +typedef void (__cdecl* TWiimote_Input)(int _number, u16 _channelID, const void* _pData, u32 _Size); typedef unsigned int (__cdecl* TWiimote_GetAttachedControllers)(); class PluginWiimote : public CPlugin { diff --git a/Source/Core/Core/Src/Core.cpp b/Source/Core/Core/Src/Core.cpp index bda22970cd..c5d69b225e 100644 --- a/Source/Core/Core/Src/Core.cpp +++ b/Source/Core/Core/Src/Core.cpp @@ -79,7 +79,7 @@ const char *Callback_ISOName(void); void Callback_DSPInterrupt(); void Callback_PADLog(const TCHAR* _szMessage); void Callback_WiimoteLog(const TCHAR* _szMessage, int _v); -void Callback_WiimoteInput(u16 _channelID, const void* _pData, u32 _Size); +void Callback_WiimoteInput(int _number, u16 _channelID, const void* _pData, u32 _Size); // For keyboard shortcuts. void Callback_KeyPress(int key, bool shift, bool control); diff --git a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_stm.h b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_stm.h index f1eb7cc1dd..4cb8773057 100644 --- a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_stm.h +++ b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_stm.h @@ -54,7 +54,7 @@ public: virtual bool Open(u32 _CommandAddress, u32 _Mode) { - ERROR_LOG(WII_IPC_STM, "STM immediate: Open"); + INFO_LOG(WII_IPC_STM, "STM immediate: Open"); Memory::Write_U32(GetDeviceID(), _CommandAddress+4); m_Active = true; return true; @@ -62,7 +62,7 @@ public: virtual bool Close(u32 _CommandAddress, bool _bForce) { - ERROR_LOG(WII_IPC_STM, "STM immediate: Close"); + INFO_LOG(WII_IPC_STM, "STM immediate: Close"); if (!_bForce) Memory::Write_U32(0, _CommandAddress+4); m_Active = false; diff --git a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_usb.cpp b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_usb.cpp index 0c5d69a0a1..a4300e2a9b 100644 --- a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_usb.cpp +++ b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_usb.cpp @@ -42,12 +42,11 @@ CWII_IPC_HLE_Device_usb_oh1_57e_305::CWII_IPC_HLE_Device_usb_oh1_57e_305(u32 _De , m_ACLBuffer(NULL) , m_ACLPool(0) , m_LastCmd(0) - , m_PacketCount(0) , m_FreqDividerSync(0) - , m_FreqDividerMote(0) { - // Connect one Wiimote by default - m_WiiMotes.push_back(CWII_IPC_HLE_WiiMote(this, 0)); + // Activate the first one Wiimote by default + m_WiiMotes.push_back(CWII_IPC_HLE_WiiMote(this, 0, true)); +// m_WiiMotes.push_back(CWII_IPC_HLE_WiiMote(this, 1)); // The BCM2045's btaddr: m_ControllerBD.b[0] = 0x11; @@ -63,6 +62,8 @@ CWII_IPC_HLE_Device_usb_oh1_57e_305::CWII_IPC_HLE_Device_usb_oh1_57e_305(u32 _De m_ClassOfDevice[2] = 0x00; memset(m_LocalName, 0, HCI_UNIT_NAME_SIZE); + memset(m_PacketCount, 0, sizeof(m_PacketCount)); + memset(m_FreqDividerMote, 0, sizeof(m_FreqDividerMote)); Host_SetWiiMoteConnectionState(0); } @@ -75,14 +76,18 @@ CWII_IPC_HLE_Device_usb_oh1_57e_305::~CWII_IPC_HLE_Device_usb_oh1_57e_305() void CWII_IPC_HLE_Device_usb_oh1_57e_305::DoState(PointerWrap &p) { p.Do(m_LastCmd); - p.Do(m_PacketCount); p.Do(m_CtrlSetup); p.Do(m_HCIBuffer); p.Do(m_HCIPool); p.Do(m_ACLBuffer); p.Do(m_ACLPool); p.Do(m_FreqDividerSync); - p.Do(m_FreqDividerMote); + + for (int i = 0; i < 4; i++) + { + p.Do(m_PacketCount[i]); + p.Do(m_FreqDividerMote[i]); + } } // =================================================== @@ -108,9 +113,9 @@ bool CWII_IPC_HLE_Device_usb_oh1_57e_305::Close(u32 _CommandAddress, bool _bForc m_HostNumSCOPackets = 0; m_LastCmd = 0; - m_PacketCount = 0; m_FreqDividerSync = 0; - m_FreqDividerMote = 0; + memset(m_FreqDividerMote, 0, sizeof(m_FreqDividerMote)); + memset(m_PacketCount, 0, sizeof(m_PacketCount)); m_HCIBuffer.m_address = NULL; m_HCIPool.m_number = 0; @@ -208,7 +213,7 @@ bool CWII_IPC_HLE_Device_usb_oh1_57e_305::IOCtlV(u32 _CommandAddress) _dbg_assert_(WII_IPC_WIIMOTE, pACLHeader->PBFlag == 2); SendToDevice(pACLHeader->ConnectionHandle, Memory::GetPointer(BulkBuffer.m_buffer + 4), pACLHeader->Size); - m_PacketCount++; + m_PacketCount[pACLHeader->ConnectionHandle & 0x1]++; // If ACLPool is not used, we can send a reply immediately // or else we have to delay this reply @@ -297,6 +302,8 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::SendToDevice(u16 _ConnectionHandle, u8 if (pWiiMote == NULL) return; + INFO_LOG(WII_IPC_WIIMOTE, "++++++++++++++++++++++++++++++++++++++"); + INFO_LOG(WII_IPC_WIIMOTE, "Execute ACL Command: ConnectionHandle 0x%04x", _ConnectionHandle); pWiiMote->ExecuteL2capCmd(_pData, _Size); } @@ -316,7 +323,7 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::SendACLPacket(u16 _ConnectionHandle, u { if(m_ACLBuffer.m_address != NULL) { - INFO_LOG(WII_IPC_WIIMOTE, "Sending ACL Packet: 0x%08x ....", m_ACLBuffer.m_address); + INFO_LOG(WII_IPC_WIIMOTE, "Sending ACL Packet: 0x%08x .... (ConnectionHandle 0x%04x)", m_ACLBuffer.m_address, _ConnectionHandle); UACLHeader* pHeader = (UACLHeader*)Memory::GetPointer(m_ACLBuffer.m_buffer); pHeader->ConnectionHandle = _ConnectionHandle; @@ -337,10 +344,10 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::SendACLPacket(u16 _ConnectionHandle, u m_ACLBuffer.m_address = NULL; m_ACLBuffer.m_buffer = NULL; } - else if ((sizeof(UACLHeader) + _Size) > 64 ) + else if ((sizeof(UACLHeader) + _Size) > ACL_MAX_SIZE ) { - ERROR_LOG(WII_IPC_HLE, "ACL Packet size is too big! (>64B)"); - PanicAlert("WII_IPC_HLE: ACL Packet size is too big! (>64B)"); + ERROR_LOG(WII_IPC_HLE, "ACL Packet size is too big!"); + PanicAlert("WII_IPC_HLE: ACL Packet size is too big!"); } else if (m_ACLPool.m_number >= 16) { @@ -349,7 +356,7 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::SendACLPacket(u16 _ConnectionHandle, u } else { - UACLHeader* pHeader = (UACLHeader*)(m_ACLPool.m_data + m_ACLPool.m_number * 64); // I believe 64B is enough + UACLHeader* pHeader = (UACLHeader*)(m_ACLPool.m_data + m_ACLPool.m_number * ACL_MAX_SIZE); pHeader->ConnectionHandle = _ConnectionHandle; pHeader->BCFlag = 0; pHeader->PBFlag = 2; @@ -378,8 +385,8 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::PurgeACLPool() { m_ACLPool.m_number--; // Fill the buffer - u8* _Address = m_ACLPool.m_data + m_ACLPool.m_number * 64; - memcpy(Memory::GetPointer(m_ACLBuffer.m_buffer), _Address, 64); + u8* _Address = m_ACLPool.m_data + m_ACLPool.m_number * ACL_MAX_SIZE; + memcpy(Memory::GetPointer(m_ACLBuffer.m_buffer), _Address, ACL_MAX_SIZE); // Write the packet size as return value Memory::Write_U32(sizeof(UACLHeader) + ((UACLHeader*)_Address)->Size, m_ACLBuffer.m_address + 0x4); // Send a reply to indicate ACL buffer is sent @@ -395,7 +402,6 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::PurgeACLPool() // ---------------- u32 CWII_IPC_HLE_Device_usb_oh1_57e_305::Update() { - // Check if HCI Pool is not purged if (m_HCIPool.m_number > 0) { @@ -440,14 +446,16 @@ u32 CWII_IPC_HLE_Device_usb_oh1_57e_305::Update() { counter--; if (counter < 0) - for (size_t i=0; i < m_WiiMotes.size(); i++) - if (m_WiiMotes[i].EventPagingChanged(2)) + { + for (unsigned int i = 0; i < m_WiiMotes.size(); i++) + if (m_WiiMotes[i].EventPagingChanged(m_ScanEnable)) { Host_SetWiiMoteConnectionState(1); // Create ACL connection SendEventRequestConnection(m_WiiMotes[i]); return true; } + } } // AyuanX: Actually we don't need to link channels so early @@ -457,7 +465,7 @@ u32 CWII_IPC_HLE_Device_usb_oh1_57e_305::Update() // But ... whatever, either way works // // Link channels when connected - if (m_ACLBuffer.m_address) + if (m_ACLBuffer.m_address && !m_LastCmd && !WII_IPCInterface::GetAddress()) { for (size_t i = 0; i < m_WiiMotes.size(); i++) { @@ -469,14 +477,17 @@ u32 CWII_IPC_HLE_Device_usb_oh1_57e_305::Update() // The Real Wiimote sends report at a fixed frequency of 100Hz // So let's make it also 100Hz here // Calculation: 15000Hz (IPC_HLE) / 100Hz (WiiMote) = 150 - if (m_ACLBuffer.m_address && !m_LastCmd && m_WiiMotes[0].IsLinked()) + if (m_ACLBuffer.m_address && !m_LastCmd) { - m_FreqDividerMote++; - if(m_FreqDividerMote >= 150) + for (unsigned int i = 0; i < m_WiiMotes.size(); i++) { - m_FreqDividerMote = 0; - CPluginManager::GetInstance().GetWiimote(0)->Wiimote_Update(); - return true; + m_FreqDividerMote[i]++; + if (m_WiiMotes[i].IsLinked() && m_FreqDividerMote[i] >= 150) + { + m_FreqDividerMote[i] = 0; + CPluginManager::GetInstance().GetWiimote(0)->Wiimote_Update(i); + return true; + } } } @@ -487,11 +498,11 @@ u32 CWII_IPC_HLE_Device_usb_oh1_57e_305::Update() if (m_HCIBuffer.m_address && !WII_IPCInterface::GetAddress() && m_WiiMotes[0].IsConnected()) { m_FreqDividerSync++; - if ((m_PacketCount > 0) || (m_FreqDividerSync >= 100)) // Feel free to tweak it + if (m_FreqDividerSync >= 500) // Feel free to tweak it { m_FreqDividerSync = 0; - SendEventNumberOfCompletedPackets(m_WiiMotes[0].GetConnectionHandle(), m_PacketCount); - m_PacketCount = 0; + SendEventNumberOfCompletedPackets(); + memset(m_PacketCount, 0, sizeof(m_PacketCount)); return true; } } @@ -528,10 +539,10 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::AddEventToQueue(const SQueuedEvent& _e m_HCIBuffer.m_address = NULL; m_HCIBuffer.m_buffer = NULL; } - else if (_event.m_size > 64) + else if (_event.m_size > HCI_MAX_SIZE) { - ERROR_LOG(WII_IPC_HLE, "HCI Packet size too big! (>64B)"); - PanicAlert("WII_IPC_HLE: HCI Packet size too big! (>64B)"); + ERROR_LOG(WII_IPC_HLE, "HCI Packet size too big!"); + PanicAlert("WII_IPC_HLE: HCI Packet size too big!"); } else if (m_HCIPool.m_number >= 16) { @@ -540,7 +551,7 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::AddEventToQueue(const SQueuedEvent& _e } else { - memcpy(m_HCIPool.m_data + m_HCIPool.m_number * 64, _event.m_buffer, _event.m_size); + memcpy(m_HCIPool.m_data + m_HCIPool.m_number * HCI_MAX_SIZE, _event.m_buffer, _event.m_size); // HCI Packet doesn't contain size info inside, so we have to store it somewhere m_HCIPool.m_size[m_HCIPool.m_number] = _event.m_size; m_HCIPool.m_number++; @@ -636,7 +647,7 @@ bool CWII_IPC_HLE_Device_usb_oh1_57e_305::SendEventInquiryResponse() return true; } -bool CWII_IPC_HLE_Device_usb_oh1_57e_305::SendEventConnectionComplete(bdaddr_t _bd) +bool CWII_IPC_HLE_Device_usb_oh1_57e_305::SendEventConnectionComplete(const bdaddr_t& _bd) { CWII_IPC_HLE_WiiMote* pWiiMote = AccessWiiMote(_bd); if (pWiiMote == NULL) @@ -650,16 +661,12 @@ bool CWII_IPC_HLE_Device_usb_oh1_57e_305::SendEventConnectionComplete(bdaddr_t _ pConnectionComplete->PayloadLength = sizeof(SHCIEventConnectionComplete) - 2; pConnectionComplete->Status = 0x00; pConnectionComplete->Connection_Handle = pWiiMote->GetConnectionHandle(); - pConnectionComplete->bdaddr = pWiiMote->GetBD(); + pConnectionComplete->bdaddr = _bd; pConnectionComplete->LinkType = HCI_LINK_ACL; pConnectionComplete->EncryptionEnabled = HCI_ENCRYPTION_MODE_NONE; AddEventToQueue(Event); - CWII_IPC_HLE_WiiMote* pWiimote = AccessWiiMote(_bd); - if (pWiimote) - pWiimote->EventConnectionAccepted(); - #if MAX_LOGLEVEL >= DEBUG_LEVEL static char s_szLinkType[][128] = { @@ -683,9 +690,6 @@ bool CWII_IPC_HLE_Device_usb_oh1_57e_305::SendEventConnectionComplete(bdaddr_t _ /* This is called from Update() after ScanEnable has been enabled. */ bool CWII_IPC_HLE_Device_usb_oh1_57e_305::SendEventRequestConnection(CWII_IPC_HLE_WiiMote& _rWiiMote) { - // We have to disable scan now to avoid running this function over and over again - m_ScanEnable = 0; - SQueuedEvent Event(sizeof(SHCIEventRequestConnection), 0); SHCIEventRequestConnection* pEventRequestConnection = (SHCIEventRequestConnection*)Event.m_buffer; @@ -698,8 +702,6 @@ bool CWII_IPC_HLE_Device_usb_oh1_57e_305::SendEventRequestConnection(CWII_IPC_HL pEventRequestConnection->uclass[2] = _rWiiMote.GetClass()[2]; pEventRequestConnection->LinkType = HCI_LINK_ACL; - AddEventToQueue(Event); - // Log #if MAX_LOGLEVEL >= DEBUG_LEVEL static char LinkType[][128] = @@ -720,6 +722,8 @@ bool CWII_IPC_HLE_Device_usb_oh1_57e_305::SendEventRequestConnection(CWII_IPC_HL DEBUG_LOG(WII_IPC_WIIMOTE, " COD[2]: 0x%02x", pEventRequestConnection->uclass[2]); //DEBUG_LOG(WII_IPC_WIIMOTE, " LinkType: %s", LinkType[pEventRequestConnection->LinkType]); + AddEventToQueue(Event); + return true; } @@ -771,7 +775,7 @@ bool CWII_IPC_HLE_Device_usb_oh1_57e_305::SendEventAuthenticationCompleted(u16 _ return true; } -bool CWII_IPC_HLE_Device_usb_oh1_57e_305::SendEventRemoteNameReq(bdaddr_t _bd) +bool CWII_IPC_HLE_Device_usb_oh1_57e_305::SendEventRemoteNameReq(const bdaddr_t& _bd) { CWII_IPC_HLE_WiiMote* pWiiMote = AccessWiiMote(_bd); if (pWiiMote == NULL) @@ -784,7 +788,7 @@ bool CWII_IPC_HLE_Device_usb_oh1_57e_305::SendEventRemoteNameReq(bdaddr_t _bd) pRemoteNameReq->EventType = HCI_EVENT_REMOTE_NAME_REQ_COMPL; pRemoteNameReq->PayloadLength = sizeof(SHCIEventRemoteNameReq) - 2; pRemoteNameReq->Status = 0x00; - pRemoteNameReq->bdaddr = pWiiMote->GetBD(); + pRemoteNameReq->bdaddr = _bd; strcpy((char*)pRemoteNameReq->RemoteName, pWiiMote->GetName()); AddEventToQueue(Event); @@ -807,10 +811,8 @@ bool CWII_IPC_HLE_Device_usb_oh1_57e_305::SendEventReadRemoteFeatures(u16 _conne SQueuedEvent Event(sizeof(SHCIEventReadRemoteFeatures), _connectionHandle); SHCIEventReadRemoteFeatures* pReadRemoteFeatures = (SHCIEventReadRemoteFeatures*)Event.m_buffer; - // WTF CAN'T WE USE THE CORRECT VALUE HERE?! - // If you set EventType to HCI_EVENT_READ_REMOTE_FEATURES_COMPL, nintendo's BT stack will take a different path - // try it and see :) - pReadRemoteFeatures->EventType = 0x0c; //HCI_EVENT_READ_REMOTE_FEATURES_COMPL; + + pReadRemoteFeatures->EventType = HCI_EVENT_READ_REMOTE_FEATURES_COMPL; pReadRemoteFeatures->PayloadLength = sizeof(SHCIEventReadRemoteFeatures) - 2; pReadRemoteFeatures->Status = 0x00; pReadRemoteFeatures->ConnectionHandle = pWiiMote->GetConnectionHandle(); @@ -955,25 +957,29 @@ bool CWII_IPC_HLE_Device_usb_oh1_57e_305::SendEventRoleChange(bdaddr_t _bd, bool return true; } -bool CWII_IPC_HLE_Device_usb_oh1_57e_305::SendEventNumberOfCompletedPackets(u16 _connectionHandle, u16 _count) +bool CWII_IPC_HLE_Device_usb_oh1_57e_305::SendEventNumberOfCompletedPackets() { - CWII_IPC_HLE_WiiMote* pWiiMote = AccessWiiMote(_connectionHandle); - if (pWiiMote == NULL) + int Num = m_WiiMotes.size(); + if (Num == NULL) return false; - SQueuedEvent Event(sizeof(SHCIEventNumberOfCompletedPackets), 0); // zero, so this packet isn't counted + SQueuedEvent Event(sizeof(SHCIEventNumberOfCompletedPackets) + Num * 4, 0); SHCIEventNumberOfCompletedPackets* pNumberOfCompletedPackets = (SHCIEventNumberOfCompletedPackets*)Event.m_buffer; pNumberOfCompletedPackets->EventType = HCI_EVENT_NUM_COMPL_PKTS; - pNumberOfCompletedPackets->PayloadLength = sizeof(SHCIEventNumberOfCompletedPackets) - 2; - pNumberOfCompletedPackets->NumberOfHandles = 1; - pNumberOfCompletedPackets->Connection_Handle = _connectionHandle; - pNumberOfCompletedPackets->Number_Of_Completed_Packets = _count; + pNumberOfCompletedPackets->PayloadLength = sizeof(SHCIEventNumberOfCompletedPackets) + Num * 4 - 2; + pNumberOfCompletedPackets->NumberOfHandles = Num; + + u16 *pData = (u16 *)(Event.m_buffer + sizeof(SHCIEventNumberOfCompletedPackets)); + for (int i = 0; i < Num; i++) + { + pData[i] = m_WiiMotes[i].GetConnectionHandle(); + pData[Num + i] = m_PacketCount[i]; + } // Log INFO_LOG(WII_IPC_WIIMOTE, "Event: SendEventNumberOfCompletedPackets"); - DEBUG_LOG(WII_IPC_WIIMOTE, " Connection_Handle: 0x%04x", pNumberOfCompletedPackets->Connection_Handle); - DEBUG_LOG(WII_IPC_WIIMOTE, " Number_Of_Completed_Packets: %i", pNumberOfCompletedPackets->Number_Of_Completed_Packets); + DEBUG_LOG(WII_IPC_WIIMOTE, " NumberOfConnectionHandle: 0x%04x", pNumberOfCompletedPackets->NumberOfHandles); AddEventToQueue(Event); @@ -1032,7 +1038,7 @@ bool CWII_IPC_HLE_Device_usb_oh1_57e_305::SendEventLinkKeyNotification(const CWI return true; }; -bool CWII_IPC_HLE_Device_usb_oh1_57e_305::SendEventRequestLinkKey(bdaddr_t _bd) +bool CWII_IPC_HLE_Device_usb_oh1_57e_305::SendEventRequestLinkKey(const bdaddr_t& _bd) { SQueuedEvent Event(sizeof(SHCIEventRequestLinkKey), 0); @@ -1042,13 +1048,13 @@ bool CWII_IPC_HLE_Device_usb_oh1_57e_305::SendEventRequestLinkKey(bdaddr_t _bd) pEventRequestLinkKey->PayloadLength = sizeof(SHCIEventRequestLinkKey) - 2; pEventRequestLinkKey->bdaddr = _bd; - AddEventToQueue(Event); - INFO_LOG(WII_IPC_WIIMOTE, "Event: SendEventRequestLinkKey"); DEBUG_LOG(WII_IPC_WIIMOTE, " bd: %02x:%02x:%02x:%02x:%02x:%02x", pEventRequestLinkKey->bdaddr.b[0], pEventRequestLinkKey->bdaddr.b[1], pEventRequestLinkKey->bdaddr.b[2], pEventRequestLinkKey->bdaddr.b[3], pEventRequestLinkKey->bdaddr.b[4], pEventRequestLinkKey->bdaddr.b[5]); + AddEventToQueue(Event); + return true; }; @@ -1121,7 +1127,7 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::ExecuteHCICommandMessage(const SHCICom if(m_LastCmd == NULL) { INFO_LOG(WII_IPC_WIIMOTE, "**************************************************"); - INFO_LOG(WII_IPC_WIIMOTE, "ExecuteHCICommandMessage(0x%04x)(ocf: 0x%02x, ogf: 0x%02x)", pMsg->Opcode, ocf, ogf); + INFO_LOG(WII_IPC_WIIMOTE, "Execute HCI Command: 0x%04x (ocf: 0x%02x, ogf: 0x%02x)", pMsg->Opcode, ocf, ogf); } switch(pMsg->Opcode) @@ -1508,7 +1514,6 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandChangeConPacketType(u8* _Input) hci_change_con_pkt_type_cp* pChangePacketType = (hci_change_con_pkt_type_cp*)_Input; INFO_LOG(WII_IPC_WIIMOTE, "Command: HCI_CMD_CHANGE_CON_PACKET_TYPE"); - DEBUG_LOG(WII_IPC_WIIMOTE, "Input:"); DEBUG_LOG(WII_IPC_WIIMOTE, " ConnectionHandle: 0x%04x", pChangePacketType->con_handle); DEBUG_LOG(WII_IPC_WIIMOTE, " PacketType: 0x%04x", pChangePacketType->pkt_type); @@ -1524,7 +1529,6 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandAuthenticationRequested(u8* _In hci_auth_req_cp* pAuthReq = (hci_auth_req_cp*)_Input; INFO_LOG(WII_IPC_WIIMOTE, "Command: HCI_CMD_AUTH_REQ"); - DEBUG_LOG(WII_IPC_WIIMOTE, "Input:"); DEBUG_LOG(WII_IPC_WIIMOTE, " ConnectionHandle: 0x%04x", pAuthReq->con_handle); SendEventAuthenticationCompleted(pAuthReq->con_handle); @@ -1539,7 +1543,6 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandRemoteNameReq(u8* _Input) hci_remote_name_req_cp* pRemoteNameReq = (hci_remote_name_req_cp*)_Input; INFO_LOG(WII_IPC_WIIMOTE, "Command: HCI_CMD_REMOTE_NAME_REQ"); - DEBUG_LOG(WII_IPC_WIIMOTE, "Input:"); DEBUG_LOG(WII_IPC_WIIMOTE, " bd: %02x:%02x:%02x:%02x:%02x:%02x", pRemoteNameReq->bdaddr.b[0], pRemoteNameReq->bdaddr.b[1], pRemoteNameReq->bdaddr.b[2], pRemoteNameReq->bdaddr.b[3], pRemoteNameReq->bdaddr.b[4], pRemoteNameReq->bdaddr.b[5]); @@ -1559,7 +1562,6 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandReadRemoteFeatures(u8* _Input) hci_read_remote_features_cp* pReadRemoteFeatures = (hci_read_remote_features_cp*)_Input; INFO_LOG(WII_IPC_WIIMOTE, "Command: HCI_CMD_READ_REMOTE_FEATURES"); - DEBUG_LOG(WII_IPC_WIIMOTE, "Input:"); DEBUG_LOG(WII_IPC_WIIMOTE, " ConnectionHandle: 0x%04x", pReadRemoteFeatures->con_handle); SendEventReadRemoteFeatures(pReadRemoteFeatures->con_handle); @@ -1574,7 +1576,6 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandReadRemoteVerInfo(u8* _Input) hci_read_remote_ver_info_cp* pReadRemoteVerInfo = (hci_read_remote_ver_info_cp*)_Input; INFO_LOG(WII_IPC_WIIMOTE, "Command: HCI_CMD_READ_REMOTE_VER_INFO"); - DEBUG_LOG(WII_IPC_WIIMOTE, "Input:"); DEBUG_LOG(WII_IPC_WIIMOTE, " ConnectionHandle: 0x%02x", pReadRemoteVerInfo->con_handle); SendEventReadRemoteVerInfo(pReadRemoteVerInfo->con_handle); @@ -1589,7 +1590,6 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandReadClockOffset(u8* _Input) hci_read_clock_offset_cp* pReadClockOffset = (hci_read_clock_offset_cp*)_Input; INFO_LOG(WII_IPC_WIIMOTE, "Command: HCI_CMD_READ_CLOCK_OFFSET"); - DEBUG_LOG(WII_IPC_WIIMOTE, "Input:"); DEBUG_LOG(WII_IPC_WIIMOTE, " ConnectionHandle: 0x%02x", pReadClockOffset->con_handle); SendEventReadClockOffsetComplete(pReadClockOffset->con_handle); @@ -1607,34 +1607,38 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandSniffMode(u8* _Input) hci_sniff_mode_cp* pSniffMode = (hci_sniff_mode_cp*)_Input; INFO_LOG(WII_IPC_WIIMOTE, "Command: HCI_CMD_SNIFF_MODE"); - DEBUG_LOG(WII_IPC_WIIMOTE, "Input:"); - DEBUG_LOG(WII_IPC_WIIMOTE, " ConnectionHandle: 0x%04x", pSniffMode->con_handle); + INFO_LOG(WII_IPC_WIIMOTE, " ConnectionHandle: 0x%04x", pSniffMode->con_handle); DEBUG_LOG(WII_IPC_WIIMOTE, " max_interval: 0x%04x", pSniffMode->max_interval); DEBUG_LOG(WII_IPC_WIIMOTE, " min_interval: 0x%04x", pSniffMode->min_interval); DEBUG_LOG(WII_IPC_WIIMOTE, " attempt: 0x%04x", pSniffMode->attempt); DEBUG_LOG(WII_IPC_WIIMOTE, " timeout: 0x%04x", pSniffMode->timeout); SendEventModeChange(pSniffMode->con_handle, 0x02, pSniffMode->max_interval); // 0x02 - sniff mode + + // Now is a good time to activate next wiimote + u16 NextHandle = pSniffMode->con_handle + 1; + if ((NextHandle & 0x1u) < m_WiiMotes.size()) + { + CWII_IPC_HLE_WiiMote* pWiimote = AccessWiiMote(NextHandle); + if (pWiimote) + pWiimote->Activate(true); + } } void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandWriteLinkPolicy(u8* _Input) { - if(SendEventCommandStatus(HCI_CMD_WRITE_LINK_POLICY_SETTINGS)) - return; - // command parameters hci_write_link_policy_settings_cp* pLinkPolicy = (hci_write_link_policy_settings_cp*)_Input; INFO_LOG(WII_IPC_WIIMOTE, "Command: HCI_CMD_WRITE_LINK_POLICY_SETTINGS"); - DEBUG_LOG(WII_IPC_WIIMOTE, "Input:"); DEBUG_LOG(WII_IPC_WIIMOTE, " ConnectionHandle: 0x%04x", pLinkPolicy->con_handle); DEBUG_LOG(WII_IPC_WIIMOTE, " Policy: 0x%04x", pLinkPolicy->settings); - CWII_IPC_HLE_WiiMote* pWiimote = AccessWiiMote(pLinkPolicy->con_handle); - if (pWiimote) - { - pWiimote->EventCommandWriteLinkPolicy(); - } + hci_write_link_policy_settings_rp Reply; + Reply.status = 0x00; + Reply.con_handle = pLinkPolicy->con_handle; + + SendEventCommandComplete(HCI_CMD_WRITE_LINK_POLICY_SETTINGS, &Reply, sizeof(hci_write_link_policy_settings_rp)); } void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandReset(u8* _Input) @@ -1660,7 +1664,6 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandSetEventFilter(u8* _Input) Reply.status = 0x00; INFO_LOG(WII_IPC_WIIMOTE, "Command: HCI_CMD_SET_EVENT_FILTER:"); - DEBUG_LOG(WII_IPC_WIIMOTE, "write:"); DEBUG_LOG(WII_IPC_WIIMOTE, " filter_type: %i", pSetEventFilter->filter_type); DEBUG_LOG(WII_IPC_WIIMOTE, " filter_condition_type: %i", pSetEventFilter->filter_condition_type); @@ -1678,7 +1681,6 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandWritePinType(u8* _Input) Reply.status = 0x00; INFO_LOG(WII_IPC_WIIMOTE, "Command: HCI_CMD_WRITE_PIN_TYPE:"); - DEBUG_LOG(WII_IPC_WIIMOTE, "write:"); DEBUG_LOG(WII_IPC_WIIMOTE, " pin_type: %x", pWritePinType->pin_type); SendEventCommandComplete(HCI_CMD_WRITE_PIN_TYPE, &Reply, sizeof(hci_write_pin_type_rp)); @@ -1735,7 +1737,6 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandDeleteStoredLinkKey(u8* _Input) hci_delete_stored_link_key_cp* pDeleteStoredLinkKey = (hci_delete_stored_link_key_cp*)_Input; INFO_LOG(WII_IPC_WIIMOTE, "Command: HCI_OCF_DELETE_STORED_LINK_KEY"); - DEBUG_LOG(WII_IPC_WIIMOTE, "Input:"); DEBUG_LOG(WII_IPC_WIIMOTE, " bd: %02x:%02x:%02x:%02x:%02x:%02x", pDeleteStoredLinkKey->bdaddr.b[0], pDeleteStoredLinkKey->bdaddr.b[1], pDeleteStoredLinkKey->bdaddr.b[2], pDeleteStoredLinkKey->bdaddr.b[3], pDeleteStoredLinkKey->bdaddr.b[4], pDeleteStoredLinkKey->bdaddr.b[5]); @@ -1767,7 +1768,6 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandWriteLocalName(u8* _Input) Reply.status = 0x00; INFO_LOG(WII_IPC_WIIMOTE, "Command: HCI_CMD_WRITE_LOCAL_NAME:"); - DEBUG_LOG(WII_IPC_WIIMOTE, "write:"); DEBUG_LOG(WII_IPC_WIIMOTE, " local_name: %s", pWriteLocalName->name); SendEventCommandComplete(HCI_CMD_WRITE_LOCAL_NAME, &Reply, sizeof(hci_write_local_name_rp)); @@ -1787,7 +1787,6 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandWritePageTimeOut(u8* _Input) Reply.status = 0x00; INFO_LOG(WII_IPC_WIIMOTE, "Command: HCI_CMD_WRITE_PAGE_TIMEOUT:"); - DEBUG_LOG(WII_IPC_WIIMOTE, "write:"); DEBUG_LOG(WII_IPC_WIIMOTE, " timeout: %i", pWritePageTimeOut->timeout); SendEventCommandComplete(HCI_CMD_WRITE_PAGE_TIMEOUT, &Reply, sizeof(hci_host_buffer_size_rp)); @@ -1815,7 +1814,6 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandWriteScanEnable(u8* _Input) #endif INFO_LOG(WII_IPC_WIIMOTE, "Command: HCI_CMD_WRITE_SCAN_ENABLE:"); - DEBUG_LOG(WII_IPC_WIIMOTE, "write:"); DEBUG_LOG(WII_IPC_WIIMOTE, " scan_enable: %s", Scanning[pWriteScanEnable->scan_enable]); SendEventCommandComplete(HCI_CMD_WRITE_SCAN_ENABLE, &Reply, sizeof(hci_write_scan_enable_rp)); @@ -1834,7 +1832,6 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandWriteUnitClass(u8* _Input) Reply.status = 0x00; INFO_LOG(WII_IPC_WIIMOTE, "Command: HCI_CMD_WRITE_UNIT_CLASS:"); - DEBUG_LOG(WII_IPC_WIIMOTE, "write:"); DEBUG_LOG(WII_IPC_WIIMOTE, " COD[0]: 0x%02x", pWriteUnitClass->uclass[0]); DEBUG_LOG(WII_IPC_WIIMOTE, " COD[1]: 0x%02x", pWriteUnitClass->uclass[1]); DEBUG_LOG(WII_IPC_WIIMOTE, " COD[2]: 0x%02x", pWriteUnitClass->uclass[2]); @@ -1856,8 +1853,6 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandHostBufferSize(u8* _Input) Reply.status = 0x00; INFO_LOG(WII_IPC_WIIMOTE, "Command: HCI_CMD_HOST_BUFFER_SIZE:"); - - DEBUG_LOG(WII_IPC_WIIMOTE, "write:"); DEBUG_LOG(WII_IPC_WIIMOTE, " max_acl_size: %i", pHostBufferSize->max_acl_size); DEBUG_LOG(WII_IPC_WIIMOTE, " max_sco_size: %i", pHostBufferSize->max_sco_size); DEBUG_LOG(WII_IPC_WIIMOTE, " num_acl_pkts: %i", pHostBufferSize->num_acl_pkts); @@ -1871,8 +1866,7 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandWriteLinkSupervisionTimeout(u8* // command parameters hci_write_link_supervision_timeout_cp* pSuperVision = (hci_write_link_supervision_timeout_cp*)_Input; - INFO_LOG(WII_IPC_WIIMOTE, "Command: HCI_OCF_WRITE_LINK_SUPERVISION_TIMEOUT"); - DEBUG_LOG(WII_IPC_WIIMOTE, "Input:"); + INFO_LOG(WII_IPC_WIIMOTE, "Command: HCI_CMD_WRITE_LINK_SUPERVISION_TIMEOUT"); DEBUG_LOG(WII_IPC_WIIMOTE, " con_handle: 0x%04x", pSuperVision->con_handle); DEBUG_LOG(WII_IPC_WIIMOTE, " timeout: 0x%02x", pSuperVision->timeout); @@ -1880,7 +1874,12 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandWriteLinkSupervisionTimeout(u8* Reply.status = 0x00; Reply.con_handle = pSuperVision->con_handle; - SendEventCommandComplete(HCI_OCF_WRITE_LINK_SUPERVISION_TIMEOUT, &Reply, sizeof(hci_write_link_supervision_timeout_rp)); + SendEventCommandComplete(HCI_CMD_WRITE_LINK_SUPERVISION_TIMEOUT, &Reply, sizeof(hci_write_link_supervision_timeout_rp)); + + // Now is a good time to link channels + CWII_IPC_HLE_WiiMote* pWiimote = AccessWiiMote(pSuperVision->con_handle); + if (pWiimote) + pWiimote->EventConnectionAccepted(); } void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandWriteInquiryScanType(u8* _Input) @@ -1894,7 +1893,6 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandWriteInquiryScanType(u8* _Input Reply.status = 0x00; INFO_LOG(WII_IPC_WIIMOTE, "Command: HCI_CMD_WRITE_INQUIRY_SCAN_TYPE:"); - DEBUG_LOG(WII_IPC_WIIMOTE, "write:"); DEBUG_LOG(WII_IPC_WIIMOTE, " type: %i", pSetEventFilter->type); SendEventCommandComplete(HCI_CMD_WRITE_INQUIRY_SCAN_TYPE, &Reply, sizeof(hci_write_inquiry_scan_type_rp)); @@ -1920,7 +1918,6 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandWriteInquiryMode(u8* _Input) }; #endif INFO_LOG(WII_IPC_WIIMOTE, "Command: HCI_CMD_WRITE_INQUIRY_MODE:"); - DEBUG_LOG(WII_IPC_WIIMOTE, "write:"); DEBUG_LOG(WII_IPC_WIIMOTE, " mode: %s", InquiryMode[pInquiryMode->mode]); SendEventCommandComplete(HCI_CMD_WRITE_INQUIRY_MODE, &Reply, sizeof(hci_write_inquiry_mode_rp)); @@ -1946,7 +1943,6 @@ void CWII_IPC_HLE_Device_usb_oh1_57e_305::CommandWritePageScanType(u8* _Input) #endif INFO_LOG(WII_IPC_WIIMOTE, "Command: HCI_CMD_WRITE_PAGE_SCAN_TYPE:"); - DEBUG_LOG(WII_IPC_WIIMOTE, "write:"); DEBUG_LOG(WII_IPC_WIIMOTE, " type: %s", PageScanType[pWritePageScanType->type]); SendEventCommandComplete(HCI_CMD_WRITE_PAGE_SCAN_TYPE, &Reply, sizeof(hci_write_page_scan_type_rp)); 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 91ea1deb31..2ec9146aa8 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 @@ -25,6 +25,8 @@ #include "WII_IPC_HLE_Device.h" #include "WII_IPC_HLE_WiiMote.h" +#define HCI_MAX_SIZE 128 +#define ACL_MAX_SIZE 128 union UACLHeader { @@ -129,7 +131,7 @@ private: struct ACLPool { u32 m_number; - u8 m_data[1024]; // Capacity: 64B x 16 + u8 m_data[ACL_MAX_SIZE * 16]; ACLPool(int num) : m_number(num) @@ -140,7 +142,7 @@ private: struct HCIPool { u32 m_number; - u8 m_data[1024]; // Capacity: 64B x 16 + u8 m_data[HCI_MAX_SIZE * 16]; u8 m_size[16]; HCIPool(int num) @@ -191,9 +193,9 @@ private: CtrlBuffer m_ACLBuffer; ACLPool m_ACLPool; u32 m_LastCmd; - int m_PacketCount; + u32 m_PacketCount[4]; + u32 m_FreqDividerMote[4]; u32 m_FreqDividerSync; - u32 m_FreqDividerMote; // Events void AddEventToQueue(const SQueuedEvent& _event); @@ -201,19 +203,19 @@ private: void SendEventCommandComplete(u16 _OpCode, void* _pData, u32 _DataSize); bool SendEventInquiryResponse(); bool SendEventInquiryComplete(); - bool SendEventRemoteNameReq(bdaddr_t _bd); + bool SendEventRemoteNameReq(const bdaddr_t& _bd); bool SendEventRequestConnection(CWII_IPC_HLE_WiiMote& _rWiiMote); - bool SendEventConnectionComplete(bdaddr_t _bd); + bool SendEventConnectionComplete(const bdaddr_t& _bd); bool SendEventReadClockOffsetComplete(u16 _connectionHandle); bool SendEventConPacketTypeChange(u16 _connectionHandle, u16 _packetType); bool SendEventReadRemoteVerInfo(u16 _connectionHandle); bool SendEventReadRemoteFeatures(u16 _connectionHandle); bool SendEventRoleChange(bdaddr_t _bd, bool _master); - bool SendEventNumberOfCompletedPackets(u16 _connectionHandle, u16 _count); + bool SendEventNumberOfCompletedPackets(); bool SendEventAuthenticationCompleted(u16 _connectionHandle); bool SendEventModeChange(u16 _connectionHandle, u8 _mode, u16 _value); bool SendEventDisconnect(u16 _connectionHandle, u8 _Reason); - bool SendEventRequestLinkKey(bdaddr_t _bd); + bool SendEventRequestLinkKey(const bdaddr_t& _bd); bool SendEventLinkKeyNotification(const CWII_IPC_HLE_WiiMote& _rWiiMote); // Execute HCI Message 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 981424696e..d01b922733 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 @@ -31,9 +31,8 @@ static CWII_IPC_HLE_Device_usb_oh1_57e_305* s_Usb; -CWII_IPC_HLE_WiiMote::CWII_IPC_HLE_WiiMote(CWII_IPC_HLE_Device_usb_oh1_57e_305* _pHost, int _Number) - : m_Connected(false) - , m_Linked(false) +CWII_IPC_HLE_WiiMote::CWII_IPC_HLE_WiiMote(CWII_IPC_HLE_Device_usb_oh1_57e_305* _pHost, int _Number, bool ready) + : m_Linked(false) , m_HIDControlChannel_Connected(false) , m_HIDControlChannel_ConnectedWait(false) , m_HIDControlChannel_Config(false) @@ -47,9 +46,14 @@ CWII_IPC_HLE_WiiMote::CWII_IPC_HLE_WiiMote(CWII_IPC_HLE_Device_usb_oh1_57e_305* { - s_Usb = _pHost; INFO_LOG(WII_IPC_WIIMOTE, "Wiimote #%i constructed", _Number); + s_Usb = _pHost; + + m_Connected = (ready) ? 0 : -1; + m_ConnectionHandle = 0x100 + _Number; + memset(m_LinkKey, 0xA0 + _Number, 16); + m_BD.b[0] = 0x11; m_BD.b[1] = 0x02; m_BD.b[2] = 0x19; @@ -57,8 +61,6 @@ CWII_IPC_HLE_WiiMote::CWII_IPC_HLE_WiiMote(CWII_IPC_HLE_Device_usb_oh1_57e_305* m_BD.b[4] = 0x00; m_BD.b[5] = _Number; - m_ControllerConnectionHandle = 0x100 + _Number; - uclass[0]= 0x00; uclass[1]= 0x04; uclass[2]= 0x48; @@ -74,8 +76,6 @@ CWII_IPC_HLE_WiiMote::CWII_IPC_HLE_WiiMote(CWII_IPC_HLE_Device_usb_oh1_57e_305* lmp_version = 0x2; lmp_subversion = 0x229; - - memset(m_LinkKey, 0xA0 + _Number, 16); } @@ -92,7 +92,7 @@ CWII_IPC_HLE_WiiMote::CWII_IPC_HLE_WiiMote(CWII_IPC_HLE_Device_usb_oh1_57e_305* bool CWII_IPC_HLE_WiiMote::LinkChannel() { - if ((m_Connected == false) || (m_Linked == true)) + if ((m_Connected <= 0) || (m_Linked == true)) return false; // try to connect HID_CONTROL_CHANNEL @@ -102,7 +102,6 @@ bool CWII_IPC_HLE_WiiMote::LinkChannel() return false; m_HIDControlChannel_ConnectedWait = true; - // The CID is fixed, other CID will be rejected SendConnectionRequest(0x0040, HID_CONTROL_CHANNEL); return true; } @@ -113,10 +112,8 @@ bool CWII_IPC_HLE_WiiMote::LinkChannel() if (m_HIDControlChannel_ConfigWait) return false; - SChannel& rChannel = m_Channel[0x0040]; - m_HIDControlChannel_ConfigWait = true; - SendConfigurationRequest(rChannel.DCID); + SendConfigurationRequest(0x0040); return true; } @@ -127,7 +124,6 @@ bool CWII_IPC_HLE_WiiMote::LinkChannel() return false; m_HIDInterruptChannel_ConnectedWait = true; - // The CID is fixed, other CID will be rejected SendConnectionRequest(0x0041, HID_INTERRUPT_CHANNEL); return true; } @@ -139,9 +135,7 @@ bool CWII_IPC_HLE_WiiMote::LinkChannel() return false; m_HIDInterruptChannel_ConfigWait = true; - - SChannel& rChannel = m_Channel[0x0041]; - SendConfigurationRequest(rChannel.DCID); + SendConfigurationRequest(0x0041); return true; } @@ -225,37 +219,43 @@ void CWII_IPC_HLE_WiiMote::UpdateStatus() // // // - +void CWII_IPC_HLE_WiiMote::Activate(bool ready) +{ + if (ready) + m_Connected = 0; + else + m_Connected = -1; +} void CWII_IPC_HLE_WiiMote::EventConnectionAccepted() { - m_Connected = true; + m_Connected = 1; m_Linked = false; } void CWII_IPC_HLE_WiiMote::EventDisconnect() { - m_Connected = false; + m_Connected = 0; m_Linked = false; // Clear channel flags - EventCommandWriteLinkPolicy(); + ResetChannels(); } bool CWII_IPC_HLE_WiiMote::EventPagingChanged(u8 _pageMode) { - if (m_Connected) + if (m_Connected != 0) return false; - if ((_pageMode & 2) == 0) + if ((_pageMode & 0x2) == 0) return false; - + + m_Connected = -1; return true; } -void CWII_IPC_HLE_WiiMote::EventCommandWriteLinkPolicy() +void CWII_IPC_HLE_WiiMote::ResetChannels() { // reset connection process - m_HIDControlChannel_Connected = false; m_HIDControlChannel_Config = false; m_HIDInterruptChannel_Connected = false; @@ -291,8 +291,7 @@ void CWII_IPC_HLE_WiiMote::ExecuteL2capCmd(u8* _pData, u32 _Size) SL2CAP_Header* pHeader = (SL2CAP_Header*)_pData; u8* pData = _pData + sizeof(SL2CAP_Header); u32 DataSize = _Size - sizeof(SL2CAP_Header); - INFO_LOG(WII_IPC_WIIMOTE, "++++++++++++++++++++++++++++++++++++++"); - INFO_LOG(WII_IPC_WIIMOTE, "Execute L2CAP Command: Cid 0x%04x, Len 0x%x, DataSize 0x%x", pHeader->CID, pHeader->Length, DataSize); + INFO_LOG(WII_IPC_WIIMOTE, " CID 0x%04x, Len 0x%x, DataSize 0x%x", pHeader->CID, pHeader->Length, DataSize); if(pHeader->Length != DataSize) { @@ -322,13 +321,13 @@ void CWII_IPC_HLE_WiiMote::ExecuteL2capCmd(u8* _pData, u32 _Size) break; case HID_CONTROL_CHANNEL: - mote->Wiimote_ControlChannel(rChannel.DCID, pData, DataSize); + mote->Wiimote_ControlChannel(m_ConnectionHandle & 0x1, pHeader->CID, pData, DataSize); // Call Wiimote Plugin break; case HID_INTERRUPT_CHANNEL: ShowStatus(pData); - mote->Wiimote_InterruptChannel(rChannel.DCID, pData, DataSize); + mote->Wiimote_InterruptChannel(m_ConnectionHandle & 0x1, pHeader->CID, pData, DataSize); // Call Wiimote Plugin break; @@ -415,7 +414,7 @@ void CWII_IPC_HLE_WiiMote::ReceiveConnectionReq(u8 _Ident, u8* _pData, u32 _Size rChannel.SCID = pCommandConnectionReq->scid; rChannel.DCID = pCommandConnectionReq->scid; - INFO_LOG(WII_IPC_WIIMOTE, "[ACL] ReceiveConnectionRequest"); + INFO_LOG(WII_IPC_WIIMOTE, "[L2CAP] ReceiveConnectionRequest"); DEBUG_LOG(WII_IPC_WIIMOTE, " Ident: 0x%02x", _Ident); DEBUG_LOG(WII_IPC_WIIMOTE, " PSM: 0x%04x", rChannel.PSM); DEBUG_LOG(WII_IPC_WIIMOTE, " SCID: 0x%04x", rChannel.SCID); @@ -428,7 +427,7 @@ void CWII_IPC_HLE_WiiMote::ReceiveConnectionReq(u8 _Ident, u8* _pData, u32 _Size Rsp.result = 0x00; Rsp.status = 0x00; - INFO_LOG(WII_IPC_WIIMOTE, "[ACL] SendConnectionResponse"); + INFO_LOG(WII_IPC_WIIMOTE, "[L2CAP] SendConnectionResponse"); SendCommandToACL(_Ident, L2CAP_CONN_RSP, sizeof(SL2CAP_ConnectionResponse), (u8*)&Rsp); } @@ -438,7 +437,7 @@ void CWII_IPC_HLE_WiiMote::ReceiveConnectionResponse(u8 _Ident, u8* _pData, u32 _dbg_assert_(WII_IPC_WIIMOTE, _Size == sizeof(l2cap_conn_rsp)); - INFO_LOG(WII_IPC_WIIMOTE, "[ACL] ReceiveConnectionResponse"); + INFO_LOG(WII_IPC_WIIMOTE, "[L2CAP] ReceiveConnectionResponse"); DEBUG_LOG(WII_IPC_WIIMOTE, " DCID: 0x%04x", rsp->dcid); DEBUG_LOG(WII_IPC_WIIMOTE, " SCID: 0x%04x", rsp->scid); DEBUG_LOG(WII_IPC_WIIMOTE, " Result: 0x%04x", rsp->result); @@ -476,7 +475,7 @@ void CWII_IPC_HLE_WiiMote::ReceiveConfigurationReq(u8 _Ident, u8* _pData, u32 _S SChannel& rChannel = m_Channel[pCommandConfigReq->dcid]; - INFO_LOG(WII_IPC_WIIMOTE, "[ACL] ReceiveConfigurationRequest"); + INFO_LOG(WII_IPC_WIIMOTE, "[L2CAP] ReceiveConfigurationRequest"); DEBUG_LOG(WII_IPC_WIIMOTE, " Ident: 0x%02x", _Ident); DEBUG_LOG(WII_IPC_WIIMOTE, " DCID: 0x%04x", pCommandConfigReq->dcid); DEBUG_LOG(WII_IPC_WIIMOTE, " Flags: 0x%04x", pCommandConfigReq->flags); @@ -506,7 +505,7 @@ void CWII_IPC_HLE_WiiMote::ReceiveConfigurationReq(u8 _Ident, u8* _pData, u32 _S _dbg_assert_(WII_IPC_WIIMOTE, pOptions->length == 2); SL2CAP_OptionsMTU* pMTU = (SL2CAP_OptionsMTU*)&_pData[Offset]; rChannel.MTU = pMTU->MTU; - DEBUG_LOG(WII_IPC_WIIMOTE, " Config MTU: 0x%04x", pMTU->MTU); + DEBUG_LOG(WII_IPC_WIIMOTE, " MTU: 0x%04x", pMTU->MTU); // AyuanX: My experiment shows that the MTU is always set to 640 bytes // This means that we only need temp_frame_size of 640B instead 1024B // Actually I've never seen a frame bigger than 64B @@ -519,7 +518,7 @@ void CWII_IPC_HLE_WiiMote::ReceiveConfigurationReq(u8 _Ident, u8* _pData, u32 _S _dbg_assert_(WII_IPC_WIIMOTE, pOptions->length == 2); SL2CAP_OptionsFlushTimeOut* pFlushTimeOut = (SL2CAP_OptionsFlushTimeOut*)&_pData[Offset]; rChannel.FlushTimeOut = pFlushTimeOut->TimeOut; - DEBUG_LOG(WII_IPC_WIIMOTE, " Config FlushTimeOut: 0x%04x", pFlushTimeOut->TimeOut); + DEBUG_LOG(WII_IPC_WIIMOTE, " FlushTimeOut: 0x%04x", pFlushTimeOut->TimeOut); } break; @@ -535,14 +534,13 @@ void CWII_IPC_HLE_WiiMote::ReceiveConfigurationReq(u8 _Ident, u8* _pData, u32 _S RespLen += OptionSize; } - INFO_LOG(WII_IPC_WIIMOTE, "[ACL] SendConfigurationResponse"); + INFO_LOG(WII_IPC_WIIMOTE, "[L2CAP] SendConfigurationResponse"); SendCommandToACL(_Ident, L2CAP_CONF_RSP, RespLen, TempBuffer); // update state machine if (rChannel.PSM == HID_CONTROL_CHANNEL) m_HIDControlChannel_Connected = true; - - if (rChannel.PSM == HID_INTERRUPT_CHANNEL) + else if (rChannel.PSM == HID_INTERRUPT_CHANNEL) m_HIDInterruptChannel_Connected = true; } @@ -551,9 +549,7 @@ void CWII_IPC_HLE_WiiMote::ReceiveConfigurationResponse(u8 _Ident, u8* _pData, u { l2cap_conf_rsp* rsp = (l2cap_conf_rsp*)_pData; - _dbg_assert_(WII_IPC_WIIMOTE, _Size == sizeof(l2cap_conf_rsp)); - - INFO_LOG(WII_IPC_WIIMOTE, "[ACL] ReceiveConfigurationResponse"); + INFO_LOG(WII_IPC_WIIMOTE, "[L2CAP] ReceiveConfigurationResponse"); DEBUG_LOG(WII_IPC_WIIMOTE, " SCID: 0x%04x", rsp->scid); DEBUG_LOG(WII_IPC_WIIMOTE, " Flags: 0x%04x", rsp->flags); DEBUG_LOG(WII_IPC_WIIMOTE, " Result: 0x%04x", rsp->result); @@ -564,30 +560,32 @@ void CWII_IPC_HLE_WiiMote::ReceiveConfigurationResponse(u8 _Ident, u8* _pData, u SChannel& rChannel = m_Channel[rsp->scid]; if (rChannel.PSM == HID_CONTROL_CHANNEL) + { m_HIDControlChannel_Config = true; - - if (rChannel.PSM == HID_INTERRUPT_CHANNEL) + INFO_LOG(WII_IPC_WIIMOTE, "Building HID_CONTROL_CHANNEL -- OK"); + } + else if (rChannel.PSM == HID_INTERRUPT_CHANNEL) + { m_HIDInterruptChannel_Config = true; - + INFO_LOG(WII_IPC_WIIMOTE, "Building HID_INTERRUPT_CHANNEL -- OK"); + } } void CWII_IPC_HLE_WiiMote::ReceiveDisconnectionReq(u8 _Ident, u8* _pData, u32 _Size) { SL2CAP_CommandDisconnectionReq* pCommandDisconnectionReq = (SL2CAP_CommandDisconnectionReq*)_pData; - _dbg_assert_(WII_IPC_WIIMOTE, m_Channel.find(pCommandDisconnectionReq->scid) != m_Channel.end()); - - INFO_LOG(WII_IPC_WIIMOTE, "[ACL] ReceiveDisconnectionReq"); + INFO_LOG(WII_IPC_WIIMOTE, "[L2CAP] ReceiveDisconnectionReq"); DEBUG_LOG(WII_IPC_WIIMOTE, " Ident: 0x%02x", _Ident); - DEBUG_LOG(WII_IPC_WIIMOTE, " SCID: 0x%04x", pCommandDisconnectionReq->dcid); - DEBUG_LOG(WII_IPC_WIIMOTE, " DCID: 0x%04x", pCommandDisconnectionReq->scid); + DEBUG_LOG(WII_IPC_WIIMOTE, " DCID: 0x%04x", pCommandDisconnectionReq->dcid); + DEBUG_LOG(WII_IPC_WIIMOTE, " SCID: 0x%04x", pCommandDisconnectionReq->scid); // response SL2CAP_CommandDisconnectionResponse Rsp; - Rsp.scid = pCommandDisconnectionReq->scid; Rsp.dcid = pCommandDisconnectionReq->dcid; + Rsp.scid = pCommandDisconnectionReq->scid; - INFO_LOG(WII_IPC_WIIMOTE, "[ACL] SendDisconnectionResponse"); + INFO_LOG(WII_IPC_WIIMOTE, "[L2CAP] SendDisconnectionResponse"); SendCommandToACL(_Ident, L2CAP_DISCONN_RSP, sizeof(SL2CAP_CommandDisconnectionResponse), (u8*)&Rsp); } @@ -614,7 +612,8 @@ void CWII_IPC_HLE_WiiMote::SendConnectionRequest(u16 scid, u16 psm) cr.psm = psm; cr.scid = scid; - INFO_LOG(WII_IPC_WIIMOTE, "[ACL] SendConnectionRequest"); + INFO_LOG(WII_IPC_WIIMOTE, "-------------------------------------"); + INFO_LOG(WII_IPC_WIIMOTE, "[L2CAP] SendConnectionRequest"); DEBUG_LOG(WII_IPC_WIIMOTE, " Psm: 0x%04x", cr.psm); DEBUG_LOG(WII_IPC_WIIMOTE, " Scid: 0x%04x", cr.scid); @@ -631,14 +630,14 @@ void CWII_IPC_HLE_WiiMote::SendDisconnectRequest(u16 scid) cr.dcid = rChannel.DCID; cr.scid = rChannel.SCID; - INFO_LOG(WII_IPC_WIIMOTE, "[ACL] SendDisconnectionRequest"); + INFO_LOG(WII_IPC_WIIMOTE, "[L2CAP] SendDisconnectionRequest"); DEBUG_LOG(WII_IPC_WIIMOTE, " Dcid: 0x%04x", cr.dcid); DEBUG_LOG(WII_IPC_WIIMOTE, " Scid: 0x%04x", cr.scid); SendCommandToACL(L2CAP_DISCONN_REQ, L2CAP_DISCONN_REQ, sizeof(l2cap_disconn_req), (u8*)&cr); } -void CWII_IPC_HLE_WiiMote::SendConfigurationRequest(u16 scid, u16* MTU, u16* FlushTimeOut) +void CWII_IPC_HLE_WiiMote::SendConfigurationRequest(u16 scid, u16 MTU, u16 FlushTimeOut) { _dbg_assert_(WII_IPC_WIIMOTE, DoesChannelExist(scid)); SChannel& rChannel = m_Channel[scid]; @@ -651,31 +650,29 @@ void CWII_IPC_HLE_WiiMote::SendConfigurationRequest(u16 scid, u16* MTU, u16* Flu cr->flags = 0; Offset += sizeof(l2cap_conf_req); - if (MTU != NULL) - { - SL2CAP_Options* pOptions = (SL2CAP_Options*)&Buffer[Offset]; - Offset += sizeof(SL2CAP_Options); + SL2CAP_Options* pOptions; - pOptions->type = 1; - pOptions->length = 2; + if (MTU == NULL) MTU = rChannel.MTU; + pOptions = (SL2CAP_Options*)&Buffer[Offset]; + Offset += sizeof(SL2CAP_Options); + pOptions->type = 1; + pOptions->length = 2; + *(u16*)&Buffer[Offset] = MTU; + Offset += 2; - *(u16*)&Buffer[Offset] = *MTU; Offset += 2; - } + if (FlushTimeOut == NULL) FlushTimeOut = rChannel.FlushTimeOut; + pOptions = (SL2CAP_Options*)&Buffer[Offset]; + Offset += sizeof(SL2CAP_Options); + pOptions->type = 2; + pOptions->length = 2; + *(u16*)&Buffer[Offset] = FlushTimeOut; + Offset += 2; - if (FlushTimeOut != NULL) - { - SL2CAP_Options* pOptions = (SL2CAP_Options*)&Buffer[Offset]; - Offset += sizeof(SL2CAP_Options); - - pOptions->type = 2; - pOptions->length = 2; - - *(u16*)&Buffer[Offset] = *FlushTimeOut; Offset += 2; - } - - INFO_LOG(WII_IPC_WIIMOTE, "[ACL] SendConfigurationRequest"); + INFO_LOG(WII_IPC_WIIMOTE, "[L2CAP] SendConfigurationRequest"); DEBUG_LOG(WII_IPC_WIIMOTE, " Dcid: 0x%04x", cr->dcid); DEBUG_LOG(WII_IPC_WIIMOTE, " Flags: 0x%04x", cr->flags); + DEBUG_LOG(WII_IPC_WIIMOTE, " MTU: 0x%04x", MTU); + DEBUG_LOG(WII_IPC_WIIMOTE, " FlushTimeOut: 0x%04x", FlushTimeOut); SendCommandToACL(L2CAP_CONF_REQ, L2CAP_CONF_REQ, Offset, Buffer); } @@ -885,17 +882,17 @@ void CWII_IPC_HLE_WiiMote::SendCommandToACL(u8 _Ident, u8 _Code, u8 _CommandLeng u32 Offset = 0; SL2CAP_Header* pHeader = (SL2CAP_Header*)&DataFrame[Offset]; Offset += sizeof(SL2CAP_Header); - pHeader->CID = 0x0001; pHeader->Length = sizeof(SL2CAP_Command) + _CommandLength; + pHeader->CID = 0x0001; SL2CAP_Command* pCommand = (SL2CAP_Command*)&DataFrame[Offset]; Offset += sizeof(SL2CAP_Command); - pCommand->len = _CommandLength; - pCommand->ident = _Ident; pCommand->code = _Code; + pCommand->ident = _Ident; + pCommand->len = _CommandLength; memcpy(&DataFrame[Offset], _pCommandData, _CommandLength); - DEBUG_LOG(WII_IPC_WIIMOTE, " SendCommandToACL (to CPU)"); + INFO_LOG(WII_IPC_WIIMOTE, "Send ACL Command to CPU"); DEBUG_LOG(WII_IPC_WIIMOTE, " Ident: 0x%02x", _Ident); DEBUG_LOG(WII_IPC_WIIMOTE, " Code: 0x%02x", _Code); @@ -944,16 +941,16 @@ namespace Core { /* This is called continuously from the Wiimote plugin as soon as it has received a reporting mode. _Size is the byte size of the report. */ - void Callback_WiimoteInput(u16 _channelID, const void* _pData, u32 _Size) + void Callback_WiimoteInput(int _number, u16 _channelID, const void* _pData, u32 _Size) { - DEBUG_LOG(WII_IPC_WIIMOTE, "========================================================="); const u8* pData = (const u8*)_pData; - DEBUG_LOG(WII_IPC_WIIMOTE, "Callback_WiimoteInput:"); - DEBUG_LOG(WII_IPC_WIIMOTE, " Data: %s", ArrayToString(pData, _Size, 0, 50).c_str()); - DEBUG_LOG(WII_IPC_WIIMOTE, " Channel: %u", _channelID); - s_Usb->m_WiiMotes[0].ReceiveL2capData(_channelID, _pData, _Size); - DEBUG_LOG(WII_IPC_WIIMOTE, "========================================================="); + INFO_LOG(WIIMOTE, "=========================="); + INFO_LOG(WIIMOTE, "Callback_WiimoteInput: (Page: %i)", _number); + DEBUG_LOG(WIIMOTE, " Data: %s", ArrayToString(pData, _Size, 0, 50).c_str()); + DEBUG_LOG(WIIMOTE, " Channel: %u", _channelID); + + s_Usb->m_WiiMotes[_number].ReceiveL2capData(_channelID, _pData, _Size); } } diff --git a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_WiiMote.h b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_WiiMote.h index 84bbbfc1c8..f577369854 100644 --- a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_WiiMote.h +++ b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_WiiMote.h @@ -183,7 +183,7 @@ class CWII_IPC_HLE_WiiMote { public: - CWII_IPC_HLE_WiiMote(CWII_IPC_HLE_Device_usb_oh1_57e_305* _pHost, int _Number); + CWII_IPC_HLE_WiiMote(CWII_IPC_HLE_Device_usb_oh1_57e_305* _pHost, int _Number, bool ready = false); virtual ~CWII_IPC_HLE_WiiMote() {} @@ -193,7 +193,9 @@ public: // we really have to clean all this code bool LinkChannel(); - bool IsConnected() const { return m_Connected; } + void ResetChannels(); + void Activate(bool ready); + bool IsConnected() const { return (m_Connected > 0) ? true : false; } bool IsLinked() const { return m_Linked; } void ShowStatus(const void* _pData); // Show status void UpdateStatus(); // Update status @@ -203,11 +205,10 @@ public: void EventConnectionAccepted(); void EventDisconnect(); bool EventPagingChanged(u8 _pageMode); - void EventCommandWriteLinkPolicy(); const bdaddr_t& GetBD() const { return m_BD; } const uint8_t* GetClass() const { return uclass; } - u16 GetConnectionHandle() const { return m_ControllerConnectionHandle; } + u16 GetConnectionHandle() const { return m_ConnectionHandle; } const u8* GetFeatures() const { return features; } const char* GetName() const { return m_Name.c_str(); } u8 GetLMPVersion() const { return lmp_version; } @@ -218,7 +219,7 @@ public: private: // state machine - bool m_Connected; + int m_Connected; // 0: ready, -1: inactive/connecting, 1: connected bool m_Linked; bool m_HIDControlChannel_Connected; bool m_HIDControlChannel_ConnectedWait; @@ -231,7 +232,7 @@ private: // STATE_TO_SAVE bdaddr_t m_BD; - u16 m_ControllerConnectionHandle; + u16 m_ConnectionHandle; uint8_t uclass[HCI_CLASS_SIZE]; u8 features[HCI_FEATURES_SIZE]; u8 lmp_version; @@ -263,7 +264,7 @@ private: void SignalChannel(u8* _pData, u32 _Size); void SendConnectionRequest(u16 _SCID, u16 _PSM); - void SendConfigurationRequest(u16 _SCID, u16* _pMTU = NULL, u16* _pFlushTimeOut = NULL); + void SendConfigurationRequest(u16 _SCID, u16 _pMTU = NULL, u16 _pFlushTimeOut = NULL); void SendDisconnectRequest(u16 _SCID); void ReceiveConnectionReq(u8 _Ident, u8* _pData, u32 _Size); diff --git a/Source/Core/DolphinWX/Src/ConfigMain.cpp b/Source/Core/DolphinWX/Src/ConfigMain.cpp index 05abca1ae8..6fa5400997 100644 --- a/Source/Core/DolphinWX/Src/ConfigMain.cpp +++ b/Source/Core/DolphinWX/Src/ConfigMain.cpp @@ -286,7 +286,7 @@ void CConfigMain::CreateGUIControls() wxT("\nIt can be convenient in a Wii game that already has a cursor.")); WiimoteStatusLEDs->SetToolTip(wxT("Show which wiimotes are connected in the statusbar.")); WiimoteStatusSpeakers->SetToolTip(wxT("Show wiimote speaker status in the statusbar.")); - DSPThread->SetToolTip(wxT("Run DSPLLE on a dedicate thread, this has no affect on DSPHLE.")); + DSPThread->SetToolTip(wxT("Run DSPLLE on a dedicate thread, this has no effects on DSPHLE.")); CPUThread->SetToolTip(wxT("This splits the Video and CPU threads, so they can be run on separate cores.") wxT("\nCauses major speed improvements on PCs with more than one core,") wxT("\nbut can also cause occasional crashes/glitches.")); diff --git a/Source/PluginSpecs/pluginspecs_wiimote.h b/Source/PluginSpecs/pluginspecs_wiimote.h index 2bc53a9666..fe173ae000 100644 --- a/Source/PluginSpecs/pluginspecs_wiimote.h +++ b/Source/PluginSpecs/pluginspecs_wiimote.h @@ -13,7 +13,7 @@ typedef void (*TLogv)(const char* _pMessage, int _v); // This is called when the Wiimote sends input reports to the Core. // Payload: an L2CAP packet. -typedef void (*TWiimoteInput)(u16 _channelID, const void* _pData, u32 _Size); +typedef void (*TWiimoteInput)(int _number, u16 _channelID, const void* _pData, u32 _Size); // This data is passed from the core on initialization. typedef struct @@ -35,7 +35,7 @@ typedef struct // input: Da pakket. // output: none // -EXPORT void CALL Wiimote_ControlChannel(u16 _channelID, const void* _pData, u32 _Size); +EXPORT void CALL Wiimote_ControlChannel(int _number, u16 _channelID, const void* _pData, u32 _Size); // __________________________________________________________________________________________________ // Function: Wiimote_Input @@ -44,7 +44,7 @@ EXPORT void CALL Wiimote_ControlChannel(u16 _channelID, const void* _pData, u32 // input: Da pakket. // output: none // -EXPORT void CALL Wiimote_InterruptChannel(u16 _channelID, const void* _pData, u32 _Size); +EXPORT void CALL Wiimote_InterruptChannel(int _number, u16 _channelID, const void* _pData, u32 _Size); // __________________________________________________________________________________________________ // Function: Wiimote_Update @@ -52,7 +52,7 @@ EXPORT void CALL Wiimote_InterruptChannel(u16 _channelID, const void* _pData, u3 // input: none // output: none // -EXPORT void CALL Wiimote_Update(); +EXPORT void CALL Wiimote_Update(int _number); // __________________________________________________________________________________________________ // Function: PAD_GetAttachedPads diff --git a/Source/Plugins/Plugin_Wiimote/Src/Config.cpp b/Source/Plugins/Plugin_Wiimote/Src/Config.cpp index 4d1c1ab06f..786648d803 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/Config.cpp +++ b/Source/Plugins/Plugin_Wiimote/Src/Config.cpp @@ -21,7 +21,7 @@ #include "Common.h" #include "IniFile.h" #include "StringUtil.h" - +#include "wiimote_hid.h" #include "Config.h" #include "EmuDefinitions.h" // for PadMapping #include "main.h" @@ -293,7 +293,7 @@ void Config::Load(bool ChangePad) iniFile.Get("Real", "AccNunNeutralY", &iAccNunNeutralY, 0); iniFile.Get("Real", "AccNunNeutralZ", &iAccNunNeutralZ, 0); - for (int i = 0; i < 1; i++) // Only got 1 wiimote yet + for (int i = 0; i < MAX_WIIMOTES; i++) { // Slot specific settings char SectionName[32]; @@ -404,7 +404,7 @@ void Config::Save(int Slot) iniFile.Set("Real", "AccNunNeutralY", iAccNunNeutralY); iniFile.Set("Real", "AccNunNeutralZ", iAccNunNeutralZ); - for (int i = 0; i < 1; i++) // Only got 1 wiimote yet + for (int i = 0; i < MAX_WIIMOTES; i++) { // Slot specific settings char SectionName[32]; diff --git a/Source/Plugins/Plugin_Wiimote/Src/ConfigPadDlg.cpp b/Source/Plugins/Plugin_Wiimote/Src/ConfigPadDlg.cpp index 1a855fc409..ef8358a7a1 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/ConfigPadDlg.cpp +++ b/Source/Plugins/Plugin_Wiimote/Src/ConfigPadDlg.cpp @@ -261,7 +261,7 @@ void WiimotePadConfigDialog::DoSave(bool ChangePad, int Slot) if(ChangePad) { // Since we are selecting the pad to save to by the Id we can't update it when we change the pad - for(int i = 0; i < 1; i++) // Only got 1 wiimote yet + for(int i = 0; i < MAX_WIIMOTES; i++) SaveButtonMapping(i, true); // Save the settings for the current pad // g_Config.Save(Slot); @@ -271,7 +271,7 @@ void WiimotePadConfigDialog::DoSave(bool ChangePad, int Slot) else { // Update PadMapping[] from the GUI controls - for(int i = 0; i < 1; i++) // Only got 1 wiimote yet + for(int i = 0; i < MAX_WIIMOTES; i++) SaveButtonMapping(i); // g_Config.Save(Slot); } diff --git a/Source/Plugins/Plugin_Wiimote/Src/DataReports.cpp b/Source/Plugins/Plugin_Wiimote/Src/DataReports.cpp index f42b547b32..48c05f5faa 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/DataReports.cpp +++ b/Source/Plugins/Plugin_Wiimote/Src/DataReports.cpp @@ -77,7 +77,7 @@ void WmReportMode(u16 _channelID, wm_report_mode* dr) DEBUG_LOG(WIIMOTE, " All The Time: %x (not only on data change)", dr->all_the_time); DEBUG_LOG(WIIMOTE, " Mode: 0x%02x", dr->mode); - g_ReportingAuto = dr->all_the_time; + g_ReportingAuto[g_RefreshWiimote] = dr->all_the_time; g_ReportingMode = dr->mode; g_ReportingChannel = _channelID; @@ -114,8 +114,7 @@ void SendReportCore(u16 _channelID) DEBUG_LOG(WIIMOTE, " Channel: %04x", _channelID); DEBUG_LOG(WIIMOTE, " Size: %08x", Offset); - g_WiimoteInitialize.pWiimoteInput(_channelID, DataFrame, Offset); - + g_WiimoteInitialize.pWiimoteInput(g_RefreshWiimote, _channelID, DataFrame, Offset); // Debugging //ReadDebugging(true, DataFrame, Offset); } @@ -140,7 +139,7 @@ void SendReportCoreAccel(u16 _channelID) DEBUG_LOG(WIIMOTE, " Channel: %04x", _channelID); DEBUG_LOG(WIIMOTE, " Size: %08x", Offset); - g_WiimoteInitialize.pWiimoteInput(_channelID, DataFrame, Offset); + g_WiimoteInitialize.pWiimoteInput(g_RefreshWiimote, _channelID, DataFrame, Offset); // Debugging //ReadDebugging(true, DataFrame, Offset); @@ -170,7 +169,7 @@ void SendReportCoreAccelIr12(u16 _channelID) { DEBUG_LOG(WIIMOTE, " Channel: %04x", _channelID); DEBUG_LOG(WIIMOTE, " Size: %08x", Offset); - g_WiimoteInitialize.pWiimoteInput(_channelID, DataFrame, Offset); + g_WiimoteInitialize.pWiimoteInput(g_RefreshWiimote, _channelID, DataFrame, Offset); // Debugging //ReadDebugging(true, DataFrame, Offset); @@ -215,7 +214,7 @@ void SendReportCoreAccelExt16(u16 _channelID) DEBUG_LOG(WIIMOTE, " Channel: %04x", _channelID); DEBUG_LOG(WIIMOTE, " Size: %08x", Offset); - g_WiimoteInitialize.pWiimoteInput(_channelID, DataFrame, Offset); + g_WiimoteInitialize.pWiimoteInput(g_RefreshWiimote, _channelID, DataFrame, Offset); // Debugging //ReadDebugging(true, DataFrame, Offset); @@ -269,7 +268,7 @@ void SendReportCoreAccelIr10Ext(u16 _channelID) DEBUG_LOG(WIIMOTE, " Channel: %04x", _channelID); DEBUG_LOG(WIIMOTE, " Size: %08x", Offset); - g_WiimoteInitialize.pWiimoteInput(_channelID, DataFrame, Offset); + g_WiimoteInitialize.pWiimoteInput(g_RefreshWiimote, _channelID, DataFrame, Offset); // Debugging //ReadDebugging(true, DataFrame, Offset); diff --git a/Source/Plugins/Plugin_Wiimote/Src/EmuDefinitions.cpp b/Source/Plugins/Plugin_Wiimote/Src/EmuDefinitions.cpp index 3aa4e294fb..509f17c5e9 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/EmuDefinitions.cpp +++ b/Source/Plugins/Plugin_Wiimote/Src/EmuDefinitions.cpp @@ -36,7 +36,7 @@ namespace WiiMoteEmu // Definitions and variable declarations //****************************************************************************** -u8 g_Leds; +u8 g_Leds[4]; u8 g_Speaker; u8 g_SpeakerVoice; u8 g_IR; @@ -48,7 +48,8 @@ u8 g_RegExt[WIIMOTE_REG_EXT_SIZE]; u8 g_RegExtTmp[WIIMOTE_REG_EXT_SIZE]; u8 g_RegIr[WIIMOTE_REG_IR_SIZE]; -bool g_ReportingAuto; // Auto report or passive report +int g_RefreshWiimote; // Current refreshing Wiimote +bool g_ReportingAuto[4]; // Auto report or passive report u8 g_ReportingMode; // The reporting mode and channel id u16 g_ReportingChannel; @@ -69,6 +70,7 @@ KeyboardNunchuck g_NunchuckExt; KeyboardClassicController g_ClassicContExt; KeyboardGH3GLP g_GH3Ext; bool KeyStatus[64]; +SWiimoteData g_WiimoteData[4]; } // namespace #endif //_EMU_DECLARATIONS_ diff --git a/Source/Plugins/Plugin_Wiimote/Src/EmuDefinitions.h b/Source/Plugins/Plugin_Wiimote/Src/EmuDefinitions.h index ca5e864131..3c88fc9288 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/EmuDefinitions.h +++ b/Source/Plugins/Plugin_Wiimote/Src/EmuDefinitions.h @@ -68,7 +68,7 @@ extern double g_RecordingCurrentTime[3]; #define WIIMOTE_REG_EXT_SIZE 0x100 #define WIIMOTE_REG_IR_SIZE 0x34 -extern u8 g_Leds; +extern u8 g_Leds[4]; extern u8 g_Speaker; extern u8 g_SpeakerVoice; extern u8 g_IR; @@ -80,7 +80,8 @@ extern u8 g_RegExt[WIIMOTE_REG_EXT_SIZE]; extern u8 g_RegExtTmp[WIIMOTE_REG_EXT_SIZE]; extern u8 g_RegIr[WIIMOTE_REG_IR_SIZE]; -extern bool g_ReportingAuto; +extern int g_RefreshWiimote; +extern bool g_ReportingAuto[4]; extern u8 g_ReportingMode; extern u16 g_ReportingChannel; @@ -187,6 +188,14 @@ struct STiltData } }; +struct SWiimoteData +{ + // Raw X and Y coordinate and processed X and Y coordinates + SIR IR; + STiltData TiltWM; + STiltData TiltNC; +}; +extern SWiimoteData g_WiimoteData[4]; // Keyboard input struct KeyboardWiimote @@ -204,10 +213,6 @@ struct KeyboardWiimote MA, MB, LAST_CONSTANT }; - - // Raw X and Y coordinate and processed X and Y coordinates - SIR IR; - STiltData TiltData; }; extern KeyboardWiimote g_Wiimote_kbd; @@ -215,12 +220,7 @@ struct KeyboardNunchuck { enum EKeyboardNunchuck { - // This is not allowed in Linux so we have to set the starting value manually - #ifdef _WIN32 - Z = g_Wiimote_kbd.LAST_CONSTANT, - #else - Z = 18, - #endif + Z = 18, C, L, R, U, D, ROLL_L, ROLL_R, @@ -228,8 +228,6 @@ struct KeyboardNunchuck SHAKE, LAST_CONSTANT }; - - STiltData TiltData; }; extern KeyboardNunchuck g_NunchuckExt; @@ -237,12 +235,7 @@ struct KeyboardClassicController { enum EKeyboardClassicController { - // This is not allowed in Linux so we have to set the starting value manually - #ifdef _WIN32 - A = g_NunchuckExt.LAST_CONSTANT, - #else - A = 29, - #endif + A = 29, B, X, Y, P, M, H, Tl, Tr, Zl, Zr, @@ -258,12 +251,7 @@ struct KeyboardGH3GLP { enum EKeyboardGH3GLP { - // This is not allowed in Linux so we have to set the starting value manually - #ifdef _WIN32 - Green = g_ClassicContExt.LAST_CONSTANT, - #else - Green = 52, - #endif + Green = 52, Red, Yellow, Blue, Orange, Plus, Minus, Whammy, Al, Ar, Au, Ad, diff --git a/Source/Plugins/Plugin_Wiimote/Src/EmuDynamics.cpp b/Source/Plugins/Plugin_Wiimote/Src/EmuDynamics.cpp index 54b5b79a4b..c45b21cfa8 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/EmuDynamics.cpp +++ b/Source/Plugins/Plugin_Wiimote/Src/EmuDynamics.cpp @@ -243,6 +243,7 @@ void PitchAccelerometerToDegree(u8 _x, u8 _y, u8 _z, int &_Roll, int &_Pitch, in // IR data functions //****************************************************************************** +/* // Calculate dot positions from the basic 10 byte IR data void IRData2DotsBasic(u8 *Data) { @@ -260,7 +261,7 @@ void IRData2DotsBasic(u8 *Data) Dot[3].Rx = 1023 - (Data[8] | ((Data[7] & 0x03) << 8)); Dot[3].Ry = Data[9] | ((Data[7] & 0x0c) << 6); - /* set each IR spot to visible if spot is in range */ + // set each IR spot to visible if spot is in range for (int i = 0; i < 4; ++i) { if (Dot[i].Ry == 1023) @@ -270,7 +271,7 @@ void IRData2DotsBasic(u8 *Data) else { Dot[i].Visible = 1; - Dot[i].Size = 0; /* since we don't know the size, set it as 0 */ + Dot[i].Size = 0; // since we don't know the size, set it as 0 } // For now we let our virtual resolution be the same as the default one @@ -281,8 +282,9 @@ void IRData2DotsBasic(u8 *Data) ReorderIRDots(); IRData2Distance(); } +*/ - +/* // Calculate dot positions from the extented 12 byte IR data void IRData2Dots(u8 *Data) { @@ -297,7 +299,7 @@ void IRData2Dots(u8 *Data) Dot[i].Size = Data[(3*i)+2] & 0x0f; - /* if in range set to visible */ + // if in range set to visible if (Dot[i].Ry == 1023) Dot[i].Visible = false; else @@ -313,8 +315,9 @@ void IRData2Dots(u8 *Data) ReorderIRDots(); IRData2Distance(); } +*/ - +/* // Reorder the IR dots according to their x-axis value void ReorderIRDots() { @@ -347,8 +350,9 @@ void ReorderIRDots() Dot[i].Order = order; } } +*/ - +/* // Calculate dot positions from the extented 12 byte IR data void IRData2Distance() { @@ -371,15 +375,15 @@ void IRData2Distance() // Only one dot was visible, we can not calculate the distance if (i2 == 4) { g_Wiimote_kbd.IR.Distance = 0; return; } - /* For the emulated Wiimote the y distance is always zero so then the distance is the - simple distance between the x dots, i.e. the sensor bar width */ + // For the emulated Wiimote the y distance is always zero so then the distance is the + // simple distance between the x dots, i.e. the sensor bar width int xd = Dot[i2].X - Dot[i1].X; int yd = Dot[i2].Y - Dot[i1].Y; // Save the distance g_Wiimote_kbd.IR.Distance = (int)sqrt((float)(xd*xd) + (float)(yd*yd)); } - +*/ //****************************************************************************** // Classic Controller functions diff --git a/Source/Plugins/Plugin_Wiimote/Src/EmuMain.cpp b/Source/Plugins/Plugin_Wiimote/Src/EmuMain.cpp index be7b63ef61..9a8d51ab59 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/EmuMain.cpp +++ b/Source/Plugins/Plugin_Wiimote/Src/EmuMain.cpp @@ -374,11 +374,17 @@ void ExtensionChecksum(u8 * Calibration) // Set initial valuesm this done both in Init and Shutdown void ResetVariables() { - g_ReportingAuto = false; + g_RefreshWiimote = 0; g_ReportingMode = 0; g_ReportingChannel = 0; g_Encryption = false; + for (int i = 0; i < 4; i++) + { + g_ReportingAuto[i] = false; + memset(&g_WiimoteData[i], 0, sizeof(g_WiimoteData)); + } + // Set default recording values #if defined(HAVE_WX) && HAVE_WX for (int i = 0; i < 3; i++) @@ -469,7 +475,6 @@ void Initialize() void DoState(PointerWrap &p) { // TODO: Shorten the list - p.Do(g_Leds); p.Do(g_Speaker); p.Do(g_SpeakerVoice); p.Do(g_IR); @@ -480,7 +485,6 @@ void DoState(PointerWrap &p) p.DoArray(g_RegExtTmp, WIIMOTE_REG_EXT_SIZE); p.DoArray(g_RegIr, WIIMOTE_REG_IR_SIZE); - p.Do(g_ReportingAuto); p.Do(g_ReportingMode); p.Do(g_ReportingChannel); @@ -492,10 +496,16 @@ void DoState(PointerWrap &p) //p.Do(joyinfo); //p.DoArray(PadState, 4); //p.DoArray(PadMapping, 4); - //p.Do(g_Wiimote_kbd); //p.Do(g_NunchuckExt); //p.Do(g_ClassicContExt); + + for (int i = 0; i < 4; i++) + { + p.Do(g_ReportingAuto[i]); + p.Do(g_Leds[i]); + p.Do(g_WiimoteData[i]); + } return; } @@ -515,8 +525,9 @@ void Shutdown() /* This function produce Wiimote Input, i.e. reports from the Wiimote in response to Output from the Wii. */ -void InterruptChannel(u16 _channelID, const void* _pData, u32 _Size) +void InterruptChannel(int _number, u16 _channelID, const void* _pData, u32 _Size) { + g_RefreshWiimote = _number; /* Debugging. We have not yet decided how much of 'data' we will use, it's not determined by sizeof(data). We have to determine it by looking at the data cases. */ @@ -524,7 +535,7 @@ void InterruptChannel(u16 _channelID, const void* _pData, u32 _Size) hid_packet* hidp = (hid_packet*)_pData; - INFO_LOG(WIIMOTE, "Emu InterruptChannel (type: 0x%02x, param: 0x%02x)", hidp->type, hidp->param); + INFO_LOG(WIIMOTE, "Emu InterruptChannel (page: %i, type: 0x%02x, param: 0x%02x)", _number, hidp->type, hidp->param); switch(hidp->type) { @@ -562,11 +573,13 @@ void InterruptChannel(u16 _channelID, const void* _pData, u32 _Size) } -void ControlChannel(u16 _channelID, const void* _pData, u32 _Size) +void ControlChannel(int _number, u16 _channelID, const void* _pData, u32 _Size) { + g_RefreshWiimote = _number; + hid_packet* hidp = (hid_packet*)_pData; - INFO_LOG(WIIMOTE, "Emu ControlChannel (type: 0x%02x, param: 0x%02x)", hidp->type, hidp->param); + INFO_LOG(WIIMOTE, "Emu ControlChannel (page: %i, type: 0x%02x, param: 0x%02x)", _number, hidp->type, hidp->param); switch(hidp->type) { @@ -586,7 +599,7 @@ void ControlChannel(u16 _channelID, const void* _pData, u32 _Size) // (TO_BE_VERIFIED) // u8 handshake = 0; - g_WiimoteInitialize.pWiimoteInput(_channelID, &handshake, 1); + g_WiimoteInitialize.pWiimoteInput(g_RefreshWiimote, _channelID, &handshake, 1); PanicAlert("HID_TYPE_DATA - OUTPUT: Ambiguous Control Channel Report!"); } @@ -608,13 +621,14 @@ void ControlChannel(u16 _channelID, const void* _pData, u32 _Size) documentation. I'm not sure exactly how often this function is called but I think it's tied to the frame rate of the game rather than a certain amount of times per second. */ -void Update() +void Update(int _number) { - if(g_ReportingAuto == false) + if (g_ReportingAuto[_number] == false) return; - // Read input or not + g_RefreshWiimote = _number; + // Read input or not if (g_Config.bInputActive) { ReadLinuxKeyboard(); @@ -626,9 +640,8 @@ void Update() && NumGoodPads > 0 && joyinfo.size() > (u32)PadMapping[0].ID) */ // Check if the pad state should be updated - const int Page = 0; - if (NumGoodPads > 0 && joyinfo.size() > (u32)PadMapping[Page].ID) - WiiMoteEmu::GetJoyState(PadState[Page], PadMapping[Page], Page, joyinfo[PadMapping[Page].ID].NumButtons); + if (NumGoodPads > 0 && joyinfo.size() > (u32)PadMapping[g_RefreshWiimote].ID) + WiiMoteEmu::GetJoyState(PadState[g_RefreshWiimote], PadMapping[g_RefreshWiimote], g_RefreshWiimote, joyinfo[PadMapping[g_RefreshWiimote].ID].NumButtons); } switch(g_ReportingMode) diff --git a/Source/Plugins/Plugin_Wiimote/Src/EmuMain.h b/Source/Plugins/Plugin_Wiimote/Src/EmuMain.h index 7ad4055a2d..a6b4ab3462 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/EmuMain.h +++ b/Source/Plugins/Plugin_Wiimote/Src/EmuMain.h @@ -38,9 +38,9 @@ void GetMousePos(float& x, float& y); void Initialize(); void DoState(PointerWrap &p); void Shutdown(); -void InterruptChannel(u16 _channelID, const void* _pData, u32 _Size); -void ControlChannel(u16 _channelID, const void* _pData, u32 _Size) ; -void Update(); +void InterruptChannel(int _number, u16 _channelID, const void* _pData, u32 _Size); +void ControlChannel(int _number, u16 _channelID, const void* _pData, u32 _Size) ; +void Update(int _number); void ReadLinuxKeyboard(); // Recordings @@ -68,8 +68,8 @@ void AdjustAngles(int &Roll, int &Pitch); void RotateIRDots(int &_x, int &_y, STiltData &_TiltData); void IRData2Dots(u8 *Data); void IRData2DotsBasic(u8 *Data); -void ReorderIRDots(); -void IRData2Distance(); +//void ReorderIRDots(); +//void IRData2Distance(); // Classic Controller data std::string CCData2Values(u8 *Data); diff --git a/Source/Plugins/Plugin_Wiimote/Src/EmuSubroutines.cpp b/Source/Plugins/Plugin_Wiimote/Src/EmuSubroutines.cpp index 78d22dc8a3..d0e1fe3523 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/EmuSubroutines.cpp +++ b/Source/Plugins/Plugin_Wiimote/Src/EmuSubroutines.cpp @@ -164,7 +164,7 @@ void WmLeds(u16 _channelID, wm_leds* leds) { INFO_LOG(WIIMOTE, "Set LEDs: %x, Rumble: %x", leds->leds, leds->rumble); - g_Leds = leds->leds; + g_Leds[g_RefreshWiimote] = leds->leds; } @@ -190,7 +190,7 @@ void WmSendAck(u16 _channelID, u8 _reportID) DEBUG_LOG(WIIMOTE, "WMSendAck"); DEBUG_LOG(WIIMOTE, " Report ID: %02x", _reportID); - g_WiimoteInitialize.pWiimoteInput(_channelID, DataFrame, Offset); + g_WiimoteInitialize.pWiimoteInput(g_RefreshWiimote, _channelID, DataFrame, Offset); // Debugging //ReadDebugging(true, DataFrame, Offset); @@ -360,11 +360,11 @@ void SendReadDataReply(u16 _channelID, void* _Base, u16 _Address, int _Size) #if defined(_DEBUG) || defined(DEBUGFAST) std::string Temp = ArrayToString(DataFrame, Offset); - ERROR_LOG(WIIMOTE, "Data: %s", Temp.c_str()); + DEBUG_LOG(WIIMOTE, "Data: %s", Temp.c_str()); #endif // Send a piece - g_WiimoteInitialize.pWiimoteInput(_channelID, DataFrame, Offset); + g_WiimoteInitialize.pWiimoteInput(g_RefreshWiimote, _channelID, DataFrame, Offset); // Update the size that is left _Size -= copySize; @@ -482,7 +482,7 @@ void WmRequestStatus(u16 _channelID, wm_request_status* rs, int Extension) #if defined(HAVE_WX) && HAVE_WX FillReportInfo(pStatus->buttons); #endif - pStatus->leds = g_Leds; // leds are 4 bit + pStatus->leds = g_Leds[g_RefreshWiimote]; // leds are 4 bit pStatus->ir = g_IR; // 1 bit pStatus->speaker = g_Speaker; // 1 bit pStatus->battery_low = 0; // battery is okay @@ -514,7 +514,7 @@ void WmRequestStatus(u16 _channelID, wm_request_status* rs, int Extension) DEBUG_LOG(WIIMOTE, " Extension: %x", pStatus->extension); DEBUG_LOG(WIIMOTE, " Buttons: 0x%04x", pStatus->buttons); - g_WiimoteInitialize.pWiimoteInput(_channelID, DataFrame, Offset); + g_WiimoteInitialize.pWiimoteInput(g_RefreshWiimote, _channelID, DataFrame, Offset); // Debugging //ReadDebugging(true, DataFrame, Offset); diff --git a/Source/Plugins/Plugin_Wiimote/Src/FillReport.cpp b/Source/Plugins/Plugin_Wiimote/Src/FillReport.cpp index e19c5baa0d..969b8afab6 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/FillReport.cpp +++ b/Source/Plugins/Plugin_Wiimote/Src/FillReport.cpp @@ -686,16 +686,16 @@ void TiltWiimote(int &_x, int &_y, int &_z) return; // Select input method and return the x, y, x values else if (g_Config.Tilt.TypeWM == g_Config.Tilt.KEYBOARD) - TiltByKeyboardWM(g_Wiimote_kbd.TiltData); + TiltByKeyboardWM(g_WiimoteData[g_RefreshWiimote].TiltWM); else - TiltByGamepad(g_Wiimote_kbd.TiltData, g_Config.Tilt.TypeWM); + TiltByGamepad(g_WiimoteData[g_RefreshWiimote].TiltWM, g_Config.Tilt.TypeWM); // Adjust angles, it's only needed if both roll and pitch is used together if (g_Config.Tilt.Range.Roll != 0 && g_Config.Tilt.Range.Pitch != 0) - AdjustAngles(g_Wiimote_kbd.TiltData.Roll, g_Wiimote_kbd.TiltData.Pitch); + AdjustAngles(g_WiimoteData[g_RefreshWiimote].TiltWM.Roll, g_WiimoteData[g_RefreshWiimote].TiltWM.Pitch); // Calculate the accelerometer value from this tilt angle - TiltToAccelerometer(_x, _y, _z, g_Wiimote_kbd.TiltData); + TiltToAccelerometer(_x, _y, _z, g_WiimoteData[g_RefreshWiimote].TiltWM); //DEBUG_LOG(WIIMOTE, "Roll:%i, Pitch:%i, _x:%u, _y:%u, _z:%u", g_Wiimote_kbd.TiltData.Roll, g_Wiimote_kbd.TiltData.Pitch, _x, _y, _z); } @@ -708,16 +708,16 @@ void TiltNunchuck(int &_x, int &_y, int &_z) return; // Select input method and return the x, y, x values else if (g_Config.Tilt.TypeNC == g_Config.Tilt.KEYBOARD) - TiltByKeyboardNC(g_NunchuckExt.TiltData); + TiltByKeyboardNC(g_WiimoteData[g_RefreshWiimote].TiltNC); else - TiltByGamepad(g_NunchuckExt.TiltData, g_Config.Tilt.TypeNC); + TiltByGamepad(g_WiimoteData[g_RefreshWiimote].TiltNC, g_Config.Tilt.TypeNC); // Adjust angles, it's only needed if both roll and pitch is used together if (g_Config.Tilt.Range.Roll != 0 && g_Config.Tilt.Range.Pitch != 0) - AdjustAngles(g_NunchuckExt.TiltData.Roll, g_NunchuckExt.TiltData.Pitch); + AdjustAngles(g_WiimoteData[g_RefreshWiimote].TiltNC.Roll, g_WiimoteData[g_RefreshWiimote].TiltNC.Pitch); // Calculate the accelerometer value from this tilt angle - TiltToAccelerometer(_x, _y, _z, g_NunchuckExt.TiltData); + TiltToAccelerometer(_x, _y, _z, g_WiimoteData[g_RefreshWiimote].TiltNC); //DEBUG_LOG(WIIMOTE, "Roll:%i, Pitch:%i, _x:%u, _y:%u, _z:%u", g_NunchuckExt.TiltData.Roll, g_NunchuckExt.TiltData.Pitch, _x, _y, _z); } @@ -745,11 +745,11 @@ void FillReportAcc(wm_accel& _acc) // Adjust position, also add some noise to prevent disconnection if (!g_Config.bUpright) - _acc.z += g_wm.cal_g.z + g_Wiimote_kbd.TiltData.FakeNoise; + _acc.z += g_wm.cal_g.z + g_WiimoteData[g_RefreshWiimote].TiltWM.FakeNoise; else // Upright wiimote - _acc.y -= g_wm.cal_g.y + g_Wiimote_kbd.TiltData.FakeNoise; + _acc.y -= g_wm.cal_g.y + g_WiimoteData[g_RefreshWiimote].TiltWM.FakeNoise; - g_Wiimote_kbd.TiltData.FakeNoise = -g_Wiimote_kbd.TiltData.FakeNoise; + g_WiimoteData[g_RefreshWiimote].TiltWM.FakeNoise = -g_WiimoteData[g_RefreshWiimote].TiltWM.FakeNoise; if (IsFocus()) { @@ -757,14 +757,14 @@ void FillReportAcc(wm_accel& _acc) int acc_y = _acc.y; int acc_z = _acc.z; - if (IsKey(g_Wiimote_kbd.SHAKE) && g_Wiimote_kbd.TiltData.Shake == 0) - g_Wiimote_kbd.TiltData.Shake = 1; + if (IsKey(g_Wiimote_kbd.SHAKE) && g_WiimoteData[g_RefreshWiimote].TiltWM.Shake == 0) + g_WiimoteData[g_RefreshWiimote].TiltWM.Shake = 1; // Step the shake simulation one step - ShakeToAccelerometer(acc_x, acc_y, acc_z, g_Wiimote_kbd.TiltData); + ShakeToAccelerometer(acc_x, acc_y, acc_z, g_WiimoteData[g_RefreshWiimote].TiltWM); // Tilt Wiimote, allow the shake function to interrupt it - if (g_Wiimote_kbd.TiltData.Shake == 0) + if (g_WiimoteData[g_RefreshWiimote].TiltWM.Shake == 0) TiltWiimote(acc_x, acc_y, acc_z); // Boundary check @@ -916,8 +916,8 @@ void FillReportIR(wm_ir_extended& _ir0, wm_ir_extended& _ir1) int x0 = 1023 - g_Config.iIRLeft - g_Config.iIRWidth * MouseX - SENSOR_BAR_WIDTH / 2; int x1 = x0 + SENSOR_BAR_WIDTH; - RotateIRDot(x0, y0, g_Wiimote_kbd.TiltData); - RotateIRDot(x1, y1, g_Wiimote_kbd.TiltData); + RotateIRDot(x0, y0, g_WiimoteData[g_RefreshWiimote].TiltWM); + RotateIRDot(x1, y1, g_WiimoteData[g_RefreshWiimote].TiltWM); // Converted to IR data _ir0.x = x0 & 0xff; _ir0.xHi = x0 >> 8; @@ -993,8 +993,8 @@ void FillReportIRBasic(wm_ir_basic& _ir0, wm_ir_basic& _ir1) int x1 = 1023 - g_Config.iIRLeft - g_Config.iIRWidth * MouseX - SENSOR_BAR_WIDTH / 2; int x2 = x1 + SENSOR_BAR_WIDTH; - RotateIRDot(x1, y1, g_Wiimote_kbd.TiltData); - RotateIRDot(x2, y2, g_Wiimote_kbd.TiltData); + RotateIRDot(x1, y1, g_WiimoteData[g_RefreshWiimote].TiltWM); + RotateIRDot(x2, y2, g_WiimoteData[g_RefreshWiimote].TiltWM); /* As with the extented report we settle with emulating two out of four possible objects the only difference is that we don't report any size of @@ -1082,14 +1082,14 @@ if (IsFocus()) int acc_y = _ext.ay; int acc_z = _ext.az; - if (IsKey(g_NunchuckExt.SHAKE) && g_NunchuckExt.TiltData.Shake == 0) - g_NunchuckExt.TiltData.Shake = 1; + if (IsKey(g_NunchuckExt.SHAKE) && g_WiimoteData[g_RefreshWiimote].TiltNC.Shake == 0) + g_WiimoteData[g_RefreshWiimote].TiltNC.Shake = 1; // Step the shake simulation one step - ShakeToAccelerometer(acc_x, acc_y, acc_z, g_NunchuckExt.TiltData); + ShakeToAccelerometer(acc_x, acc_y, acc_z, g_WiimoteData[g_RefreshWiimote].TiltNC); // Tilt Nunchuck, allow the shake function to interrupt it - if (g_NunchuckExt.TiltData.Shake == 0) + if (g_WiimoteData[g_RefreshWiimote].TiltNC.Shake == 0) TiltNunchuck(acc_x, acc_y, acc_z); // Boundary check diff --git a/Source/Plugins/Plugin_Wiimote/Src/main.cpp b/Source/Plugins/Plugin_Wiimote/Src/main.cpp index d32f8e218b..29342177c3 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/main.cpp +++ b/Source/Plugins/Plugin_Wiimote/Src/main.cpp @@ -305,7 +305,7 @@ void DoState(unsigned char **ptr, int mode) Switch between real and emulated wiimote: We send all this Input to WiiMoteEmu::InterruptChannel() so that it knows the channel ID and the data reporting mode at all times. */ -void Wiimote_InterruptChannel(u16 _channelID, const void* _pData, u32 _Size) +void Wiimote_InterruptChannel(int _number, u16 _channelID, const void* _pData, u32 _Size) { const u8* data = (const u8*)_pData; @@ -319,17 +319,17 @@ void Wiimote_InterruptChannel(u16 _channelID, const void* _pData, u32 _Size) // Decice where to send the message if (!g_Config.bUseRealWiimote || !g_RealWiiMotePresent) - WiiMoteEmu::InterruptChannel(_channelID, _pData, _Size); + WiiMoteEmu::InterruptChannel(_number, _channelID, _pData, _Size); #if HAVE_WIIUSE else if (g_RealWiiMotePresent) - WiiMoteReal::InterruptChannel(_channelID, _pData, _Size); + WiiMoteReal::InterruptChannel(_channelID, _pData, _Size); // TODO: Multi-Wiimote #endif } // Function: Used for the initial Bluetooth HID handshake. -void Wiimote_ControlChannel(u16 _channelID, const void* _pData, u32 _Size) +void Wiimote_ControlChannel(int _number, u16 _channelID, const void* _pData, u32 _Size) { const u8* data = (const u8*)_pData; @@ -354,17 +354,17 @@ void Wiimote_ControlChannel(u16 _channelID, const void* _pData, u32 _Size) } if (!g_Config.bUseRealWiimote || !g_RealWiiMotePresent) - WiiMoteEmu::ControlChannel(_channelID, _pData, _Size); + WiiMoteEmu::ControlChannel(_number, _channelID, _pData, _Size); #if HAVE_WIIUSE else if (g_RealWiiMotePresent) - WiiMoteReal::ControlChannel(_channelID, _pData, _Size); + WiiMoteReal::ControlChannel(_channelID, _pData, _Size); // TODO: Multi-Wiimote #endif } /* This sends a Data Report from the Wiimote. See SystemTimers.cpp for the documentation of this update. */ -void Wiimote_Update() +void Wiimote_Update(int _number) { // Tell us about the update rate, but only about once every second to avoid a major slowdown #if defined(HAVE_WX) && HAVE_WX @@ -384,10 +384,10 @@ void Wiimote_Update() // Emulated Wiimote: Only data reports 0x30-0x37 // Real Wiimote: Both data reports 0x30-0x37 and all other read reports if (!g_Config.bUseRealWiimote || !g_RealWiiMotePresent) - WiiMoteEmu::Update(); + WiiMoteEmu::Update(_number); #if HAVE_WIIUSE else if (g_RealWiiMotePresent) - WiiMoteReal::Update(); + WiiMoteReal::Update(); // TODO: Multi-Wiimote #endif // Debugging @@ -445,7 +445,7 @@ void DisableExtensions() g_Config.iExtensionConnected = EXT_NONE; } - +/* void ReadDebugging(bool Emu, const void* _pData, int Size) { // @@ -484,8 +484,8 @@ void ReadDebugging(bool Emu, const void* _pData, int Size) //(pStatus->leds >> 3), pStatus->battery_low ); - /* Update the global (for both the real and emulated) extension settings from whatever - the real Wiimote use. We will enable the extension from the 0x21 report. */ + // Update the global (for both the real and emulated) extension settings from whatever + // the real Wiimote use. We will enable the extension from the 0x21 report. if(!Emu && !pStatus->extension) { DisableExtensions(); @@ -518,8 +518,8 @@ void ReadDebugging(bool Emu, const void* _pData, int Size) wiimote_decrypt(&WiiMoteEmu::g_ExtKey, &data[0x07], 0x02, (data[4] >> 0x04) + 1); } - /* Update the global extension settings. Enable the emulated extension from reading - what the real Wiimote has connected. To keep the emulated and real Wiimote in sync. */ + // Update the global extension settings. Enable the emulated extension from reading + // what the real Wiimote has connected. To keep the emulated and real Wiimote in sync. if(data[4] == 0x10) { if (!Emu) DisableExtensions(); @@ -553,9 +553,9 @@ void ReadDebugging(bool Emu, const void* _pData, int Size) } // Show the Wiimote neutral values - /* The only difference between the Nunchuck and Wiimote that we go - after is calibration here is the offset in memory. If needed we can - check the preceding 0x17 request to. */ + // The only difference between the Nunchuck and Wiimote that we go + // after is calibration here is the offset in memory. If needed we can + // check the preceding 0x17 request to. if(data[4] == 0xf0 && data[5] == 0x00 && data[6] == 0x10) { if(data[6] == 0x10) @@ -763,7 +763,6 @@ void ReadDebugging(bool Emu, const void* _pData, int Size) // --------------------------------------------- // Test the angles to x, y, z values formula by calculating the values back and forth // ----------- - /* ConsoleListener* Console = LogManager::GetInstance()->getConsoleListener(); Console->ClearScreen(); // Show a test of our calculations @@ -771,7 +770,7 @@ void ReadDebugging(bool Emu, const void* _pData, int Size) u8 x, y, z; //WiiMoteEmu::Tilt(x, y, z); //WiiMoteEmu::TiltTest(x, y, z); - */ + // ------------------------- // --------------------------------------------- @@ -825,7 +824,7 @@ void ReadDebugging(bool Emu, const void* _pData, int Size) DEBUG_LOG(WIIMOTE, "Accel x, y, z: %03u %03u %03u", data[4], data[5], data[6]); } } - +*/ void InterruptDebugging(bool Emu, const void* _pData) { diff --git a/Source/Plugins/Plugin_Wiimote/Src/wiimote_hid.h b/Source/Plugins/Plugin_Wiimote/Src/wiimote_hid.h index 8374e889a3..ba2debe2b7 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/wiimote_hid.h +++ b/Source/Plugins/Plugin_Wiimote/Src/wiimote_hid.h @@ -25,6 +25,8 @@ #endif #pragma pack(push, 1) +#define MAX_WIIMOTES 2 + // Source: HID_010_SPC_PFL/1.0 (official HID specification) struct hid_packet { diff --git a/Source/Plugins/Plugin_Wiimote/Src/wiimote_real.cpp b/Source/Plugins/Plugin_Wiimote/Src/wiimote_real.cpp index c3e0a84226..0f5c661126 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/wiimote_real.cpp +++ b/Source/Plugins/Plugin_Wiimote/Src/wiimote_real.cpp @@ -235,7 +235,7 @@ void SendEvent(SEvent& _rEvent) Offset += sizeof(_rEvent.m_PayLoad); // Send it - g_WiimoteInitialize.pWiimoteInput(m_channelID, Buffer, Offset); + g_WiimoteInitialize.pWiimoteInput(0, m_channelID, Buffer, Offset); // TODO: Multi-Wiimote // Debugging // ReadDebugging(false, Buffer, Offset); diff --git a/Source/Plugins/Plugin_Wiimote/Src/wiimote_real.h b/Source/Plugins/Plugin_Wiimote/Src/wiimote_real.h index d422785f5e..d3892a9fb9 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/wiimote_real.h +++ b/Source/Plugins/Plugin_Wiimote/Src/wiimote_real.h @@ -26,8 +26,6 @@ namespace WiiMoteReal { -#define MAX_WIIMOTES 1 - int Initialize(); void DoState(PointerWrap &p); void Shutdown(void); diff --git a/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigJoypad.cpp b/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigJoypad.cpp index 9b2f63db1c..7618da9385 100644 --- a/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigJoypad.cpp +++ b/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigJoypad.cpp @@ -119,6 +119,7 @@ void PADConfigDialognJoy::SaveButtonMapping(int controller, bool DontChangeId, i // Set other settings if(!DontChangeId) PadMapping[controller].ID = m_Joyname[FromSlot]->GetSelection(); + PadMapping[controller].enable = m_Enable[FromSlot]->IsChecked(); PadMapping[controller].controllertype = m_ControlType[FromSlot]->GetSelection(); PadMapping[controller].triggertype = m_TriggerType[FromSlot]->GetSelection(); PadMapping[controller].deadzone = m_Deadzone[FromSlot]->GetSelection(); diff --git a/Source/Plugins/Plugin_nJoy_SDL/Src/nJoy.cpp b/Source/Plugins/Plugin_nJoy_SDL/Src/nJoy.cpp index 8b009ccbe5..4c76165e38 100644 --- a/Source/Plugins/Plugin_nJoy_SDL/Src/nJoy.cpp +++ b/Source/Plugins/Plugin_nJoy_SDL/Src/nJoy.cpp @@ -259,6 +259,9 @@ void PAD_Input(u16 _Key, u8 _UpDown) // Check if the keys are interesting, and then update it for(int i = 0; i < 4; i++) { + if (!PadMapping[i].enable) + continue; + for(int j = InputCommon::CTL_L_SHOULDER; j <= InputCommon::CTL_START; j++) { if (PadMapping[i].buttons[j] == _Key) @@ -292,7 +295,7 @@ void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus) { // Check if the pad is avaliable, currently we don't disable pads just because they are // disconnected - if (!PadState[_numPAD].joy || !PadMapping[_numPAD].enable) + if (!PadState[_numPAD].joy) return; // Clear pad status