summaryrefslogtreecommitdiff
path: root/Source/Plugins
diff options
context:
space:
mode:
authorShawn Hoffman <godisgovernment@gmail.com>2009-11-24 05:03:47 +0000
committerShawn Hoffman <godisgovernment@gmail.com>2009-11-24 05:03:47 +0000
commit6a46befc2aa419a9c0527f52cdced3fd3adfae0e (patch)
treecfe27cde9462689abbe8275ab112c45ba8e469bf /Source/Plugins
parent55dc7efaa427f442bec4fa5cdbb7ad0ecba19082 (diff)
commit ayuanx's patch from issue 1634. Fixes quite a few IPC + IPC_HLE + IPC_HLE_USB + wiimote problems, see the issue for full details
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4606 8ced0084-cf51-0410-be5f-012b33b47a6e
Diffstat (limited to 'Source/Plugins')
-rw-r--r--Source/Plugins/Plugin_Wiimote/Src/DataReports.cpp64
-rw-r--r--Source/Plugins/Plugin_Wiimote/Src/EmuDefinitions.cpp1
-rw-r--r--Source/Plugins/Plugin_Wiimote/Src/EmuDefinitions.h1
-rw-r--r--Source/Plugins/Plugin_Wiimote/Src/EmuMain.cpp152
-rw-r--r--Source/Plugins/Plugin_Wiimote/Src/EmuSubroutines.cpp342
-rw-r--r--Source/Plugins/Plugin_Wiimote/Src/EmuSubroutines.h8
-rw-r--r--Source/Plugins/Plugin_Wiimote/Src/FillReport.cpp8
-rw-r--r--Source/Plugins/Plugin_Wiimote/Src/main.cpp30
-rw-r--r--Source/Plugins/Plugin_Wiimote/Src/wiimote_hid.h12
9 files changed, 257 insertions, 361 deletions
diff --git a/Source/Plugins/Plugin_Wiimote/Src/DataReports.cpp b/Source/Plugins/Plugin_Wiimote/Src/DataReports.cpp
index 5e0997a242..f42b547b32 100644
--- a/Source/Plugins/Plugin_Wiimote/Src/DataReports.cpp
+++ b/Source/Plugins/Plugin_Wiimote/Src/DataReports.cpp
@@ -37,7 +37,7 @@
Callback_WiimoteInput()
CWII_IPC_HLE_WiiMote::SendL2capData()
WII_IPC_HLE_Device_usb.cpp:
- CWII_IPC_HLE_Device_usb_oh1_57e_305::SendACLFrame()
+ CWII_IPC_HLE_Device_usb_oh1_57e_305::SendACLPacket()
at that point the message is queued and will be sent by the next
CWII_IPC_HLE_Device_usb_oh1_57e_305::Update()
*/
@@ -69,22 +69,20 @@ namespace WiiMoteEmu
// Update the data reporting mode
-void WmDataReporting(u16 _channelID, wm_data_reporting* dr)
+void WmReportMode(u16 _channelID, wm_report_mode* dr)
{
- DEBUG_LOG(WIIMOTE, " Set Data reporting mode");
+ INFO_LOG(WIIMOTE, "Set data report mode");
DEBUG_LOG(WIIMOTE, " Rumble: %x", dr->rumble);
DEBUG_LOG(WIIMOTE, " Continuous: %x", dr->continuous);
DEBUG_LOG(WIIMOTE, " All The Time: %x (not only on data change)", dr->all_the_time);
DEBUG_LOG(WIIMOTE, " Mode: 0x%02x", dr->mode);
- DEBUG_LOG(WIIMOTE, "Data reporting:");
- DEBUG_LOG(WIIMOTE, " Continuous: %x", dr->continuous);
- DEBUG_LOG(WIIMOTE, " All The Time: %x (not only on data change)", dr->all_the_time);
- DEBUG_LOG(WIIMOTE, " Mode: 0x%02x", dr->mode);
- DEBUG_LOG(WIIMOTE, " Channel: 0x%04x", _channelID);
-
+
+ g_ReportingAuto = dr->all_the_time;
g_ReportingMode = dr->mode;
g_ReportingChannel = _channelID;
- switch(dr->mode) // See Wiimote_Update()
+
+ // Validation check
+ switch(dr->mode)
{
case WM_REPORT_CORE:
case WM_REPORT_CORE_ACCEL:
@@ -95,9 +93,6 @@ void WmDataReporting(u16 _channelID, wm_data_reporting* dr)
default:
PanicAlert("Wiimote: Unsupported reporting mode 0x%x", dr->mode);
}
-
- // WmSendAck(_channelID, WM_DATA_REPORTING);
-
}
@@ -106,7 +101,7 @@ void WmDataReporting(u16 _channelID, wm_data_reporting* dr)
void SendReportCore(u16 _channelID)
{
u8 DataFrame[1024];
- u32 Offset = WriteWmReport(DataFrame, WM_REPORT_CORE);
+ u32 Offset = WriteWmReportHdr(DataFrame, WM_REPORT_CORE);
wm_report_core* pReport = (wm_report_core*)(DataFrame + Offset);
Offset += sizeof(wm_report_core);
@@ -115,12 +110,14 @@ void SendReportCore(u16 _channelID)
FillReportInfo(pReport->c);
#endif
- INFO_LOG(WIIMOTE, " SendReportCore()");
+ INFO_LOG(WIIMOTE, " SendReportCore(0x30)");
+ DEBUG_LOG(WIIMOTE, " Channel: %04x", _channelID);
+ DEBUG_LOG(WIIMOTE, " Size: %08x", Offset);
g_WiimoteInitialize.pWiimoteInput(_channelID, DataFrame, Offset);
// Debugging
- ReadDebugging(true, DataFrame, Offset);
+ //ReadDebugging(true, DataFrame, Offset);
}
@@ -128,7 +125,7 @@ void SendReportCore(u16 _channelID)
void SendReportCoreAccel(u16 _channelID)
{
u8 DataFrame[1024];
- u32 Offset = WriteWmReport(DataFrame, WM_REPORT_CORE_ACCEL);
+ u32 Offset = WriteWmReportHdr(DataFrame, WM_REPORT_CORE_ACCEL);
wm_report_core_accel* pReport = (wm_report_core_accel*)(DataFrame + Offset);
Offset += sizeof(wm_report_core_accel);
@@ -140,20 +137,20 @@ void SendReportCoreAccel(u16 _channelID)
#endif
INFO_LOG(WIIMOTE, " SendReportCoreAccel (0x31)");
- INFO_LOG(WIIMOTE, " Channel: %04x", _channelID);
- INFO_LOG(WIIMOTE, " Offset: %08x", Offset);
+ DEBUG_LOG(WIIMOTE, " Channel: %04x", _channelID);
+ DEBUG_LOG(WIIMOTE, " Size: %08x", Offset);
g_WiimoteInitialize.pWiimoteInput(_channelID, DataFrame, Offset);
// Debugging
- ReadDebugging(true, DataFrame, Offset);
+ //ReadDebugging(true, DataFrame, Offset);
}
/* Case 0x33: Core Buttons and Accelerometer with 12 IR bytes */
void SendReportCoreAccelIr12(u16 _channelID) {
u8 DataFrame[1024];
- u32 Offset = WriteWmReport(DataFrame, WM_REPORT_CORE_ACCEL_IR12);
+ u32 Offset = WriteWmReportHdr(DataFrame, WM_REPORT_CORE_ACCEL_IR12);
wm_report_core_accel_ir12* pReport = (wm_report_core_accel_ir12*)(DataFrame + Offset);
Offset += sizeof(wm_report_core_accel_ir12);
@@ -169,13 +166,14 @@ void SendReportCoreAccelIr12(u16 _channelID) {
memset(&pReport->ir[2], 0xff, sizeof(wm_ir_extended));
memset(&pReport->ir[3], 0xff, sizeof(wm_ir_extended));
- INFO_LOG(WIIMOTE, " SendReportCoreAccelIr12()");
- INFO_LOG(WIIMOTE, " Offset: %08x", Offset);
+ INFO_LOG(WIIMOTE, " SendReportCoreAccelIr12(0x33)");
+ DEBUG_LOG(WIIMOTE, " Channel: %04x", _channelID);
+ DEBUG_LOG(WIIMOTE, " Size: %08x", Offset);
g_WiimoteInitialize.pWiimoteInput(_channelID, DataFrame, Offset);
// Debugging
- ReadDebugging(true, DataFrame, Offset);
+ //ReadDebugging(true, DataFrame, Offset);
}
@@ -183,7 +181,7 @@ void SendReportCoreAccelIr12(u16 _channelID) {
void SendReportCoreAccelExt16(u16 _channelID)
{
u8 DataFrame[1024];
- u32 Offset = WriteWmReport(DataFrame, WM_REPORT_CORE_ACCEL_EXT16);
+ u32 Offset = WriteWmReportHdr(DataFrame, WM_REPORT_CORE_ACCEL_EXT16);
wm_report_core_accel_ext16* pReport = (wm_report_core_accel_ext16*)(DataFrame + Offset);
Offset += sizeof(wm_report_core_accel_ext16);
@@ -209,18 +207,18 @@ void SendReportCoreAccelExt16(u16 _channelID)
#if defined(HAVE_WX) && HAVE_WX
FillReportClassicExtension(_ext);
#endif
-//TODO // Copy _ext to pReport->ext
+ // Copy _ext to pReport->ext
memcpy(&pReport->ext, &_ext, sizeof(_ext));
}
INFO_LOG(WIIMOTE, " SendReportCoreAccelExt16 (0x35)");
- INFO_LOG(WIIMOTE, " Channel: %04x", _channelID);
- INFO_LOG(WIIMOTE, " Offset: %08x", Offset);
+ DEBUG_LOG(WIIMOTE, " Channel: %04x", _channelID);
+ DEBUG_LOG(WIIMOTE, " Size: %08x", Offset);
g_WiimoteInitialize.pWiimoteInput(_channelID, DataFrame, Offset);
// Debugging
- ReadDebugging(true, DataFrame, Offset);
+ //ReadDebugging(true, DataFrame, Offset);
}
@@ -228,7 +226,7 @@ void SendReportCoreAccelExt16(u16 _channelID)
void SendReportCoreAccelIr10Ext(u16 _channelID)
{
u8 DataFrame[1024];
- u32 Offset = WriteWmReport(DataFrame, WM_REPORT_CORE_ACCEL_IR10_EXT6);
+ u32 Offset = WriteWmReportHdr(DataFrame, WM_REPORT_CORE_ACCEL_IR10_EXT6);
wm_report_core_accel_ir10_ext6* pReport = (wm_report_core_accel_ir10_ext6*)(DataFrame + Offset);
Offset += sizeof(wm_report_core_accel_ir10_ext6);
@@ -267,12 +265,14 @@ void SendReportCoreAccelIr10Ext(u16 _channelID)
memcpy(&pReport->ext, &_GH3_ext, sizeof(_GH3_ext));
}
- INFO_LOG(WIIMOTE, " SendReportCoreAccelIr10Ext()");
+ INFO_LOG(WIIMOTE, " SendReportCoreAccelIr10Ext(0x37)");
+ DEBUG_LOG(WIIMOTE, " Channel: %04x", _channelID);
+ DEBUG_LOG(WIIMOTE, " Size: %08x", Offset);
g_WiimoteInitialize.pWiimoteInput(_channelID, DataFrame, Offset);
// Debugging
- ReadDebugging(true, DataFrame, Offset);
+ //ReadDebugging(true, DataFrame, Offset);
}
diff --git a/Source/Plugins/Plugin_Wiimote/Src/EmuDefinitions.cpp b/Source/Plugins/Plugin_Wiimote/Src/EmuDefinitions.cpp
index fd3af76015..f96e7b9cb4 100644
--- a/Source/Plugins/Plugin_Wiimote/Src/EmuDefinitions.cpp
+++ b/Source/Plugins/Plugin_Wiimote/Src/EmuDefinitions.cpp
@@ -48,6 +48,7 @@ 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
u8 g_ReportingMode; // The reporting mode and channel id
u16 g_ReportingChannel;
diff --git a/Source/Plugins/Plugin_Wiimote/Src/EmuDefinitions.h b/Source/Plugins/Plugin_Wiimote/Src/EmuDefinitions.h
index 84ea66ca71..eccfe00145 100644
--- a/Source/Plugins/Plugin_Wiimote/Src/EmuDefinitions.h
+++ b/Source/Plugins/Plugin_Wiimote/Src/EmuDefinitions.h
@@ -80,6 +80,7 @@ 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 u8 g_ReportingMode;
extern u16 g_ReportingChannel;
diff --git a/Source/Plugins/Plugin_Wiimote/Src/EmuMain.cpp b/Source/Plugins/Plugin_Wiimote/Src/EmuMain.cpp
index 236b98cebd..63b0a3c0ca 100644
--- a/Source/Plugins/Plugin_Wiimote/Src/EmuMain.cpp
+++ b/Source/Plugins/Plugin_Wiimote/Src/EmuMain.cpp
@@ -373,6 +373,7 @@ void ExtensionChecksum(u8 * Calibration)
// Set initial valuesm this done both in Init and Shutdown
void ResetVariables()
{
+ g_ReportingAuto = false;
g_ReportingMode = 0;
g_ReportingChannel = 0;
g_Encryption = false;
@@ -465,11 +466,10 @@ void Initialize()
void DoState(PointerWrap &p)
{
- return;
// TODO: Shorten the list
p.Do(g_Leds);
- //p.Do(g_Speaker);
- //p.Do(g_SpeakerVoice);
+ p.Do(g_Speaker);
+ p.Do(g_SpeakerVoice);
p.Do(g_IR);
p.DoArray(g_Eeprom, WIIMOTE_EEPROM_SIZE);
p.DoArray(g_RegSpeaker, WIIMOTE_REG_SPEAKER_SIZE);
@@ -477,23 +477,23 @@ 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);
- p.Do(AckDelay);
-
p.Do(g_ExtKey);
p.Do(g_Encryption);
- p.Do(NumPads);
- p.Do(NumGoodPads);
- p.Do(joyinfo);
- p.DoArray(PadState, 4);
- p.DoArray(PadMapping, 4);
+ //p.Do(NumPads);
+ //p.Do(NumGoodPads);
+ //p.Do(joyinfo);
+ //p.DoArray(PadState, 4);
+ //p.DoArray(PadMapping, 4);
- p.Do(g_Wiimote_kbd);
- p.Do(g_NunchuckExt);
- p.Do(g_ClassicContExt);
+ //p.Do(g_Wiimote_kbd);
+ //p.Do(g_NunchuckExt);
+ //p.Do(g_ClassicContExt);
+ return;
}
/* This is not needed if we call FreeLibrary() when we stop a game, but if it's
@@ -528,62 +528,19 @@ void Shutdown(void)
if (SDL_WasInit(0)) SDL_Quit();
}
-
-/* An ack delay of 1 was not small enough, but 2 seemed to work, that was about
- between 20 ms and 100 ms in my case in Zelda - TP. You may have to increase
- this value for other things to work, for example in the wpad demo I had to
- set it to at least 3 for the Sound to be able to turned on (I have an update
- rate of around 150 fps in the wpad demo) */
-void CreateAckDelay(u8 _ChannelID, u16 _ReportID)
-{
- // Settings
- int GlobalDelay = 2;
-
- // Queue an acknowledgment
- wm_ackdelay Tmp;
- Tmp.Delay = GlobalDelay;
- Tmp.ChannelID = _ChannelID;
- Tmp.ReportID = (u8)_ReportID;
- AckDelay.push_back(Tmp);
-}
-
-
-void CheckAckDelay()
-{
- for (int i = 0; i < (int)AckDelay.size(); i++)
- {
- // See if there are any acks to send
- if (AckDelay.at(i).Delay >= 0)
- {
- if(AckDelay.at(i).Delay == 0)
- {
- WmSendAck(AckDelay.at(i).ChannelID, AckDelay.at(i).ReportID, 0);
- AckDelay.erase(AckDelay.begin() + i);
- continue;
- }
- AckDelay.at(i).Delay--;
-
- //INFO_LOG(WIIMOTE, "%i 0x%04x 0x%02x", i, AckDelay.at(i).ChannelID, AckDelay.at(i).ReportID);
- }
- }
-}
-
-
/* 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)
{
- //INFO_LOG(WIIMOTE, "Emu InterruptChannel");
-
- DEBUG_LOG(WIIMOTE, "Wiimote_Input");
- const u8* data = (const u8*)_pData;
-
/* 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. */
- InterruptDebugging(true, data);
+ //InterruptDebugging(true, (const void*)_pData);
+
+ hid_packet* hidp = (hid_packet*)_pData;
+
+ INFO_LOG(WIIMOTE, "Emu InterruptChannel (type: 0x%02x, param: 0x%02x)", hidp->type, hidp->param);
- hid_packet* hidp = (hid_packet*) data;
switch(hidp->type)
{
case HID_TYPE_DATA:
@@ -612,11 +569,20 @@ void InterruptChannel(u16 _channelID, const void* _pData, u32 _Size)
// that, also if we do *we should update the 0x22 to have
// the core keys* otherwise the game will think we release
// the key every time it rumbles
+
+ // AyuanX: Since I've rewritten the whole WII_IPC & WII_IPC_HLE & USB & BT
+ // finally we can get rid of this AckDelay issue, HAHA!
+ //
+ /*
+ const u8* data = (const u8*)_pData;
if(!(data[1] == WM_READ_DATA && data[2] == 0x00)
&& !(data[1] == WM_REQUEST_STATUS)
&& !(data[1] == WM_WRITE_SPEAKER_DATA)
&& !(data[1] == WM_RUMBLE))
- if (!g_Config.bUseRealWiimote || !g_RealWiiMotePresent) CreateAckDelay((u8)_channelID, (u16)sr->channel);
+ if (!g_Config.bUseRealWiimote || !g_RealWiiMotePresent)
+ CreateAckDelay((u8)_channelID, (u16)sr->wm);
+ */
+
}
break;
@@ -636,47 +602,36 @@ void InterruptChannel(u16 _channelID, const void* _pData, u32 _Size)
void ControlChannel(u16 _channelID, const void* _pData, u32 _Size)
{
- //INFO_LOG(WIIMOTE, "Emu ControlChannel");
+ hid_packet* hidp = (hid_packet*)_pData;
- const u8* data = (const u8*)_pData;
- // Dump raw data
- {
- INFO_LOG(WIIMOTE, "Wiimote_ControlChannel");
- std::string Temp = ArrayToString(data, 0, _Size);
- DEBUG_LOG(WIIMOTE, " Data: %s", Temp.c_str());
- }
+ INFO_LOG(WIIMOTE, "Emu ControlChannel (type: 0x%02x, param: 0x%02x)", hidp->type, hidp->param);
- hid_packet* hidp = (hid_packet*) data;
switch(hidp->type)
{
case HID_TYPE_HANDSHAKE:
- if (hidp->param == HID_PARAM_INPUT)
- {
- PanicAlert("HID_TYPE_HANDSHAKE - HID_PARAM_INPUT");
- }
- else
- {
- PanicAlert("HID_TYPE_HANDSHAKE - HID_PARAM_OUTPUT");
- }
+ PanicAlert("HID_TYPE_HANDSHAKE - %s", (hidp->param == HID_PARAM_INPUT) ? "INPUT" : "OUPUT");
break;
case HID_TYPE_SET_REPORT:
if (hidp->param == HID_PARAM_INPUT)
{
- PanicAlert("HID_TYPE_SET_REPORT input");
+ PanicAlert("HID_TYPE_SET_REPORT - INPUT");
}
else
{
- HidOutputReport(_channelID, (wm_report*)hidp->data);
-
- // Return handshake
+ // AyuanX: My experiment shows Control Channel is never used
+ // In case it happens, we will send back a handshake which means report failed/rejected
+ // (TO_BE_VERIFIED)
+ //
u8 handshake = 0;
g_WiimoteInitialize.pWiimoteInput(_channelID, &handshake, 1);
+
+ PanicAlert("HID_TYPE_DATA - OUTPUT: Ambiguous Control Channel Report!");
}
break;
case HID_TYPE_DATA:
- PanicAlert("HID_TYPE_DATA %s", hidp->type, hidp->param == HID_PARAM_INPUT ? "input" : "output");
+ PanicAlert("HID_TYPE_DATA - %s", (hidp->param == HID_PARAM_INPUT) ? "INPUT" : "OUTPUT");
break;
default:
@@ -693,9 +648,10 @@ void ControlChannel(u16 _channelID, const void* _pData, u32 _Size)
of times per second. */
void Update()
{
+ if(g_ReportingAuto == false)
+ return;
+
readKeyboard();
- //LOG(WIIMOTE, "Wiimote_Update");
- //INFO_LOG(WIIMOTE, "Emu Update: %i", g_ReportingMode);
// Check if the pad state should be updated
if ((g_Config.Trigger.Type == g_Config.Trigger.TRIGGER || g_Config.Trigger.Type == g_Config.Trigger.ANALOG1 || g_Config.Trigger.Type == g_Config.Trigger.ANALOG2
@@ -712,17 +668,25 @@ void Update()
{
case 0:
break;
- case WM_REPORT_CORE: SendReportCore(g_ReportingChannel); break;
- case WM_REPORT_CORE_ACCEL: SendReportCoreAccel(g_ReportingChannel); break;
- case WM_REPORT_CORE_ACCEL_IR12: SendReportCoreAccelIr12(g_ReportingChannel); break;
- case WM_REPORT_CORE_ACCEL_EXT16: SendReportCoreAccelExt16(g_ReportingChannel); break;
- case WM_REPORT_CORE_ACCEL_IR10_EXT6: SendReportCoreAccelIr10Ext(g_ReportingChannel);break;
+ case WM_REPORT_CORE:
+ SendReportCore(g_ReportingChannel);
+ break;
+ case WM_REPORT_CORE_ACCEL:
+ SendReportCoreAccel(g_ReportingChannel);
+ break;
+ case WM_REPORT_CORE_ACCEL_IR12:
+ SendReportCoreAccelIr12(g_ReportingChannel);
+ break;
+ case WM_REPORT_CORE_ACCEL_EXT16:
+ SendReportCoreAccelExt16(g_ReportingChannel);
+ break;
+ case WM_REPORT_CORE_ACCEL_IR10_EXT6:
+ SendReportCoreAccelIr10Ext(g_ReportingChannel);
+ break;
}
-
- // Potentially send a delayed acknowledgement to an InterruptChannel() Output
- CheckAckDelay();
}
+
void readKeyboard()
{
#if defined(HAVE_X11) && HAVE_X11
diff --git a/Source/Plugins/Plugin_Wiimote/Src/EmuSubroutines.cpp b/Source/Plugins/Plugin_Wiimote/Src/EmuSubroutines.cpp
index e24bc357d9..5f60c794ba 100644
--- a/Source/Plugins/Plugin_Wiimote/Src/EmuSubroutines.cpp
+++ b/Source/Plugins/Plugin_Wiimote/Src/EmuSubroutines.cpp
@@ -65,74 +65,88 @@ namespace WiiMoteEmu
0x2 = Disable
0x6 = Enable
*/
-void HidOutputReport(u16 _channelID, wm_report* sr) {
- INFO_LOG(WIIMOTE, "HidOutputReport (0x%02x)", sr->channel);
- std::string Temp;
+void HidOutputReport(u16 _channelID, wm_report* sr)
+{
+ INFO_LOG(WIIMOTE, "HidOutputReport (cid: 0x%02x, wm: 0x%02x)", _channelID, sr->wm);
- switch(sr->channel)
+ switch(sr->wm)
{
- case WM_RUMBLE:
+ case WM_RUMBLE: // 0x10
// TODO: Implement rumble for real wiimotes
break;
+
case WM_LEDS: // 0x11
WmLeds(_channelID, (wm_leds*)sr->data);
break;
- case WM_DATA_REPORTING: // 0x12
- WmDataReporting(_channelID, (wm_data_reporting*)sr->data);
- break;
- case WM_REQUEST_STATUS: // 0x15
- if (!g_Config.bUseRealWiimote || !g_RealWiiMotePresent) WmRequestStatus(_channelID, (wm_request_status*)sr->data);
- //Temp = ArrayToString(sr->data, sizeof(wm_request_status), 0);
- //DEBUG_LOG(WIIMOTE, "%s: InterruptChannel: %s", Tm().c_str(), Temp.c_str());
- break;
- case WM_READ_DATA: // 0x17
- if (!g_Config.bUseRealWiimote || !g_RealWiiMotePresent) WmReadData(_channelID, (wm_read_data*)sr->data);
+
+ case WM_REPORT_MODE: // 0x12
+ WmReportMode(_channelID, (wm_report_mode*)sr->data);
break;
- /* This enables or disables the IR lights, we update the global variable
- g_IR so that WmRequestStatus() knows about it */
case WM_IR_PIXEL_CLOCK: // 0x13
case WM_IR_LOGIC: // 0x1a
- WARN_LOG(WIIMOTE, " IR Enable 0x%02x: 0x%02x", sr->channel, sr->data[0]);
- DEBUG_LOG(WIIMOTE, "IR Enable/Disable 0x%02x: 0x%02x", sr->channel, sr->data[0]);
+ // This enables or disables the IR lights, we update the global variable g_IR
+ // so that WmRequestStatus() knows about it
+ INFO_LOG(WIIMOTE, "WM IR Enable: 0x%02x", sr->data[0]);
if(sr->data[0] == 0x02) g_IR = 0;
else if(sr->data[0] == 0x06) g_IR = 1;
break;
+ case WM_SPEAKER_ENABLE: // 0x14
+ INFO_LOG(WIIMOTE, "WM Speaker Enable: 0x%02x", sr->data[0]);
+ if(sr->data[0] == 0x02) g_Speaker = 0;
+ else if(sr->data[0] == 0x06) g_Speaker = 1;
+ break;
+
+ case WM_REQUEST_STATUS: // 0x15
+ if (!g_Config.bUseRealWiimote || !g_RealWiiMotePresent)
+ WmRequestStatus(_channelID, (wm_request_status*)sr->data);
+ break;
+
case WM_WRITE_DATA: // 0x16
WmWriteData(_channelID, (wm_write_data*)sr->data);
break;
- case WM_SPEAKER_ENABLE: // 0x14
- INFO_LOG(WIIMOTE, " WM Speaker Enable 0x%02x: 0x%02x", sr->channel, sr->data[0]);
- //DEBUG_LOG(WIIMOTE, "Speaker Enable/Disable 0x%02x: 0x%02x", sr->channel, sr->data[0]);
- if(sr->data[0] == 0x02) g_Speaker = 0;
- else if(sr->data[0] == 0x06) g_Speaker = 1;
+ case WM_READ_DATA: // 0x17
+ if (!g_Config.bUseRealWiimote || !g_RealWiiMotePresent)
+ WmReadData(_channelID, (wm_read_data*)sr->data);
break;
+
+ case WM_WRITE_SPEAKER_DATA: // 0x18
+ break;
+
case WM_SPEAKER_MUTE: // 0x19
- INFO_LOG(WIIMOTE, " WM Mute Enable 0x%02x: 0x%02x", sr->channel, sr->data[0]);
- //DEBUG_LOG(WIIMOTE, "Speaker Mute/Unmute 0x%02x: 0x%02x", sr->channel, sr->data[0]);
+ INFO_LOG(WIIMOTE, "WM Mute Enable: 0x%02x", sr->data[0]);
if(sr->data[0] == 0x02) g_SpeakerVoice = 0; // g_SpeakerVoice
else if(sr->data[0] == 0x06) g_SpeakerVoice = 1;
break;
- case WM_WRITE_SPEAKER_DATA: // 0x18
- break;
default:
- PanicAlert("HidOutputReport: Unknown channel 0x%02x", sr->channel);
+ PanicAlert("HidOutputReport: Unknown channel 0x%02x", sr->wm);
return;
}
+
+ // Send general feedback except the following types
+ // as these ones generate their own feedbacks
+ if ((sr->wm != WM_RUMBLE)
+ && (sr->wm != WM_READ_DATA)
+ && (sr->wm != WM_REQUEST_STATUS)
+ && (sr->wm != WM_WRITE_SPEAKER_DATA)
+ )
+ {
+ WmSendAck(_channelID, sr->wm);
+ }
}
/* Generate the right header for wm reports. The returned values is the length
of the header before the data begins. It's always two for all reports 0x20 -
0x22, 0x30 - 0x37 */
-int WriteWmReport(u8* dst, u8 channel)
+int WriteWmReportHdr(u8* dst, u8 wm)
{
// Update the first byte to 0xa1
u32 Offset = 0;
- hid_packet* pHidHeader = (hid_packet*)(dst + Offset);
+ hid_packet* pHidHeader = (hid_packet*)dst;
Offset += sizeof(hid_packet);
pHidHeader->type = HID_TYPE_DATA;
pHidHeader->param = HID_PARAM_INPUT;
@@ -140,59 +154,44 @@ int WriteWmReport(u8* dst, u8 channel)
// Update the second byte to the current report type 0x20 - 0x22, 0x30 - 0x37
wm_report* pReport = (wm_report*)(dst + Offset);
Offset += sizeof(wm_report);
- pReport->channel = channel;
+ pReport->wm = wm;
return Offset;
}
/* LED (blue lights) report. */
-void WmLeds(u16 _channelID, wm_leds* leds) {
- INFO_LOG(WIIMOTE, " Set LEDs Leds: %x Rumble: %x", leds->leds, leds->rumble);
+void WmLeds(u16 _channelID, wm_leds* leds)
+{
+ INFO_LOG(WIIMOTE, "Set LEDs: %x, Rumble: %x", leds->leds, leds->rumble);
g_Leds = leds->leds;
}
-/* This will generate the 0x22 acknowledgment after all Input reports. It will
- have the form a1 22 00 00 _reportID 00. The first two bytes are the core
- buttons data, they are 00 00 when nothing is pressed. The last byte is the
- success code 00. */
-void WmSendAck(u16 _channelID, u8 _reportID, u32 address)
+/* This will generate the 0x22 acknowledgement for most Input reports.
+ It has the form of "a1 22 00 00 _reportID 00".
+ The first two bytes are the core buttons data,
+ 00 00 means nothing is pressed.
+ The last byte is the success code 00. */
+void WmSendAck(u16 _channelID, u8 _reportID)
{
u8 DataFrame[1024];
- u32 Offset = 0;
-
- // Header
- hid_packet* pHidHeader = (hid_packet*)(DataFrame + Offset);
- pHidHeader->type = HID_TYPE_DATA;
- pHidHeader->param = HID_PARAM_INPUT;
- Offset += sizeof(hid_packet);
+ // Write DataFrame header
+ u32 Offset = WriteWmReportHdr(DataFrame, WM_ACK_DATA);
wm_acknowledge* pData = (wm_acknowledge*)(DataFrame + Offset);
- pData->Channel = WM_WRITE_DATA_REPLY;
- pData->unk0 = 0;
- pData->unk1 = 0;
+ pData->buttons = 0;
pData->reportID = _reportID;
pData->errorID = 0;
Offset += sizeof(wm_acknowledge);
- INFO_LOG(WIIMOTE, " WMSendAck()");
- INFO_LOG(WIIMOTE, " Report ID: %02x", _reportID);
- //std::string Temp = ArrayToString(DataFrame, Offset, 0);
- //LOGV(WIIMOTE, 2, " Data: %s", Temp.c_str());
- //DEBUG_LOG(WIIMOTE, "%s: WMSendAck: %s", Tm(true).c_str(), Temp.c_str());
-
- /* Debug. Write the report for extension registry writes.
- if((_reportID == 0x16 || _reportID == 0x17) && ((address >> 16) & 0xfe) == 0xa4)
- {
- DEBUG_LOG(WIIMOTE, "WMSendAck Report ID: %02x Encryption: %02x", _reportID, g_RegExt[0xf0]);
- DEBUG_LOG(WIIMOTE, "Data: %s", Temp.c_str());
- }*/
+ DEBUG_LOG(WIIMOTE, "WMSendAck");
+ DEBUG_LOG(WIIMOTE, " Report ID: %02x", _reportID);
g_WiimoteInitialize.pWiimoteInput(_channelID, DataFrame, Offset);
// Debugging
- ReadDebugging(true, DataFrame, Offset);
+ //ReadDebugging(true, DataFrame, Offset);
}
@@ -201,17 +200,14 @@ void WmReadData(u16 _channelID, wm_read_data* rd)
{
u32 address = convert24bit(rd->address);
u16 size = convert16bit(rd->size);
- std::string Temp;
- INFO_LOG(WIIMOTE, "Read data Address space: %x", rd->space);
- INFO_LOG(WIIMOTE, "Read data Address: 0x%06x", address);
- INFO_LOG(WIIMOTE, "Read data Size: 0x%04x", size);
- INFO_LOG(WIIMOTE, "Read data Rumble: %x", rd->rumble);
-
- //u32 _address = address;
- std::string Tmp; // Debugging
+
+ INFO_LOG(WIIMOTE, "Read data");
+ DEBUG_LOG(WIIMOTE, " Read data Space: %x", rd->space);
+ DEBUG_LOG(WIIMOTE, " Read data Address: 0x%06x", address);
+ DEBUG_LOG(WIIMOTE, " Read data Size: 0x%04x", size);
/* Now we determine what address space we are reading from. Space 0 is
- Eeprom and space 1 and 2 is the registers. */
+ Eeprom and space 1 and 2 are the registers. */
if(rd->space == WM_SPACE_EEPROM)
{
if (address + size > WIIMOTE_EEPROM_SIZE)
@@ -219,7 +215,7 @@ void WmReadData(u16 _channelID, wm_read_data* rd)
PanicAlert("WmReadData: address + size out of bounds");
return;
}
- SendReadDataReply(_channelID, g_Eeprom + address, address, (u8)size);
+ SendReadDataReply(_channelID, g_Eeprom + address, address, (int)size);
/*DEBUG_LOG(WIIMOTE, "Read RegEeprom: Size: %i, Address: %08x, Offset: %08x",
size, address, (address & 0xffff));*/
}
@@ -232,62 +228,38 @@ void WmReadData(u16 _channelID, wm_read_data* rd)
case 0xA2:
block = g_RegSpeaker;
blockSize = WIIMOTE_REG_SPEAKER_SIZE;
- INFO_LOG(WIIMOTE, " Case 0xa2: g_RegSpeaker");
- /*Tmp = ArrayToString(g_RegSpeaker, size, (address & 0xffff));
- //LOGV(WIIMOTE, 0, " Data: %s", Temp.c_str());
- DEBUG_LOG(WIIMOTE, "Read RegSpkr: Size %i Address %08x Offset %08x\nData %s",
- size, address, (address & 0xffff), Tmp.c_str());*/
+ DEBUG_LOG(WIIMOTE, " Case 0xa2: g_RegSpeaker");
break;
case 0xA4:
block = g_RegExt;
blockSize = WIIMOTE_REG_EXT_SIZE;
- INFO_LOG(WIIMOTE, " Case 0xa4: Read ExtReg");
- /*Tmp = ArrayToString(g_RegExt, size, (address & 0xffff), 40);
- //LOGV(WIIMOTE, 0, " Data: %s", Temp.c_str());
- DEBUG_LOG(WIIMOTE, "Read RegExt: Size %i Address %08x Offset %08x\nData %s",
- size, address, (address & 0xffff), Tmp.c_str());*/
+ DEBUG_LOG(WIIMOTE, " Case 0xa4: ExtReg");
+ break;
+/*
+ case 0xA6:
+ block = g_RegMotionPlus;
+ block[0xFC] = 0xA6;
+ block[0xFD] = 0x20;
+ block[0xFE] = 0x00;
+ block[0xFF] = 0x05;
+ blockSize = WIIMOTE_REG_EXT_SIZE;
+ DEBUG_LOG(WIIMOTE, " Case 0xa6: MotionPlusReg [%x]", address);
break;
-// case 0xA6:
-// block = g_RegMotionPlus;
-// block[0xFC] = 0xA6;
-// block[0xFD] = 0x20;
-// block[0xFE] = 0x00;
-// block[0xFF] = 0x05;
-// blockSize = WIIMOTE_REG_EXT_SIZE;
-// INFO_LOG(WIIMOTE, " Case 0xa6: MotionPlusReg [%x]", address);
- /*
- Tmp = ArrayToString(block, size, (address & 0xffff));
- //LOGV(WIIMOTE, 0, " Data: %s", Temp.c_str());
- INFO_LOG(WIIMOTE, "Read MotionPlusReg: Size %i Address %08x Offset %08x\nData %s",
- size, address, (address & 0xffff), Tmp.c_str());
- */
-// break;
+*/
case 0xB0:
block = g_RegIr;
blockSize = WIIMOTE_REG_IR_SIZE;
- INFO_LOG(WIIMOTE, " Case: 0xb0 g_RegIr");
- /*Tmp = ArrayToString(g_RegIr, size, (address & 0xffff));
- //LOGV(WIIMOTE, 0, " Data: %s", Temp.c_str());
- DEBUG_LOG(WIIMOTE, "Read RegIR: Size %i Address %08x Offset %08x\nData %s",
- size, address, (address & 0xffff), Tmp.c_str());*/
+ DEBUG_LOG(WIIMOTE, " Case 0xb0: g_RegIr");
break;
+
default:
ERROR_LOG(WIIMOTE, "WmReadData: bad register block!");
return;
}
-
// Encrypt data that is read from the Wiimote Extension Register
if(((address >> 16) & 0xfe) == 0xa4)
{
- /* Debugging
- DEBUG_LOG(WIIMOTE, "WmReadData Address: %08x Offset: %08x Size: %i byte",
- address, address & 0xffff, (u8)size);
- // Debugging
- u32 offset = address & 0xffff;
- std::string Temp = ArrayToString(g_RegExt, size, offset);
- DEBUG_LOG(WIIMOTE, "Unencrypted data:\n%s", Temp.c_str());*/
-
// Check if encrypted reads is on
if(g_RegExt[0xf0] == 0xaa)
{
@@ -300,16 +272,12 @@ void WmReadData(u16 _channelID, wm_read_data* rd)
// Update the block that SendReadDataReply will eventually send to the Wii
block = g_RegExtTmp;
-
- /* Debugging: Show the encrypted data
- std::string Temp = ArrayToString(g_RegExtTmp, size, offset);
- DEBUG_LOG(WIIMOTE, "Encrypted data:\n%s", Temp.c_str());*/
}
}
- //-------------
address &= 0xFFFF;
- if(address + size > blockSize) {
+ if(address + size > blockSize)
+ {
PanicAlert("WmReadData: address + size out of bounds! [%d %d %d]", address, size, blockSize);
return;
}
@@ -321,7 +289,6 @@ void WmReadData(u16 _channelID, wm_read_data* rd)
{
PanicAlert("WmReadData: unimplemented parameters (size: %i, addr: 0x%x)!", size, rd->space);
}
-
}
/* Here we produce the actual 0x21 Input report that we send to the Wii. The
@@ -331,11 +298,11 @@ void WmReadData(u16 _channelID, wm_read_data* rd)
bytes in the message, the 0 means no error, the 00 20 means that the message
is at the 00 20 offest in the registry that was read.
- _Base: The data beginning at _Base[0] _Address: The starting address inside
- the registry, this is used to check for out of bounds reading _Size: The
- total size to send
- */
-void SendReadDataReply(u16 _channelID, void* _Base, u16 _Address, u8 _Size)
+ _Base: The data beginning at _Base[0]
+ _Address: The starting address inside the registry, this is used to check for out of bounds reading
+ _Size: The total size to send
+*/
+void SendReadDataReply(u16 _channelID, void* _Base, u16 _Address, int _Size)
{
int dataOffset = 0;
const u8* data = (const u8*)_Base;
@@ -344,29 +311,27 @@ void SendReadDataReply(u16 _channelID, void* _Base, u16 _Address, u8 _Size)
{
u8 DataFrame[1024];
// Write the first two bytes to DataFrame
- u32 Offset = WriteWmReport(DataFrame, WM_READ_DATA_REPLY);
+ u32 Offset = WriteWmReportHdr(DataFrame, WM_READ_DATA_REPLY);
// Limit the size to 16 bytes
- int copySize = _Size;
- if (copySize > 16) copySize = 16;
+ int copySize = (_Size > 16) ? 16 : _Size;
+ // AyuanX: the MTU is 640B though... what a waste!
- // Connect pReply->data to the almost empty DataFrame
wm_read_data_reply* pReply = (wm_read_data_reply*)(DataFrame + Offset);
- // Now we increase Offset to the final size of the report
Offset += sizeof(wm_read_data_reply);
- // Add header values
+
pReply->buttons = 0;
pReply->error = 0;
// 0x1 means two bytes, 0xf means 16 bytes
- pReply->size = (copySize - 1) & 0xf;
+ pReply->size = copySize - 1;
pReply->address = Common::swap16(_Address + dataOffset);
+ // Clear the mem first
+ memset(pReply->data, 0, 16);
+
// Write a pice of _Base to DataFrame
memcpy(pReply->data, data + dataOffset, copySize);
- // Check if we have less than 16 bytes left to send
- if(copySize < 16) memset(pReply->data + copySize, 0, 16 - copySize);
-
// Update DataOffset for the next loop
dataOffset += copySize;
@@ -382,31 +347,25 @@ void SendReadDataReply(u16 _channelID, void* _Base, u16 _Address, u8 _Size)
}
// Logging
- INFO_LOG(WIIMOTE, " SendReadDataReply()");
- DEBUG_LOG(WIIMOTE, " Buttons: 0x%04x", pReply->buttons);
- DEBUG_LOG(WIIMOTE, " Error: 0x%x", pReply->error);
- DEBUG_LOG(WIIMOTE, " Size: 0x%x", pReply->size);
- DEBUG_LOG(WIIMOTE, " Address: 0x%04x", pReply->address);
- /*DEBUG_LOG(WIIMOTE, " SendReadDataReply()");
- DEBUG_LOG(WIIMOTE, " Offset: 0x%x", Offset);
- DEBUG_LOG(WIIMOTE, " dataOffset: 0x%x", dataOffset);
- DEBUG_LOG(WIIMOTE, " copySize: 0x%x", copySize);
- DEBUG_LOG(WIIMOTE, " Size: 0x%x", pReply->size);
- DEBUG_LOG(WIIMOTE, " Address: 0x%04x", Common::swap16(pReply->address));*/
- //std::string Temp = ArrayToString(data, 0x40);
- //DEBUG_LOG(WIIMOTE, "Data:\n%s", Temp.c_str());
+ DEBUG_LOG(WIIMOTE, "SendReadDataReply");
+ DEBUG_LOG(WIIMOTE, " Buttons: 0x%04x", pReply->buttons);
+ DEBUG_LOG(WIIMOTE, " Error: 0x%x", pReply->error);
+ DEBUG_LOG(WIIMOTE, " Size: 0x%x", pReply->size);
+ DEBUG_LOG(WIIMOTE, " Address: 0x%04x", pReply->address);
+
+#if defined(_DEBUG) || defined(DEBUGFAST)
+ std::string Temp = ArrayToString(DataFrame, Offset);
+ ERROR_LOG(WIIMOTE, "Data: %s", Temp.c_str());
+#endif
// Send a piece
g_WiimoteInitialize.pWiimoteInput(_channelID, DataFrame, Offset);
+
// Update the size that is left
_Size -= copySize;
// Debugging
- ReadDebugging(true, DataFrame, Offset);
- }
-
- if (_Size != 0) {
- PanicAlert("WiiMote-Plugin: SendReadDataReply() failed");
+ //ReadDebugging(true, DataFrame, Offset);
}
}
@@ -414,14 +373,12 @@ void SendReadDataReply(u16 _channelID, void* _Base, u16 _Address, u8 _Size)
/* Write data to Wiimote and Extensions registers. */
void WmWriteData(u16 _channelID, wm_write_data* wd)
{
- u32 address = convert24bit(wd->address);
- INFO_LOG(WIIMOTE, "Write data");
- DEBUG_LOG(WIIMOTE, " Address space: %x", wd->space);
- DEBUG_LOG(WIIMOTE, " Address: 0x%06x", address);
- DEBUG_LOG(WIIMOTE, " Size: 0x%02x", wd->size);
- DEBUG_LOG(WIIMOTE, " Rumble: %x", wd->rumble);
- //std::string Temp = ArrayToString(wd->data, wd->size);
- //LOGV(WIIMOTE, 0, " Data: %s", Temp.c_str());
+ u32 address = convert24bit(wd->address);
+
+ INFO_LOG(WIIMOTE, "Write data");
+ DEBUG_LOG(WIIMOTE, " Space: %x", wd->space);
+ DEBUG_LOG(WIIMOTE, " Address: 0x%06x", address);
+ DEBUG_LOG(WIIMOTE, " Size: 0x%02x", wd->size);
// Write to EEPROM
if(wd->size <= 16 && wd->space == WM_SPACE_EEPROM)
@@ -432,8 +389,6 @@ void WmWriteData(u16 _channelID, wm_write_data* wd)
return;
}
memcpy(g_Eeprom + address, wd->data, wd->size);
- /*DEBUG_LOG(WIIMOTE, "Write RegEeprom: Size: %i, Address: %08x, Offset: %08x",
- wd->size, address, (address & 0xffff));*/
}
// Write to registers
else if(wd->size <= 16 && (wd->space == WM_SPACE_REGS1 || wd->space == WM_SPACE_REGS2))
@@ -445,35 +400,26 @@ void WmWriteData(u16 _channelID, wm_write_data* wd)
case 0xA2:
block = g_RegSpeaker;
blockSize = WIIMOTE_REG_SPEAKER_SIZE;
- INFO_LOG(WIIMOTE, " Case 0xa2: RegSpeaker");
- /*DEBUG_LOG(WIIMOTE, "Write RegSpeaker: Size: %i, Address: %08x, Offset: %08x",
- wd->size, address, (address & 0xffff));
- DEBUG_LOG(WIIMOTE, "Data: %s", Temp.c_str());*/
+ DEBUG_LOG(WIIMOTE, " Case 0xa2: RegSpeaker");
break;
case 0xA4:
block = g_RegExt; // Extension Controller register
blockSize = WIIMOTE_REG_EXT_SIZE;
- INFO_LOG(WIIMOTE, " Case 0xa4: ExtReg");
- /*DEBUG_LOG(WIIMOTE, "Write RegExt Size: %i Address: %08x Offset: %08x ",
- wd->size, address, (address & 0xffff));
- DEBUG_LOG(WIIMOTE, "Data: %s", Temp.c_str());*/
+ DEBUG_LOG(WIIMOTE, " Case 0xa4: ExtReg");
+ break;
+/*
+ case 0xA6:
+ block = g_RegMotionPlus;
+ blockSize = WIIMOTE_REG_EXT_SIZE;
+ DEBUG_LOG(WIIMOTE, " Case 0xa6: MotionPlusReg [%x]", address);
break;
-// case 0xA6:
-// block = g_RegMotionPlus;
-// blockSize = WIIMOTE_REG_EXT_SIZE;
-// INFO_LOG(WIIMOTE, " Case 0xa6: MotionPlusReg [%x] Write ", address);
- /*INFO_LOG(WIIMOTE, "Write MotionPlusReg Size: %i Address: %08x Offset: %08x ",
- wd->size, address, (address & 0xffff));
-// INFO_LOG(WIIMOTE, "Data: %s", Temp.c_str());*/
-// break;
+*/
case 0xB0:
block = g_RegIr;
blockSize = WIIMOTE_REG_IR_SIZE;
- INFO_LOG(WIIMOTE, " Case 0xb0: RegIr");
- /*DEBUG_LOG(WIIMOTE, "Write RegIR Size: %i Address: %08x Offset: %08x ",
- wd->size, address, (address & 0xffff));
- DEBUG_LOG(WIIMOTE, "Data: %s", Temp.c_str());*/
+ INFO_LOG(WIIMOTE, " Case 0xb0: RegIr");
break;
+
default:
ERROR_LOG(WIIMOTE, "WmWriteData: bad register block!");
PanicAlert("WmWriteData: bad register block!");
@@ -492,66 +438,57 @@ void WmWriteData(u16 _channelID, wm_write_data* wd)
// Finally write the registers to the right structure
memcpy(block + address, wd->data, wd->size);
-
// Generate key for the Wiimote Extension
if(blockSize == WIIMOTE_REG_EXT_SIZE)
{
- /* Debugging. Write the data.
- DEBUG_LOG(WIIMOTE, "Data: %s", Temp.c_str());
- DEBUG_LOG(WIIMOTE, "Current address: %08x", address); */
-
/* Run the key generation on all writes in the key area, it doesn't matter
that we send it parts of a key, only the last full key will have an
effect */
if(address >= 0x40 && address <= 0x4c)
wiimote_gen_key(&g_ExtKey, &g_RegExt[0x40]);
}
- // -------------
-
- } else {
+ }
+ else
+ {
PanicAlert("WmWriteData: unimplemented parameters!");
}
/* Just added for home brew... Isn't it enough that we call this from
InterruptChannel()? Or is there a separate route here that don't pass
though InterruptChannel()? */
- //WmSendAck(_channelID, WM_WRITE_DATA, _address);
}
+
/* Here we produce a 0x20 status report to send to the Wii. We currently ignore
the status request rs and all its eventual instructions it may include (for
example turn off rumble or something else) and just send the status
report. */
void WmRequestStatus(u16 _channelID, wm_request_status* rs, int Extension)
{
- INFO_LOG(WIIMOTE, " Request Status: Rumble: %x Channel: %04x",
- rs->rumble, _channelID);
-
- //SendStatusReport();
u8 DataFrame[1024];
- u32 Offset = WriteWmReport(DataFrame, WM_STATUS_REPORT);
+ u32 Offset = WriteWmReportHdr(DataFrame, WM_STATUS_REPORT);
wm_status_report* pStatus = (wm_status_report*)(DataFrame + Offset);
Offset += sizeof(wm_status_report);
memset(pStatus, 0, sizeof(wm_status_report)); // fill the status report with zeroes
// Status values
- pStatus->battery_low = 0; // battery is okay
pStatus->leds = g_Leds; // leds are 4 bit
pStatus->ir = g_IR; // 1 bit
pStatus->speaker = g_Speaker; // 1 bit
+ pStatus->battery_low = 0; // battery is okay
+ pStatus->battery = 0x5f; // fully charged
/* Battery levels in voltage
0x00 - 0x32: level 1
0x33 - 0x43: level 2
0x33 - 0x54: level 3
0x55 - 0xff: level 4 */
- pStatus->battery = 0x5f; // fully charged
// Check if we have a specific order about the extension status
if (Extension == -1)
{
- // Read config value for this one
+ // Read config value for the first time
if(g_Config.iExtensionConnected == EXT_NONE)
pStatus->extension = 0;
else
@@ -565,15 +502,14 @@ void WmRequestStatus(u16 _channelID, wm_request_status* rs, int Extension)
pStatus->extension = 0;
}
- INFO_LOG(WIIMOTE, " Extension: %x", pStatus->extension);
- INFO_LOG(WIIMOTE, " SendStatusReport() Flags: 0x%02x Battery: %d"
- ,pStatus->padding1[2], pStatus->battery);
+ INFO_LOG(WIIMOTE, "Request Status");
+ DEBUG_LOG(WIIMOTE, " Extension: %x", pStatus->extension);
+ DEBUG_LOG(WIIMOTE, " Flags: 0x%02x", pStatus->padding1[2]);
g_WiimoteInitialize.pWiimoteInput(_channelID, DataFrame, Offset);
-
// Debugging
- ReadDebugging(true, DataFrame, Offset);
+ //ReadDebugging(true, DataFrame, Offset);
}
} // WiiMoteEmu
diff --git a/Source/Plugins/Plugin_Wiimote/Src/EmuSubroutines.h b/Source/Plugins/Plugin_Wiimote/Src/EmuSubroutines.h
index a83f689084..9a4b4f8655 100644
--- a/Source/Plugins/Plugin_Wiimote/Src/EmuSubroutines.h
+++ b/Source/Plugins/Plugin_Wiimote/Src/EmuSubroutines.h
@@ -42,17 +42,17 @@ void WmReadData(u16 _channelID, wm_read_data* rd);
void WmWriteData(u16 _channelID, wm_write_data* wd);
void WmRequestStatus(u16 _channelID, wm_request_status* rs, int Extension = -1);
void WmRequestStatus_(u16 _channelID, int a);
-void WmDataReporting(u16 _channelID, wm_data_reporting* dr);
+void WmReportMode(u16 _channelID, wm_report_mode* dr);
-void SendReadDataReply(u16 _channelID, void* _Base, u16 _Address, u8 _Size);
void SendReportCoreAccel(u16 _channelID);
void SendReportCoreAccelIr12(u16 _channelID);
void SendReportCore(u16 _channelID);
void SendReportCoreAccelExt16(u16 _channelID);
void SendReportCoreAccelIr10Ext(u16 _channelID);
-int WriteWmReport(u8* dst, u8 channel);
-void WmSendAck(u16 _channelID, u8 _reportID, u32 address);
+int WriteWmReportHdr(u8* dst, u8 wm);
+void WmSendAck(u16 _channelID, u8 _reportID);
+void SendReadDataReply(u16 _channelID, void* _Base, u16 _Address, int _Size);
void FillReportAcc(wm_accel& _acc);
void FillReportInfo(wm_core& _core);
diff --git a/Source/Plugins/Plugin_Wiimote/Src/FillReport.cpp b/Source/Plugins/Plugin_Wiimote/Src/FillReport.cpp
index 015d639abd..1efb8dbcef 100644
--- a/Source/Plugins/Plugin_Wiimote/Src/FillReport.cpp
+++ b/Source/Plugins/Plugin_Wiimote/Src/FillReport.cpp
@@ -343,10 +343,6 @@ int IsKey(int Key)
// Wiimote core buttons
void FillReportInfo(wm_core& _core)
{
- /* This has to be filled with zeroes (and not for example 0xff) because when no buttons are pressed the
- value is 00 00 */
- memset(&_core, 0x00, sizeof(wm_core));
-
// Check that Dolphin is in focus
if (!IsFocus()) return;
@@ -436,7 +432,7 @@ void SingleShake(u8 &_y, u8 &_z, int i)
/* Tilting Wiimote with gamepad. We can guess that the game will calculate a
Wiimote pitch and use it as a measure of the tilting of the Wiimote. We are
- interested in this tilting range 90° to -90° */
+ interested in this tilting range 90?to -90?*/
void TiltWiimoteGamepad(float &Roll, float &Pitch)
{
// Return if we have no pads
@@ -460,7 +456,7 @@ void TiltWiimoteGamepad(float &Roll, float &Pitch)
float Tl = (float)_Tl;
float Tr = (float)_Tr;
- // Save the Range in degrees, 45° and 90° are good values in some games
+ // Save the Range in degrees, 45?and 90?are good values in some games
float RollRange = (float)g_Config.Trigger.Range.Roll;
float PitchRange = (float)g_Config.Trigger.Range.Pitch;
diff --git a/Source/Plugins/Plugin_Wiimote/Src/main.cpp b/Source/Plugins/Plugin_Wiimote/Src/main.cpp
index 1f9dae90ef..86f7116f81 100644
--- a/Source/Plugins/Plugin_Wiimote/Src/main.cpp
+++ b/Source/Plugins/Plugin_Wiimote/Src/main.cpp
@@ -269,10 +269,9 @@ void Shutdown(void)
void DoState(unsigned char **ptr, int mode)
{
PointerWrap p(ptr, mode);
-
- return;
// TODO: Shorten the list
+
//p.Do(g_EmulatorRunning);
//p.Do(g_ISOId);
p.Do(g_FrameOpen);
@@ -280,16 +279,18 @@ void DoState(unsigned char **ptr, int mode)
p.Do(g_RealWiiMoteInitialized);
p.Do(g_EmulatedWiiMoteInitialized);
p.Do(g_WiimoteUnexpectedDisconnect);
- p.Do(g_UpdateCounter);
- p.Do(g_UpdateTime);
- p.Do(g_UpdateRate);
- p.Do(g_UpdateWriteScreen);
- p.Do(g_UpdateTimeList);
+ //p.Do(g_UpdateCounter);
+ //p.Do(g_UpdateTime);
+ //p.Do(g_UpdateRate);
+ //p.Do(g_UpdateWriteScreen);
+ //p.Do(g_UpdateTimeList);
#if HAVE_WIIUSE
WiiMoteReal::DoState(p);
#endif
WiiMoteEmu::DoState(p);
+
+ return;
}
@@ -305,7 +306,7 @@ void Wiimote_InterruptChannel(u16 _channelID, const void* _pData, u32 _Size)
// Debugging
{
- DEBUG_LOG(WIIMOTE, "Wiimote_Input");
+ DEBUG_LOG(WIIMOTE, "Wiimote_InterruptChannel");
DEBUG_LOG(WIIMOTE, " Channel ID: %04x", _channelID);
std::string Temp = ArrayToString(data, _Size);
DEBUG_LOG(WIIMOTE, " Data: %s", Temp.c_str());
@@ -333,6 +334,7 @@ void Wiimote_ControlChannel(u16 _channelID, const void* _pData, u32 _Size)
DEBUG_LOG(WIIMOTE, "Wiimote Disconnected");
g_EmulatorRunning = false;
g_WiimoteUnexpectedDisconnect = true;
+
#if defined(HAVE_WX) && HAVE_WX
if (m_BasicConfigFrame) m_BasicConfigFrame->UpdateGUI();
#endif
@@ -344,7 +346,6 @@ void Wiimote_ControlChannel(u16 _channelID, const void* _pData, u32 _Size)
DEBUG_LOG(WIIMOTE, "Wiimote_ControlChannel");
std::string Temp = ArrayToString(data, _Size);
DEBUG_LOG(WIIMOTE, " Data: %s", Temp.c_str());
- //PanicAlert("Wiimote_ControlChannel");
}
//if (!g_RealWiiMotePresent)
@@ -372,8 +373,8 @@ void Wiimote_Update()
}
g_UpdateWriteScreen++;
}
-
#endif
+
// This functions will send:
// Emulated Wiimote: Only data reports 0x30-0x37
// Real Wiimote: Both data reports 0x30-0x37 and all other read reports
@@ -638,7 +639,7 @@ void ReadDebugging(bool Emu, const void* _pData, int Size)
}
break;
- case WM_WRITE_DATA_REPLY: // 0x22
+ case WM_ACK_DATA: // 0x22
size = sizeof(wm_acknowledge) - 1;
Name = "REPLY";
break;
@@ -820,7 +821,6 @@ void ReadDebugging(bool Emu, const void* _pData, int Size)
void InterruptDebugging(bool Emu, const void* _pData)
{
- //
const u8* data = (const u8*)_pData;
std::string Name;
@@ -840,9 +840,9 @@ void InterruptDebugging(bool Emu, const void* _pData)
size = sizeof(wm_leds);
if (g_DebugComm) Name.append("WM_LEDS");
break;
- case WM_DATA_REPORTING: // 0x12
- size = sizeof(wm_data_reporting);
- if (g_DebugComm) Name.append("WM_DATA_REPORTING");
+ case WM_REPORT_MODE: // 0x12
+ size = sizeof(wm_report_mode);
+ if (g_DebugComm) Name.append("WM_REPORT_MODE");
break;
case WM_REQUEST_STATUS: // 0x15
size = sizeof(wm_request_status);
diff --git a/Source/Plugins/Plugin_Wiimote/Src/wiimote_hid.h b/Source/Plugins/Plugin_Wiimote/Src/wiimote_hid.h
index f209891d2c..f12c8bd991 100644
--- a/Source/Plugins/Plugin_Wiimote/Src/wiimote_hid.h
+++ b/Source/Plugins/Plugin_Wiimote/Src/wiimote_hid.h
@@ -45,7 +45,7 @@ struct hid_packet {
//source: http://wiibrew.org/wiki/Wiimote
struct wm_report {
- u8 channel;
+ u8 wm;
u8 data[0];
};
@@ -57,8 +57,8 @@ struct wm_leds {
u8 leds : 4;
};
-#define WM_DATA_REPORTING 0x12
-struct wm_data_reporting {
+#define WM_REPORT_MODE 0x12
+struct wm_report_mode {
u8 rumble : 1;
u8 continuous : 1;
u8 all_the_time : 1;
@@ -98,12 +98,10 @@ struct wm_write_data
u8 data[16];
};
-#define WM_WRITE_DATA_REPLY 0x22 //empty, afaik
+#define WM_ACK_DATA 0x22
struct wm_acknowledge
{
- u8 Channel;
- u8 unk0; // Core buttons state (wm_core), can be zero
- u8 unk1;
+ u16 buttons;
u8 reportID;
u8 errorID;
};