diff --git a/src/duckstation-qt/gamepropertiesdialog.cpp b/src/duckstation-qt/gamepropertiesdialog.cpp index a8c01e375..c104cd784 100644 --- a/src/duckstation-qt/gamepropertiesdialog.cpp +++ b/src/duckstation-qt/gamepropertiesdialog.cpp @@ -2,6 +2,7 @@ #include "common/cd_image.h" #include "common/cd_image_hasher.h" #include "core/settings.h" +#include "core/system.h" #include "frontend-common/game_list.h" #include "qthostinterface.h" #include "qtprogresscallback.h" @@ -254,6 +255,18 @@ void GamePropertiesDialog::populateGameSettings() m_trait_checkboxes[i]->setChecked(gs.HasTrait(static_cast(i))); } + if (gs.cpu_overclock_numerator.has_value() || gs.cpu_overclock_denominator.has_value()) + { + const u32 numerator = gs.cpu_overclock_numerator.value_or(1); + const u32 denominator = gs.cpu_overclock_denominator.value_or(1); + const u32 percent = Settings::CPUOverclockFractionToPercent(numerator, denominator); + QSignalBlocker sb(m_ui.userCPUClockSpeed); + m_ui.userCPUClockSpeed->setValue(static_cast(percent)); + } + + populateBooleanUserSetting(m_ui.userEnableCPUClockSpeedControl, gs.cpu_overclock_enable); + updateCPUClockSpeedLabel(); + if (gs.display_active_start_offset.has_value()) { QSignalBlocker sb(m_ui.displayActiveStartOffset); @@ -385,6 +398,28 @@ void GamePropertiesDialog::connectUi() m_ui.exportCompatibilityInfo->setVisible(show_buttons); }); + connectBooleanUserSetting(m_ui.userEnableCPUClockSpeedControl, &m_game_settings.cpu_overclock_enable); + connect(m_ui.userEnableCPUClockSpeedControl, &QCheckBox::stateChanged, this, + &GamePropertiesDialog::updateCPUClockSpeedLabel); + + connect(m_ui.userCPUClockSpeed, &QSlider::valueChanged, [this](int value) { + if (value == 100) + { + m_game_settings.cpu_overclock_numerator.reset(); + m_game_settings.cpu_overclock_denominator.reset(); + } + else + { + u32 numerator, denominator; + Settings::CPUOverclockPercentToFraction(static_cast(value), &numerator, &denominator); + m_game_settings.cpu_overclock_numerator = numerator; + m_game_settings.cpu_overclock_denominator = denominator; + } + + saveGameSettings(); + updateCPUClockSpeedLabel(); + }); + connect(m_ui.userAspectRatio, QOverload::of(&QComboBox::currentIndexChanged), [this](int index) { if (index <= 0) m_game_settings.display_aspect_ratio.reset(); @@ -514,6 +549,13 @@ void GamePropertiesDialog::connectUi() }); } +void GamePropertiesDialog::updateCPUClockSpeedLabel() +{ + const int percent = m_ui.userCPUClockSpeed->value(); + const double frequency = (static_cast(System::MASTER_CLOCK) * static_cast(percent)) / 100.0; + m_ui.userCPUClockSpeedLabel->setText(tr("%1% (%2MHz)").arg(percent).arg(frequency / 1000000.0, 0, 'f', 2)); +} + void GamePropertiesDialog::fillEntryFromUi(GameListCompatibilityEntry* entry) { entry->code = m_ui.gameCode->text().toStdString(); diff --git a/src/duckstation-qt/gamepropertiesdialog.h b/src/duckstation-qt/gamepropertiesdialog.h index ed2e74aab..d3fde36ac 100644 --- a/src/duckstation-qt/gamepropertiesdialog.h +++ b/src/duckstation-qt/gamepropertiesdialog.h @@ -36,6 +36,7 @@ private Q_SLOTS: void onComputeHashClicked(); void onVerifyDumpClicked(); void onExportCompatibilityInfoClicked(); + void updateCPUClockSpeedLabel(); private: void setupAdditionalUi(); diff --git a/src/duckstation-qt/gamepropertiesdialog.ui b/src/duckstation-qt/gamepropertiesdialog.ui index 47d7fff1a..3de862a54 100644 --- a/src/duckstation-qt/gamepropertiesdialog.ui +++ b/src/duckstation-qt/gamepropertiesdialog.ui @@ -187,6 +187,74 @@ User Settings (Console) + + + + CPU Clock Speed Control + + + + + + + + Enable Clock Speed Control (Overclocking/Underclocking) + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + 100% (effective 33.3mhz) + + + Qt::AlignCenter + + + + + + + + + 10 + + + 1000 + + + 100 + + + Qt::Horizontal + + + QSlider::TicksBothSides + + + 50 + + + + + +