added PAL60 signature check to auto detect display type (resolves #1061)

This commit is contained in:
thrust26 2024-12-17 23:03:57 +01:00
parent db3a38be7b
commit 2abd72ff86
2 changed files with 65 additions and 1 deletions

View File

@ -171,8 +171,10 @@ Console::Console(OSystem& osystem, unique_ptr<Cartridge>& cart,
myDevSettingsHandler = make_unique<DevSettingsHandler>(myOSystem); myDevSettingsHandler = make_unique<DevSettingsHandler>(myOSystem);
// Auto-detect NTSC/PAL mode if it's requested // Auto-detect NTSC/PAL mode if it's requested
if (myDisplayFormat == "AUTO") if(myDisplayFormat == "AUTO")
myDisplayFormat = formatFromFilename(); myDisplayFormat = formatFromFilename();
if(myDisplayFormat == "AUTO")
myDisplayFormat = formatFromSignature();
// Add the real controllers for this system // Add the real controllers for this system
// This must be done before the debugger is initialized // This must be done before the debugger is initialized
@ -386,6 +388,48 @@ string Console::formatFromFilename() const
return "AUTO"; return "AUTO";
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
string Console::formatFromSignature() const
{
static constexpr uInt8 PAL60[] = { 'P', 'A', 'L', '6', '0'};
static constexpr uInt8 PAL_60[] = { 'P', 'A', 'L', ' ', '6', '0'};
static constexpr uInt8 PAL__60[] = { 'P', 'A', 'L', '-', '6', '0'};
size_t size;
const ByteBuffer& image = myCart->getImage(size);
if(searchForBytes(image, size, PAL60, 5) ||
searchForBytes(image, size, PAL_60, 6) ||
searchForBytes(image, size, PAL__60, 6))
return "PAL60";
// Nothing found
return "AUTO";
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool Console::searchForBytes(const ByteBuffer& image, size_t imagesize,
const uInt8* signature, uInt32 sigsize) const
{
if(imagesize >= sigsize)
for(uInt32 i = 0; i < imagesize - sigsize; ++i)
{
uInt32 matches = 0;
for(uInt32 j = 0; j < sigsize; ++j)
{
if(image[i + j] == signature[j])
++matches;
else
break;
}
if(matches == sigsize)
{
return true;
}
}
return false;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool Console::save(Serializer& out) const bool Console::save(Serializer& out) const
{ {

View File

@ -420,6 +420,26 @@ class Console : public Serializable, public ConsoleIO
*/ */
string formatFromFilename() const; string formatFromFilename() const;
/**
* Determine display format by signature string (only PAL?60 so far)
* Returns "AUTO" if nothing is found
*/
string formatFromSignature() const;
/**
Search the image for the specified byte signature.
@param image A pointer to the ROM image
@param imagesize The size of the ROM image
@param signature The byte sequence to search for
@param sigsize The number of bytes in the signature
@return True if the signature was found, else false
*/
bool searchForBytes(const ByteBuffer& image, size_t imagesize,
const uInt8* signature, uInt32 sigsize) const;
/** /**
Create the audio queue Create the audio queue
*/ */