From f8535185402cb02dfafcbd6d79abd30c99dc4399 Mon Sep 17 00:00:00 2001 From: stephena Date: Thu, 19 Apr 2012 20:11:16 +0000 Subject: [PATCH] Fixed ghost key issue with the CompuMate emulation. It seems that mixing SDL keyboard events and the static GetKeyState() method doesn't always work as you'd expect. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@2447 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba --- Changes.txt | 4 +++- src/common/StellaKeys.hxx | 12 ------------ src/emucore/CompuMate.cxx | 2 +- src/emucore/CompuMate.hxx | 2 +- src/emucore/Event.hxx | 17 +++++++++++++++++ src/emucore/EventHandler.cxx | 3 +++ 6 files changed, 25 insertions(+), 15 deletions(-) diff --git a/Changes.txt b/Changes.txt index 33da1ce90..e670d2b28 100644 --- a/Changes.txt +++ b/Changes.txt @@ -17,7 +17,9 @@ * Updated the CompuMate keyboard handler to recognize more keys on an actual keyboard, instead of having to remember the weird combinations used on the original CompuMate keyboard (although those original keys - will continue to work). + will continue to work). Related to this, fixed bug whereby + 'ghost keys' would be detected by the CompuMate, particularly after + pressing 'Enter' to start a game from the ROM launcher. * Added emulation for MindLink controller using the mouse; the 'Bionic Breakthrough' and 'Telepathy' ROMs now work. diff --git a/src/common/StellaKeys.hxx b/src/common/StellaKeys.hxx index b49b70af6..77ad3dcaa 100644 --- a/src/common/StellaKeys.hxx +++ b/src/common/StellaKeys.hxx @@ -312,16 +312,4 @@ typedef enum { // The underlying code doesn't need to know how it's implemented typedef int StellaMod; -// Wrapper around the SDL_GetKeyState function -// This can be used as-is since KBDK keys and SDL keys are the same -class StellaKeys -{ - public: - // According to the SDL source code, this only needs to be called - // once, since it points to an internal static variable in SDL - // As such, it's not really a (current) state table, since that - // implies it needs to be called each time you want the state updated - static inline uInt8* GetKeyTable() { return SDL_GetKeyState(NULL); } -}; - #endif /* StellaKeys */ diff --git a/src/emucore/CompuMate.cxx b/src/emucore/CompuMate.cxx index 2c45320be..c96cd4aed 100644 --- a/src/emucore/CompuMate.cxx +++ b/src/emucore/CompuMate.cxx @@ -40,7 +40,7 @@ CompuMate::CompuMate(CartridgeCM& cart, const Event& event, myRightController->myAnalogPinValue[Controller::Nine] = Controller::minimumResistance; myRightController->myAnalogPinValue[Controller::Five] = Controller::maximumResistance; - myKeyTable = StellaKeys::GetKeyTable(); + myKeyTable = event.getKeys(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/CompuMate.hxx b/src/emucore/CompuMate.hxx index 6917c7cfc..b18481ec3 100644 --- a/src/emucore/CompuMate.hxx +++ b/src/emucore/CompuMate.hxx @@ -124,7 +124,7 @@ class CompuMate CMControl *myLeftController, *myRightController; // The keyboard state array (tells us the current state of the keyboard) - uInt8* myKeyTable; + const bool* myKeyTable; // System cycle at which the update() method is called // Multiple calls at the same cycle should be ignored diff --git a/src/emucore/Event.hxx b/src/emucore/Event.hxx index c007620d0..95573851c 100644 --- a/src/emucore/Event.hxx +++ b/src/emucore/Event.hxx @@ -21,6 +21,7 @@ #define EVENT_HXX #include "bspf.hxx" +#include "StellaKeys.hxx" class Event; @@ -107,11 +108,27 @@ class Event { for(uInt32 i = 0; i < LastType; ++i) myValues[i] = Event::NoType; + + for(uInt32 i = 0; i < KBDK_LAST; ++i) + myKeyTable[i] = false; } + /** + Get the keytable associated with this event + */ + const bool* getKeys() const { return myKeyTable; } + + /** + Set the value associated with the event of the specified type + */ + void setKey(StellaKey key, bool state) { myKeyTable[key] = state; } + private: // Array of values associated with each event type Int32 myValues[LastType]; + + // Array of keyboard key states + bool myKeyTable[KBDK_LAST]; }; #endif diff --git a/src/emucore/EventHandler.cxx b/src/emucore/EventHandler.cxx index 186ab65a8..e32682e88 100644 --- a/src/emucore/EventHandler.cxx +++ b/src/emucore/EventHandler.cxx @@ -329,6 +329,9 @@ void EventHandler::poll(uInt64 time) bool state = event.key.type == SDL_KEYDOWN; bool handled = true; + // Immediately store the key state + myEvent.setKey(key, state); + // An attempt to speed up event processing // All SDL-specific event actions are accessed by either // Control or Alt/Cmd keys. So we quickly check for those.