From 91044b3b4f15f044a616c9e8df4f0b496f4104a2 Mon Sep 17 00:00:00 2001 From: Christian Speckner Date: Sun, 11 Aug 2024 15:21:47 +0200 Subject: [PATCH] Fix and hook up speed setting. --- src/common/DevSettingsHandler.cxx | 1 + src/emucore/CartELF.cxx | 38 ++++++++++++++++--------------- src/emucore/CartELF.hxx | 8 ++++--- src/gui/DeveloperDialog.cxx | 7 +++--- 4 files changed, 30 insertions(+), 24 deletions(-) diff --git a/src/common/DevSettingsHandler.cxx b/src/common/DevSettingsHandler.cxx index d6c624858..c33e22340 100644 --- a/src/common/DevSettingsHandler.cxx +++ b/src/common/DevSettingsHandler.cxx @@ -125,6 +125,7 @@ void DevSettingsHandler::saveSettings(SettingsSet set) #endif // Thumb ARM emulation exception settings.setValue("dev.thumb.trapfatal", myThumbException[set]); + settings.setValue("dev.arm.mips", myArmSpeed[set]); } // AtariVox/SaveKey/PlusROM access diff --git a/src/emucore/CartELF.cxx b/src/emucore/CartELF.cxx index d1cec5790..a19c3d02f 100644 --- a/src/emucore/CartELF.cxx +++ b/src/emucore/CartELF.cxx @@ -203,7 +203,21 @@ namespace { default: throw runtime_error("invalid system type"); } -} + } + + uInt32 get6502SpeedHz(ConsoleTiming timing) { + switch (timing) { + case ConsoleTiming::ntsc: + return 262 * 76 * 60; + + case ConsoleTiming::pal: + case ConsoleTiming::secam: + return 312 * 76 * 50; + + default: + throw runtime_error("invalid console timing"); + } + } } // namespace // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -232,11 +246,15 @@ void CartridgeELF::reset() { const bool devMode = mySettings.getBool("dev.settings"); const bool strictMode = devMode && mySettings.getBool("dev.thumb.trapfatal"); + const uInt32 mips = devMode ? mySettings.getInt("dev.arm.mips") : MIPS_MAX; std::fill_n(myLastPeekResult.get(), 0x1000, 0); myIsBusDriven = false; myDriveBusValue = 0; myArmCyclesOffset = 0; + myArmCyclesPer6502Cycle = (mips * 1000000) / get6502SpeedHz(myConsoleTiming); + + cout << myArmCyclesPer6502Cycle << std::endl; mySystemType = determineSystemType(myProperties); myLinker->relink(externalSymbols(mySystemType)); @@ -530,22 +548,6 @@ void CartridgeELF::setupMemoryMap(bool strictMode) myFallbackDelegate.setErrorsAreFatal(strictMode); } -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt32 CartridgeELF::getCoreClock() const -{ - switch (myConsoleTiming) { - case ConsoleTiming::ntsc: - return myArmCyclesPer6502Cycle * 262 * 76 * 60; - - case ConsoleTiming::pal: - case ConsoleTiming::secam: - return myArmCyclesPer6502Cycle * 312 * 76 * 50; - - default: - throw runtime_error("invalid console timing"); - } -} - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CartridgeELF::switchExecutionStage() { @@ -603,7 +605,7 @@ void CartridgeELF::callMain() err |= myCortexEmu.write32(sp, 0); sp -= 4; - err |= myCortexEmu.write32(sp, getCoreClock()); + err |= myCortexEmu.write32(sp, myArmCyclesPer6502Cycle * get6502SpeedHz(myConsoleTiming)); sp -= 4; err |= myCortexEmu.write32(sp, getSystemTypeParam(mySystemType)); diff --git a/src/emucore/CartELF.hxx b/src/emucore/CartELF.hxx index 0082a6817..9b3d496d5 100644 --- a/src/emucore/CartELF.hxx +++ b/src/emucore/CartELF.hxx @@ -29,6 +29,10 @@ class ElfLinker; class CartridgeELF: public Cartridge { + public: + static constexpr uInt32 MIPS_MAX = 300; + static constexpr uInt32 MIPS_MIN = 50; + public: CartridgeELF(const ByteBuffer& image, size_t size, string_view md5, const Settings& settings); @@ -102,8 +106,6 @@ class CartridgeELF: public Cartridge { void allocationSections(); void setupMemoryMap(bool strictMode); - uInt32 getCoreClock() const; - void switchExecutionStage(); void callFn(uInt32 ptr, uInt32 sp); void callMain(); @@ -138,7 +140,7 @@ class CartridgeELF: public Cartridge { BusFallbackDelegate myFallbackDelegate; ConsoleTiming myConsoleTiming{ConsoleTiming::ntsc}; - uInt32 myArmCyclesPer6502Cycle{160}; + uInt32 myArmCyclesPer6502Cycle{100}; Int64 myArmCyclesOffset{0}; diff --git a/src/gui/DeveloperDialog.cxx b/src/gui/DeveloperDialog.cxx index 4e411ccc1..cb7eb7cfe 100644 --- a/src/gui/DeveloperDialog.cxx +++ b/src/gui/DeveloperDialog.cxx @@ -35,6 +35,7 @@ #include "StateManager.hxx" #include "RewindManager.hxx" #include "M6502.hxx" +#include "CartELF.hxx" #ifdef DEBUGGER_SUPPORT #include "Debugger.hxx" #include "DebuggerDialog.hxx" @@ -224,10 +225,10 @@ void DeveloperDialog::addEmulationTab(const GUI::Font& font) ypos += lineHeight + VGAP; myArmSpeedWidget = new SliderWidget(myTab, font, HBORDER + INDENT * 1, ypos - 1, - fontWidth * 10, lineHeight, "Limit ARM speed ", + fontWidth * 10, lineHeight, "Limit ARM speed ", 0, kArmSpeedChanged, fontWidth * 9, " MIPS"); - myArmSpeedWidget->setMinValue(50); // TODO: use constant - myArmSpeedWidget->setMaxValue(250); // TODO: use constant + myArmSpeedWidget->setMinValue(CartridgeELF::MIPS_MIN); // TODO: use constant + myArmSpeedWidget->setMaxValue(CartridgeELF::MIPS_MAX); // TODO: use constant myArmSpeedWidget->setTickmarkIntervals(4); myArmSpeedWidget->setStepValue(2); myArmSpeedWidget->setToolTip("Limit emulation speed to simulate ARM CPU used.");