From 002481c6b9a324c131a3fe23e22d85e1775de9f8 Mon Sep 17 00:00:00 2001 From: Matthew Budd Date: Sat, 18 Jul 2020 15:19:01 -0400 Subject: [PATCH 1/3] Added a few more options to the palette config window. --- src/drivers/Qt/PaletteConf.cpp | 75 +++++++++++++++++++++++++++++++++- src/drivers/Qt/PaletteConf.h | 6 +++ src/drivers/Qt/sdl-video.cpp | 19 +++++++-- 3 files changed, 96 insertions(+), 4 deletions(-) diff --git a/src/drivers/Qt/PaletteConf.cpp b/src/drivers/Qt/PaletteConf.cpp index b02c57e5..75156312 100644 --- a/src/drivers/Qt/PaletteConf.cpp +++ b/src/drivers/Qt/PaletteConf.cpp @@ -9,6 +9,9 @@ #include "Qt/keyscan.h" #include "Qt/fceuWrapper.h" +#include "../../ppu.h" + +extern bool force_grayscale; //---------------------------------------------------- PaletteConfDialog_t::PaletteConfDialog_t(QWidget *parent) : QDialog( parent ) @@ -31,8 +34,25 @@ PaletteConfDialog_t::PaletteConfDialog_t(QWidget *parent) mainLayout = new QVBoxLayout(); frame = new QGroupBox( tr("Custom Palette:") ); + vbox = new QVBoxLayout(); hbox1 = new QHBoxLayout(); + useCustom = new QCheckBox( tr("Use Custom Palette") ); + GrayScale = new QCheckBox( tr("Force Grayscale") ); + deemphSwap = new QCheckBox( tr("De-emphasis Bit Swap") ); + + GrayScale->setChecked( force_grayscale ); + deemphSwap->setChecked( paldeemphswap ); + + connect(useCustom , SIGNAL(stateChanged(int)), this, SLOT(use_Custom_Changed(int)) ); + connect(GrayScale , SIGNAL(stateChanged(int)), this, SLOT(force_GrayScale_Changed(int)) ); + connect(deemphSwap, SIGNAL(stateChanged(int)), this, SLOT(deemphswap_Changed(int)) ); + + vbox->addWidget( useCustom ); + vbox->addLayout( hbox1 ); + vbox->addWidget( GrayScale ); + vbox->addWidget( deemphSwap); + button = new QPushButton( tr("Open Palette") ); hbox1->addWidget( button ); @@ -50,7 +70,7 @@ PaletteConfDialog_t::PaletteConfDialog_t(QWidget *parent) connect( button, SIGNAL(clicked(void)), this, SLOT(clearPalette(void)) ); - frame->setLayout( hbox1 ); + frame->setLayout( vbox ); mainLayout->addWidget( frame ); @@ -156,6 +176,59 @@ void PaletteConfDialog_t::tintChanged(int v) } } //---------------------------------------------------- +void PaletteConfDialog_t::use_Custom_Changed(int state) +{ + int value = (state == Qt::Unchecked) ? 0 : 1; + std::string filename; + + g_config->getOption ("SDL.Palette", &filename); + + if ( fceuWrapperTryLock() ) + { + if ( value && (filename.size() > 0) ) + { + LoadCPalette ( filename.c_str() ); + } + else + { + FCEUI_SetUserPalette( NULL, 0); + } + fceuWrapperUnLock(); + } +} +//---------------------------------------------------- +void PaletteConfDialog_t::force_GrayScale_Changed(int state) +{ + int value = (state == Qt::Unchecked) ? 0 : 1; + + if ( fceuWrapperTryLock() ) + { + int e, h, t; + g_config->getOption ("SDL.NTSCpalette", &e); + g_config->getOption ("SDL.Hue", &h); + g_config->getOption ("SDL.Tint", &t); + force_grayscale = value ? true : false; + FCEUI_SetNTSCTH( e, t, h); + fceuWrapperUnLock(); + } +} +//---------------------------------------------------- +void PaletteConfDialog_t::deemphswap_Changed(int state) +{ + int value = (state == Qt::Unchecked) ? 0 : 1; + + if ( fceuWrapperTryLock() ) + { + int e, h, t; + g_config->getOption ("SDL.NTSCpalette", &e); + g_config->getOption ("SDL.Hue", &h); + g_config->getOption ("SDL.Tint", &t); + paldeemphswap = value ? true : false; + FCEUI_SetNTSCTH( e, t, h); + fceuWrapperUnLock(); + } +} +//---------------------------------------------------- void PaletteConfDialog_t::use_NTSC_Changed(int state) { int h, t; diff --git a/src/drivers/Qt/PaletteConf.h b/src/drivers/Qt/PaletteConf.h index f1d83041..494d78aa 100644 --- a/src/drivers/Qt/PaletteConf.h +++ b/src/drivers/Qt/PaletteConf.h @@ -27,6 +27,9 @@ class PaletteConfDialog_t : public QDialog protected: QLineEdit *custom_palette_path; + QCheckBox *useCustom; + QCheckBox *GrayScale; + QCheckBox *deemphSwap; QCheckBox *useNTSC; QSlider *tintSlider; QSlider *hueSlider; @@ -42,5 +45,8 @@ class PaletteConfDialog_t : public QDialog void openPaletteFile(void); void clearPalette(void); void use_NTSC_Changed(int v); + void use_Custom_Changed(int v); + void force_GrayScale_Changed(int v); + void deemphswap_Changed(int v); }; diff --git a/src/drivers/Qt/sdl-video.cpp b/src/drivers/Qt/sdl-video.cpp index 95e9584c..cd52b9e5 100644 --- a/src/drivers/Qt/sdl-video.cpp +++ b/src/drivers/Qt/sdl-video.cpp @@ -51,6 +51,7 @@ // GLOBALS extern Config *g_config; +extern bool force_grayscale; // STATIC GLOBALS static int s_curbpp = 0; @@ -269,9 +270,21 @@ FCEUD_SetPalette(uint8 index, uint8 g, uint8 b) { - s_psdl[index].r = r; - s_psdl[index].g = g; - s_psdl[index].b = b; + if ( force_grayscale ) + { + // convert the palette entry to grayscale + int gray = ((float)r * 0.299 + (float)g * 0.587 + (float)b * 0.114); + + s_psdl[index].r = gray; + s_psdl[index].g = gray; + s_psdl[index].b = gray; + } + else + { + s_psdl[index].r = r; + s_psdl[index].g = g; + s_psdl[index].b = b; + } s_paletterefresh = 1; } From c0febe1d3e31abc981a74a70651789aff1e7c09f Mon Sep 17 00:00:00 2001 From: Matthew Budd Date: Sat, 18 Jul 2020 21:58:38 -0400 Subject: [PATCH 2/3] Added a hook in the core palette emulation to allow for the gui to determine if a custom user palette is available and in use. --- src/driver.h | 1 + src/drivers/Qt/PaletteConf.cpp | 55 ++++++++++++++++++++++++++-------- src/palette.cpp | 5 ++++ 3 files changed, 48 insertions(+), 13 deletions(-) diff --git a/src/driver.h b/src/driver.h index d3f1f020..9987643c 100644 --- a/src/driver.h +++ b/src/driver.h @@ -143,6 +143,7 @@ void FCEUI_SetRenderedLines(int ntscf, int ntscl, int palf, int pall); //Sets the base directory(save states, snapshots, etc. are saved in directories below this directory. void FCEUI_SetBaseDirectory(std::string const & dir); +bool FCEUI_GetUserPaletteAvail(void); void FCEUI_SetUserPalette(uint8 *pal, int nEntries); //Sets up sound code to render sound at the specified rate, in samples diff --git a/src/drivers/Qt/PaletteConf.cpp b/src/drivers/Qt/PaletteConf.cpp index 75156312..dcfe85f0 100644 --- a/src/drivers/Qt/PaletteConf.cpp +++ b/src/drivers/Qt/PaletteConf.cpp @@ -1,6 +1,7 @@ // PaletteConf.cpp // #include +#include #include "Qt/PaletteConf.h" #include "Qt/main.h" @@ -12,6 +13,14 @@ #include "../../ppu.h" extern bool force_grayscale; + +static const char *commentText = +"Palette Selection uses the 1st Matching Condition:\n\ + 1. Game type is NSF (always uses fixed palette) \n\ + 2. Custom User Palette is Available and Enabled \n\ + 3. NTSC Color Emulation is Enabled \n\ + 4. Individual Game Palette is Available \n\ + 5. Default Built-in Palette "; //---------------------------------------------------- PaletteConfDialog_t::PaletteConfDialog_t(QWidget *parent) : QDialog( parent ) @@ -21,10 +30,13 @@ PaletteConfDialog_t::PaletteConfDialog_t(QWidget *parent) QGroupBox *frame; //QPushButton *closebutton; QPushButton *button; + QTextEdit *comments; int hue, tint; char stmp[64]; std::string paletteFile; + resize( 512, 600 ); + // sync with config g_config->getOption ("SDL.Hue", &hue); g_config->getOption ("SDL.Tint", &tint); @@ -41,6 +53,7 @@ PaletteConfDialog_t::PaletteConfDialog_t(QWidget *parent) GrayScale = new QCheckBox( tr("Force Grayscale") ); deemphSwap = new QCheckBox( tr("De-emphasis Bit Swap") ); + useCustom->setChecked( FCEUI_GetUserPaletteAvail() ); GrayScale->setChecked( force_grayscale ); deemphSwap->setChecked( paldeemphswap ); @@ -48,11 +61,6 @@ PaletteConfDialog_t::PaletteConfDialog_t(QWidget *parent) connect(GrayScale , SIGNAL(stateChanged(int)), this, SLOT(force_GrayScale_Changed(int)) ); connect(deemphSwap, SIGNAL(stateChanged(int)), this, SLOT(deemphswap_Changed(int)) ); - vbox->addWidget( useCustom ); - vbox->addLayout( hbox1 ); - vbox->addWidget( GrayScale ); - vbox->addWidget( deemphSwap); - button = new QPushButton( tr("Open Palette") ); hbox1->addWidget( button ); @@ -63,7 +71,13 @@ PaletteConfDialog_t::PaletteConfDialog_t(QWidget *parent) custom_palette_path = new QLineEdit(); custom_palette_path->setReadOnly(true); custom_palette_path->setText( paletteFile.c_str() ); - hbox1->addWidget( custom_palette_path ); + + vbox->addWidget( useCustom ); + vbox->addLayout( hbox1 ); + vbox->addWidget( custom_palette_path ); + vbox->addWidget( GrayScale ); + vbox->addWidget( deemphSwap); + button = new QPushButton( tr("Clear") ); hbox1->addWidget( button ); @@ -119,6 +133,14 @@ PaletteConfDialog_t::PaletteConfDialog_t(QWidget *parent) mainLayout->addWidget( frame ); + comments = new QTextEdit(); + + comments->setText( commentText ); + comments->moveCursor(QTextCursor::Start); + comments->setReadOnly(true); + + mainLayout->addWidget( comments ); + setLayout( mainLayout ); } @@ -181,6 +203,8 @@ void PaletteConfDialog_t::use_Custom_Changed(int state) int value = (state == Qt::Unchecked) ? 0 : 1; std::string filename; + //printf("Use Custom:%i \n", state ); + g_config->getOption ("SDL.Palette", &filename); if ( fceuWrapperTryLock() ) @@ -257,6 +281,7 @@ void PaletteConfDialog_t::clearPalette(void) { FCEUI_SetUserPalette( NULL, 0); fceuWrapperUnLock(); + useCustom->setChecked(false); } } //---------------------------------------------------- @@ -298,18 +323,22 @@ void PaletteConfDialog_t::openPaletteFile(void) } qDebug() << "selected file path : " << filename.toUtf8(); - g_config->setOption ("SDL.Palette", filename.toStdString().c_str() ); - g_config->setOption ("SDL.NTSCpalette", 0); - if ( fceuWrapperTryLock() ) { - LoadCPalette ( filename.toStdString().c_str() ); + if ( LoadCPalette ( filename.toStdString().c_str() ) ) + { + g_config->setOption ("SDL.Palette", filename.toStdString().c_str() ); + custom_palette_path->setText( filename.toStdString().c_str() ); + } + else + { + printf("Error: Failed to Load Palette File: %s \n", filename.toStdString().c_str() ); + } fceuWrapperUnLock(); + + useCustom->setChecked( FCEUI_GetUserPaletteAvail() ); } - custom_palette_path->setText( filename.toStdString().c_str() ); - - useNTSC->setChecked( 0 ); return; } diff --git a/src/palette.cpp b/src/palette.cpp index bc552d12..5a9c2709 100644 --- a/src/palette.cpp +++ b/src/palette.cpp @@ -289,6 +289,11 @@ static void ApplyDeemphasisComplete(pal* pal512) } } +bool FCEUI_GetUserPaletteAvail( void ) +{ + return palette_user_available; +} + void FCEUI_SetUserPalette(uint8 *pal, int nEntries) { if(!pal) From 564e8b228e456902d5accbcaaaa4ee5984efb3e1 Mon Sep 17 00:00:00 2001 From: Matthew Budd Date: Sun, 19 Jul 2020 10:02:36 -0400 Subject: [PATCH 3/3] Updated comments in the INSTALL readme file. --- INSTALL | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/INSTALL b/INSTALL index f1f2a562..265f68af 100644 --- a/INSTALL +++ b/INSTALL @@ -3,5 +3,6 @@ To compile and install FCEUX for SDL, follow the instructions in the README-SDL. Users of Microsoft Visual Studio can use the solution files within the vc directory. These solution files will compile FCEUX and some included libraries for full functionality. -CMake has been depreciated in favor of scons. However, if you wish to use it you can find the old cmake build files in the attic. +The SDL port build tool of choice has come full circle back to Cmake. The cmake build tool will compile the new Qt version of the SDL GUI. +The scons build tool will build the older GTK based GUI which currently only builds on Linux.