Changed Switches::update() to not evaluate settings on every call.

Basically, removed determination of whether we're in 2600 or 7800 mode
from the hot path, and moved it to a method that is called only when
it changes (currently that method doesn't seem to be called at all, since
it seems like 'console' setting cannot be changed dynamically).
This commit is contained in:
Stephen Anthony 2017-12-04 14:12:06 -03:30
parent a91bcbadc9
commit 1f43539f10
8 changed files with 70 additions and 25 deletions

View File

@ -95,7 +95,7 @@ Console::Console(OSystem& osystem, unique_ptr<Cartridge>& cart,
myRiot = make_unique<M6532>(*this, myOSystem.settings()); myRiot = make_unique<M6532>(*this, myOSystem.settings());
myTIA = make_unique<TIA>(*this, myOSystem.sound(), myOSystem.settings()); myTIA = make_unique<TIA>(*this, myOSystem.sound(), myOSystem.settings());
myFrameManager = make_unique<FrameManager>(); myFrameManager = make_unique<FrameManager>();
mySwitches = make_unique<Switches>(myEvent, myProperties); mySwitches = make_unique<Switches>(myEvent, myProperties, myOSystem.settings());
myTIA->setFrameManager(myFrameManager.get()); myTIA->setFrameManager(myFrameManager.get());

View File

@ -65,6 +65,7 @@ EventHandler::EventHandler(OSystem& osystem)
myFryingFlag(false), myFryingFlag(false),
myUseCtrlKeyFlag(true), myUseCtrlKeyFlag(true),
mySkipMouseMotion(true), mySkipMouseMotion(true),
myIs7800(false),
myAltKeyCounter(0), myAltKeyCounter(0),
myContSnapshotInterval(0), myContSnapshotInterval(0),
myContSnapshotCounter(0) myContSnapshotCounter(0)
@ -117,6 +118,9 @@ void EventHandler::initialize()
// Default phosphor blend // Default phosphor blend
Properties::setDefault(Display_PPBlend, Properties::setDefault(Display_PPBlend,
myOSystem.settings().getString("tv.phosblend")); myOSystem.settings().getString("tv.phosblend"));
// Toggle 7800 mode
set7800Mode();
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -192,6 +196,15 @@ void EventHandler::toggleSAPortOrder()
#endif #endif
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::set7800Mode()
{
if(myOSystem.hasConsole())
myIs7800 = myOSystem.console().switches().toggle7800Mode(myOSystem.settings());
else
myIs7800 = false;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::poll(uInt64 time) 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 // Take care of special events that aren't part of the emulation core
// or need to be preprocessed before passing them on // 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) switch(event)
{ {
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
@ -1026,21 +1036,21 @@ void EventHandler::handleEvent(Event::Type event, int state)
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// Events which relate to switches() // Events which relate to switches()
case Event::ConsoleColor: case Event::ConsoleColor:
if(state && !is7800) if(state && !myIs7800)
{ {
myEvent.set(Event::ConsoleBlackWhite, 0); myEvent.set(Event::ConsoleBlackWhite, 0);
myOSystem.frameBuffer().showMessage("Color Mode"); myOSystem.frameBuffer().showMessage("Color Mode");
} }
break; break;
case Event::ConsoleBlackWhite: case Event::ConsoleBlackWhite:
if(state && !is7800) if(state && !myIs7800)
{ {
myEvent.set(Event::ConsoleColor, 0); myEvent.set(Event::ConsoleColor, 0);
myOSystem.frameBuffer().showMessage("BW Mode"); myOSystem.frameBuffer().showMessage("BW Mode");
} }
break; break;
case Event::ConsoleColorToggle: case Event::ConsoleColorToggle:
if(state && !is7800) if(state && !myIs7800)
{ {
if(myOSystem.console().switches().tvColor()) if(myOSystem.console().switches().tvColor())
{ {
@ -1054,7 +1064,7 @@ void EventHandler::handleEvent(Event::Type event, int state)
myEvent.set(Event::ConsoleColor, 1); myEvent.set(Event::ConsoleColor, 1);
myOSystem.frameBuffer().showMessage("Color Mode"); myOSystem.frameBuffer().showMessage("Color Mode");
} }
myOSystem.console().switches().update(myOSystem.settings()); myOSystem.console().switches().update();
} }
return; return;
@ -1087,7 +1097,7 @@ void EventHandler::handleEvent(Event::Type event, int state)
myEvent.set(Event::ConsoleLeftDiffB, 0); myEvent.set(Event::ConsoleLeftDiffB, 0);
myOSystem.frameBuffer().showMessage("Left Difficulty A"); myOSystem.frameBuffer().showMessage("Left Difficulty A");
} }
myOSystem.console().switches().update(myOSystem.settings()); myOSystem.console().switches().update();
} }
return; return;
@ -1120,7 +1130,7 @@ void EventHandler::handleEvent(Event::Type event, int state)
myEvent.set(Event::ConsoleRightDiffB, 0); myEvent.set(Event::ConsoleRightDiffB, 0);
myOSystem.frameBuffer().showMessage("Right Difficulty A"); myOSystem.frameBuffer().showMessage("Right Difficulty A");
} }
myOSystem.console().switches().update(myOSystem.settings()); myOSystem.console().switches().update();
} }
return; return;
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////

