From ef8fdc8cd9b7a340f08f20c88252fc2e1d1204ca Mon Sep 17 00:00:00 2001 From: thrust26 Date: Mon, 27 May 2019 20:01:49 +0200 Subject: [PATCH] fix combined modifier handling (finally :-) make more hotkeys configurable --- src/common/KeyMap.cxx | 8 +-- src/common/KeyMap.hxx | 19 +++---- src/common/PKeyboardHandler.cxx | 69 ++++++------------------ src/emucore/Event.hxx | 5 ++ src/emucore/EventHandler.cxx | 93 ++++++++++++++++++++++++++++++++- src/emucore/EventHandler.hxx | 2 +- 6 files changed, 128 insertions(+), 68 deletions(-) diff --git a/src/common/KeyMap.cxx b/src/common/KeyMap.cxx index e80d951ae..21efed323 100644 --- a/src/common/KeyMap.cxx +++ b/src/common/KeyMap.cxx @@ -98,12 +98,12 @@ string KeyMap::getDesc(const Mapping& mapping) const else if (mapping.mod & KBDM_LCTRL) buf << "Left " << modifier; else if (mapping.mod & KBDM_RCTRL) buf << "Right " << modifier; - if ((mapping.mod & KBDM_ALT) && buf.tellp()) buf << "+"; + if ((mapping.mod & (KBDM_ALT)) && buf.tellp()) buf << "+"; if ((mapping.mod & KBDM_ALT) == KBDM_ALT) buf << "Alt"; else if (mapping.mod & KBDM_LALT) buf << "Left Alt"; else if (mapping.mod & KBDM_RALT) buf << "Right Alt"; - if ((mapping.mod & KBDM_SHIFT) && buf.tellp()) buf << "+"; + if ((mapping.mod & (KBDM_SHIFT)) && buf.tellp()) buf << "+"; if ((mapping.mod & KBDM_SHIFT) == KBDM_SHIFT) buf << "Shift"; else if (mapping.mod & KBDM_LSHIFT) buf << "Left Shift"; else if (mapping.mod & KBDM_RSHIFT) buf << "Right Shift"; @@ -151,8 +151,6 @@ std::vector KeyMap::getEventMapping(const Event::Type event, co if (item.second == event && item.first.mode == mode) map.push_back(item.first); - int i = 0; - return map; } @@ -221,8 +219,10 @@ KeyMap::Mapping KeyMap::convertMod(const Mapping& mapping) const // handle solo modifier keys differently m.mod = KBDM_NONE; else + { // limit to modifiers we want to support m.mod = StellaMod(m.mod & (KBDM_SHIFT | KBDM_ALT | KBDM_CTRL)); + } return m; } diff --git a/src/common/KeyMap.hxx b/src/common/KeyMap.hxx index 3b2e4129e..cc576d03c 100644 --- a/src/common/KeyMap.hxx +++ b/src/common/KeyMap.hxx @@ -47,10 +47,12 @@ class KeyMap bool operator==(const Mapping& other) const { - return (//&& mod == other.mod - (mod | other.mod ? mod & other.mod : true) + return (key == other.key && mode == other.mode - && key == other.key); + && (((mod | other.mod) & KBDM_SHIFT) ? (mod & other.mod & KBDM_SHIFT) : true) + && (((mod | other.mod) & KBDM_ALT ) ? (mod & other.mod & KBDM_ALT ) : true) + && (((mod | other.mod) & KBDM_CTRL ) ? (mod & other.mod & KBDM_CTRL ) : true) + ); } }; @@ -99,12 +101,11 @@ class KeyMap struct KeyHash { size_t operator()(const Mapping& m)const { - return std::hash()((uInt64(m.mode)) // 1 bit - ^ ((uInt64(m.key)) << 1) // 8 bits - // no mod in hash to allow mapping left and right modifiers as one - // also see '==' above - /* ^ ((uInt64(m.mod)) << 9)*/); // 15 bits - + return std::hash()((uInt64(m.mode)) // 1 bit + ^ ((uInt64(m.key)) << 1) // 8 bits + ^ ((uInt64((m.mod & KBDM_SHIFT) != 0) << 9)) // 1 bit + ^ ((uInt64((m.mod & KBDM_ALT ) != 0) << 10)) // 1 bit + ^ ((uInt64((m.mod & KBDM_CTRL ) != 0) << 11))); // 1 bit } }; diff --git a/src/common/PKeyboardHandler.cxx b/src/common/PKeyboardHandler.cxx index 61091c40b..daedaa2ab 100644 --- a/src/common/PKeyboardHandler.cxx +++ b/src/common/PKeyboardHandler.cxx @@ -174,6 +174,22 @@ void PhysicalKeyboardHandler::setDefaultMapping(Event::Type event, EventMode mod setDefaultKey(Event::DecreaseAttribute , KBDK_0, KBDM_SHIFT | KBDM_ALT); setDefaultKey(Event::IncreaseAttribute , KBDK_0, KBDM_ALT); + setDefaultKey(Event::ToggleP0Collision , KBDK_Z, KBDM_SHIFT | KBDM_ALT); + setDefaultKey(Event::ToggleP0Bit , KBDK_Z, KBDM_ALT); + setDefaultKey(Event::ToggleP1Collision , KBDK_X, KBDM_SHIFT | KBDM_ALT); + setDefaultKey(Event::ToggleP1Bit , KBDK_X, KBDM_ALT); + setDefaultKey(Event::ToggleM0Collision , KBDK_C, KBDM_SHIFT | KBDM_ALT); + setDefaultKey(Event::ToggleM0Bit , KBDK_C, KBDM_ALT); + setDefaultKey(Event::ToggleM1Collision , KBDK_V, KBDM_SHIFT | KBDM_ALT); + setDefaultKey(Event::ToggleM1Bit , KBDK_V, KBDM_ALT); + setDefaultKey(Event::ToggleBLCollision , KBDK_B, KBDM_SHIFT | KBDM_ALT); + setDefaultKey(Event::ToggleBLBit , KBDK_B, KBDM_ALT); + setDefaultKey(Event::TogglePFCollision , KBDK_N, KBDM_SHIFT | KBDM_ALT); + setDefaultKey(Event::TogglePFBit , KBDK_N, KBDM_ALT); + setDefaultKey(Event::ToggleFixedColors , KBDK_COMMA, KBDM_ALT); + setDefaultKey(Event::ToggleCollisions , KBDK_PERIOD, KBDM_SHIFT | KBDM_ALT); + setDefaultKey(Event::ToggleBits , KBDK_PERIOD, KBDM_ALT); + // FIXME - use the R77 define in the final release // use the '1' define for testing #if defined(RETRON77) @@ -386,59 +402,6 @@ bool PhysicalKeyboardHandler::handleAltEvent(StellaKey key, StellaMod mod, bool myOSystem.console().changeYStart(-1); break; - case KBDK_Z: - if(StellaModTest::isShift(mod)) - myOSystem.console().toggleP0Collision(); - else - myOSystem.console().toggleP0Bit(); - break; - - case KBDK_X: - if(StellaModTest::isShift(mod)) - myOSystem.console().toggleP1Collision(); - else - myOSystem.console().toggleP1Bit(); - break; - - case KBDK_C: - if(StellaModTest::isShift(mod)) - myOSystem.console().toggleM0Collision(); - else - myOSystem.console().toggleM0Bit(); - break; - - case KBDK_V: - if(StellaModTest::isShift(mod)) - myOSystem.console().toggleM1Collision(); - else - myOSystem.console().toggleM1Bit(); - break; - - case KBDK_B: - if(StellaModTest::isShift(mod)) - myOSystem.console().toggleBLCollision(); - else - myOSystem.console().toggleBLBit(); - break; - - case KBDK_N: - if(StellaModTest::isShift(mod)) - myOSystem.console().togglePFCollision(); - else - myOSystem.console().togglePFBit(); - break; - - case KBDK_COMMA: - myOSystem.console().toggleFixedColors(); - break; - - case KBDK_PERIOD: - if(StellaModTest::isShift(mod)) - myOSystem.console().toggleCollisions(); - else - myOSystem.console().toggleBits(); - break; - case KBDK_I: // Alt-i decreases phosphor blend myOSystem.console().changePhosphor(-1); break; diff --git a/src/emucore/Event.hxx b/src/emucore/Event.hxx index 07dbd253b..3a234eaa2 100644 --- a/src/emucore/Event.hxx +++ b/src/emucore/Event.hxx @@ -87,6 +87,11 @@ class Event PreviousAttribute, NextAttribute, DecreaseAttribute, IncreaseAttribute, ScanlinesDecrease, ScanlinesIncrease, + ToggleP0Collision, ToggleP0Bit, ToggleP1Collision, ToggleP1Bit, + ToggleM0Collision, ToggleM0Bit, ToggleM1Collision, ToggleM1Bit, + ToggleBLCollision, ToggleBLBit, TogglePFCollision, TogglePFBit, + ToggleCollisions, ToggleBits, ToggleFixedColors, + LastType }; diff --git a/src/emucore/EventHandler.cxx b/src/emucore/EventHandler.cxx index 247bf17aa..b6bc19821 100644 --- a/src/emucore/EventHandler.cxx +++ b/src/emucore/EventHandler.cxx @@ -477,6 +477,81 @@ void EventHandler::handleEvent(Event::Type event, bool pressed) } return; + case Event::ToggleP0Collision: + if (pressed) + myOSystem.console().toggleP0Collision(); + return; + + case Event::ToggleP0Bit: + if (pressed) + myOSystem.console().toggleP0Bit(); + return; + + case Event::ToggleP1Collision: + if (pressed) + myOSystem.console().toggleP1Collision(); + return; + + case Event::ToggleP1Bit: + if (pressed) + myOSystem.console().toggleP1Bit(); + return; + + case Event::ToggleM0Collision: + if (pressed) + myOSystem.console().toggleM0Collision(); + return; + + case Event::ToggleM0Bit: + if (pressed) + myOSystem.console().toggleM0Bit(); + return; + + case Event::ToggleM1Collision: + if (pressed) + myOSystem.console().toggleM1Collision(); + return; + + case Event::ToggleM1Bit: + if (pressed) + myOSystem.console().toggleM1Bit(); + return; + + case Event::ToggleBLCollision: + if (pressed) + myOSystem.console().toggleBLCollision(); + return; + + case Event::ToggleBLBit: + if (pressed) + myOSystem.console().toggleBLBit(); + return; + + case Event::TogglePFCollision: + if (pressed) + myOSystem.console().togglePFCollision(); + return; + + case Event::TogglePFBit: + if (pressed) + myOSystem.console().togglePFBit(); + return; + + case Event::ToggleFixedColors: + if (pressed) + myOSystem.console().toggleFixedColors(); + return; + + case Event::ToggleCollisions: + if (pressed) + myOSystem.console().toggleCollisions(); + return; + + case Event::ToggleBits: + if (pressed) + myOSystem.console().toggleBits(); + return; + case Event::SaveState: if(pressed) myOSystem.state().saveState(); return; @@ -1469,7 +1544,23 @@ EventHandler::ActionList EventHandler::ourEmulActionList[EMUL_ACTIONLIST_SIZE] = { Event::Combo13, "Combo 13", "", false }, { Event::Combo14, "Combo 14", "", false }, { Event::Combo15, "Combo 15", "", false }, - { Event::Combo16, "Combo 16", "", false } + { Event::Combo16, "Combo 16", "", false }, + + { Event::ToggleP0Bit, "Toggle TIA Player0 object", "", false }, + { Event::ToggleP0Collision, "Toggle TIA Player0 collisions", "", false }, + { Event::ToggleP1Bit, "Toggle TIA Player1 object", "", false }, + { Event::ToggleP1Collision, "Toggle TIA Player1 collisions", "", false }, + { Event::ToggleM0Bit, "Toggle TIA Missile0 object", "", false }, + { Event::ToggleM0Collision, "Toggle TIA Missile0 collisions", "", false }, + { Event::ToggleM1Bit, "Toggle TIA Missile1 object", "", false }, + { Event::ToggleM1Collision, "Toggle TIA Missile1 collisions", "", false }, + { Event::ToggleBLBit, "Toggle TIA Ball object", "", false }, + { Event::ToggleBLCollision, "Toggle TIA Ball collisions", "", false }, + { Event::TogglePFBit, "Toggle TIA Playfield object", "", false }, + { Event::TogglePFCollision, "Toggle TIA Playfield collisions","", false }, + { Event::ToggleFixedColors, "Toggle TIA 'Fixed Debug Colors' mode","", false }, + { Event::ToggleBits, "Toggle all TIA objects", "", false }, + { Event::ToggleCollisions, "Toggle all TIA collisions", "", false } }; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/EventHandler.hxx b/src/emucore/EventHandler.hxx index a6659b946..1f7933542 100644 --- a/src/emucore/EventHandler.hxx +++ b/src/emucore/EventHandler.hxx @@ -367,7 +367,7 @@ class EventHandler static constexpr Int32 COMBO_SIZE = 16, EVENTS_PER_COMBO = 8, - EMUL_ACTIONLIST_SIZE = 98 + COMBO_SIZE, + EMUL_ACTIONLIST_SIZE = 113 + COMBO_SIZE, MENU_ACTIONLIST_SIZE = 18 ;