| 1 | //============================================================================ |
| 2 | // |
| 3 | // SSSS tt lll lll |
| 4 | // SS SS tt ll ll |
| 5 | // SS tttttt eeee ll ll aaaa |
| 6 | // SSSS tt ee ee ll ll aa |
| 7 | // SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" |
| 8 | // SS SS tt ee ll ll aa aa |
| 9 | // SSSS ttt eeeee llll llll aaaaa |
| 10 | // |
| 11 | // Copyright (c) 1995-2019 by Bradford W. Mott, Stephen Anthony |
| 12 | // and the Stella Team |
| 13 | // |
| 14 | // See the file "License.txt" for information on usage and redistribution of |
| 15 | // this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 16 | //============================================================================ |
| 17 | |
| 18 | #ifndef CONTROLLER_DETECTOR_HXX |
| 19 | #define CONTROLLER_DETECTOR_HXX |
| 20 | |
| 21 | #include "Control.hxx" |
| 22 | |
| 23 | /** |
| 24 | Auto-detect controller type by matching determining pattern. |
| 25 | |
| 26 | @author Thomas Jentzsch |
| 27 | */ |
| 28 | |
| 29 | class ControllerDetector |
| 30 | { |
| 31 | public: |
| 32 | /** |
| 33 | Detects the controller type at the given port if no controller is provided. |
| 34 | |
| 35 | @param image A pointer to the ROM image |
| 36 | @param size The size of the ROM image |
| 37 | @param controller The provided controller type of the ROM image |
| 38 | @param port The port to be checked |
| 39 | @param settings A reference to the various settings (read-only) |
| 40 | @return The detected controller type |
| 41 | */ |
| 42 | static Controller::Type detectType(const uInt8* image, size_t size, |
| 43 | const Controller::Type controller, const Controller::Jack port, |
| 44 | const Settings& settings); |
| 45 | |
| 46 | /** |
| 47 | Detects the controller type at the given port if no controller is provided |
| 48 | and returns its name. |
| 49 | |
| 50 | @param image A pointer to the ROM image |
| 51 | @param size The size of the ROM image |
| 52 | @param type The provided controller type of the ROM image |
| 53 | @param port The port to be checked |
| 54 | @param settings A reference to the various settings (read-only) |
| 55 | |
| 56 | @return The (detected) controller name |
| 57 | */ |
| 58 | static string detectName(const uInt8* image, size_t size, |
| 59 | const Controller::Type type, const Controller::Jack port, |
| 60 | const Settings& settings); |
| 61 | |
| 62 | private: |
| 63 | /** |
| 64 | Detects the controller type at the given port. |
| 65 | |
| 66 | @param image A pointer to the ROM image |
| 67 | @param size The size of the ROM image |
| 68 | @param port The port to be checked |
| 69 | @param settings A reference to the various settings (read-only) |
| 70 | |
| 71 | @return The detected controller type |
| 72 | */ |
| 73 | static Controller::Type autodetectPort(const uInt8* image, size_t size, |
| 74 | Controller::Jack port, const Settings& settings); |
| 75 | |
| 76 | /** |
| 77 | Search the image for the specified byte signature. |
| 78 | |
| 79 | @param image A pointer to the ROM image |
| 80 | @param imagesize The size of the ROM image |
| 81 | @param signature The byte sequence to search for |
| 82 | @param sigsize The number of bytes in the signature |
| 83 | |
| 84 | @return True if the signature was found, else false |
| 85 | */ |
| 86 | static bool searchForBytes(const uInt8* image, size_t imagesize, |
| 87 | const uInt8* signature, uInt32 sigsize); |
| 88 | |
| 89 | // Returns true if the port's joystick button access code is found. |
| 90 | static bool usesJoystickButton(const uInt8* image, size_t size, Controller::Jack port); |
| 91 | |
| 92 | // Returns true if the port's keyboard access code is found. |
| 93 | static bool usesKeyboard(const uInt8* image, size_t size, Controller::Jack port); |
| 94 | |
| 95 | // Returns true if the port's 2nd Genesis button access code is found. |
| 96 | static bool usesGenesisButton(const uInt8* image, size_t size, Controller::Jack port); |
| 97 | |
| 98 | // Returns true if the port's paddle button access code is found. |
| 99 | static bool usesPaddle(const uInt8* image, size_t size, Controller::Jack port, |
| 100 | const Settings& settings); |
| 101 | |
| 102 | // Returns true if a Trak-Ball table is found. |
| 103 | static bool isProbablyTrakBall(const uInt8* image, size_t size); |
| 104 | |
| 105 | // Returns true if an Atari Mouse table is found. |
| 106 | static bool isProbablyAtariMouse(const uInt8* image, size_t size); |
| 107 | |
| 108 | // Returns true if an Amiga Mouse table is found. |
| 109 | static bool isProbablyAmigaMouse(const uInt8* image, size_t size); |
| 110 | |
| 111 | // Returns true if a SaveKey code pattern is found. |
| 112 | static bool isProbablySaveKey(const uInt8* image, size_t size, Controller::Jack port); |
| 113 | |
| 114 | private: |
| 115 | // Following constructors and assignment operators not supported |
| 116 | ControllerDetector() = delete; |
| 117 | ControllerDetector(const ControllerDetector&) = delete; |
| 118 | ControllerDetector(ControllerDetector&&) = delete; |
| 119 | ControllerDetector& operator=(const ControllerDetector&) = delete; |
| 120 | ControllerDetector& operator=(ControllerDetector&&) = delete; |
| 121 | }; |
| 122 | |
| 123 | #endif |
| 124 | |
| 125 | |