diff --git a/src/emucore/Cart.cxx b/src/emucore/Cart.cxx index 64acbb368..1eedda89e 100644 --- a/src/emucore/Cart.cxx +++ b/src/emucore/Cart.cxx @@ -314,7 +314,7 @@ bool Cartridge::saveROM(ofstream& out) int size = -1; const uInt8* image = getImage(size); - if(image == 0 || size <= 0) + if(image == nullptr || size <= 0) { cerr << "save not supported" << endl; 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 // 128 bytes in the RAM area, which is the first 256 bytes of each 4K bank - uInt32 banks = size / 4096; - for(uInt32 i = 0; i < banks; ++i) + while(size) { - for(uInt32 j = 0; j < 128; ++j) - { - if(image[i*4096+j] != image[i*4096+j + 128]) - return false; - } + if(memcmp(image, image + 128, 128) != 0) + return false; + + image += 4096; + size -= 4096; } return true; } diff --git a/src/emucore/Cart.hxx b/src/emucore/Cart.hxx index 25614520a..6d99f0f1d 100644 --- a/src/emucore/Cart.hxx +++ b/src/emucore/Cart.hxx @@ -259,6 +259,7 @@ class Cartridge : public Device /** 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);