View File

@ -91,6 +91,13 @@ class EventHandler
*/ */
void toggleSAPortOrder(); 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 Collects and dispatches any pending events. This method should be
called regularly (at X times per second, where X is the game framerate). 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 // state change; we detect when this happens and discard the event
bool mySkipMouseMotion; 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 // Sometimes key combos with the Alt key become 'stuck' after the
// window changes state, and we want to ignore that event // window changes state, and we want to ignore that event
// For example, press Alt-Tab and then upon re-entering the window, // For example, press Alt-Tab and then upon re-entering the window,

View File

@ -106,7 +106,7 @@ void M6532::update()
// Update entire port state // Update entire port state
port0.update(); port0.update();
port1.update(); port1.update();
myConsole.switches().update(mySettings); myConsole.switches().update();
// Get new PA7 state // Get new PA7 state
bool currPA7 = port0.myDigitalPinState[Controller::Four]; bool currPA7 = port0.myDigitalPinState[Controller::Four];

View File

@ -17,12 +17,15 @@
#include "Event.hxx" #include "Event.hxx"
#include "Props.hxx" #include "Props.hxx"
#include "Settings.hxx"
#include "Switches.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), : myEvent(event),
mySwitches(0xFF) mySwitches(0xFF),
myIs7800(false)
{ {
if(properties.get(Console_RightDifficulty) == "B") if(properties.get(Console_RightDifficulty) == "B")
{ {
@ -50,15 +53,14 @@ Switches::Switches(const Event& event, const Properties& properties)
{ {
mySwitches &= ~0x08; mySwitches &= ~0x08;
} }
toggle7800Mode(settings);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Switches::update(const Settings& settings) void Switches::update()
{ {
bool devSettings = settings.getBool("dev.settings"); if(myIs7800)
bool is7800 = devSettings && (settings.getString("dev.console") == "7800");
if(is7800)
{ {
if(myEvent.get(Event::Console7800Pause) != 0) if(myEvent.get(Event::Console7800Pause) != 0)
{ {
@ -147,3 +149,12 @@ bool Switches::load(Serializer& in)
} }
return true; return true;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool Switches::toggle7800Mode(const Settings& settings)
{
bool devSettings = settings.getBool("dev.settings");
myIs7800 = devSettings && (settings.getString("dev.console") == "7800");
return myIs7800;
}

View File

@ -20,10 +20,10 @@
class Event; class Event;
class Properties; class Properties;
class Settings;
#include "Serializable.hxx" #include "Serializable.hxx"
#include "bspf.hxx" #include "bspf.hxx"
#include "Settings.hxx"
/** /**
This class represents the console switches of the game console. This class represents the console switches of the game console.
@ -40,25 +40,27 @@ class Switches : public Serializable
public: public:
/** /**
Create a new set of switches using the specified events and Create a new set of switches using the specified events and
properties properties.
@param event The event object to use for events @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; virtual ~Switches() = default;
public: 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 @return The 8 bits which represent the state of the console switches
*/ */
uInt8 read() const { return mySwitches; } 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. 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; } 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: private:
// Reference to the event object to use // Reference to the event object to use
const Event& myEvent; const Event& myEvent;
@ -111,6 +120,9 @@ class Switches : public Serializable
// State of the console switches // State of the console switches
uInt8 mySwitches; uInt8 mySwitches;
// Are we in 7800 or 2600 mode?
bool myIs7800;
private: private:
// Following constructors and assignment operators not supported // Following constructors and assignment operators not supported
Switches() = delete; Switches() = delete;

View File

@ -184,7 +184,7 @@ void CommandDialog::handleCommand(CommandSender* sender, int cmd,
{ {
instance().eventHandler().leaveMenuMode(); instance().eventHandler().leaveMenuMode();
instance().eventHandler().handleEvent(event, 1); instance().eventHandler().handleEvent(event, 1);
instance().console().switches().update(instance().settings()); instance().console().switches().update();
instance().console().tia().update(); instance().console().tia().update();
instance().eventHandler().handleEvent(event, 0); instance().eventHandler().handleEvent(event, 0);
} }

View File

@ -671,6 +671,7 @@ void DeveloperDialog::saveConfig()
#endif #endif
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void DeveloperDialog::setDefaults() void DeveloperDialog::setDefaults()
{ {
bool devSettings = mySettingsGroup0->getSelected() == 1; bool devSettings = mySettingsGroup0->getSelected() == 1;