diff options
author | Jesse Talavera-Greenberg <jesse@jesse.tg> | 2023-11-28 17:16:41 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-28 23:16:41 +0100 |
commit | e973236203292637eb7bd009a4cfbd6fd785181f (patch) | |
tree | 4c348a9927bfa6f8f37cc943291174a1096434b3 /src/ARMJIT_Memory.h | |
parent | c84cb174628c5a2e8e6cc0179e16de3eab47864a (diff) |
Refactor `NDS` and `DSi` to be objects (#1893)
* First crack at refactoring NDS and DSi into objects
- Remove all global/`static` variables in `NDS` and related classes
- Rely more on virtual dispatch when we need to pick methods at runtime
- Pass `NDS&` or `DSi&` to its constituent components where necessary
- Introduce some headers or move some definitions to break `#include` cycles
* Refactor the frontend to accommodate the core's changes
* Move up `SchedList`'s declaration
- Move it to before the components are initialized so the `map`s inside are initialized
- Fields in C++ are initialized in the order they're declared
* Fix a crash when allocating memory
* Fix JIT-free builds
* Fix GDB-free builds
* Fix Linux builds
- Explicitly qualify some member types in NDS, since they share the same name as their classes
* Remove an unnecessary template argument
- This was causing the build to fail on macOS
* Fix ARM and Android builds
* Rename `Constants.h` to `MemConstants.h`
* Add `NDS::IsRunning()`
* Use an `#include` guard instead of `#pragma once`
Diffstat (limited to 'src/ARMJIT_Memory.h')
-rw-r--r-- | src/ARMJIT_Memory.h | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/src/ARMJIT_Memory.h b/src/ARMJIT_Memory.h index ed48437..487005b 100644 --- a/src/ARMJIT_Memory.h +++ b/src/ARMJIT_Memory.h @@ -23,7 +23,7 @@ #include "TinyVector.h" #include "ARM.h" -#include "DSi.h" +#include "MemConstants.h" #if defined(__SWITCH__) #include <switch.h> @@ -44,6 +44,7 @@ namespace melonDS { +namespace Platform { struct DynamicLibrary; } class Compiler; class ARMJIT; @@ -57,13 +58,13 @@ constexpr u32 RoundUp(u32 size) noexcept } const u32 MemBlockMainRAMOffset = 0; -const u32 MemBlockSWRAMOffset = RoundUp(NDS::MainRAMMaxSize); -const u32 MemBlockARM7WRAMOffset = MemBlockSWRAMOffset + RoundUp(NDS::SharedWRAMSize); -const u32 MemBlockDTCMOffset = MemBlockARM7WRAMOffset + RoundUp(NDS::ARM7WRAMSize); +const u32 MemBlockSWRAMOffset = RoundUp(MainRAMMaxSize); +const u32 MemBlockARM7WRAMOffset = MemBlockSWRAMOffset + RoundUp(SharedWRAMSize); +const u32 MemBlockDTCMOffset = MemBlockARM7WRAMOffset + RoundUp(ARM7WRAMSize); const u32 MemBlockNWRAM_AOffset = MemBlockDTCMOffset + RoundUp(DTCMPhysicalSize); -const u32 MemBlockNWRAM_BOffset = MemBlockNWRAM_AOffset + RoundUp(DSi::NWRAMSize); -const u32 MemBlockNWRAM_COffset = MemBlockNWRAM_BOffset + RoundUp(DSi::NWRAMSize); -const u32 MemoryTotalSize = MemBlockNWRAM_COffset + RoundUp(DSi::NWRAMSize); +const u32 MemBlockNWRAM_BOffset = MemBlockNWRAM_AOffset + RoundUp(NWRAMSize); +const u32 MemBlockNWRAM_COffset = MemBlockNWRAM_BOffset + RoundUp(NWRAMSize); +const u32 MemoryTotalSize = MemBlockNWRAM_COffset + RoundUp(NWRAMSize); class ARMJIT_Memory { @@ -96,7 +97,7 @@ public: #ifdef JIT_ENABLED public: - explicit ARMJIT_Memory(ARMJIT& jit) noexcept; + explicit ARMJIT_Memory(melonDS::NDS& nds); ~ARMJIT_Memory() noexcept; ARMJIT_Memory(const ARMJIT_Memory&) = delete; ARMJIT_Memory(ARMJIT_Memory&&) = delete; @@ -144,7 +145,7 @@ private: u32 Size, LocalOffset; u32 Num; - void Unmap(int region, ARMJIT_Memory& memory) noexcept; + void Unmap(int region, NDS& nds) noexcept; }; struct FaultDescription @@ -152,12 +153,12 @@ private: u32 EmulatedFaultAddr; u8* FaultPC; }; - static bool FaultHandler(FaultDescription& faultDesc, ARMJIT& jit); + static bool FaultHandler(FaultDescription& faultDesc, melonDS::NDS& nds); bool MapIntoRange(u32 addr, u32 num, u32 offset, u32 size) noexcept; bool UnmapFromRange(u32 addr, u32 num, u32 offset, u32 size) noexcept; void SetCodeProtectionRange(u32 addr, u32 size, u32 num, int protection) noexcept; - ARMJIT& JIT; + melonDS::NDS& NDS; void* FastMem9Start; void* FastMem7Start; u8* MemoryBase = nullptr; @@ -180,7 +181,7 @@ private: TinyVector<Mapping> Mappings[memregions_Count] {}; #else public: - explicit ARMJIT_Memory(ARMJIT&) {}; + explicit ARMJIT_Memory(melonDS::NDS&) {}; ~ARMJIT_Memory() = default; ARMJIT_Memory(const ARMJIT_Memory&) = delete; ARMJIT_Memory(ARMJIT_Memory&&) = delete; @@ -214,13 +215,13 @@ public: [[nodiscard]] u8* GetNWRAM_C() noexcept { return NWRAM_C.data(); } [[nodiscard]] const u8* GetNWRAM_C() const noexcept { return NWRAM_C.data(); } private: - std::array<u8, NDS::MainRAMMaxSize> MainRAM {}; - std::array<u8, NDS::ARM7WRAMSize> ARM7WRAM {}; - std::array<u8, NDS::SharedWRAMSize> SharedWRAM {}; + std::array<u8, MainRAMMaxSize> MainRAM {}; + std::array<u8, ARM7WRAMSize> ARM7WRAM {}; + std::array<u8, SharedWRAMSize> SharedWRAM {}; std::array<u8, DTCMPhysicalSize> DTCM {}; - std::array<u8, DSi::NWRAMSize> NWRAM_A {}; - std::array<u8, DSi::NWRAMSize> NWRAM_B {}; - std::array<u8, DSi::NWRAMSize> NWRAM_C {}; + std::array<u8, NWRAMSize> NWRAM_A {}; + std::array<u8, NWRAMSize> NWRAM_B {}; + std::array<u8, NWRAMSize> NWRAM_C {}; #endif }; } |