From 99636374634af721b36a1197e2cccf70efb8cb39 Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Tue, 13 Sep 2022 03:58:32 +0200 Subject: [PATCH] HW: Remove global state from functions in Sram.h. --- Source/Core/Core/HW/EXI/EXI.cpp | 2 +- Source/Core/Core/HW/EXI/EXI_DeviceIPL.cpp | 2 +- .../Core/Core/HW/EXI/EXI_DeviceMemoryCard.cpp | 2 +- Source/Core/Core/HW/Sram.cpp | 27 +++++++++---------- Source/Core/Core/HW/Sram.h | 7 ++--- Source/Core/Core/NetPlayServer.cpp | 2 +- 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Source/Core/Core/HW/EXI/EXI.cpp b/Source/Core/Core/HW/EXI/EXI.cpp index c480e09235..08b5fe8eec 100644 --- a/Source/Core/Core/HW/EXI/EXI.cpp +++ b/Source/Core/Core/HW/EXI/EXI.cpp @@ -106,7 +106,7 @@ void Init() { if (!g_SRAM_netplay_initialized) { - InitSRAM(); + InitSRAM(&g_SRAM, SConfig::GetInstance().m_strSRAM); } CEXIMemoryCard::Init(); diff --git a/Source/Core/Core/HW/EXI/EXI_DeviceIPL.cpp b/Source/Core/Core/HW/EXI/EXI_DeviceIPL.cpp index 6f4d7ad2c2..b1ff59cbab 100644 --- a/Source/Core/Core/HW/EXI/EXI_DeviceIPL.cpp +++ b/Source/Core/Core/HW/EXI/EXI_DeviceIPL.cpp @@ -136,7 +136,7 @@ CEXIIPL::CEXIIPL() // you please g_SRAM.settings.language = Config::Get(Config::MAIN_GC_LANGUAGE); g_SRAM.settings.rtc_bias = 0; - FixSRAMChecksums(); + FixSRAMChecksums(&g_SRAM); } CEXIIPL::~CEXIIPL() diff --git a/Source/Core/Core/HW/EXI/EXI_DeviceMemoryCard.cpp b/Source/Core/Core/HW/EXI/EXI_DeviceMemoryCard.cpp index 5e012e44db..a5d3f3a1e0 100644 --- a/Source/Core/Core/HW/EXI/EXI_DeviceMemoryCard.cpp +++ b/Source/Core/Core/HW/EXI/EXI_DeviceMemoryCard.cpp @@ -141,7 +141,7 @@ CEXIMemoryCard::CEXIMemoryCard(const Slot slot, bool gci_folder, m_memory_card_size = m_memory_card->GetCardId() * SIZE_TO_Mb; std::array header{}; m_memory_card->Read(0, static_cast(header.size()), header.data()); - SetCardFlashID(header.data(), m_card_slot); + SetCardFlashID(&g_SRAM, header.data(), m_card_slot); } std::pair diff --git a/Source/Core/Core/HW/Sram.cpp b/Source/Core/Core/HW/Sram.cpp index 1f8b29116a..b177ed6443 100644 --- a/Source/Core/Core/HW/Sram.cpp +++ b/Source/Core/Core/HW/Sram.cpp @@ -9,7 +9,6 @@ #include "Common/MsgHandler.h" #include "Common/Swap.h" -#include "Core/ConfigManager.h" #include "Core/HW/EXI/EXI.h" // English @@ -58,24 +57,24 @@ const SRAM sram_dump_german = {{ }}; #endif -void InitSRAM() +void InitSRAM(Sram* sram, const std::string& filename) { - File::IOFile file(SConfig::GetInstance().m_strSRAM, "rb"); + File::IOFile file(filename, "rb"); if (file) { - if (!file.ReadArray(&g_SRAM, 1)) + if (!file.ReadArray(sram, 1)) { ERROR_LOG_FMT(EXPANSIONINTERFACE, "EXI IPL-DEV: Could not read all of SRAM"); - g_SRAM = sram_dump; + *sram = sram_dump; } } else { - g_SRAM = sram_dump; + *sram = sram_dump; } } -void SetCardFlashID(const u8* buffer, ExpansionInterface::Slot card_slot) +void SetCardFlashID(Sram* sram, const u8* buffer, ExpansionInterface::Slot card_slot) { u8 card_index; switch (card_slot) @@ -96,25 +95,25 @@ void SetCardFlashID(const u8* buffer, ExpansionInterface::Slot card_slot) for (int i = 0; i < 12; i++) { rand = (((rand * (u64)0x0000000041c64e6dULL) + (u64)0x0000000000003039ULL) >> 16); - csum += g_SRAM.settings_ex.flash_id[card_index][i] = buffer[i] - ((u8)rand & 0xff); + csum += sram->settings_ex.flash_id[card_index][i] = buffer[i] - ((u8)rand & 0xff); rand = (((rand * (u64)0x0000000041c64e6dULL) + (u64)0x0000000000003039ULL) >> 16); rand &= (u64)0x0000000000007fffULL; } - g_SRAM.settings_ex.flash_id_checksum[card_index] = csum ^ 0xFF; + sram->settings_ex.flash_id_checksum[card_index] = csum ^ 0xFF; } -void FixSRAMChecksums() +void FixSRAMChecksums(Sram* sram) { // 16bit big-endian additive checksum u16 checksum = 0; u16 checksum_inv = 0; - for (auto p = reinterpret_cast(&g_SRAM.settings.rtc_bias); - p != reinterpret_cast(&g_SRAM.settings_ex); p++) + for (auto p = reinterpret_cast(&sram->settings.rtc_bias); + p != reinterpret_cast(&sram->settings_ex); p++) { u16 value = Common::FromBigEndian(*p); checksum += value; checksum_inv += ~value; } - g_SRAM.settings.checksum = checksum; - g_SRAM.settings.checksum_inv = checksum_inv; + sram->settings.checksum = checksum; + sram->settings.checksum_inv = checksum_inv; } diff --git a/Source/Core/Core/HW/Sram.h b/Source/Core/Core/HW/Sram.h index 92262ca331..3063b9383d 100644 --- a/Source/Core/Core/HW/Sram.h +++ b/Source/Core/Core/HW/Sram.h @@ -34,6 +34,7 @@ distribution. #pragma once #include +#include #include "Common/CommonTypes.h" #include "Common/Swap.h" @@ -133,9 +134,9 @@ static_assert(sizeof(Sram) == 0x44); #pragma pack(pop) -void InitSRAM(); -void SetCardFlashID(const u8* buffer, ExpansionInterface::Slot card_slot); -void FixSRAMChecksums(); +void InitSRAM(Sram* sram, const std::string& filename); +void SetCardFlashID(Sram* sram, const u8* buffer, ExpansionInterface::Slot card_slot); +void FixSRAMChecksums(Sram* sram); extern Sram g_SRAM; extern bool g_SRAM_netplay_initialized; diff --git a/Source/Core/Core/NetPlayServer.cpp b/Source/Core/Core/NetPlayServer.cpp index 64656c64f3..1327ad2e03 100644 --- a/Source/Core/Core/NetPlayServer.cpp +++ b/Source/Core/Core/NetPlayServer.cpp @@ -1440,7 +1440,7 @@ bool NetPlayServer::StartGame() if (!g_SRAM_netplay_initialized) { SConfig::GetInstance().m_strSRAM = File::GetUserPath(F_GCSRAM_IDX); - InitSRAM(); + InitSRAM(&g_SRAM, SConfig::GetInstance().m_strSRAM); g_SRAM_netplay_initialized = true; } sf::Packet srampac;