diff --git a/src/emucore/Console.cxx b/src/emucore/Console.cxx index 3a755f853..54b9276ce 100644 --- a/src/emucore/Console.cxx +++ b/src/emucore/Console.cxx @@ -95,7 +95,7 @@ Console::Console(OSystem& osystem, unique_ptr& cart, myRiot = make_unique(*this, myOSystem.settings()); myTIA = make_unique(*this, myOSystem.sound(), myOSystem.settings()); myFrameManager = make_unique(); - mySwitches = make_unique(myEvent, myProperties); + mySwitches = make_unique(myEvent, myProperties, myOSystem.settings()); myTIA->setFrameManager(myFrameManager.get()); diff --git a/src/emucore/EventHandler.cxx b/src/emucore/EventHandler.cxx index f505096b7..943b3f883 100644 --- a/src/emucore/EventHandler.cxx +++ b/src/emucore/EventHandler.cxx @@ -65,6 +65,7 @@ EventHandler::EventHandler(OSystem& osystem) myFryingFlag(false), myUseCtrlKeyFlag(true), mySkipMouseMotion(true), + myIs7800(false), myAltKeyCounter(0), myContSnapshotInterval(0), myContSnapshotCounter(0) @@ -117,6 +118,9 @@ void EventHandler::initialize() // Default phosphor blend Properties::setDefault(Display_PPBlend, myOSystem.settings().getString("tv.phosblend")); + + // Toggle 7800 mode + set7800Mode(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -192,6 +196,15 @@ void EventHandler::toggleSAPortOrder() #endif } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void EventHandler::set7800Mode() +{ + if(myOSystem.hasConsole()) + myIs7800 = myOSystem.console().switches().toggle7800Mode(myOSystem.settings()); + else + myIs7800 = false; +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void EventHandler::poll(uInt64 time) { @@ -900,9 +913,6 @@ void EventHandler::handleEvent(Event::Type event, int state) { // Take care of special events that aren't part of the emulation core // or need to be preprocessed before passing them on - bool devSettings = myOSystem.settings().getBool("dev.settings"); - bool is7800 = (myOSystem.settings().getString(devSettings ? "dev.console" : "plr.console") == "7800"); - switch(event) { //////////////////////////////////////////////////////////////////////// @@ -1026,21 +1036,21 @@ void EventHandler::handleEvent(Event::Type event, int state) //////////////////////////////////////////////////////////////////////// // Events which relate to switches() case Event::ConsoleColor: - if(state && !is7800) + if(state && !myIs7800) { myEvent.set(Event::ConsoleBlackWhite, 0); myOSystem.frameBuffer().showMessage("Color Mode"); } break; case Event::ConsoleBlackWhite: - if(state && !is7800) + if(state && !myIs7800) { myEvent.set(Event::ConsoleColor, 0); myOSystem.frameBuffer().showMessage("BW Mode"); } break; case Event::ConsoleColorToggle: - if(state && !is7800) + if(state && !myIs7800) { if(myOSystem.console().switches().tvColor()) { @@ -1054,7 +1064,7 @@ void EventHandler::handleEvent(Event::Type event, int state) myEvent.set(Event::ConsoleColor, 1); myOSystem.frameBuffer().showMessage("Color Mode"); } - myOSystem.console().switches().update(myOSystem.settings()); + myOSystem.console().switches().update(); } return; @@ -1087,7 +1097,7 @@ void EventHandler::handleEvent(Event::Type event, int state) myEvent.set(Event::ConsoleLeftDiffB, 0); myOSystem.frameBuffer().showMessage("Left Difficulty A"); } - myOSystem.console().switches().update(myOSystem.settings()); + myOSystem.console().switches().update(); } return; @@ -1120,7 +1130,7 @@ void EventHandler::handleEvent(Event::Type event, int state) myEvent.set(Event::ConsoleRightDiffB, 0); myOSystem.frameBuffer().showMessage("Right Difficulty A"); } - myOSystem.console().switches().update(myOSystem.settings()); + myOSystem.console().switches().update(); } return; //////////////////////////////////////////////////////////////////////// diff --git a/src/emucore/EventHandler.hxx b/src/emucore/EventHandler.hxx index 62fd60e8d..9fa9645ee 100644 --- a/src/emucore/EventHandler.hxx +++ b/src/emucore/EventHandler.hxx @@ -91,6 +91,13 @@ class EventHandler */ void toggleSAPortOrder(); + /** + Toggle whether the console is in 2600 or 7800 mode. + Note that for now, this only affects whether the 7800 pause button is + supported; there is no further emulation of the 7800 itself. + */ + void set7800Mode(); + /** Collects and dispatches any pending events. This method should be called regularly (at X times per second, where X is the game framerate). @@ -558,6 +565,10 @@ class EventHandler // state change; we detect when this happens and discard the event bool mySkipMouseMotion; + // Whether the currently enabled console is emulating certain aspects + // of the 7800 (for now, only the switches are notified) + bool myIs7800; + // Sometimes key combos with the Alt key become 'stuck' after the // window changes state, and we want to ignore that event // For example, press Alt-Tab and then upon re-entering the window, diff --git a/src/emucore/M6532.cxx b/src/emucore/M6532.cxx index a0d966c4d..61167ba5f 100644 --- a/src/emucore/M6532.cxx +++ b/src/emucore/M6532.cxx @@ -106,7 +106,7 @@ void M6532::update() // Update entire port state port0.update(); port1.update(); - myConsole.switches().update(mySettings); + myConsole.switches().update(); // Get new PA7 state bool currPA7 = port0.myDigitalPinState[Controller::Four]; diff --git a/src/emucore/Switches.cxx b/src/emucore/Switches.cxx index 07df17db6..349891132 100644 --- a/src/emucore/Switches.cxx +++ b/src/emucore/Switches.cxx @@ -17,12 +17,15 @@ #include "Event.hxx" #include "Props.hxx" +#include "Settings.hxx" #include "Switches.hxx" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Switches::Switches(const Event& event, const Properties& properties) +Switches::Switches(const Event& event, const Properties& properties, + const Settings& settings) : myEvent(event), - mySwitches(0xFF) + mySwitches(0xFF), + myIs7800(false) { if(properties.get(Console_RightDifficulty) == "B") { @@ -50,15 +53,14 @@ Switches::Switches(const Event& event, const Properties& properties) { mySwitches &= ~0x08; } + + toggle7800Mode(settings); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Switches::update(const Settings& settings) +void Switches::update() { - bool devSettings = settings.getBool("dev.settings"); - bool is7800 = devSettings && (settings.getString("dev.console") == "7800"); - - if(is7800) + if(myIs7800) { if(myEvent.get(Event::Console7800Pause) != 0) { @@ -147,3 +149,12 @@ bool Switches::load(Serializer& in) } return true; } + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool Switches::toggle7800Mode(const Settings& settings) +{ + bool devSettings = settings.getBool("dev.settings"); + myIs7800 = devSettings && (settings.getString("dev.console") == "7800"); + + return myIs7800; +} diff --git a/src/emucore/Switches.hxx b/src/emucore/Switches.hxx index a3ac5d741..50e77e8b5 100644 --- a/src/emucore/Switches.hxx +++ b/src/emucore/Switches.hxx @@ -20,10 +20,10 @@ class Event; class Properties; +class Settings; #include "Serializable.hxx" #include "bspf.hxx" -#include "Settings.hxx" /** This class represents the console switches of the game console. @@ -40,25 +40,27 @@ class Switches : public Serializable public: /** Create a new set of switches using the specified events and - properties + properties. @param event The event object to use for events + @param props The ROM properties to use for the currently enabled ROM + @param settings The settings used by the system */ - Switches(const Event& event, const Properties& properties); + Switches(const Event& event, const Properties& props, const Settings& settings); virtual ~Switches() = default; public: /** - Get the value of the console switches + Get the value of the console switches. @return The 8 bits which represent the state of the console switches */ uInt8 read() const { return mySwitches; } /** - Update the switches variable + Update the switches variable. */ - void update(const Settings& settings); + void update(); /** Save the current state of the switches to the given Serializer. @@ -104,6 +106,13 @@ class Switches : public Serializable */ bool rightDifficultyA() const { return mySwitches & 0x80; } + /** + Toggle between 2600 and 7800 mode depending on settings. + + @return True if 7800 mode enabled, else false + */ + bool toggle7800Mode(const Settings& settings); + private: // Reference to the event object to use const Event& myEvent; @@ -111,6 +120,9 @@ class Switches : public Serializable // State of the console switches uInt8 mySwitches; + // Are we in 7800 or 2600 mode? + bool myIs7800; + private: // Following constructors and assignment operators not supported Switches() = delete; diff --git a/src/gui/CommandDialog.cxx b/src/gui/CommandDialog.cxx index 898a362bc..0df07a596 100644 --- a/src/gui/CommandDialog.cxx +++ b/src/gui/CommandDialog.cxx @@ -184,7 +184,7 @@ void CommandDialog::handleCommand(CommandSender* sender, int cmd, { instance().eventHandler().leaveMenuMode(); instance().eventHandler().handleEvent(event, 1); - instance().console().switches().update(instance().settings()); + instance().console().switches().update(); instance().console().tia().update(); instance().eventHandler().handleEvent(event, 0); } diff --git a/src/gui/DeveloperDialog.cxx b/src/gui/DeveloperDialog.cxx index 7dfda32d3..231bfdc3c 100644 --- a/src/gui/DeveloperDialog.cxx +++ b/src/gui/DeveloperDialog.cxx @@ -671,6 +671,7 @@ void DeveloperDialog::saveConfig() #endif } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void DeveloperDialog::setDefaults() { bool devSettings = mySettingsGroup0->getSelected() == 1;