HW: Remove global state from functions in Sram.h.
This commit is contained in:
parent
720b3f5519
commit
9963637463
|
@ -106,7 +106,7 @@ void Init()
|
||||||
{
|
{
|
||||||
if (!g_SRAM_netplay_initialized)
|
if (!g_SRAM_netplay_initialized)
|
||||||
{
|
{
|
||||||
InitSRAM();
|
InitSRAM(&g_SRAM, SConfig::GetInstance().m_strSRAM);
|
||||||
}
|
}
|
||||||
|
|
||||||
CEXIMemoryCard::Init();
|
CEXIMemoryCard::Init();
|
||||||
|
|
|
@ -136,7 +136,7 @@ CEXIIPL::CEXIIPL()
|
||||||
// you please
|
// you please
|
||||||
g_SRAM.settings.language = Config::Get(Config::MAIN_GC_LANGUAGE);
|
g_SRAM.settings.language = Config::Get(Config::MAIN_GC_LANGUAGE);
|
||||||
g_SRAM.settings.rtc_bias = 0;
|
g_SRAM.settings.rtc_bias = 0;
|
||||||
FixSRAMChecksums();
|
FixSRAMChecksums(&g_SRAM);
|
||||||
}
|
}
|
||||||
|
|
||||||
CEXIIPL::~CEXIIPL()
|
CEXIIPL::~CEXIIPL()
|
||||||
|
|
|
@ -141,7 +141,7 @@ CEXIMemoryCard::CEXIMemoryCard(const Slot slot, bool gci_folder,
|
||||||
m_memory_card_size = m_memory_card->GetCardId() * SIZE_TO_Mb;
|
m_memory_card_size = m_memory_card->GetCardId() * SIZE_TO_Mb;
|
||||||
std::array<u8, 20> header{};
|
std::array<u8, 20> header{};
|
||||||
m_memory_card->Read(0, static_cast<s32>(header.size()), header.data());
|
m_memory_card->Read(0, static_cast<s32>(header.size()), header.data());
|
||||||
SetCardFlashID(header.data(), m_card_slot);
|
SetCardFlashID(&g_SRAM, header.data(), m_card_slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<std::string /* path */, bool /* migrate */>
|
std::pair<std::string /* path */, bool /* migrate */>
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
#include "Common/MsgHandler.h"
|
#include "Common/MsgHandler.h"
|
||||||
#include "Common/Swap.h"
|
#include "Common/Swap.h"
|
||||||
|
|
||||||
#include "Core/ConfigManager.h"
|
|
||||||
#include "Core/HW/EXI/EXI.h"
|
#include "Core/HW/EXI/EXI.h"
|
||||||
|
|
||||||
// English
|
// English
|
||||||
|
@ -58,24 +57,24 @@ const SRAM sram_dump_german = {{
|
||||||
}};
|
}};
|
||||||
#endif
|
#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)
|
||||||
{
|
{
|
||||||
if (!file.ReadArray(&g_SRAM, 1))
|
if (!file.ReadArray(sram, 1))
|
||||||
{
|
{
|
||||||
ERROR_LOG_FMT(EXPANSIONINTERFACE, "EXI IPL-DEV: Could not read all of SRAM");
|
ERROR_LOG_FMT(EXPANSIONINTERFACE, "EXI IPL-DEV: Could not read all of SRAM");
|
||||||
g_SRAM = sram_dump;
|
*sram = sram_dump;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
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;
|
u8 card_index;
|
||||||
switch (card_slot)
|
switch (card_slot)
|
||||||
|
@ -96,25 +95,25 @@ void SetCardFlashID(const u8* buffer, ExpansionInterface::Slot card_slot)
|
||||||
for (int i = 0; i < 12; i++)
|
for (int i = 0; i < 12; i++)
|
||||||
{
|
{
|
||||||
rand = (((rand * (u64)0x0000000041c64e6dULL) + (u64)0x0000000000003039ULL) >> 16);
|
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 = (((rand * (u64)0x0000000041c64e6dULL) + (u64)0x0000000000003039ULL) >> 16);
|
||||||
rand &= (u64)0x0000000000007fffULL;
|
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
|
// 16bit big-endian additive checksum
|
||||||
u16 checksum = 0;
|
u16 checksum = 0;
|
||||||
u16 checksum_inv = 0;
|
u16 checksum_inv = 0;
|
||||||
for (auto p = reinterpret_cast<u16*>(&g_SRAM.settings.rtc_bias);
|
for (auto p = reinterpret_cast<u16*>(&sram->settings.rtc_bias);
|
||||||
p != reinterpret_cast<u16*>(&g_SRAM.settings_ex); p++)
|
p != reinterpret_cast<u16*>(&sram->settings_ex); p++)
|
||||||
{
|
{
|
||||||
u16 value = Common::FromBigEndian(*p);
|
u16 value = Common::FromBigEndian(*p);
|
||||||
checksum += value;
|
checksum += value;
|
||||||
checksum_inv += ~value;
|
checksum_inv += ~value;
|
||||||
}
|
}
|
||||||
g_SRAM.settings.checksum = checksum;
|
sram->settings.checksum = checksum;
|
||||||
g_SRAM.settings.checksum_inv = checksum_inv;
|
sram->settings.checksum_inv = checksum_inv;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ distribution.
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
#include "Common/Swap.h"
|
#include "Common/Swap.h"
|
||||||
|
@ -133,9 +134,9 @@ static_assert(sizeof(Sram) == 0x44);
|
||||||
|
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
||||||
void InitSRAM();
|
void InitSRAM(Sram* sram, const std::string& filename);
|
||||||
void SetCardFlashID(const u8* buffer, ExpansionInterface::Slot card_slot);
|
void SetCardFlashID(Sram* sram, const u8* buffer, ExpansionInterface::Slot card_slot);
|
||||||
void FixSRAMChecksums();
|
void FixSRAMChecksums(Sram* sram);
|
||||||
|
|
||||||
extern Sram g_SRAM;
|
extern Sram g_SRAM;
|
||||||
extern bool g_SRAM_netplay_initialized;
|
extern bool g_SRAM_netplay_initialized;
|
||||||
|
|
|
@ -1440,7 +1440,7 @@ bool NetPlayServer::StartGame()
|
||||||
if (!g_SRAM_netplay_initialized)
|
if (!g_SRAM_netplay_initialized)
|
||||||
{
|
{
|
||||||
SConfig::GetInstance().m_strSRAM = File::GetUserPath(F_GCSRAM_IDX);
|
SConfig::GetInstance().m_strSRAM = File::GetUserPath(F_GCSRAM_IDX);
|
||||||
InitSRAM();
|
InitSRAM(&g_SRAM, SConfig::GetInstance().m_strSRAM);
|
||||||
g_SRAM_netplay_initialized = true;
|
g_SRAM_netplay_initialized = true;
|
||||||
}
|
}
|
||||||
sf::Packet srampac;
|
sf::Packet srampac;
|
||||||
|
|
Loading…
Reference in New Issue