SDL-1.2: atari: add support for Milan's AltGr

From ea0674c911d262a05a600f09ae3552d01850d81e Mon Sep 17 00:00:00 2001
From: Miro Kropacek <[EMAIL REDACTED]>
Date: Sat, 11 May 2024 20:26:34 +0200
Subject: [PATCH] atari: add support for Milan's AltGr

---
 src/video/ataricommon/SDL_atarievents.c  | 1 +
 src/video/ataricommon/SDL_atarikeys.h    | 1 +
 src/video/ataricommon/SDL_biosevents.c   | 1 +
 src/video/ataricommon/SDL_gemdosevents.c | 1 +
 src/video/ataricommon/SDL_ikbdevents.c   | 6 ++++++
 src/video/gem/SDL_gemevents.c            | 3 ++-
 6 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/video/ataricommon/SDL_atarievents.c b/src/video/ataricommon/SDL_atarievents.c
index b486d899..a5172de3 100644
--- a/src/video/ataricommon/SDL_atarievents.c
+++ b/src/video/ataricommon/SDL_atarievents.c
@@ -174,6 +174,7 @@ void SDL_Atari_InitInternalKeymap(_THIS)
 	keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
 	keymap[SCANCODE_LEFTALT] = SDLK_LALT;
 	keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
+	keymap[SCANCODE_ALTGR] = SDLK_MODE;
 }
 
 void Atari_PumpEvents(_THIS)
diff --git a/src/video/ataricommon/SDL_atarikeys.h b/src/video/ataricommon/SDL_atarikeys.h
index ed286540..99bcf668 100644
--- a/src/video/ataricommon/SDL_atarikeys.h
+++ b/src/video/ataricommon/SDL_atarikeys.h
@@ -94,6 +94,7 @@
 #define SCANCODE_LEFTALT	0x38
 #define SCANCODE_SPACE		0x39
 #define SCANCODE_CAPSLOCK	0x3a
+#define SCANCODE_ALTGR		0x4c	/* Milan's AltGr */
 
 /* Functions keys */
 #define SCANCODE_F1		0x3b
diff --git a/src/video/ataricommon/SDL_biosevents.c b/src/video/ataricommon/SDL_biosevents.c
index 964c7fe4..20d3dd1b 100644
--- a/src/video/ataricommon/SDL_biosevents.c
+++ b/src/video/ataricommon/SDL_biosevents.c
@@ -140,6 +140,7 @@ static void UpdateSpecialKeys(int special_keys_state)
 	UPDATE_SPECIAL_KEYS(K_CTRL, SCANCODE_LEFTCONTROL);
 	UPDATE_SPECIAL_KEYS(K_ALT, SCANCODE_LEFTALT);
 	UPDATE_SPECIAL_KEYS(K_CAPSLOCK, SCANCODE_CAPSLOCK);
+	UPDATE_SPECIAL_KEYS(0x80, SCANCODE_ALTGR);
 }
 
 void AtariBios_ShutdownEvents(void)
diff --git a/src/video/ataricommon/SDL_gemdosevents.c b/src/video/ataricommon/SDL_gemdosevents.c
index b19c4ef8..1e2d4718 100644
--- a/src/video/ataricommon/SDL_gemdosevents.c
+++ b/src/video/ataricommon/SDL_gemdosevents.c
@@ -141,6 +141,7 @@ static void UpdateSpecialKeys(int special_keys_state)
 	UPDATE_SPECIAL_KEYS(K_CTRL, SCANCODE_LEFTCONTROL);
 	UPDATE_SPECIAL_KEYS(K_ALT, SCANCODE_LEFTALT);
 	UPDATE_SPECIAL_KEYS(K_CAPSLOCK, SCANCODE_CAPSLOCK);
+	UPDATE_SPECIAL_KEYS(0x80, SCANCODE_ALTGR);
 }
 
 void AtariGemdos_ShutdownEvents(void)
diff --git a/src/video/ataricommon/SDL_ikbdevents.c b/src/video/ataricommon/SDL_ikbdevents.c
index 13a3f5b5..06074343 100644
--- a/src/video/ataricommon/SDL_ikbdevents.c
+++ b/src/video/ataricommon/SDL_ikbdevents.c
@@ -98,6 +98,9 @@ void AtariIkbd_PumpEvents(_THIS)
 			case SCANCODE_CAPSLOCK:
 				shiftstate |= K_CAPSLOCK;
 				break;
+			case SCANCODE_ALTGR:
+				shiftstate |= 0x80;
+				break;
 			}
 
 			SDL_PrivateKeyboard(SDL_PRESSED,
@@ -130,6 +133,9 @@ void AtariIkbd_PumpEvents(_THIS)
 			case SCANCODE_CAPSLOCK:
 				shiftstate &= ~K_CAPSLOCK;
 				break;
+			case SCANCODE_ALTGR:
+				shiftstate &= ~0x80;
+				break;
 			}
 
 			if (i == SCANCODE_CAPSLOCK) {
diff --git a/src/video/gem/SDL_gemevents.c b/src/video/gem/SDL_gemevents.c
index f662970e..fc091bc4 100644
--- a/src/video/gem/SDL_gemevents.c
+++ b/src/video/gem/SDL_gemevents.c
@@ -131,7 +131,7 @@ void GEM_PumpEvents(_THIS)
 
 		/* Keyboard event ? */
 		if (resultat & MU_KEYBD) {
-			em_out.emo_kmeta |= (Kbshift(-1) & K_CAPSLOCK);	/* MU_KEYBD is not aware of CAPSLOCK */
+			em_out.emo_kmeta |= (Kbshift(-1) & (0x80 | K_CAPSLOCK));	/* MU_KEYBD is not aware of AltGr and CAPSLOCK */
 			do_keyboard_special(em_out.emo_kmeta, cur_tick);
 			if (prevkc != em_out.emo_kreturn) {
 				do_keyboard(em_out.emo_kreturn, cur_tick);
@@ -332,6 +332,7 @@ static void do_keyboard_special(short ks, Uint32 tick)
 	UPDATE_SPECIAL_KEYS(K_CTRL, SCANCODE_LEFTCONTROL);
 	UPDATE_SPECIAL_KEYS(K_ALT, SCANCODE_LEFTALT);
 	UPDATE_SPECIAL_KEYS(K_CAPSLOCK, SCANCODE_CAPSLOCK);
+	UPDATE_SPECIAL_KEYS(0x80, SCANCODE_ALTGR);
 }
 
 static void do_mouse_motion(_THIS, short mx, short my)