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
This commit is contained in:
urchlay 2005-07-09 15:19:24 +00:00
parent 3fabe0ece8
commit adb22f7b00
2 changed files with 35 additions and 7 deletions

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // 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 <assert.h> #include <assert.h>
@ -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; 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; uInt32 count = 0;
for(uInt32 i = 0; i < size - 1; ++i) 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; ++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);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // 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 #ifndef CARTRIDGE_HXX
@ -31,7 +31,7 @@ class System;
game and handles any bankswitching performed by the cartridge. game and handles any bankswitching performed by the cartridge.
@author Bradford W. Mott @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 class Cartridge : public Device
{ {
@ -75,10 +75,20 @@ class Cartridge : public Device
static string autodetectType(const uInt8* image, uInt32 size); 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); 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: private:
// Copy constructor isn't supported by cartridges so make it private // Copy constructor isn't supported by cartridges so make it private
Cartridge(const Cartridge&); Cartridge(const Cartridge&);