From ef8b9a0dcda06a29534deef3854a27c6ede2643b Mon Sep 17 00:00:00 2001 From: "Dr. Dystopia" Date: Thu, 24 Apr 2025 16:47:06 +0200 Subject: [PATCH] Core/HW/SI: Make variables constant --- Source/Core/Core/HW/SI/SI.cpp | 14 +++++++------- Source/Core/Core/HW/SI/SI_Device.cpp | 2 +- Source/Core/Core/HW/SI/SI_DeviceDanceMat.cpp | 2 +- Source/Core/Core/HW/SI/SI_DeviceGBA.cpp | 13 +++++++------ Source/Core/Core/HW/SI/SI_DeviceGBAEmu.cpp | 3 ++- Source/Core/Core/HW/SI/SI_DeviceGCAdapter.cpp | 2 +- Source/Core/Core/HW/SI/SI_DeviceGCController.cpp | 8 ++++---- .../Core/Core/HW/SI/SI_DeviceGCSteeringWheel.cpp | 4 ++-- Source/Core/Core/HW/SI/SI_DeviceKeyboard.cpp | 2 +- 9 files changed, 26 insertions(+), 24 deletions(-) diff --git a/Source/Core/Core/HW/SI/SI.cpp b/Source/Core/Core/HW/SI/SI.cpp index bd856733a2..5968b904ba 100644 --- a/Source/Core/Core/HW/SI/SI.cpp +++ b/Source/Core/Core/HW/SI/SI.cpp @@ -160,7 +160,7 @@ void SerialInterfaceManager::RunSIBuffer(u64 user_data, s64 cycles_late) if (actual_response_length > 0 && expected_response_length != actual_response_length) { std::ostringstream ss; - for (u8 b : request_copy) + for (const u8 b : request_copy) { ss << std::hex << std::setw(2) << std::setfill('0') << (int)b << ' '; } @@ -203,7 +203,7 @@ void SerialInterfaceManager::DoState(PointerWrap& p) p.Do(m_channel[i].out.hex); p.Do(m_channel[i].has_recent_device_change); - std::unique_ptr& device = m_channel[i].device; + const std::unique_ptr& device = m_channel[i].device; SIDevices type = device->GetDeviceType(); p.Do(type); @@ -225,7 +225,7 @@ void SerialInterfaceManager::DoState(PointerWrap& p) template void SerialInterfaceManager::DeviceEventCallback(Core::System& system, u64 userdata, s64 cyclesLate) { - auto& si = system.GetSerialInterface(); + const auto& si = system.GetSerialInterface(); si.m_channel[device_number].device->OnEvent(userdata, cyclesLate); } @@ -282,7 +282,7 @@ void SerialInterfaceManager::Init() } else if (movie.IsUsingPad(i)) { - SIDevices current = Config::Get(Config::GetInfoForSIDevice(i)); + const SIDevices current = Config::Get(Config::GetInfoForSIDevice(i)); // GC pad-compatible devices can be used for both playing and recording if (movie.IsUsingBongo(i)) m_desired_device_types[i] = SIDEVICE_GC_TARUKONGA; @@ -331,7 +331,7 @@ void SerialInterfaceManager::RegisterMMIO(MMIO::Mapping* mmio, u32 base) const u32 address = base | static_cast(io_buffer_base + i); mmio->Register(address, MMIO::ComplexRead([i](Core::System& system, u32) { - auto& si = system.GetSerialInterface(); + const auto& si = system.GetSerialInterface(); u32 val; std::memcpy(&val, &si.m_si_buffer[i], sizeof(val)); return Common::swap32(val); @@ -347,7 +347,7 @@ void SerialInterfaceManager::RegisterMMIO(MMIO::Mapping* mmio, u32 base) const u32 address = base | static_cast(io_buffer_base + i); mmio->Register(address, MMIO::ComplexRead([i](Core::System& system, u32) { - auto& si = system.GetSerialInterface(); + const auto& si = system.GetSerialInterface(); u16 val; std::memcpy(&val, &si.m_si_buffer[i], sizeof(val)); return Common::swap16(val); @@ -487,7 +487,7 @@ void SerialInterfaceManager::RemoveDevice(int device_number) void SerialInterfaceManager::AddDevice(std::unique_ptr device) { - int device_number = device->GetDeviceNumber(); + const int device_number = device->GetDeviceNumber(); // Delete the old device RemoveDevice(device_number); diff --git a/Source/Core/Core/HW/SI/SI_Device.cpp b/Source/Core/Core/HW/SI/SI_Device.cpp index 10efa799b8..8ea3e75d02 100644 --- a/Source/Core/Core/HW/SI/SI_Device.cpp +++ b/Source/Core/Core/HW/SI/SI_Device.cpp @@ -92,7 +92,7 @@ int SIDevice_GetGBATransferTime(const SystemTimers::SystemTimersManager& timers, { u64 gc_bytes_transferred = 1; u64 gba_bytes_transferred = 1; - u64 stop_bits_ns = GC_STOP_BIT_NS + GBA_STOP_BIT_NS; + const u64 stop_bits_ns = GC_STOP_BIT_NS + GBA_STOP_BIT_NS; switch (cmd) { diff --git a/Source/Core/Core/HW/SI/SI_DeviceDanceMat.cpp b/Source/Core/Core/HW/SI/SI_DeviceDanceMat.cpp index 8dfb6f46b8..d7ca1c8a3a 100644 --- a/Source/Core/Core/HW/SI/SI_DeviceDanceMat.cpp +++ b/Source/Core/Core/HW/SI/SI_DeviceDanceMat.cpp @@ -24,7 +24,7 @@ int CSIDevice_DanceMat::RunBuffer(u8* buffer, int request_length) { ISIDevice::RunBuffer(buffer, request_length); - u32 id = Common::swap32(SI_DANCEMAT); + const u32 id = Common::swap32(SI_DANCEMAT); std::memcpy(buffer, &id, sizeof(id)); return sizeof(id); } diff --git a/Source/Core/Core/HW/SI/SI_DeviceGBA.cpp b/Source/Core/Core/HW/SI/SI_DeviceGBA.cpp index b257ebe0c0..f9be6953a9 100644 --- a/Source/Core/Core/HW/SI/SI_DeviceGBA.cpp +++ b/Source/Core/Core/HW/SI/SI_DeviceGBA.cpp @@ -146,7 +146,7 @@ void GBASockServer::ClockSync(Core::System& system) if (!(m_clock_sync = GetNextClock())) return; - auto& core_timing = system.GetCoreTiming(); + const auto& core_timing = system.GetCoreTiming(); u32 time_slice = 0; @@ -169,7 +169,7 @@ void GBASockServer::ClockSync(Core::System& system) bytes[2] = (time_slice >> 8) & 0xff; bytes[3] = time_slice & 0xff; - sf::Socket::Status status = m_clock_sync->send(bytes, 4); + const sf::Socket::Status status = m_clock_sync->send(bytes, 4); if (status == sf::Socket::Status::Disconnected) { m_clock_sync->disconnect(); @@ -228,7 +228,7 @@ int GBASockServer::Receive(u8* si_buffer, u8 bytes) size_t num_received = 0; std::array recv_data; - sf::Socket::Status recv_stat = m_client->receive(recv_data.data(), bytes, num_received); + const sf::Socket::Status recv_stat = m_client->receive(recv_data.data(), bytes, num_received); if (recv_stat == sf::Socket::Status::Disconnected) { Disconnect(); @@ -256,7 +256,7 @@ void GBASockServer::Flush() u8 byte; while (num_received) { - sf::Socket::Status recv_stat = m_client->receive(&byte, 1, num_received); + const sf::Socket::Status recv_stat = m_client->receive(&byte, 1, num_received); if (recv_stat != sf::Socket::Status::Done) break; } @@ -296,7 +296,8 @@ int CSIDevice_GBA::RunBuffer(u8* buffer, int request_length) case NextAction::WaitTransferTime: { - int elapsed_time = static_cast(m_system.GetCoreTiming().GetTicks() - m_timestamp_sent); + const int elapsed_time = + static_cast(m_system.GetCoreTiming().GetTicks() - m_timestamp_sent); // Tell SI to ask again after TransferInterval() cycles if (SIDevice_GetGBATransferTime(m_system.GetSystemTimers(), m_last_cmd) > elapsed_time) return 0; @@ -319,7 +320,7 @@ int CSIDevice_GBA::RunBuffer(u8* buffer, int request_length) default: break; } - int num_data_received = m_sock_server.Receive(buffer, bytes); + const int num_data_received = m_sock_server.Receive(buffer, bytes); m_next_action = NextAction::SendCommand; if (num_data_received == 0) diff --git a/Source/Core/Core/HW/SI/SI_DeviceGBAEmu.cpp b/Source/Core/Core/HW/SI/SI_DeviceGBAEmu.cpp index a78b73e4c7..4506791358 100644 --- a/Source/Core/Core/HW/SI/SI_DeviceGBAEmu.cpp +++ b/Source/Core/Core/HW/SI/SI_DeviceGBAEmu.cpp @@ -78,7 +78,8 @@ int CSIDevice_GBAEmu::RunBuffer(u8* buffer, int request_length) case NextAction::WaitTransferTime: { - int elapsed_time = static_cast(m_system.GetCoreTiming().GetTicks() - m_timestamp_sent); + const int elapsed_time = + static_cast(m_system.GetCoreTiming().GetTicks() - m_timestamp_sent); // Tell SI to ask again after TransferInterval() cycles if (TransferInterval() > elapsed_time) return 0; diff --git a/Source/Core/Core/HW/SI/SI_DeviceGCAdapter.cpp b/Source/Core/Core/HW/SI/SI_DeviceGCAdapter.cpp index d520f43312..6067a9ea58 100644 --- a/Source/Core/Core/HW/SI/SI_DeviceGCAdapter.cpp +++ b/Source/Core/Core/HW/SI/SI_DeviceGCAdapter.cpp @@ -61,7 +61,7 @@ int CSIDevice_GCAdapter::RunBuffer(u8* buffer, int request_length) // into this port on the hardware gc adapter, exposing it to the game. if (!GCAdapter::DeviceConnected(m_device_number)) { - u32 device = Common::swap32(SI_NONE); + const u32 device = Common::swap32(SI_NONE); memcpy(buffer, &device, sizeof(device)); return 4; } diff --git a/Source/Core/Core/HW/SI/SI_DeviceGCController.cpp b/Source/Core/Core/HW/SI/SI_DeviceGCController.cpp index dcc30fd4f9..beb633f499 100644 --- a/Source/Core/Core/HW/SI/SI_DeviceGCController.cpp +++ b/Source/Core/Core/HW/SI/SI_DeviceGCController.cpp @@ -44,7 +44,7 @@ int CSIDevice_GCController::RunBuffer(u8* buffer, int request_length) // For debug logging only ISIDevice::RunBuffer(buffer, request_length); - GCPadStatus pad_status = GetPadStatus(); + const GCPadStatus pad_status = GetPadStatus(); if (!pad_status.isConnected) return -1; @@ -57,7 +57,7 @@ int CSIDevice_GCController::RunBuffer(u8* buffer, int request_length) case EBufferCommands::CMD_STATUS: case EBufferCommands::CMD_RESET: { - u32 id = Common::swap32(SI_GC_CONTROLLER); + const u32 id = Common::swap32(SI_GC_CONTROLLER); std::memcpy(buffer, &id, sizeof(id)); return sizeof(id); } @@ -79,7 +79,7 @@ int CSIDevice_GCController::RunBuffer(u8* buffer, int request_length) { INFO_LOG_FMT(SERIALINTERFACE, "PAD - Get Origin"); - u8* calibration = reinterpret_cast(&m_origin); + const u8* calibration = reinterpret_cast(&m_origin); for (int i = 0; i < (int)sizeof(SOrigin); i++) { buffer[i] = *calibration++; @@ -92,7 +92,7 @@ int CSIDevice_GCController::RunBuffer(u8* buffer, int request_length) { INFO_LOG_FMT(SERIALINTERFACE, "PAD - Recalibrate"); - u8* calibration = reinterpret_cast(&m_origin); + const u8* calibration = reinterpret_cast(&m_origin); for (int i = 0; i < (int)sizeof(SOrigin); i++) { buffer[i] = *calibration++; diff --git a/Source/Core/Core/HW/SI/SI_DeviceGCSteeringWheel.cpp b/Source/Core/Core/HW/SI/SI_DeviceGCSteeringWheel.cpp index 11bba73090..cb639f415e 100644 --- a/Source/Core/Core/HW/SI/SI_DeviceGCSteeringWheel.cpp +++ b/Source/Core/Core/HW/SI/SI_DeviceGCSteeringWheel.cpp @@ -34,7 +34,7 @@ int CSIDevice_GCSteeringWheel::RunBuffer(u8* buffer, int request_length) case EBufferCommands::CMD_STATUS: case EBufferCommands::CMD_RESET: { - u32 id = Common::swap32(SI_GC_STEERING); + const u32 id = Common::swap32(SI_GC_STEERING); std::memcpy(buffer, &id, sizeof(id)); return sizeof(id); } @@ -47,7 +47,7 @@ DataResponse CSIDevice_GCSteeringWheel::GetData(u32& hi, u32& low) { if (m_mode == 6) { - GCPadStatus pad_status = GetPadStatus(); + const GCPadStatus pad_status = GetPadStatus(); hi = (u32)((u8)pad_status.stickX); // Steering hi |= 0x800; // Pedal connected flag diff --git a/Source/Core/Core/HW/SI/SI_DeviceKeyboard.cpp b/Source/Core/Core/HW/SI/SI_DeviceKeyboard.cpp index beb722dc82..28ffc13f61 100644 --- a/Source/Core/Core/HW/SI/SI_DeviceKeyboard.cpp +++ b/Source/Core/Core/HW/SI/SI_DeviceKeyboard.cpp @@ -35,7 +35,7 @@ int CSIDevice_Keyboard::RunBuffer(u8* buffer, int request_length) case EBufferCommands::CMD_STATUS: case EBufferCommands::CMD_RESET: { - u32 id = Common::swap32(SI_GC_KEYBOARD); + const u32 id = Common::swap32(SI_GC_KEYBOARD); std::memcpy(buffer, &id, sizeof(id)); return sizeof(id); }