diff --git a/src/emucore/Console.cxx b/src/emucore/Console.cxx index de4baaf35..af6eb3c7d 100644 --- a/src/emucore/Console.cxx +++ b/src/emucore/Console.cxx @@ -683,7 +683,7 @@ void Console::setTIAProperties() void Console::setControllers(const string& rommd5) { // Setup the controllers based on properties - const string& left = myProperties.get(Controller_Left); + const string& left = myProperties.get(Controller_Left); const string& right = myProperties.get(Controller_Right); // Check for CompuMate controllers; they are special in that a handler @@ -699,155 +699,111 @@ void Console::setControllers(const string& rommd5) cartcm->setCompuMate(myCMHandler); myCart = std::move(cartcm); - myLeftControl = std::move(myCMHandler->leftController()); + myLeftControl = std::move(myCMHandler->leftController()); myRightControl = std::move(myCMHandler->rightController()); return; } - unique_ptr leftC = std::move(myLeftControl), - rightC = std::move(myRightControl); - - // Also check if we should swap the paddles plugged into a jack - bool swapPaddles = myProperties.get(Controller_SwapPaddles) == "YES"; - - // Construct left controller - if(left == "JOYSTICK") - { - // Already created in c'tor - // We save some time by not looking at all the other types - if(!leftC) - leftC = make_unique(Controller::Left, myEvent, *mySystem); - } - else if(left == "BOOSTERGRIP") - { - leftC = make_unique(Controller::Left, myEvent, *mySystem); - } - else if(left == "DRIVING") - { - leftC = make_unique(Controller::Left, myEvent, *mySystem); - } - else if((left == "KEYBOARD") || (left == "KEYPAD")) - { - leftC = make_unique(Controller::Left, myEvent, *mySystem); - } - else if(BSPF::startsWithIgnoreCase(left, "PADDLES")) - { - bool swapAxis = false, swapDir = false; - if(left == "PADDLES_IAXIS") - swapAxis = true; - else if(left == "PADDLES_IDIR") - swapDir = true; - else if(left == "PADDLES_IAXDR") - swapAxis = swapDir = true; - leftC = make_unique(Controller::Left, myEvent, *mySystem, - swapPaddles, swapAxis, swapDir); - } - else if(left == "AMIGAMOUSE") - { - leftC = make_unique(Controller::Left, myEvent, *mySystem); - } - else if(left == "ATARIMOUSE") - { - leftC = make_unique(Controller::Left, myEvent, *mySystem); - } - else if(left == "TRAKBALL") - { - leftC = make_unique(Controller::Left, myEvent, *mySystem); - } - else if(left == "GENESIS") - { - leftC = make_unique(Controller::Left, myEvent, *mySystem); - } - else if(left == "MINDLINK") - { - leftC = make_unique(Controller::Left, myEvent, *mySystem); - } - - // Construct right controller - if(right == "JOYSTICK") - { - // Already created in c'tor - // We save some time by not looking at all the other types - if(!rightC) - rightC = make_unique(Controller::Right, myEvent, *mySystem); - } - else if(right == "BOOSTERGRIP") - { - rightC = make_unique(Controller::Right, myEvent, *mySystem); - } - else if(right == "DRIVING") - { - rightC = make_unique(Controller::Right, myEvent, *mySystem); - } - else if((right == "KEYBOARD") || (right == "KEYPAD")) - { - rightC = make_unique(Controller::Right, myEvent, *mySystem); - } - else if(BSPF::startsWithIgnoreCase(right, "PADDLES")) - { - bool swapAxis = false, swapDir = false; - if(right == "PADDLES_IAXIS") - swapAxis = true; - else if(right == "PADDLES_IDIR") - swapDir = true; - else if(right == "PADDLES_IAXDR") - swapAxis = swapDir = true; - rightC = make_unique(Controller::Right, myEvent, *mySystem, - swapPaddles, swapAxis, swapDir); - } - else if(left == "AMIGAMOUSE") - { - rightC = make_unique(Controller::Left, myEvent, *mySystem); - } - else if(left == "ATARIMOUSE") - { - rightC = make_unique(Controller::Left, myEvent, *mySystem); - } - else if(left == "TRAKBALL") - { - rightC = make_unique(Controller::Left, myEvent, *mySystem); - } - else if(right == "ATARIVOX") - { - const string& nvramfile = myOSystem.nvramDir() + "atarivox_eeprom.dat"; - rightC = make_unique(Controller::Right, myEvent, - *mySystem, myOSystem.serialPort(), - myOSystem.settings().getString("avoxport"), nvramfile); - } - else if(right == "SAVEKEY") - { - const string& nvramfile = myOSystem.nvramDir() + "savekey_eeprom.dat"; - rightC = make_unique(Controller::Right, myEvent, *mySystem, - nvramfile); - } - else if(right == "GENESIS") - { - rightC = make_unique(Controller::Right, myEvent, *mySystem); - } - else if(right == "KIDVID") - { - rightC = make_unique(Controller::Right, myEvent, *mySystem, rommd5); - } - else if(right == "MINDLINK") - { - rightC = make_unique(Controller::Right, myEvent, *mySystem); - } + unique_ptr leftC = std::move(myLeftControl), + rightC = std::move(myRightControl); + + leftC = getControllerPort(rommd5, left, Controller::Left); + rightC = getControllerPort(rommd5, right, Controller::Right); // Swap the ports if necessary - if(myProperties.get(Console_SwapPorts) == "NO") + if(myProperties.get(Console_SwapPorts) == "NO") { - myLeftControl = std::move(leftC); + myLeftControl = std::move(leftC); myRightControl = std::move(rightC); } - else + else { - myLeftControl = std::move(rightC); + myLeftControl = std::move(rightC); myRightControl = std::move(leftC); } myTIA->bindToControllers(); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +unique_ptr Console::getControllerPort(const string& rommd5, string controllerName, Controller::Jack port) +{ + unique_ptr controller = std::move(myLeftControl); + + if(controllerName == "JOYSTICK") + { + // Already created in c'tor + // We save some time by not looking at all the other types + if(!controller) + controller = make_unique(port, myEvent, *mySystem); + } + else if(controllerName == "BOOSTERGRIP") + { + controller = make_unique(port, myEvent, *mySystem); + } + else if(controllerName == "DRIVING") + { + controller = make_unique(port, myEvent, *mySystem); + } + else if((controllerName == "KEYBOARD") || (controllerName == "KEYPAD")) + { + controller = make_unique(port, myEvent, *mySystem); + } + else if(BSPF::startsWithIgnoreCase(controllerName, "PADDLES")) + { + // Also check if we should swap the paddles plugged into a jack + bool swapPaddles = myProperties.get(Controller_SwapPaddles) == "YES"; + bool swapAxis = false, swapDir = false; + if(controllerName == "PADDLES_IAXIS") + swapAxis = true; + else if(controllerName == "PADDLES_IDIR") + swapDir = true; + else if(controllerName == "PADDLES_IAXDR") + swapAxis = swapDir = true; + controller = make_unique(port, myEvent, *mySystem, + swapPaddles, swapAxis, swapDir); + } + else if(controllerName == "AMIGAMOUSE") + { + controller = make_unique(port, myEvent, *mySystem); + } + else if(controllerName == "ATARIMOUSE") + { + controller = make_unique(port, myEvent, *mySystem); + } + else if(controllerName == "TRAKBALL") + { + controller = make_unique(port, myEvent, *mySystem); + } + else if(controllerName == "ATARIVOX") + { + const string& nvramfile = myOSystem.nvramDir() + "atarivox_eeprom.dat"; + controller = make_unique(port, myEvent, + *mySystem, myOSystem.serialPort(), + myOSystem.settings().getString("avoxport"), nvramfile); + } + else if(controllerName == "SAVEKEY") + { + const string& nvramfile = myOSystem.nvramDir() + "savekey_eeprom.dat"; + controller = make_unique(port, myEvent, *mySystem, + nvramfile); + } + else if(controllerName == "GENESIS") + { + controller = make_unique(port, myEvent, *mySystem); + } + else if(controllerName == "KIDVID") + { + controller = make_unique(port, myEvent, *mySystem, rommd5); + } + else if(controllerName == "MINDLINK") + { + controller = make_unique(port, myEvent, *mySystem); + } + + return controller; +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Console::loadUserPalette() { diff --git a/src/emucore/Console.hxx b/src/emucore/Console.hxx index 65855e682..d8c799799 100644 --- a/src/emucore/Console.hxx +++ b/src/emucore/Console.hxx @@ -315,6 +315,11 @@ class Console : public Serializable */ void setControllers(const string& rommd5); + /** + Selects the left or right controller depending on ROM properties + */ + unique_ptr getControllerPort(const string& rommd5, string controllerName, Controller::Jack port); + /** Loads a user-defined palette file (from OSystem::paletteFile), filling the appropriate user-defined palette arrays.