mirror of https://github.com/stella-emu/stella.git
Optimized Cart::isProbablySC. Perhaps a small change, but more
efficiency never hurts.
This commit is contained in:
parent
02a399a8aa
commit
0e712b39e1
|
@ -314,7 +314,7 @@ bool Cartridge::saveROM(ofstream& out)
|
||||||
int size = -1;
|
int size = -1;
|
||||||
|
|
||||||
const uInt8* image = getImage(size);
|
const uInt8* image = getImage(size);
|
||||||
if(image == 0 || size <= 0)
|
if(image == nullptr || size <= 0)
|
||||||
{
|
{
|
||||||
cerr << "save not supported" << endl;
|
cerr << "save not supported" << endl;
|
||||||
return false;
|
return false;
|
||||||
|
@ -576,14 +576,13 @@ bool Cartridge::isProbablySC(const uInt8* image, uInt32 size)
|
||||||
{
|
{
|
||||||
// We assume a Superchip cart repeats the first 128 bytes for the second
|
// We assume a Superchip cart repeats the first 128 bytes for the second
|
||||||
// 128 bytes in the RAM area, which is the first 256 bytes of each 4K bank
|
// 128 bytes in the RAM area, which is the first 256 bytes of each 4K bank
|
||||||
uInt32 banks = size / 4096;
|
while(size)
|
||||||
for(uInt32 i = 0; i < banks; ++i)
|
|
||||||
{
|
{
|
||||||
for(uInt32 j = 0; j < 128; ++j)
|
if(memcmp(image, image + 128, 128) != 0)
|
||||||
{
|
return false;
|
||||||
if(image[i*4096+j] != image[i*4096+j + 128])
|
|
||||||
return false;
|
image += 4096;
|
||||||
}
|
size -= 4096;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -259,6 +259,7 @@ class Cartridge : public Device
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns true if the image is probably a SuperChip (256 bytes RAM)
|
Returns true if the image is probably a SuperChip (256 bytes RAM)
|
||||||
|
Note: should be called only on ROMs with size multiple of 4K
|
||||||
*/
|
*/
|
||||||
static bool isProbablySC(const uInt8* image, uInt32 size);
|
static bool isProbablySC(const uInt8* image, uInt32 size);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue