From 4aba8a19558454060a583023d27266bcf96efd4d Mon Sep 17 00:00:00 2001 From: thrust26 Date: Tue, 7 May 2024 17:14:40 +0200 Subject: [PATCH] improved QuadTari auto detection and setup --- Changes.txt | 4 +++ src/common/PJoystickHandler.cxx | 13 +++++----- src/common/PJoystickHandler.hxx | 4 ++- src/common/PKeyboardHandler.cxx | 11 ++++---- src/common/PKeyboardHandler.hxx | 4 ++- src/emucore/Console.cxx | 40 +++++++++++++++++++----------- src/emucore/ControllerDetector.cxx | 5 ++-- src/emucore/EventHandler.hxx | 12 ++++++--- src/gui/QuadTariDialog.cxx | 27 +++++++++++--------- 9 files changed, 74 insertions(+), 46 deletions(-) diff --git a/Changes.txt b/Changes.txt index 87e470ba5..ec3e29084 100644 --- a/Changes.txt +++ b/Changes.txt @@ -34,12 +34,16 @@ * Added Joy2B+ controller support. + * Added auto detection for QuadTari attached controllers + * Enhanced Kid Vid support to play tape audio. * Added port selection, used for controller default mapping. * Added missing PlusROM support for E7 bankswitching. + * Enhanced movie cart (MVC) support + * Accelerated emulation up to ~15% (ARM). * Added limited GameLine Master Module bankswitching support. diff --git a/src/common/PJoystickHandler.cxx b/src/common/PJoystickHandler.cxx index 7ee5532c4..7fd5e8eb2 100644 --- a/src/common/PJoystickHandler.cxx +++ b/src/common/PJoystickHandler.cxx @@ -500,21 +500,22 @@ void PhysicalJoystickHandler::setDefaultMapping(Event::Type event, EventMode mod } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void PhysicalJoystickHandler::defineControllerMappings(const Controller::Type type, Controller::Jack port, - const Properties& properties) +void PhysicalJoystickHandler::defineControllerMappings( + const Controller::Type type, Controller::Jack port, const Properties& properties, + Controller::Type qtType1, Controller::Type qtType2) { // Determine controller events to use if(type == Controller::Type::QuadTari) { if(port == Controller::Jack::Left) { - myLeftMode = getMode(properties, PropType::Controller_Left1); - myLeft2ndMode = getMode(properties, PropType::Controller_Left2); + myLeftMode = getMode(qtType1); + myLeft2ndMode = getMode(qtType2); } else { - myRightMode = getMode(properties, PropType::Controller_Right1); - myRight2ndMode = getMode(properties, PropType::Controller_Right2); + myRightMode = getMode(qtType1); + myRight2ndMode = getMode(qtType2); } } else diff --git a/src/common/PJoystickHandler.hxx b/src/common/PJoystickHandler.hxx index cea47dddd..a151d8c8e 100644 --- a/src/common/PJoystickHandler.hxx +++ b/src/common/PJoystickHandler.hxx @@ -93,7 +93,9 @@ class PhysicalJoystickHandler /** define mappings for current controllers */ void defineControllerMappings(const Controller::Type type, Controller::Jack port, - const Properties& properties); + const Properties& properties, + Controller::Type qtType1 = Controller::Type::Unknown, + Controller::Type qtType2 = Controller::Type::Unknown); /** enable mappings for emulation mode */ void enableEmulationMappings(); diff --git a/src/common/PKeyboardHandler.cxx b/src/common/PKeyboardHandler.cxx index 0b171ed36..f4effceae 100644 --- a/src/common/PKeyboardHandler.cxx +++ b/src/common/PKeyboardHandler.cxx @@ -235,20 +235,21 @@ void PhysicalKeyboardHandler::setDefaultMapping(Event::Type event, EventMode mod // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void PhysicalKeyboardHandler::defineControllerMappings( - const Controller::Type type, Controller::Jack port, const Properties& properties) + const Controller::Type type, Controller::Jack port, const Properties& properties, + Controller::Type qtType1, Controller::Type qtType2) { // Determine controller events to use if(type == Controller::Type::QuadTari) { if(port == Controller::Jack::Left) { - myLeftMode = getMode(properties, PropType::Controller_Left1); - myLeft2ndMode = getMode(properties, PropType::Controller_Left2); + myLeftMode = getMode(qtType1); + myLeft2ndMode = getMode(qtType2); } else { - myRightMode = getMode(properties, PropType::Controller_Right1); - myRight2ndMode = getMode(properties, PropType::Controller_Right2); + myRightMode = getMode(qtType1); + myRight2ndMode = getMode(qtType2); } } else diff --git a/src/common/PKeyboardHandler.hxx b/src/common/PKeyboardHandler.hxx index 2b3969afe..b50e3fcce 100644 --- a/src/common/PKeyboardHandler.hxx +++ b/src/common/PKeyboardHandler.hxx @@ -54,7 +54,9 @@ class PhysicalKeyboardHandler /** define mappings for current controllers */ void defineControllerMappings(const Controller::Type type, Controller::Jack port, - const Properties& properties); + const Properties& properties, + Controller::Type qtType1 = Controller::Type::Unknown, + Controller::Type qtType2 = Controller::Type::Unknown); /** enable mappings for emulation mode */ void enableEmulationMappings(); diff --git a/src/emucore/Console.cxx b/src/emucore/Console.cxx index dd2e456fd..cc7b636bc 100644 --- a/src/emucore/Console.cxx +++ b/src/emucore/Console.cxx @@ -1005,8 +1005,11 @@ unique_ptr Console::getControllerPort( { unique_ptr controller; - myOSystem.eventHandler().defineKeyControllerMappings(type, port, myProperties); - myOSystem.eventHandler().defineJoyControllerMappings(type, port, myProperties); + if(type != Controller::Type::QuadTari) + { + myOSystem.eventHandler().defineKeyControllerMappings(type, port, myProperties); + myOSystem.eventHandler().defineJoyControllerMappings(type, port, myProperties); + } switch(type) { @@ -1061,11 +1064,11 @@ unique_ptr Console::getControllerPort( nvramfile /= "atarivox_eeprom.dat"; const Controller::onMessageCallback callback = [&os = myOSystem] (string_view msg) - { - const bool devSettings = os.settings().getBool("dev.settings"); - if(os.settings().getBool(devSettings ? "dev.extaccess" : "plr.extaccess")) - os.frameBuffer().showTextMessage(msg); - }; + { + const bool devSettings = os.settings().getBool("dev.settings"); + if(os.settings().getBool(devSettings ? "dev.extaccess" : "plr.extaccess")) + os.frameBuffer().showTextMessage(msg); + }; controller = make_unique(port, myEvent, *mySystem, myOSystem.settings().getString("avoxport"), nvramfile, callback); break; @@ -1076,11 +1079,11 @@ unique_ptr Console::getControllerPort( nvramfile /= "savekey_eeprom.dat"; const Controller::onMessageCallback callback = [&os = myOSystem] (string_view msg) - { - const bool devSettings = os.settings().getBool("dev.settings"); - if(os.settings().getBool(devSettings ? "dev.extaccess" : "plr.extaccess")) - os.frameBuffer().showTextMessage(msg); - }; + { + const bool devSettings = os.settings().getBool("dev.settings"); + if(os.settings().getBool(devSettings ? "dev.extaccess" : "plr.extaccess")) + os.frameBuffer().showTextMessage(msg); + }; controller = make_unique(port, myEvent, *mySystem, nvramfile, callback); break; } @@ -1095,7 +1098,7 @@ unique_ptr Console::getControllerPort( const bool devSettings = os.settings().getBool("dev.settings"); if(force || os.settings().getBool(devSettings ? "dev.extaccess" : "plr.extaccess")) os.frameBuffer().showTextMessage(msg); - }; + }; controller = make_unique (port, myEvent, myOSystem, *mySystem, romMd5, callback); break; @@ -1111,9 +1114,16 @@ unique_ptr Console::getControllerPort( break; case Controller::Type::QuadTari: - controller = make_unique(port, myOSystem, *mySystem, myProperties, *myCart); - break; + { + unique_ptr quadTari = make_unique(port, myOSystem, *mySystem, myProperties, *myCart); + myOSystem.eventHandler().defineKeyControllerMappings(type, port, myProperties, + quadTari->firstController().type(), quadTari->secondController().type()); + myOSystem.eventHandler().defineJoyControllerMappings(type, port, myProperties, + quadTari->firstController().type(), quadTari->secondController().type()); + controller = std::move(quadTari); + break; + } case Controller::Type::Joy2BPlus: controller = make_unique(port, myEvent, *mySystem); break; diff --git a/src/emucore/ControllerDetector.cxx b/src/emucore/ControllerDetector.cxx index 2f750996b..eef68ed97 100644 --- a/src/emucore/ControllerDetector.cxx +++ b/src/emucore/ControllerDetector.cxx @@ -737,10 +737,11 @@ bool ControllerDetector::isProbablyQuadTari(const ByteBuffer& image, size_t size Controller::Jack port) { { - static constexpr int NUM_SIGS = 2; + static constexpr int NUM_SIGS = 3; static constexpr int SIG_SIZE = 8; static constexpr uInt8 signatureBoth[NUM_SIGS][SIG_SIZE] = { - { 0x1B, 0x1F, 0x0B, 0x0E, 0x1E, 0x0B, 0x1C, 0x13 }, + { 0x1B, 0x1F, 0x0B, 0x0E, 0x1E, 0x0B, 0x1C, 0x13 }, // Champ Games + { 0x1c, 0x20, 0x0C, 0x0F, 0x1F, 0x0C, 0x1D, 0x14 }, // RobotWar-2684 { 'Q', 'U', 'A', 'D', 'T', 'A', 'R', 'I' } }; // "QUADTARI" diff --git a/src/emucore/EventHandler.hxx b/src/emucore/EventHandler.hxx index f81b9cb1e..97991e1b7 100644 --- a/src/emucore/EventHandler.hxx +++ b/src/emucore/EventHandler.hxx @@ -231,8 +231,10 @@ class EventHandler Enable controller specific keyboard event mappings. */ void defineKeyControllerMappings(const Controller::Type type, Controller::Jack port, - const Properties& properties) { - myPKeyHandler->defineControllerMappings(type, port, properties); + const Properties& properties, + Controller::Type qtType1 = Controller::Type::Unknown, + Controller::Type qtType2 = Controller::Type::Unknown) { + myPKeyHandler->defineControllerMappings(type, port, properties, qtType1, qtType2); } /** @@ -283,8 +285,10 @@ class EventHandler Enable controller specific keyboard event mappings. */ void defineJoyControllerMappings(const Controller::Type type, Controller::Jack port, - const Properties& properties) { - myPJoyHandler->defineControllerMappings(type, port, properties); + const Properties& properties, + Controller::Type qtType1 = Controller::Type::Unknown, + Controller::Type qtType2 = Controller::Type::Unknown) { + myPJoyHandler->defineControllerMappings(type, port, properties, qtType1, qtType2); } /** diff --git a/src/gui/QuadTariDialog.cxx b/src/gui/QuadTariDialog.cxx index cd83b238f..06afe9d20 100644 --- a/src/gui/QuadTariDialog.cxx +++ b/src/gui/QuadTariDialog.cxx @@ -78,7 +78,7 @@ QuadTariDialog::QuadTariDialog(GuiObject* boss, const GUI::Font& font, int max_w ypos += lineHeight + VGAP; myLeft1PortDetected = new StaticTextWidget(this, ifont, - myLeft1Port->getLeft() + fontWidth * 3, ypos, "AtariVox detected"); + myLeft1Port->getLeft() + fontWidth * 3, ypos, " "); ypos += lineHeight + VGAP; myLeft2Port = new PopUpWidget(this, font, xpos, ypos, @@ -87,7 +87,7 @@ QuadTariDialog::QuadTariDialog(GuiObject* boss, const GUI::Font& font, int max_w ypos += lineHeight + VGAP; myLeft2PortDetected = new StaticTextWidget(this, ifont, - myLeft2Port->getLeft() + fontWidth * 3, ypos, "AtariVox detected"); + myLeft2Port->getLeft() + fontWidth * 3, ypos, " "); xpos = _w - HBORDER - myLeft1Port->getWidth(); // aligned right ypos = myLeftPortLabel->getTop() - 1; @@ -100,7 +100,7 @@ QuadTariDialog::QuadTariDialog(GuiObject* boss, const GUI::Font& font, int max_w ypos += lineHeight + VGAP; myRight1PortDetected = new StaticTextWidget(this, ifont, - myRight1Port->getLeft() + fontWidth * 3, ypos, "AtariVox detected"); + myRight1Port->getLeft() + fontWidth * 3, ypos, " "); ypos += lineHeight + VGAP; //ypos += lineHeight + VGAP * 2; @@ -110,7 +110,7 @@ QuadTariDialog::QuadTariDialog(GuiObject* boss, const GUI::Font& font, int max_w ypos += lineHeight + VGAP; myRight2PortDetected = new StaticTextWidget(this, ifont, - myRight2Port->getLeft() + fontWidth * 3, ypos, "AtariVox detected"); + myRight2Port->getLeft() + fontWidth * 3, ypos, " "); addDefaultsOKCancelBGroup(wid, _font); addBGroupToFocusList(wid); @@ -160,8 +160,8 @@ void QuadTariDialog::defineController(const Properties& props, PropType key, ByteBuffer image; size_t size = 0; - string controller = props.get(key); - popupWidget->setSelected(controller, "AUTO"); + string controllerName = props.get(key); + popupWidget->setSelected(controllerName, "AUTO"); // try to load the image for auto detection if(!instance().hasConsole()) @@ -179,15 +179,18 @@ void QuadTariDialog::defineController(const Properties& props, PropType key, { if(instance().hasConsole()) { - const QuadTari* qt = dynamic_cast( - jack == Controller::Jack::Left - ? &instance().console().leftController() - : &instance().console().rightController()); - if(qt != nullptr) + Controller& controller = (jack == Controller::Jack::Left + ? instance().console().leftController() + : instance().console().rightController()); + + if(BSPF::startsWithIgnoreCase(controller.name(), "QT")) + { + const QuadTari* qt = static_cast(&controller); label = (first ? qt->firstController().name() : qt->secondController().name()) - + " detected"; + + " detected"; + } else label = "nothing detected"; }