Add support for cc and nunchuck in input display.

This commit is contained in:
Rachel Bryk 2014-09-29 23:17:59 -04:00
parent b5ebace92e
commit 4280d9777a
3 changed files with 88 additions and 26 deletions

View File

@ -626,7 +626,7 @@ void Wiimote::Update()
const ReportFeatures& rptf = reporting_mode_features[m_reporting_mode - WM_REPORT_CORE];
s8 rptf_size = rptf.size;
if (Movie::IsPlayingInput() && Movie::PlayWiimote(m_index, data, rptf))
if (Movie::IsPlayingInput() && Movie::PlayWiimote(m_index, data, rptf, m_extension->active_extension, m_ext_key))
{
if (rptf.core)
m_status.buttons = *(wm_core*)(data + rptf.core);
@ -738,7 +738,7 @@ void Wiimote::Update()
}
if (!Movie::IsPlayingInput())
{
Movie::CheckWiimoteStatus(m_index, data, rptf);
Movie::CheckWiimoteStatus(m_index, data, rptf, m_extension->active_extension, m_ext_key);
}
// don't send a data report if auto reporting is off

View File

@ -25,6 +25,8 @@
#include "Core/HW/Wiimote.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
#include "Core/HW/WiimoteEmu/WiimoteHid.h"
#include "Core/HW/WiimoteEmu/Attachment/Classic.h"
#include "Core/HW/WiimoteEmu/Attachment/Nunchuk.h"
#include "Core/IPC_HLE/WII_IPC_HLE_Device_usb.h"
#include "Core/PowerPC/PowerPC.h"
#include "InputCommon/GCPadStatus.h"
@ -497,24 +499,25 @@ bool BeginRecordingInput(int controllers)
return true;
}
static std::string Analog2DToString(u8 x, u8 y, const std::string& prefix)
static std::string Analog2DToString(u8 x, u8 y, const std::string& prefix, u8 range = 255)
{
if ((x <= 1 || x == 128 || x >= 255) &&
(y <= 1 || y == 128 || y >= 255))
u8 center = range / 2 + 1;
if ((x <= 1 || x == center || x >= range) &&
(y <= 1 || y == center || y >= range))
{
if (x != 128 || y != 128)
if (x != center || y != center)
{
if (x != 128 && y != 128)
if (x != center && y != center)
{
return StringFromFormat("%s:%s,%s", prefix.c_str(), x<128?"LEFT":"RIGHT", y<128?"DOWN":"UP");
return StringFromFormat("%s:%s,%s", prefix.c_str(), x < center ? "LEFT" : "RIGHT", y < center ? "DOWN" : "UP");
}
else if (x != 128)
else if (x != center)
{
return StringFromFormat("%s:%s", prefix.c_str(), x<128?"LEFT":"RIGHT");
return StringFromFormat("%s:%s", prefix.c_str(), x < center ? "LEFT" : "RIGHT");
}
else
{
return StringFromFormat("%s:%s", prefix.c_str(), y<128?"DOWN":"UP");
return StringFromFormat("%s:%s", prefix.c_str(), y < center ? "DOWN" : "UP");
}
}
else
@ -528,11 +531,11 @@ static std::string Analog2DToString(u8 x, u8 y, const std::string& prefix)
}
}
static std::string Analog1DToString(u8 v, const std::string& prefix)
static std::string Analog1DToString(u8 v, const std::string& prefix, u8 range = 255)
{
if (v > 0)
{
if (v == 255)
if (v == range)
{
return prefix;
}
@ -580,12 +583,17 @@ static void SetInputDisplayString(ControllerState padState, int controllerID)
s_InputDisplay[controllerID].append("\n");
}
static void SetWiiInputDisplayString(int remoteID, u8* const coreData, u8* const accelData, u8* const irData)
static void SetWiiInputDisplayString(int remoteID, u8* const data, const WiimoteEmu::ReportFeatures& rptf, int ext, const wiimote_key key)
{
int controllerID = remoteID + 4;
s_InputDisplay[controllerID] = StringFromFormat("R%d:", remoteID + 1);
u8* const coreData = rptf.core ? (data + rptf.core) : nullptr;
u8* const accelData = rptf.accel ? (data + rptf.accel) : nullptr;
u8* const irData = rptf.ir ? (data + rptf.ir) : nullptr;
u8* const extData = rptf.ext ? (data + rptf.ext) : nullptr;
if (coreData)
{
wm_core buttons = *(wm_core*)coreData;
@ -626,6 +634,65 @@ static void SetWiiInputDisplayString(int remoteID, u8* const coreData, u8* const
s_InputDisplay[controllerID].append(ir);
}
// Nunchuck
if (extData && ext == 1)
{
wm_extension nunchuck;
memcpy(&nunchuck, extData, sizeof(wm_extension));
WiimoteDecrypt(&key, (u8*)&nunchuck, 0, sizeof(wm_extension));
nunchuck.bt = nunchuck.bt ^ 0xFF;
std::string accel = StringFromFormat(" N-ACC:%d,%d,%d", nunchuck.ax, nunchuck.ay, nunchuck.az);
if (nunchuck.bt & WiimoteEmu::Nunchuk::BUTTON_C)
s_InputDisplay[controllerID].append(" C");
if (nunchuck.bt & WiimoteEmu::Nunchuk::BUTTON_Z)
s_InputDisplay[controllerID].append(" Z");
s_InputDisplay[controllerID].append(accel);
s_InputDisplay[controllerID].append(Analog2DToString(nunchuck.jx, nunchuck.jy, " ANA"));
}
// Classic controller
if (extData && ext == 2)
{
wm_classic_extension cc;
memcpy(&cc, extData, sizeof(wm_classic_extension));
WiimoteDecrypt(&key, (u8*)&cc, 0, sizeof(wm_classic_extension));
cc.bt = cc.bt ^ 0xFFFF;
if (cc.bt & WiimoteEmu::Classic::PAD_LEFT)
s_InputDisplay[controllerID].append(" LEFT");
if (cc.bt & WiimoteEmu::Classic::PAD_RIGHT)
s_InputDisplay[controllerID].append(" RIGHT");
if (cc.bt & WiimoteEmu::Classic::PAD_DOWN)
s_InputDisplay[controllerID].append(" DOWN");
if (cc.bt & WiimoteEmu::Classic::PAD_UP)
s_InputDisplay[controllerID].append(" UP");
if (cc.bt & WiimoteEmu::Classic::BUTTON_A)
s_InputDisplay[controllerID].append(" A");
if (cc.bt & WiimoteEmu::Classic::BUTTON_B)
s_InputDisplay[controllerID].append(" B");
if (cc.bt & WiimoteEmu::Classic::BUTTON_X)
s_InputDisplay[controllerID].append(" X");
if (cc.bt & WiimoteEmu::Classic::BUTTON_Y)
s_InputDisplay[controllerID].append(" Y");
if (cc.bt & WiimoteEmu::Classic::BUTTON_ZL)
s_InputDisplay[controllerID].append(" ZL");
if (cc.bt & WiimoteEmu::Classic::BUTTON_ZR)
s_InputDisplay[controllerID].append(" ZR");
if (cc.bt & WiimoteEmu::Classic::BUTTON_PLUS)
s_InputDisplay[controllerID].append(" +");
if (cc.bt & WiimoteEmu::Classic::BUTTON_MINUS)
s_InputDisplay[controllerID].append(" -");
if (cc.bt & WiimoteEmu::Classic::BUTTON_HOME)
s_InputDisplay[controllerID].append(" HOME");
s_InputDisplay[controllerID].append(Analog1DToString(cc.lt1 | (cc.lt2 << 3), " L", 31));
s_InputDisplay[controllerID].append(Analog1DToString(cc.rt, " R", 31));
s_InputDisplay[controllerID].append(Analog2DToString(cc.lx, cc.ly, " ANA", 63));
s_InputDisplay[controllerID].append(Analog2DToString(cc.rx1 | (cc.rx2 << 1) | (cc.rx3 << 3), cc.ry, " R-ANA", 31));
}
s_InputDisplay[controllerID].append("\n");
}
@ -676,13 +743,10 @@ void RecordInput(GCPadStatus* PadStatus, int controllerID)
s_totalBytes = s_currentByte;
}
void CheckWiimoteStatus(int wiimote, u8 *data, const WiimoteEmu::ReportFeatures& rptf)
void CheckWiimoteStatus(int wiimote, u8 *data, const WiimoteEmu::ReportFeatures& rptf, int ext, const wiimote_key key)
{
u8* const coreData = rptf.core ? (data + rptf.core) : nullptr;
u8* const accelData = rptf.accel ? (data + rptf.accel) : nullptr;
u8* const irData = rptf.ir ? (data + rptf.ir) : nullptr;
u8 size = rptf.size;
SetWiiInputDisplayString(wiimote, coreData, accelData, irData);
SetWiiInputDisplayString(wiimote, data, rptf, ext, key);
if (IsRecordingInput())
RecordWiimote(wiimote, data, size);
@ -1046,7 +1110,7 @@ void PlayController(GCPadStatus* PadStatus, int controllerID)
CheckInputEnd();
}
bool PlayWiimote(int wiimote, u8 *data, const WiimoteEmu::ReportFeatures& rptf)
bool PlayWiimote(int wiimote, u8 *data, const WiimoteEmu::ReportFeatures& rptf, int ext, const wiimote_key key)
{
if (!IsPlayingInput() || !IsUsingWiimote(wiimote) || tmpInput == nullptr)
return false;
@ -1058,9 +1122,6 @@ bool PlayWiimote(int wiimote, u8 *data, const WiimoteEmu::ReportFeatures& rptf)
return false;
}
u8* const coreData = rptf.core ? (data + rptf.core) : nullptr;
u8* const accelData = rptf.accel ? (data + rptf.accel) : nullptr;
u8* const irData = rptf.ir ? (data + rptf.ir) : nullptr;
u8 size = rptf.size;
u8 sizeInMovie = tmpInput[s_currentByte];
@ -1085,7 +1146,7 @@ bool PlayWiimote(int wiimote, u8 *data, const WiimoteEmu::ReportFeatures& rptf)
memcpy(data, &(tmpInput[s_currentByte]), size);
s_currentByte += size;
SetWiiInputDisplayString(wiimote, coreData, accelData, irData);
SetWiiInputDisplayString(wiimote, data, rptf, ext, key);
g_currentInputCount++;

View File

@ -10,6 +10,7 @@
struct GCPadStatus;
class PointerWrap;
struct wiimote_key;
namespace WiimoteEmu
{
@ -162,7 +163,7 @@ bool PlayInput(const std::string& filename);
void LoadInput(const std::string& filename);
void ReadHeader();
void PlayController(GCPadStatus* PadStatus, int controllerID);
bool PlayWiimote(int wiimote, u8* data, const struct WiimoteEmu::ReportFeatures& rptf);
bool PlayWiimote(int wiimote, u8* data, const struct WiimoteEmu::ReportFeatures& rptf, int ext, const struct wiimote_key key);
void EndPlayInput(bool cont);
void SaveRecording(const std::string& filename);
void DoState(PointerWrap &p);
@ -170,7 +171,7 @@ void CheckMD5();
void GetMD5();
void Shutdown();
void CheckPadStatus(GCPadStatus* PadStatus, int controllerID);
void CheckWiimoteStatus(int wiimote, u8* data, const struct WiimoteEmu::ReportFeatures& rptf);
void CheckWiimoteStatus(int wiimote, u8* data, const struct WiimoteEmu::ReportFeatures& rptf, int ext, const struct wiimote_key key);
std::string GetInputDisplay();