diff --git a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp index 61347c2b4a..587031f2b0 100644 --- a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp @@ -849,15 +849,16 @@ void Wiimote::Update() Movie::SetPolledDevice(); + // TODO: Is max battery really 100 and not 0xff? m_status.battery = (u8)(m_battery_setting->GetValue() * 100); const ReportFeatures& rptf = reporting_mode_features[m_reporting_mode - RT_REPORT_CORE]; - s8 rptf_size = rptf.size; + s8 rptf_size = rptf.total_size; if (Movie::IsPlayingInput() && Movie::PlayWiimote(m_index, data, rptf, m_extension->active_extension, m_ext_logic.ext_key)) { - if (rptf.core) - m_status.buttons = *reinterpret_cast(data + rptf.core); + if (rptf.core_size) + m_status.buttons = *reinterpret_cast(data + 2); } else { @@ -873,38 +874,43 @@ void Wiimote::Update() u8* feature_ptr = data + 2; // core buttons - if (rptf.core) + if (rptf.core_size) { GetButtonData(feature_ptr); - feature_ptr += rptf.core; + feature_ptr += rptf.core_size; } // acceleration - if (rptf.accel) + if (rptf.accel_size) { // TODO: GetAccelData has hardcoded payload offsets.. GetAccelData(data); - feature_ptr += rptf.accel; + feature_ptr += rptf.accel_size; } // IR Camera // TODO: kill use_accel param // TODO: call only if camera logic is enabled? - UpdateIRData(rptf.accel != 0); - if (rptf.ir) + UpdateIRData(rptf.accel_size != 0); + if (rptf.ir_size) { // TODO: kill magic numbers - m_i2c_bus.BusRead(0x58, 0x37, rptf.ir, feature_ptr); - feature_ptr += rptf.ir; + m_i2c_bus.BusRead(0x58, 0x37, rptf.ir_size, feature_ptr); + feature_ptr += rptf.ir_size; } // extension UpdateExtData(); - if (rptf.ext) + if (rptf.ext_size) { // TODO: kill magic numbers - m_i2c_bus.BusRead(0x52, 0x00, rptf.ext, feature_ptr); - feature_ptr += rptf.ext; + m_i2c_bus.BusRead(0x52, 0x00, rptf.ext_size, feature_ptr); + feature_ptr += rptf.ext_size; + } + + if (feature_ptr != data + rptf_size) + { + PanicAlert("Wiimote input report is the wrong size!"); } Movie::CallWiiInputManip(data, rptf, m_index, m_extension->active_extension, @@ -912,9 +918,9 @@ void Wiimote::Update() } if (NetPlay::IsNetPlayRunning()) { - NetPlay_GetWiimoteData(m_index, data, rptf.size, m_reporting_mode); - if (rptf.core) - m_status.buttons = *reinterpret_cast(data + rptf.core); + NetPlay_GetWiimoteData(m_index, data, rptf.total_size, m_reporting_mode); + if (rptf.core_size) + m_status.buttons = *reinterpret_cast(data + rptf.core_size); } // TODO: need to fix usage of rptf probably diff --git a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h index 6ab0659ca7..9a41765626 100644 --- a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h +++ b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h @@ -16,9 +16,6 @@ // Registry sizes #define WIIMOTE_EEPROM_SIZE (16 * 1024) #define WIIMOTE_EEPROM_FREE_SIZE 0x1700 -#define WIIMOTE_REG_SPEAKER_SIZE 10 -#define WIIMOTE_REG_EXT_SIZE 0x100 -#define WIIMOTE_REG_IR_SIZE 0x34 class PointerWrap; @@ -116,7 +113,14 @@ enum class TurntableGroup struct ReportFeatures { - u8 core, accel, ir, ext, size; + // Byte counts: + // Features are always in the following order in an input report: + u8 core_size, accel_size, ir_size, ext_size, total_size; + + int GetCoreOffset() const { return 2; } + int GetAccelOffset() const { return GetCoreOffset() + core_size; } + int GetIROffset() const { return GetAccelOffset() + accel_size; } + int GetExtOffset() const { return GetIROffset() + ir_size; } }; struct AccelData @@ -403,7 +407,7 @@ private: } m_ext_logic; - struct SpeakerLogic : public I2CSlave + struct SpeakerLogic : public I2CSlave { struct { diff --git a/Source/Core/Core/Movie.cpp b/Source/Core/Core/Movie.cpp index 85e4b47e52..36d18f8be1 100644 --- a/Source/Core/Core/Movie.cpp +++ b/Source/Core/Core/Movie.cpp @@ -648,10 +648,10 @@ static void SetWiiInputDisplayString(int remoteID, const u8* const data, std::string display_str = StringFromFormat("R%d:", remoteID + 1); - const u8* const coreData = rptf.core ? (data + rptf.core) : nullptr; - const u8* const accelData = rptf.accel ? (data + rptf.accel) : nullptr; - const u8* const irData = rptf.ir ? (data + rptf.ir) : nullptr; - const u8* const extData = rptf.ext ? (data + rptf.ext) : nullptr; + const u8* const coreData = rptf.core_size ? (data + rptf.GetCoreOffset()) : nullptr; + const u8* const accelData = rptf.accel_size ? (data + rptf.GetAccelOffset()) : nullptr; + const u8* const irData = rptf.ir_size ? (data + rptf.GetIROffset()) : nullptr; + const u8* const extData = rptf.ext_size ? (data + rptf.GetExtOffset()) : nullptr; if (coreData) { @@ -821,7 +821,7 @@ void CheckWiimoteStatus(int wiimote, const u8* data, const WiimoteEmu::ReportFea SetWiiInputDisplayString(wiimote, data, rptf, ext, key); if (IsRecordingInput()) - RecordWiimote(wiimote, data, rptf.size); + RecordWiimote(wiimote, data, rptf.total_size); } void RecordWiimote(int wiimote, const u8* data, u8 size) @@ -1204,7 +1204,7 @@ bool PlayWiimote(int wiimote, u8* data, const WiimoteEmu::ReportFeatures& rptf, return false; } - u8 size = rptf.size; + u8 size = rptf.total_size; u8 sizeInMovie = s_temp_input[s_currentByte]; diff --git a/Source/Core/DolphinQt/TAS/WiiTASInputWindow.cpp b/Source/Core/DolphinQt/TAS/WiiTASInputWindow.cpp index 03a09f83a9..71d62f5fe3 100644 --- a/Source/Core/DolphinQt/TAS/WiiTASInputWindow.cpp +++ b/Source/Core/DolphinQt/TAS/WiiTASInputWindow.cpp @@ -326,10 +326,10 @@ void WiiTASInputWindow::GetValues(u8* report_data, WiimoteEmu::ReportFeatures rp UpdateExt(ext); - u8* const buttons_data = rptf.core ? (report_data + rptf.core) : nullptr; - u8* const accel_data = rptf.accel ? (report_data + rptf.accel) : nullptr; - u8* const ir_data = rptf.ir ? (report_data + rptf.ir) : nullptr; - u8* const ext_data = rptf.ext ? (report_data + rptf.ext) : nullptr; + u8* const buttons_data = rptf.core_size ? (report_data + rptf.GetCoreOffset()) : nullptr; + u8* const accel_data = rptf.accel_size ? (report_data + rptf.GetAccelOffset()) : nullptr; + u8* const ir_data = rptf.ir_size ? (report_data + rptf.GetIROffset()) : nullptr; + u8* const ext_data = rptf.ext_size ? (report_data + rptf.GetExtOffset()) : nullptr; if (m_remote_buttons_box->isVisible() && buttons_data) { @@ -380,10 +380,11 @@ void WiiTASInputWindow::GetValues(u8* report_data, WiimoteEmu::ReportFeatures rp u8 mode; // Mode 5 not supported in core anyway. - if (rptf.ext) - mode = (rptf.ext - rptf.ir) == 10 ? 1 : 3; + // TODO: Can just use ir_size to determine mode + if (rptf.ext_size) + mode = (rptf.GetExtOffset() - rptf.GetIROffset()) == 10 ? 1 : 3; else - mode = (rptf.size - rptf.ir) == 10 ? 1 : 3; + mode = (rptf.total_size - rptf.GetIROffset()) == 10 ? 1 : 3; if (mode == 1) {