From b6203c66c20e83b9f254bf58cadaeab235a51ecc Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 2 Jun 2018 14:08:01 -0400 Subject: [PATCH 1/4] EXI_DeviceIPL: In-class initialize data members where applicable --- Source/Core/Core/HW/EXI/EXI_DeviceIPL.cpp | 5 +---- Source/Core/Core/HW/EXI/EXI_DeviceIPL.h | 10 +++++----- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/Source/Core/Core/HW/EXI/EXI_DeviceIPL.cpp b/Source/Core/Core/HW/EXI/EXI_DeviceIPL.cpp index 08af03a6da..db2f64afb4 100644 --- a/Source/Core/Core/HW/EXI/EXI_DeviceIPL.cpp +++ b/Source/Core/Core/HW/EXI/EXI_DeviceIPL.cpp @@ -95,7 +95,7 @@ void CEXIIPL::Descrambler(u8* data, u32 size) } } -CEXIIPL::CEXIIPL() : m_uPosition(0), m_uAddress(0), m_uRWOffset(0), m_FontsLoaded(false) +CEXIIPL::CEXIIPL() { // Create the IPL m_pIPL = static_cast(Common::AllocateMemoryPages(ROM_SIZE)); @@ -123,9 +123,6 @@ CEXIIPL::CEXIIPL() : m_uPosition(0), m_uAddress(0), m_uRWOffset(0), m_FontsLoade LoadFontFile((File::GetSysDirectory() + GC_SYS_DIR + DIR_SEP + FONT_WINDOWS_1252), 0x1fcf00); } - // Clear RTC - memset(m_RTC, 0, sizeof(m_RTC)); - // We Overwrite language selection here since it's possible on the GC to change the language as // you please g_SRAM.lang = SConfig::GetInstance().SelectedLanguage; diff --git a/Source/Core/Core/HW/EXI/EXI_DeviceIPL.h b/Source/Core/Core/HW/EXI/EXI_DeviceIPL.h index d1c7404f8e..f271739ee4 100644 --- a/Source/Core/Core/HW/EXI/EXI_DeviceIPL.h +++ b/Source/Core/Core/HW/EXI/EXI_DeviceIPL.h @@ -56,15 +56,15 @@ private: // STATE_TO_SAVE //! RealTimeClock - u8 m_RTC[4]; + u8 m_RTC[4] = {}; //! Helper - u32 m_uPosition; - u32 m_uAddress; - u32 m_uRWOffset; + u32 m_uPosition = 0; + u32 m_uAddress = 0; + u32 m_uRWOffset = 0; std::string m_buffer; - bool m_FontsLoaded; + bool m_FontsLoaded = false; void UpdateRTC(); From bf4775f95f24a69d210a87dacc4388935ab8b4b0 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 2 Jun 2018 14:10:14 -0400 Subject: [PATCH 2/4] EXI_DeviceIPL: Normalize variable names Makes naming consistent with our coding style. --- Source/Core/Core/HW/EXI/EXI_DeviceIPL.cpp | 108 +++++++++++----------- Source/Core/Core/HW/EXI/EXI_DeviceIPL.h | 20 ++-- 2 files changed, 64 insertions(+), 64 deletions(-) diff --git a/Source/Core/Core/HW/EXI/EXI_DeviceIPL.cpp b/Source/Core/Core/HW/EXI/EXI_DeviceIPL.cpp index db2f64afb4..7e54a0292a 100644 --- a/Source/Core/Core/HW/EXI/EXI_DeviceIPL.cpp +++ b/Source/Core/Core/HW/EXI/EXI_DeviceIPL.cpp @@ -98,15 +98,15 @@ void CEXIIPL::Descrambler(u8* data, u32 size) CEXIIPL::CEXIIPL() { // Create the IPL - m_pIPL = static_cast(Common::AllocateMemoryPages(ROM_SIZE)); + m_ipl = static_cast(Common::AllocateMemoryPages(ROM_SIZE)); // Load whole ROM dump // Note: The Wii doesn't have a copy of the IPL, only fonts. if (!SConfig::GetInstance().bWii && LoadFileToIPL(SConfig::GetInstance().m_strBootROM, 0)) { // Descramble the encrypted section (contains BS1 and BS2) - Descrambler(m_pIPL + 0x100, 0x1afe00); - INFO_LOG(BOOT, "Loaded bootrom: %s", m_pIPL); // yay for null-terminated strings ;p + Descrambler(m_ipl + 0x100, 0x1afe00); + INFO_LOG(BOOT, "Loaded bootrom: %s", m_ipl); // yay for null-terminated strings ;p } else { @@ -114,9 +114,9 @@ CEXIIPL::CEXIIPL() // Copy header if (DiscIO::IsNTSC(SConfig::GetInstance().m_region)) - memcpy(m_pIPL, iplverNTSC, sizeof(iplverNTSC)); + memcpy(m_ipl, iplverNTSC, sizeof(iplverNTSC)); else - memcpy(m_pIPL, iplverPAL, sizeof(iplverPAL)); + memcpy(m_ipl, iplverPAL, sizeof(iplverPAL)); // Load fonts LoadFontFile((File::GetSysDirectory() + GC_SYS_DIR + DIR_SEP + FONT_SHIFT_JIS), 0x1aff00); @@ -130,14 +130,14 @@ CEXIIPL::CEXIIPL() g_SRAM.counter_bias = 0; FixSRAMChecksums(); - Common::WriteProtectMemory(m_pIPL, ROM_SIZE); - m_uAddress = 0; + Common::WriteProtectMemory(m_ipl, ROM_SIZE); + m_address = 0; } CEXIIPL::~CEXIIPL() { - Common::FreeMemoryPages(m_pIPL, ROM_SIZE); - m_pIPL = nullptr; + Common::FreeMemoryPages(m_ipl, ROM_SIZE); + m_ipl = nullptr; // SRAM if (!g_SRAM_netplay_initialized) @@ -152,12 +152,12 @@ CEXIIPL::~CEXIIPL() } void CEXIIPL::DoState(PointerWrap& p) { - p.Do(m_RTC); - p.Do(m_uPosition); - p.Do(m_uAddress); - p.Do(m_uRWOffset); + p.Do(m_rtc); + p.Do(m_position); + p.Do(m_address); + p.Do(m_rw_offset); p.Do(m_buffer); - p.Do(m_FontsLoaded); + p.Do(m_fonts_loaded); } bool CEXIIPL::LoadFileToIPL(const std::string& filename, u32 offset) @@ -168,10 +168,10 @@ bool CEXIIPL::LoadFileToIPL(const std::string& filename, u32 offset) u64 filesize = stream.GetSize(); - if (!stream.ReadBytes(m_pIPL + offset, filesize)) + if (!stream.ReadBytes(m_ipl + offset, filesize)) return false; - m_FontsLoaded = true; + m_fonts_loaded = true; return true; } @@ -220,24 +220,24 @@ void CEXIIPL::LoadFontFile(const std::string& filename, u32 offset) ((offset == 0x1aff00) ? "Shift JIS" : "Windows-1252"), (ipl_rom_path).c_str()); stream.Seek(offset, 0); - stream.ReadBytes(m_pIPL + offset, fontsize); + stream.ReadBytes(m_ipl + offset, fontsize); - m_FontsLoaded = true; + m_fonts_loaded = true; } -void CEXIIPL::SetCS(int _iCS) +void CEXIIPL::SetCS(int cs) { - if (_iCS) - { - // cs transition to high - m_uPosition = 0; - } + if (!cs) + return; + + // cs transition to high + m_position = 0; } void CEXIIPL::UpdateRTC() { u32 rtc = Common::swap32(GetEmulatedTime(GC_EPOCH)); - std::memcpy(m_RTC, &rtc, sizeof(u32)); + std::memcpy(m_rtc, &rtc, sizeof(u32)); } bool CEXIIPL::IsPresent() const @@ -245,19 +245,19 @@ bool CEXIIPL::IsPresent() const return true; } -void CEXIIPL::TransferByte(u8& _uByte) +void CEXIIPL::TransferByte(u8& byte) { // The first 4 bytes must be the address // If we haven't read it, do it now - if (m_uPosition <= 3) + if (m_position <= 3) { - m_uAddress <<= 8; - m_uAddress |= _uByte; - m_uRWOffset = 0; - _uByte = 0xFF; + m_address <<= 8; + m_address |= byte; + m_rw_offset = 0; + byte = 0xFF; // Check if the command is complete - if (m_uPosition == 3) + if (m_position == 3) { // Get the time... UpdateRTC(); @@ -292,7 +292,7 @@ void CEXIIPL::TransferByte(u8& _uByte) device_name = "Wii RTC flags - not implemented"; break; default: - if ((m_uAddress >> 6) < ROM_SIZE) + if ((m_address >> 6) < ROM_SIZE) { device_name = "ROM"; } @@ -300,13 +300,13 @@ void CEXIIPL::TransferByte(u8& _uByte) { device_name = "illegal address"; DEBUG_ASSERT_MSG(EXPANSIONINTERFACE, 0, "EXI IPL-DEV: %s %08x", device_name.c_str(), - m_uAddress); + m_address); } break; } DEBUG_LOG(EXPANSIONINTERFACE, "%s %s %08x", device_name.c_str(), - IsWriteCommand() ? "write" : "read", m_uAddress); + IsWriteCommand() ? "write" : "read", m_address); } } else @@ -316,26 +316,26 @@ void CEXIIPL::TransferByte(u8& _uByte) { case REGION_RTC: if (IsWriteCommand()) - m_RTC[(m_uAddress & 0x03) + m_uRWOffset] = _uByte; + m_rtc[(m_address & 0x03) + m_rw_offset] = byte; else - _uByte = m_RTC[(m_uAddress & 0x03) + m_uRWOffset]; + byte = m_rtc[(m_address & 0x03) + m_rw_offset]; break; case REGION_SRAM: if (IsWriteCommand()) - g_SRAM.p_SRAM[(m_uAddress & 0x3F) + m_uRWOffset] = _uByte; + g_SRAM.p_SRAM[(m_address & 0x3F) + m_rw_offset] = byte; else - _uByte = g_SRAM.p_SRAM[(m_uAddress & 0x3F) + m_uRWOffset]; + byte = g_SRAM.p_SRAM[(m_address & 0x3F) + m_rw_offset]; break; case REGION_UART: case REGION_EUART: if (IsWriteCommand()) { - if (_uByte != '\0') - m_buffer += _uByte; + if (byte != '\0') + m_buffer += byte; - if (_uByte == '\r') + if (byte == '\r') { NOTICE_LOG(OSREPORT, "%s", SHIFTJISToUTF8(m_buffer).c_str()); m_buffer.clear(); @@ -344,7 +344,7 @@ void CEXIIPL::TransferByte(u8& _uByte) else { // "Queue Length"... return 0 cause we're instant - _uByte = 0; + byte = 0; } break; @@ -354,12 +354,12 @@ void CEXIIPL::TransferByte(u8& _uByte) break; case REGION_UART_UNK: - DEBUG_LOG(OSREPORT, "UART? %x", _uByte); - _uByte = 0xff; + DEBUG_LOG(OSREPORT, "UART? %x", byte); + byte = 0xff; break; case REGION_BARNACLE: - DEBUG_LOG(OSREPORT, "UART Barnacle %x", _uByte); + DEBUG_LOG(OSREPORT, "UART Barnacle %x", byte); break; case REGION_WRTC0: @@ -367,18 +367,18 @@ void CEXIIPL::TransferByte(u8& _uByte) case REGION_WRTC2: // Wii only RTC flags... afaik just the Wii Menu initialize it default: - if ((m_uAddress >> 6) < ROM_SIZE) + if ((m_address >> 6) < ROM_SIZE) { if (!IsWriteCommand()) { - u32 position = ((m_uAddress >> 6) & ROM_MASK) + m_uRWOffset; + u32 position = ((m_address >> 6) & ROM_MASK) + m_rw_offset; // Technically we should descramble here iff descrambling logic is enabled. // At the moment, we pre-decrypt the whole thing and // ignore the "enabled" bit - see CEXIIPL::CEXIIPL - _uByte = m_pIPL[position]; + byte = m_ipl[position]; - if ((position >= 0x001AFF00) && (position <= 0x001FF474) && !m_FontsLoaded) + if ((position >= 0x001AFF00) && (position <= 0x001FF474) && !m_fonts_loaded) { if (position >= 0x001FCF00) { @@ -390,22 +390,22 @@ void CEXIIPL::TransferByte(u8& _uByte) PanicAlertT("Error: Trying to access Shift JIS fonts but they are not loaded. " "Games may not show fonts correctly, or crash."); } - m_FontsLoaded = true; // Don't be a nag :p + m_fonts_loaded = true; // Don't be a nag :p } } } else { NOTICE_LOG(OSREPORT, "EXI IPL-DEV: %s %x at %08x", IsWriteCommand() ? "write" : "read", - _uByte, m_uAddress); + byte, m_address); } break; } - m_uRWOffset++; + m_rw_offset++; } - m_uPosition++; + m_position++; } u32 CEXIIPL::GetEmulatedTime(u32 epoch) diff --git a/Source/Core/Core/HW/EXI/EXI_DeviceIPL.h b/Source/Core/Core/HW/EXI/EXI_DeviceIPL.h index f271739ee4..1c83ac6c21 100644 --- a/Source/Core/Core/HW/EXI/EXI_DeviceIPL.h +++ b/Source/Core/Core/HW/EXI/EXI_DeviceIPL.h @@ -18,7 +18,7 @@ public: CEXIIPL(); virtual ~CEXIIPL(); - void SetCS(int _iCS) override; + void SetCS(int cs) override; bool IsPresent() const override; void DoState(PointerWrap& p) override; @@ -52,25 +52,25 @@ private: }; //! IPL - u8* m_pIPL; + u8* m_ipl; // STATE_TO_SAVE //! RealTimeClock - u8 m_RTC[4] = {}; + u8 m_rtc[4] = {}; //! Helper - u32 m_uPosition = 0; - u32 m_uAddress = 0; - u32 m_uRWOffset = 0; + u32 m_position = 0; + u32 m_address = 0; + u32 m_rw_offset = 0; std::string m_buffer; - bool m_FontsLoaded = false; + bool m_fonts_loaded = false; void UpdateRTC(); - void TransferByte(u8& _uByte) override; - bool IsWriteCommand() const { return !!(m_uAddress & (1 << 31)); } - u32 CommandRegion() const { return (m_uAddress & ~(1 << 31)) >> 8; } + void TransferByte(u8& byte) override; + bool IsWriteCommand() const { return !!(m_address & (1 << 31)); } + u32 CommandRegion() const { return (m_address & ~(1 << 31)) >> 8; } bool LoadFileToIPL(const std::string& filename, u32 offset); void LoadFontFile(const std::string& filename, u32 offset); std::string FindIPLDump(const std::string& path_prefix); From 0d89650950acb6dac6b94092646c77714a1941fc Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 2 Jun 2018 14:18:02 -0400 Subject: [PATCH 3/4] EXI_DeviceIPL: Use std::array where applicable --- Source/Core/Core/HW/EXI/EXI_DeviceIPL.cpp | 4 ++-- Source/Core/Core/HW/EXI/EXI_DeviceIPL.h | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Source/Core/Core/HW/EXI/EXI_DeviceIPL.cpp b/Source/Core/Core/HW/EXI/EXI_DeviceIPL.cpp index 7e54a0292a..60599996f2 100644 --- a/Source/Core/Core/HW/EXI/EXI_DeviceIPL.cpp +++ b/Source/Core/Core/HW/EXI/EXI_DeviceIPL.cpp @@ -236,8 +236,8 @@ void CEXIIPL::SetCS(int cs) void CEXIIPL::UpdateRTC() { - u32 rtc = Common::swap32(GetEmulatedTime(GC_EPOCH)); - std::memcpy(m_rtc, &rtc, sizeof(u32)); + const u32 rtc = Common::swap32(GetEmulatedTime(GC_EPOCH)); + std::memcpy(m_rtc.data(), &rtc, sizeof(u32)); } bool CEXIIPL::IsPresent() const diff --git a/Source/Core/Core/HW/EXI/EXI_DeviceIPL.h b/Source/Core/Core/HW/EXI/EXI_DeviceIPL.h index 1c83ac6c21..7f90a6b373 100644 --- a/Source/Core/Core/HW/EXI/EXI_DeviceIPL.h +++ b/Source/Core/Core/HW/EXI/EXI_DeviceIPL.h @@ -4,6 +4,7 @@ #pragma once +#include #include #include "Core/HW/EXI/EXI_Device.h" @@ -56,7 +57,7 @@ private: // STATE_TO_SAVE //! RealTimeClock - u8 m_rtc[4] = {}; + std::array m_rtc{}; //! Helper u32 m_position = 0; From b1c7ce75e4300027bc3bfed612196852660b8b35 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 2 Jun 2018 14:18:49 -0400 Subject: [PATCH 4/4] EXI_DeviceIPL: Replace superfluous virtual with override on destructor --- Source/Core/Core/HW/EXI/EXI_DeviceIPL.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/Core/HW/EXI/EXI_DeviceIPL.h b/Source/Core/Core/HW/EXI/EXI_DeviceIPL.h index 7f90a6b373..2bbd7056ab 100644 --- a/Source/Core/Core/HW/EXI/EXI_DeviceIPL.h +++ b/Source/Core/Core/HW/EXI/EXI_DeviceIPL.h @@ -17,7 +17,7 @@ class CEXIIPL : public IEXIDevice { public: CEXIIPL(); - virtual ~CEXIIPL(); + ~CEXIIPL() override; void SetCS(int cs) override; bool IsPresent() const override;