From e4afa8e5124a61c17f171406b2011a1ea8b163ea Mon Sep 17 00:00:00 2001 From: Hamish Milne Date: Sun, 5 Jan 2020 13:26:16 +0000 Subject: [PATCH] Make the tests pass --- src/common/memory_ref.h | 17 +++++++++++------ src/core/core.cpp | 4 ++-- src/core/hle/service/cecd/cecd.cpp | 3 +-- src/core/memory.cpp | 21 +++++++++++---------- 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/common/memory_ref.h b/src/common/memory_ref.h index 5aaaef468a..05b1c7901f 100644 --- a/src/common/memory_ref.h +++ b/src/common/memory_ref.h @@ -91,15 +91,20 @@ public: } private: - std::shared_ptr backing_mem; - u32 offset; + std::shared_ptr backing_mem = nullptr; + u32 offset = 0; // Cached values for speed - u8* cptr; - u32 csize; + u8* cptr = nullptr; + u32 csize = 0; void Init() { - cptr = backing_mem->GetPtr() + offset; - csize = static_cast(backing_mem->GetSize() - offset); + if (backing_mem) { + cptr = backing_mem->GetPtr() + offset; + csize = static_cast(backing_mem->GetSize() - offset); + } else { + cptr = nullptr; + csize = 0; + } } template diff --git a/src/core/core.cpp b/src/core/core.cpp index a05e2a6365..bada80b55e 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -214,8 +214,8 @@ System::ResultStatus System::Init(Frontend::EmuWindow& emu_window, u32 system_mo timing = std::make_unique(); - kernel = std::make_unique( - *memory, *timing, [this] { PrepareReschedule(); }, system_mode); + kernel = std::make_unique(*memory, *timing, + [this] { PrepareReschedule(); }, system_mode); if (Settings::values.use_cpu_jit) { #ifdef ARCHITECTURE_x86_64 diff --git a/src/core/hle/service/cecd/cecd.cpp b/src/core/hle/service/cecd/cecd.cpp index 42ac76946a..f13df6926b 100644 --- a/src/core/hle/service/cecd/cecd.cpp +++ b/src/core/hle/service/cecd/cecd.cpp @@ -1352,8 +1352,7 @@ void Module::CheckAndUpdateFile(const CecDataPathType path_type, const u32 ncch_ case CecDataPathType::MboxData: case CecDataPathType::MboxIcon: case CecDataPathType::MboxTitle: - default: { - } + default: {} } } diff --git a/src/core/memory.cpp b/src/core/memory.cpp index 9762619f03..dd3a078043 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp @@ -98,7 +98,7 @@ public: std::shared_ptr n3ds_extra_ram_mem; std::shared_ptr dsp_mem; - MemorySystem::Impl(); + Impl(); virtual u8* GetPtr(Region r) { switch (r) { @@ -157,16 +157,17 @@ private: template class MemorySystem::BackingMemImpl : public BackingMem { public: - BackingMemImpl() : system(Core::Global().Memory()) {} + BackingMemImpl() : impl(*Core::Global().Memory().impl) {} + BackingMemImpl(MemorySystem::Impl& impl_) : impl(impl_) {} virtual u8* GetPtr() { - return system.impl->GetPtr(R); + return impl.GetPtr(R); } virtual u32 GetSize() const { - return system.impl->GetSize(R); + return impl.GetSize(R); } private: - MemorySystem& system; + MemorySystem::Impl& impl; template void serialize(Archive& ar, const unsigned int) {} @@ -174,10 +175,10 @@ private: }; MemorySystem::Impl::Impl() - : fcram_mem(std::make_shared>()), - vram_mem(std::make_shared>()), - n3ds_extra_ram_mem(std::make_shared>()), - dsp_mem(std::make_shared>()) {} + : fcram_mem(std::make_shared>(*this)), + vram_mem(std::make_shared>(*this)), + n3ds_extra_ram_mem(std::make_shared>(*this)), + dsp_mem(std::make_shared>(*this)) {} MemorySystem::MemorySystem() : impl(std::make_unique()) {} MemorySystem::~MemorySystem() = default; @@ -219,7 +220,7 @@ void MemorySystem::MapPages(PageTable& page_table, u32 base, u32 size, MemoryRef } base += 1; - if (memory != nullptr) + if (memory != nullptr && memory.GetSize() > PAGE_SIZE) memory += PAGE_SIZE; } }