diff --git a/include/emulator.hpp b/include/emulator.hpp index abb74089..329beeaa 100644 --- a/include/emulator.hpp +++ b/include/emulator.hpp @@ -40,9 +40,9 @@ enum class ROMType { class Emulator { EmulatorConfig config; + Memory memory; CPU cpu; GPU gpu; - Memory memory; Kernel kernel; std::unique_ptr dsp; Scheduler scheduler; @@ -55,7 +55,7 @@ class Emulator { static constexpr u32 width = 400; static constexpr u32 height = 240 * 2; // * 2 because 2 screens ROMType romType = ROMType::None; - bool running = false; // Is the emulator running a game? + bool running = false; // Is the emulator running a game? private: #ifdef PANDA3DS_ENABLE_HTTP_SERVER diff --git a/include/memory.hpp b/include/memory.hpp index ce008335..a3f4efbe 100644 --- a/include/memory.hpp +++ b/include/memory.hpp @@ -16,8 +16,6 @@ #include "loader/ncsd.hpp" #include "services/region_codes.hpp" -#define PANDA3DS_HARDWARE_FASTMEM - namespace PhysicalAddrs { enum : u32 { VRAM = 0x18000000, @@ -112,7 +110,7 @@ class Memory { u8* dspRam; // Provided to us by Audio u8* vram; // Provided to the memory class by the GPU class - u64& cpuTicks; // Reference to the CPU tick counter + const u64* cpuTicks = nullptr; // Pointer to the CPU tick counter, provided to us by the CPU class using SharedMemoryBlock = KernelMemoryTypes::SharedMemoryBlock; // Our dynarmic core uses page tables for reads and writes with 4096 byte pages @@ -207,7 +205,7 @@ private: u32 usedUserMemory = u32(0_MB); // How much of the APPLICATION FCRAM range is used (allocated to the appcore) u32 usedSystemMemory = u32(0_MB); // Similar for the SYSTEM range (reserved for the syscore) - Memory(u64& cpuTicks, const EmulatorConfig& config); + Memory(const EmulatorConfig& config); void reset(); void* getReadPointer(u32 address); void* getWritePointer(u32 address); @@ -330,6 +328,7 @@ private: void setVRAM(u8* pointer) { vram = pointer; } void setDSPMem(u8* pointer) { dspRam = pointer; } + void setCPUTicks(const u64& ticks) { cpuTicks = &ticks; } bool allocateMainThreadStack(u32 size); Regions getConsoleRegion(); diff --git a/src/core/CPU/cpu_dynarmic.cpp b/src/core/CPU/cpu_dynarmic.cpp index d15fbb13..124647d8 100644 --- a/src/core/CPU/cpu_dynarmic.cpp +++ b/src/core/CPU/cpu_dynarmic.cpp @@ -6,6 +6,7 @@ CPU::CPU(Memory& mem, Kernel& kernel, Emulator& emu) : mem(mem), emu(emu), scheduler(emu.getScheduler()), env(mem, kernel, emu.getScheduler()) { cp15 = std::make_shared(); + mem.setCPUTicks(getTicksRef()); Dynarmic::A32::UserConfig config; config.arch_version = Dynarmic::A32::ArchVersion::v6K; diff --git a/src/core/memory.cpp b/src/core/memory.cpp index 2bbb10d1..b4a8ea67 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp @@ -14,7 +14,7 @@ CMRC_DECLARE(ConsoleFonts); using namespace KernelMemoryTypes; -Memory::Memory(u64& cpuTicks, const EmulatorConfig& config) : cpuTicks(cpuTicks), config(config) { +Memory::Memory(const EmulatorConfig& config) : config(config) { fcram = new uint8_t[FCRAM_SIZE](); readTable.resize(totalPageCount, 0); @@ -44,7 +44,6 @@ Memory::Memory(u64& cpuTicks, const EmulatorConfig& config) : cpuTicks(cpuTicks) useFastmem = false; fastmemArenaBase = nullptr; #endif - } void Memory::reset() { @@ -189,8 +188,8 @@ u32 Memory::read32(u32 vaddr) { case ConfigMem::Datetime0 + 4: return u32(timeSince3DSEpoch() >> 32); // top 32 bits // Ticks since time was last updated. For now we return the current tick count - case ConfigMem::Datetime0 + 8: return u32(cpuTicks); - case ConfigMem::Datetime0 + 12: return u32(cpuTicks >> 32); + case ConfigMem::Datetime0 + 8: return u32(*cpuTicks); + case ConfigMem::Datetime0 + 12: return u32(*cpuTicks >> 32); case ConfigMem::Datetime0 + 16: return 0xFFB0FF0; // Unknown, set by PTM case ConfigMem::Datetime0 + 20: case ConfigMem::Datetime0 + 24: diff --git a/src/emulator.cpp b/src/emulator.cpp index fc25eacb..4568dfd0 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -19,7 +19,7 @@ __declspec(dllexport) DWORD AmdPowerXpressRequestHighPerformance = 1; #endif Emulator::Emulator() - : config(getConfigPath()), kernel(cpu, memory, gpu, config), cpu(memory, kernel, *this), gpu(memory, config), memory(cpu.getTicksRef(), config), + : config(getConfigPath()), kernel(cpu, memory, gpu, config), cpu(memory, kernel, *this), gpu(memory, config), memory(config), cheats(memory, kernel.getServiceManager().getHID()), audioDevice(config.audioDeviceConfig), lua(*this), running(false) #ifdef PANDA3DS_ENABLE_HTTP_SERVER ,