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()
{
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<uInt8, 3> pixbuf; // Temporary buffer for one 24-bit pixel

View File

@ -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()
{

View File

@ -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.

View File

@ -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);