hook up savestate shito

This commit is contained in:
Arisotura 2020-04-29 00:50:23 +02:00
parent 47ff012f5e
commit 5fbad464c2
4 changed files with 149 additions and 2 deletions

View File

@ -47,7 +47,7 @@ bool LoadBIOS();
// note: loading a ROM to the NDS slot resets emulation
bool LoadROM(const char* file, int slot);
// get the filename associated with the given savestate slot
// get the filename associated with the given savestate slot (1-8)
void GetSavestateName(int slot, char* filename, int len);
// determine whether the given savestate slot does contain a savestate

View File

@ -69,6 +69,8 @@ bool LoadBIOS()
NDS::LoadBIOS();
SavestateLoaded = false;
// TODO: error reporting?
return true;
}

View File

@ -395,7 +395,7 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
{
QMenu* menu = menubar->addMenu("File");
actOpenROM = menu->addAction("Open file...");
actOpenROM = menu->addAction("Open ROM...");
connect(actOpenROM, &QAction::triggered, this, &MainWindow::onOpenFile);
//actBootFirmware = menu->addAction("Launch DS menu");
@ -404,6 +404,49 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
menu->addSeparator();
{
QMenu* submenu = menu->addMenu("Save state");
for (int i = 1; i < 9; i++)
{
char title[16];
sprintf(title, "%d", i);
actSaveState[i] = submenu->addAction(title);
actSaveState[i]->setShortcut(QKeySequence(Qt::ShiftModifier | (Qt::Key_F1+i-1)));
actSaveState[i]->setData(QVariant(i));
connect(actSaveState[i], &QAction::triggered, this, &MainWindow::onSaveState);
}
actSaveState[0] = submenu->addAction("File...");
actSaveState[0]->setShortcut(QKeySequence(Qt::ShiftModifier | Qt::Key_F9));
actSaveState[0]->setData(QVariant(0));
connect(actSaveState[0], &QAction::triggered, this, &MainWindow::onSaveState);
}
{
QMenu* submenu = menu->addMenu("Load state");
for (int i = 1; i < 9; i++)
{
char title[16];
sprintf(title, "%d", i);
actLoadState[i] = submenu->addAction(title);
actLoadState[i]->setShortcut(QKeySequence(Qt::Key_F1+i-1));
actLoadState[i]->setData(QVariant(i));
connect(actLoadState[i], &QAction::triggered, this, &MainWindow::onLoadState);
}
actLoadState[0] = submenu->addAction("File...");
actLoadState[0]->setShortcut(QKeySequence(Qt::Key_F9));
actLoadState[0]->setData(QVariant(0));
connect(actLoadState[0], &QAction::triggered, this, &MainWindow::onLoadState);
}
actUndoStateLoad = menu->addAction("Undo state load");
actUndoStateLoad->setShortcut(QKeySequence(Qt::Key_F12));
connect(actUndoStateLoad, &QAction::triggered, this, &MainWindow::onUndoStateLoad);
menu->addSeparator();
actQuit = menu->addAction("Quit");
connect(actQuit, &QAction::triggered, this, &MainWindow::onQuit);
}
@ -499,6 +542,102 @@ void MainWindow::onBootFirmware()
}
}
void MainWindow::onSaveState()
{
int slot = ((QAction*)sender())->data().toInt();
emuThread->emuPause(true);
char filename[1024];
if (slot > 0)
{
Frontend::GetSavestateName(slot, filename, 1024);
}
else
{
// TODO: specific 'last directory' for savestate files?
QString qfilename = QFileDialog::getSaveFileName(this,
"Save state",
Config::LastROMFolder,
"melonDS savestates (*.mln);;Any file (*.*)");
if (qfilename.isEmpty())
{
emuThread->emuUnpause();
return;
}
strncpy(filename, qfilename.toStdString().c_str(), 1023); filename[1023] = '\0';
}
if (Frontend::SaveState(filename))
{
// TODO: OSD message
}
else
{
// TODO: OSD error message?
}
emuThread->emuUnpause();
}
void MainWindow::onLoadState()
{
int slot = ((QAction*)sender())->data().toInt();
emuThread->emuPause(true);
char filename[1024];
if (slot > 0)
{
Frontend::GetSavestateName(slot, filename, 1024);
}
else
{
// TODO: specific 'last directory' for savestate files?
QString qfilename = QFileDialog::getOpenFileName(this,
"Load state",
Config::LastROMFolder,
"melonDS savestates (*.ml*);;Any file (*.*)");
if (qfilename.isEmpty())
{
emuThread->emuUnpause();
return;
}
strncpy(filename, qfilename.toStdString().c_str(), 1023); filename[1023] = '\0';
}
if (!Platform::FileExists(filename))
{
/*char msg[64];
if (slot > 0) sprintf(msg, "State slot %d is empty", slot);
else sprintf(msg, "State file does not exist");
OSD::AddMessage(0xFFA0A0, msg);*/
emuThread->emuUnpause();
return;
}
if (Frontend::LoadState(filename))
{
// TODO: OSD message
}
else
{
// TODO: OSD error message?
}
emuThread->emuUnpause();
}
void MainWindow::onUndoStateLoad()
{
emuThread->emuPause(true);
Frontend::UndoStateLoad();
emuThread->emuUnpause();
}
void MainWindow::onQuit()
{
QApplication::quit();

View File

@ -81,6 +81,9 @@ protected:
private slots:
void onOpenFile();
void onBootFirmware();
void onSaveState();
void onLoadState();
void onUndoStateLoad();
void onQuit();
void onTitleUpdate(QString title);
@ -90,6 +93,9 @@ private:
QAction* actOpenROM;
QAction* actBootFirmware;
QAction* actSaveState[9];
QAction* actLoadState[9];
QAction* actUndoStateLoad;
QAction* actQuit;
};