This commit is contained in:
2026-06-10 10:53:49 +02:00
parent e72abc2407
commit ac4af8106c
11 changed files with 139 additions and 70 deletions
+92 -31
View File
@@ -22,11 +22,11 @@ KaizenGui::KaizenGui() noexcept : QMainWindow(nullptr), settings(QSettings::User
vulkanWidget->hide();
cpuTypeLabel = new QLabel("Interpreter");
if (Options::GetCpuType() == 1)
if (Options::GetCpuType() == n64::CachedInterpreter)
cpuTypeLabel->setText("Cached Interpreter");
idleSkipLabel = new QLabel("Idle skipping");
if (!Options::GetIdleSkip())
if (!Options::GetIdleSkip() || Options::GetCpuType() == n64::PlainInterpreter)
idleSkipLabel->hide();
fpsLabel = new QLabel("Not running");
@@ -42,7 +42,7 @@ KaizenGui::KaizenGui() noexcept : QMainWindow(nullptr), settings(QSettings::User
setAcceptDrops(true);
statusBarTimer = new QTimer();
statusBarTimer->setInterval(1000);
statusBarTimer->setInterval(500);
connect(statusBarTimer, &QTimer::timeout, this, [&] {
pause->setText("Pause");
@@ -53,6 +53,7 @@ KaizenGui::KaizenGui() noexcept : QMainWindow(nullptr), settings(QSettings::User
}
if (!core.romLoaded) {
pause->setText("Pause");
pause->setDisabled(true);
reset->setDisabled(true);
stop->setDisabled(true);
@@ -64,11 +65,11 @@ KaizenGui::KaizenGui() noexcept : QMainWindow(nullptr), settings(QSettings::User
auto fileMenu = menuBar()->addMenu("File");
auto open = fileMenu->addAction("Open");
open->setShortcut(QKeyCombination(Qt::CTRL, Qt::Key_O));
connect(open, &QAction::triggered, this, [&] {
auto fileToLoad =
QFileDialog::getOpenFileName(this, "Select a Nintendo 64 ROM", QDir::currentPath(),
"N64 ROM (*.z64 *.n64 *.v64)", nullptr, QFileDialog::DontUseNativeDialog)
.toStdString();
auto fileToLoad = QFileDialog::getOpenFileName(this, "Select a Nintendo 64 ROM", QDir::currentPath(),
"N64 ROM (*.z64 *.n64 *.v64)")
.toStdString();
if (!fileToLoad.empty())
LoadROM(fileToLoad);
});
@@ -82,20 +83,28 @@ KaizenGui::KaizenGui() noexcept : QMainWindow(nullptr), settings(QSettings::User
connect(settingsMenu, &QAction::triggered, settingsWindow, &SettingsWindow::show);
connect(settingsWindow->cpu, &CPUSettings::cpuTypeChanged, this, [&] {
core.cpuType = Options::GetCpuType();
cpuTypeLabel->setText("Cached Interpreter");
if (Options::GetCpuType() == 0)
idleSkipLabel->setVisible(Options::GetCpuType() == n64::CachedInterpreter);
if (Options::GetCpuType() == n64::PlainInterpreter)
cpuTypeLabel->setText("Interpreter");
});
connect(settingsWindow->cpu, &CPUSettings::idleSkipChanged, this, [&] {
idleSkipLabel->show();
if (!Options::GetIdleSkip())
idleSkipLabel->hide();
core.idleSkip = Options::GetIdleSkip();
idleSkipLabel->setVisible(Options::GetIdleSkip());
});
emulationMenu->addSeparator();
auto unlockFramerate = emulationMenu->addAction("Unlock framerate");
unlockFramerate->setCheckable(true);
connect(unlockFramerate, &QAction::triggered, this,
[&](bool checked) { core.parallel.SetFramerateUnlocked(checked); });
pause->setDisabled(true);
pause->setShortcut(QKeyCombination(Qt::CTRL, Qt::Key_P));
emulationMenu->addAction(pause);
connect(pause, &QAction::triggered, this, [&] {
if (!core.pause)
@@ -104,11 +113,14 @@ KaizenGui::KaizenGui() noexcept : QMainWindow(nullptr), settings(QSettings::User
core.TogglePause();
});
reset->setDisabled(true);
reset->setShortcut(QKeyCombination(Qt::CTRL, Qt::Key_R));
emulationMenu->addAction(reset);
connect(reset, &QAction::triggered, this, [&] { Scheduler::GetInstance().EnqueueRelative(0, RESET); });
stop->setDisabled(true);
stop->setShortcut(QKeyCombination(Qt::CTRL, Qt::Key_X));
emulationMenu->addAction(stop);
connect(stop, &QAction::triggered, this, [&] {
Scheduler::GetInstance().EnqueueRelative(0, STOP);
@@ -134,47 +146,82 @@ KaizenGui::KaizenGui() noexcept : QMainWindow(nullptr), settings(QSettings::User
core.parallel.Init(vulkanWidget->wsiPlatform, vulkanWidget->windowInfo, vulkanWidget->qtVkInstanceFactory.get(),
core.GetMem().GetRDRAMPtr());
while (!emuThread->isInterruptionRequested()) {
if (!core.romLoaded) {
core.parallel.UpdateScreen<false>();
if (!core.romLoaded || core.pause)
continue;
}
if (!core.pause) {
auto timeStart = SDL_GetTicks();
core.Run();
core.parallel.UpdateScreen<true>();
elapsed = SDL_GetTicks() - timeStart;
continue;
}
updateKeys();
updateAxis();
auto timeStart = SDL_GetTicks();
core.Run();
core.parallel.UpdateScreen();
elapsed = SDL_GetTicks() - timeStart;
}
});
emuThread->start();
}
KaizenGui::~KaizenGui() {
SDL_Quit();
emuThread->requestInterruption();
emuThread->quit();
KaizenGui::~KaizenGui() { cleanup(); }
void KaizenGui::updateKeys() {
auto &pif = core.mem->mmio.si.pif;
pif.UpdateButton(0, n64::Controller::Z, pressedKeys.test(0));
pif.UpdateButton(0, n64::Controller::A, pressedKeys.test(1));
pif.UpdateButton(0, n64::Controller::B, pressedKeys.test(2));
pif.UpdateButton(0, n64::Controller::LT, pressedKeys.test(3));
pif.UpdateButton(0, n64::Controller::RT, pressedKeys.test(4));
pif.UpdateButton(0, n64::Controller::Start, pressedKeys.test(5));
pif.UpdateButton(0, n64::Controller::DUp, pressedKeys.test(6));
pif.UpdateButton(0, n64::Controller::DDown, pressedKeys.test(7));
pif.UpdateButton(0, n64::Controller::DLeft, pressedKeys.test(8));
pif.UpdateButton(0, n64::Controller::DRight, pressedKeys.test(9));
pif.UpdateButton(0, n64::Controller::CUp, pressedKeys.test(10));
pif.UpdateButton(0, n64::Controller::CDown, pressedKeys.test(11));
pif.UpdateButton(0, n64::Controller::CLeft, pressedKeys.test(12));
pif.UpdateButton(0, n64::Controller::CRight, pressedKeys.test(13));
}
void KaizenGui::updateAxis() {
s16 x = 0, y = 0;
auto &pif = core.mem->mmio.si.pif;
if (pressedKeys.test(14)) // up
y += 86;
if (pressedKeys.test(15)) // down
y -= 86;
if (pressedKeys.test(16)) // left
x -= 86;
if (pressedKeys.test(17)) // right
x += 86;
core.mem->mmio.si.pif.UpdateAxis(0, n64::Controller::X, x);
core.mem->mmio.si.pif.UpdateAxis(0, n64::Controller::Y, y);
}
void KaizenGui::LoadROM(const std::string &path) noexcept {
n64::Core &core = n64::Core::GetInstance();
core.LoadROM(path);
pause->setEnabled(true);
reset->setEnabled(true);
stop->setEnabled(true);
vulkanWidget->show();
setWindowTitle(("Kaizen " KAIZEN_VERSION_STR " - " + n64::Core::GetMem().rom.gameNameDB).c_str());
setWindowTitle(("Kaizen " KAIZEN_VERSION_STR " - " + core.mem->rom.gameNameDB).c_str());
}
void KaizenGui::LoadTAS(const std::string &path) noexcept { n64::Core::GetInstance().LoadTAS(fs::path(path)); }
void KaizenGui::LoadTAS(const std::string &path) noexcept { core.LoadTAS(fs::path(path)); }
void KaizenGui::closeEvent(QCloseEvent *event) {
Scheduler::GetInstance().EnqueueRelative(0, STOP);
void KaizenGui::cleanup() {
SDL_Quit();
core.Stop();
emuThread->requestInterruption();
emuThread->quit();
delete emuThread;
delete vulkanWidget;
delete settingsWindow;
settings.setValue("geometry", saveGeometry());
settings.setValue("windowState", saveState());
QMainWindow::closeEvent(event);
}
void KaizenGui::dropEvent(QDropEvent *event) {
@@ -189,3 +236,17 @@ void KaizenGui::dragEnterEvent(QDragEnterEvent *event) {
if (event->mimeData()->hasUrls())
event->acceptProposedAction();
}
void KaizenGui::keyPressEvent(QKeyEvent *event) {
for (int i = 0; i < mapping.size(); i++) {
if (mapping[i] == event->key())
pressedKeys.set(i);
}
}
void KaizenGui::keyReleaseEvent(QKeyEvent *event) {
for (int i = 0; i < mapping.size(); i++) {
if (mapping[i] == event->key())
pressedKeys.reset(i);
}
}