2023-09-02 07:27:34 +00:00
|
|
|
// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com>
|
2022-12-04 11:03:45 +00:00
|
|
|
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
|
|
|
|
|
2020-09-22 13:08:07 +00:00
|
|
|
#include "biossettingswidget.h"
|
2022-07-11 13:03:29 +00:00
|
|
|
#include "qthost.h"
|
2020-09-23 12:53:51 +00:00
|
|
|
#include "qtutils.h"
|
2020-09-22 13:08:07 +00:00
|
|
|
#include "settingsdialog.h"
|
|
|
|
#include "settingwidgetbinder.h"
|
2023-09-02 07:27:34 +00:00
|
|
|
|
|
|
|
#include "core/bios.h"
|
|
|
|
#include "core/settings.h"
|
|
|
|
|
2020-09-22 13:08:07 +00:00
|
|
|
#include <QtWidgets/QFileDialog>
|
|
|
|
#include <algorithm>
|
|
|
|
|
2022-07-11 13:03:29 +00:00
|
|
|
BIOSSettingsWidget::BIOSSettingsWidget(SettingsDialog* dialog, QWidget* parent) : QWidget(parent), m_dialog(dialog)
|
|
|
|
{
|
|
|
|
SettingsInterface* sif = dialog->getSettingsInterface();
|
|
|
|
|
|
|
|
m_ui.setupUi(this);
|
|
|
|
|
2023-08-29 11:18:04 +00:00
|
|
|
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.enableTTYLogging, "BIOS", "TTYLogging", false);
|
2022-07-11 13:03:29 +00:00
|
|
|
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.fastBoot, "BIOS", "PatchFastBoot", false);
|
|
|
|
|
|
|
|
dialog->registerWidgetHelp(m_ui.fastBoot, tr("Fast Boot"), tr("Unchecked"),
|
|
|
|
tr("Patches the BIOS to skip the console's boot animation. Does not work with all games, "
|
|
|
|
"but usually safe to enable."));
|
2023-09-02 07:27:34 +00:00
|
|
|
dialog->registerWidgetHelp(m_ui.enableTTYLogging, tr("Enable TTY Logging"), tr("Unchecked"),
|
|
|
|
tr("Logs BIOS calls to printf(). Not all games contain debugging messages."));
|
2022-07-11 13:03:29 +00:00
|
|
|
|
|
|
|
connect(m_ui.imageNTSCJ, QOverload<int>::of(&QComboBox::currentIndexChanged), [this](int index) {
|
|
|
|
if (m_dialog->isPerGameSettings() && index == 0)
|
|
|
|
{
|
|
|
|
m_dialog->removeSettingValue("BIOS", "PathNTSCJ");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_dialog->setStringSettingValue("BIOS", "PathNTSCJ",
|
|
|
|
m_ui.imageNTSCJ->itemData(index).toString().toStdString().c_str());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
connect(m_ui.imageNTSCU, QOverload<int>::of(&QComboBox::currentIndexChanged), [this](int index) {
|
|
|
|
if (m_dialog->isPerGameSettings() && index == 0)
|
|
|
|
{
|
|
|
|
m_dialog->removeSettingValue("BIOS", "PathNTSCU");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_dialog->setStringSettingValue("BIOS", "PathNTSCU",
|
|
|
|
m_ui.imageNTSCU->itemData(index).toString().toStdString().c_str());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
connect(m_ui.imagePAL, QOverload<int>::of(&QComboBox::currentIndexChanged), [this](int index) {
|
|
|
|
if (m_dialog->isPerGameSettings() && index == 0)
|
|
|
|
{
|
|
|
|
m_dialog->removeSettingValue("BIOS", "PathPAL");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_dialog->setStringSettingValue("BIOS", "PathPAL",
|
|
|
|
m_ui.imagePAL->itemData(index).toString().toStdString().c_str());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
connect(m_ui.refresh, &QPushButton::clicked, this, &BIOSSettingsWidget::refreshList);
|
|
|
|
|
|
|
|
m_ui.searchDirectory->setText(QString::fromStdString(EmuFolders::Bios));
|
|
|
|
SettingWidgetBinder::BindWidgetToFolderSetting(sif, m_ui.searchDirectory, m_ui.browseSearchDirectory,
|
|
|
|
m_ui.openSearchDirectory, nullptr, "BIOS", "SearchDirectory",
|
|
|
|
Path::Combine(EmuFolders::DataRoot, "bios"));
|
|
|
|
connect(m_ui.searchDirectory, &QLineEdit::textChanged, this, &BIOSSettingsWidget::refreshList);
|
|
|
|
refreshList();
|
|
|
|
}
|
|
|
|
|
|
|
|
BIOSSettingsWidget::~BIOSSettingsWidget() = default;
|
|
|
|
|
2023-09-02 07:27:34 +00:00
|
|
|
std::vector<std::pair<std::string, const BIOS::ImageInfo*>> BIOSSettingsWidget::getList(const char* directory)
|
|
|
|
{
|
|
|
|
return BIOS::FindBIOSImagesInDirectory(directory);
|
|
|
|
}
|
|
|
|
|
2022-07-11 13:03:29 +00:00
|
|
|
void BIOSSettingsWidget::refreshList()
|
|
|
|
{
|
2023-09-02 07:27:34 +00:00
|
|
|
auto images = getList(m_ui.searchDirectory->text().toUtf8().constData());
|
|
|
|
populateDropDownForRegion(ConsoleRegion::NTSC_J, m_ui.imageNTSCJ, images, m_dialog->isPerGameSettings());
|
|
|
|
populateDropDownForRegion(ConsoleRegion::NTSC_U, m_ui.imageNTSCU, images, m_dialog->isPerGameSettings());
|
|
|
|
populateDropDownForRegion(ConsoleRegion::PAL, m_ui.imagePAL, images, m_dialog->isPerGameSettings());
|
|
|
|
|
|
|
|
setDropDownValue(m_ui.imageNTSCJ, m_dialog->getStringValue("BIOS", "PathNTSCJ", std::nullopt),
|
|
|
|
m_dialog->isPerGameSettings());
|
|
|
|
setDropDownValue(m_ui.imageNTSCU, m_dialog->getStringValue("BIOS", "PathNTSCU", std::nullopt),
|
|
|
|
m_dialog->isPerGameSettings());
|
|
|
|
setDropDownValue(m_ui.imagePAL, m_dialog->getStringValue("BIOS", "PathPAL", std::nullopt),
|
|
|
|
m_dialog->isPerGameSettings());
|
2022-07-11 13:03:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BIOSSettingsWidget::populateDropDownForRegion(ConsoleRegion region, QComboBox* cb,
|
2023-09-02 07:27:34 +00:00
|
|
|
std::vector<std::pair<std::string, const BIOS::ImageInfo*>>& images,
|
|
|
|
bool per_game)
|
2020-09-22 13:08:07 +00:00
|
|
|
{
|
2020-09-23 12:53:51 +00:00
|
|
|
QSignalBlocker sb(cb);
|
|
|
|
cb->clear();
|
|
|
|
|
2023-09-02 07:27:34 +00:00
|
|
|
if (per_game)
|
2022-07-11 13:03:29 +00:00
|
|
|
cb->addItem(QIcon(QStringLiteral(":/icons/system-search.png")), tr("Use Global Setting"));
|
|
|
|
|
|
|
|
cb->addItem(QIcon(QStringLiteral(":/icons/system-search.png")), tr("Auto-Detect"));
|
2020-09-22 13:08:07 +00:00
|
|
|
|
|
|
|
std::sort(images.begin(), images.end(), [region](const auto& left, const auto& right) {
|
|
|
|
const bool left_region_match = (left.second && left.second->region == region);
|
|
|
|
const bool right_region_match = (right.second && right.second->region == region);
|
|
|
|
if (left_region_match && !right_region_match)
|
|
|
|
return true;
|
2020-11-01 12:12:04 +00:00
|
|
|
else if (right_region_match && !left_region_match)
|
2020-09-22 13:08:07 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return left.first < right.first;
|
|
|
|
});
|
|
|
|
|
|
|
|
for (const auto& [name, info] : images)
|
|
|
|
{
|
|
|
|
QString name_str(QString::fromStdString(name));
|
2022-07-11 13:03:29 +00:00
|
|
|
cb->addItem(QtUtils::GetIconForRegion(info ? info->region : ConsoleRegion::Count),
|
2020-09-22 13:08:07 +00:00
|
|
|
QStringLiteral("%1 (%2)")
|
|
|
|
.arg(info ? QString(info->description) : qApp->translate("BIOSSettingsWidget", "Unknown"))
|
|
|
|
.arg(name_str),
|
|
|
|
QVariant(name_str));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-02 07:27:34 +00:00
|
|
|
void BIOSSettingsWidget::setDropDownValue(QComboBox* cb, const std::optional<std::string>& name, bool per_game)
|
2020-09-22 13:08:07 +00:00
|
|
|
{
|
|
|
|
QSignalBlocker sb(cb);
|
|
|
|
|
2022-07-11 13:03:29 +00:00
|
|
|
if (!name.has_value() || name->empty())
|
2020-09-22 13:08:07 +00:00
|
|
|
{
|
2023-09-02 07:27:34 +00:00
|
|
|
cb->setCurrentIndex((per_game && name.has_value()) ? 1 : 0);
|
2020-09-22 13:08:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-07-11 13:03:29 +00:00
|
|
|
QString qname(QString::fromStdString(name.value()));
|
2020-09-22 13:08:07 +00:00
|
|
|
for (int i = 1; i < cb->count(); i++)
|
|
|
|
{
|
|
|
|
if (cb->itemData(i) == qname)
|
|
|
|
{
|
|
|
|
cb->setCurrentIndex(i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cb->addItem(qname, QVariant(qname));
|
|
|
|
cb->setCurrentIndex(cb->count() - 1);
|
|
|
|
}
|