diff --git a/core/cfg/option.cpp b/core/cfg/option.cpp index 7a57c4a21..b09660195 100644 --- a/core/cfg/option.cpp +++ b/core/cfg/option.cpp @@ -25,6 +25,7 @@ namespace config { // Dynarec Option DynarecEnabled("Dynarec.Enabled", true); +Option Sh4Clock("Sh4Clock", 200); // General diff --git a/core/cfg/option.h b/core/cfg/option.h index c27410c45..aa1777a04 100644 --- a/core/cfg/option.h +++ b/core/cfg/option.h @@ -356,6 +356,9 @@ using OptionString = Option; // Dynarec extern Option DynarecEnabled; +#ifndef LIBRETRO +extern Option Sh4Clock; +#endif // General diff --git a/core/hw/sh4/dyna/decoder.cpp b/core/hw/sh4/dyna/decoder.cpp index 2884c8e54..4977b92f5 100644 --- a/core/hw/sh4/dyna/decoder.cpp +++ b/core/hw/sh4/dyna/decoder.cpp @@ -1057,8 +1057,8 @@ _end: verify(blk->oplist.size() <= BLOCK_MAX_SH_OPS_HARD); - //make sure we don't use wayy-too-many cycles - blk->guest_cycles = std::min(blk->guest_cycles, max_cycles); + blk->guest_cycles = std::round(blk->guest_cycles * 200.f / std::max(1.f, (float)config::Sh4Clock)); + //make sure we don't use wayy-too-few cycles blk->guest_cycles = std::max(1U, blk->guest_cycles); blk = nullptr; diff --git a/core/rend/gui.cpp b/core/rend/gui.cpp index 34675daa0..4ad3d7b27 100644 --- a/core/rend/gui.cpp +++ b/core/rend/gui.cpp @@ -2172,6 +2172,10 @@ static void gui_display_settings() OptionRadioButton("Interpreter", config::DynarecEnabled, false, "Use the interpreter. Very slow but may help in case of a dynarec problem"); ImGui::Columns(1, NULL, false); + + OptionSlider("SH4 Clock", config::Sh4Clock, 100, 300, + "Over/Underclock the main SH4 CPU. Default is 200 MHz. Other values may crash, freeze or trigger unexpected nuclear reactions.", + "%d MHz"); } ImGui::Spacing(); header("Network"); diff --git a/shell/libretro/libretro_core_options.h b/shell/libretro/libretro_core_options.h index 9f6b9ed1e..d12076903 100644 --- a/shell/libretro/libretro_core_options.h +++ b/shell/libretro/libretro_core_options.h @@ -689,6 +689,39 @@ struct retro_core_option_v2_definition option_defs_us[] = { "disabled", #endif }, + { + CORE_OPTION_NAME "_sh4clock", + "SH4 CPU under/overclock", + NULL, + "Change the SH4 main CPU clock from the default 200 MHz. Underclocking may help slow platforms. Overclocking may increase the frame rate for some games. Use with caution.", + NULL, + "hacks", + { + { "100", "100 MHz" }, + { "110", "110 MHz" }, + { "120", "120 MHz" }, + { "130", "130 MHz" }, + { "140", "140 MHz" }, + { "150", "150 MHz" }, + { "160", "160 MHz" }, + { "170", "170 MHz" }, + { "180", "180 MHz" }, + { "190", "190 MHz" }, + { "200", "200 MHz" }, + { "210", "210 MHz" }, + { "220", "220 MHz" }, + { "230", "230 MHz" }, + { "240", "240 MHz" }, + { "250", "250 MHz" }, + { "260", "260 MHz" }, + { "270", "270 MHz" }, + { "280", "280 MHz" }, + { "290", "290 MHz" }, + { "300", "300 MHz" }, + { NULL, NULL }, + }, + "200", + }, { CORE_OPTION_NAME "_custom_textures", "Load Custom Textures", diff --git a/shell/libretro/option.cpp b/shell/libretro/option.cpp index 7489e3f16..cd5f9498d 100644 --- a/shell/libretro/option.cpp +++ b/shell/libretro/option.cpp @@ -24,6 +24,7 @@ namespace config { // Dynarec Option DynarecEnabled("", true); +IntOption Sh4Clock(CORE_OPTION_NAME "_sh4clock", 200); // General diff --git a/shell/libretro/option_lr.h b/shell/libretro/option_lr.h index d691f01a2..2f10fd60d 100644 --- a/shell/libretro/option_lr.h +++ b/shell/libretro/option_lr.h @@ -202,3 +202,4 @@ extern Option PowerVR2Filter; extern IntOption TextureUpscale; extern IntOption MaxFilteredTextureSize; extern IntOption PerPixelLayers; +extern IntOption Sh4Clock;