From 3c2a93d7c4856371deeb7defac9e12d49ff8a490 Mon Sep 17 00:00:00 2001 From: Matthew Budd Date: Mon, 27 Jul 2020 21:20:25 -0400 Subject: [PATCH 01/15] Added a protection in the audio output loop to break out of the loop if the audio sink is not draining. This will prevent lockups in the event that the audio output device has failed. --- src/drivers/Qt/sdl-sound.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/drivers/Qt/sdl-sound.cpp b/src/drivers/Qt/sdl-sound.cpp index 28c263ba..d869fc49 100644 --- a/src/drivers/Qt/sdl-sound.cpp +++ b/src/drivers/Qt/sdl-sound.cpp @@ -195,11 +195,19 @@ WriteSound(int32 *buf, extern int EmulationPaused; if (EmulationPaused == 0) { + int waitCount = 0; + while(Count) { while(s_BufferIn == s_BufferSize) { - SDL_Delay(1); + SDL_Delay(1); waitCount++; + + if ( waitCount > 1000 ) + { + printf("Error: Sound sink is not draining... Breaking out of audio loop to prevent lockup.\n"); + return; + } } s_Buffer[s_BufferWrite] = *buf; From c76d70582a05655544882721d488e53255c727fa Mon Sep 17 00:00:00 2001 From: Matthew Budd Date: Mon, 27 Jul 2020 22:26:41 -0400 Subject: [PATCH 02/15] Adding GUI framework for cheat window. --- src/CMakeLists.txt | 1 + src/drivers/Qt/CheatsConf.cpp | 171 +++++++++++++++++++++++++++++++ src/drivers/Qt/CheatsConf.h | 55 ++++++++++ src/drivers/Qt/ConsoleWindow.cpp | 29 ++++++ src/drivers/Qt/ConsoleWindow.h | 3 + 5 files changed, 259 insertions(+) create mode 100644 src/drivers/Qt/CheatsConf.cpp create mode 100644 src/drivers/Qt/CheatsConf.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 261e45cb..7e51a044 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -391,6 +391,7 @@ set(SRC_DRIVERS_SDL ${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/PaletteConf.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/GuiConf.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/LuaControl.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/CheatsConf.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/ConsoleUtilities.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/ConsoleVideoConf.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/ConsoleSoundConf.cpp diff --git a/src/drivers/Qt/CheatsConf.cpp b/src/drivers/Qt/CheatsConf.cpp new file mode 100644 index 00000000..b78c4df0 --- /dev/null +++ b/src/drivers/Qt/CheatsConf.cpp @@ -0,0 +1,171 @@ +// HotKeyConf.cpp +// +#include +#include +#include +#include + +#include +#include + +#include "Qt/main.h" +#include "Qt/dface.h" +#include "Qt/input.h" +#include "Qt/config.h" +#include "Qt/keyscan.h" +#include "Qt/fceuWrapper.h" +#include "Qt/CheatsConf.h" + +//---------------------------------------------------------------------------- +GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) + : QDialog( parent ) +{ + QHBoxLayout *mainLayout, *hbox; + QVBoxLayout *vbox; + QTreeWidgetItem *item; + QLabel *lbl; + + setWindowTitle("Cheat Search"); + + //resize( 512, 512 ); + + mainLayout = new QHBoxLayout(); + + actCheatFrame = new QGroupBox( tr("Active Cheats") ); + + vbox = new QVBoxLayout(); + + mainLayout->addWidget( actCheatFrame ); + + tree = new QTreeWidget(); + + tree->setColumnCount(2); + + item = new QTreeWidgetItem(); + item->setText( 0, QString::fromStdString( "Code" ) ); + item->setText( 1, QString::fromStdString( "Name" ) ); + item->setTextAlignment( 0, Qt::AlignLeft); + item->setTextAlignment( 1, Qt::AlignLeft); + + tree->setHeaderItem( item ); + + tree->header()->setSectionResizeMode( QHeaderView::ResizeToContents ); + + //for (int i=0; igetOption (optionName.c_str (), &keycode); + + // item = new QTreeWidgetItem(); + + // item->setText( 0, QString::fromStdString( optionName ) ); + // item->setText( 1, QString::fromStdString( SDL_GetKeyName (keycode) ) ); + + // item->setTextAlignment( 0, Qt::AlignLeft); + // item->setTextAlignment( 1, Qt::AlignCenter); + + // tree->addTopLevelItem( item ); + //} + // + + vbox->addWidget( tree ); + + hbox = new QHBoxLayout(); + + lbl = new QLabel( tr("Name:") ); + cheatNameEntry = new QLineEdit(); + + hbox->addWidget( lbl ); + hbox->addWidget( cheatNameEntry ); + + vbox->addLayout( hbox ); + + hbox = new QHBoxLayout(); + + lbl = new QLabel( tr("Address:") ); + cheatAddrEntry = new QLineEdit(); + + hbox->addWidget( lbl ); + hbox->addWidget( cheatAddrEntry ); + + lbl = new QLabel( tr("Value:") ); + cheatValEntry = new QLineEdit(); + + hbox->addWidget( lbl ); + hbox->addWidget( cheatValEntry ); + + lbl = new QLabel( tr("Compare:") ); + cheatCmpEntry = new QLineEdit(); + + hbox->addWidget( lbl ); + hbox->addWidget( cheatCmpEntry ); + + vbox->addLayout( hbox ); + + hbox = new QHBoxLayout(); + + addCheatBtn = new QPushButton( tr("Add") ); + delCheatBtn = new QPushButton( tr("Delete") ); + modCheatBtn = new QPushButton( tr("Update") ); + + hbox->addWidget( addCheatBtn ); + hbox->addWidget( delCheatBtn ); + hbox->addWidget( modCheatBtn ); + + vbox->addLayout( hbox ); + + hbox = new QHBoxLayout(); + + importCheatFileBtn = new QPushButton( tr("Import") ); + exportCheatFileBtn = new QPushButton( tr("Export") ); + + hbox->addWidget( importCheatFileBtn ); + hbox->addWidget( exportCheatFileBtn ); + + vbox->addLayout( hbox ); + + actCheatFrame->setLayout( vbox ); + + cheatSearchFrame = new QGroupBox( tr("Cheat Search") ); + cheatResultFrame = new QGroupBox( tr("Possibilities") ); + + hbox = new QHBoxLayout(); + + vbox = new QVBoxLayout(); + + hbox->addLayout( vbox ); + hbox->addWidget( cheatResultFrame ); + + cheatSearchFrame->setLayout( hbox ); + + srchResetBtn = new QPushButton( tr("Reset") ); + knownValBtn = new QPushButton( tr("Known Value:") ); + + vbox->addWidget( srchResetBtn ); + vbox->addWidget( knownValBtn ); + + hbox = new QHBoxLayout(); + vbox->addLayout( hbox ); + + lbl = new QLabel( tr("0x") ); + knownValEntry = new QLineEdit(); + hbox->addWidget( lbl ); + hbox->addWidget( knownValEntry ); + + mainLayout->addWidget( cheatSearchFrame ); + + setLayout( mainLayout ); +} +//---------------------------------------------------------------------------- +GuiCheatsDialog_t::~GuiCheatsDialog_t(void) +{ + +} +//---------------------------------------------------------------------------- +void GuiCheatsDialog_t::closeWindow(void) +{ + //printf("Close Window\n"); + done(0); +} +//---------------------------------------------------------------------------- diff --git a/src/drivers/Qt/CheatsConf.h b/src/drivers/Qt/CheatsConf.h new file mode 100644 index 00000000..7e1fee1a --- /dev/null +++ b/src/drivers/Qt/CheatsConf.h @@ -0,0 +1,55 @@ +// GamePadConf.h +// + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "Qt/main.h" + +class GuiCheatsDialog_t : public QDialog +{ + Q_OBJECT + + public: + GuiCheatsDialog_t(QWidget *parent = 0); + ~GuiCheatsDialog_t(void); + + protected: + + QGroupBox *actCheatFrame; + QGroupBox *cheatSearchFrame; + QGroupBox *cheatResultFrame; + QPushButton *addCheatBtn; + QPushButton *delCheatBtn; + QPushButton *modCheatBtn; + QPushButton *importCheatFileBtn; + QPushButton *exportCheatFileBtn; + QPushButton *srchResetBtn; + QPushButton *knownValBtn; + QTreeWidget *tree; + QLineEdit *cheatNameEntry; + QLineEdit *cheatAddrEntry; + QLineEdit *cheatValEntry; + QLineEdit *cheatCmpEntry; + QLineEdit *knownValEntry; + + private: + + public slots: + void closeWindow(void); + private slots: + +}; diff --git a/src/drivers/Qt/ConsoleWindow.cpp b/src/drivers/Qt/ConsoleWindow.cpp index f4798adc..8376262b 100644 --- a/src/drivers/Qt/ConsoleWindow.cpp +++ b/src/drivers/Qt/ConsoleWindow.cpp @@ -23,6 +23,7 @@ #include "Qt/PaletteConf.h" #include "Qt/GuiConf.h" #include "Qt/LuaControl.h" +#include "Qt/CheatsConf.h" #include "Qt/ConsoleUtilities.h" #include "Qt/ConsoleSoundConf.h" #include "Qt/ConsoleVideoConf.h" @@ -471,6 +472,18 @@ void consoleWin_t::createMainMenu(void) subMenu->addAction(fdsLoadBiosAct); + //----------------------------------------------------------------------- + // Tools + toolsMenu = menuBar()->addMenu(tr("Tools")); + + // Tools -> Cheats + cheatsAct = new QAction(tr("Cheats..."), this); + //cheatsAct->setShortcut( QKeySequence(tr("Shift+F7"))); + cheatsAct->setStatusTip(tr("Open Cheat Window")); + connect(cheatsAct, SIGNAL(triggered()), this, SLOT(openCheats(void)) ); + + toolsMenu->addAction(cheatsAct); + //----------------------------------------------------------------------- // Movie movieMenu = menuBar()->addMenu(tr("Movie")); @@ -981,6 +994,22 @@ void consoleWin_t::openGuiConfWin(void) //printf("GUI Config Window Destroyed\n"); } +void consoleWin_t::openCheats(void) +{ + GuiCheatsDialog_t *cheatWin; + + //printf("Open GUI Cheat Window\n"); + + cheatWin = new GuiCheatsDialog_t(this); + + cheatWin->show(); + cheatWin->exec(); + + delete cheatWin; + + //printf("GUI Cheat Window Destroyed\n"); +} + void consoleWin_t::toggleAutoResume(void) { //printf("Auto Resume: %i\n", autoResume->isChecked() ); diff --git a/src/drivers/Qt/ConsoleWindow.h b/src/drivers/Qt/ConsoleWindow.h index 1ce854c5..e2bd6a69 100644 --- a/src/drivers/Qt/ConsoleWindow.h +++ b/src/drivers/Qt/ConsoleWindow.h @@ -52,6 +52,7 @@ class consoleWin_t : public QMainWindow QMenu *fileMenu; QMenu *optMenu; QMenu *emuMenu; + QMenu *toolsMenu; QMenu *movieMenu; QMenu *helpMenu; @@ -86,6 +87,7 @@ class consoleWin_t : public QMainWindow QAction *fdsSwitchAct; QAction *fdsEjectAct; QAction *fdsLoadBiosAct; + QAction *cheatsAct; QAction *openMovAct; QAction *stopMovAct; QAction *recMovAct; @@ -152,6 +154,7 @@ class consoleWin_t : public QMainWindow void fdsSwitchDisk(void); void fdsEjectDisk(void); void fdsLoadBiosFile(void); + void openCheats(void); void openMovie(void); void stopMovie(void); void recordMovie(void); From 5088991a8d44f4f2860b627bfb4f3cc99a3c0cad Mon Sep 17 00:00:00 2001 From: Matthew Budd Date: Tue, 28 Jul 2020 21:37:28 -0400 Subject: [PATCH 03/15] Added more widgets to the cheat window. --- src/drivers/Qt/CheatsConf.cpp | 145 +++++++++++++++++++++++++++++----- src/drivers/Qt/CheatsConf.h | 12 +++ 2 files changed, 139 insertions(+), 18 deletions(-) diff --git a/src/drivers/Qt/CheatsConf.cpp b/src/drivers/Qt/CheatsConf.cpp index b78c4df0..754d9542 100644 --- a/src/drivers/Qt/CheatsConf.cpp +++ b/src/drivers/Qt/CheatsConf.cpp @@ -20,20 +20,25 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) : QDialog( parent ) { - QHBoxLayout *mainLayout, *hbox; - QVBoxLayout *vbox; + QHBoxLayout *mainLayout, *hbox, *hbox1; + QVBoxLayout *vbox, *vbox1, *vbox2, *vbox3; QTreeWidgetItem *item; QLabel *lbl; + QGroupBox *groupBox; + QFrame *frame; setWindowTitle("Cheat Search"); //resize( 512, 512 ); + // Window Layout Box mainLayout = new QHBoxLayout(); + //------------------------------------------------------- + // Left Side Active Cheats Frame actCheatFrame = new QGroupBox( tr("Active Cheats") ); - vbox = new QVBoxLayout(); + vbox1 = new QVBoxLayout(); mainLayout->addWidget( actCheatFrame ); @@ -69,7 +74,7 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) //} // - vbox->addWidget( tree ); + vbox1->addWidget( tree ); hbox = new QHBoxLayout(); @@ -79,7 +84,7 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) hbox->addWidget( lbl ); hbox->addWidget( cheatNameEntry ); - vbox->addLayout( hbox ); + vbox1->addLayout( hbox ); hbox = new QHBoxLayout(); @@ -101,7 +106,7 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) hbox->addWidget( lbl ); hbox->addWidget( cheatCmpEntry ); - vbox->addLayout( hbox ); + vbox1->addLayout( hbox ); hbox = new QHBoxLayout(); @@ -113,7 +118,7 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) hbox->addWidget( delCheatBtn ); hbox->addWidget( modCheatBtn ); - vbox->addLayout( hbox ); + vbox1->addLayout( hbox ); hbox = new QHBoxLayout(); @@ -123,35 +128,139 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) hbox->addWidget( importCheatFileBtn ); hbox->addWidget( exportCheatFileBtn ); - vbox->addLayout( hbox ); + vbox1->addLayout( hbox ); - actCheatFrame->setLayout( vbox ); + actCheatFrame->setLayout( vbox1 ); cheatSearchFrame = new QGroupBox( tr("Cheat Search") ); cheatResultFrame = new QGroupBox( tr("Possibilities") ); - hbox = new QHBoxLayout(); + srchResults = new QTreeWidget(); + srchResults->setColumnCount(3); + + item = new QTreeWidgetItem(); + item->setText( 0, QString::fromStdString( "Addr" ) ); + item->setText( 1, QString::fromStdString( "Pre" ) ); + item->setText( 2, QString::fromStdString( "Cur" ) ); + item->setTextAlignment( 0, Qt::AlignCenter); + item->setTextAlignment( 1, Qt::AlignCenter); + item->setTextAlignment( 2, Qt::AlignCenter); + + srchResults->setHeaderItem( item ); + + //srchResults->header()->setSectionResizeMode( QHeaderView::ResizeToContents ); + srchResults->header()->setSectionResizeMode( QHeaderView::Interactive ); + //srchResults->header()->setSectionResizeMode( QHeaderView::Fixed ); + //srchResults->header()->setSectionResizeMode( QHeaderView::Stretch ); + //srchResults->header()->setDefaultSectionSize( 200 ); + //srchResults->setReadOnly(true); vbox = new QVBoxLayout(); + vbox->addWidget( srchResults ); + cheatResultFrame->setLayout( vbox ); - hbox->addLayout( vbox ); - hbox->addWidget( cheatResultFrame ); + hbox1 = new QHBoxLayout(); - cheatSearchFrame->setLayout( hbox ); + vbox2 = new QVBoxLayout(); + + hbox1->addLayout( vbox2 ); + hbox1->addWidget( cheatResultFrame ); + + cheatSearchFrame->setLayout( hbox1 ); srchResetBtn = new QPushButton( tr("Reset") ); + + vbox2->addWidget( srchResetBtn ); + + frame = new QFrame(); + frame->setFrameShape( QFrame::Box ); + vbox2->addWidget( frame ); + vbox = new QVBoxLayout(); + + frame->setLayout( vbox ); + knownValBtn = new QPushButton( tr("Known Value:") ); - vbox->addWidget( srchResetBtn ); vbox->addWidget( knownValBtn ); - hbox = new QHBoxLayout(); - vbox->addLayout( hbox ); + hbox1 = new QHBoxLayout(); + vbox->addLayout( hbox1 ); lbl = new QLabel( tr("0x") ); knownValEntry = new QLineEdit(); - hbox->addWidget( lbl ); - hbox->addWidget( knownValEntry ); + hbox1->addWidget( lbl ); + hbox1->addWidget( knownValEntry ); + + groupBox = new QGroupBox( tr("Previous Compare") ); + vbox2->addWidget( groupBox ); + + vbox3 = new QVBoxLayout(); + + frame = new QFrame(); + frame->setFrameShape( QFrame::Box ); + vbox3->addWidget( frame ); + vbox = new QVBoxLayout(); + + eqValBtn = new QPushButton( tr("Equal") ); + vbox->addWidget( eqValBtn ); + + frame->setLayout( vbox ); + + frame = new QFrame(); + frame->setFrameShape( QFrame::Box ); + vbox3->addWidget( frame ); + vbox = new QVBoxLayout(); + + neValBtn = new QPushButton( tr("Not Equal") ); + + hbox = new QHBoxLayout(); + useNeVal = new QCheckBox( tr("By:") ); + neValEntry = new QLineEdit(); + + hbox->addWidget( useNeVal ); + hbox->addWidget( neValEntry ); + + vbox->addWidget( neValBtn ); + vbox->addLayout( hbox ); + frame->setLayout( vbox ); + + frame = new QFrame(); + frame->setFrameShape( QFrame::Box ); + vbox3->addWidget( frame ); + vbox = new QVBoxLayout(); + + grValBtn = new QPushButton( tr("Greater Than") ); + + hbox = new QHBoxLayout(); + useGrVal = new QCheckBox( tr("By:") ); + grValEntry = new QLineEdit(); + + hbox->addWidget( useGrVal ); + hbox->addWidget( grValEntry ); + + vbox->addWidget( grValBtn ); + vbox->addLayout( hbox ); + frame->setLayout( vbox ); + + frame = new QFrame(); + frame->setFrameShape( QFrame::Box ); + vbox3->addWidget( frame ); + vbox = new QVBoxLayout(); + + ltValBtn = new QPushButton( tr("Less Than") ); + + hbox = new QHBoxLayout(); + useLtVal = new QCheckBox( tr("By:") ); + ltValEntry = new QLineEdit(); + + hbox->addWidget( useLtVal ); + hbox->addWidget( ltValEntry ); + + vbox->addWidget( ltValBtn ); + vbox->addLayout( hbox ); + frame->setLayout( vbox ); + + groupBox->setLayout( vbox3 ); mainLayout->addWidget( cheatSearchFrame ); diff --git a/src/drivers/Qt/CheatsConf.h b/src/drivers/Qt/CheatsConf.h index 7e1fee1a..3aa952c7 100644 --- a/src/drivers/Qt/CheatsConf.h +++ b/src/drivers/Qt/CheatsConf.h @@ -16,6 +16,7 @@ #include #include #include +#include #include "Qt/main.h" @@ -39,12 +40,23 @@ class GuiCheatsDialog_t : public QDialog QPushButton *exportCheatFileBtn; QPushButton *srchResetBtn; QPushButton *knownValBtn; + QPushButton *eqValBtn; + QPushButton *neValBtn; + QPushButton *grValBtn; + QPushButton *ltValBtn; + QCheckBox *useNeVal; + QCheckBox *useGrVal; + QCheckBox *useLtVal; QTreeWidget *tree; + QTreeWidget *srchResults; QLineEdit *cheatNameEntry; QLineEdit *cheatAddrEntry; QLineEdit *cheatValEntry; QLineEdit *cheatCmpEntry; QLineEdit *knownValEntry; + QLineEdit *neValEntry; + QLineEdit *grValEntry; + QLineEdit *ltValEntry; private: From bec89112e210cc4d7d277018c0b2166c68e24880 Mon Sep 17 00:00:00 2001 From: Matthew Budd Date: Tue, 28 Jul 2020 22:54:52 -0400 Subject: [PATCH 04/15] More updates to cheat window. --- src/drivers/Qt/CheatsConf.cpp | 96 +++++++++++++++++++++++++++++++++++ src/drivers/Qt/CheatsConf.h | 7 +++ 2 files changed, 103 insertions(+) diff --git a/src/drivers/Qt/CheatsConf.cpp b/src/drivers/Qt/CheatsConf.cpp index 754d9542..e3b38cbe 100644 --- a/src/drivers/Qt/CheatsConf.cpp +++ b/src/drivers/Qt/CheatsConf.cpp @@ -8,6 +8,11 @@ #include #include +#include "../../types.h" +#include "../../fceu.h" +#include "../../cheat.h" +#include "../../debug.h" +#include "../../driver.h" #include "Qt/main.h" #include "Qt/dface.h" #include "Qt/input.h" @@ -16,6 +21,7 @@ #include "Qt/fceuWrapper.h" #include "Qt/CheatsConf.h" +static GuiCheatsDialog_t *win = NULL; //---------------------------------------------------------------------------- GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) : QDialog( parent ) @@ -26,6 +32,10 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) QLabel *lbl; QGroupBox *groupBox; QFrame *frame; + QFont font; + + font.setStyle( QFont::StyleNormal ); + font.setStyleHint( QFont::Monospace ); setWindowTitle("Cheat Search"); @@ -47,6 +57,8 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) tree->setColumnCount(2); item = new QTreeWidgetItem(); + item->setFont( 0, font ); + item->setFont( 1, font ); item->setText( 0, QString::fromStdString( "Code" ) ); item->setText( 1, QString::fromStdString( "Name" ) ); item->setTextAlignment( 0, Qt::AlignLeft); @@ -139,6 +151,9 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) srchResults->setColumnCount(3); item = new QTreeWidgetItem(); + item->setFont( 0, font ); + item->setFont( 1, font ); + item->setFont( 2, font ); item->setText( 0, QString::fromStdString( "Addr" ) ); item->setText( 1, QString::fromStdString( "Pre" ) ); item->setText( 2, QString::fromStdString( "Cur" ) ); @@ -188,6 +203,8 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) lbl = new QLabel( tr("0x") ); knownValEntry = new QLineEdit(); + knownValEntry->setMaxLength(2); + //knownValEntry->setInputMask( "AA" ); hbox1->addWidget( lbl ); hbox1->addWidget( knownValEntry ); @@ -265,6 +282,12 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) mainLayout->addWidget( cheatSearchFrame ); setLayout( mainLayout ); + + connect( srchResetBtn, SIGNAL(clicked(void)), this, SLOT(resetSearchCallback(void)) ); + connect( knownValBtn , SIGNAL(clicked(void)), this, SLOT(knownValueCallback(void)) ); + + cheat_search_known_value = 0; + } //---------------------------------------------------------------------------- GuiCheatsDialog_t::~GuiCheatsDialog_t(void) @@ -278,3 +301,76 @@ void GuiCheatsDialog_t::closeWindow(void) done(0); } //---------------------------------------------------------------------------- +int GuiCheatsDialog_t::addSearchResult (uint32_t a, uint8_t last, uint8_t current) +{ + QTreeWidgetItem *item; + char addrStr[8], lastStr[8], curStr[8]; + + item = new QTreeWidgetItem(); + + sprintf (addrStr, "$%04X", a); + sprintf (lastStr, "%02X", last); + sprintf (curStr , "%02X", current); + + item->setText( 0, tr(addrStr) ); + item->setText( 1, tr(lastStr) ); + item->setText( 2, tr(curStr) ); + + item->setTextAlignment( 0, Qt::AlignCenter); + item->setTextAlignment( 1, Qt::AlignCenter); + item->setTextAlignment( 2, Qt::AlignCenter); + + srchResults->addTopLevelItem( item ); + + return 1; +} +//---------------------------------------------------------------------------- +static int ShowCheatSearchResultsCallB (uint32 a, uint8 last, uint8 current) +{ + return win->addSearchResult( a, last, current ); +} +//---------------------------------------------------------------------------- +void GuiCheatsDialog_t::showCheatSearchResults(void) +{ + int total_matches; + + win = this; + + srchResults->clear(); + + total_matches = FCEUI_CheatSearchGetCount (); + + FCEUI_CheatSearchGetRange (0, total_matches, + ShowCheatSearchResultsCallB); + + printf("Num Matches: %i \n", total_matches ); +} +//---------------------------------------------------------------------------- +void GuiCheatsDialog_t::resetSearchCallback(void) +{ + fceuWrapperLock(); + + FCEUI_CheatSearchBegin (); + + showCheatSearchResults(); + + fceuWrapperUnLock(); +} +//---------------------------------------------------------------------------- +void GuiCheatsDialog_t::knownValueCallback(void) +{ + //printf("Cheat Search Known!\n"); + fceuWrapperLock(); + + //printf("%s\n", knownValEntry->text().toStdString().c_str() ); + + cheat_search_known_value = strtol( knownValEntry->text().toStdString().c_str(), NULL, 16 ); + + FCEUI_CheatSearchEnd (FCEU_SEARCH_NEWVAL_KNOWN, + cheat_search_known_value, 0); + + showCheatSearchResults(); + + fceuWrapperUnLock(); +} +//---------------------------------------------------------------------------- diff --git a/src/drivers/Qt/CheatsConf.h b/src/drivers/Qt/CheatsConf.h index 3aa952c7..b057ba0a 100644 --- a/src/drivers/Qt/CheatsConf.h +++ b/src/drivers/Qt/CheatsConf.h @@ -28,6 +28,8 @@ class GuiCheatsDialog_t : public QDialog GuiCheatsDialog_t(QWidget *parent = 0); ~GuiCheatsDialog_t(void); + int addSearchResult( uint32_t a, uint8_t last, uint8_t current ); + protected: QGroupBox *actCheatFrame; @@ -58,10 +60,15 @@ class GuiCheatsDialog_t : public QDialog QLineEdit *grValEntry; QLineEdit *ltValEntry; + int cheat_search_known_value; + private: + void showCheatSearchResults(void); public slots: void closeWindow(void); private slots: + void resetSearchCallback(void); + void knownValueCallback(void); }; From cf54c8d22584def140de8a21bba19f20317b933b Mon Sep 17 00:00:00 2001 From: Matthew Budd Date: Thu, 30 Jul 2020 23:06:02 -0400 Subject: [PATCH 05/15] Cheat window widget layout in work. --- src/drivers/Qt/CheatsConf.cpp | 74 ++++++++++++++++++++++++++++++----- 1 file changed, 65 insertions(+), 9 deletions(-) diff --git a/src/drivers/Qt/CheatsConf.cpp b/src/drivers/Qt/CheatsConf.cpp index e3b38cbe..b3f5f700 100644 --- a/src/drivers/Qt/CheatsConf.cpp +++ b/src/drivers/Qt/CheatsConf.cpp @@ -92,6 +92,7 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) lbl = new QLabel( tr("Name:") ); cheatNameEntry = new QLineEdit(); + cheatNameEntry->setFont( font ); hbox->addWidget( lbl ); hbox->addWidget( cheatNameEntry ); @@ -102,18 +103,33 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) lbl = new QLabel( tr("Address:") ); cheatAddrEntry = new QLineEdit(); + cheatAddrEntry->setMaxLength(4); + cheatAddrEntry->setInputMask( ">HHHH;0" ); + cheatAddrEntry->setFont( font ); + cheatAddrEntry->setCursorPosition(0); + cheatAddrEntry->setMaximumWidth( 5 * cheatAddrEntry->fontMetrics().boundingRect('0').width() ); hbox->addWidget( lbl ); hbox->addWidget( cheatAddrEntry ); lbl = new QLabel( tr("Value:") ); cheatValEntry = new QLineEdit(); + cheatValEntry->setMaxLength(2); + cheatValEntry->setInputMask( ">HH;0" ); + cheatValEntry->setFont( font ); + cheatValEntry->setCursorPosition(0); + cheatValEntry->setMaximumWidth( 3 * cheatValEntry->fontMetrics().boundingRect('0').width() ); hbox->addWidget( lbl ); hbox->addWidget( cheatValEntry ); lbl = new QLabel( tr("Compare:") ); cheatCmpEntry = new QLineEdit(); + cheatCmpEntry->setMaxLength(2); + cheatCmpEntry->setInputMask( ">HH;X" ); + cheatCmpEntry->setFont( font ); + cheatCmpEntry->setCursorPosition(0); + cheatCmpEntry->setMaximumWidth( 3 * cheatCmpEntry->fontMetrics().boundingRect('0').width() ); hbox->addWidget( lbl ); hbox->addWidget( cheatCmpEntry ); @@ -136,6 +152,8 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) importCheatFileBtn = new QPushButton( tr("Import") ); exportCheatFileBtn = new QPushButton( tr("Export") ); + importCheatFileBtn->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); + exportCheatFileBtn->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); hbox->addWidget( importCheatFileBtn ); hbox->addWidget( exportCheatFileBtn ); @@ -184,17 +202,20 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) cheatSearchFrame->setLayout( hbox1 ); srchResetBtn = new QPushButton( tr("Reset") ); + srchResetBtn->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); vbox2->addWidget( srchResetBtn ); frame = new QFrame(); frame->setFrameShape( QFrame::Box ); + frame->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); vbox2->addWidget( frame ); vbox = new QVBoxLayout(); frame->setLayout( vbox ); knownValBtn = new QPushButton( tr("Known Value:") ); + knownValBtn->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); vbox->addWidget( knownValBtn ); @@ -202,40 +223,57 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) vbox->addLayout( hbox1 ); lbl = new QLabel( tr("0x") ); + lbl->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); knownValEntry = new QLineEdit(); knownValEntry->setMaxLength(2); - //knownValEntry->setInputMask( "AA" ); - hbox1->addWidget( lbl ); - hbox1->addWidget( knownValEntry ); + knownValEntry->setInputMask( ">HH;0" ); + knownValEntry->setFont( font ); + knownValEntry->setCursorPosition(0); + knownValEntry->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); + knownValEntry->setMaximumWidth( 3 * knownValEntry->fontMetrics().boundingRect('0').width() ); + hbox1->addWidget( lbl, 0, Qt::AlignRight ); + hbox1->addWidget( knownValEntry, 0, Qt::AlignLeft ); groupBox = new QGroupBox( tr("Previous Compare") ); vbox2->addWidget( groupBox ); + groupBox->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); vbox3 = new QVBoxLayout(); frame = new QFrame(); frame->setFrameShape( QFrame::Box ); + frame->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); vbox3->addWidget( frame ); vbox = new QVBoxLayout(); eqValBtn = new QPushButton( tr("Equal") ); + eqValBtn->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); vbox->addWidget( eqValBtn ); frame->setLayout( vbox ); frame = new QFrame(); frame->setFrameShape( QFrame::Box ); + frame->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); vbox3->addWidget( frame ); vbox = new QVBoxLayout(); neValBtn = new QPushButton( tr("Not Equal") ); + neValBtn->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); hbox = new QHBoxLayout(); useNeVal = new QCheckBox( tr("By:") ); + useNeVal->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); neValEntry = new QLineEdit(); + neValEntry->setMaxLength(2); + neValEntry->setInputMask( ">HH;0" ); + neValEntry->setFont( font ); + neValEntry->setCursorPosition(0); + neValEntry->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); + neValEntry->setMaximumWidth( 3 * neValEntry->fontMetrics().boundingRect('0').width() ); - hbox->addWidget( useNeVal ); - hbox->addWidget( neValEntry ); + hbox->addWidget( useNeVal, 0, Qt::AlignRight ); + hbox->addWidget( neValEntry, 0, Qt::AlignLeft ); vbox->addWidget( neValBtn ); vbox->addLayout( hbox ); @@ -243,17 +281,26 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) frame = new QFrame(); frame->setFrameShape( QFrame::Box ); + frame->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); vbox3->addWidget( frame ); vbox = new QVBoxLayout(); grValBtn = new QPushButton( tr("Greater Than") ); + grValBtn->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); hbox = new QHBoxLayout(); useGrVal = new QCheckBox( tr("By:") ); + useGrVal->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); grValEntry = new QLineEdit(); + grValEntry->setMaxLength(2); + grValEntry->setInputMask( ">HH;0" ); + grValEntry->setFont( font ); + grValEntry->setCursorPosition(0); + grValEntry->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); + grValEntry->setMaximumWidth( 3 * grValEntry->fontMetrics().boundingRect('0').width() ); - hbox->addWidget( useGrVal ); - hbox->addWidget( grValEntry ); + hbox->addWidget( useGrVal, 0, Qt::AlignRight ); + hbox->addWidget( grValEntry, 0, Qt::AlignLeft ); vbox->addWidget( grValBtn ); vbox->addLayout( hbox ); @@ -261,17 +308,26 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) frame = new QFrame(); frame->setFrameShape( QFrame::Box ); + frame->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); vbox3->addWidget( frame ); vbox = new QVBoxLayout(); ltValBtn = new QPushButton( tr("Less Than") ); + ltValBtn->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); hbox = new QHBoxLayout(); useLtVal = new QCheckBox( tr("By:") ); + useLtVal->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); ltValEntry = new QLineEdit(); + ltValEntry->setMaxLength(2); + ltValEntry->setInputMask( ">HH;0" ); + ltValEntry->setFont( font ); + ltValEntry->setCursorPosition(0); + ltValEntry->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); + ltValEntry->setMaximumWidth( 3 * ltValEntry->fontMetrics().boundingRect('0').width() ); - hbox->addWidget( useLtVal ); - hbox->addWidget( ltValEntry ); + hbox->addWidget( useLtVal, 0, Qt::AlignRight ); + hbox->addWidget( ltValEntry, 0, Qt::AlignLeft ); vbox->addWidget( ltValBtn ); vbox->addLayout( hbox ); From b6871bc36db563c1cd8f368c2224ee1aace321cc Mon Sep 17 00:00:00 2001 From: Matthew Budd Date: Fri, 31 Jul 2020 20:14:17 -0400 Subject: [PATCH 06/15] Added callbacks for cheat search buttons. --- src/drivers/Qt/CheatsConf.cpp | 112 +++++++++++++++++++++++++++++++--- src/drivers/Qt/CheatsConf.h | 9 +++ 2 files changed, 113 insertions(+), 8 deletions(-) diff --git a/src/drivers/Qt/CheatsConf.cpp b/src/drivers/Qt/CheatsConf.cpp index b3f5f700..7829e713 100644 --- a/src/drivers/Qt/CheatsConf.cpp +++ b/src/drivers/Qt/CheatsConf.cpp @@ -32,11 +32,14 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) QLabel *lbl; QGroupBox *groupBox; QFrame *frame; - QFont font; font.setStyle( QFont::StyleNormal ); font.setStyleHint( QFont::Monospace ); + QFontMetrics fm(font); + + fontCharWidth = fm.boundingRect('0').width(); + setWindowTitle("Cheat Search"); //resize( 512, 512 ); @@ -107,7 +110,7 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) cheatAddrEntry->setInputMask( ">HHHH;0" ); cheatAddrEntry->setFont( font ); cheatAddrEntry->setCursorPosition(0); - cheatAddrEntry->setMaximumWidth( 5 * cheatAddrEntry->fontMetrics().boundingRect('0').width() ); + cheatAddrEntry->setMaximumWidth( 5 * fontCharWidth ); hbox->addWidget( lbl ); hbox->addWidget( cheatAddrEntry ); @@ -118,7 +121,7 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) cheatValEntry->setInputMask( ">HH;0" ); cheatValEntry->setFont( font ); cheatValEntry->setCursorPosition(0); - cheatValEntry->setMaximumWidth( 3 * cheatValEntry->fontMetrics().boundingRect('0').width() ); + cheatValEntry->setMaximumWidth( 3 * fontCharWidth ); hbox->addWidget( lbl ); hbox->addWidget( cheatValEntry ); @@ -129,7 +132,7 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) cheatCmpEntry->setInputMask( ">HH;X" ); cheatCmpEntry->setFont( font ); cheatCmpEntry->setCursorPosition(0); - cheatCmpEntry->setMaximumWidth( 3 * cheatCmpEntry->fontMetrics().boundingRect('0').width() ); + cheatCmpEntry->setMaximumWidth( 3 * fontCharWidth ); hbox->addWidget( lbl ); hbox->addWidget( cheatCmpEntry ); @@ -184,8 +187,12 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) //srchResults->header()->setSectionResizeMode( QHeaderView::ResizeToContents ); srchResults->header()->setSectionResizeMode( QHeaderView::Interactive ); //srchResults->header()->setSectionResizeMode( QHeaderView::Fixed ); + srchResults->header()->resizeSection( 0, 10 * fontCharWidth ); + srchResults->header()->resizeSection( 1, 6 * fontCharWidth ); + srchResults->header()->resizeSection( 2, 6 * fontCharWidth ); //srchResults->header()->setSectionResizeMode( QHeaderView::Stretch ); //srchResults->header()->setDefaultSectionSize( 200 ); + //srchResults->header()->setDefaultSectionSize( 200 ); //srchResults->setReadOnly(true); vbox = new QVBoxLayout(); @@ -230,7 +237,7 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) knownValEntry->setFont( font ); knownValEntry->setCursorPosition(0); knownValEntry->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); - knownValEntry->setMaximumWidth( 3 * knownValEntry->fontMetrics().boundingRect('0').width() ); + knownValEntry->setMaximumWidth( 3 * fontCharWidth ); hbox1->addWidget( lbl, 0, Qt::AlignRight ); hbox1->addWidget( knownValEntry, 0, Qt::AlignLeft ); @@ -270,7 +277,7 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) neValEntry->setFont( font ); neValEntry->setCursorPosition(0); neValEntry->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); - neValEntry->setMaximumWidth( 3 * neValEntry->fontMetrics().boundingRect('0').width() ); + neValEntry->setMaximumWidth( 3 * fontCharWidth ); hbox->addWidget( useNeVal, 0, Qt::AlignRight ); hbox->addWidget( neValEntry, 0, Qt::AlignLeft ); @@ -297,7 +304,7 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) grValEntry->setFont( font ); grValEntry->setCursorPosition(0); grValEntry->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); - grValEntry->setMaximumWidth( 3 * grValEntry->fontMetrics().boundingRect('0').width() ); + grValEntry->setMaximumWidth( 3 * fontCharWidth ); hbox->addWidget( useGrVal, 0, Qt::AlignRight ); hbox->addWidget( grValEntry, 0, Qt::AlignLeft ); @@ -324,7 +331,7 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) ltValEntry->setFont( font ); ltValEntry->setCursorPosition(0); ltValEntry->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); - ltValEntry->setMaximumWidth( 3 * ltValEntry->fontMetrics().boundingRect('0').width() ); + ltValEntry->setMaximumWidth( 3 * fontCharWidth ); hbox->addWidget( useLtVal, 0, Qt::AlignRight ); hbox->addWidget( ltValEntry, 0, Qt::AlignLeft ); @@ -341,6 +348,10 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) connect( srchResetBtn, SIGNAL(clicked(void)), this, SLOT(resetSearchCallback(void)) ); connect( knownValBtn , SIGNAL(clicked(void)), this, SLOT(knownValueCallback(void)) ); + connect( eqValBtn , SIGNAL(clicked(void)), this, SLOT(equalValueCallback(void)) ); + connect( neValBtn , SIGNAL(clicked(void)), this, SLOT(notEqualValueCallback(void)) ); + connect( ltValBtn , SIGNAL(clicked(void)), this, SLOT(lessThanValueCallback(void)) ); + connect( grValBtn , SIGNAL(clicked(void)), this, SLOT(greaterThanValueCallback(void)) ); cheat_search_known_value = 0; @@ -368,6 +379,10 @@ int GuiCheatsDialog_t::addSearchResult (uint32_t a, uint8_t last, uint8_t curren sprintf (lastStr, "%02X", last); sprintf (curStr , "%02X", current); + //item->setFont( 0, font ); + //item->setFont( 1, font ); + //item->setFont( 2, font ); + item->setText( 0, tr(addrStr) ); item->setText( 1, tr(lastStr) ); item->setText( 2, tr(curStr) ); @@ -430,3 +445,84 @@ void GuiCheatsDialog_t::knownValueCallback(void) fceuWrapperUnLock(); } //---------------------------------------------------------------------------- +void GuiCheatsDialog_t::equalValueCallback(void) +{ + //printf("Cheat Search Equal!\n"); + fceuWrapperLock(); + + FCEUI_CheatSearchEnd (FCEU_SEARCH_PUERLY_RELATIVE_CHANGE, 0, 0); + + showCheatSearchResults(); + + fceuWrapperUnLock(); +} +//---------------------------------------------------------------------------- +void GuiCheatsDialog_t::notEqualValueCallback(void) +{ + //printf("Cheat Search Not Equal!\n"); + int checked = useNeVal->checkState() != Qt::Unchecked; + + fceuWrapperLock(); + + if (checked) + { + cheat_search_neq_value = strtol( neValEntry->text().toStdString().c_str(), NULL, 16 ); + + FCEUI_CheatSearchEnd (FCEU_SEARCH_PUERLY_RELATIVE_CHANGE, 0, cheat_search_neq_value); + } + else + { + FCEUI_CheatSearchEnd (FCEU_SEARCH_ANY_CHANGE, 0, 0); + } + + showCheatSearchResults(); + + fceuWrapperUnLock(); +} +//---------------------------------------------------------------------------- +void GuiCheatsDialog_t::greaterThanValueCallback(void) +{ + //printf("Cheat Search Greater Than!\n"); + int checked = useGrVal->checkState() != Qt::Unchecked; + + fceuWrapperLock(); + + if (checked) + { + cheat_search_gt_value = strtol( grValEntry->text().toStdString().c_str(), NULL, 16 ); + + FCEUI_CheatSearchEnd (FCEU_SEARCH_NEWVAL_GT_KNOWN, 0, cheat_search_gt_value); + } + else + { + FCEUI_CheatSearchEnd (FCEU_SEARCH_NEWVAL_GT, 0, 0); + } + + showCheatSearchResults(); + + fceuWrapperUnLock(); +} +//---------------------------------------------------------------------------- +void GuiCheatsDialog_t::lessThanValueCallback(void) +{ + //printf("Cheat Search Less Than!\n"); + int checked = useLtVal->checkState() != Qt::Unchecked; + + fceuWrapperLock(); + + if (checked) + { + cheat_search_lt_value = strtol( ltValEntry->text().toStdString().c_str(), NULL, 16 ); + + FCEUI_CheatSearchEnd (FCEU_SEARCH_NEWVAL_LT_KNOWN, 0, cheat_search_lt_value); + } + else + { + FCEUI_CheatSearchEnd (FCEU_SEARCH_NEWVAL_LT, 0, 0); + } + + showCheatSearchResults(); + + fceuWrapperUnLock(); +} +//---------------------------------------------------------------------------- diff --git a/src/drivers/Qt/CheatsConf.h b/src/drivers/Qt/CheatsConf.h index b057ba0a..5791b60c 100644 --- a/src/drivers/Qt/CheatsConf.h +++ b/src/drivers/Qt/CheatsConf.h @@ -59,8 +59,13 @@ class GuiCheatsDialog_t : public QDialog QLineEdit *neValEntry; QLineEdit *grValEntry; QLineEdit *ltValEntry; + QFont font; + int fontCharWidth; int cheat_search_known_value; + int cheat_search_neq_value; + int cheat_search_gt_value; + int cheat_search_lt_value; private: void showCheatSearchResults(void); @@ -70,5 +75,9 @@ class GuiCheatsDialog_t : public QDialog private slots: void resetSearchCallback(void); void knownValueCallback(void); + void equalValueCallback(void); + void notEqualValueCallback(void); + void lessThanValueCallback(void); + void greaterThanValueCallback(void); }; From 3e1cfb3a94faac3c2b5daa6bebcd661ce526d107 Mon Sep 17 00:00:00 2001 From: Matthew Budd Date: Fri, 31 Jul 2020 20:18:39 -0400 Subject: [PATCH 07/15] More cheat search updates. --- src/drivers/Qt/CheatsConf.cpp | 23 ++++++++++++----------- src/drivers/Qt/CheatsConf.h | 4 ---- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/drivers/Qt/CheatsConf.cpp b/src/drivers/Qt/CheatsConf.cpp index 7829e713..f6b016df 100644 --- a/src/drivers/Qt/CheatsConf.cpp +++ b/src/drivers/Qt/CheatsConf.cpp @@ -353,8 +353,6 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) connect( ltValBtn , SIGNAL(clicked(void)), this, SLOT(lessThanValueCallback(void)) ); connect( grValBtn , SIGNAL(clicked(void)), this, SLOT(greaterThanValueCallback(void)) ); - cheat_search_known_value = 0; - } //---------------------------------------------------------------------------- GuiCheatsDialog_t::~GuiCheatsDialog_t(void) @@ -430,15 +428,15 @@ void GuiCheatsDialog_t::resetSearchCallback(void) //---------------------------------------------------------------------------- void GuiCheatsDialog_t::knownValueCallback(void) { + int value; //printf("Cheat Search Known!\n"); fceuWrapperLock(); //printf("%s\n", knownValEntry->text().toStdString().c_str() ); - cheat_search_known_value = strtol( knownValEntry->text().toStdString().c_str(), NULL, 16 ); + value = strtol( knownValEntry->text().toStdString().c_str(), NULL, 16 ); - FCEUI_CheatSearchEnd (FCEU_SEARCH_NEWVAL_KNOWN, - cheat_search_known_value, 0); + FCEUI_CheatSearchEnd (FCEU_SEARCH_NEWVAL_KNOWN, value, 0); showCheatSearchResults(); @@ -460,15 +458,16 @@ void GuiCheatsDialog_t::equalValueCallback(void) void GuiCheatsDialog_t::notEqualValueCallback(void) { //printf("Cheat Search Not Equal!\n"); + int value; int checked = useNeVal->checkState() != Qt::Unchecked; fceuWrapperLock(); if (checked) { - cheat_search_neq_value = strtol( neValEntry->text().toStdString().c_str(), NULL, 16 ); + value = strtol( neValEntry->text().toStdString().c_str(), NULL, 16 ); - FCEUI_CheatSearchEnd (FCEU_SEARCH_PUERLY_RELATIVE_CHANGE, 0, cheat_search_neq_value); + FCEUI_CheatSearchEnd (FCEU_SEARCH_PUERLY_RELATIVE_CHANGE, 0, value); } else { @@ -483,15 +482,16 @@ void GuiCheatsDialog_t::notEqualValueCallback(void) void GuiCheatsDialog_t::greaterThanValueCallback(void) { //printf("Cheat Search Greater Than!\n"); + int value; int checked = useGrVal->checkState() != Qt::Unchecked; fceuWrapperLock(); if (checked) { - cheat_search_gt_value = strtol( grValEntry->text().toStdString().c_str(), NULL, 16 ); + value = strtol( grValEntry->text().toStdString().c_str(), NULL, 16 ); - FCEUI_CheatSearchEnd (FCEU_SEARCH_NEWVAL_GT_KNOWN, 0, cheat_search_gt_value); + FCEUI_CheatSearchEnd (FCEU_SEARCH_NEWVAL_GT_KNOWN, 0, value); } else { @@ -506,15 +506,16 @@ void GuiCheatsDialog_t::greaterThanValueCallback(void) void GuiCheatsDialog_t::lessThanValueCallback(void) { //printf("Cheat Search Less Than!\n"); + int value; int checked = useLtVal->checkState() != Qt::Unchecked; fceuWrapperLock(); if (checked) { - cheat_search_lt_value = strtol( ltValEntry->text().toStdString().c_str(), NULL, 16 ); + value = strtol( ltValEntry->text().toStdString().c_str(), NULL, 16 ); - FCEUI_CheatSearchEnd (FCEU_SEARCH_NEWVAL_LT_KNOWN, 0, cheat_search_lt_value); + FCEUI_CheatSearchEnd (FCEU_SEARCH_NEWVAL_LT_KNOWN, 0, value); } else { diff --git a/src/drivers/Qt/CheatsConf.h b/src/drivers/Qt/CheatsConf.h index 5791b60c..e76563a0 100644 --- a/src/drivers/Qt/CheatsConf.h +++ b/src/drivers/Qt/CheatsConf.h @@ -62,10 +62,6 @@ class GuiCheatsDialog_t : public QDialog QFont font; int fontCharWidth; - int cheat_search_known_value; - int cheat_search_neq_value; - int cheat_search_gt_value; - int cheat_search_lt_value; private: void showCheatSearchResults(void); From 2d57b88e645fd7f8bd04f49859ef286cb7562591 Mon Sep 17 00:00:00 2001 From: Matthew Budd Date: Fri, 31 Jul 2020 22:03:14 -0400 Subject: [PATCH 08/15] Added code to populate active cheat list. --- src/drivers/Qt/CheatsConf.cpp | 175 +++++++++++++++++++++++++++++----- src/drivers/Qt/CheatsConf.h | 11 ++- 2 files changed, 160 insertions(+), 26 deletions(-) diff --git a/src/drivers/Qt/CheatsConf.cpp b/src/drivers/Qt/CheatsConf.cpp index f6b016df..46986871 100644 --- a/src/drivers/Qt/CheatsConf.cpp +++ b/src/drivers/Qt/CheatsConf.cpp @@ -7,6 +7,7 @@ #include #include +#include #include "../../types.h" #include "../../fceu.h" @@ -20,6 +21,7 @@ #include "Qt/keyscan.h" #include "Qt/fceuWrapper.h" #include "Qt/CheatsConf.h" +#include "Qt/ConsoleUtilities.h" static GuiCheatsDialog_t *win = NULL; //---------------------------------------------------------------------------- @@ -55,41 +57,26 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) mainLayout->addWidget( actCheatFrame ); - tree = new QTreeWidget(); + actvCheatList = new QTreeWidget(); - tree->setColumnCount(2); + actvCheatList->setColumnCount(2); item = new QTreeWidgetItem(); item->setFont( 0, font ); item->setFont( 1, font ); item->setText( 0, QString::fromStdString( "Code" ) ); item->setText( 1, QString::fromStdString( "Name" ) ); - item->setTextAlignment( 0, Qt::AlignLeft); - item->setTextAlignment( 1, Qt::AlignLeft); + item->setTextAlignment( 0, Qt::AlignCenter); + item->setTextAlignment( 1, Qt::AlignCenter); - tree->setHeaderItem( item ); + actvCheatList->setHeaderItem( item ); - tree->header()->setSectionResizeMode( QHeaderView::ResizeToContents ); + actvCheatList->header()->setSectionResizeMode( QHeaderView::ResizeToContents ); - //for (int i=0; igetOption (optionName.c_str (), &keycode); - - // item = new QTreeWidgetItem(); - - // item->setText( 0, QString::fromStdString( optionName ) ); - // item->setText( 1, QString::fromStdString( SDL_GetKeyName (keycode) ) ); - - // item->setTextAlignment( 0, Qt::AlignLeft); - // item->setTextAlignment( 1, Qt::AlignCenter); - - // tree->addTopLevelItem( item ); - //} - // - - vbox1->addWidget( tree ); + vbox1->addWidget( actvCheatList ); hbox = new QHBoxLayout(); @@ -353,6 +340,9 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) connect( ltValBtn , SIGNAL(clicked(void)), this, SLOT(lessThanValueCallback(void)) ); connect( grValBtn , SIGNAL(clicked(void)), this, SLOT(greaterThanValueCallback(void)) ); + connect( importCheatFileBtn, SIGNAL(clicked(void)), this, SLOT(openCheatFile(void)) ); + + showActiveCheatList(true); } //---------------------------------------------------------------------------- GuiCheatsDialog_t::~GuiCheatsDialog_t(void) @@ -527,3 +517,140 @@ void GuiCheatsDialog_t::lessThanValueCallback(void) fceuWrapperUnLock(); } //---------------------------------------------------------------------------- +int GuiCheatsDialog_t::activeCheatListCB (char *name, uint32 a, uint8 v, int c, int s, int type, void *data) +{ + QTreeWidgetItem *item; + char codeStr[32]; + + if (c >= 0) + { + sprintf (codeStr, "$%04X:%02X:%02X", a,v,c); + } + else + { + sprintf (codeStr, "$%04X:%02X ", a,v); + } + + item = actvCheatList->topLevelItem(actvCheatIdx); + + if ( item == NULL ) + { + item = new QTreeWidgetItem(); + + actvCheatList->addTopLevelItem( item ); + } + + //item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsUserCheckable ); + item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemNeverHasChildren ); + + item->setCheckState( 0, s ? Qt::Checked : Qt::Unchecked ); + + item->setText( 0, tr(codeStr)); + item->setText( 1, tr(name) ); + + item->setTextAlignment( 0, Qt::AlignLeft); + item->setTextAlignment( 1, Qt::AlignLeft); + + actvCheatIdx++; + + return 1; +} +//---------------------------------------------------------------------------- +static int activeCheatListCB (char *name, uint32 a, uint8 v, int c, int s, int type, void *data) +{ + return win->activeCheatListCB( name, a, v, c, s, type, data ); +} +//---------------------------------------------------------------------------- +void GuiCheatsDialog_t::showActiveCheatList(bool redraw) +{ + win = this; + + actvCheatRedraw = redraw; + + if ( redraw ) + { + actvCheatList->clear(); + } + actvCheatIdx = 0; + + FCEUI_ListCheats (::activeCheatListCB, (void *) this); +} +//---------------------------------------------------------------------------- +void GuiCheatsDialog_t::openCheatFile(void) +{ + FILE *fp; + int ret, useNativeFileDialogVal; + QString filename; + std::string last; + char dir[512]; + QFileDialog dialog(this, tr("Open Cheat File") ); + + dialog.setFileMode(QFileDialog::ExistingFile); + + dialog.setNameFilter(tr("Cheat files (*.cht *.CHT) ;; All files (*)")); + + dialog.setViewMode(QFileDialog::List); + dialog.setFilter( QDir::AllEntries | QDir::Hidden ); + dialog.setLabelText( QFileDialog::Accept, tr("Open") ); + + g_config->getOption ("SDL.LastOpenFile", &last ); + + getDirFromFile( last.c_str(), dir ); + + dialog.setDirectory( tr(dir) ); + + // Check config option to use native file dialog or not + g_config->getOption ("SDL.UseNativeFileDialog", &useNativeFileDialogVal); + + dialog.setOption(QFileDialog::DontUseNativeDialog, !useNativeFileDialogVal); + + 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() ); + + fceuWrapperLock(); + + fp = fopen (filename.toStdString().c_str(), "r"); + + if (fp != NULL) + { + FCEU_LoadGameCheats (fp, 0); + fclose (fp); + } + fceuWrapperUnLock(); + + showActiveCheatList(true); + + return; +} +//---------------------------------------------------------------------------- +void GuiCheatsDialog_t::actvCheatItemClicked( QTreeWidgetItem *item, int column) +{ + int row = actvCheatList->indexOfTopLevelItem(item); + + printf("Row: %i Column: %i \n", row, column ); + + if ( column == 0 ) + { + FCEUI_ToggleCheat( row ); + } +} +//---------------------------------------------------------------------------- diff --git a/src/drivers/Qt/CheatsConf.h b/src/drivers/Qt/CheatsConf.h index e76563a0..dc457793 100644 --- a/src/drivers/Qt/CheatsConf.h +++ b/src/drivers/Qt/CheatsConf.h @@ -30,6 +30,8 @@ class GuiCheatsDialog_t : public QDialog int addSearchResult( uint32_t a, uint8_t last, uint8_t current ); + int activeCheatListCB (char *name, uint32 a, uint8 v, int c, int s, int type, void *data); + protected: QGroupBox *actCheatFrame; @@ -49,7 +51,7 @@ class GuiCheatsDialog_t : public QDialog QCheckBox *useNeVal; QCheckBox *useGrVal; QCheckBox *useLtVal; - QTreeWidget *tree; + QTreeWidget *actvCheatList; QTreeWidget *srchResults; QLineEdit *cheatNameEntry; QLineEdit *cheatAddrEntry; @@ -61,10 +63,13 @@ class GuiCheatsDialog_t : public QDialog QLineEdit *ltValEntry; QFont font; - int fontCharWidth; + int fontCharWidth; + int actvCheatIdx; + bool actvCheatRedraw; private: void showCheatSearchResults(void); + void showActiveCheatList(bool redraw); public slots: void closeWindow(void); @@ -75,5 +80,7 @@ class GuiCheatsDialog_t : public QDialog void notEqualValueCallback(void); void lessThanValueCallback(void); void greaterThanValueCallback(void); + void openCheatFile(void); + void actvCheatItemClicked( QTreeWidgetItem *item, int column); }; From 34279fd5ac8734b90aaaa32de1ff5c574a5a72bb Mon Sep 17 00:00:00 2001 From: Matthew Budd Date: Sat, 1 Aug 2020 21:33:43 -0400 Subject: [PATCH 09/15] Added logic for modify active cheat parameter update button. --- src/drivers/Qt/CheatsConf.cpp | 105 +++++++++++++++++++++++++++++++++- src/drivers/Qt/CheatsConf.h | 3 + 2 files changed, 107 insertions(+), 1 deletion(-) diff --git a/src/drivers/Qt/CheatsConf.cpp b/src/drivers/Qt/CheatsConf.cpp index 46986871..e1a228e2 100644 --- a/src/drivers/Qt/CheatsConf.cpp +++ b/src/drivers/Qt/CheatsConf.cpp @@ -83,6 +83,7 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) lbl = new QLabel( tr("Name:") ); cheatNameEntry = new QLineEdit(); cheatNameEntry->setFont( font ); + //cheatNameEntry->setMaxLength(64); hbox->addWidget( lbl ); hbox->addWidget( cheatNameEntry ); @@ -339,6 +340,9 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) connect( neValBtn , SIGNAL(clicked(void)), this, SLOT(notEqualValueCallback(void)) ); connect( ltValBtn , SIGNAL(clicked(void)), this, SLOT(lessThanValueCallback(void)) ); connect( grValBtn , SIGNAL(clicked(void)), this, SLOT(greaterThanValueCallback(void)) ); + connect( addCheatBtn , SIGNAL(clicked(void)), this, SLOT(addActvCheat(void)) ); + connect( delCheatBtn , SIGNAL(clicked(void)), this, SLOT(deleteActvCheat(void)) ); + connect( modCheatBtn , SIGNAL(clicked(void)), this, SLOT(updateCheatParameters(void)) ); connect( importCheatFileBtn, SIGNAL(clicked(void)), this, SLOT(openCheatFile(void)) ); @@ -642,15 +646,114 @@ void GuiCheatsDialog_t::openCheatFile(void) return; } //---------------------------------------------------------------------------- +void GuiCheatsDialog_t::addActvCheat(void) +{ + // TODO +} +//---------------------------------------------------------------------------- +void GuiCheatsDialog_t::deleteActvCheat(void) +{ + // TODO +} +//---------------------------------------------------------------------------- +void GuiCheatsDialog_t::updateCheatParameters(void) +{ + uint32 a = 0; + uint8 v = 0; + int c = -1, s = 0, type = 0; + std::string name, cmpStr; + QTreeWidgetItem *item; + + item = actvCheatList->currentItem(); + + if ( item == NULL ) + { + printf( "No Item Selected\n"); + return; + } + + int row = actvCheatList->indexOfTopLevelItem(item); + + if ( FCEUI_GetCheat( row, NULL, &a, &v, &c, &s, &type) == 0 ) + { + return; + } + //printf("Row: %i \n", row ); + + a = strtoul( cheatAddrEntry->text().toStdString().c_str(), NULL, 16 ); + + v = strtoul( cheatValEntry->text().toStdString().c_str(), NULL, 16 ); + + cmpStr = cheatCmpEntry->text().toStdString(); + + if ( isdigit( cmpStr[0] ) ) + { + c = strtoul( cmpStr.c_str(), NULL, 16 ); + } + else + { + c = -1; + } + + name = cheatNameEntry->text().toStdString(); + + //printf("Name: %s \n", name.c_str() ); + + FCEUI_SetCheat( row, name.c_str(), a, v, c, s, type); + + showActiveCheatList(false); +} +//---------------------------------------------------------------------------- void GuiCheatsDialog_t::actvCheatItemClicked( QTreeWidgetItem *item, int column) { + uint32 a = 0; + uint8 v = 0; + int c = -1, s = 0, type = 0; + char *name = NULL; + char stmp[64]; + int row = actvCheatList->indexOfTopLevelItem(item); printf("Row: %i Column: %i \n", row, column ); + if ( FCEUI_GetCheat( row, &name, &a, &v, &c, &s, &type) == 0 ) + { + return; + } + if ( column == 0 ) { - FCEUI_ToggleCheat( row ); + int isChecked = item->checkState( column ) != Qt::Unchecked; + + if ( isChecked != s ) + { + //printf("Toggle Cheat: %i\n", isChecked); + FCEUI_ToggleCheat( row ); + } + } + sprintf( stmp, "%04X", a ); + cheatAddrEntry->setText( tr(stmp) ); + + sprintf( stmp, "%02X", v ); + cheatValEntry->setText( tr(stmp) ); + + if ( c >= 0 ) + { + sprintf( stmp, "%02X", c ); + cheatCmpEntry->setText( tr(stmp) ); + } + else + { + cheatCmpEntry->setText( tr("") ); + } + + if ( name != NULL ) + { + cheatNameEntry->setText( tr(name) ); + } + else + { + cheatNameEntry->setText( tr("") ); } } //---------------------------------------------------------------------------- diff --git a/src/drivers/Qt/CheatsConf.h b/src/drivers/Qt/CheatsConf.h index dc457793..43dc8da7 100644 --- a/src/drivers/Qt/CheatsConf.h +++ b/src/drivers/Qt/CheatsConf.h @@ -81,6 +81,9 @@ class GuiCheatsDialog_t : public QDialog void lessThanValueCallback(void); void greaterThanValueCallback(void); void openCheatFile(void); + void addActvCheat(void); + void deleteActvCheat(void); + void updateCheatParameters(void); void actvCheatItemClicked( QTreeWidgetItem *item, int column); }; From 2905c105bf3f6ed3bbf4fabd208792d2eee96cc5 Mon Sep 17 00:00:00 2001 From: Matthew Budd Date: Sun, 2 Aug 2020 20:04:59 -0400 Subject: [PATCH 10/15] Added cheat add/delete button logic. --- src/drivers/Qt/CheatsConf.cpp | 56 ++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/src/drivers/Qt/CheatsConf.cpp b/src/drivers/Qt/CheatsConf.cpp index e1a228e2..f264d7ab 100644 --- a/src/drivers/Qt/CheatsConf.cpp +++ b/src/drivers/Qt/CheatsConf.cpp @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include "../../types.h" #include "../../fceu.h" @@ -34,13 +36,21 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) QLabel *lbl; QGroupBox *groupBox; QFrame *frame; + QScreen *screen = QGuiApplication::primaryScreen(); + int devPixRatio = 1; + + if ( screen != NULL ) + { + devPixRatio = (int)( screen->devicePixelRatio() + 0.50f); + printf("Pix Ratio: %i \n", devPixRatio ); + } font.setStyle( QFont::StyleNormal ); font.setStyleHint( QFont::Monospace ); QFontMetrics fm(font); - fontCharWidth = fm.boundingRect('0').width(); + fontCharWidth = fm.boundingRect('0').width() * devPixRatio; setWindowTitle("Cheat Search"); @@ -648,12 +658,50 @@ void GuiCheatsDialog_t::openCheatFile(void) //---------------------------------------------------------------------------- void GuiCheatsDialog_t::addActvCheat(void) { - // TODO + uint32 a = 0; + uint8 v = 0; + int c = -1; + std::string name, cmpStr; + + a = strtoul( cheatAddrEntry->text().toStdString().c_str(), NULL, 16 ); + + v = strtoul( cheatValEntry->text().toStdString().c_str(), NULL, 16 ); + + cmpStr = cheatCmpEntry->text().toStdString(); + + if ( isdigit( cmpStr[0] ) ) + { + c = strtoul( cmpStr.c_str(), NULL, 16 ); + } + else + { + c = -1; + } + + name = cheatNameEntry->text().toStdString(); + + FCEUI_AddCheat( name.c_str(), a, v, c, 1 ); + + showActiveCheatList(true); } //---------------------------------------------------------------------------- void GuiCheatsDialog_t::deleteActvCheat(void) { - // TODO + QTreeWidgetItem *item; + + item = actvCheatList->currentItem(); + + if ( item == NULL ) + { + printf( "No Item Selected\n"); + return; + } + + int row = actvCheatList->indexOfTopLevelItem(item); + + FCEUI_DelCheat (row); + + showActiveCheatList(true); } //---------------------------------------------------------------------------- void GuiCheatsDialog_t::updateCheatParameters(void) @@ -714,7 +762,7 @@ void GuiCheatsDialog_t::actvCheatItemClicked( QTreeWidgetItem *item, int column int row = actvCheatList->indexOfTopLevelItem(item); - printf("Row: %i Column: %i \n", row, column ); + //printf("Row: %i Column: %i \n", row, column ); if ( FCEUI_GetCheat( row, &name, &a, &v, &c, &s, &type) == 0 ) { From 53c96c9fbd29e228dd35a1d0901ecaadba93be06 Mon Sep 17 00:00:00 2001 From: Matthew Budd Date: Sun, 2 Aug 2020 20:23:12 -0400 Subject: [PATCH 11/15] Added button sensitivity logic for cheat search window. --- src/drivers/Qt/CheatsConf.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/drivers/Qt/CheatsConf.cpp b/src/drivers/Qt/CheatsConf.cpp index f264d7ab..bc39339d 100644 --- a/src/drivers/Qt/CheatsConf.cpp +++ b/src/drivers/Qt/CheatsConf.cpp @@ -221,6 +221,7 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) knownValBtn = new QPushButton( tr("Known Value:") ); knownValBtn->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); + knownValBtn->setEnabled(false); vbox->addWidget( knownValBtn ); @@ -236,6 +237,7 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) knownValEntry->setCursorPosition(0); knownValEntry->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); knownValEntry->setMaximumWidth( 3 * fontCharWidth ); + knownValEntry->setEnabled(false); hbox1->addWidget( lbl, 0, Qt::AlignRight ); hbox1->addWidget( knownValEntry, 0, Qt::AlignLeft ); @@ -253,6 +255,7 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) eqValBtn = new QPushButton( tr("Equal") ); eqValBtn->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); + eqValBtn->setEnabled(false); vbox->addWidget( eqValBtn ); frame->setLayout( vbox ); @@ -265,10 +268,12 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) neValBtn = new QPushButton( tr("Not Equal") ); neValBtn->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); + neValBtn->setEnabled(false); hbox = new QHBoxLayout(); useNeVal = new QCheckBox( tr("By:") ); useNeVal->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); + useNeVal->setEnabled(false); neValEntry = new QLineEdit(); neValEntry->setMaxLength(2); neValEntry->setInputMask( ">HH;0" ); @@ -276,6 +281,7 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) neValEntry->setCursorPosition(0); neValEntry->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); neValEntry->setMaximumWidth( 3 * fontCharWidth ); + neValEntry->setEnabled(false); hbox->addWidget( useNeVal, 0, Qt::AlignRight ); hbox->addWidget( neValEntry, 0, Qt::AlignLeft ); @@ -292,10 +298,12 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) grValBtn = new QPushButton( tr("Greater Than") ); grValBtn->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); + grValBtn->setEnabled(false); hbox = new QHBoxLayout(); useGrVal = new QCheckBox( tr("By:") ); useGrVal->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); + useGrVal->setEnabled(false); grValEntry = new QLineEdit(); grValEntry->setMaxLength(2); grValEntry->setInputMask( ">HH;0" ); @@ -303,6 +311,7 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) grValEntry->setCursorPosition(0); grValEntry->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); grValEntry->setMaximumWidth( 3 * fontCharWidth ); + grValEntry->setEnabled(false); hbox->addWidget( useGrVal, 0, Qt::AlignRight ); hbox->addWidget( grValEntry, 0, Qt::AlignLeft ); @@ -319,10 +328,12 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) ltValBtn = new QPushButton( tr("Less Than") ); ltValBtn->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); + ltValBtn->setEnabled(false); hbox = new QHBoxLayout(); useLtVal = new QCheckBox( tr("By:") ); useLtVal->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); + useLtVal->setEnabled(false); ltValEntry = new QLineEdit(); ltValEntry->setMaxLength(2); ltValEntry->setInputMask( ">HH;0" ); @@ -330,6 +341,7 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) ltValEntry->setCursorPosition(0); ltValEntry->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); ltValEntry->setMaximumWidth( 3 * fontCharWidth ); + ltValEntry->setEnabled(false); hbox->addWidget( useLtVal, 0, Qt::AlignRight ); hbox->addWidget( ltValEntry, 0, Qt::AlignLeft ); @@ -428,6 +440,21 @@ void GuiCheatsDialog_t::resetSearchCallback(void) showCheatSearchResults(); fceuWrapperUnLock(); + + knownValBtn->setEnabled(true); + eqValBtn->setEnabled(true); + neValBtn->setEnabled(true); + grValBtn->setEnabled(true); + ltValBtn->setEnabled(true); + + useNeVal->setEnabled(true); + useGrVal->setEnabled(true); + useLtVal->setEnabled(true); + + knownValEntry->setEnabled(true); + neValEntry->setEnabled(true); + grValEntry->setEnabled(true); + ltValEntry->setEnabled(true); } //---------------------------------------------------------------------------- void GuiCheatsDialog_t::knownValueCallback(void) @@ -702,6 +729,11 @@ void GuiCheatsDialog_t::deleteActvCheat(void) FCEUI_DelCheat (row); showActiveCheatList(true); + + cheatNameEntry->setText( tr("") ); + cheatAddrEntry->setText( tr("") ); + cheatValEntry->setText( tr("") ); + cheatCmpEntry->setText( tr("") ); } //---------------------------------------------------------------------------- void GuiCheatsDialog_t::updateCheatParameters(void) From 7d6f1fdacc214954b9f5718fc240f07abd9a9978 Mon Sep 17 00:00:00 2001 From: Matthew Budd Date: Sun, 2 Aug 2020 20:29:24 -0400 Subject: [PATCH 12/15] Added logic to lock emulation when adding or deleting cheats. --- src/drivers/Qt/CheatsConf.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/drivers/Qt/CheatsConf.cpp b/src/drivers/Qt/CheatsConf.cpp index bc39339d..e8da1dc5 100644 --- a/src/drivers/Qt/CheatsConf.cpp +++ b/src/drivers/Qt/CheatsConf.cpp @@ -707,7 +707,9 @@ void GuiCheatsDialog_t::addActvCheat(void) name = cheatNameEntry->text().toStdString(); + fceuWrapperLock(); FCEUI_AddCheat( name.c_str(), a, v, c, 1 ); + fceuWrapperUnLock(); showActiveCheatList(true); } @@ -726,7 +728,9 @@ void GuiCheatsDialog_t::deleteActvCheat(void) int row = actvCheatList->indexOfTopLevelItem(item); + fceuWrapperLock(); FCEUI_DelCheat (row); + fceuWrapperUnLock(); showActiveCheatList(true); From e99cc1d64dbd4844611eb37546727e348fe8b6eb Mon Sep 17 00:00:00 2001 From: Matthew Budd Date: Sun, 2 Aug 2020 20:31:21 -0400 Subject: [PATCH 13/15] Added logic to lock emulation when modifying cheats. --- src/drivers/Qt/CheatsConf.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/drivers/Qt/CheatsConf.cpp b/src/drivers/Qt/CheatsConf.cpp index e8da1dc5..74c0a41a 100644 --- a/src/drivers/Qt/CheatsConf.cpp +++ b/src/drivers/Qt/CheatsConf.cpp @@ -783,8 +783,12 @@ void GuiCheatsDialog_t::updateCheatParameters(void) //printf("Name: %s \n", name.c_str() ); + fceuWrapperLock(); + FCEUI_SetCheat( row, name.c_str(), a, v, c, s, type); + fceuWrapperUnLock(); + showActiveCheatList(false); } //---------------------------------------------------------------------------- From 7c84e7b3832553a9b31d1bcc01d9cab720675b80 Mon Sep 17 00:00:00 2001 From: Matthew Budd Date: Sun, 2 Aug 2020 20:58:59 -0400 Subject: [PATCH 14/15] Added global cheat enable and auto load/save checkboxes --- src/drivers/Qt/CheatsConf.cpp | 36 +++++++++++++++++++++++++++++++++++ src/drivers/Qt/CheatsConf.h | 4 ++++ 2 files changed, 40 insertions(+) diff --git a/src/drivers/Qt/CheatsConf.cpp b/src/drivers/Qt/CheatsConf.cpp index 74c0a41a..74f61a15 100644 --- a/src/drivers/Qt/CheatsConf.cpp +++ b/src/drivers/Qt/CheatsConf.cpp @@ -86,6 +86,19 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) connect( actvCheatList, SIGNAL(itemClicked(QTreeWidgetItem*, int)), this, SLOT(actvCheatItemClicked( QTreeWidgetItem*, int)) ); + hbox = new QHBoxLayout(); + + enaCheats = new QCheckBox( tr("Enable Cheats") ); + autoSave = new QCheckBox( tr("Auto Load / Save with Game") ); + + enaCheats->setChecked( !globalCheatDisabled ); + autoSave->setChecked( !disableAutoLSCheats ); + + hbox->addWidget( enaCheats ); + hbox->addWidget( autoSave ); + + vbox1->addLayout( hbox ); + vbox1->addWidget( actvCheatList ); hbox = new QHBoxLayout(); @@ -366,6 +379,9 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) connect( delCheatBtn , SIGNAL(clicked(void)), this, SLOT(deleteActvCheat(void)) ); connect( modCheatBtn , SIGNAL(clicked(void)), this, SLOT(updateCheatParameters(void)) ); + connect( enaCheats, SIGNAL(stateChanged(int)), this, SLOT(globalEnableCheats(int)) ); + connect( autoSave , SIGNAL(stateChanged(int)), this, SLOT(autoLoadSaveCheats(int)) ); + connect( importCheatFileBtn, SIGNAL(clicked(void)), this, SLOT(openCheatFile(void)) ); showActiveCheatList(true); @@ -845,3 +861,23 @@ void GuiCheatsDialog_t::actvCheatItemClicked( QTreeWidgetItem *item, int column } } //---------------------------------------------------------------------------- +void GuiCheatsDialog_t::globalEnableCheats(int state) +{ + fceuWrapperLock(); + FCEUI_GlobalToggleCheat( state != Qt::Unchecked ); + fceuWrapperUnLock(); +} +//---------------------------------------------------------------------------- +void GuiCheatsDialog_t::autoLoadSaveCheats(int state) +{ + if ( state == Qt::Unchecked ) + { + printf("If this option is unchecked, you must manually save the cheats by yourself, or all the changes you made to the cheat list would be discarded silently without any asking once you close the game!\nDo you really want to do it in this way?"); + disableAutoLSCheats = 2; + } + else + { + disableAutoLSCheats = 0; + } +} +//---------------------------------------------------------------------------- diff --git a/src/drivers/Qt/CheatsConf.h b/src/drivers/Qt/CheatsConf.h index 43dc8da7..35d1bc48 100644 --- a/src/drivers/Qt/CheatsConf.h +++ b/src/drivers/Qt/CheatsConf.h @@ -51,6 +51,8 @@ class GuiCheatsDialog_t : public QDialog QCheckBox *useNeVal; QCheckBox *useGrVal; QCheckBox *useLtVal; + QCheckBox *enaCheats; + QCheckBox *autoSave; QTreeWidget *actvCheatList; QTreeWidget *srchResults; QLineEdit *cheatNameEntry; @@ -84,6 +86,8 @@ class GuiCheatsDialog_t : public QDialog void addActvCheat(void); void deleteActvCheat(void); void updateCheatParameters(void); + void autoLoadSaveCheats(int state); + void globalEnableCheats(int state); void actvCheatItemClicked( QTreeWidgetItem *item, int column); }; From b0529d564a7e91f6c5af59c538b659f5e2ebfc4c Mon Sep 17 00:00:00 2001 From: Matthew Budd Date: Sun, 2 Aug 2020 21:19:32 -0400 Subject: [PATCH 15/15] Added pause while cheat window is active checkbox logic. --- src/drivers/Qt/CheatsConf.cpp | 42 ++++++++++++++++++++++++++++++++++- src/drivers/Qt/CheatsConf.h | 4 ++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/drivers/Qt/CheatsConf.cpp b/src/drivers/Qt/CheatsConf.cpp index 74f61a15..29f9bdaf 100644 --- a/src/drivers/Qt/CheatsConf.cpp +++ b/src/drivers/Qt/CheatsConf.cpp @@ -54,6 +54,9 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) setWindowTitle("Cheat Search"); + pauseWhileActive = false; + wasPausedByCheats = false; + //resize( 512, 512 ); // Window Layout Box @@ -365,7 +368,14 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) groupBox->setLayout( vbox3 ); - mainLayout->addWidget( cheatSearchFrame ); + vbox = new QVBoxLayout(); + + pauseBox = new QCheckBox( tr("Pause emulation when this window is active") ); + + vbox->addWidget( cheatSearchFrame ); + vbox->addWidget( pauseBox ); + + mainLayout->addLayout( vbox ); setLayout( mainLayout ); @@ -381,6 +391,7 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) connect( enaCheats, SIGNAL(stateChanged(int)), this, SLOT(globalEnableCheats(int)) ); connect( autoSave , SIGNAL(stateChanged(int)), this, SLOT(autoLoadSaveCheats(int)) ); + connect( pauseBox , SIGNAL(stateChanged(int)), this, SLOT(pauseWindowState(int)) ); connect( importCheatFileBtn, SIGNAL(clicked(void)), this, SLOT(openCheatFile(void)) ); @@ -389,6 +400,12 @@ GuiCheatsDialog_t::GuiCheatsDialog_t(QWidget *parent) //---------------------------------------------------------------------------- GuiCheatsDialog_t::~GuiCheatsDialog_t(void) { + if (EmulationPaused && wasPausedByCheats) + { + EmulationPaused = 0; + FCEU_printf ("Emulation paused: %d\n", EmulationPaused); + } + wasPausedByCheats = false; } //---------------------------------------------------------------------------- @@ -881,3 +898,26 @@ void GuiCheatsDialog_t::autoLoadSaveCheats(int state) } } //---------------------------------------------------------------------------- +void GuiCheatsDialog_t::pauseWindowState(int state) +{ + pauseWhileActive = (state != Qt::Unchecked); + + if (pauseWhileActive) + { + if (EmulationPaused == 0) + { + EmulationPaused = 1; + wasPausedByCheats = true; + } + } + else + { + if (EmulationPaused && wasPausedByCheats) + { + EmulationPaused = 0; + } + wasPausedByCheats = false; + } + FCEU_printf ("Emulation paused: %d\n", EmulationPaused); +} +//---------------------------------------------------------------------------- diff --git a/src/drivers/Qt/CheatsConf.h b/src/drivers/Qt/CheatsConf.h index 35d1bc48..1adb7b82 100644 --- a/src/drivers/Qt/CheatsConf.h +++ b/src/drivers/Qt/CheatsConf.h @@ -53,6 +53,7 @@ class GuiCheatsDialog_t : public QDialog QCheckBox *useLtVal; QCheckBox *enaCheats; QCheckBox *autoSave; + QCheckBox *pauseBox; QTreeWidget *actvCheatList; QTreeWidget *srchResults; QLineEdit *cheatNameEntry; @@ -68,6 +69,8 @@ class GuiCheatsDialog_t : public QDialog int fontCharWidth; int actvCheatIdx; bool actvCheatRedraw; + bool pauseWhileActive; + bool wasPausedByCheats; private: void showCheatSearchResults(void); @@ -88,6 +91,7 @@ class GuiCheatsDialog_t : public QDialog void updateCheatParameters(void); void autoLoadSaveCheats(int state); void globalEnableCheats(int state); + void pauseWindowState(int state); void actvCheatItemClicked( QTreeWidgetItem *item, int column); };