HW: Move g_SRAM to System.

This commit is contained in:
Admiral H. Curtiss 2022-09-14 01:11:04 +02:00
parent 0a517ebdbd
commit c21f2512c8
No known key found for this signature in database
GPG Key ID: F051B4C4044F33FB
7 changed files with 41 additions and 21 deletions

View File

@ -21,10 +21,10 @@
#include "Core/HW/Sram.h"
#include "Core/HW/SystemTimers.h"
#include "Core/Movie.h"
#include "Core/System.h"
#include "DiscIO/Enums.h"
Sram g_SRAM;
bool s_using_overridden_sram = false;
namespace ExpansionInterface
@ -105,14 +105,15 @@ u8 SlotToEXIDevice(Slot slot)
void Init(const Sram* override_sram)
{
auto& sram = Core::System::GetInstance().GetSRAM();
if (override_sram)
{
g_SRAM = *override_sram;
sram = *override_sram;
s_using_overridden_sram = true;
}
else
{
InitSRAM(&g_SRAM, SConfig::GetInstance().m_strSRAM);
InitSRAM(&sram, SConfig::GetInstance().m_strSRAM);
s_using_overridden_sram = false;
}
@ -125,9 +126,9 @@ void Init(const Sram* override_sram)
size_mbits = Memcard::MBIT_SIZE_MEMORY_CARD_59 << size_override;
const bool shift_jis =
Config::ToGameCubeRegion(SConfig::GetInstance().m_region) == DiscIO::Region::NTSC_J;
const CardFlashId& flash_id = g_SRAM.settings_ex.flash_id[Memcard::SLOT_A];
const u32 rtc_bias = g_SRAM.settings.rtc_bias;
const u32 sram_language = static_cast<u32>(g_SRAM.settings.language);
const CardFlashId& flash_id = sram.settings_ex.flash_id[Memcard::SLOT_A];
const u32 rtc_bias = sram.settings.rtc_bias;
const u32 sram_language = static_cast<u32>(sram.settings.language);
const u64 format_time =
Common::Timer::GetLocalTimeSinceJan1970() - ExpansionInterface::CEXIIPL::GC_EPOCH;
@ -162,7 +163,8 @@ void Shutdown()
if (!s_using_overridden_sram)
{
File::IOFile file(SConfig::GetInstance().m_strSRAM, "wb");
file.WriteArray(&g_SRAM, 1);
auto& sram = Core::System::GetInstance().GetSRAM();
file.WriteArray(&sram, 1);
}
}

View File

