Skip to content

Commit

Permalink
improved QuadTari auto detection and setup
Browse files Browse the repository at this point in the history
  • Loading branch information
thrust26 committed May 7, 2024
1 parent c713f4f commit 4aba8a1
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 46 deletions.
4 changes: 4 additions & 0 deletions Changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 7 additions & 6 deletions src/common/PJoystickHandler.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/common/PJoystickHandler.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
11 changes: 6 additions & 5 deletions src/common/PKeyboardHandler.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/common/PKeyboardHandler.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
40 changes: 25 additions & 15 deletions src/emucore/Console.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1005,8 +1005,11 @@ unique_ptr<Controller> Console::getControllerPort(
{
unique_ptr<Controller> 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)
{
Expand Down Expand Up @@ -1061,11 +1064,11 @@ unique_ptr<Controller> 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<AtariVox>(port, myEvent, *mySystem,
myOSystem.settings().getString("avoxport"), nvramfile, callback);
break;
Expand All @@ -1076,11 +1079,11 @@ unique_ptr<Controller> 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<SaveKey>(port, myEvent, *mySystem, nvramfile, callback);
break;
}
Expand All @@ -1095,7 +1098,7 @@ unique_ptr<Controller> 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<KidVid>
(port, myEvent, myOSystem, *mySystem, romMd5, callback);
break;
Expand All @@ -1111,9 +1114,16 @@ unique_ptr<Controller> Console::getControllerPort(
break;

case Controller::Type::QuadTari:
controller = make_unique<QuadTari>(port, myOSystem, *mySystem, myProperties, *myCart);
break;
{
unique_ptr<QuadTari> quadTari = make_unique<QuadTari>(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<Joy2BPlus>(port, myEvent, *mySystem);
break;
Expand Down
5 changes: 3 additions & 2 deletions src/emucore/ControllerDetector.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
12 changes: 8 additions & 4 deletions src/emucore/EventHandler.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand Down
27 changes: 15 additions & 12 deletions src/gui/QuadTariDialog.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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())
Expand All @@ -179,15 +179,18 @@ void QuadTariDialog::defineController(const Properties& props, PropType key,
{
if(instance().hasConsole())
{
const QuadTari* qt = dynamic_cast<QuadTari*>(
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<QuadTari*>(&controller);
label = (first
? qt->firstController().name()
: qt->secondController().name())
+ " detected";
+ " detected";
}
else
label = "nothing detected";
}
Expand Down

0 comments on commit 4aba8a1

Please sign in to comment.