WiimoteEmu: Major renaming and cleanup.

This commit is contained in:
Jordan Woyak
2019-01-01 08:32:39 -06:00
parent b1f350ab1c
commit 0d1fbe7bbc
64 changed files with 4140 additions and 3185 deletions

View File

@ -45,8 +45,13 @@
#include "Core/HW/ProcessorInterface.h"
#include "Core/HW/SI/SI.h"
#include "Core/HW/Wiimote.h"
#include "Core/HW/WiimoteCommon/DataReport.h"
#include "Core/HW/WiimoteCommon/WiimoteReport.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
#include "Core/HW/WiimoteEmu/Encryption.h"
#include "Core/HW/WiimoteEmu/Extension/Classic.h"
#include "Core/HW/WiimoteEmu/Extension/Nunchuk.h"
#include "Core/IOS/USB/Bluetooth/BTEmu.h"
#include "Core/IOS/USB/Bluetooth/WiimoteDevice.h"
#include "Core/NetPlayProto.h"
@ -64,6 +69,9 @@
namespace Movie
{
using namespace WiimoteCommon;
using namespace WiimoteEmu;
static bool s_bReadOnly = true;
static u32 s_rerecords = 0;
static PlayMode s_playMode = MODE_NONE;
@ -640,23 +648,17 @@ static void SetInputDisplayString(ControllerState padState, int controllerID)
}
// NOTE: CPU Thread
static void SetWiiInputDisplayString(int remoteID, const u8* const data,
const WiimoteEmu::ReportFeatures& rptf, int ext,
const wiimote_key key)
static void SetWiiInputDisplayString(int remoteID, const DataReportBuilder& rpt, int ext,
const EncryptionKey& key)
{
int controllerID = remoteID + 4;
std::string display_str = StringFromFormat("R%d:", remoteID + 1);
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)
if (rpt.HasCore())
{
wm_buttons buttons;
std::memcpy(&buttons, coreData, sizeof(buttons));
ButtonData buttons;
rpt.GetCoreData(&buttons);
if (buttons.left)
display_str += " LEFT";
@ -680,31 +682,37 @@ static void SetWiiInputDisplayString(int remoteID, const u8* const data,
display_str += " 2";
if (buttons.home)
display_str += " HOME";
// A few bits of accelData are actually inside the coreData struct.
if (accelData)
{
wm_accel dt;
std::memcpy(&dt, accelData, sizeof(dt));
display_str +=
StringFromFormat(" ACC:%d,%d,%d (LSB not shown)", dt.x << 2, dt.y << 2, dt.z << 2);
}
}
if (irData)
if (rpt.HasAccel())
{
DataReportBuilder::AccelData accel_data;
rpt.GetAccelData(&accel_data);
// FYI: This will only print partial data for interleaved reports.
display_str += StringFromFormat(" ACC:%d,%d,%d", accel_data.x, accel_data.y, accel_data.z);
}
if (rpt.HasIR())
{
const u8* const irData = rpt.GetIRDataPtr();
// TODO: This does not handle the different IR formats.
u16 x = irData[0] | ((irData[2] >> 4 & 0x3) << 8);
u16 y = irData[1] | ((irData[2] >> 6 & 0x3) << 8);
display_str += StringFromFormat(" IR:%d,%d", x, y);
}
// Nunchuk
if (extData && ext == 1)
if (rpt.HasExt() && ext == 1)
{
wm_nc nunchuk;
memcpy(&nunchuk, extData, sizeof(wm_nc));
WiimoteDecrypt(&key, (u8*)&nunchuk, 0, sizeof(wm_nc));
const u8* const extData = rpt.GetExtDataPtr();
Nunchuk::DataFormat nunchuk;
memcpy(&nunchuk, extData, sizeof(nunchuk));
key.Decrypt((u8*)&nunchuk, 0, sizeof(nunchuk));
nunchuk.bt.hex = nunchuk.bt.hex ^ 0x3;
std::string accel = StringFromFormat(
@ -720,20 +728,22 @@ static void SetWiiInputDisplayString(int remoteID, const u8* const data,
}
// Classic controller
if (extData && ext == 2)
if (rpt.HasExt() && ext == 2)
{
wm_classic_extension cc;
memcpy(&cc, extData, sizeof(wm_classic_extension));
WiimoteDecrypt(&key, (u8*)&cc, 0, sizeof(wm_classic_extension));
const u8* const extData = rpt.GetExtDataPtr();
Classic::DataFormat cc;
memcpy(&cc, extData, sizeof(cc));
key.Decrypt((u8*)&cc, 0, sizeof(cc));
cc.bt.hex = cc.bt.hex ^ 0xFFFF;
if (cc.bt.regular_data.dpad_left)
if (cc.bt.dpad_left)
display_str += " LEFT";
if (cc.bt.dpad_right)
display_str += " RIGHT";
if (cc.bt.dpad_down)
display_str += " DOWN";
if (cc.bt.regular_data.dpad_up)
if (cc.bt.dpad_up)
display_str += " UP";
if (cc.bt.a)
display_str += " A";
@ -756,7 +766,7 @@ static void SetWiiInputDisplayString(int remoteID, const u8* const data,
display_str += Analog1DToString(cc.lt1 | (cc.lt2 << 3), " L", 31);
display_str += Analog1DToString(cc.rt, " R", 31);
display_str += Analog2DToString(cc.regular_data.lx, cc.regular_data.ly, " ANA", 63);
display_str += Analog2DToString(cc.lx, cc.ly, " ANA", 63);
display_str += Analog2DToString(cc.rx1 | (cc.rx2 << 1) | (cc.rx3 << 3), cc.ry, " R-ANA", 31);
}
@ -814,13 +824,13 @@ void RecordInput(const GCPadStatus* PadStatus, int controllerID)
}
// NOTE: CPU Thread
void CheckWiimoteStatus(int wiimote, const u8* data, const WiimoteEmu::ReportFeatures& rptf,
int ext, const wiimote_key key)
void CheckWiimoteStatus(int wiimote, const DataReportBuilder& rpt, int ext,
const EncryptionKey& key)
{
SetWiiInputDisplayString(wiimote, data, rptf, ext, key);
SetWiiInputDisplayString(wiimote, rpt, ext, key);
if (IsRecordingInput())
RecordWiimote(wiimote, data, rptf.total_size);
RecordWiimote(wiimote, rpt.GetDataPtr(), rpt.GetDataSize());
}
void RecordWiimote(int wiimote, const u8* data, u8 size)
@ -1189,8 +1199,8 @@ void PlayController(GCPadStatus* PadStatus, int controllerID)
}
// NOTE: CPU Thread
bool PlayWiimote(int wiimote, u8* data, const WiimoteEmu::ReportFeatures& rptf, int ext,
const wiimote_key key)
bool PlayWiimote(int wiimote, WiimoteCommon::DataReportBuilder& rpt, int ext,
const EncryptionKey& key)
{
if (!IsPlayingInput() || !IsUsingWiimote(wiimote) || s_temp_input.empty())
return false;
@ -1203,9 +1213,8 @@ bool PlayWiimote(int wiimote, u8* data, const WiimoteEmu::ReportFeatures& rptf,
return false;
}
u8 size = rptf.total_size;
u8 sizeInMovie = s_temp_input[s_currentByte];
const u8 size = rpt.GetDataSize();
const u8 sizeInMovie = s_temp_input[s_currentByte];
if (size != sizeInMovie)
{
@ -1229,7 +1238,7 @@ bool PlayWiimote(int wiimote, u8* data, const WiimoteEmu::ReportFeatures& rptf,
return false;
}
memcpy(data, &s_temp_input[s_currentByte], size);
memcpy(rpt.GetDataPtr(), &s_temp_input[s_currentByte], size);
s_currentByte += size;
s_currentInputCount++;
@ -1348,11 +1357,10 @@ void CallGCInputManip(GCPadStatus* PadStatus, int controllerID)
s_gc_manip_func(PadStatus, controllerID);
}
// NOTE: CPU Thread
void CallWiiInputManip(u8* data, WiimoteEmu::ReportFeatures rptf, int controllerID, int ext,
const wiimote_key key)
void CallWiiInputManip(DataReportBuilder& rpt, int controllerID, int ext, const EncryptionKey& key)
{
if (s_wii_manip_func)
s_wii_manip_func(data, rptf, controllerID, ext, key);
s_wii_manip_func(rpt, controllerID, ext, key);
}
// NOTE: GPU Thread