Properly fix fastmem

This commit is contained in:
wheremyfoodat 2024-11-30 14:49:06 +02:00
parent ca068c45dd
commit f4d629980b
5 changed files with 10 additions and 11 deletions

View file

@ -40,9 +40,9 @@ enum class ROMType {
class Emulator { class Emulator {
EmulatorConfig config; EmulatorConfig config;
Memory memory;
CPU cpu; CPU cpu;
GPU gpu; GPU gpu;
Memory memory;
Kernel kernel; Kernel kernel;
std::unique_ptr<Audio::DSPCore> dsp; std::unique_ptr<Audio::DSPCore> dsp;
Scheduler scheduler; Scheduler scheduler;
@ -55,7 +55,7 @@ class Emulator {
static constexpr u32 width = 400; static constexpr u32 width = 400;
static constexpr u32 height = 240 * 2; // * 2 because 2 screens static constexpr u32 height = 240 * 2; // * 2 because 2 screens
ROMType romType = ROMType::None; ROMType romType = ROMType::None;
bool running = false; // Is the emulator running a game? bool running = false; // Is the emulator running a game?
private: private:
#ifdef PANDA3DS_ENABLE_HTTP_SERVER #ifdef PANDA3DS_ENABLE_HTTP_SERVER

View file

@ -16,8 +16,6 @@
#include "loader/ncsd.hpp" #include "loader/ncsd.hpp"
#include "services/region_codes.hpp" #include "services/region_codes.hpp"
#define PANDA3DS_HARDWARE_FASTMEM
namespace PhysicalAddrs { namespace PhysicalAddrs {
enum : u32 { enum : u32 {
VRAM = 0x18000000, VRAM = 0x18000000,
@ -112,7 +110,7 @@ class Memory {
u8* dspRam; // Provided to us by Audio u8* dspRam; // Provided to us by Audio
u8* vram; // Provided to the memory class by the GPU class 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; using SharedMemoryBlock = KernelMemoryTypes::SharedMemoryBlock;
// Our dynarmic core uses page tables for reads and writes with 4096 byte pages // 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 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) 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 reset();
void* getReadPointer(u32 address); void* getReadPointer(u32 address);
void* getWritePointer(u32 address); void* getWritePointer(u32 address);
@ -330,6 +328,7 @@ private:
void setVRAM(u8* pointer) { vram = pointer; } void setVRAM(u8* pointer) { vram = pointer; }
void setDSPMem(u8* pointer) { dspRam = pointer; } void setDSPMem(u8* pointer) { dspRam = pointer; }
void setCPUTicks(const u64& ticks) { cpuTicks = &ticks; }
bool allocateMainThreadStack(u32 size); bool allocateMainThreadStack(u32 size);
Regions getConsoleRegion(); Regions getConsoleRegion();

View file

@ -6,6 +6,7 @@
CPU::CPU(Memory& mem, Kernel& kernel, Emulator& emu) : mem(mem), emu(emu), scheduler(emu.getScheduler()), env(mem, kernel, emu.getScheduler()) { CPU::CPU(Memory& mem, Kernel& kernel, Emulator& emu) : mem(mem), emu(emu), scheduler(emu.getScheduler()), env(mem, kernel, emu.getScheduler()) {
cp15 = std::make_shared<CP15>(); cp15 = std::make_shared<CP15>();
mem.setCPUTicks(getTicksRef());
Dynarmic::A32::UserConfig config; Dynarmic::A32::UserConfig config;
config.arch_version = Dynarmic::A32::ArchVersion::v6K; config.arch_version = Dynarmic::A32::ArchVersion::v6K;

View file

@ -14,7 +14,7 @@ CMRC_DECLARE(ConsoleFonts);
using namespace KernelMemoryTypes; 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](); fcram = new uint8_t[FCRAM_SIZE]();
readTable.resize(totalPageCount, 0); readTable.resize(totalPageCount, 0);
@ -44,7 +44,6 @@ Memory::Memory(u64& cpuTicks, const EmulatorConfig& config) : cpuTicks(cpuTicks)
useFastmem = false; useFastmem = false;
fastmemArenaBase = nullptr; fastmemArenaBase = nullptr;
#endif #endif
} }
void Memory::reset() { void Memory::reset() {
@ -189,8 +188,8 @@ u32 Memory::read32(u32 vaddr) {
case ConfigMem::Datetime0 + 4: case ConfigMem::Datetime0 + 4:
return u32(timeSince3DSEpoch() >> 32); // top 32 bits return u32(timeSince3DSEpoch() >> 32); // top 32 bits
// Ticks since time was last updated. For now we return the current tick count // Ticks since time was last updated. For now we return the current tick count
case ConfigMem::Datetime0 + 8: return u32(cpuTicks); case ConfigMem::Datetime0 + 8: return u32(*cpuTicks);
case ConfigMem::Datetime0 + 12: return u32(cpuTicks >> 32); case ConfigMem::Datetime0 + 12: return u32(*cpuTicks >> 32);
case ConfigMem::Datetime0 + 16: return 0xFFB0FF0; // Unknown, set by PTM case ConfigMem::Datetime0 + 16: return 0xFFB0FF0; // Unknown, set by PTM
case ConfigMem::Datetime0 + 20: case ConfigMem::Datetime0 + 20:
case ConfigMem::Datetime0 + 24: case ConfigMem::Datetime0 + 24:

View file

@ -19,7 +19,7 @@ __declspec(dllexport) DWORD AmdPowerXpressRequestHighPerformance = 1;
#endif #endif
Emulator::Emulator() 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) cheats(memory, kernel.getServiceManager().getHID()), audioDevice(config.audioDeviceConfig), lua(*this), running(false)
#ifdef PANDA3DS_ENABLE_HTTP_SERVER #ifdef PANDA3DS_ENABLE_HTTP_SERVER
, ,