From 9ea265859a8a5d76135d4c32eaf353fcc360b656 Mon Sep 17 00:00:00 2001 From: thrust26 Date: Sun, 26 May 2019 00:07:53 +0200 Subject: [PATCH] add new mappings automatically add more events which can be remapped enable all emulation events for pause mode too --- src/common/KeyMap.cxx | 12 +++ src/common/KeyMap.hxx | 2 + src/common/PKeyboardHandler.cxx | 116 +++++++-------------------- src/common/tv_filters/NTSCFilter.cxx | 10 +-- src/emucore/Event.hxx | 16 ++-- src/emucore/EventHandler.cxx | 90 ++++++++++++++++++++- src/emucore/EventHandler.hxx | 2 +- 7 files changed, 150 insertions(+), 98 deletions(-) diff --git a/src/common/KeyMap.cxx b/src/common/KeyMap.cxx index 937f8d470..6fdc4efaa 100644 --- a/src/common/KeyMap.cxx +++ b/src/common/KeyMap.cxx @@ -88,6 +88,18 @@ string KeyMap::getEventMappingDesc(const Event::Type event, const int mode) cons return buf.str(); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +std::vector KeyMap::getEventMapping(const Event::Type event, const int mode) const +{ + std::vector map; + + for (auto item : myMap) + if (item.second == event && item.first.mode == mode) + map.push_back(item.first); + + return map; +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - string KeyMap::saveMapping(const int mode) const { diff --git a/src/common/KeyMap.hxx b/src/common/KeyMap.hxx index bc56c629c..51ca23f5c 100644 --- a/src/common/KeyMap.hxx +++ b/src/common/KeyMap.hxx @@ -75,6 +75,8 @@ class KeyMap string getDesc(const Mapping& input) const; string getDesc(const int mode, const int key, const int mod) const; + std::vector getEventMapping(const Event::Type event, const int mode) const; + string saveMapping(const int mode) const; int loadMapping(string& list, const int mode); diff --git a/src/common/PKeyboardHandler.cxx b/src/common/PKeyboardHandler.cxx index 386425c70..48f4e8c5e 100644 --- a/src/common/PKeyboardHandler.cxx +++ b/src/common/PKeyboardHandler.cxx @@ -49,26 +49,29 @@ PhysicalKeyboardHandler::PhysicalKeyboardHandler( list = myOSystem.settings().getString("keymap_ui"); i += myKeyMap.loadMapping(list, kMenuMode); - if (!i) - { - setDefaultMapping(Event::NoType, kEmulationMode); - setDefaultMapping(Event::NoType, kMenuMode); - } + setDefaultMapping(Event::NoType, kEmulationMode); + setDefaultMapping(Event::NoType, kMenuMode); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void PhysicalKeyboardHandler::setDefaultMapping(Event::Type event, EventMode mode) { - // If event is 'NoType', erase and reset all mappings - // Otherwise, only reset the given event - bool eraseAll = (event == Event::NoType); - if(eraseAll) - // Erase all mappings of given mode - myKeyMap.eraseMode(mode); + // If event is 'NoType', check for missing default mappings + bool defaultMissing = (event == Event::NoType); - auto setDefaultKey = [&](Event::Type k_event, StellaKey key, int mod = StellaMod::KBDM_NONE) + auto setDefaultKey = [&](Event::Type k_event, StellaKey key, int mod = KBDM_NONE) { - if (eraseAll || k_event == event) + if (defaultMissing) + { + // if there is no existing mapping for the event and + // the default mapping for the event is unused, set default key for event + if (myKeyMap.getEventMapping(k_event, mode).size() == 0 && + myKeyMap.get(mode, key, mod) == Event::Type::NoType) + { + myKeyMap.add(k_event, mode, key, mod); + } + } + else if (k_event == event) { myKeyMap.eraseEvent(k_event, mode); myKeyMap.add(k_event, mode, key, mod); @@ -147,6 +150,20 @@ void PhysicalKeyboardHandler::setDefaultMapping(Event::Type event, EventMode mod setDefaultKey(Event::VolumeIncrease , KBDK_RIGHTBRACKET, KBDM_ALT); setDefaultKey(Event::SoundToggle , KBDK_RIGHTBRACKET, KBDM_CTRL); + setDefaultKey(Event::ToggleFullScreen , KBDK_RETURN, KBDM_ALT); + setDefaultKey(Event::VidmodeStd , KBDK_1, KBDM_ALT); + setDefaultKey(Event::VidmodeRGB , KBDK_2, KBDM_ALT); + setDefaultKey(Event::VidmodeSVideo , KBDK_3, KBDM_ALT); + setDefaultKey(Event::VidModeComposite , KBDK_4, KBDM_ALT); + setDefaultKey(Event::VidModeBad , KBDK_5, KBDM_ALT); + setDefaultKey(Event::VidModeCustom , KBDK_6, KBDM_ALT); + setDefaultKey(Event::ScanlinesDecrease , KBDK_7, KBDM_SHIFT | KBDM_ALT); + setDefaultKey(Event::ScanlinesIncrease , KBDK_7, KBDM_ALT); + setDefaultKey(Event::PreviousAttribute , KBDK_9, KBDM_SHIFT | KBDM_ALT); + setDefaultKey(Event::NextAttribute , KBDK_9, KBDM_ALT); + setDefaultKey(Event::DecreaseAttribute , KBDK_0, KBDM_SHIFT | KBDM_ALT); + setDefaultKey(Event::IncreaseAttribute , KBDK_0, KBDM_ALT); + // FIXME - use the R77 define in the final release // use the '1' define for testing #if defined(RETRON77) @@ -294,20 +311,8 @@ void PhysicalKeyboardHandler::handleEvent(StellaKey key, StellaMod mod, bool pre switch(estate) { case EventHandlerState::EMULATION: - myHandler.handleEvent(myKeyMap.get(kEmulationMode, key, mod), pressed); - break; - case EventHandlerState::PAUSE: - switch (myKeyMap.get(kEmulationMode, key, mod)) - { - case Event::TakeSnapshot: - case Event::DebuggerMode: - myHandler.handleEvent(myKeyMap.get(kEmulationMode, key, mod), pressed); - break; - - default: - break; - } + myHandler.handleEvent(myKeyMap.get(kEmulationMode, key, mod), pressed); break; default: @@ -341,10 +346,6 @@ bool PhysicalKeyboardHandler::handleAltEvent(StellaKey key, StellaMod mod, bool myAltKeyCounter = 1; return true; } - else if(key == KBDK_RETURN) - { - myOSystem.frameBuffer().toggleFullscreen(); - } // State rewinding must work in pause mode too else if(estate == EventHandlerState::EMULATION || estate == EventHandlerState::PAUSE) { @@ -374,61 +375,6 @@ bool PhysicalKeyboardHandler::handleAltEvent(StellaKey key, StellaMod mod, bool myOSystem.console().changeYStart(-1); break; - case KBDK_1: // Alt-1 turns off NTSC filtering - myOSystem.frameBuffer().tiaSurface().setNTSC(NTSCFilter::Preset::OFF); - break; - - case KBDK_2: // Alt-2 turns on 'rgb' NTSC filtering - myOSystem.frameBuffer().tiaSurface().setNTSC(NTSCFilter::Preset::RGB); - break; - - case KBDK_3: // Alt-3 turns on 'svideo' NTSC filtering - myOSystem.frameBuffer().tiaSurface().setNTSC(NTSCFilter::Preset::SVIDEO); - break; - - case KBDK_4: // Alt-4 turns on 'composite' NTSC filtering - myOSystem.frameBuffer().tiaSurface().setNTSC(NTSCFilter::Preset::COMPOSITE); - break; - - case KBDK_5: // Alt-5 turns on 'bad' NTSC filtering - myOSystem.frameBuffer().tiaSurface().setNTSC(NTSCFilter::Preset::BAD); - break; - - case KBDK_6: // Alt-6 turns on 'custom' NTSC filtering - myOSystem.frameBuffer().tiaSurface().setNTSC(NTSCFilter::Preset::CUSTOM); - break; - - case KBDK_7: // Alt-7 changes scanline intensity for NTSC filtering - if(StellaModTest::isShift(mod)) - myOSystem.frameBuffer().tiaSurface().setScanlineIntensity(-5); - else - myOSystem.frameBuffer().tiaSurface().setScanlineIntensity(+5); - break; - - case KBDK_9: // Alt-9 selects various custom adjustables for NTSC filtering - if(myOSystem.frameBuffer().tiaSurface().ntscEnabled()) - { - if(StellaModTest::isShift(mod)) - myOSystem.frameBuffer().showMessage( - myOSystem.frameBuffer().tiaSurface().ntsc().setPreviousAdjustable()); - else - myOSystem.frameBuffer().showMessage( - myOSystem.frameBuffer().tiaSurface().ntsc().setNextAdjustable()); - } - break; - - case KBDK_0: // Alt-0 changes custom adjustables for NTSC filtering - if(myOSystem.frameBuffer().tiaSurface().ntscEnabled()) - { - if(StellaModTest::isShift(mod)) - myOSystem.frameBuffer().showMessage( - myOSystem.frameBuffer().tiaSurface().ntsc().decreaseAdjustable()); - else - myOSystem.frameBuffer().showMessage( - myOSystem.frameBuffer().tiaSurface().ntsc().increaseAdjustable()); - } - break; - case KBDK_Z: if(StellaModTest::isShift(mod)) myOSystem.console().toggleP0Collision(); diff --git a/src/common/tv_filters/NTSCFilter.cxx b/src/common/tv_filters/NTSCFilter.cxx index c02191a88..047898c27 100644 --- a/src/common/tv_filters/NTSCFilter.cxx +++ b/src/common/tv_filters/NTSCFilter.cxx @@ -70,11 +70,11 @@ string NTSCFilter::getPreset() const { switch(myPreset) { - case Preset::COMPOSITE: return "COMPOSITE"; - case Preset::SVIDEO: return "S-VIDEO"; - case Preset::RGB: return "RGB"; - case Preset::BAD: return "BAD ADJUST"; - case Preset::CUSTOM: return "CUSTOM"; + case Preset::COMPOSITE: return "COMPOSITE"; + case Preset::SVIDEO: return "S-VIDEO"; + case Preset::RGB: return "RGB"; + case Preset::BAD: return "BAD ADJUST"; + case Preset::CUSTOM: return "CUSTOM"; default: return "Disabled"; } } diff --git a/src/emucore/Event.hxx b/src/emucore/Event.hxx index ca4d513db..07dbd253b 100644 --- a/src/emucore/Event.hxx +++ b/src/emucore/Event.hxx @@ -36,12 +36,13 @@ class Event */ enum Type { - NoType, - ConsoleOn, ConsoleOff, ConsoleColor, ConsoleBlackWhite, + NoType = 0, + ConsoleOn = 1, ConsoleOff = 2, ConsoleColor = 3, ConsoleBlackWhite = 4, ConsoleLeftDiffA, ConsoleLeftDiffB, ConsoleRightDiffA, ConsoleRightDiffB, ConsoleSelect, ConsoleReset, - ConsoleLeftDiffToggle, ConsoleRightDiffToggle, ConsoleColorToggle, Console7800Pause, + ConsoleLeftDiffToggle, ConsoleRightDiffToggle, ConsoleColorToggle, + Console7800Pause, JoystickZeroUp, JoystickZeroDown, JoystickZeroLeft, JoystickZeroRight, JoystickZeroFire, JoystickZeroFire5, JoystickZeroFire9, @@ -81,6 +82,11 @@ class Event UISelect, UINavPrev, UINavNext, UIOK, UICancel, UIPrevDir, UITabPrev, UITabNext, + ToggleFullScreen, + VidmodeStd, VidmodeRGB, VidmodeSVideo, VidModeComposite, VidModeBad, VidModeCustom, + PreviousAttribute, NextAttribute, DecreaseAttribute, IncreaseAttribute, + ScanlinesDecrease, ScanlinesIncrease, + LastType }; @@ -147,10 +153,10 @@ class Event { std::lock_guard lock(myMutex); - for(uInt32 i = 0; i < LastType; ++i) + for(Int32 i = 0; i < LastType; ++i) myValues[i] = Event::NoType; - for(uInt32 i = 0; i < KBDK_LAST; ++i) + for(Int32 i = 0; i < KBDK_LAST; ++i) myKeyTable[i] = false; } diff --git a/src/emucore/EventHandler.cxx b/src/emucore/EventHandler.cxx index d8f08af33..8b4bcaab7 100644 --- a/src/emucore/EventHandler.cxx +++ b/src/emucore/EventHandler.cxx @@ -405,6 +405,78 @@ void EventHandler::handleEvent(Event::Type event, bool pressed) if(pressed) myOSystem.frameBuffer().changeVidMode(+1); return; + case Event::ToggleFullScreen: + if (pressed) myOSystem.frameBuffer().toggleFullscreen(); + return; + + case Event::VidmodeStd: + if (pressed) myOSystem.frameBuffer().tiaSurface().setNTSC(NTSCFilter::Preset::OFF); + return; + + case Event::VidmodeRGB: + if (pressed) myOSystem.frameBuffer().tiaSurface().setNTSC(NTSCFilter::Preset::RGB); + return; + + case Event::VidmodeSVideo: + if (pressed) myOSystem.frameBuffer().tiaSurface().setNTSC(NTSCFilter::Preset::SVIDEO); + return; + + case Event::VidModeComposite: + if (pressed) myOSystem.frameBuffer().tiaSurface().setNTSC(NTSCFilter::Preset::COMPOSITE); + return; + + case Event::VidModeBad: + if (pressed) myOSystem.frameBuffer().tiaSurface().setNTSC(NTSCFilter::Preset::BAD); + return; + + case Event::VidModeCustom: + if (pressed) myOSystem.frameBuffer().tiaSurface().setNTSC(NTSCFilter::Preset::CUSTOM); + return; + + case Event::ScanlinesDecrease: + if (pressed) myOSystem.frameBuffer().tiaSurface().setScanlineIntensity(-5); + return; + + case Event::ScanlinesIncrease: + if (pressed) myOSystem.frameBuffer().tiaSurface().setScanlineIntensity(+5); + return; + + case Event::PreviousAttribute: + if (pressed) + { + myOSystem.frameBuffer().tiaSurface().setNTSC(NTSCFilter::Preset::CUSTOM); + myOSystem.frameBuffer().showMessage( + myOSystem.frameBuffer().tiaSurface().ntsc().setPreviousAdjustable()); + } + return; + + case Event::NextAttribute: + if (pressed) + { + myOSystem.frameBuffer().tiaSurface().setNTSC(NTSCFilter::Preset::CUSTOM); + myOSystem.frameBuffer().showMessage( + myOSystem.frameBuffer().tiaSurface().ntsc().setNextAdjustable()); + } + return; + + case Event::DecreaseAttribute: + if (pressed) + { + myOSystem.frameBuffer().tiaSurface().setNTSC(NTSCFilter::Preset::CUSTOM); + myOSystem.frameBuffer().showMessage( + myOSystem.frameBuffer().tiaSurface().ntsc().decreaseAdjustable()); + } + return; + + case Event::IncreaseAttribute: + if (pressed) + { + myOSystem.frameBuffer().tiaSurface().setNTSC(NTSCFilter::Preset::CUSTOM); + myOSystem.frameBuffer().showMessage( + myOSystem.frameBuffer().tiaSurface().ntsc().increaseAdjustable()); + } + return; + case Event::SaveState: if(pressed) myOSystem.state().saveState(); return; @@ -1309,11 +1381,25 @@ EventHandler::ActionList EventHandler::ourEmulActionList[EMUL_ACTIONLIST_SIZE] = { Event::LoadState, "Load state", "", false }, { Event::TakeSnapshot, "Snapshot", "", false }, { Event::Fry, "Fry cartridge", "", false }, + { Event::VidmodeDecrease, "Previous zoom level", "", false }, + { Event::VidmodeIncrease, "Next zoom level", "", false }, + { Event::ToggleFullScreen, "Toggle fullscreen", "", false }, + + { Event::VidmodeStd, "Disable TV effects", "", false }, + { Event::VidmodeRGB, "Select 'RGB' preset", "", false }, + { Event::VidmodeSVideo, "Select 'S-Video' preset", "", false }, + { Event::VidModeComposite, "Select 'Composite' preset", "", false }, + { Event::VidModeBad, "Select 'Badly adjusted' preset", "", false }, + { Event::VidModeCustom, "Select 'Custom' preset", "", false }, + { Event::PreviousAttribute, "Select previous 'Custom' attribute", "", false }, + { Event::NextAttribute, "Select next 'Custom' attribute", "", false }, + { Event::DecreaseAttribute, "Decrease selected 'Custom' attribute", "", false }, + { Event::IncreaseAttribute, "Increase selected 'Custom' attribute", "", false }, + { Event::ScanlinesDecrease, "Decrease scanlines", "", false }, + { Event::ScanlinesIncrease, "Increase scanlines", "", false }, { Event::VolumeDecrease, "Decrease volume", "", false }, { Event::VolumeIncrease, "Increase volume", "", false }, { Event::SoundToggle, "Toggle sound", "", false }, - { Event::VidmodeDecrease, "Previous zoom level", "", false }, - { Event::VidmodeIncrease, "Next zoom level", "", false }, { Event::PauseMode, "Pause", "", false }, { Event::OptionsMenuMode, "Enter options menu UI", "", false }, { Event::CmdMenuMode, "Toggle command menu UI", "", false }, diff --git a/src/emucore/EventHandler.hxx b/src/emucore/EventHandler.hxx index 83f330087..03e03e9cb 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 = 85 + COMBO_SIZE, + EMUL_ACTIONLIST_SIZE = 98 + COMBO_SIZE, MENU_ACTIONLIST_SIZE = 16 ;