From 32caf387d6b881f29d65e97a02cda0b369526b13 Mon Sep 17 00:00:00 2001 From: Joshua Smith Date: Fri, 15 Nov 2024 14:41:41 -0500 Subject: [PATCH] add a flag to enable use of upper 4mb memory in DS mode --- src/NDS.cpp | 7 ++++++- src/NDS.h | 3 +++ src/frontend/qt_sdl/EmuInstance.cpp | 1 + src/frontend/qt_sdl/EmuSettingsDialog.cpp | 3 +++ src/frontend/qt_sdl/EmuSettingsDialog.ui | 11 +++++++++-- 5 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/NDS.cpp b/src/NDS.cpp index 1023d3c0..617f3118 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -444,7 +444,7 @@ void NDS::Reset() else { ARM9ClockShift = 1; - MainRAMMask = 0x3FFFFF; + MainRAMMask = useExtendedMemory ? 0x7FFFFF : 0x3FFFFF; } // has to be called before InitTimings // otherwise some PU settings are completely @@ -4345,4 +4345,9 @@ void NDS::ARM7IOWrite32(u32 addr, u32 val) Log(LogLevel::Debug, "unknown ARM7 IO write32 %08X %08X %08X\n", addr, val, ARM7.R[15]); } +void NDS::SetMemoryExtension(bool enabled) +{ + useExtendedMemory = enabled; +} + } diff --git a/src/NDS.h b/src/NDS.h index b2bfb385..b356b837 100644 --- a/src/NDS.h +++ b/src/NDS.h @@ -469,6 +469,8 @@ public: // TODO: Encapsulate the rest of these members virtual void ARM7IOWrite16(u32 addr, u16 val); virtual void ARM7IOWrite32(u32 addr, u32 val); + void SetMemoryExtension(bool enabled); + #ifdef JIT_ENABLED [[nodiscard]] bool IsJITEnabled() const noexcept { return EnableJIT; } void SetJITArgs(std::optional args) noexcept; @@ -527,6 +529,7 @@ private: void EnterSleepMode(); template u32 RunFrame(); + bool useExtendedMemory = false; public: NDS(NDSArgs&& args, void* userdata = nullptr) noexcept : NDS(std::move(args), 0, userdata) {} diff --git a/src/frontend/qt_sdl/EmuInstance.cpp b/src/frontend/qt_sdl/EmuInstance.cpp index 7a74c6be..b51e3bb5 100644 --- a/src/frontend/qt_sdl/EmuInstance.cpp +++ b/src/frontend/qt_sdl/EmuInstance.cpp @@ -1353,6 +1353,7 @@ bool EmuInstance::updateConsole(UpdateConsoleNDSArgs&& _ndsargs, UpdateConsoleGB nds = new NDS(std::move(ndsargs), this); NDS::Current = nds; + nds->SetMemoryExtension(localCfg.GetBool("Debug.ExtendedMemory")); nds->Reset(); loadRTCData(); //emuThread->updateVideoRenderer(); // not actually needed? diff --git a/src/frontend/qt_sdl/EmuSettingsDialog.cpp b/src/frontend/qt_sdl/EmuSettingsDialog.cpp index 6c7e90a7..b53e96cc 100644 --- a/src/frontend/qt_sdl/EmuSettingsDialog.cpp +++ b/src/frontend/qt_sdl/EmuSettingsDialog.cpp @@ -109,6 +109,8 @@ EmuSettingsDialog::EmuSettingsDialog(QWidget* parent) : QDialog(parent), ui(new ui->cbGdbBOSA9->setDisabled(true); #endif + ui->cbDebugExtendedMem->setChecked(instcfg.GetBool("Debug.ExtendedMemory")); + on_chkEnableJIT_toggled(); on_cbGdbEnabled_toggled(); on_chkExternalBIOS_toggled(); @@ -301,6 +303,7 @@ void EmuSettingsDialog::done(int r) instcfg.SetBool("Gdb.ARM7.BreakOnStartup", ui->cbGdbBOSA7->isChecked()); instcfg.SetBool("Gdb.ARM9.BreakOnStartup", ui->cbGdbBOSA9->isChecked()); #endif + instcfg.SetBool("Debug.ExtendedMemory", ui->cbDebugExtendedMem->isChecked()); cfg.SetInt("Emu.ConsoleType", ui->cbxConsoleType->currentIndex()); cfg.SetBool("Emu.DirectBoot", ui->chkDirectBoot->isChecked()); diff --git a/src/frontend/qt_sdl/EmuSettingsDialog.ui b/src/frontend/qt_sdl/EmuSettingsDialog.ui index 1b123f67..a5de75a6 100644 --- a/src/frontend/qt_sdl/EmuSettingsDialog.ui +++ b/src/frontend/qt_sdl/EmuSettingsDialog.ui @@ -580,7 +580,7 @@ - + Qt::Vertical @@ -614,7 +614,14 @@ - + + + + Enable extended main RAM (8Mb) + + + + Note: melonDS must be restarted in order for these changes to have effect