mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-04-20 11:35:54 +00:00
Create initial balance board extension, hardcoding my own data
This commit is contained in:
parent
84d28a4272
commit
1b1ffeb539
11 changed files with 199 additions and 6 deletions
|
@ -304,6 +304,8 @@ add_library(core
|
|||
HW/WiimoteEmu/EmuSubroutines.cpp
|
||||
HW/WiimoteEmu/Encryption.cpp
|
||||
HW/WiimoteEmu/Encryption.h
|
||||
HW/WiimoteEmu/Extension/BalanceBoard.cpp
|
||||
HW/WiimoteEmu/Extension/BalanceBoard.h
|
||||
HW/WiimoteEmu/Extension/Classic.cpp
|
||||
HW/WiimoteEmu/Extension/Classic.h
|
||||
HW/WiimoteEmu/Extension/DesiredExtensionState.h
|
||||
|
|
|
@ -117,7 +117,7 @@ SerializedWiimoteState SerializeDesiredState(const DesiredWiimoteState& state)
|
|||
using T = std::decay_t<decltype(arg)>;
|
||||
if constexpr (!std::is_same_v<std::monostate, T>)
|
||||
{
|
||||
static_assert(sizeof(arg) <= 6);
|
||||
static_assert(sizeof(arg) <= 12);
|
||||
static_assert(std::is_trivially_copyable_v<T>);
|
||||
std::memcpy(&s.data[s.length], &arg, sizeof(arg));
|
||||
s.length += sizeof(arg);
|
||||
|
@ -213,6 +213,9 @@ bool DeserializeDesiredState(DesiredWiimoteState* state, const SerializedWiimote
|
|||
case ExtensionNumber::SHINKANSEN:
|
||||
s += sizeof(Shinkansen::DesiredState);
|
||||
break;
|
||||
case ExtensionNumber::BALANCE_BOARD:
|
||||
s += sizeof(BalanceBoardExt::DataFormat);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -319,6 +322,8 @@ bool DeserializeDesiredState(DesiredWiimoteState* state, const SerializedWiimote
|
|||
return DeserializeExtensionState<TaTaCon::DataFormat>(state, serialized, pos);
|
||||
case ExtensionNumber::SHINKANSEN:
|
||||
return DeserializeExtensionState<Shinkansen::DesiredState>(state, serialized, pos);
|
||||
case ExtensionNumber::BALANCE_BOARD:
|
||||
return DeserializeExtensionState<BalanceBoardExt::DataFormat>(state, serialized, pos);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ struct DesiredWiimoteState
|
|||
struct SerializedWiimoteState
|
||||
{
|
||||
u8 length;
|
||||
std::array<u8, 30> data; // 18 bytes Wiimote, 6 bytes MotionPlus, 6 bytes Extension
|
||||
std::array<u8, 36> data; // 18 bytes Wiimote, 6 bytes MotionPlus, 12 bytes Extension
|
||||
};
|
||||
|
||||
SerializedWiimoteState SerializeDesiredState(const DesiredWiimoteState& state);
|
||||
|
|
|
@ -149,7 +149,18 @@ void Wiimote::HandleExtensionSwap(ExtensionNumber desired_extension_number,
|
|||
if (WIIMOTE_BALANCE_BOARD == m_index)
|
||||
{
|
||||
// Prevent M+ or anything else silly from being attached to a balance board.
|
||||
// In the future if we support an emulated balance board we can force the BB "extension" here.
|
||||
if (m_is_motion_plus_attached)
|
||||
{
|
||||
m_is_motion_plus_attached = false;
|
||||
m_motion_plus.GetExtPort().AttachExtension(GetNoneExtension());
|
||||
}
|
||||
// Also force the BB "extension".
|
||||
if (m_active_extension != ExtensionNumber::BALANCE_BOARD)
|
||||
{
|
||||
m_active_extension = ExtensionNumber::BALANCE_BOARD;
|
||||
m_extension_port.AttachExtension(GetActiveExtension());
|
||||
GetActiveExtension()->Reset();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
109
Source/Core/Core/HW/WiimoteEmu/Extension/BalanceBoard.cpp
Normal file
109
Source/Core/Core/HW/WiimoteEmu/Extension/BalanceBoard.cpp
Normal file
|
@ -0,0 +1,109 @@
|
|||
// Copyright 2022 Dolphin Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "Core/HW/WiimoteEmu/Extension/BalanceBoard.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
#include "Common/BitUtils.h"
|
||||
#include "Common/Common.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/MathUtil.h"
|
||||
#include "Common/Swap.h"
|
||||
|
||||
#include "Core/HW/Wiimote.h"
|
||||
#include "Core/HW/WiimoteEmu/Extension/DesiredExtensionState.h"
|
||||
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
|
||||
|
||||
#include "InputCommon/ControllerEmu/Control/Input.h"
|
||||
#include "InputCommon/ControllerEmu/ControlGroup/AnalogStick.h"
|
||||
#include "InputCommon/ControllerEmu/ControlGroup/Buttons.h"
|
||||
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
|
||||
#include "InputCommon/ControllerEmu/ControlGroup/Force.h"
|
||||
#include "InputCommon/ControllerEmu/ControlGroup/Tilt.h"
|
||||
|
||||
namespace WiimoteEmu
|
||||
{
|
||||
constexpr std::array<u8, 6> balance_board_id{{0x00, 0x00, 0xa4, 0x20, 0x04, 0x02}};
|
||||
|
||||
BalanceBoardExt::BalanceBoardExt() : Extension1stParty("BalanceBoard", _trans("Balance Board"))
|
||||
{
|
||||
}
|
||||
|
||||
void BalanceBoardExt::BuildDesiredExtensionState(DesiredExtensionState* target_state)
|
||||
{
|
||||
DataFormat bb_data = {};
|
||||
|
||||
bb_data.top_right = Common::swap16(0x0743);
|
||||
bb_data.bottom_right = Common::swap16(0x11a2);
|
||||
bb_data.top_left = Common::swap16(0x06a8);
|
||||
bb_data.bottom_left = Common::swap16(0x4694);
|
||||
bb_data.temperature = 0x19;
|
||||
bb_data.battery = 0x83;
|
||||
|
||||
target_state->data = bb_data;
|
||||
}
|
||||
|
||||
void BalanceBoardExt::Update(const DesiredExtensionState& target_state)
|
||||
{
|
||||
DefaultExtensionUpdate<DataFormat>(&m_reg, target_state);
|
||||
}
|
||||
|
||||
void BalanceBoardExt::Reset()
|
||||
{
|
||||
EncryptedExtension::Reset();
|
||||
|
||||
m_reg.identifier = balance_board_id;
|
||||
|
||||
// Build calibration data:
|
||||
m_reg.calibration = {{// Unused battery calibration
|
||||
0x01, 0x69, 0x00, 0x00,
|
||||
// Top right 0kg
|
||||
0x07, 0xbc,
|
||||
// Bottom right 0kg
|
||||
0x11, 0x8b,
|
||||
// Top left 0kg
|
||||
0x06, 0xba,
|
||||
// Bottom left 0kg
|
||||
0x46, 0x52,
|
||||
// Top right 17kg
|
||||
0x0e, 0x6e,
|
||||
// Bottom right 17kg
|
||||
0x18, 0x79}};
|
||||
m_reg.calibration2 = {{// Top left 17kg
|
||||
0x0d, 0x5d,
|
||||
// Bottom left 17kg
|
||||
0x4d, 0x4c,
|
||||
// Top right 34kg
|
||||
0x15, 0x2e,
|
||||
// Bottom right 34kg
|
||||
0x1f, 0x71,
|
||||
// Top left 34kg
|
||||
0x14, 0x07,
|
||||
// Bottom left 34kg
|
||||
0x54, 0x51,
|
||||
// Checksum
|
||||
0xa9, 0x06, 0xb4, 0xf0}};
|
||||
m_reg.calibration3 = {{0x19, 0x01}};
|
||||
|
||||
// UpdateCalibrationDataChecksum(m_reg.calibration, CALIBRATION_CHECKSUM_BYTES);
|
||||
}
|
||||
|
||||
ControllerEmu::ControlGroup* BalanceBoardExt::GetGroup(BalanceBoardGroup group)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void BalanceBoardExt::DoState(PointerWrap& p)
|
||||
{
|
||||
EncryptedExtension::DoState(p);
|
||||
}
|
||||
|
||||
void BalanceBoardExt::LoadDefaults(const ControllerInterface& ciface)
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace WiimoteEmu
|
51
Source/Core/Core/HW/WiimoteEmu/Extension/BalanceBoard.h
Normal file
51
Source/Core/Core/HW/WiimoteEmu/Extension/BalanceBoard.h
Normal file
|
@ -0,0 +1,51 @@
|
|||
// Copyright 2022 Dolphin Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
|
||||
#include "Core/HW/WiimoteCommon/WiimoteReport.h"
|
||||
#include "Core/HW/WiimoteEmu/Dynamics.h"
|
||||
#include "Core/HW/WiimoteEmu/Extension/Extension.h"
|
||||
|
||||
namespace ControllerEmu
|
||||
{
|
||||
class ControlGroup;
|
||||
} // namespace ControllerEmu
|
||||
|
||||
namespace WiimoteEmu
|
||||
{
|
||||
enum class BalanceBoardGroup
|
||||
{
|
||||
};
|
||||
|
||||
class BalanceBoardExt : public Extension1stParty
|
||||
{
|
||||
public:
|
||||
struct DataFormat
|
||||
{
|
||||
u16 top_right;
|
||||
u16 bottom_right;
|
||||
u16 top_left;
|
||||
u16 bottom_left;
|
||||
u8 temperature;
|
||||
u8 padding;
|
||||
u8 battery;
|
||||
};
|
||||
static_assert(sizeof(DataFormat) == 12, "Wrong size");
|
||||
|
||||
BalanceBoardExt();
|
||||
|
||||
void BuildDesiredExtensionState(DesiredExtensionState* target_state) override;
|
||||
void Update(const DesiredExtensionState& target_state) override;
|
||||
void Reset() override;
|
||||
void DoState(PointerWrap& p) override;
|
||||
|
||||
ControllerEmu::ControlGroup* GetGroup(BalanceBoardGroup group);
|
||||
|
||||
void LoadDefaults(const ControllerInterface& ciface) override;
|
||||
|
||||
private:
|
||||
};
|
||||
} // namespace WiimoteEmu
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include "Common/BitUtils.h"
|
||||
|
||||
#include "Core/HW/WiimoteEmu/Extension/BalanceBoard.h"
|
||||
#include "Core/HW/WiimoteEmu/Extension/Classic.h"
|
||||
#include "Core/HW/WiimoteEmu/Extension/DrawsomeTablet.h"
|
||||
#include "Core/HW/WiimoteEmu/Extension/Drums.h"
|
||||
|
@ -27,7 +28,8 @@ struct DesiredExtensionState
|
|||
using ExtensionData =
|
||||
std::variant<std::monostate, Nunchuk::DataFormat, Classic::DataFormat, Guitar::DataFormat,
|
||||
Drums::DesiredState, Turntable::DataFormat, UDrawTablet::DataFormat,
|
||||
DrawsomeTablet::DataFormat, TaTaCon::DataFormat, Shinkansen::DesiredState>;
|
||||
DrawsomeTablet::DataFormat, TaTaCon::DataFormat, Shinkansen::DesiredState,
|
||||
BalanceBoardExt::DataFormat>;
|
||||
ExtensionData data = std::monostate();
|
||||
|
||||
static_assert(std::is_same_v<std::monostate,
|
||||
|
@ -57,6 +59,9 @@ struct DesiredExtensionState
|
|||
static_assert(
|
||||
std::is_same_v<Shinkansen::DesiredState,
|
||||
std::variant_alternative_t<ExtensionNumber::SHINKANSEN, ExtensionData>>);
|
||||
static_assert(
|
||||
std::is_same_v<BalanceBoardExt::DataFormat,
|
||||
std::variant_alternative_t<ExtensionNumber::BALANCE_BOARD, ExtensionData>>);
|
||||
static_assert(std::variant_size_v<DesiredExtensionState::ExtensionData> == ExtensionNumber::MAX);
|
||||
};
|
||||
|
||||
|
|
|
@ -85,11 +85,14 @@ public:
|
|||
|
||||
// address 0x20
|
||||
std::array<u8, 0x10> calibration;
|
||||
u8 unknown3[0x10];
|
||||
std::array<u8, 0x10> calibration2;
|
||||
|
||||
// address 0x40
|
||||
std::array<u8, 0x10> encryption_key_data;
|
||||
u8 unknown4[0xA0];
|
||||
u8 unknown3[0x10];
|
||||
// Address 0x60
|
||||
std::array<u8, 2> calibration3;
|
||||
u8 unknown4[0x8e];
|
||||
|
||||
// address 0xF0
|
||||
u8 encryption;
|
||||
|
|
|
@ -23,6 +23,8 @@ enum ExtensionNumber : u8
|
|||
TATACON,
|
||||
SHINKANSEN,
|
||||
|
||||
BALANCE_BOARD,
|
||||
|
||||
MAX
|
||||
};
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "Core/HW/WiimoteCommon/WiimoteConstants.h"
|
||||
#include "Core/HW/WiimoteCommon/WiimoteHid.h"
|
||||
#include "Core/HW/WiimoteEmu/DesiredWiimoteState.h"
|
||||
#include "Core/HW/WiimoteEmu/Extension/BalanceBoard.h"
|
||||
#include "Core/HW/WiimoteEmu/Extension/Classic.h"
|
||||
#include "Core/HW/WiimoteEmu/Extension/DesiredExtensionState.h"
|
||||
#include "Core/HW/WiimoteEmu/Extension/DrawsomeTablet.h"
|
||||
|
@ -182,6 +183,7 @@ void Wiimote::Reset()
|
|||
{
|
||||
// Switch to desired M+ status and extension (if any).
|
||||
// M+ and EXT are reset on attachment.
|
||||
// This also ensures that the balance board extension is attached if needed.
|
||||
HandleExtensionSwap(static_cast<ExtensionNumber>(m_attachments->GetSelectedAttachment()),
|
||||
m_motion_plus_setting.GetValue());
|
||||
}
|
||||
|
@ -280,6 +282,7 @@ Wiimote::Wiimote(const unsigned int index) : m_index(index), m_bt_device_index(i
|
|||
m_attachments->AddAttachment(std::make_unique<WiimoteEmu::DrawsomeTablet>());
|
||||
m_attachments->AddAttachment(std::make_unique<WiimoteEmu::TaTaCon>());
|
||||
m_attachments->AddAttachment(std::make_unique<WiimoteEmu::Shinkansen>());
|
||||
m_attachments->AddAttachment(std::make_unique<WiimoteEmu::BalanceBoardExt>());
|
||||
|
||||
m_attachments->AddSetting(&m_motion_plus_setting, {_trans("Attach MotionPlus")}, true);
|
||||
|
||||
|
|
|
@ -337,6 +337,7 @@
|
|||
<ClInclude Include="Core\HW\WiimoteEmu\Dynamics.h" />
|
||||
<ClInclude Include="Core\HW\WiimoteEmu\DesiredWiimoteState.h" />
|
||||
<ClInclude Include="Core\HW\WiimoteEmu\Encryption.h" />
|
||||
<ClInclude Include="Core\HW\WiimoteEmu\Extension\BalanceBoard.h" />
|
||||
<ClInclude Include="Core\HW\WiimoteEmu\Extension\Classic.h" />
|
||||
<ClInclude Include="Core\HW\WiimoteEmu\Extension\DesiredExtensionState.h" />
|
||||
<ClInclude Include="Core\HW\WiimoteEmu\Extension\DrawsomeTablet.h" />
|
||||
|
@ -1001,6 +1002,7 @@
|
|||
<ClCompile Include="Core\HW\WiimoteEmu\Dynamics.cpp" />
|
||||
<ClCompile Include="Core\HW\WiimoteEmu\EmuSubroutines.cpp" />
|
||||
<ClCompile Include="Core\HW\WiimoteEmu\Encryption.cpp" />
|
||||
<ClCompile Include="Core\HW\WiimoteEmu\Extension\BalanceBoard.cpp" />
|
||||
<ClCompile Include="Core\HW\WiimoteEmu\Extension\Classic.cpp" />
|
||||
<ClCompile Include="Core\HW\WiimoteEmu\Extension\DrawsomeTablet.cpp" />
|
||||
<ClCompile Include="Core\HW\WiimoteEmu\Extension\Drums.cpp" />
|
||||
|
|
Loading…
Add table
Reference in a new issue