sdl12-compat: Modifier keys on Mac OS X do not have scancodes

From e1d7b809d73715491a18db4fe6e2ec7557dfb32a Mon Sep 17 00:00:00 2001
From: David Gow <[EMAIL REDACTED]>
Date: Thu, 10 Jun 2021 21:04:59 +0800
Subject: [PATCH] Modifier keys on Mac OS X do not have scancodes

This actually fixes three related issues:
- Modifier keys on OS X should have "unknown" scancodes
- Unknown scancodes on OS X should have the value 0, even though that
  conflicts with the scancode for "a"
- RGUI and RSHIFT should have scancodes on non-OSX platforms.

SDL 1.2's Quartz backend, used on Mac OS X, always gives modifier keys a
scancode of 0, even though OS X actually does have a scancode number for
them. This can be seen (both for < OS X 10.3, where left and right
modifiers could not be distinguished, and for newer versions where they
can) in the implementation here:

Applications such as DOSBox rely heavily on this behaviour, and the keys
will not function in the default "usescancodes=true" mode if a scancode
other than 0 is returned for the right-hand-side modifier keys.

This can be seen in sdl12-compat GitHub issue #84, where the issue was
 src/SDL12_compat.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/src/SDL12_compat.c b/src/SDL12_compat.c
index 30cee4f..12f3a0c 100644
--- a/src/SDL12_compat.c
+++ b/src/SDL12_compat.c
@@ -2418,7 +2418,7 @@ Scancode20to12(SDL_Scancode sc)
     CASESCANCODE20TO12(BACKSPACE, 0x16, 0x33);
     CASESCANCODE20TO12(C, 0x36, 0x08);
-    CASESCANCODE20TO12(CAPSLOCK, 0x42, 0x39);
+    CASESCANCODE20TO12(CAPSLOCK, 0x42, 0x00);
     CASESCANCODE20TO12(COMMA, 0x3B, 0x2B);
     CASESCANCODE20TO12(D, 0x28, 0x02);
     CASESCANCODE20TO12(DELETE, 0x00, 0x75);
@@ -2466,12 +2466,12 @@ Scancode20to12(SDL_Scancode sc)
     CASESCANCODE20TO12(KP_PERIOD, 0x5B, 0x41);
     CASESCANCODE20TO12(KP_PLUS, 0x56, 0x44);
     CASESCANCODE20TO12(L, 0x2E, 0x25);
-    CASESCANCODE20TO12(LALT, 0x40, 0x3A);
-    CASESCANCODE20TO12(LCTRL, 0x25, 0x3B);
+    CASESCANCODE20TO12(LALT, 0x40, 0x00);
+    CASESCANCODE20TO12(LCTRL, 0x25, 0x00);
     CASESCANCODE20TO12(LEFT, 0x00, 0x7B);
-    CASESCANCODE20TO12(LGUI, 0x85, 0x37);
-    CASESCANCODE20TO12(LSHIFT, 0x32, 0x38);
+    CASESCANCODE20TO12(LGUI, 0x85, 0x00);
+    CASESCANCODE20TO12(LSHIFT, 0x32, 0x00);
     CASESCANCODE20TO12(M, 0x3A, 0x29);
     CASESCANCODE20TO12(MINUS, 0x14, 0x1B);
     CASESCANCODE20TO12(N, 0x39, 0x28);
@@ -2485,8 +2485,10 @@ Scancode20to12(SDL_Scancode sc)
     CASESCANCODE20TO12(Q, 0x18, 0x0C);
     CASESCANCODE20TO12(R, 0x1B, 0x0F);
     CASESCANCODE20TO12(RETURN, 0x24, 0x24);
+    CASESCANCODE20TO12(RGUI, 0x86, 0x00);
     CASESCANCODE20TO12(RIGHT, 0x00, 0x7C);
+    CASESCANCODE20TO12(RSHIFT, 0x3E, 0x00);
     CASESCANCODE20TO12(S, 0x27, 0x01);
@@ -2503,13 +2505,9 @@ Scancode20to12(SDL_Scancode sc)
     CASESCANCODE20TO12(Z, 0x34, 0x06);
 #undef CASESCANCODE20TO12    
-        /* If we don't know it, return 0, which is "unknown" on everything
-           except Mac OS X, where it's "A" for whatever reason. */
-#ifdef __MACOSX__
-        return 0x34;    /* DOSBox should treat this as unknown. */
+        /* If we don't know it, return 0, which is "unknown".
+           It's also "a" on Mac OS X, but SDL 1.2 uses it as "unknown", too. */
         return 0;
     return 0;