Merge pull request #11320 from AdmiralCurtiss/globals-memory

HW/Memmap: Refactor Memory to class, move to Core::System.
This commit is contained in:
Mai
2022-12-07 00:52:31 +00:00
committed by GitHub
83 changed files with 2222 additions and 1361 deletions
+17 -5
View File
@@ -55,6 +55,7 @@ namespace fs = std::filesystem;
#include "Core/PowerPC/PPCAnalyst.h"
#include "Core/PowerPC/PPCSymbolDB.h"
#include "Core/PowerPC/PowerPC.h"
#include "Core/System.h"
#include "DiscIO/Enums.h"
#include "DiscIO/GameModDescriptor.h"
@@ -348,7 +349,10 @@ bool CBoot::DVDRead(const DiscIO::VolumeDisc& disc, u64 dvd_offset, u32 output_a
std::vector<u8> buffer(length);
if (!disc.Read(dvd_offset, length, buffer.data(), partition))
return false;
Memory::CopyToEmu(output_address, buffer.data(), length);
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
memory.CopyToEmu(output_address, buffer.data(), length);
return true;
}
@@ -357,7 +361,11 @@ bool CBoot::DVDReadDiscID(const DiscIO::VolumeDisc& disc, u32 output_address)
std::array<u8, 0x20> buffer;
if (!disc.Read(0, buffer.size(), buffer.data(), DiscIO::PARTITION_NONE))
return false;
Memory::CopyToEmu(output_address, buffer.data(), buffer.size());
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
memory.CopyToEmu(output_address, buffer.data(), buffer.size());
// Transition out of the DiscIdNotRead state (which the drive should be in at this point,
// on the assumption that this is only used for the first read)
DVDInterface::SetDriveState(DVDInterface::DriveState::ReadyNoReadsMade);
@@ -455,8 +463,10 @@ bool CBoot::Load_BS2(const std::string& boot_rom_filename)
// copying the initial boot code to 0x81200000 is a hack.
// For now, HLE the first few instructions and start at 0x81200150
// to work around this.
Memory::CopyToEmu(0x01200000, data.data() + 0x100, 0x700);
Memory::CopyToEmu(0x01300000, data.data() + 0x820, 0x1AFE00);
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
memory.CopyToEmu(0x01200000, data.data() + 0x100, 0x700);
memory.CopyToEmu(0x01300000, data.data() + 0x820, 0x1AFE00);
PowerPC::ppcState.gpr[3] = 0xfff0001f;
PowerPC::ppcState.gpr[4] = 0x00002030;
@@ -491,9 +501,11 @@ static void CopyDefaultExceptionHandlers()
0x00000900, 0x00000C00, 0x00000D00, 0x00000F00,
0x00001300, 0x00001400, 0x00001700};
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
constexpr u32 RFI_INSTRUCTION = 0x4C000064;
for (const u32 address : EXCEPTION_HANDLER_ADDRESSES)
Memory::Write_U32(RFI_INSTRUCTION, address);
memory.Write_U32(RFI_INSTRUCTION, address);
}
// Third boot step after BootManager and Core. See Call schedule in BootManager.cpp
+45 -33
View File
@@ -32,6 +32,7 @@
#include "Core/IOS/Uids.h"
#include "Core/PowerPC/MMU.h"
#include "Core/PowerPC/PowerPC.h"
#include "Core/System.h"
#include "DiscIO/Enums.h"
#include "DiscIO/RiivolutionPatcher.h"
@@ -212,11 +213,14 @@ bool CBoot::RunApploader(bool is_wii, const DiscIO::VolumeDisc& volume,
void CBoot::SetupGCMemory()
{
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
// Booted from bootrom. 0xE5207C22 = booted from jtag
PowerPC::HostWrite_U32(0x0D15EA5E, 0x80000020);
// Physical Memory Size (24MB on retail)
PowerPC::HostWrite_U32(Memory::GetRamSizeReal(), 0x80000028);
PowerPC::HostWrite_U32(memory.GetRamSizeReal(), 0x80000028);
// Console type - DevKit (retail ID == 0x00000003) see YAGCD 4.2.1.1.2
// TODO: determine why some games fail when using a retail ID.
@@ -271,10 +275,12 @@ bool CBoot::EmulatedBS2_GC(const DiscIO::VolumeDisc& volume,
DVDReadDiscID(volume, 0x00000000);
bool streaming = Memory::Read_U8(0x80000008);
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
bool streaming = memory.Read_U8(0x80000008);
if (streaming)
{
u8 streaming_size = Memory::Read_U8(0x80000009);
u8 streaming_size = memory.Read_U8(0x80000009);
// If the streaming buffer size is 0, then BS2 uses a default size of 10 instead.
// No known game uses a size other than the default.
if (streaming_size == 0)
@@ -412,8 +418,11 @@ bool CBoot::SetupWiiMemory(IOS::HLE::IOSC::ConsoleType console_type)
return false;
}
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
// Write the 256 byte setting.txt to memory.
Memory::CopyToEmu(0x3800, gen.GetBytes().data(), gen.GetBytes().size());
memory.CopyToEmu(0x3800, gen.GetBytes().data(), gen.GetBytes().size());
INFO_LOG_FMT(BOOT, "Setup Wii Memory...");
@@ -427,28 +436,28 @@ bool CBoot::SetupWiiMemory(IOS::HLE::IOSC::ConsoleType console_type)
0x80000060 Copyright code
*/
Memory::Write_U32(0x0D15EA5E, 0x00000020); // Another magic word
Memory::Write_U32(0x00000001, 0x00000024); // Unknown
Memory::Write_U32(Memory::GetRamSizeReal(), 0x00000028); // MEM1 size 24MB
memory.Write_U32(0x0D15EA5E, 0x00000020); // Another magic word
memory.Write_U32(0x00000001, 0x00000024); // Unknown
memory.Write_U32(memory.GetRamSizeReal(), 0x00000028); // MEM1 size 24MB
const Core::ConsoleType board_model = console_type == IOS::HLE::IOSC::ConsoleType::RVT ?
Core::ConsoleType::NDEV2_1 :
Core::ConsoleType::RVL_Retail3;
Memory::Write_U32(static_cast<u32>(board_model), 0x0000002c); // Board Model
Memory::Write_U32(0x00000000, 0x00000030); // Init
Memory::Write_U32(0x817FEC60, 0x00000034); // Init
memory.Write_U32(static_cast<u32>(board_model), 0x0000002c); // Board Model
memory.Write_U32(0x00000000, 0x00000030); // Init
memory.Write_U32(0x817FEC60, 0x00000034); // Init
// 38, 3C should get start, size of FST through apploader
Memory::Write_U32(0x8008f7b8, 0x000000e4); // Thread Init
Memory::Write_U32(Memory::GetRamSizeReal(), 0x000000f0); // "Simulated memory size" (debug mode?)
Memory::Write_U32(0x8179b500, 0x000000f4); // __start
Memory::Write_U32(0x0e7be2c0, 0x000000f8); // Bus speed
Memory::Write_U32(0x2B73A840, 0x000000fc); // CPU speed
Memory::Write_U16(0x0000, 0x000030e6); // Console type
Memory::Write_U32(0x00000000, 0x000030c0); // EXI
Memory::Write_U32(0x00000000, 0x000030c4); // EXI
Memory::Write_U32(0x00000000, 0x000030dc); // Time
Memory::Write_U32(0xffffffff, 0x000030d8); // Unknown, set by any official NAND title
Memory::Write_U16(0x8201, 0x000030e6); // Dev console / debug capable
Memory::Write_U32(0x00000000, 0x000030f0); // Apploader
memory.Write_U32(0x8008f7b8, 0x000000e4); // Thread Init
memory.Write_U32(memory.GetRamSizeReal(), 0x000000f0); // "Simulated memory size" (debug mode?)
memory.Write_U32(0x8179b500, 0x000000f4); // __start
memory.Write_U32(0x0e7be2c0, 0x000000f8); // Bus speed
memory.Write_U32(0x2B73A840, 0x000000fc); // CPU speed
memory.Write_U16(0x0000, 0x000030e6); // Console type
memory.Write_U32(0x00000000, 0x000030c0); // EXI
memory.Write_U32(0x00000000, 0x000030c4); // EXI
memory.Write_U32(0x00000000, 0x000030dc); // Time
memory.Write_U32(0xffffffff, 0x000030d8); // Unknown, set by any official NAND title
memory.Write_U16(0x8201, 0x000030e6); // Dev console / debug capable
memory.Write_U32(0x00000000, 0x000030f0); // Apploader
// During the boot process, 0x315c is first set to 0xdeadbeef by IOS
// in the boot_ppc syscall. The value is then partly overwritten by SDK titles.
@@ -457,19 +466,19 @@ bool CBoot::SetupWiiMemory(IOS::HLE::IOSC::ConsoleType console_type)
//
// 0x0113 appears to mean v1.13, which is the latest version.
// It is fine to always use the latest value as apploaders work with all versions.
Memory::Write_U16(0x0113, 0x0000315e);
memory.Write_U16(0x0113, 0x0000315e);
Memory::Write_U8(0x80, 0x0000315c); // OSInit
Memory::Write_U16(0x0000, 0x000030e0); // PADInit
Memory::Write_U32(0x80000000, 0x00003184); // GameID Address
memory.Write_U8(0x80, 0x0000315c); // OSInit
memory.Write_U16(0x0000, 0x000030e0); // PADInit
memory.Write_U32(0x80000000, 0x00003184); // GameID Address
// Fake the VI Init of the IPL
Memory::Write_U32(DiscIO::IsNTSC(SConfig::GetInstance().m_region) ? 0 : 1, 0x000000CC);
memory.Write_U32(DiscIO::IsNTSC(SConfig::GetInstance().m_region) ? 0 : 1, 0x000000CC);
// Clear exception handler. Why? Don't we begin with only zeros?
for (int i = 0x3000; i <= 0x3038; i += 4)
{
Memory::Write_U32(0x00000000, i);
memory.Write_U32(0x00000000, i);
}
return true;
@@ -513,6 +522,9 @@ bool CBoot::EmulatedBS2_Wii(const DiscIO::VolumeDisc& volume,
state->discstate = 0x01;
});
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
// The system menu clears the RTC flags.
// However, the system menu also updates the disc cache when this happens; see
// https://wiibrew.org/wiki/MX23L4005#DI and
@@ -526,8 +538,8 @@ bool CBoot::EmulatedBS2_Wii(const DiscIO::VolumeDisc& volume,
// When launching the disc game, it copies the partition type and offset to 0x3194
// and 0x3198 respectively.
const DiscIO::Partition data_partition = volume.GetGamePartition();
Memory::Write_U32(0, 0x3194);
Memory::Write_U32(static_cast<u32>(data_partition.offset >> 2), 0x3198);
memory.Write_U32(0, 0x3194);
memory.Write_U32(static_cast<u32>(data_partition.offset >> 2), 0x3198);
const s32 ios_override = Config::Get(Config::MAIN_OVERRIDE_BOOT_IOS);
const u64 ios = ios_override >= 0 ? Titles::IOS(static_cast<u32>(ios_override)) : tmd.GetIOSId();
@@ -554,9 +566,9 @@ bool CBoot::EmulatedBS2_Wii(const DiscIO::VolumeDisc& volume,
SetupHID(/*is_wii*/ true);
SetupBAT(/*is_wii*/ true);
Memory::Write_U32(0x4c000064, 0x00000300); // Write default DSI Handler: rfi
Memory::Write_U32(0x4c000064, 0x00000800); // Write default FPU Handler: rfi
Memory::Write_U32(0x4c000064, 0x00000C00); // Write default Syscall Handler: rfi
memory.Write_U32(0x4c000064, 0x00000300); // Write default DSI Handler: rfi
memory.Write_U32(0x4c000064, 0x00000800); // Write default FPU Handler: rfi
memory.Write_U32(0x4c000064, 0x00000C00); // Write default Syscall Handler: rfi
PowerPC::ppcState.gpr[1] = 0x816ffff0; // StackPointer
+19 -8
View File
@@ -12,6 +12,7 @@
#include "Common/Swap.h"
#include "Core/Boot/AncastTypes.h"
#include "Core/HW/Memmap.h"
#include "Core/System.h"
DolReader::DolReader(std::vector<u8> buffer) : BootExecutableReader(std::move(buffer))
{
@@ -117,25 +118,32 @@ bool DolReader::LoadIntoMemory(bool only_in_mem1) const
if (m_is_ancast)
return LoadAncastIntoMemory();
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
// load all text (code) sections
for (size_t i = 0; i < m_text_sections.size(); ++i)
{
if (!m_text_sections[i].empty() &&
!(only_in_mem1 &&
m_dolheader.textAddress[i] + m_text_sections[i].size() >= Memory::GetRamSizeReal()))
m_dolheader.textAddress[i] + m_text_sections[i].size() >= memory.GetRamSizeReal()))
{
Memory::CopyToEmu(m_dolheader.textAddress[i], m_text_sections[i].data(),
m_text_sections[i].size());
memory.CopyToEmu(m_dolheader.textAddress[i], m_text_sections[i].data(),
m_text_sections[i].size());
}
}
// load all data sections
for (size_t i = 0; i < m_data_sections.size(); ++i)
{
if (!m_data_sections[i].empty() &&
!(only_in_mem1 &&
m_dolheader.dataAddress[i] + m_data_sections[i].size() >= Memory::GetRamSizeReal()))
m_dolheader.dataAddress[i] + m_data_sections[i].size() >= memory.GetRamSizeReal()))
{
Memory::CopyToEmu(m_dolheader.dataAddress[i], m_data_sections[i].data(),
m_data_sections[i].size());
memory.CopyToEmu(m_dolheader.dataAddress[i], m_data_sections[i].data(),
m_data_sections[i].size());
}
}
return true;
}
@@ -219,11 +227,14 @@ bool DolReader::LoadAncastIntoMemory() const
body_size))
return false;
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
// Copy the Ancast header to the emu
Memory::CopyToEmu(section_address, header, sizeof(EspressoAncastHeader));
memory.CopyToEmu(section_address, header, sizeof(EspressoAncastHeader));
// Copy the decrypted body to the emu
Memory::CopyToEmu(section_address + sizeof(EspressoAncastHeader), decrypted.data(), body_size);
memory.CopyToEmu(section_address + sizeof(EspressoAncastHeader), decrypted.data(), body_size);
return true;
}
+7 -3
View File
@@ -14,6 +14,7 @@
#include "Core/HW/Memmap.h"
#include "Core/PowerPC/PPCSymbolDB.h"
#include "Core/System.h"
static void bswap(u32& w)
{
@@ -135,6 +136,9 @@ bool ElfReader::LoadIntoMemory(bool only_in_mem1) const
INFO_LOG_FMT(BOOT, "{} segments:", header->e_phnum);
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
// Copy segments into ram.
for (int i = 0; i < header->e_phnum; i++)
{
@@ -150,12 +154,12 @@ bool ElfReader::LoadIntoMemory(bool only_in_mem1) const
u32 srcSize = p->p_filesz;
u32 dstSize = p->p_memsz;
if (only_in_mem1 && p->p_vaddr >= Memory::GetRamSizeReal())
if (only_in_mem1 && p->p_vaddr >= memory.GetRamSizeReal())
continue;
Memory::CopyToEmu(writeAddr, src, srcSize);
memory.CopyToEmu(writeAddr, src, srcSize);
if (srcSize < dstSize)
Memory::Memset(writeAddr + srcSize, 0, dstSize - srcSize); // zero out bss
memory.Memset(writeAddr + srcSize, 0, dstSize - srcSize); // zero out bss
INFO_LOG_FMT(BOOT, "Loadable Segment Copied to {:08x}, size {:08x}", writeAddr, p->p_memsz);
}
+10 -6
View File
@@ -13,6 +13,7 @@
#include "Common/MsgHandler.h"
#include "Core/Config/MainSettings.h"
#include "Core/HW/Memmap.h"
#include "Core/System.h"
constexpr u32 FILE_ID = 0x0d01f1f0;
constexpr u32 VERSION_NUMBER = 5;
@@ -161,8 +162,10 @@ bool FifoDataFile::Save(const std::string& filename)
header.flags = m_Flags;
header.mem1_size = Memory::GetRamSizeReal();
header.mem2_size = Memory::GetExRamSizeReal();
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
header.mem1_size = memory.GetRamSizeReal();
header.mem2_size = memory.GetExRamSizeReal();
file.Seek(0, File::SeekOrigin::Begin);
file.WriteBytes(&header, sizeof(FileHeader));
@@ -267,14 +270,15 @@ std::unique_ptr<FifoDataFile> FifoDataFile::Load(const std::string& filename, bo
// It should be noted, however, that Dolphin *will still crash* from the nullptr being returned
// in a non-flagsOnly context, so if this code becomes necessary, it should be moved above the
// prior conditional.
if (header.mem1_size != Memory::GetRamSizeReal() ||
header.mem2_size != Memory::GetExRamSizeReal())
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
if (header.mem1_size != memory.GetRamSizeReal() || header.mem2_size != memory.GetExRamSizeReal())
{
CriticalAlertFmtT("Emulated memory size mismatch!\n"
"Current: MEM1 {0:08X} ({1} MiB), MEM2 {2:08X} ({3} MiB)\n"
"DFF: MEM1 {4:08X} ({5} MiB), MEM2 {6:08X} ({7} MiB)",
Memory::GetRamSizeReal(), Memory::GetRamSizeReal() / 0x100000,
Memory::GetExRamSizeReal(), Memory::GetExRamSizeReal() / 0x100000,
memory.GetRamSizeReal(), memory.GetRamSizeReal() / 0x100000,
memory.GetExRamSizeReal(), memory.GetExRamSizeReal() / 0x100000,
header.mem1_size, header.mem1_size / 0x100000, header.mem2_size,
header.mem2_size / 0x100000);
return nullptr;
+4 -2
View File
@@ -494,12 +494,14 @@ void FifoPlayer::WriteAllMemoryUpdates()
void FifoPlayer::WriteMemory(const MemoryUpdate& memUpdate)
{
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
u8* mem = nullptr;
if (memUpdate.address & 0x10000000)
mem = &Memory::m_pEXRAM[memUpdate.address & Memory::GetExRamMask()];
mem = &memory.GetEXRAM()[memUpdate.address & memory.GetExRamMask()];
else
mem = &Memory::m_pRAM[memUpdate.address & Memory::GetRamMask()];
mem = &memory.GetRAM()[memUpdate.address & memory.GetRamMask()];
std::copy(memUpdate.data.begin(), memUpdate.data.end(), mem);
}
+12 -6
View File
@@ -12,6 +12,7 @@
#include "Core/ConfigManager.h"
#include "Core/HW/Memmap.h"
#include "Core/System.h"
#include "VideoCommon/OpcodeDecoding.h"
#include "VideoCommon/XFStructs.h"
@@ -229,8 +230,10 @@ void FifoRecorder::StartRecording(s32 numFrames, CallbackFunc finishedCb)
// - Global variables suck
// - Multithreading with the above two sucks
//
m_Ram.resize(Memory::GetRamSize());
m_ExRam.resize(Memory::GetExRamSize());
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
m_Ram.resize(memory.GetRamSize());
m_ExRam.resize(memory.GetExRamSize());
std::fill(m_Ram.begin(), m_Ram.end(), 0);
std::fill(m_ExRam.begin(), m_ExRam.end(), 0);
@@ -310,17 +313,20 @@ void FifoRecorder::WriteGPCommand(const u8* data, u32 size)
void FifoRecorder::UseMemory(u32 address, u32 size, MemoryUpdate::Type type, bool dynamicUpdate)
{
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
u8* curData;
u8* newData;
if (address & 0x10000000)
{
curData = &m_ExRam[address & Memory::GetExRamMask()];
newData = &Memory::m_pEXRAM[address & Memory::GetExRamMask()];
curData = &m_ExRam[address & memory.GetExRamMask()];
newData = &memory.GetEXRAM()[address & memory.GetExRamMask()];
}
else
{
curData = &m_Ram[address & Memory::GetRamMask()];
newData = &Memory::m_pRAM[address & Memory::GetRamMask()];
curData = &m_Ram[address & memory.GetRamMask()];
newData = &memory.GetRAM()[address & memory.GetRamMask()];
}
if (!dynamicUpdate && memcmp(curData, newData, size) != 0)
+4 -1
View File
@@ -19,6 +19,7 @@
#include "Core/IOS/ES/ES.h"
#include "Core/PowerPC/PPCSymbolDB.h"
#include "Core/PowerPC/PowerPC.h"
#include "Core/System.h"
namespace HLE
{
@@ -90,7 +91,9 @@ void PatchFixedFunctions()
if (!Config::Get(Config::MAIN_ENABLE_CHEATS))
{
Patch(0x80001800, "HBReload");
Memory::CopyToEmu(0x00001804, "STUBHAXX", 8);
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
memory.CopyToEmu(0x00001804, "STUBHAXX", 8);
}
// Not part of the binary itself, but either we or Gecko OS might insert
+11 -4
View File
@@ -10,6 +10,7 @@
#include "Core/HW/DSP.h"
#include "Core/HW/Memmap.h"
#include "Core/PowerPC/MMU.h"
#include "Core/System.h"
namespace AddressSpace
{
@@ -92,6 +93,9 @@ struct EffectiveAddressSpaceAccessors : Accessors
bool Matches(u32 haystack_start, const u8* needle_start, std::size_t needle_size) const
{
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
u32 page_base = haystack_start & 0xfffff000;
u32 offset = haystack_start & 0x0000fff;
do
@@ -114,7 +118,7 @@ struct EffectiveAddressSpaceAccessors : Accessors
return false;
}
u8* page_ptr = Memory::GetPointer(*page_physical_address);
u8* page_ptr = memory.GetPointer(*page_physical_address);
if (page_ptr == nullptr)
{
return false;
@@ -417,9 +421,12 @@ Accessors* GetAccessors(Type address_space)
void Init()
{
s_mem1_address_space_accessors = {&Memory::m_pRAM, Memory::GetRamSizeReal()};
s_mem2_address_space_accessors = {&Memory::m_pEXRAM, Memory::GetExRamSizeReal()};
s_fake_address_space_accessors = {&Memory::m_pFakeVMEM, Memory::GetFakeVMemSize()};
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
s_mem1_address_space_accessors = {&memory.GetRAM(), memory.GetRamSizeReal()};
s_mem2_address_space_accessors = {&memory.GetEXRAM(), memory.GetExRamSizeReal()};
s_fake_address_space_accessors = {&memory.GetFakeVMEM(), memory.GetFakeVMemSize()};
s_physical_address_space_accessors_gcn = {{0x00000000, &s_mem1_address_space_accessors}};
s_physical_address_space_accessors_wii = {{0x00000000, &s_mem1_address_space_accessors},
{0x10000000, &s_mem2_address_space_accessors}};
+29 -19
View File
@@ -205,16 +205,18 @@ void Init(bool hle)
void Reinit(bool hle)
{
auto& state = Core::System::GetInstance().GetDSPState().GetData();
auto& system = Core::System::GetInstance();
auto& state = system.GetDSPState().GetData();
state.dsp_emulator = CreateDSPEmulator(hle);
state.is_lle = state.dsp_emulator->IsLLE();
if (SConfig::GetInstance().bWii)
{
auto& memory = system.GetMemory();
state.aram.wii_mode = true;
state.aram.size = Memory::GetExRamSizeReal();
state.aram.mask = Memory::GetExRamMask();
state.aram.ptr = Memory::m_pEXRAM;
state.aram.size = memory.GetExRamSizeReal();
state.aram.mask = memory.GetExRamMask();
state.aram.ptr = memory.GetEXRAM();
}
else
{
@@ -527,7 +529,8 @@ void UpdateAudioDMA()
// Read audio at g_audioDMA.current_source_address in RAM and push onto an
// external audio fifo in the emulator, to be mixed with the disc
// streaming output.
void* address = Memory::GetPointer(state.audio_dma.current_source_address);
auto& memory = system.GetMemory();
void* address = memory.GetPointer(state.audio_dma.current_source_address);
AudioCommon::SendAIBuffer(system, reinterpret_cast<short*>(address), 8);
if (state.audio_dma.remaining_blocks_count != 0)
@@ -554,6 +557,7 @@ static void Do_ARAM_DMA()
{
auto& system = Core::System::GetInstance();
auto& core_timing = system.GetCoreTiming();
auto& memory = system.GetMemory();
auto& state = system.GetDSPState().GetData();
state.dsp_control.DMAState = 1;
@@ -581,18 +585,18 @@ static void Do_ARAM_DMA()
// See below in the write section for more information
if ((state.aram_info.Hex & 0xf) == 3)
{
Memory::Write_U64_Swap(*(u64*)&state.aram.ptr[state.aram_dma.ARAddr & state.aram.mask],
state.aram_dma.MMAddr);
memory.Write_U64_Swap(*(u64*)&state.aram.ptr[state.aram_dma.ARAddr & state.aram.mask],
state.aram_dma.MMAddr);
}
else if ((state.aram_info.Hex & 0xf) == 4)
{
Memory::Write_U64_Swap(*(u64*)&state.aram.ptr[state.aram_dma.ARAddr & state.aram.mask],
state.aram_dma.MMAddr);
memory.Write_U64_Swap(*(u64*)&state.aram.ptr[state.aram_dma.ARAddr & state.aram.mask],
state.aram_dma.MMAddr);
}
else
{
Memory::Write_U64_Swap(*(u64*)&state.aram.ptr[state.aram_dma.ARAddr & state.aram.mask],
state.aram_dma.MMAddr);
memory.Write_U64_Swap(*(u64*)&state.aram.ptr[state.aram_dma.ARAddr & state.aram.mask],
state.aram_dma.MMAddr);
}
state.aram_dma.MMAddr += 8;
@@ -604,7 +608,7 @@ static void Do_ARAM_DMA()
{
while (state.aram_dma.Cnt.count)
{
Memory::Write_U64(HSP::Read(state.aram_dma.ARAddr), state.aram_dma.MMAddr);
memory.Write_U64(HSP::Read(state.aram_dma.ARAddr), state.aram_dma.MMAddr);
state.aram_dma.MMAddr += 8;
state.aram_dma.ARAddr += 8;
state.aram_dma.Cnt.count -= 8;
@@ -628,22 +632,22 @@ static void Do_ARAM_DMA()
if ((state.aram_info.Hex & 0xf) == 3)
{
*(u64*)&state.aram.ptr[state.aram_dma.ARAddr & state.aram.mask] =
Common::swap64(Memory::Read_U64(state.aram_dma.MMAddr));
Common::swap64(memory.Read_U64(state.aram_dma.MMAddr));
}
else if ((state.aram_info.Hex & 0xf) == 4)
{
if (state.aram_dma.ARAddr < 0x400000)
{
*(u64*)&state.aram.ptr[(state.aram_dma.ARAddr + 0x400000) & state.aram.mask] =
Common::swap64(Memory::Read_U64(state.aram_dma.MMAddr));
Common::swap64(memory.Read_U64(state.aram_dma.MMAddr));
}
*(u64*)&state.aram.ptr[state.aram_dma.ARAddr & state.aram.mask] =
Common::swap64(Memory::Read_U64(state.aram_dma.MMAddr));
Common::swap64(memory.Read_U64(state.aram_dma.MMAddr));
}
else
{
*(u64*)&state.aram.ptr[state.aram_dma.ARAddr & state.aram.mask] =
Common::swap64(Memory::Read_U64(state.aram_dma.MMAddr));
Common::swap64(memory.Read_U64(state.aram_dma.MMAddr));
}
state.aram_dma.MMAddr += 8;
@@ -655,7 +659,7 @@ static void Do_ARAM_DMA()
{
while (state.aram_dma.Cnt.count)
{
HSP::Write(state.aram_dma.ARAddr, Memory::Read_U64(state.aram_dma.MMAddr));
HSP::Write(state.aram_dma.ARAddr, memory.Read_U64(state.aram_dma.MMAddr));
state.aram_dma.MMAddr += 8;
state.aram_dma.ARAddr += 8;
@@ -670,14 +674,20 @@ static void Do_ARAM_DMA()
// (LM) It just means that DSP reads via '0xffdd' on Wii can end up in EXRAM or main RAM
u8 ReadARAM(u32 address)
{
auto& state = Core::System::GetInstance().GetDSPState().GetData();
auto& system = Core::System::GetInstance();
auto& state = system.GetDSPState().GetData();
if (state.aram.wii_mode)
{
if (address & 0x10000000)
{
return state.aram.ptr[address & state.aram.mask];
}
else
return Memory::Read_U8(address & Memory::GetRamMask());
{
auto& memory = system.GetMemory();
return memory.Read_U8(address & memory.GetRamMask());
}
}
else
{
+4 -1
View File
@@ -19,6 +19,7 @@
#include "Common/Swap.h"
#include "Core/HW/DSPHLE/UCodes/UCodes.h"
#include "Core/HW/Memmap.h"
#include "Core/System.h"
namespace DSP::HLE
{
@@ -142,8 +143,10 @@ protected:
template <int Millis, size_t BufCount>
void InitMixingBuffers(u32 init_addr, const std::array<BufferDesc, BufCount>& buffers)
{
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
std::array<u16, 3 * BufCount> init_array;
Memory::CopyFromEmuSwapped(init_array.data(), init_addr, sizeof(init_array));
memory.CopyFromEmuSwapped(init_array.data(), init_addr, sizeof(init_array));
for (size_t i = 0; i < BufCount; ++i)
{
const BufferDesc& buf = buffers[i];
+13 -6
View File
@@ -22,6 +22,7 @@
#include "Core/HW/DSPHLE/UCodes/AX.h"
#include "Core/HW/DSPHLE/UCodes/AXStructs.h"
#include "Core/HW/Memmap.h"
#include "Core/System.h"
namespace DSP::HLE
{
@@ -101,10 +102,13 @@ bool HasLpf(u32 crc)
// Read a PB from MRAM/ARAM
void ReadPB(u32 addr, PB_TYPE& pb, u32 crc)
{
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
if (HasLpf(crc))
{
u16* dst = (u16*)&pb;
Memory::CopyFromEmuSwapped<u16>(dst, addr, sizeof(pb));
memory.CopyFromEmuSwapped<u16>(dst, addr, sizeof(pb));
}
else
{
@@ -116,19 +120,22 @@ void ReadPB(u32 addr, PB_TYPE& pb, u32 crc)
constexpr size_t lpf_off = offsetof(AXPB, lpf);
constexpr size_t lc_off = offsetof(AXPB, loop_counter);
Memory::CopyFromEmuSwapped<u16>((u16*)dst, addr, lpf_off);
memory.CopyFromEmuSwapped<u16>((u16*)dst, addr, lpf_off);
memset(dst + lpf_off, 0, lc_off - lpf_off);
Memory::CopyFromEmuSwapped<u16>((u16*)(dst + lc_off), addr + lpf_off, sizeof(pb) - lc_off);
memory.CopyFromEmuSwapped<u16>((u16*)(dst + lc_off), addr + lpf_off, sizeof(pb) - lc_off);
}
}
// Write a PB back to MRAM/ARAM
void WritePB(u32 addr, const PB_TYPE& pb, u32 crc)
{
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
if (HasLpf(crc))
{
const u16* src = (const u16*)&pb;
Memory::CopyToEmuSwapped<u16>(addr, src, sizeof(pb));
memory.CopyToEmuSwapped<u16>(addr, src, sizeof(pb));
}
else
{
@@ -140,8 +147,8 @@ void WritePB(u32 addr, const PB_TYPE& pb, u32 crc)
constexpr size_t lpf_off = offsetof(AXPB, lpf);
constexpr size_t lc_off = offsetof(AXPB, loop_counter);
Memory::CopyToEmuSwapped<u16>(addr, (const u16*)src, lpf_off);
Memory::CopyToEmuSwapped<u16>(addr + lpf_off, (const u16*)(src + lc_off), sizeof(pb) - lc_off);
memory.CopyToEmuSwapped<u16>(addr, (const u16*)src, lpf_off);
memory.CopyToEmuSwapped<u16>(addr + lpf_off, (const u16*)(src + lc_off), sizeof(pb) - lc_off);
}
}
+41 -17
View File
@@ -30,6 +30,7 @@
#include "Core/HW/DSPHLE/UCodes/ROM.h"
#include "Core/HW/DSPHLE/UCodes/Zelda.h"
#include "Core/HW/Memmap.h"
#include "Core/System.h"
namespace DSP::HLE
{
@@ -40,28 +41,37 @@ constexpr bool ExramRead(u32 address)
u8 HLEMemory_Read_U8(u32 address)
{
if (ExramRead(address))
return Memory::m_pEXRAM[address & Memory::GetExRamMask()];
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
return Memory::m_pRAM[address & Memory::GetRamMask()];
if (ExramRead(address))
return memory.GetEXRAM()[address & memory.GetExRamMask()];
return memory.GetRAM()[address & memory.GetRamMask()];
}
void HLEMemory_Write_U8(u32 address, u8 value)
{
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
if (ExramRead(address))
Memory::m_pEXRAM[address & Memory::GetExRamMask()] = value;
memory.GetEXRAM()[address & memory.GetExRamMask()] = value;
else
Memory::m_pRAM[address & Memory::GetRamMask()] = value;
memory.GetRAM()[address & memory.GetRamMask()] = value;
}
u16 HLEMemory_Read_U16LE(u32 address)
{
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
u16 value;
if (ExramRead(address))
std::memcpy(&value, &Memory::m_pEXRAM[address & Memory::GetExRamMask()], sizeof(u16));
std::memcpy(&value, &memory.GetEXRAM()[address & memory.GetExRamMask()], sizeof(u16));
else
std::memcpy(&value, &Memory::m_pRAM[address & Memory::GetRamMask()], sizeof(u16));
std::memcpy(&value, &memory.GetRAM()[address & memory.GetRamMask()], sizeof(u16));
return value;
}
@@ -73,10 +83,13 @@ u16 HLEMemory_Read_U16(u32 address)
void HLEMemory_Write_U16LE(u32 address, u16 value)
{
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
if (ExramRead(address))
std::memcpy(&Memory::m_pEXRAM[address & Memory::GetExRamMask()], &value, sizeof(u16));
std::memcpy(&memory.GetEXRAM()[address & memory.GetExRamMask()], &value, sizeof(u16));
else
std::memcpy(&Memory::m_pRAM[address & Memory::GetRamMask()], &value, sizeof(u16));
std::memcpy(&memory.GetRAM()[address & memory.GetRamMask()], &value, sizeof(u16));
}
void HLEMemory_Write_U16(u32 address, u16 value)
@@ -86,12 +99,15 @@ void HLEMemory_Write_U16(u32 address, u16 value)
u32 HLEMemory_Read_U32LE(u32 address)
{
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
u32 value;
if (ExramRead(address))
std::memcpy(&value, &Memory::m_pEXRAM[address & Memory::GetExRamMask()], sizeof(u32));
std::memcpy(&value, &memory.GetEXRAM()[address & memory.GetExRamMask()], sizeof(u32));
else
std::memcpy(&value, &Memory::m_pRAM[address & Memory::GetRamMask()], sizeof(u32));
std::memcpy(&value, &memory.GetRAM()[address & memory.GetRamMask()], sizeof(u32));
return value;
}
@@ -103,10 +119,13 @@ u32 HLEMemory_Read_U32(u32 address)
void HLEMemory_Write_U32LE(u32 address, u32 value)
{
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
if (ExramRead(address))
std::memcpy(&Memory::m_pEXRAM[address & Memory::GetExRamMask()], &value, sizeof(u32));
std::memcpy(&memory.GetEXRAM()[address & memory.GetExRamMask()], &value, sizeof(u32));
else
std::memcpy(&Memory::m_pRAM[address & Memory::GetRamMask()], &value, sizeof(u32));
std::memcpy(&memory.GetRAM()[address & memory.GetRamMask()], &value, sizeof(u32));
}
void HLEMemory_Write_U32(u32 address, u32 value)
@@ -116,10 +135,13 @@ void HLEMemory_Write_U32(u32 address, u32 value)
void* HLEMemory_Get_Pointer(u32 address)
{
if (ExramRead(address))
return &Memory::m_pEXRAM[address & Memory::GetExRamMask()];
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
return &Memory::m_pRAM[address & Memory::GetRamMask()];
if (ExramRead(address))
return &memory.GetEXRAM()[address & memory.GetExRamMask()];
return &memory.GetRAM()[address & memory.GetRamMask()];
}
UCodeInterface::UCodeInterface(DSPHLE* dsphle, u32 crc)
@@ -188,7 +210,9 @@ void UCodeInterface::PrepareBootUCode(u32 mail)
if (Config::Get(Config::MAIN_DUMP_UCODE))
{
DSP::DumpDSPCode(Memory::GetPointer(m_next_ucode.iram_mram_addr), m_next_ucode.iram_size,
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
DSP::DumpDSPCode(memory.GetPointer(m_next_ucode.iram_mram_addr), m_next_ucode.iram_size,
ector_crc);
}
+10 -3
View File
@@ -18,6 +18,7 @@
#include "Core/HW/DSPLLE/DSPSymbols.h"
#include "Core/HW/Memmap.h"
#include "Core/Host.h"
#include "Core/System.h"
#include "VideoCommon/OnScreenDisplay.h"
// The user of the DSPCore library must supply a few functions so that the
@@ -39,12 +40,16 @@ void WriteHostMemory(u8 value, u32 addr)
void DMAToDSP(u16* dst, u32 addr, u32 size)
{
Memory::CopyFromEmuSwapped(dst, addr, size);
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
memory.CopyFromEmuSwapped(dst, addr, size);
}
void DMAFromDSP(const u16* src, u32 addr, u32 size)
{
Memory::CopyToEmuSwapped(addr, src, size);
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
memory.CopyToEmuSwapped(addr, src, size);
}
void OSD_AddMessage(std::string str, u32 ms)
@@ -70,7 +75,9 @@ void InterruptRequest()
void CodeLoaded(DSPCore& dsp, u32 addr, size_t size)
{
CodeLoaded(dsp, Memory::GetPointer(addr), size);
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
CodeLoaded(dsp, memory.GetPointer(addr), size);
}
void CodeLoaded(DSPCore& dsp, const u8* ptr, size_t size)
+12 -7
View File
@@ -896,15 +896,17 @@ void ExecuteCommand(ReplyType reply_type)
{
// Used by both GC and Wii
case DICommand::Inquiry:
{
// (shuffle2) Taken from my Wii
Memory::Write_U32(0x00000002, state.DIMAR); // Revision level, device code
Memory::Write_U32(0x20060526, state.DIMAR + 4); // Release date
Memory::Write_U32(0x41000000, state.DIMAR + 8); // Version
auto& memory = system.GetMemory();
memory.Write_U32(0x00000002, state.DIMAR); // Revision level, device code
memory.Write_U32(0x20060526, state.DIMAR + 4); // Release date
memory.Write_U32(0x41000000, state.DIMAR + 8); // Version
INFO_LOG_FMT(DVDINTERFACE, "DVDLowInquiry (Buffer {:#010x}, {:#x})", state.DIMAR,
state.DILENGTH);
break;
}
// GC-only patched drive firmware command, used by libogc
case DICommand::Unknown55:
INFO_LOG_FMT(DVDINTERFACE, "SetExtension");
@@ -1024,17 +1026,20 @@ void ExecuteCommand(ReplyType reply_type)
break;
// Wii-exclusive
case DICommand::ReadBCA:
{
WARN_LOG_FMT(DVDINTERFACE, "DVDLowReadDiskBca - supplying dummy data to appease NSMBW");
DolphinAnalytics::Instance().ReportGameQuirk(GameQuirk::USES_DVD_LOW_READ_DISK_BCA);
// NSMBW checks that the first 0x33 bytes of the BCA are 0, then it expects a 1.
// Most (all?) other games have 0x34 0's at the start of the BCA, but don't actually
// read it. NSMBW doesn't care about the other 12 bytes (which contain manufacturing data?)
auto& memory = system.GetMemory();
// TODO: Read the .bca file that cleanrip generates, if it exists
// Memory::CopyToEmu(output_address, bca_data, 0x40);
Memory::Memset(state.DIMAR, 0, 0x40);
Memory::Write_U8(1, state.DIMAR + 0x33);
// memory.CopyToEmu(output_address, bca_data, 0x40);
memory.Memset(state.DIMAR, 0, 0x40);
memory.Write_U8(1, state.DIMAR + 0x33);
break;
}
// Wii-exclusive
case DICommand::RequestDiscStatus:
ERROR_LOG_FMT(DVDINTERFACE, "DVDLowRequestDiscStatus");
+4 -1
View File
@@ -391,7 +391,10 @@ static void FinishRead(Core::System& system, u64 id, s64 cycles_late)
else
{
if (request.copy_to_ram)
Memory::CopyToEmu(request.output_address, buffer.data(), request.length);
{
auto& memory = system.GetMemory();
memory.CopyToEmu(request.output_address, buffer.data(), request.length);
}
interrupt = DVDInterface::DIInterruptType::TCINT;
}
+7 -2
View File
@@ -15,6 +15,7 @@
#include "Core/HW/EXI/EXI_DeviceMemoryCard.h"
#include "Core/HW/EXI/EXI_DeviceMic.h"
#include "Core/HW/Memmap.h"
#include "Core/System.h"
namespace ExpansionInterface
{
@@ -47,20 +48,24 @@ void IEXIDevice::ImmReadWrite(u32& data, u32 size)
void IEXIDevice::DMAWrite(u32 address, u32 size)
{
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
while (size--)
{
u8 byte = Memory::Read_U8(address++);
u8 byte = memory.Read_U8(address++);
TransferByte(byte);
}
}
void IEXIDevice::DMARead(u32 address, u32 size)
{
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
while (size--)
{
u8 byte = 0;
TransferByte(byte);
Memory::Write_U8(byte, address++);
memory.Write_U8(byte, address++);
}
}
@@ -19,6 +19,7 @@
#include "Core/HW/EXI/EXI.h"
#include "Core/HW/Memmap.h"
#include "Core/PowerPC/PowerPC.h"
#include "Core/System.h"
namespace ExpansionInterface
{
@@ -233,7 +234,9 @@ void CEXIETHERNET::DMAWrite(u32 addr, u32 size)
if (transfer.region == transfer.MX && transfer.direction == transfer.WRITE &&
transfer.address == BBA_WRTXFIFOD)
{
DirectFIFOWrite(Memory::GetPointer(addr), size);
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
DirectFIFOWrite(memory.GetPointer(addr), size);
}
else
{
@@ -246,7 +249,9 @@ void CEXIETHERNET::DMAWrite(u32 addr, u32 size)
void CEXIETHERNET::DMARead(u32 addr, u32 size)
{
DEBUG_LOG_FMT(SP1, "DMA read: {:08x} {:x}", addr, size);
Memory::CopyToEmu(addr, &mBbaMem[transfer.address], size);
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
memory.CopyToEmu(addr, &mBbaMem[transfer.address], size);
transfer.address += size;
}
@@ -523,7 +523,9 @@ void CEXIMemoryCard::DoState(PointerWrap& p)
// read all at once instead of single byte at a time as done by IEXIDevice::DMARead
void CEXIMemoryCard::DMARead(u32 addr, u32 size)
{
m_memory_card->Read(m_address, size, Memory::GetPointer(addr));
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
m_memory_card->Read(m_address, size, memory.GetPointer(addr));
if ((m_address + size) % Memcard::BLOCK_SIZE == 0)
{
@@ -531,7 +533,7 @@ void CEXIMemoryCard::DMARead(u32 addr, u32 size)
}
// Schedule transfer complete later based on read speed
Core::System::GetInstance().GetCoreTiming().ScheduleEvent(
system.GetCoreTiming().ScheduleEvent(
size * (SystemTimers::GetTicksPerSecond() / MC_TRANSFER_RATE_READ),
s_et_transfer_complete[m_card_slot], static_cast<u64>(m_card_slot));
}
@@ -540,7 +542,9 @@ void CEXIMemoryCard::DMARead(u32 addr, u32 size)
// write all at once instead of single byte at a time as done by IEXIDevice::DMAWrite
void CEXIMemoryCard::DMAWrite(u32 addr, u32 size)
{
m_memory_card->Write(m_address, size, Memory::GetPointer(addr));
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
m_memory_card->Write(m_address, size, memory.GetPointer(addr));
if (((m_address + size) % Memcard::BLOCK_SIZE) == 0)
{
@@ -548,7 +552,7 @@ void CEXIMemoryCard::DMAWrite(u32 addr, u32 size)
}
// Schedule transfer complete later based on write speed
Core::System::GetInstance().GetCoreTiming().ScheduleEvent(
system.GetCoreTiming().ScheduleEvent(
size * (SystemTimers::GetTicksPerSecond() / MC_TRANSFER_RATE_WRITE),
s_et_transfer_complete[m_card_slot], static_cast<u64>(m_card_slot));
}
+5 -3
View File
@@ -83,9 +83,12 @@ void ResetGatherPipe()
void UpdateGatherPipe()
{
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
size_t pipe_count = GetGatherPipeCount();
size_t processed;
u8* cur_mem = Memory::GetPointer(ProcessorInterface::Fifo_CPUWritePointer);
u8* cur_mem = memory.GetPointer(ProcessorInterface::Fifo_CPUWritePointer);
for (processed = 0; pipe_count >= GATHER_PIPE_SIZE; processed += GATHER_PIPE_SIZE)
{
// copy the GatherPipe
@@ -96,7 +99,7 @@ void UpdateGatherPipe()
if (ProcessorInterface::Fifo_CPUWritePointer == ProcessorInterface::Fifo_CPUEnd)
{
ProcessorInterface::Fifo_CPUWritePointer = ProcessorInterface::Fifo_CPUBase;
cur_mem = Memory::GetPointer(ProcessorInterface::Fifo_CPUWritePointer);
cur_mem = memory.GetPointer(ProcessorInterface::Fifo_CPUWritePointer);
}
else
{
@@ -104,7 +107,6 @@ void UpdateGatherPipe()
ProcessorInterface::Fifo_CPUWritePointer += GATHER_PIPE_SIZE;
}
auto& system = Core::System::GetInstance();
system.GetCommandProcessor().GatherPipeBursted(system);
}

Some files were not shown because too many files have changed in this diff Show More