AdvancedPane.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. // Copyright 2017 Dolphin Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include "DolphinQt/Settings/AdvancedPane.h"
  4. #include <QCheckBox>
  5. #include <QComboBox>
  6. #include <QDateTimeEdit>
  7. #include <QFormLayout>
  8. #include <QGroupBox>
  9. #include <QHBoxLayout>
  10. #include <QLabel>
  11. #include <QRadioButton>
  12. #include <QSignalBlocker>
  13. #include <QSlider>
  14. #include <QVBoxLayout>
  15. #include <cmath>
  16. #include "Core/Config/MainSettings.h"
  17. #include "Core/ConfigManager.h"
  18. #include "Core/Core.h"
  19. #include "Core/HW/SystemTimers.h"
  20. #include "Core/PowerPC/PowerPC.h"
  21. #include "Core/System.h"
  22. #include "DolphinQt/Config/ConfigControls/ConfigBool.h"
  23. #include "DolphinQt/QtUtils/QtUtils.h"
  24. #include "DolphinQt/QtUtils/SignalBlocking.h"
  25. #include "DolphinQt/Settings.h"
  26. static const std::map<PowerPC::CPUCore, const char*> CPU_CORE_NAMES = {
  27. {PowerPC::CPUCore::Interpreter, QT_TR_NOOP("Interpreter (slowest)")},
  28. {PowerPC::CPUCore::CachedInterpreter, QT_TR_NOOP("Cached Interpreter (slower)")},
  29. {PowerPC::CPUCore::JIT64, QT_TR_NOOP("JIT Recompiler for x86-64 (recommended)")},
  30. {PowerPC::CPUCore::JITARM64, QT_TR_NOOP("JIT Recompiler for ARM64 (recommended)")},
  31. };
  32. AdvancedPane::AdvancedPane(QWidget* parent) : QWidget(parent)
  33. {
  34. CreateLayout();
  35. Update();
  36. ConnectLayout();
  37. connect(&Settings::Instance(), &Settings::EmulationStateChanged, this, &AdvancedPane::Update);
  38. }
  39. void AdvancedPane::CreateLayout()
  40. {
  41. auto* main_layout = new QVBoxLayout();
  42. setLayout(main_layout);
  43. auto* cpu_options_group = new QGroupBox(tr("CPU Options"));
  44. auto* cpu_options_group_layout = new QVBoxLayout();
  45. cpu_options_group->setLayout(cpu_options_group_layout);
  46. main_layout->addWidget(cpu_options_group);
  47. auto* cpu_emulation_engine_layout = new QFormLayout;
  48. cpu_emulation_engine_layout->setFormAlignment(Qt::AlignLeft | Qt::AlignTop);
  49. cpu_emulation_engine_layout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
  50. cpu_options_group_layout->addLayout(cpu_emulation_engine_layout);
  51. m_cpu_emulation_engine_combobox = new QComboBox(this);
  52. cpu_emulation_engine_layout->addRow(tr("CPU Emulation Engine:"), m_cpu_emulation_engine_combobox);
  53. for (PowerPC::CPUCore cpu_core : PowerPC::AvailableCPUCores())
  54. {
  55. m_cpu_emulation_engine_combobox->addItem(tr(CPU_CORE_NAMES.at(cpu_core)));
  56. }
  57. m_enable_mmu_checkbox = new ConfigBool(tr("Enable MMU"), Config::MAIN_MMU);
  58. m_enable_mmu_checkbox->SetDescription(
  59. tr("Enables the Memory Management Unit, needed for some games. (ON = Compatible, OFF = "
  60. "Fast)<br><br><dolphin_emphasis>If unsure, leave this unchecked.</dolphin_emphasis>"));
  61. cpu_options_group_layout->addWidget(m_enable_mmu_checkbox);
  62. m_pause_on_panic_checkbox = new ConfigBool(tr("Pause on Panic"), Config::MAIN_PAUSE_ON_PANIC);
  63. m_pause_on_panic_checkbox->SetDescription(
  64. tr("Pauses the emulation if a Read/Write or Unknown Instruction panic occurs.<br>Enabling "
  65. "will affect performance.<br>The performance impact is the same as having Enable MMU "
  66. "on.<br><br><dolphin_emphasis>If unsure, leave this unchecked.</dolphin_emphasis>"));
  67. cpu_options_group_layout->addWidget(m_pause_on_panic_checkbox);
  68. m_accurate_cpu_cache_checkbox =
  69. new ConfigBool(tr("Enable Write-Back Cache (slow)"), Config::MAIN_ACCURATE_CPU_CACHE);
  70. m_accurate_cpu_cache_checkbox->SetDescription(
  71. tr("Enables emulation of the CPU write-back cache.<br>Enabling will have a significant "
  72. "impact on performance.<br>This should be left disabled unless absolutely "
  73. "needed.<br><br><dolphin_emphasis>If unsure, leave this unchecked.</dolphin_emphasis>"));
  74. cpu_options_group_layout->addWidget(m_accurate_cpu_cache_checkbox);
  75. auto* clock_override = new QGroupBox(tr("Clock Override"));
  76. auto* clock_override_layout = new QVBoxLayout();
  77. clock_override->setLayout(clock_override_layout);
  78. main_layout->addWidget(clock_override);
  79. m_cpu_clock_override_checkbox = new QCheckBox(tr("Enable Emulated CPU Clock Override"));
  80. clock_override_layout->addWidget(m_cpu_clock_override_checkbox);
  81. auto* cpu_clock_override_slider_layout = new QHBoxLayout();
  82. cpu_clock_override_slider_layout->setContentsMargins(0, 0, 0, 0);
  83. clock_override_layout->addLayout(cpu_clock_override_slider_layout);
  84. m_cpu_clock_override_slider = new QSlider(Qt::Horizontal);
  85. m_cpu_clock_override_slider->setRange(1, 400);
  86. cpu_clock_override_slider_layout->addWidget(m_cpu_clock_override_slider);
  87. m_cpu_clock_override_slider_label = new QLabel();
  88. cpu_clock_override_slider_layout->addWidget(m_cpu_clock_override_slider_label);
  89. auto* cpu_clock_override_description =
  90. new QLabel(tr("Adjusts the emulated CPU's clock rate.\n\n"
  91. "Higher values may make variable-framerate games run at a higher framerate, "
  92. "at the expense of performance. Lower values may activate a game's "
  93. "internal frameskip, potentially improving performance.\n\n"
  94. "WARNING: Changing this from the default (100%) can and will "
  95. "break games and cause glitches. Do so at your own risk. "
  96. "Please do not report bugs that occur with a non-default clock."));
  97. cpu_clock_override_description->setWordWrap(true);
  98. clock_override_layout->addWidget(cpu_clock_override_description);
  99. auto* ram_override = new QGroupBox(tr("Memory Override"));
  100. auto* ram_override_layout = new QVBoxLayout();
  101. ram_override->setLayout(ram_override_layout);
  102. main_layout->addWidget(ram_override);
  103. m_ram_override_checkbox = new QCheckBox(tr("Enable Emulated Memory Size Override"));
  104. ram_override_layout->addWidget(m_ram_override_checkbox);
  105. auto* mem1_override_slider_layout = new QHBoxLayout();
  106. mem1_override_slider_layout->setContentsMargins(0, 0, 0, 0);
  107. ram_override_layout->addLayout(mem1_override_slider_layout);
  108. m_mem1_override_slider = new QSlider(Qt::Horizontal);
  109. m_mem1_override_slider->setRange(24, 64);
  110. mem1_override_slider_layout->addWidget(m_mem1_override_slider);
  111. m_mem1_override_slider_label = new QLabel();
  112. mem1_override_slider_layout->addWidget(m_mem1_override_slider_label);
  113. auto* mem2_override_slider_layout = new QHBoxLayout();
  114. mem2_override_slider_layout->setContentsMargins(0, 0, 0, 0);
  115. ram_override_layout->addLayout(mem2_override_slider_layout);
  116. m_mem2_override_slider = new QSlider(Qt::Horizontal);
  117. m_mem2_override_slider->setRange(64, 128);
  118. mem2_override_slider_layout->addWidget(m_mem2_override_slider);
  119. m_mem2_override_slider_label = new QLabel();
  120. mem2_override_slider_layout->addWidget(m_mem2_override_slider_label);
  121. auto* ram_override_description =
  122. new QLabel(tr("Adjusts the amount of RAM in the emulated console.\n\n"
  123. "WARNING: Enabling this will completely break many games. Only a small number "
  124. "of games can benefit from this."));
  125. ram_override_description->setWordWrap(true);
  126. ram_override_layout->addWidget(ram_override_description);
  127. auto* rtc_options = new QGroupBox(tr("Custom RTC Options"));
  128. rtc_options->setLayout(new QVBoxLayout());
  129. main_layout->addWidget(rtc_options);
  130. m_custom_rtc_checkbox = new QCheckBox(tr("Enable Custom RTC"));
  131. rtc_options->layout()->addWidget(m_custom_rtc_checkbox);
  132. m_custom_rtc_datetime = new QDateTimeEdit();
  133. // Show seconds
  134. m_custom_rtc_datetime->setDisplayFormat(m_custom_rtc_datetime->displayFormat().replace(
  135. QStringLiteral("mm"), QStringLiteral("mm:ss")));
  136. QtUtils::ShowFourDigitYear(m_custom_rtc_datetime);
  137. m_custom_rtc_datetime->setDateTimeRange(QDateTime({2000, 1, 1}, {0, 0, 0}, Qt::UTC),
  138. QDateTime({2099, 12, 31}, {23, 59, 59}, Qt::UTC));
  139. m_custom_rtc_datetime->setTimeSpec(Qt::UTC);
  140. rtc_options->layout()->addWidget(m_custom_rtc_datetime);
  141. auto* custom_rtc_description =
  142. new QLabel(tr("This setting allows you to set a custom real time clock (RTC) separate from "
  143. "your current system time.\n\nIf unsure, leave this unchecked."));
  144. custom_rtc_description->setWordWrap(true);
  145. rtc_options->layout()->addWidget(custom_rtc_description);
  146. main_layout->addStretch(1);
  147. }
  148. void AdvancedPane::ConnectLayout()
  149. {
  150. connect(m_cpu_emulation_engine_combobox, &QComboBox::currentIndexChanged, [](int index) {
  151. const auto cpu_cores = PowerPC::AvailableCPUCores();
  152. if (index >= 0 && static_cast<size_t>(index) < cpu_cores.size())
  153. Config::SetBaseOrCurrent(Config::MAIN_CPU_CORE, cpu_cores[index]);
  154. });
  155. connect(m_cpu_clock_override_checkbox, &QCheckBox::toggled, [this](bool enable_clock_override) {
  156. Config::SetBaseOrCurrent(Config::MAIN_OVERCLOCK_ENABLE, enable_clock_override);
  157. Update();
  158. });
  159. connect(m_cpu_clock_override_slider, &QSlider::valueChanged, [this](int oc_factor) {
  160. const float factor = m_cpu_clock_override_slider->value() / 100.f;
  161. Config::SetBaseOrCurrent(Config::MAIN_OVERCLOCK, factor);
  162. Update();
  163. });
  164. connect(m_ram_override_checkbox, &QCheckBox::toggled, [this](bool enable_ram_override) {
  165. Config::SetBaseOrCurrent(Config::MAIN_RAM_OVERRIDE_ENABLE, enable_ram_override);
  166. Update();
  167. });
  168. connect(m_mem1_override_slider, &QSlider::valueChanged, [this](int slider_value) {
  169. const u32 mem1_size = m_mem1_override_slider->value() * 0x100000;
  170. Config::SetBaseOrCurrent(Config::MAIN_MEM1_SIZE, mem1_size);
  171. Update();
  172. });
  173. connect(m_mem2_override_slider, &QSlider::valueChanged, [this](int slider_value) {
  174. const u32 mem2_size = m_mem2_override_slider->value() * 0x100000;
  175. Config::SetBaseOrCurrent(Config::MAIN_MEM2_SIZE, mem2_size);
  176. Update();
  177. });
  178. connect(m_custom_rtc_checkbox, &QCheckBox::toggled, [this](bool enable_custom_rtc) {
  179. Config::SetBaseOrCurrent(Config::MAIN_CUSTOM_RTC_ENABLE, enable_custom_rtc);
  180. Update();
  181. });
  182. connect(m_custom_rtc_datetime, &QDateTimeEdit::dateTimeChanged, [this](QDateTime date_time) {
  183. Config::SetBaseOrCurrent(Config::MAIN_CUSTOM_RTC_VALUE,
  184. static_cast<u32>(date_time.toSecsSinceEpoch()));
  185. Update();
  186. });
  187. }
  188. void AdvancedPane::Update()
  189. {
  190. const bool is_uninitialized = Core::IsUninitialized(Core::System::GetInstance());
  191. const bool enable_cpu_clock_override_widgets = Config::Get(Config::MAIN_OVERCLOCK_ENABLE);
  192. const bool enable_ram_override_widgets = Config::Get(Config::MAIN_RAM_OVERRIDE_ENABLE);
  193. const bool enable_custom_rtc_widgets =
  194. Config::Get(Config::MAIN_CUSTOM_RTC_ENABLE) && is_uninitialized;
  195. const auto available_cpu_cores = PowerPC::AvailableCPUCores();
  196. const auto cpu_core = Config::Get(Config::MAIN_CPU_CORE);
  197. for (size_t i = 0; i < available_cpu_cores.size(); ++i)
  198. {
  199. if (available_cpu_cores[i] == cpu_core)
  200. m_cpu_emulation_engine_combobox->setCurrentIndex(int(i));
  201. }
  202. m_cpu_emulation_engine_combobox->setEnabled(is_uninitialized);
  203. m_enable_mmu_checkbox->setEnabled(is_uninitialized);
  204. m_pause_on_panic_checkbox->setEnabled(is_uninitialized);
  205. {
  206. QFont bf = font();
  207. bf.setBold(Config::GetActiveLayerForConfig(Config::MAIN_OVERCLOCK_ENABLE) !=
  208. Config::LayerType::Base);
  209. const QSignalBlocker blocker(m_cpu_clock_override_checkbox);
  210. m_cpu_clock_override_checkbox->setFont(bf);
  211. m_cpu_clock_override_checkbox->setChecked(enable_cpu_clock_override_widgets);
  212. }
  213. m_cpu_clock_override_slider->setEnabled(enable_cpu_clock_override_widgets);
  214. m_cpu_clock_override_slider_label->setEnabled(enable_cpu_clock_override_widgets);
  215. {
  216. const QSignalBlocker blocker(m_cpu_clock_override_slider);
  217. m_cpu_clock_override_slider->setValue(
  218. static_cast<int>(std::round(Config::Get(Config::MAIN_OVERCLOCK) * 100.f)));
  219. }
  220. m_cpu_clock_override_slider_label->setText([] {
  221. int core_clock =
  222. Core::System::GetInstance().GetSystemTimers().GetTicksPerSecond() / std::pow(10, 6);
  223. int percent = static_cast<int>(std::round(Config::Get(Config::MAIN_OVERCLOCK) * 100.f));
  224. int clock = static_cast<int>(std::round(Config::Get(Config::MAIN_OVERCLOCK) * core_clock));
  225. return tr("%1% (%2 MHz)").arg(QString::number(percent), QString::number(clock));
  226. }());
  227. m_ram_override_checkbox->setEnabled(is_uninitialized);
  228. SignalBlocking(m_ram_override_checkbox)->setChecked(enable_ram_override_widgets);
  229. m_mem1_override_slider->setEnabled(enable_ram_override_widgets && is_uninitialized);
  230. m_mem1_override_slider_label->setEnabled(enable_ram_override_widgets && is_uninitialized);
  231. {
  232. const QSignalBlocker blocker(m_mem1_override_slider);
  233. const u32 mem1_size = Config::Get(Config::MAIN_MEM1_SIZE) / 0x100000;
  234. m_mem1_override_slider->setValue(mem1_size);
  235. }
  236. m_mem1_override_slider_label->setText([] {
  237. const u32 mem1_size = Config::Get(Config::MAIN_MEM1_SIZE) / 0x100000;
  238. return tr("%1 MB (MEM1)").arg(QString::number(mem1_size));
  239. }());
  240. m_mem2_override_slider->setEnabled(enable_ram_override_widgets && is_uninitialized);
  241. m_mem2_override_slider_label->setEnabled(enable_ram_override_widgets && is_uninitialized);
  242. {
  243. const QSignalBlocker blocker(m_mem2_override_slider);
  244. const u32 mem2_size = Config::Get(Config::MAIN_MEM2_SIZE) / 0x100000;
  245. m_mem2_override_slider->setValue(mem2_size);
  246. }
  247. m_mem2_override_slider_label->setText([] {
  248. const u32 mem2_size = Config::Get(Config::MAIN_MEM2_SIZE) / 0x100000;
  249. return tr("%1 MB (MEM2)").arg(QString::number(mem2_size));
  250. }());
  251. m_custom_rtc_checkbox->setEnabled(is_uninitialized);
  252. SignalBlocking(m_custom_rtc_checkbox)->setChecked(Config::Get(Config::MAIN_CUSTOM_RTC_ENABLE));
  253. QDateTime initial_date_time;
  254. initial_date_time.setSecsSinceEpoch(Config::Get(Config::MAIN_CUSTOM_RTC_VALUE));
  255. m_custom_rtc_datetime->setEnabled(enable_custom_rtc_widgets);
  256. SignalBlocking(m_custom_rtc_datetime)->setDateTime(initial_date_time);
  257. }