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
This commit is contained in:
stephena 2012-04-19 20:11:16 +00:00
parent e1d31ada6e
commit f853518540
6 changed files with 25 additions and 15 deletions

View File

@ -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.

View File

@ -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 */

View File

@ -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();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -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

View File

@ -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

View File

@ -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.