From 3945aa624203c2e82160ef7fd045ab74fa47ca95 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Fri, 4 Jan 2019 18:18:44 -0600 Subject: [PATCH] WiimoteEmu: Fix battery level handling and remove old comments. --- .../Core/Core/HW/WiimoteEmu/EmuSubroutines.cpp | 18 +++++++++++------- Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Source/Core/Core/HW/WiimoteEmu/EmuSubroutines.cpp b/Source/Core/Core/HW/WiimoteEmu/EmuSubroutines.cpp index 30a5fa1efc..f989d70576 100644 --- a/Source/Core/Core/HW/WiimoteEmu/EmuSubroutines.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/EmuSubroutines.cpp @@ -225,14 +225,18 @@ void Wiimote::HandleRequestStatus(const OutputReportRequestStatus&) // Update status struct m_status.extension = m_extension_port.IsDeviceConnected(); - // TODO: Battery level will break determinism in TAS/Netplay + // Based on testing, old WiiLi.org docs, and WiiUse library: + // Max battery level seems to be 0xc8 (decimal 200) + constexpr u8 MAX_BATTERY_LEVEL = 0xc8; + + m_status.battery = (u8)(m_battery_setting->GetValue() * MAX_BATTERY_LEVEL); + + if (Core::WantsDeterminism()) + { + // One less thing to break determinism: + m_status.battery = MAX_BATTERY_LEVEL; + } - // Battery levels in voltage - // 0x00 - 0x32: level 1 - // 0x33 - 0x43: level 2 - // 0x33 - 0x54: level 3 - // 0x55 - 0xff: level 4 - m_status.battery = (u8)(m_battery_setting->GetValue() * 0xff); // Less than 0x20 triggers the low-battery flag: m_status.battery_low = m_status.battery < 0x20; diff --git a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp index 2dcf99a898..cd2b10347c 100644 --- a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp @@ -235,7 +235,7 @@ Wiimote::Wiimote(const unsigned int index) : m_index(index) m_options->numeric_settings.emplace_back( std::make_unique(_trans("Speaker Pan"), 0, -127, 127)); m_options->numeric_settings.emplace_back( - m_battery_setting = new ControllerEmu::NumericSetting(_trans("Battery"), 95.0 / 100, 0, 255)); + m_battery_setting = new ControllerEmu::NumericSetting(_trans("Battery"), 95.0 / 100, 0, 100)); // hotkeys groups.emplace_back(m_hotkeys = new ControllerEmu::ModifySettingsButton(_trans("Hotkeys")));