diff --git a/src/emucore/Console.cxx b/src/emucore/Console.cxx index 867eee9d9..5cef206b0 100644 --- a/src/emucore/Console.cxx +++ b/src/emucore/Console.cxx @@ -996,22 +996,11 @@ unique_ptr Console::getControllerPort(const Controller::Type type, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Console::loadUserPalette() { - const string& palette = myOSystem.paletteFile(); - ifstream in(palette, std::ios::binary); - if(!in) + if (!myOSystem.checkUserPalette(true)) return; - // Make sure the contains enough data for the NTSC, PAL and SECAM palettes - // This means 128 colours each for NTSC and PAL, at 3 bytes per pixel - // and 8 colours for SECAM at 3 bytes per pixel - in.seekg(0, std::ios::end); - std::streampos length = in.tellg(); - in.seekg(0, std::ios::beg); - if(length < 128 * 3 * 2 + 8 * 3) - { - cerr << "ERROR: invalid palette file " << palette << endl; - return; - } + const string& palette = myOSystem.paletteFile(); + ifstream in(palette, std::ios::binary); // Now that we have valid data, create the user-defined palettes std::array pixbuf; // Temporary buffer for one 24-bit pixel diff --git a/src/emucore/OSystem.cxx b/src/emucore/OSystem.cxx index 70f738f1f..638265910 100644 --- a/src/emucore/OSystem.cxx +++ b/src/emucore/OSystem.cxx @@ -301,6 +301,29 @@ void OSystem::setConfigPaths() #endif } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool OSystem::checkUserPalette(bool outputError) const +{ + const string& palette = paletteFile(); + ifstream in(palette, std::ios::binary); + if (!in) + return false; + + // Make sure the contains enough data for the NTSC, PAL and SECAM palettes + // This means 128 colours each for NTSC and PAL, at 3 bytes per pixel + // and 8 colours for SECAM at 3 bytes per pixel + in.seekg(0, std::ios::end); + std::streampos length = in.tellg(); + in.seekg(0, std::ios::beg); + if (length < 128 * 3 * 2 + 8 * 3) + { + if (outputError) + cerr << "ERROR: invalid palette file " << palette << endl; + return false; + } + return true; +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - FBInitStatus OSystem::createFrameBuffer() { diff --git a/src/emucore/OSystem.hxx b/src/emucore/OSystem.hxx index b505a4940..123bc92cb 100644 --- a/src/emucore/OSystem.hxx +++ b/src/emucore/OSystem.hxx @@ -287,6 +287,11 @@ class OSystem */ const string& paletteFile() const { return myPaletteFile; } + /** + Checks if a valid a user-defined palette file exists. + */ + bool checkUserPalette(bool outputError = false) const; + /** This method should be called to get the full path of the currently loaded ROM. diff --git a/src/gui/VideoDialog.cxx b/src/gui/VideoDialog.cxx index 7cbb73033..90e126918 100644 --- a/src/gui/VideoDialog.cxx +++ b/src/gui/VideoDialog.cxx @@ -116,8 +116,9 @@ VideoDialog::VideoDialog(OSystem& osystem, DialogContainer& parent, // TIA Palette items.clear(); VarList::push_back(items, "Standard", "standard"); - VarList::push_back(items, "Z26", "z26"); - VarList::push_back(items, "User", "user"); + VarList::push_back(items, "z26", "z26"); + if (instance().checkUserPalette()) + VarList::push_back(items, "User", "user"); myTIAPalette = new PopUpWidget(myTab, font, xpos, ypos, pwidth, lineHeight, items, "Palette ", lwidth); wid.push_back(myTIAPalette);