diff --git a/src/emucore/ControllerDetector.cxx b/src/emucore/ControllerDetector.cxx index df842bc82..548fc8ed4 100644 --- a/src/emucore/ControllerDetector.cxx +++ b/src/emucore/ControllerDetector.cxx @@ -24,8 +24,8 @@ string ControllerDetector::detect(const uInt8* image, uInt32 size, const string& controller, const Controller::Jack port, const Settings& settings) { - //string type(controller); - string type("AUTO"); // dirty hack for testing!!! + string type(controller); + //string type("AUTO"); // dirty hack for testing!!! if(type == "AUTO" || settings.getBool("rominfo")) { @@ -102,6 +102,7 @@ bool ControllerDetector::usesJoystickButton(const uInt8* image, uInt32 size, Con { if(port == Controller::Left) { + // check for INPT4 access const int NUM_SIGS_0 = 17; const int SIG_SIZE_0 = 3; uInt8 signature_0[NUM_SIGS_0][SIG_SIZE_0] = { @@ -155,6 +156,7 @@ bool ControllerDetector::usesJoystickButton(const uInt8* image, uInt32 size, Con } else if(port == Controller::Right) { + // check for INPT5 and indexed INPT4 access const int NUM_SIGS_0 = 13; const int SIG_SIZE_0 = 3; uInt8 signature_0[NUM_SIGS_0][SIG_SIZE_0] = { @@ -206,21 +208,23 @@ bool ControllerDetector::usesGenesisButton(const uInt8* image, uInt32 size, Cont { if(port == Controller::Left) { - const int NUM_SIGS_0 = 12; + // check for INPT1 access + const int NUM_SIGS_0 = 13; const int SIG_SIZE_0 = 3; uInt8 signature_0[NUM_SIGS_0][SIG_SIZE_0] = { - { 0x24, 0x09, 0x10 }, // bit INPT1; bpl - { 0x24, 0x09, 0x30 }, // bit INPT1; bmi - { 0xa5, 0x09, 0x10 }, // lda INPT1; bpl - { 0xa5, 0x09, 0x30 }, // lda INPT1; bmi - { 0x24, 0x39, 0x10 }, // bit INPT1|$30; bpl - { 0x24, 0x39, 0x30 }, // bit INPT1|$30; bmi - { 0xa5, 0x39, 0x10 }, // lda INPT1|$30; bpl - { 0xa5, 0x39, 0x30 }, // lda INPT1|$30; bmi - { 0xa5, 0x39, 0x6a }, // lda INPT1|$30; ror - { 0xa6, 0x39, 0x8e }, // ldx INPT1|$30; stx - { 0xa5, 0x09, 0x29 }, // lda INPT1; and - { 0xa4, 0x09, 0x30 }, // ldy INPT1; bmi + { 0x24, 0x09, 0x10 }, // bit INPT1; bpl (Genesis only) + { 0x24, 0x09, 0x30 }, // bit INPT1; bmi (paddle ROMS too) + { 0xa5, 0x09, 0x10 }, // lda INPT1; bpl (paddle ROMS too) + { 0xa5, 0x09, 0x30 }, // lda INPT1; bmi (paddle ROMS too) + { 0xa4, 0x09, 0x30 }, // ldy INPT1; bmi (Genesis only) + { 0xa6, 0x09, 0x30 }, // ldx INPT1; bmi (Genesis only) + { 0x24, 0x39, 0x10 }, // bit INPT1|$30; bpl (keyboard and paddle ROMS too) + { 0x24, 0x39, 0x30 }, // bit INPT1|$30; bmi (keyboard and paddle ROMS too) + { 0xa5, 0x39, 0x10 }, // lda INPT1|$30; bpl (keyboard ROMS too) + { 0xa5, 0x39, 0x30 }, // lda INPT1|$30; bmi (keyboard and paddle ROMS too) + { 0xa5, 0x39, 0x6a }, // lda INPT1|$30; ror (Genesis only) + { 0xa6, 0x39, 0x8e }, // ldx INPT1|$30; stx (Genesis only) + { 0xa5, 0x09, 0x29 }, // lda INPT1; and (Genesis only) }; for(uInt32 i = 0; i < NUM_SIGS_0; ++i) if(searchForBytes(image, size, signature_0[i], SIG_SIZE_0)) @@ -228,6 +232,7 @@ bool ControllerDetector::usesGenesisButton(const uInt8* image, uInt32 size, Cont } else if(port == Controller::Right) { + // check for INPT3 access const int NUM_SIGS_0 = 9; const int SIG_SIZE_0 = 3; uInt8 signature_0[NUM_SIGS_0][SIG_SIZE_0] = { @@ -254,6 +259,7 @@ bool ControllerDetector::usesPaddle(const uInt8* image, uInt32 size, { if(port == Controller::Left) { + // check for INPT0 access const int NUM_SIGS_0 = 13; const int SIG_SIZE_0 = 3; uInt8 signature_0[NUM_SIGS_0][SIG_SIZE_0] = { @@ -304,6 +310,7 @@ bool ControllerDetector::usesPaddle(const uInt8* image, uInt32 size, } else if(port == Controller::Right) { + // check for INPT2 and indexed INPT0 access const int NUM_SIGS_0 = 17; const int SIG_SIZE_0 = 3; uInt8 signature_0[NUM_SIGS_0][SIG_SIZE_0] = { @@ -357,6 +364,7 @@ bool ControllerDetector::usesPaddle(const uInt8* image, uInt32 size, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool ControllerDetector::isProbablyTrakBall(const uInt8* image, uInt32 size) { + // check for TrakBall table const int NUM_SIGS = 1; const int SIG_SIZE = 8; uInt8 signature[SIG_SIZE] = { @@ -373,6 +381,7 @@ bool ControllerDetector::isProbablyTrakBall(const uInt8* image, uInt32 size) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool ControllerDetector::isProbablyAtariMouse(const uInt8* image, uInt32 size) { + // check for Atari Mouse table const int SIG_SIZE = 8; uInt8 signature[SIG_SIZE] = { 0b0101, 0b0111, 0b0100, 0b0110, 0b1101, 0b1111, 0b1100, 0b1110 // NextTrackTbl @@ -388,6 +397,7 @@ bool ControllerDetector::isProbablyAtariMouse(const uInt8* image, uInt32 size) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool ControllerDetector::isProbablyAmigaMouse(const uInt8* image, uInt32 size) { + // check for Amiga Mouse table const int SIG_SIZE = 8; uInt8 signature[SIG_SIZE] = { 0b1100, 0b1000, 0b0100, 0b0000, 0b1101, 0b1001, 0b0101, 0b0001 // NextTrackTbl @@ -403,18 +413,43 @@ bool ControllerDetector::isProbablyAmigaMouse(const uInt8* image, uInt32 size) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool ControllerDetector::isProbablySaveKey(const uInt8* image, uInt32 size, Controller::Jack port) { - // known SaveKey code only supports right port + // check for known SaveKey code, only supports right port if(port == Controller::Right) { + const int NUM_SIGS = 4; const int SIG_SIZE = 9; - uInt8 signature[SIG_SIZE] = { // from I2C_TXNACK - 0xa9, 0x10, // lda #I2C_SCL_MASK*2 - 0x8d, 0x80, 0x02, // sta SWCHA - 0x4a, // lsr - 0x8d, 0x81, 0x02 // sta SWACNT + uInt8 signature[NUM_SIGS][SIG_SIZE] = { + { // from I2C_START (i2c.inc) + 0xa9, 0x08, // lda #I2C_SCL_MASK + 0x8d, 0x80, 0x02, // sta SWCHA + 0xa9, 0x0c, // lda #I2C_SCL_MASK|I2C_SDA_MASK + 0x8d, 0x81 // sta SWACNT + }, + { // from I2C_START (i2c_v2.1..3.inc) + 0xa9, 0x18, // #(I2C_SCL_MASK|I2C_SDA_MASK)*2 + 0x8d, 0x80, 0x02, // sta SWCHA + 0x4a, // lsr + 0x8d, 0x81, 0x02 // sta SWACNT + }, + { // from I2C_START (Strat-O-Gems) + 0xa2, 0x08, // ldx #I2C_SCL_MASK + 0x8e, 0x80, 0x02, // stx SWCHA + 0xa2, 0x0c, // ldx #I2C_SCL_MASK|I2C_SDA_MASK + 0x8e, 0x81 // stx SWACNT + }, + { // from I2C_START (AStar, Fall Down, Go Fish!) + 0xa9, 0x08, // lda #I2C_SCL_MASK + 0x8d, 0x80, 0x02, // sta SWCHA + 0xea, // nop + 0xa9, 0x0c, // lda #I2C_SCL_MASK|I2C_SDA_MASK + 0x8d // sta SWACNT + }, + }; - return (searchForBytes(image, size, signature, SIG_SIZE)); + for(uInt32 i = 0; i < NUM_SIGS; ++i) + if(searchForBytes(image, size, signature[i], SIG_SIZE)) + return true; } return false; diff --git a/src/emucore/ControllerDetector.hxx b/src/emucore/ControllerDetector.hxx index fbca382ab..a7144ac13 100644 --- a/src/emucore/ControllerDetector.hxx +++ b/src/emucore/ControllerDetector.hxx @@ -19,29 +19,25 @@ #ifndef CONTROLLER_DETECTOR_HXX #define CONTROLLER_DETECTOR_HXX -class Cartridge; -class Properties; -class OSystem; - -class FilesystemNode; - -//#include "Bankswitch.hxx" - #include "Control.hxx" -#include "bspf.hxx" + +/** + Auto-detect controller type by matching determining pattern. + + @author Thomas Jentzsch +*/ class ControllerDetector { public: /** - Create a new cartridge object allocated on the heap. The - type of cartridge created depends on the properties object. + Detects the controller at the given port if no controller is provided. @param image A pointer to the ROM image @param size The size of the ROM image - @param controller The provided left controller type of the ROM image + @param controller The provided controller type of the ROM image @param port The port to be checked - @param osystem The osystem associated with the system + @param settings A reference to the various settings (read-only) @return The detected controller name */ static string detect(const uInt8* image, uInt32 size, @@ -49,42 +45,51 @@ class ControllerDetector const Settings& settings); private: + /** + Detects the controller at the given port. + + @param image A pointer to the ROM image + @param size The size of the ROM image + @param port The port to be checked + @param settings A reference to the various settings (read-only) + @return The detected controller name + */ static string autodetectPort(const uInt8* image, uInt32 size, Controller::Jack port, const Settings& settings); /** - Search the image for the specified byte signature + 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 - @param minhits The minimum number of times a signature is to be found - @return True if the signature was found at least 'minhits' time, else false + @return True if the signature was found, else false */ static bool searchForBytes(const uInt8* image, uInt32 imagesize, const uInt8* signature, uInt32 sigsize); - // Returns true if the port's joystick button access code is found + // Returns true if the port's joystick button access code is found. static bool usesJoystickButton(const uInt8* image, uInt32 size, Controller::Jack port); + // Returns true if the port's 2nd Genesis button access code is found. static bool usesGenesisButton(const uInt8* image, uInt32 size, Controller::Jack port); - // Returns true if the port's paddle button access code is found + // Returns true if the port's paddle button access code is found. static bool usesPaddle(const uInt8* image, uInt32 size, Controller::Jack port, const Settings& settings); - // Returns true if Trak-Ball table is found + // Returns true if Trak-Ball table is found. static bool isProbablyTrakBall(const uInt8* image, uInt32 size); - // Returns true if Atari Mouse table is found + // Returns true if Atari Mouse table is found. static bool isProbablyAtariMouse(const uInt8* image, uInt32 size); - // Returns true if Amiga Mouse table is found + // Returns true if Amiga Mouse table is found. static bool isProbablyAmigaMouse(const uInt8* image, uInt32 size); - // Returns true if the SaveKey code pattern is found + // Returns true if the SaveKey code pattern is found. static bool isProbablySaveKey(const uInt8* image, uInt32 size, Controller::Jack port); private: diff --git a/src/gui/GameInfoDialog.cxx b/src/gui/GameInfoDialog.cxx index 275031952..6007a13f5 100644 --- a/src/gui/GameInfoDialog.cxx +++ b/src/gui/GameInfoDialog.cxx @@ -90,7 +90,7 @@ GameInfoDialog::GameInfoDialog( ypos += lineHeight + VGAP; myTypeDetected = new StaticTextWidget(myTab, ifont, t->getRight() + 8, ypos, - "(CM (SpectraVideo CompuMate) detected)"); + "CM (SpectraVideo CompuMate) detected"); ypos += ifont.getLineHeight() + VGAP * 4; pwidth = font.getStringWidth("Auto-detect");