From 0e79db6cf7a969a2d5c92f5d50086899ef711a7b Mon Sep 17 00:00:00 2001
From: RedPanda4552 <redpanda4552@gmail.com>
Date: Fri, 29 Sep 2023 14:32:52 -0400
Subject: [PATCH] More detailed log for pads

---
 pcsx2/SIO/Pad/PadDualshock2.cpp | 81 ++++++++++++++++++++++++++++++---
 pcsx2/SIO/Pad/PadDualshock2.h   |  2 +
 pcsx2/SIO/Pad/PadGuitar.cpp     | 20 +++++---
 pcsx2/SIO/Pad/PadGuitar.h       |  2 +
 4 files changed, 92 insertions(+), 13 deletions(-)

diff --git a/pcsx2/SIO/Pad/PadDualshock2.cpp b/pcsx2/SIO/Pad/PadDualshock2.cpp
index 0eae96931f..11ff2ca7d6 100644
--- a/pcsx2/SIO/Pad/PadDualshock2.cpp
+++ b/pcsx2/SIO/Pad/PadDualshock2.cpp
@@ -95,6 +95,79 @@ static const SettingInfo s_settings[] = {
 const Pad::ControllerInfo PadDualshock2::ControllerInfo = {Pad::ControllerType::DualShock2, "DualShock2",
 	TRANSLATE_NOOP("Pad", "DualShock 2"), s_bindings, s_settings, Pad::VibrationCapabilities::LargeSmallMotors};
 
+void PadDualshock2::ConfigLog()
+{
+	const auto [port, slot] = sioConvertPadToPortAndSlot(unifiedSlot);
+	std::string_view smallMotorStr;
+
+	switch (this->smallMotorLastConfig)
+	{
+		case 0xff:
+			smallMotorStr = "Disabled";
+			break;
+		case 0x00:
+			smallMotorStr = "Normal";
+			break;
+		case 0x01:
+			smallMotorStr = "Inverted";
+			break;
+		default:
+			smallMotorStr = "Undefined";
+			break;
+	}
+
+	std::string_view largeMotorStr;
+
+	switch (this->largeMotorLastConfig)
+	{
+		case 0xff:
+			largeMotorStr = "Disabled";
+			break;
+		case 0x00:
+			largeMotorStr = "Inverted";
+			break;
+		case 0x01:
+			largeMotorStr = "Normal";
+			break;
+		default:
+			largeMotorStr = "Undefined";
+			break;
+	}
+
+	std::string_view pressureStr;
+
+	switch (this->responseBytes)
+	{
+		case static_cast<u32>(Pad::ResponseBytes::DUALSHOCK2):
+			pressureStr = "D+A+P";
+			break;
+		case static_cast<u32>(Pad::ResponseBytes::ANALOG):
+			pressureStr = "D+A";
+			break;
+		case static_cast<u32>(Pad::ResponseBytes::DIGITAL):
+			pressureStr = "D";
+			break;
+		default:
+			pressureStr = "U";
+			break;
+	}
+
+	// AL: Analog Light (is it turned on right now)
+	// AB: Analog Button (is it useable or is it locked in its current state)
+	// VS: Vibration Small (how is the small vibration motor mapped)
+	// VL: Vibration Large (how is the large vibration motor mapped)
+	// RB: Response Bytes (what data is included in the controller's responses - D = Digital, A = Analog, P = Pressure)
+	Console.WriteLn(fmt::format("[Pad] DS2 Config Finished - P{0}/S{1} - AL: {2} - AB: {3} - VS: {4} - VL: {5} - RB: {6} (0x{7:08X})",
+		port + 1,
+		slot + 1,
+		(this->analogLight ? "On" : "Off"),
+		(this->analogLocked ? "Locked" : "Usable"),
+		smallMotorStr,
+		largeMotorStr,
+		pressureStr,
+		this->responseBytes));
+}
+
 u8 PadDualshock2::Mystery(u8 commandByte)
 {
 	switch (commandBytesReceived)
@@ -257,13 +330,7 @@ u8 PadDualshock2::Config(u8 commandByte)
 			if (this->isInConfig)
 			{
 				this->isInConfig = false;
-				const auto [port, slot] = sioConvertPadToPortAndSlot(unifiedSlot);
-				Console.WriteLn(StringUtil::StdStringFromFormat("[Pad] Game finished pad setup for port %d / slot %d - Analogs: %s - Analog Button: %s - Pressure: %s",
-					port + 1,
-					slot + 1,
-					(this->analogLight ? "On" : "Off"),
-					(this->analogLocked ? "Locked" : "Usable"),
-					(this->responseBytes == static_cast<u32>(Pad::ResponseBytes::DUALSHOCK2) ? "On" : "Off")));
+				this->ConfigLog();
 			}
 			else
 			{
diff --git a/pcsx2/SIO/Pad/PadDualshock2.h b/pcsx2/SIO/Pad/PadDualshock2.h
index 5a88722d4b..b797bc4dc2 100644
--- a/pcsx2/SIO/Pad/PadDualshock2.h
+++ b/pcsx2/SIO/Pad/PadDualshock2.h
@@ -97,6 +97,8 @@ private:
 	// Used to store the last vibration mapping request the PS2 made for the large motor.
 	u8 largeMotorLastConfig = 0xff;
 
+	void ConfigLog();
+
 	u8 Mystery(u8 commandByte);
 	u8 ButtonQuery(u8 commandByte);
 	u8 Poll(u8 commandByte);
diff --git a/pcsx2/SIO/Pad/PadGuitar.cpp b/pcsx2/SIO/Pad/PadGuitar.cpp
index 4ce087dd10..8f092829cd 100644
--- a/pcsx2/SIO/Pad/PadGuitar.cpp
+++ b/pcsx2/SIO/Pad/PadGuitar.cpp
@@ -51,6 +51,19 @@ static const SettingInfo s_settings[] = {
 const Pad::ControllerInfo PadGuitar::ControllerInfo = {Pad::ControllerType::Guitar, "Guitar",
 	TRANSLATE_NOOP("Pad", "Guitar"), s_bindings, s_settings, Pad::VibrationCapabilities::NoVibration};
 
+void PadGuitar::ConfigLog()
+{
+	const auto [port, slot] = sioConvertPadToPortAndSlot(unifiedSlot);
+
+	// AL: Analog Light (is it turned on right now)
+	// AB: Analog Button (is it useable or is it locked in its current state)
+	Console.WriteLn(fmt::format("[Pad] Guitar Config Finished - P{0}/S{1} - AL: {2} - AB: {3}",
+		port + 1,
+		slot + 1,
+		(this->analogLight ? "On" : "Off"),
+		(this->analogLocked ? "Locked" : "Usable")));
+}
+
 u8 PadGuitar::Mystery(u8 commandByte)
 {
 	switch (this->commandBytesReceived)
@@ -124,12 +137,7 @@ u8 PadGuitar::Config(u8 commandByte)
 			if (this->isInConfig)
 			{
 				this->isInConfig = false;
-				const auto [port, slot] = sioConvertPadToPortAndSlot(unifiedSlot);
-				Console.WriteLn("[Pad] Game finished pad setup for port %d / slot %d - Analogs: %s - Analog Button: %s - Pressure: Not available on guitars",
-					port + 1,
-					slot + 1,
-					(this->analogLight ? "On" : "Off"),
-					(this->analogLocked ? "Locked" : "Usable"));
+				this->ConfigLog();
 			}
 			else
 			{
diff --git a/pcsx2/SIO/Pad/PadGuitar.h b/pcsx2/SIO/Pad/PadGuitar.h
index 8b67272a4d..8b4f28c4ba 100644
--- a/pcsx2/SIO/Pad/PadGuitar.h
+++ b/pcsx2/SIO/Pad/PadGuitar.h
@@ -49,6 +49,8 @@ private:
 	float whammyDeadzone = 0.0f;
 	float buttonDeadzone = 0.0f; // Button deadzone is still a good idea, in case a host analog stick is bound to a guitar button
 
+	void ConfigLog();
+
 	u8 Mystery(u8 commandByte);
 	u8 ButtonQuery(u8 commandByte);
 	u8 Poll(u8 commandByte);