diff --git a/src/emucore/Console.cxx b/src/emucore/Console.cxx index 41d9686c2..7df73bac1 100644 --- a/src/emucore/Console.cxx +++ b/src/emucore/Console.cxx @@ -852,12 +852,12 @@ void Console::setControllers(const string& rommd5) // try to detect controllers if(image != nullptr || size != 0) { - left = ControllerDetector::detect(image, size, left, - !swappedPorts ? Controller::Left : Controller::Right, - myOSystem.settings()); - right = ControllerDetector::detect(image, size, right, - !swappedPorts ? Controller::Right : Controller::Left, - myOSystem.settings()); + left = ControllerDetector::detectType(image, size, left, + !swappedPorts ? Controller::Left : Controller::Right, + myOSystem.settings()); + right = ControllerDetector::detectType(image, size, right, + !swappedPorts ? Controller::Right : Controller::Left, + myOSystem.settings()); } unique_ptr leftC = getControllerPort(rommd5, left, Controller::Left), diff --git a/src/emucore/ControllerDetector.cxx b/src/emucore/ControllerDetector.cxx index 37f76ab0b..6054fd19e 100644 --- a/src/emucore/ControllerDetector.cxx +++ b/src/emucore/ControllerDetector.cxx @@ -20,9 +20,9 @@ #include "ControllerDetector.hxx" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -string ControllerDetector::detect(const uInt8* image, uInt32 size, - const string& controller, const Controller::Jack port, - const Settings& settings) +string ControllerDetector::detectType(const uInt8* image, uInt32 size, + const string& controller, const Controller::Jack port, + const Settings& settings) { string type(controller); @@ -41,6 +41,14 @@ string ControllerDetector::detect(const uInt8* image, uInt32 size, return type; } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +string ControllerDetector::detectName(const uInt8* image, uInt32 size, + const string& controller, const Controller::Jack port, + const Settings& settings) +{ + return getControllerName(detectType(image, size, controller, port, settings)); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - string ControllerDetector::autodetectPort(const uInt8* image, uInt32 size, Controller::Jack port, const Settings& settings) @@ -595,3 +603,44 @@ bool ControllerDetector::isProbablySaveKey(const uInt8* image, uInt32 size, Cont return false; } + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +const string ControllerDetector::getControllerName(const string& controller) +{ + // auto detected: + if(BSPF::equalsIgnoreCase(controller, "JOYSTICK")) + return "Joystick"; + if(BSPF::equalsIgnoreCase(controller, "SAVEKEY")) + return "SaveKey"; + if(BSPF::equalsIgnoreCase(controller, "TRAKBALL")) + return "TrakBall"; + if(BSPF::equalsIgnoreCase(controller, "ATARIMOUSE")) + return "AtariMouse"; + if(BSPF::equalsIgnoreCase(controller, "AMIGAMOUSE")) + return "AmigaMouse"; + if(BSPF::equalsIgnoreCase(controller, "KEYBOARD")) + return "Keyboard"; + if(BSPF::equalsIgnoreCase(controller, "GENESIS")) + return "Sega Genesis"; + if(BSPF::equalsIgnoreCase(controller, "PADDLES")) + return "Paddles"; + // not auto detected: + if(BSPF::equalsIgnoreCase(controller, "BOOSTERGRIP")) + return "BoosterGrip"; + if(BSPF::equalsIgnoreCase(controller, "DRIVING")) + return "Driving"; + if(BSPF::equalsIgnoreCase(controller, "MINDLINK")) + return "MindLink"; + if(BSPF::equalsIgnoreCase(controller, "ATARIVOX")) + return "AtariVox"; + if(BSPF::equalsIgnoreCase(controller, "PADDLES_IAXIS")) + return "Paddles IAxis"; + if(BSPF::equalsIgnoreCase(controller, "PADDLES_IAXDR")) + return "Paddles IAxDr"; + if(BSPF::equalsIgnoreCase(controller, "COMPUMATE")) + return "CompuMate"; + if(BSPF::equalsIgnoreCase(controller, "KIDVID")) + return "KidVid"; + + return controller; +} diff --git a/src/emucore/ControllerDetector.hxx b/src/emucore/ControllerDetector.hxx index 1971e1a2f..529ff4de3 100644 --- a/src/emucore/ControllerDetector.hxx +++ b/src/emucore/ControllerDetector.hxx @@ -31,28 +31,54 @@ class ControllerDetector { public: /** - Detects the controller at the given port if no controller is provided. + Detects the controller type 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 controller type 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 + @return The detected controller type */ - static string detect(const uInt8* image, uInt32 size, - const string& controller, const Controller::Jack port, - const Settings& settings); + static string detectType(const uInt8* image, uInt32 size, + const string& controller, const Controller::Jack port, + const Settings& settings); + + /** + Detects the controller type at the given port if no controller is provided + and returns its name. + + @param image A pointer to the ROM image + @param size The size of the ROM image + @param controller The provided controller type 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 detectName(const uInt8* image, uInt32 size, + const string& controller, const Controller::Jack port, + const Settings& settings); + + /** + Returns a nicer formatted name for the given controller. + + @param controller The provided controller type of the ROM image + + @return The controller name + */ + static const string getControllerName(const string& controller); private: /** - Detects the controller at the given port. + Detects the controller type 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 + + @return The detected controller type */ static string autodetectPort(const uInt8* image, uInt32 size, Controller::Jack port, const Settings& settings); diff --git a/src/gui/GameInfoDialog.cxx b/src/gui/GameInfoDialog.cxx index e39f04b89..11cf128ef 100644 --- a/src/gui/GameInfoDialog.cxx +++ b/src/gui/GameInfoDialog.cxx @@ -434,18 +434,12 @@ void GameInfoDialog::loadControllerProperties(const Properties& props) if(myLeftPort->getSelectedTag().toString() == "AUTO") { if(instance().hasConsole()) - { label = (!swapPorts ? instance().console().leftController().name() - : instance().console().rightController().name()) - + " detected"; - } + : instance().console().rightController().name()) + " detected"; else if(autoDetect) - { - controller = ControllerDetector::detect(image.get(), size, controller, - !swapPorts ? Controller::Jack::Left : Controller::Jack::Right, - instance().settings()); - label = getControllerName(controller) + " detected"; - } + label = ControllerDetector::detectName(image.get(), size, controller, + !swapPorts ? Controller::Jack::Left : Controller::Jack::Right, + instance().settings()) + " detected"; } myLeftPortDetected->setLabel(label); @@ -456,18 +450,12 @@ void GameInfoDialog::loadControllerProperties(const Properties& props) if(myRightPort->getSelectedTag().toString() == "AUTO") { if(instance().hasConsole()) - { label = (!swapPorts ? instance().console().rightController().name() - : instance().console().leftController().name()) - + " detected"; - } + : instance().console().leftController().name()) + " detected"; else if(autoDetect) - { - controller = ControllerDetector::detect(image.get(), size, controller, - !swapPorts ? Controller::Jack::Right : Controller::Jack::Left, - instance().settings()); - label = getControllerName(controller) + " detected"; - } + label = ControllerDetector::detectName(image.get(), size, controller, + !swapPorts ? Controller::Jack::Right : Controller::Jack::Left, + instance().settings()) + " detected"; } myRightPortDetected->setLabel(label); @@ -651,29 +639,6 @@ void GameInfoDialog::updateControllerStates() myEraseEEPROMInfo->setEnabled(enableEEEraseButton); } -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -const string GameInfoDialog::getControllerName(const string& type) -{ - if(BSPF::equalsIgnoreCase(type, "JOYSTICK")) - return "Joystick"; - if(BSPF::equalsIgnoreCase(type, "SAVEKEY")) - return "SaveKey"; - if(BSPF::equalsIgnoreCase(type, "TRAKBALL")) - return "TrakBall"; - if(BSPF::equalsIgnoreCase(type, "ATA RIMOUSE")) - return "AtariMouse"; - if(BSPF::equalsIgnoreCase(type, "AMIGAMOUSE")) - return "AmigaMouse"; - if(BSPF::equalsIgnoreCase(type, "KEYBOARD")) - return "Keyboard"; - if(BSPF::equalsIgnoreCase(type, "GENESIS")) - return "Genesis"; - if(BSPF::equalsIgnoreCase(type, "PADDLES")) - return "Paddles"; - - return type; -} - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void GameInfoDialog::eraseEEPROM() { diff --git a/src/gui/GameInfoDialog.hxx b/src/gui/GameInfoDialog.hxx index ebade6d13..c268ab8f1 100644 --- a/src/gui/GameInfoDialog.hxx +++ b/src/gui/GameInfoDialog.hxx @@ -55,7 +55,6 @@ class GameInfoDialog : public Dialog, public CommandSender void loadCartridgeProperties(const Properties& props); void updateControllerStates(); - const string getControllerName(const string& type); void eraseEEPROM(); private: diff --git a/src/gui/RomInfoWidget.cxx b/src/gui/RomInfoWidget.cxx index 154919ab0..40577e135 100644 --- a/src/gui/RomInfoWidget.cxx +++ b/src/gui/RomInfoWidget.cxx @@ -136,12 +136,12 @@ void RomInfoWidget::parseProperties(const FilesystemNode& node) if(node.exists() && !node.isDirectory() && (image = instance().openROM(node, md5, size)) != nullptr) { - left = ControllerDetector::detect(image.get(), size, left, - !swappedPorts ? Controller::Jack::Left : Controller::Jack::Right, - instance().settings()); - right = ControllerDetector::detect(image.get(), size, right, - !swappedPorts ? Controller::Jack::Right : Controller::Jack::Left, - instance().settings()); + left = ControllerDetector::detectName(image.get(), size, left, + !swappedPorts ? Controller::Jack::Left : Controller::Jack::Right, + instance().settings()); + right = ControllerDetector::detectName(image.get(), size, right, + !swappedPorts ? Controller::Jack::Right : Controller::Jack::Left, + instance().settings()); } myRomInfo.push_back("Controllers: " + (left + " (left), " + right + " (right)"));