From 8f42fb8caf7c2f797bfe0c94a19a3c4eb4d08a17 Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Mon, 4 Dec 2023 19:11:45 +0200 Subject: [PATCH] Added third backslash/f11 option that matches pre-5.0 behavior. --- keybuf.cpp | 27 ++++++++++++++++++++------- od-win32/dinput.cpp | 2 +- od-win32/resources/winuae.rc | 2 +- od-win32/win32.cpp | 8 ++++---- od-win32/win32gui.cpp | 18 +++++++++++++++--- 5 files changed, 41 insertions(+), 16 deletions(-) diff --git a/keybuf.cpp b/keybuf.cpp index e1dc10fe..8ae63184 100644 --- a/keybuf.cpp +++ b/keybuf.cpp @@ -275,6 +275,21 @@ int record_key (int kc) return record_key_direct (kc); } +static void keyswap(int *kcdp, int *kcp, uae_u8 k1, uae_u8 k2) +{ + int kcd = *kcdp; + int kc = *kcp; + if ((kcd & 0x7f) == k1) { + kcd = k2 | (kcd & 0x80); + kc = (kcd << 1) | (kcd >> 7); + } else if ((kcd & 0x7f) == k2) { + kcd = k1 | (kcd & 0x80); + kc = (kcd << 1) | (kcd >> 7); + } + *kcdp = kcd; + *kcp = kc; +} + int record_key_direct (int kc) { int kpb_next = kpb_first + 1; @@ -282,13 +297,11 @@ int record_key_direct (int kc) if (key_swap_hack2) { // $0D <> $0C - if ((kcd & 0x7f) == 0x0c) { - kcd = 0x0d | (kcd & 0x80); - kc = (kcd << 1) | (kcd >> 7); - } else if ((kcd & 0x7f) == 0x0d) { - kcd = 0x0c | (kcd & 0x80); - kc = (kcd << 1) | (kcd >> 7); - } + keyswap(&kcd, &kc, 0x0d, 0x0c); + } + if (key_swap_hack == 2) { + // $2B <> $0D + keyswap(&kcd, &kc, 0x2b, 0x0d); } if (ignore_next_release) { diff --git a/od-win32/dinput.cpp b/od-win32/dinput.cpp index ceff6deb..1aff3ae1 100644 --- a/od-win32/dinput.cpp +++ b/od-win32/dinput.cpp @@ -2463,7 +2463,7 @@ static void handle_rawinput_2 (RAWINPUT *raw, LPARAM lParam) if (rp_isactive ()) return; #endif - if (key_swap_hack) { + if (key_swap_hack == 1) { if (scancode == DIK_F11) { scancode = DIK_EQUALS; } else if (scancode == DIK_EQUALS) { diff --git a/od-win32/resources/winuae.rc b/od-win32/resources/winuae.rc index 58b3e17a..c2189c39 100644 --- a/od-win32/resources/winuae.rc +++ b/od-win32/resources/winuae.rc @@ -929,7 +929,7 @@ BEGIN PUSHBUTTON "Copy from:",IDC_INPUTCOPY,324,267,70,14 COMBOBOX IDC_INPUTCOPYFROM,324,285,70,150,CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_VSCROLL | WS_TABSTOP PUSHBUTTON "Swap 1<>2",IDC_INPUTSWAP,324,302,70,14 - CONTROL "Swap Backslash/F11",IDC_KEYBOARD_SWAPHACK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,209,302,87,10 + CONTROL "Swap Backslash/F11",IDC_KEYBOARD_SWAPHACK,"Button", BS_AUTO3STATE | WS_TABSTOP,209,302,87,10 END IDD_FILTER DIALOGEX 0, 0, 396, 316 diff --git a/od-win32/win32.cpp b/od-win32/win32.cpp index a12403d7..1f4af365 100644 --- a/od-win32/win32.cpp +++ b/od-win32/win32.cpp @@ -6937,10 +6937,6 @@ static int parseargs(const TCHAR *argx, const TCHAR *np, const TCHAR *np2) rp_modem = 1; return 1; } - if (!_tcscmp(arg, _T("key_swap_hack"))) { - key_swap_hack = 1; - return 1; - } if (!_tcscmp(arg, _T("key_swap_hack2"))) { key_swap_hack2 = 1; return 1; @@ -7134,6 +7130,10 @@ static int parseargs(const TCHAR *argx, const TCHAR *np, const TCHAR *np2) } return 2; } + if (!_tcscmp(arg, _T("key_swap_hack"))) { + key_swap_hack = getval(np); + return 2; + } #endif return 0; diff --git a/od-win32/win32gui.cpp b/od-win32/win32gui.cpp index bf3fa74f..541d7681 100644 --- a/od-win32/win32gui.cpp +++ b/od-win32/win32gui.cpp @@ -18559,7 +18559,11 @@ static void values_to_inputdlg (HWND hDlg) SetDlgItemInt (hDlg, IDC_INPUTSPEEDD, workprefs.input_joymouse_speed, FALSE); SetDlgItemInt (hDlg, IDC_INPUTSPEEDA, workprefs.input_joymouse_multiplier, FALSE); CheckDlgButton (hDlg, IDC_INPUTDEVICEDISABLE, (!input_total_devices || inputdevice_get_device_status (input_selected_device)) ? BST_CHECKED : BST_UNCHECKED); - setchecked(hDlg, IDC_KEYBOARD_SWAPHACK, key_swap_hack); + if (key_swap_hack == 2) { + CheckDlgButton(hDlg, IDC_KEYBOARD_SWAPHACK, BST_INDETERMINATE); + } else { + setchecked(hDlg, IDC_KEYBOARD_SWAPHACK, key_swap_hack); + } } static int askinputcustom (HWND hDlg, TCHAR *custom, int maxlen, DWORD titleid) @@ -20136,8 +20140,16 @@ static INT_PTR CALLBACK InputDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM inputdevice_set_device_status (input_selected_device, ischecked (hDlg, IDC_INPUTDEVICEDISABLE)); break; case IDC_KEYBOARD_SWAPHACK: - key_swap_hack = ischecked(hDlg, IDC_KEYBOARD_SWAPHACK); - regsetint(NULL, _T("KeySwapBackslashF11"), key_swap_hack); + { + int v = IsDlgButtonChecked(hDlg, IDC_KEYBOARD_SWAPHACK); + key_swap_hack = v == BST_INDETERMINATE ? 2 : v > 0; + key_swap_hack++; + if (key_swap_hack > 2) { + key_swap_hack = 0; + } + regsetint(NULL, _T("KeySwapBackslashF11"), key_swap_hack); + values_to_inputdlg(hDlg); + } break; default: switch (LOWORD (wParam)) -- 2.47.3