disable user palette option if no file exists (resolves #572)

This commit is contained in:
thrust26 2020-02-06 20:44:17 +01:00
parent 7a7969ae8a
commit aa18ce6bcd
4 changed files with 34 additions and 16 deletions

View File

@ -996,22 +996,11 @@ unique_ptr<Controller> Console::getControllerPort(const Controller::Type type,
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Console::loadUserPalette() void Console::loadUserPalette()
{ {
const string& palette = myOSystem.paletteFile(); if (!myOSystem.checkUserPalette(true))
ifstream in(palette, std::ios::binary);
if(!in)
return; return;
// Make sure the contains enough data for the NTSC, PAL and SECAM palettes const string& palette = myOSystem.paletteFile();
// This means 128 colours each for NTSC and PAL, at 3 bytes per pixel ifstream in(palette, std::ios::binary);
// 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;
}
// Now that we have valid data, create the user-defined palettes // Now that we have valid data, create the user-defined palettes
std::array<uInt8, 3> pixbuf; // Temporary buffer for one 24-bit pixel std::array<uInt8, 3> pixbuf; // Temporary buffer for one 24-bit pixel

View File

@ -301,6 +301,29 @@ void OSystem::setConfigPaths()
#endif #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() FBInitStatus OSystem::createFrameBuffer()
{ {

View File

@ -287,6 +287,11 @@ class OSystem
*/ */
const string& paletteFile() const { return myPaletteFile; } 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 This method should be called to get the full path of the currently
loaded ROM. loaded ROM.

View File

@ -116,7 +116,8 @@ VideoDialog::VideoDialog(OSystem& osystem, DialogContainer& parent,
// TIA Palette // TIA Palette
items.clear(); items.clear();
VarList::push_back(items, "Standard", "standard"); VarList::push_back(items, "Standard", "standard");
VarList::push_back(items, "Z26", "z26"); VarList::push_back(items, "z26", "z26");
if (instance().checkUserPalette())
VarList::push_back(items, "User", "user"); VarList::push_back(items, "User", "user");
myTIAPalette = new PopUpWidget(myTab, font, xpos, ypos, pwidth, myTIAPalette = new PopUpWidget(myTab, font, xpos, ypos, pwidth,
lineHeight, items, "Palette ", lwidth); lineHeight, items, "Palette ", lwidth);