[PATCH] Fix ALT_XXX scancode handling

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


ALT_XXX uses STKey "scancode" member to indicate what 1-3 digit
series of key presses need to be generated.

Using it as an actual scancode needs to be prevented to avoid
overwriting unrelated memory and inject IKBD control codes
(mouse/joy mode changes etc).
---
 src/keymap.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/src/keymap.c b/src/keymap.c
index bd6bec63..422c83eb 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -68,6 +68,7 @@ static const struct
 
 typedef struct
 {
+	/* real scancode, or ALT_XXX code */
 	uint8_t scancode;
 	/* key modifiers matching ST_Modifiers[].mod bit values */
 	uint8_t mods;
@@ -932,7 +933,6 @@ void Keymap_KeyDown(const SDL_Keysym *sdlkey)
 	STScanCode = stkey->scancode;
 	LOG_TRACE(TRACE_KEYMAP, "key map: sym=0x%x to ST-scan=0x%02x\n", symkey, STScanCode);
 
-	assert(Keyboard.KeyStates[scancode] == 0);
 	if (InsertModifiers(stkey->mods, true))
 	{
 		bool done = InsertAltXXXDigits(stkey);
@@ -940,6 +940,8 @@ void Keymap_KeyDown(const SDL_Keysym *sdlkey)
 		if (done)
 			return;
 	}
+	assert(STScanCode < ARRAY_SIZE(Keyboard.KeyStates));
+	assert(Keyboard.KeyStates[STScanCode] == 0);
 	if (!Keyboard.KeyStates[STScanCode])
 	{
 		/* Set down */
@@ -984,12 +986,16 @@ void Keymap_KeyUp(const SDL_Keysym *sdlkey)
 	}
 
 	/* Release key (only if was pressed) */
-	STScanCode = stkey->scancode;
-	assert(Keyboard.KeyStates[STScanCode] > 0);
-	if (Keyboard.KeyStates[STScanCode])
+	if (!(stkey->mods & ALT_XXX_BIT))
 	{
-		IKBD_PressSTKey(STScanCode, false);
-		Keyboard.KeyStates[STScanCode]--;
+		STScanCode = stkey->scancode;
+		assert(STScanCode < ARRAY_SIZE(Keyboard.KeyStates));
+		assert(Keyboard.KeyStates[STScanCode] > 0);
+		if (Keyboard.KeyStates[STScanCode])
+		{
+			IKBD_PressSTKey(STScanCode, false);
+			Keyboard.KeyStates[STScanCode]--;
+		}
 	}
 	if (InsertModifiers(stkey->mods, false))
 	{
-- 
2.30.2


--------------FD3F06539A82B5F443DBCFDE--



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/