@ -28,6 +28,7 @@
#include "Core/HW/SystemTimers.h"
#include "Core/Movie.h"
#include "Core/NetPlayProto.h"
#include "Core/System.h"
#include "DiscIO/Enums.h"
@ -129,21 +130,25 @@ CEXIIPL::CEXIIPL()
LoadFontFile((File::GetSysDirectory() + GC_SYS_DIR + DIR_SEP + FONT_WINDOWS_1252), 0x1fcf00);
}
auto& sram = Core::System::GetInstance().GetSRAM();
// Clear RTC
g_SRAM.rtc = 0;
sram.rtc = 0;
// We Overwrite language selection here since it's possible on the GC to change the language as
// you please
g_SRAM.settings.language = Config::Get(Config::MAIN_GC_LANGUAGE);
g_SRAM.settings.rtc_bias = 0;
FixSRAMChecksums(&g_SRAM);
sram.settings.language = Config::Get(Config::MAIN_GC_LANGUAGE);
sram.settings.rtc_bias = 0;
FixSRAMChecksums(&sram);
}
CEXIIPL::~CEXIIPL() = default;
void CEXIIPL::DoState(PointerWrap& p)
{
p.Do(g_SRAM);
auto& sram = Core::System::GetInstance().GetSRAM();
p.Do(sram);
p.Do(g_rtc_flags);
p.Do(m_command);
p.Do(m_command_bytes_received);
@ -246,7 +251,8 @@ void CEXIIPL::SetCS(int cs)
void CEXIIPL::UpdateRTC()
{
g_SRAM.rtc = GetEmulatedTime(GC_EPOCH);
auto& sram = Core::System::GetInstance().GetSRAM();
sram.rtc = GetEmulatedTime(GC_EPOCH);
}
bool CEXIIPL::IsPresent() const
@ -336,11 +342,12 @@ void CEXIIPL::TransferByte(u8& data)
}
else if (IN_RANGE(SRAM))
{
auto& sram = Core::System::GetInstance().GetSRAM();
u32 dev_addr = DEV_ADDR_CURSOR(SRAM);
if (m_command.is_write())
g_SRAM[dev_addr] = data;
sram[dev_addr] = data;
else
data = g_SRAM[dev_addr];
data = sram[dev_addr];
}
else if (IN_RANGE(UART))
{

View File

@ -34,6 +34,7 @@
#include "Core/HW/Sram.h"
#include "Core/HW/SystemTimers.h"
#include "Core/Movie.h"
#include "Core/System.h"
#include "DiscIO/Enums.h"
namespace ExpansionInterface
@ -141,7 +142,8 @@ CEXIMemoryCard::CEXIMemoryCard(const Slot slot, bool gci_folder,
m_memory_card_size = m_memory_card->GetCardId() * SIZE_TO_Mb;
std::array<u8, 20> header{};
m_memory_card->Read(0, static_cast<s32>(header.size()), header.data());
SetCardFlashID(&g_SRAM, header.data(), m_card_slot);
auto& sram = Core::System::GetInstance().GetSRAM();
SetCardFlashID(&sram, header.data(), m_card_slot);
}
std::pair<std::string /* path */, bool /* migrate */>

View File

@ -30,6 +30,7 @@
#include "Core/HW/EXI/EXI_DeviceIPL.h"
#include "Core/HW/GCMemcard/GCMemcard.h"
#include "Core/HW/Sram.h"
#include "Core/System.h"
#define SIZE_TO_Mb (1024 * 8 * 16)
#define MC_HDR_SIZE 0xA000
@ -59,10 +60,11 @@ MemoryCard::MemoryCard(const std::string& filename, ExpansionInterface::Slot car
m_memcard_data = std::make_unique<u8[]>(m_memory_card_size);
// Fills in the first 5 blocks (MC_HDR_SIZE bytes)
const CardFlashId& flash_id = g_SRAM.settings_ex.flash_id[Memcard::SLOT_A];
auto& sram = Core::System::GetInstance().GetSRAM();
const CardFlashId& flash_id = sram.settings_ex.flash_id[Memcard::SLOT_A];
const bool shift_jis = m_filename.find(".JAP.raw") != std::string::npos;
const u32 rtc_bias = g_SRAM.settings.rtc_bias;
const u32 sram_language = static_cast<u32>(g_SRAM.settings.language);
const u32 rtc_bias = sram.settings.rtc_bias;
const u32 sram_language = static_cast<u32>(sram.settings.language);
const u64 format_time =
Common::Timer::GetLocalTimeSinceJan1970() - ExpansionInterface::CEXIIPL::GC_EPOCH;
Memcard::GCMemcard::Format(&m_memcard_data[0], flash_id, size_mbits, shift_jis, rtc_bias,

View File

@ -137,5 +137,3 @@ static_assert(sizeof(Sram) == 0x44);
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;

View File

@ -10,6 +10,7 @@
#include "Core/HW/AudioInterface.h"
#include "Core/HW/DVD/DVDInterface.h"
#include "Core/HW/DVD/DVDThread.h"
#include "Core/HW/Sram.h"
namespace Core
{
@ -22,6 +23,7 @@ struct System::Impl
AudioInterface::AudioInterfaceState m_audio_interface_state;
DVDInterface::DVDInterfaceState m_dvd_interface_state;
DVDThread::DVDThreadState m_dvd_thread_state;
Sram m_sram;
};
System::System() : m_impl{std::make_unique<Impl>()}
@ -80,4 +82,9 @@ DVDThread::DVDThreadState& System::GetDVDThreadState() const
{
return m_impl->m_dvd_thread_state;
}
Sram& System::GetSRAM() const
{
return m_impl->m_sram;
}
} // namespace Core

View File

@ -6,6 +6,7 @@
#include <memory>
class SoundStream;
struct Sram;
namespace AudioInterface
{
@ -56,6 +57,7 @@ public:
AudioInterface::AudioInterfaceState& GetAudioInterfaceState() const;
DVDInterface::DVDInterfaceState& GetDVDInterfaceState() const;
DVDThread::DVDThreadState& GetDVDThreadState() const;
Sram& GetSRAM() const;
private:
System();