From b4280ee33d96f9b3303a7f6f5f513309ef5fb463 Mon Sep 17 00:00:00 2001 From: Matthew Budd Date: Sat, 11 Jul 2020 14:03:40 -0400 Subject: [PATCH] Added menu logic to load Game Genie ROM file --- src/drivers/Qt/ConsoleWindow.cpp | 68 +++++++++++++++++++++++++++++++- src/drivers/Qt/ConsoleWindow.h | 2 + 2 files changed, 69 insertions(+), 1 deletion(-) diff --git a/src/drivers/Qt/ConsoleWindow.cpp b/src/drivers/Qt/ConsoleWindow.cpp index e3b9bcc7..8f69bdf6 100644 --- a/src/drivers/Qt/ConsoleWindow.cpp +++ b/src/drivers/Qt/ConsoleWindow.cpp @@ -1,5 +1,8 @@ // GameApp.cpp // +#include +#include +#include #include #include "../../fceu.h" @@ -331,7 +334,7 @@ void consoleWin_t::createMainMenu(void) emuMenu->addSeparator(); - // Options -> Full Screen + // Emulation -> Enable Game Genie gameGenieAct = new QAction(tr("Enable Game Genie"), this); //gameGenieAct->setShortcut( QKeySequence(tr("Ctrl+G"))); gameGenieAct->setCheckable(true); @@ -342,6 +345,16 @@ void consoleWin_t::createMainMenu(void) emuMenu->addAction(gameGenieAct); + // Emulation -> Load Game Genie ROM + loadGgROMAct = new QAction(tr("Load Game Genie ROM"), this); + //loadGgROMAct->setShortcut( QKeySequence(tr("Ctrl+G"))); + loadGgROMAct->setStatusTip(tr("Load Game Genie ROM")); + connect(loadGgROMAct, SIGNAL(triggered()), this, SLOT(loadGameGenieROM(void)) ); + + emuMenu->addAction(loadGgROMAct); + + emuMenu->addSeparator(); + //----------------------------------------------------------------------- // Help helpMenu = menuBar()->addMenu(tr("Help")); @@ -855,6 +868,59 @@ void consoleWin_t::toggleGameGenie(bool checked) return; } +void consoleWin_t::loadGameGenieROM(void) +{ + int ret; + QString filename; + std::string last; + QFileDialog dialog(this, tr("Open Game Genie ROM") ); + + dialog.setFileMode(QFileDialog::ExistingFile); + + dialog.setNameFilter(tr("GG ROM File (gg.rom)(*Genie*.nes) ;; All files (*)")); + + dialog.setViewMode(QFileDialog::List); + + g_config->getOption ("SDL.LastOpenFile", &last ); + + dialog.setDirectory( tr(last.c_str()) ); + + // the gnome default file dialog is not playing nice with QT. + // TODO make this a config option to use native file dialog. + dialog.setOption(QFileDialog::DontUseNativeDialog, true); + + dialog.show(); + ret = dialog.exec(); + + if ( ret ) + { + QStringList fileList; + fileList = dialog.selectedFiles(); + + if ( fileList.size() > 0 ) + { + filename = fileList[0]; + } + } + + if ( filename.isNull() ) + { + return; + } + qDebug() << "selected file path : " << filename.toUtf8(); + + g_config->setOption ("SDL.LastOpenFile", filename.toStdString().c_str() ); + + // copy file to proper place (~/.fceux/gg.rom) + std::ifstream f1 ( filename.toStdString().c_str(), std::fstream::binary); + std::string fn_out = FCEU_MakeFName (FCEUMKF_GGROM, 0, ""); + std::ofstream f2 (fn_out.c_str (), + std::fstream::trunc | std::fstream::binary); + f2 << f1.rdbuf (); + + return; +} + void consoleWin_t::aboutFCEUX(void) { printf("About FCEUX\n"); diff --git a/src/drivers/Qt/ConsoleWindow.h b/src/drivers/Qt/ConsoleWindow.h index a4b6bebb..032ec9af 100644 --- a/src/drivers/Qt/ConsoleWindow.h +++ b/src/drivers/Qt/ConsoleWindow.h @@ -75,6 +75,7 @@ class consoleWin_t : public QMainWindow QAction *sresetAct; QAction *pauseAct; QAction *gameGenieAct; + QAction *loadGgROMAct; QTimer *gameTimer; emulatorThread_t *emulatorThread; @@ -124,6 +125,7 @@ class consoleWin_t : public QMainWindow void consoleSoftReset(void); void consolePause(void); void toggleGameGenie(bool checked); + void loadGameGenieROM(void); };