From adb22f7b001f302d19a19e4d5b0e3df745cbbb1e Mon Sep 17 00:00:00 2001 From: urchlay Date: Sat, 9 Jul 2005 15:19:24 +0000 Subject: [PATCH] Added detection for 3E carts. As it was, 3E carts would detect as 3F, so it's just one test (search for STA $3E in the image) to distinguish between the two. I still only have 3 3E images (notBD PAL and NTSC, and Armin's test cart), but all 3 are detected, at least. Autodetection isn't as important in Stella as it is in some other emulators, due to the stella.pro database, so I won't try to make this too smart for its own good... git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@629 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba --- stella/src/emucore/Cart.cxx | 26 ++++++++++++++++++++++---- stella/src/emucore/Cart.hxx | 16 +++++++++++++--- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/stella/src/emucore/Cart.cxx b/stella/src/emucore/Cart.cxx index 0787502ab..b044ff106 100644 --- a/stella/src/emucore/Cart.cxx +++ b/stella/src/emucore/Cart.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: Cart.cxx,v 1.13 2005-07-08 11:50:32 stephena Exp $ +// $Id: Cart.cxx,v 1.14 2005-07-09 15:19:24 urchlay Exp $ //============================================================================ #include @@ -238,22 +238,40 @@ string Cartridge::autodetectType(const uInt8* image, uInt32 size) } } + /* The above logic was written long before 3E support existed. It will + detect a 3E cart as 3F. Let's remedy that situation: */ + + if(type == "3F" && isProbably3E(image, size)) + type = "3E"; + return type; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool Cartridge::isProbably3F(const uInt8* image, uInt32 size) +int Cartridge::searchForBytes(const uInt8* image, uInt32 size, uInt8 byte1, uInt8 byte2) { uInt32 count = 0; for(uInt32 i = 0; i < size - 1; ++i) { - if((image[i] == 0x85) && (image[i + 1] == 0x3F)) + if((image[i] == byte1) && (image[i + 1] == byte2)) { ++count; } } - return (count > 2); + return count; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool Cartridge::isProbably3F(const uInt8* image, uInt32 size) +{ + return (searchForBytes(image, size, 0x85, 0x3F) > 2); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool Cartridge::isProbably3E(const uInt8* image, uInt32 size) +{ + return (searchForBytes(image, size, 0x85, 0x3E) > 2); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/stella/src/emucore/Cart.hxx b/stella/src/emucore/Cart.hxx index 0d7170a5f..38b18f6c0 100644 --- a/stella/src/emucore/Cart.hxx +++ b/stella/src/emucore/Cart.hxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: Cart.hxx,v 1.6 2005-06-28 01:15:17 urchlay Exp $ +// $Id: Cart.hxx,v 1.7 2005-07-09 15:19:24 urchlay Exp $ //============================================================================ #ifndef CARTRIDGE_HXX @@ -31,7 +31,7 @@ class System; game and handles any bankswitching performed by the cartridge. @author Bradford W. Mott - @version $Id: Cart.hxx,v 1.6 2005-06-28 01:15:17 urchlay Exp $ + @version $Id: Cart.hxx,v 1.7 2005-07-09 15:19:24 urchlay Exp $ */ class Cartridge : public Device { @@ -75,10 +75,20 @@ class Cartridge : public Device static string autodetectType(const uInt8* image, uInt32 size); /** - Returns true iff the image is probably a 3F bankswitching cartridge + Returns true if the image is probably a 3F bankswitching cartridge */ static bool isProbably3F(const uInt8* image, uInt32 size); + /** + Returns true if the image is probably a 3E bankswitching cartridge + */ + static bool isProbably3E(const uInt8* image, uInt32 size); + + /** + Utility method used by isProbably3F and isProbably3E + */ + static int searchForBytes(const uInt8* image, uInt32 size, uInt8 byte1, uInt8 byte2); + private: // Copy constructor isn't supported by cartridges so make it private Cartridge(const Cartridge&);