From e16dd9875936812087a830ba9b5992a9bc3236af Mon Sep 17 00:00:00 2001 From: ejaquay Date: Thu, 22 Jul 2021 22:52:18 -0400 Subject: [PATCH 1/3] keyboardLayout.c Map Pc HOME key to CoCo CLEAR on coco and natural keymaps keyboard.c define ScanCode unsigned char (was signed) config.c Auto select custom keyboard when edit button pushed --- config.c | 17 +++++++++-------- keyboard.c | 9 ++++++--- keyboardLayout.c | 2 ++ 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/config.c b/config.c index 1fc276cf..eacbf7d7 100644 --- a/config.c +++ b/config.c @@ -917,18 +917,19 @@ LRESULT CALLBACK InputConfig(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPar break; case WM_COMMAND: - TempConfig.KeyMap = (unsigned char) - SendDlgItemMessage(hDlg,IDC_KBCONFIG,CB_GETCURSEL,0,0); if (LOWORD(wParam)==IDC_KEYMAPED) { - // Notify user if custom keyboard if not selected but allow edit anyway. + // Insure custom keyboard is selected (unless canceled). if (CurrentConfig.KeyMap != 3) { - MessageBox(0, "The custom keyboard map is not currently applied. For edits " - "to take effect select Custom mapping AND Apply when done.", - "Notice", 0); + TempConfig.KeyMap = 3; + SendDlgItemMessage(hDlg,IDC_KBCONFIG,CB_SETCURSEL,(WPARAM)TempConfig.KeyMap,0); } - DialogBox( EmuState.WindowInstance, (LPCTSTR) IDD_KEYMAPEDIT, hDlg, + + DialogBox( EmuState.WindowInstance, (LPCTSTR) IDD_KEYMAPEDIT, hDlg, (DLGPROC) KeyMapProc ); - } + } else { + TempConfig.KeyMap = (unsigned char) + SendDlgItemMessage(hDlg,IDC_KBCONFIG,CB_GETCURSEL,0,0); + } break; } return(0); diff --git a/keyboard.c b/keyboard.c index 80587fef..738cebef 100644 --- a/keyboard.c +++ b/keyboard.c @@ -47,12 +47,13 @@ This file is part of VCC (Virtual Color Computer). #include "xDebug.h" + /*****************************************************************************/ /* Forward declarations */ -char SetMouseStatus(char, unsigned char); +unsigned char SetMouseStatus(unsigned char, unsigned char); bool pasting = false; //Are the keyboard functions in the middle of a paste operation? /*****************************************************************************/ @@ -671,11 +672,13 @@ unsigned short get_pot_value(unsigned char pot) /*****************************************************************************/ /** */ -char SetMouseStatus(char ScanCode,unsigned char Phase) +unsigned char SetMouseStatus(unsigned char ScanCode,unsigned char Phase) { char ReturnValue=ScanCode; - // Allow extended keyboard arrow keys + // Mask scan code high bit to accept keys from extended keyboard arrow + // keypad. A more elegant solution would be to use the virtual key code + // for joystick mappings but that would require changes to config.c as well. ScanCode = ScanCode & 0x7F; switch (Phase) diff --git a/keyboardLayout.c b/keyboardLayout.c index cf9c076b..a9fd05d1 100644 --- a/keyboardLayout.c +++ b/keyboardLayout.c @@ -164,6 +164,7 @@ keytranslationentry_t keyTranslationsCoCo[] = { DIK_RETURN, 0, 64, 0, 0, 0 }, // ENTER { DIK_NUMPAD7, 0, 64, 1, 0, 0 }, // HOME (CLEAR) + { DIK_HOME, 0, 64, 1, 0, 0 }, // HOME (CLEAR) { DIK_NUMPAD1, 0, 64, 2, 0, 0 }, // ESCAPE (BREAK) { DIK_F1, 0, 64, 5, 0, 0 }, // F1 { DIK_F2, 0, 64, 6, 0, 0 }, // F2 @@ -298,6 +299,7 @@ keytranslationentry_t keyTranslationsNatural[] = { DIK_RETURN, 0, 64, 0, 0, 0 }, // ENTER { DIK_NUMPAD7, 0, 64, 1, 0, 0 }, // HOME (CLEAR) + { DIK_HOME, 0, 64, 1, 0, 0 }, // HOME (CLEAR) { DIK_ESCAPE, 0, 64, 2, 0, 0 }, // ESCAPE (BREAK) { DIK_F12, 0, 64, 2, 0, 0 }, // Alternate ESCAPE (BREAK) (fixes sequence) { DIK_NUMPAD1, 0, 64, 7, 8, 6 }, // END OF LINE (SHIFT)(RIGHT) From 3cd014d611b5423515e5aaef09ee78451924bd81 Mon Sep 17 00:00:00 2001 From: ejaquay Date: Fri, 23 Jul 2021 09:54:37 -0400 Subject: [PATCH 2/3] Prevent bad window size when Vcc.ini is missing config.c prevent write bad window size (x or y < 20 pixels) to inifile clean up reloading of custom keymap keyboardLayout.c add home key mapping to custom keymap fallback --- config.c | 37 ++++++++++++++++++++++--------------- keyboardLayout.c | 1 + 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/config.c b/config.c index eacbf7d7..136f425a 100644 --- a/config.c +++ b/config.c @@ -221,7 +221,14 @@ void LoadConfig(SystemState *LCState) unsigned char WriteIniFile(void) { POINT tp = GetCurWindowSize(); - CurrentConfig.Resize = 1; + CurrentConfig.Resize = 1; // How to restore default window size? + + // Prevent bad window size being written to the inifile + if ((tp.x < 20) || (tp.y < 20)) { + tp.x = 640; + tp.y = 480; + } + GetCurrentModule(CurrentConfig.ModulePath); ValidatePath(CurrentConfig.ModulePath); ValidatePath(CurrentConfig.ExternalBasicImage); @@ -449,8 +456,6 @@ LRESULT CALLBACK Config(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) SoundInit(EmuState.WindowHandle,SoundCards[TempConfig.SndOutDev].Guid,TempConfig.AudioRate); CurrentConfig=TempConfig; - - if (CurrentConfig.KeyMap == kKBLayoutCustom) LoadCustomKeyMap(GetKeyMapFilePath()); vccKeyboardBuildRuntimeTable((keyboardlayout_e)CurrentConfig.KeyMap); Right=TempRight; @@ -477,8 +482,6 @@ LRESULT CALLBACK Config(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) SoundInit(EmuState.WindowHandle,SoundCards[TempConfig.SndOutDev].Guid,TempConfig.AudioRate); CurrentConfig=TempConfig; - - if (CurrentConfig.KeyMap == kKBLayoutCustom) LoadCustomKeyMap(GetKeyMapFilePath()); vccKeyboardBuildRuntimeTable((keyboardlayout_e)CurrentConfig.KeyMap); Right=TempRight; @@ -917,19 +920,23 @@ LRESULT CALLBACK InputConfig(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPar break; case WM_COMMAND: - if (LOWORD(wParam)==IDC_KEYMAPED) { - // Insure custom keyboard is selected (unless canceled). - if (CurrentConfig.KeyMap != 3) { - TempConfig.KeyMap = 3; - SendDlgItemMessage(hDlg,IDC_KBCONFIG,CB_SETCURSEL,(WPARAM)TempConfig.KeyMap,0); - } - + // If Custom keymap button pushed + if (LOWORD(wParam)==IDC_KEYMAPED) { + // Insure custom keyboard is selected. + if (TempConfig.KeyMap != kKBLayoutCustom) { + TempConfig.KeyMap = kKBLayoutCustom; + SendDlgItemMessage(hDlg,IDC_KBCONFIG,CB_SETCURSEL, + (WPARAM)TempConfig.KeyMap,0); + } + // Run the keymap editor DialogBox( EmuState.WindowInstance, (LPCTSTR) IDD_KEYMAPEDIT, hDlg, (DLGPROC) KeyMapProc ); - } else { - TempConfig.KeyMap = (unsigned char) - SendDlgItemMessage(hDlg,IDC_KBCONFIG,CB_GETCURSEL,0,0); + } else { + // Set temporary keymap to the one currently selected + TempConfig.KeyMap = (unsigned char) + SendDlgItemMessage(hDlg,IDC_KBCONFIG,CB_GETCURSEL,0,0); } + break; } return(0); diff --git a/keyboardLayout.c b/keyboardLayout.c index a9fd05d1..4a0a1212 100644 --- a/keyboardLayout.c +++ b/keyboardLayout.c @@ -576,6 +576,7 @@ keytranslationentry_t keyTranslationsCustom[MAX_CTRANSTBLSIZ] = { DIK_RETURN, 0, 64, 0, 0, 0 }, // ENTER { DIK_NUMPAD7, 0, 64, 1, 0, 0 }, // HOME (CLEAR) + { DIK_HOME, 0, 64, 1, 0, 0 }, // HOME (CLEAR) { DIK_ESCAPE, 0, 64, 2, 0, 0 }, // ESCAPE (BREAK) { DIK_NUMPAD1, 0, 64, 7, 8, 6 }, // END OF LINE (SHIFT)(RIGHT) { DIK_NUMPADPERIOD, 0, 64, 4, 8, 5 }, // DELETE (CTRL)(LEFT) From f38779c07145307d40a71579bbeaf6cdd1057bcd Mon Sep 17 00:00:00 2001 From: ejaquay Date: Fri, 23 Jul 2021 14:23:48 -0400 Subject: [PATCH 3/3] Set mappings for PC END key to match KEYPAD 1 for hardcoded keymaps --- keyboardLayout.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/keyboardLayout.c b/keyboardLayout.c index 4a0a1212..cf7b9b00 100644 --- a/keyboardLayout.c +++ b/keyboardLayout.c @@ -164,8 +164,9 @@ keytranslationentry_t keyTranslationsCoCo[] = { DIK_RETURN, 0, 64, 0, 0, 0 }, // ENTER { DIK_NUMPAD7, 0, 64, 1, 0, 0 }, // HOME (CLEAR) - { DIK_HOME, 0, 64, 1, 0, 0 }, // HOME (CLEAR) - { DIK_NUMPAD1, 0, 64, 2, 0, 0 }, // ESCAPE (BREAK) + { DIK_HOME, 0, 64, 1, 0, 0 }, // HOME (CLEAR) + { DIK_NUMPAD1, 0, 64, 2, 0, 0 }, // ESCAPE (BREAK) + { DIK_END, 0, 64, 2, 0, 0 }, // ESCAPE (BREAK) { DIK_F1, 0, 64, 5, 0, 0 }, // F1 { DIK_F2, 0, 64, 6, 0, 0 }, // F2 { DIK_BACK, 0, 8, 5, 0, 0 }, // BACKSPACE -> CoCo left arrow @@ -303,6 +304,7 @@ keytranslationentry_t keyTranslationsNatural[] = { DIK_ESCAPE, 0, 64, 2, 0, 0 }, // ESCAPE (BREAK) { DIK_F12, 0, 64, 2, 0, 0 }, // Alternate ESCAPE (BREAK) (fixes sequence) { DIK_NUMPAD1, 0, 64, 7, 8, 6 }, // END OF LINE (SHIFT)(RIGHT) + { DIK_END, 0, 64, 7, 8, 6 }, // END OF LINE (SHIFT)(RIGHT) { DIK_NUMPADPERIOD, 0, 64, 4, 8, 5 }, // DELETE (CTRL)(LEFT) { DIK_NUMPAD0, 0, 64, 4, 8, 6 }, // INSERT (CTRL)(RIGHT) { DIK_NUMPAD9, 0, 64, 7, 8, 3 }, // PAGEUP (SHFT)(UP) @@ -579,6 +581,7 @@ keytranslationentry_t keyTranslationsCustom[MAX_CTRANSTBLSIZ] = { DIK_HOME, 0, 64, 1, 0, 0 }, // HOME (CLEAR) { DIK_ESCAPE, 0, 64, 2, 0, 0 }, // ESCAPE (BREAK) { DIK_NUMPAD1, 0, 64, 7, 8, 6 }, // END OF LINE (SHIFT)(RIGHT) + { DIK_END, 0, 64, 7, 8, 6 }, // END OF LINE (SHIFT)(RIGHT) { DIK_NUMPADPERIOD, 0, 64, 4, 8, 5 }, // DELETE (CTRL)(LEFT) { DIK_NUMPAD0, 0, 64, 4, 8, 6 }, // INSERT (CTRL)(RIGHT) { DIK_NUMPAD9, 0, 64, 7, 8, 3 }, // PAGEUP (SHFT)(UP)