summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorBonta <40473493+Bonta0@users.noreply.github.com>2021-07-04 13:02:50 +0200
committerBonta <40473493+Bonta0@users.noreply.github.com>2021-07-13 16:42:40 +0200
commitfdcee30a3d191946ebbd93f6ecc5be644e493de9 (patch)
treed1f785e4ccf74ed8b0a31d096dbec32831167d78 /Source
parent8ee21acf3460e00d55002fb3387be4dd763b01e9 (diff)
SI: Expose Commands constants and switch to enum class
Diffstat (limited to 'Source')
-rw-r--r--Source/Core/Core/HW/SI/SI_Device.h34
-rw-r--r--Source/Core/Core/HW/SI/SI_DeviceDanceMat.cpp4
-rw-r--r--Source/Core/Core/HW/SI/SI_DeviceGBA.cpp35
-rw-r--r--Source/Core/Core/HW/SI/SI_DeviceGBA.h2
-rw-r--r--Source/Core/Core/HW/SI/SI_DeviceGCController.cpp27
-rw-r--r--Source/Core/Core/HW/SI/SI_DeviceGCController.h29
-rw-r--r--Source/Core/Core/HW/SI/SI_DeviceGCSteeringWheel.cpp8
-rw-r--r--Source/Core/Core/HW/SI/SI_DeviceGCSteeringWheel.h15
-rw-r--r--Source/Core/Core/HW/SI/SI_DeviceKeyboard.cpp18
-rw-r--r--Source/Core/Core/HW/SI/SI_DeviceKeyboard.h28
10 files changed, 69 insertions, 131 deletions
diff --git a/Source/Core/Core/HW/SI/SI_Device.h b/Source/Core/Core/HW/SI/SI_Device.h
index 323f6c602a..14bd83201c 100644
--- a/Source/Core/Core/HW/SI/SI_Device.h
+++ b/Source/Core/Core/HW/SI/SI_Device.h
@@ -41,6 +41,40 @@ enum TSIDevices : u32
SI_AM_BASEBOARD = 0x10110800 // gets ORd with dipswitch state
};
+// Commands
+enum class EBufferCommands : u8
+{
+ CMD_STATUS = 0x00,
+ CMD_READ_GBA = 0x14,
+ CMD_WRITE_GBA = 0x15,
+ CMD_DIRECT = 0x40,
+ CMD_ORIGIN = 0x41,
+ CMD_RECALIBRATE = 0x42,
+ CMD_DIRECT_KB = 0x54,
+ CMD_RESET = 0xFF
+};
+
+enum class EDirectCommands : u8
+{
+ CMD_FORCE = 0x30,
+ CMD_WRITE = 0x40,
+ CMD_POLL = 0x54
+};
+
+union UCommand
+{
+ u32 hex = 0;
+ struct
+ {
+ u32 parameter1 : 8;
+ u32 parameter2 : 8;
+ u32 command : 8;
+ u32 : 8;
+ };
+ UCommand() = default;
+ UCommand(u32 value) : hex{value} {}
+};
+
// For configuration use, since some devices can have the same SI Device ID
enum SIDevices : int
{
diff --git a/Source/Core/Core/HW/SI/SI_DeviceDanceMat.cpp b/Source/Core/Core/HW/SI/SI_DeviceDanceMat.cpp
index ae5ae477ab..f2f6545776 100644
--- a/Source/Core/Core/HW/SI/SI_DeviceDanceMat.cpp
+++ b/Source/Core/Core/HW/SI/SI_DeviceDanceMat.cpp
@@ -19,8 +19,8 @@ CSIDevice_DanceMat::CSIDevice_DanceMat(SIDevices device, int device_number)
int CSIDevice_DanceMat::RunBuffer(u8* buffer, int request_length)
{
// Read the command
- EBufferCommands command = static_cast<EBufferCommands>(buffer[0]);
- if (command == CMD_RESET)
+ const auto command = static_cast<EBufferCommands>(buffer[0]);
+ if (command == EBufferCommands::CMD_STATUS)
{
ISIDevice::RunBuffer(buffer, request_length);
diff --git a/Source/Core/Core/HW/SI/SI_DeviceGBA.cpp b/Source/Core/Core/HW/SI/SI_DeviceGBA.cpp
index b1d2704a47..57679bbe50 100644
--- a/Source/Core/Core/HW/SI/SI_DeviceGBA.cpp
+++ b/Source/Core/Core/HW/SI/SI_DeviceGBA.cpp
@@ -34,14 +34,6 @@ int s_num_connected;
Common::Flag s_server_running;
} // namespace
-enum EJoybusCmds
-{
- CMD_RESET = 0xff,
- CMD_STATUS = 0x00,
- CMD_READ = 0x14,
- CMD_WRITE = 0x15
-};
-
constexpr auto GC_BITS_PER_SECOND = 200000;
constexpr auto GBA_BITS_PER_SECOND = 250000;
constexpr auto GC_STOP_BIT_NS = 6500;
@@ -50,7 +42,7 @@ constexpr auto SEND_MAX_SIZE = 5, RECV_MAX_SIZE = 5;
// --- GameBoy Advance "Link Cable" ---
-static int GetTransferTime(u8 cmd)
+static int GetTransferTime(EBufferCommands cmd)
{
u64 gc_bytes_transferred = 1;
u64 gba_bytes_transferred = 1;
@@ -58,18 +50,18 @@ static int GetTransferTime(u8 cmd)
switch (cmd)
{
- case CMD_RESET:
- case CMD_STATUS:
+ case EBufferCommands::CMD_RESET:
+ case EBufferCommands::CMD_STATUS:
{
gba_bytes_transferred = 3;
break;
}
- case CMD_READ:
+ case EBufferCommands::CMD_READ_GBA:
{
gba_bytes_transferred = 5;
break;
}
- case CMD_WRITE:
+ case EBufferCommands::CMD_WRITE_GBA:
{
gc_bytes_transferred = 5;
break;
@@ -249,10 +241,10 @@ void GBASockServer::Send(const u8* si_buffer)
for (size_t i = 0; i < send_data.size(); i++)
send_data[i] = si_buffer[i];
- u8 cmd = send_data[0];
+ const auto cmd = static_cast<EBufferCommands>(send_data[0]);
sf::Socket::Status status;
- if (cmd == CMD_WRITE)
+ if (cmd == EBufferCommands::CMD_WRITE_GBA)
status = m_client->send(send_data.data(), send_data.size());
else
status = m_client->send(send_data.data(), 1);
@@ -334,7 +326,7 @@ int CSIDevice_GBA::RunBuffer(u8* buffer, int request_length)
return -1;
}
- m_last_cmd = buffer[0];
+ m_last_cmd = static_cast<EBufferCommands>(buffer[0]);
m_timestamp_sent = CoreTiming::GetTicks();
m_next_action = NextAction::WaitTransferTime;
return 0;
@@ -355,11 +347,11 @@ int CSIDevice_GBA::RunBuffer(u8* buffer, int request_length)
u8 bytes = 1;
switch (m_last_cmd)
{
- case CMD_RESET:
- case CMD_STATUS:
+ case EBufferCommands::CMD_RESET:
+ case EBufferCommands::CMD_STATUS:
bytes = 3;
break;
- case CMD_READ:
+ case EBufferCommands::CMD_READ_GBA:
bytes = 5;
break;
default:
@@ -372,8 +364,9 @@ int CSIDevice_GBA::RunBuffer(u8* buffer, int request_length)
return -1;
#ifdef _DEBUG
const Common::Log::LOG_LEVELS log_level =
- (m_last_cmd == CMD_STATUS || m_last_cmd == CMD_RESET) ? Common::Log::LERROR :
- Common::Log::LWARNING;
+ (m_last_cmd == EBufferCommands::CMD_STATUS || m_last_cmd == EBufferCommands::CMD_RESET) ?
+ Common::Log::LERROR :
+ Common::Log::LWARNING;
GENERIC_LOG_FMT(Common::Log::SERIALINTERFACE, log_level,
"{} [< {:02x}{:02x}{:02x}{:02x}{:02x}] ({})",
m_device_number, buffer[0], buffer[1], buffer[2], buffer[3], buffer[4],
diff --git a/Source/Core/Core/HW/SI/SI_DeviceGBA.h b/Source/Core/Core/HW/SI/SI_DeviceGBA.h
index dccbf2235e..663c4c9b1f 100644
--- a/Source/Core/Core/HW/SI/SI_DeviceGBA.h
+++ b/Source/Core/Core/HW/SI/SI_DeviceGBA.h
@@ -60,7 +60,7 @@ private:
GBASockServer m_sock_server;
NextAction m_next_action = NextAction::SendCommand;
- u8 m_last_cmd;
+ EBufferCommands m_last_cmd;
u64 m_timestamp_sent = 0;
};
} // namespace SerialInterface
diff --git a/Source/Core/Core/HW/SI/SI_DeviceGCController.cpp b/Source/Core/Core/HW/SI/SI_DeviceGCController.cpp
index 8c485f1a9f..985033f97b 100644
--- a/Source/Core/Core/HW/SI/SI_DeviceGCController.cpp
+++ b/Source/Core/Core/HW/SI/SI_DeviceGCController.cpp
@@ -45,20 +45,20 @@ int CSIDevice_GCController::RunBuffer(u8* buffer, int request_length)
return -1;
// Read the command
- EBufferCommands command = static_cast<EBufferCommands>(buffer[0]);
+ const auto command = static_cast<EBufferCommands>(buffer[0]);
// Handle it
switch (command)
{
- case CMD_RESET:
- case CMD_ID:
+ case EBufferCommands::CMD_STATUS:
+ case EBufferCommands::CMD_RESET:
{
u32 id = Common::swap32(SI_GC_CONTROLLER);
std::memcpy(buffer, &id, sizeof(id));
return sizeof(id);
}
- case CMD_DIRECT:
+ case EBufferCommands::CMD_DIRECT:
{
INFO_LOG_FMT(SERIALINTERFACE, "PAD - Direct (Request length: {})", request_length);
u32 high, low;
@@ -71,7 +71,7 @@ int CSIDevice_GCController::RunBuffer(u8* buffer, int request_length)
return sizeof(high) + sizeof(low);
}
- case CMD_ORIGIN:
+ case EBufferCommands::CMD_ORIGIN:
{
INFO_LOG_FMT(SERIALINTERFACE, "PAD - Get Origin");
@@ -84,7 +84,7 @@ int CSIDevice_GCController::RunBuffer(u8* buffer, int request_length)
}
// Recalibrate (FiRES: i am not 100 percent sure about this)
- case CMD_RECALIBRATE:
+ case EBufferCommands::CMD_RECALIBRATE:
{
INFO_LOG_FMT(SERIALINTERFACE, "PAD - Recalibrate");
@@ -290,13 +290,7 @@ void CSIDevice_GCController::SendCommand(u32 command, u8 poll)
{
UCommand controller_command(command);
- switch (controller_command.command)
- {
- // Costis sent it in some demos :)
- case 0x00:
- break;
-
- case CMD_WRITE:
+ if (static_cast<EDirectCommands>(controller_command.command) == EDirectCommands::CMD_WRITE)
{
const u32 type = controller_command.parameter1; // 0 = stop, 1 = rumble, 2 = stop hard
@@ -317,15 +311,12 @@ void CSIDevice_GCController::SendCommand(u32 command, u8 poll)
INFO_LOG_FMT(SERIALINTERFACE, "PAD {} set to mode {}", m_device_number, m_mode);
}
}
- break;
-
- default:
+ else if (controller_command.command != 0x00)
{
+ // Costis sent 0x00 in some demos :)
ERROR_LOG_FMT(SERIALINTERFACE, "Unknown direct command ({:#x})", command);
PanicAlertFmt("SI: Unknown direct command");
}
- break;
- }
}
// Savestate support
diff --git a/Source/Core/Core/HW/SI/SI_DeviceGCController.h b/Source/Core/Core/HW/SI/SI_DeviceGCController.h
index 9904e855bb..6d7f4722af 100644
--- a/Source/Core/Core/HW/SI/SI_DeviceGCController.h
+++ b/Source/Core/Core/HW/SI/SI_DeviceGCController.h
@@ -12,16 +12,6 @@ namespace SerialInterface
class CSIDevice_GCController : public ISIDevice
{
protected:
- // Commands
- enum EBufferCommands
- {
- CMD_RESET = 0x00,
- CMD_DIRECT = 0x40,
- CMD_ORIGIN = 0x41,
- CMD_RECALIBRATE = 0x42,
- CMD_ID = 0xff,
- };
-
struct SOrigin
{
u16 button;
@@ -35,25 +25,6 @@ protected:
u8 unk_5;
};
- enum EDirectCommands
- {
- CMD_WRITE = 0x40
- };
-
- union UCommand
- {
- u32 hex = 0;
- struct
- {
- u32 parameter1 : 8;
- u32 parameter2 : 8;
- u32 command : 8;
- u32 : 8;
- };
- UCommand() = default;
- UCommand(u32 value) : hex{value} {}
- };
-
enum EButtonCombo
{
COMBO_NONE = 0,
diff --git a/Source/Core/Core/HW/SI/SI_DeviceGCSteeringWheel.cpp b/Source/Core/Core/HW/SI/SI_DeviceGCSteeringWheel.cpp
index a801296267..212c08d52b 100644
--- a/Source/Core/Core/HW/SI/SI_DeviceGCSteeringWheel.cpp
+++ b/Source/Core/Core/HW/SI/SI_DeviceGCSteeringWheel.cpp
@@ -25,13 +25,13 @@ int CSIDevice_GCSteeringWheel::RunBuffer(u8* buffer, int request_length)
ISIDevice::RunBuffer(buffer, request_length);
// Read the command
- EBufferCommands command = static_cast<EBufferCommands>(buffer[0]);
+ const auto command = static_cast<EBufferCommands>(buffer[0]);
// Handle it
switch (command)
{
- case CMD_RESET:
- case CMD_ID:
+ case EBufferCommands::CMD_STATUS:
+ case EBufferCommands::CMD_RESET:
{
u32 id = Common::swap32(SI_GC_STEERING);
std::memcpy(buffer, &id, sizeof(id));
@@ -101,7 +101,7 @@ void CSIDevice_GCSteeringWheel::SendCommand(u32 command, u8 poll)
{
UCommand wheel_command(command);
- if (wheel_command.command == CMD_FORCE)
+ if (static_cast<EDirectCommands>(wheel_command.command) == EDirectCommands::CMD_FORCE)
{
// get the correct pad number that should rumble locally when using netplay
const int pad_num = NetPlay_InGamePadToLocalPad(m_device_number);
diff --git a/Source/Core/Core/HW/SI/SI_DeviceGCSteeringWheel.h b/Source/Core/Core/HW/SI/SI_DeviceGCSteeringWheel.h
index 37b0cfff3a..4de13d142d 100644
--- a/Source/Core/Core/HW/SI/SI_DeviceGCSteeringWheel.h
+++ b/Source/Core/Core/HW/SI/SI_DeviceGCSteeringWheel.h
@@ -17,21 +17,6 @@ public:
void SendCommand(u32 command, u8 poll) override;
private:
- // Commands
- enum EBufferCommands
- {
- CMD_RESET = 0x00,
- CMD_ORIGIN = 0x41,
- CMD_RECALIBRATE = 0x42,
- CMD_ID = 0xff,
- };
-
- enum EDirectCommands
- {
- CMD_FORCE = 0x30,
- CMD_WRITE = 0x40
- };
-
enum class ForceCommandType : u8
{
MotorOn = 0x03,
diff --git a/Source/Core/Core/HW/SI/SI_DeviceKeyboard.cpp b/Source/Core/Core/HW/SI/SI_DeviceKeyboard.cpp
index 8c5092adc7..13f067dc59 100644
--- a/Source/Core/Core/HW/SI/SI_DeviceKeyboard.cpp
+++ b/Source/Core/Core/HW/SI/SI_DeviceKeyboard.cpp
@@ -31,15 +31,15 @@ int CSIDevice_Keyboard::RunBuffer(u8* buffer, int request_length)
// Handle it
switch (command)
{
- case CMD_RESET:
- case CMD_ID:
+ case EBufferCommands::CMD_STATUS:
+ case EBufferCommands::CMD_RESET:
{
u32 id = Common::swap32(SI_GC_KEYBOARD);
std::memcpy(buffer, &id, sizeof(id));
return sizeof(id);
}
- case CMD_DIRECT:
+ case EBufferCommands::CMD_DIRECT_KB:
{
INFO_LOG_FMT(SERIALINTERFACE, "Keyboard - Direct (Request Length: {})", request_length);
u32 high, low;
@@ -84,23 +84,15 @@ void CSIDevice_Keyboard::SendCommand(u32 command, u8 poll)
{
UCommand keyboard_command(command);
- switch (keyboard_command.command)
- {
- case 0x00:
- break;
-
- case CMD_POLL:
+ if (static_cast<EDirectCommands>(keyboard_command.command) == EDirectCommands::CMD_POLL)
{
m_counter++;
m_counter &= 15;
}
- break;
- default:
+ else if (keyboard_command.command != 0x00)
{
ERROR_LOG_FMT(SERIALINTERFACE, "Unknown direct command ({:#x})", command);
}
- break;
- }
}
void CSIDevice_Keyboard::DoState(PointerWrap& p)
diff --git a/Source/Core/Core/HW/SI/SI_DeviceKeyboard.h b/Source/Core/Core/HW/SI/SI_DeviceKeyboard.h
index beb34f0960..aebc63afa0 100644
--- a/Source/Core/Core/HW/SI/SI_DeviceKeyboard.h
+++ b/Source/Core/Core/HW/SI/SI_DeviceKeyboard.h
@@ -32,34 +32,6 @@ public:
void DoState(PointerWrap& p) override;
protected:
- // Commands
- enum EBufferCommands
- {
- CMD_RESET = 0x00,
- CMD_DIRECT = 0x54,
- CMD_ID = 0xff,
- };
-
- enum EDirectCommands
- {
- CMD_WRITE = 0x40,
- CMD_POLL = 0x54
- };
-
- union UCommand
- {
- u32 hex = 0;
- struct
- {
- u32 parameter1 : 8;
- u32 parameter2 : 8;
- u32 command : 8;
- u32 : 8;
- };
- UCommand() = default;
- UCommand(u32 value) : hex{value} {}
- };
-
// PADAnalogMode
u8 m_mode = 0;