From 80b4e29d0a88406a99a78a03874fff9d63beb5cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrea=20Palmat=C3=A8?= Date: Thu, 4 Apr 2024 09:41:00 +0200 Subject: [PATCH] More OS4 fixes --- src/os4_init.c | 336 +++++++++++++++++++++++++++++++-------------- src/os4_joystick.c | 88 +++--------- src/os4_joystick.h | 2 - src/os4_monitor.c | 62 +++------ src/os4_platform.h | 2 - src/os4_window.c | 59 ++++++-- 6 files changed, 321 insertions(+), 228 deletions(-) diff --git a/src/os4_init.c b/src/os4_init.c index c13b69b0..6b5d7384 100644 --- a/src/os4_init.c +++ b/src/os4_init.c @@ -274,128 +274,264 @@ static void closeLibraries(void) } } +static const char* get_key_name(int key) +{ + switch (key) + { + // Printable keys + case GLFW_KEY_A: return "A"; + case GLFW_KEY_B: return "B"; + case GLFW_KEY_C: return "C"; + case GLFW_KEY_D: return "D"; + case GLFW_KEY_E: return "E"; + case GLFW_KEY_F: return "F"; + case GLFW_KEY_G: return "G"; + case GLFW_KEY_H: return "H"; + case GLFW_KEY_I: return "I"; + case GLFW_KEY_J: return "J"; + case GLFW_KEY_K: return "K"; + case GLFW_KEY_L: return "L"; + case GLFW_KEY_M: return "M"; + case GLFW_KEY_N: return "N"; + case GLFW_KEY_O: return "O"; + case GLFW_KEY_P: return "P"; + case GLFW_KEY_Q: return "Q"; + case GLFW_KEY_R: return "R"; + case GLFW_KEY_S: return "S"; + case GLFW_KEY_T: return "T"; + case GLFW_KEY_U: return "U"; + case GLFW_KEY_V: return "V"; + case GLFW_KEY_W: return "W"; + case GLFW_KEY_X: return "X"; + case GLFW_KEY_Y: return "Y"; + case GLFW_KEY_Z: return "Z"; + case GLFW_KEY_1: return "1"; + case GLFW_KEY_2: return "2"; + case GLFW_KEY_3: return "3"; + case GLFW_KEY_4: return "4"; + case GLFW_KEY_5: return "5"; + case GLFW_KEY_6: return "6"; + case GLFW_KEY_7: return "7"; + case GLFW_KEY_8: return "8"; + case GLFW_KEY_9: return "9"; + case GLFW_KEY_0: return "0"; + case GLFW_KEY_SPACE: return "SPACE"; + case GLFW_KEY_MINUS: return "MINUS"; + case GLFW_KEY_EQUAL: return "EQUAL"; + case GLFW_KEY_LEFT_BRACKET: return "LEFT BRACKET"; + case GLFW_KEY_RIGHT_BRACKET: return "RIGHT BRACKET"; + case GLFW_KEY_BACKSLASH: return "BACKSLASH"; + case GLFW_KEY_SEMICOLON: return "SEMICOLON"; + case GLFW_KEY_APOSTROPHE: return "APOSTROPHE"; + case GLFW_KEY_GRAVE_ACCENT: return "GRAVE ACCENT"; + case GLFW_KEY_COMMA: return "COMMA"; + case GLFW_KEY_PERIOD: return "PERIOD"; + case GLFW_KEY_SLASH: return "SLASH"; + case GLFW_KEY_WORLD_1: return "WORLD 1"; + case GLFW_KEY_WORLD_2: return "WORLD 2"; + + // Function keys + case GLFW_KEY_ESCAPE: return "ESCAPE"; + case GLFW_KEY_F1: return "F1"; + case GLFW_KEY_F2: return "F2"; + case GLFW_KEY_F3: return "F3"; + case GLFW_KEY_F4: return "F4"; + case GLFW_KEY_F5: return "F5"; + case GLFW_KEY_F6: return "F6"; + case GLFW_KEY_F7: return "F7"; + case GLFW_KEY_F8: return "F8"; + case GLFW_KEY_F9: return "F9"; + case GLFW_KEY_F10: return "F10"; + case GLFW_KEY_F11: return "F11"; + case GLFW_KEY_F12: return "F12"; + case GLFW_KEY_F13: return "F13"; + case GLFW_KEY_F14: return "F14"; + case GLFW_KEY_F15: return "F15"; + case GLFW_KEY_F16: return "F16"; + case GLFW_KEY_F17: return "F17"; + case GLFW_KEY_F18: return "F18"; + case GLFW_KEY_F19: return "F19"; + case GLFW_KEY_F20: return "F20"; + case GLFW_KEY_F21: return "F21"; + case GLFW_KEY_F22: return "F22"; + case GLFW_KEY_F23: return "F23"; + case GLFW_KEY_F24: return "F24"; + case GLFW_KEY_F25: return "F25"; + case GLFW_KEY_UP: return "UP"; + case GLFW_KEY_DOWN: return "DOWN"; + case GLFW_KEY_LEFT: return "LEFT"; + case GLFW_KEY_RIGHT: return "RIGHT"; + case GLFW_KEY_LEFT_SHIFT: return "LEFT SHIFT"; + case GLFW_KEY_RIGHT_SHIFT: return "RIGHT SHIFT"; + case GLFW_KEY_LEFT_CONTROL: return "LEFT CONTROL"; + case GLFW_KEY_RIGHT_CONTROL: return "RIGHT CONTROL"; + case GLFW_KEY_LEFT_ALT: return "LEFT ALT"; + case GLFW_KEY_RIGHT_ALT: return "RIGHT ALT"; + case GLFW_KEY_TAB: return "TAB"; + case GLFW_KEY_ENTER: return "ENTER"; + case GLFW_KEY_BACKSPACE: return "BACKSPACE"; + case GLFW_KEY_INSERT: return "INSERT"; + case GLFW_KEY_DELETE: return "DELETE"; + case GLFW_KEY_PAGE_UP: return "PAGE UP"; + case GLFW_KEY_PAGE_DOWN: return "PAGE DOWN"; + case GLFW_KEY_HOME: return "HOME"; + case GLFW_KEY_END: return "END"; + case GLFW_KEY_KP_0: return "KEYPAD 0"; + case GLFW_KEY_KP_1: return "KEYPAD 1"; + case GLFW_KEY_KP_2: return "KEYPAD 2"; + case GLFW_KEY_KP_3: return "KEYPAD 3"; + case GLFW_KEY_KP_4: return "KEYPAD 4"; + case GLFW_KEY_KP_5: return "KEYPAD 5"; + case GLFW_KEY_KP_6: return "KEYPAD 6"; + case GLFW_KEY_KP_7: return "KEYPAD 7"; + case GLFW_KEY_KP_8: return "KEYPAD 8"; + case GLFW_KEY_KP_9: return "KEYPAD 9"; + case GLFW_KEY_KP_DIVIDE: return "KEYPAD DIVIDE"; + case GLFW_KEY_KP_MULTIPLY: return "KEYPAD MULTIPLY"; + case GLFW_KEY_KP_SUBTRACT: return "KEYPAD SUBTRACT"; + case GLFW_KEY_KP_ADD: return "KEYPAD ADD"; + case GLFW_KEY_KP_DECIMAL: return "KEYPAD DECIMAL"; + case GLFW_KEY_KP_EQUAL: return "KEYPAD EQUAL"; + case GLFW_KEY_KP_ENTER: return "KEYPAD ENTER"; + case GLFW_KEY_PRINT_SCREEN: return "PRINT SCREEN"; + case GLFW_KEY_NUM_LOCK: return "NUM LOCK"; + case GLFW_KEY_CAPS_LOCK: return "CAPS LOCK"; + case GLFW_KEY_SCROLL_LOCK: return "SCROLL LOCK"; + case GLFW_KEY_PAUSE: return "PAUSE"; + case GLFW_KEY_LEFT_SUPER: return "LEFT SUPER"; + case GLFW_KEY_RIGHT_SUPER: return "RIGHT SUPER"; + case GLFW_KEY_MENU: return "MENU"; + + default: return "UNKNOWN"; + } +} + static void createKeyTables(void) { memset(_glfw.os4.keycodes, -1, sizeof(_glfw.os4.keycodes)); memset(_glfw.os4.scancodes, -1, sizeof(_glfw.os4.scancodes)); + memset(_glfw.os4.keynames, 0, sizeof(_glfw.os4.keynames)); - _glfw.os4.keycodes[0xb] = GLFW_KEY_GRAVE_ACCENT; - _glfw.os4.keycodes[0x1] = GLFW_KEY_1; - _glfw.os4.keycodes[0x2] = GLFW_KEY_2; - _glfw.os4.keycodes[0x3] = GLFW_KEY_3; - _glfw.os4.keycodes[0x4] = GLFW_KEY_4; - _glfw.os4.keycodes[0x5] = GLFW_KEY_5; - _glfw.os4.keycodes[0x6] = GLFW_KEY_6; - _glfw.os4.keycodes[0x7] = GLFW_KEY_7; - _glfw.os4.keycodes[0x8] = GLFW_KEY_8; - _glfw.os4.keycodes[0x9] = GLFW_KEY_9; - _glfw.os4.keycodes[0xa] = GLFW_KEY_0; - _glfw.os4.keycodes[0x40] = GLFW_KEY_SPACE; // - _glfw.os4.keycodes[0x3a] = GLFW_KEY_MINUS; - _glfw.os4.keycodes[0xc] = GLFW_KEY_EQUAL; - _glfw.os4.keycodes[0x10] = GLFW_KEY_Q; - _glfw.os4.keycodes[0x11] = GLFW_KEY_W; - _glfw.os4.keycodes[0x12] = GLFW_KEY_E; - _glfw.os4.keycodes[0x13] = GLFW_KEY_R; - _glfw.os4.keycodes[0x14] = GLFW_KEY_T; - _glfw.os4.keycodes[0x15] = GLFW_KEY_Y; - _glfw.os4.keycodes[0x16] = GLFW_KEY_U; - _glfw.os4.keycodes[0x17] = GLFW_KEY_I; - _glfw.os4.keycodes[0x18] = GLFW_KEY_O; - _glfw.os4.keycodes[0x19] = GLFW_KEY_P; - _glfw.os4.keycodes[0x1a] = GLFW_KEY_LEFT_BRACKET; - _glfw.os4.keycodes[0x1b] = GLFW_KEY_RIGHT_BRACKET; - _glfw.os4.keycodes[0x20] = GLFW_KEY_A; - _glfw.os4.keycodes[0x21] = GLFW_KEY_S; - _glfw.os4.keycodes[0x22] = GLFW_KEY_D; - _glfw.os4.keycodes[0x23] = GLFW_KEY_F; - _glfw.os4.keycodes[0x24] = GLFW_KEY_G; - _glfw.os4.keycodes[0x25] = GLFW_KEY_H; - _glfw.os4.keycodes[0x26] = GLFW_KEY_J; - _glfw.os4.keycodes[0x27] = GLFW_KEY_K; - _glfw.os4.keycodes[0x28] = GLFW_KEY_L; + _glfw.os4.keycodes[0xb] = GLFW_KEY_GRAVE_ACCENT; + _glfw.os4.keycodes[0x1] = GLFW_KEY_1; + _glfw.os4.keycodes[0x2] = GLFW_KEY_2; + _glfw.os4.keycodes[0x3] = GLFW_KEY_3; + _glfw.os4.keycodes[0x4] = GLFW_KEY_4; + _glfw.os4.keycodes[0x5] = GLFW_KEY_5; + _glfw.os4.keycodes[0x6] = GLFW_KEY_6; + _glfw.os4.keycodes[0x7] = GLFW_KEY_7; + _glfw.os4.keycodes[0x8] = GLFW_KEY_8; + _glfw.os4.keycodes[0x9] = GLFW_KEY_9; + _glfw.os4.keycodes[0xa] = GLFW_KEY_0; + _glfw.os4.keycodes[0x40] = GLFW_KEY_SPACE; // + _glfw.os4.keycodes[0x3a] = GLFW_KEY_MINUS; + _glfw.os4.keycodes[0xc] = GLFW_KEY_EQUAL; + _glfw.os4.keycodes[0x10] = GLFW_KEY_Q; + _glfw.os4.keycodes[0x11] = GLFW_KEY_W; + _glfw.os4.keycodes[0x12] = GLFW_KEY_E; + _glfw.os4.keycodes[0x13] = GLFW_KEY_R; + _glfw.os4.keycodes[0x14] = GLFW_KEY_T; + _glfw.os4.keycodes[0x15] = GLFW_KEY_Y; + _glfw.os4.keycodes[0x16] = GLFW_KEY_U; + _glfw.os4.keycodes[0x17] = GLFW_KEY_I; + _glfw.os4.keycodes[0x18] = GLFW_KEY_O; + _glfw.os4.keycodes[0x19] = GLFW_KEY_P; + _glfw.os4.keycodes[0x1a] = GLFW_KEY_LEFT_BRACKET; + _glfw.os4.keycodes[0x1b] = GLFW_KEY_RIGHT_BRACKET; + _glfw.os4.keycodes[0x20] = GLFW_KEY_A; + _glfw.os4.keycodes[0x21] = GLFW_KEY_S; + _glfw.os4.keycodes[0x22] = GLFW_KEY_D; + _glfw.os4.keycodes[0x23] = GLFW_KEY_F; + _glfw.os4.keycodes[0x24] = GLFW_KEY_G; + _glfw.os4.keycodes[0x25] = GLFW_KEY_H; + _glfw.os4.keycodes[0x26] = GLFW_KEY_J; + _glfw.os4.keycodes[0x27] = GLFW_KEY_K; + _glfw.os4.keycodes[0x28] = GLFW_KEY_L; //_glfw.os4.keycodes[KEY_SEMICOLON] = GLFW_KEY_SEMICOLON; //_glfw.os4.keycodes[KEY_APOSTROPHE] = GLFW_KEY_APOSTROPHE; - _glfw.os4.keycodes[0x31] = GLFW_KEY_Z; - _glfw.os4.keycodes[0x32] = GLFW_KEY_X; - _glfw.os4.keycodes[0x33] = GLFW_KEY_C; - _glfw.os4.keycodes[0x34] = GLFW_KEY_V; - _glfw.os4.keycodes[0x35] = GLFW_KEY_B; - _glfw.os4.keycodes[0x36] = GLFW_KEY_N; - _glfw.os4.keycodes[0x37] = GLFW_KEY_M; - _glfw.os4.keycodes[0x38] = GLFW_KEY_COMMA; - _glfw.os4.keycodes[0x39] = GLFW_KEY_PERIOD; - _glfw.os4.keycodes[0x3a] = GLFW_KEY_SLASH; - _glfw.os4.keycodes[0x0] = GLFW_KEY_BACKSLASH; - _glfw.os4.keycodes[RAWKEY_ESC] = GLFW_KEY_ESCAPE; // - _glfw.os4.keycodes[RAWKEY_TAB] = GLFW_KEY_TAB; // - _glfw.os4.keycodes[RAWKEY_LSHIFT] = GLFW_KEY_LEFT_SHIFT; // - _glfw.os4.keycodes[RAWKEY_RSHIFT] = GLFW_KEY_RIGHT_SHIFT; // - _glfw.os4.keycodes[RAWKEY_LCTRL] = GLFW_KEY_LEFT_CONTROL; // - _glfw.os4.keycodes[RAWKEY_LCTRL] = GLFW_KEY_RIGHT_CONTROL; - _glfw.os4.keycodes[RAWKEY_LALT] = GLFW_KEY_LEFT_ALT; // - _glfw.os4.keycodes[RAWKEY_RALT] = GLFW_KEY_RIGHT_ALT; // + _glfw.os4.keycodes[0x31] = GLFW_KEY_Z; + _glfw.os4.keycodes[0x32] = GLFW_KEY_X; + _glfw.os4.keycodes[0x33] = GLFW_KEY_C; + _glfw.os4.keycodes[0x34] = GLFW_KEY_V; + _glfw.os4.keycodes[0x35] = GLFW_KEY_B; + _glfw.os4.keycodes[0x36] = GLFW_KEY_N; + _glfw.os4.keycodes[0x37] = GLFW_KEY_M; + _glfw.os4.keycodes[0x38] = GLFW_KEY_COMMA; + _glfw.os4.keycodes[0x39] = GLFW_KEY_PERIOD; + _glfw.os4.keycodes[0x3a] = GLFW_KEY_SLASH; + _glfw.os4.keycodes[0x0] = GLFW_KEY_BACKSLASH; + _glfw.os4.keycodes[RAWKEY_ESC] = GLFW_KEY_ESCAPE; // + _glfw.os4.keycodes[RAWKEY_TAB] = GLFW_KEY_TAB; // + _glfw.os4.keycodes[RAWKEY_LSHIFT] = GLFW_KEY_LEFT_SHIFT; // + _glfw.os4.keycodes[RAWKEY_RSHIFT] = GLFW_KEY_RIGHT_SHIFT; // + _glfw.os4.keycodes[RAWKEY_LCTRL] = GLFW_KEY_LEFT_CONTROL; // + _glfw.os4.keycodes[RAWKEY_LCTRL] = GLFW_KEY_RIGHT_CONTROL; + _glfw.os4.keycodes[RAWKEY_LALT] = GLFW_KEY_LEFT_ALT; // + _glfw.os4.keycodes[RAWKEY_RALT] = GLFW_KEY_RIGHT_ALT; // _glfw.os4.keycodes[RAWKEY_LCOMMAND] = GLFW_KEY_LEFT_SUPER; // _glfw.os4.keycodes[RAWKEY_RCOMMAND] = GLFW_KEY_RIGHT_SUPER; - _glfw.os4.keycodes[RAWKEY_MENU] = GLFW_KEY_MENU; // + _glfw.os4.keycodes[RAWKEY_MENU] = GLFW_KEY_MENU; // //_glfw.os4.keycodes[KEY_NUMLOCK] = GLFW_KEY_NUM_LOCK; _glfw.os4.keycodes[RAWKEY_CAPSLOCK] = GLFW_KEY_CAPS_LOCK; // - _glfw.os4.keycodes[RAWKEY_BREAK] = GLFW_KEY_PRINT_SCREEN; - _glfw.os4.keycodes[0x5f] = GLFW_KEY_SCROLL_LOCK; - _glfw.os4.keycodes[RAWKEY_BREAK] = GLFW_KEY_PAUSE; - _glfw.os4.keycodes[RAWKEY_DEL] = GLFW_KEY_DELETE; // + _glfw.os4.keycodes[RAWKEY_BREAK] = GLFW_KEY_PRINT_SCREEN; + _glfw.os4.keycodes[0x5f] = GLFW_KEY_SCROLL_LOCK; + _glfw.os4.keycodes[RAWKEY_BREAK] = GLFW_KEY_PAUSE; + _glfw.os4.keycodes[RAWKEY_DEL] = GLFW_KEY_DELETE; // _glfw.os4.keycodes[RAWKEY_BACKSPACE] = GLFW_KEY_BACKSPACE; // - _glfw.os4.keycodes[RAWKEY_RETURN] = GLFW_KEY_ENTER; // - _glfw.os4.keycodes[RAWKEY_HOME] = GLFW_KEY_HOME; // - _glfw.os4.keycodes[RAWKEY_END] = GLFW_KEY_END; // - _glfw.os4.keycodes[RAWKEY_PAGEUP] = GLFW_KEY_PAGE_UP; // + _glfw.os4.keycodes[RAWKEY_RETURN] = GLFW_KEY_ENTER; // + _glfw.os4.keycodes[RAWKEY_HOME] = GLFW_KEY_HOME; // + _glfw.os4.keycodes[RAWKEY_END] = GLFW_KEY_END; // + _glfw.os4.keycodes[RAWKEY_PAGEUP] = GLFW_KEY_PAGE_UP; // _glfw.os4.keycodes[RAWKEY_PAGEDOWN] = GLFW_KEY_PAGE_DOWN; // - _glfw.os4.keycodes[RAWKEY_INSERT] = GLFW_KEY_INSERT; // + _glfw.os4.keycodes[RAWKEY_INSERT] = GLFW_KEY_INSERT; // _glfw.os4.keycodes[RAWKEY_CRSRLEFT] = GLFW_KEY_LEFT; _glfw.os4.keycodes[RAWKEY_CRSRRIGHT] = GLFW_KEY_RIGHT; // _glfw.os4.keycodes[RAWKEY_CRSRDOWN] = GLFW_KEY_DOWN; // - _glfw.os4.keycodes[RAWKEY_CRSRUP] = GLFW_KEY_UP; // - _glfw.os4.keycodes[RAWKEY_F1] = GLFW_KEY_F1; // - _glfw.os4.keycodes[RAWKEY_F2] = GLFW_KEY_F2; // - _glfw.os4.keycodes[RAWKEY_F3] = GLFW_KEY_F3; // - _glfw.os4.keycodes[RAWKEY_F4] = GLFW_KEY_F4; // - _glfw.os4.keycodes[RAWKEY_F5] = GLFW_KEY_F5; // - _glfw.os4.keycodes[RAWKEY_F6] = GLFW_KEY_F6; // - _glfw.os4.keycodes[RAWKEY_F7] = GLFW_KEY_F7; // - _glfw.os4.keycodes[RAWKEY_F8] = GLFW_KEY_F8; // - _glfw.os4.keycodes[RAWKEY_F9] = GLFW_KEY_F9; // - _glfw.os4.keycodes[RAWKEY_F10] = GLFW_KEY_F10; // - _glfw.os4.keycodes[RAWKEY_F11] = GLFW_KEY_F11; // - _glfw.os4.keycodes[RAWKEY_F12] = GLFW_KEY_F12; // - _glfw.os4.keycodes[RAWKEY_F13] = GLFW_KEY_F13; // - _glfw.os4.keycodes[RAWKEY_F14] = GLFW_KEY_F14; // - _glfw.os4.keycodes[RAWKEY_F15] = GLFW_KEY_F15; // - _glfw.os4.keycodes[RAWKEY_HELP] = GLFW_KEY_F16; // Mapped amiga HELP key with F16 - _glfw.os4.keycodes[0x5c] = GLFW_KEY_KP_DIVIDE; - _glfw.os4.keycodes[0x5d] = GLFW_KEY_KP_MULTIPLY; - _glfw.os4.keycodes[0x4a] = GLFW_KEY_KP_SUBTRACT; - _glfw.os4.keycodes[0x5e] = GLFW_KEY_KP_ADD; - _glfw.os4.keycodes[0xf] = GLFW_KEY_KP_0; - _glfw.os4.keycodes[0x1d] = GLFW_KEY_KP_1; - _glfw.os4.keycodes[0x1e] = GLFW_KEY_KP_2; - _glfw.os4.keycodes[0x1f] = GLFW_KEY_KP_3; - _glfw.os4.keycodes[0x2d] = GLFW_KEY_KP_4; - _glfw.os4.keycodes[0x2e] = GLFW_KEY_KP_5; - _glfw.os4.keycodes[0x2f] = GLFW_KEY_KP_6; - _glfw.os4.keycodes[0x3d] = GLFW_KEY_KP_7; - _glfw.os4.keycodes[0x3e] = GLFW_KEY_KP_8; - _glfw.os4.keycodes[0x3f] = GLFW_KEY_KP_9; - _glfw.os4.keycodes[0x3c] = GLFW_KEY_KP_DECIMAL; + _glfw.os4.keycodes[RAWKEY_CRSRUP] = GLFW_KEY_UP; // + _glfw.os4.keycodes[RAWKEY_F1] = GLFW_KEY_F1; // + _glfw.os4.keycodes[RAWKEY_F2] = GLFW_KEY_F2; // + _glfw.os4.keycodes[RAWKEY_F3] = GLFW_KEY_F3; // + _glfw.os4.keycodes[RAWKEY_F4] = GLFW_KEY_F4; // + _glfw.os4.keycodes[RAWKEY_F5] = GLFW_KEY_F5; // + _glfw.os4.keycodes[RAWKEY_F6] = GLFW_KEY_F6; // + _glfw.os4.keycodes[RAWKEY_F7] = GLFW_KEY_F7; // + _glfw.os4.keycodes[RAWKEY_F8] = GLFW_KEY_F8; // + _glfw.os4.keycodes[RAWKEY_F9] = GLFW_KEY_F9; // + _glfw.os4.keycodes[RAWKEY_F10] = GLFW_KEY_F10; // + _glfw.os4.keycodes[RAWKEY_F11] = GLFW_KEY_F11; // + _glfw.os4.keycodes[RAWKEY_F12] = GLFW_KEY_F12; // + _glfw.os4.keycodes[RAWKEY_F13] = GLFW_KEY_F13; // + _glfw.os4.keycodes[RAWKEY_F14] = GLFW_KEY_F14; // + _glfw.os4.keycodes[RAWKEY_F15] = GLFW_KEY_F15; // + _glfw.os4.keycodes[RAWKEY_HELP] = GLFW_KEY_F16; // Mapped amiga HELP key with F16 + _glfw.os4.keycodes[0x5c] = GLFW_KEY_KP_DIVIDE; + _glfw.os4.keycodes[0x5d] = GLFW_KEY_KP_MULTIPLY; + _glfw.os4.keycodes[0x4a] = GLFW_KEY_KP_SUBTRACT; + _glfw.os4.keycodes[0x5e] = GLFW_KEY_KP_ADD; + _glfw.os4.keycodes[0xf] = GLFW_KEY_KP_0; + _glfw.os4.keycodes[0x1d] = GLFW_KEY_KP_1; + _glfw.os4.keycodes[0x1e] = GLFW_KEY_KP_2; + _glfw.os4.keycodes[0x1f] = GLFW_KEY_KP_3; + _glfw.os4.keycodes[0x2d] = GLFW_KEY_KP_4; + _glfw.os4.keycodes[0x2e] = GLFW_KEY_KP_5; + _glfw.os4.keycodes[0x2f] = GLFW_KEY_KP_6; + _glfw.os4.keycodes[0x3d] = GLFW_KEY_KP_7; + _glfw.os4.keycodes[0x3e] = GLFW_KEY_KP_8; + _glfw.os4.keycodes[0x3f] = GLFW_KEY_KP_9; + _glfw.os4.keycodes[0x3c] = GLFW_KEY_KP_DECIMAL; /* _glfw.os4.keycodes[KEY_KPEQUAL] = GLFW_KEY_KP_EQUAL; */ - _glfw.os4.keycodes[RAWKEY_ENTER] = GLFW_KEY_KP_ENTER; // + _glfw.os4.keycodes[RAWKEY_ENTER] = GLFW_KEY_KP_ENTER; // - for (int scancode = 0; scancode < 512; scancode++) - { + for (int scancode = 0; scancode < 512; scancode++) { if (_glfw.os4.keycodes[scancode] > 0) _glfw.os4.scancodes[_glfw.os4.keycodes[scancode]] = scancode; } + + for (int i = GLFW_KEY_SPACE; i < GLFW_KEY_LAST; i++) { + strncpy(_glfw.os4.keynames[i], get_key_name(_glfw.os4.keycodes[i]), 16); + } } ////////////////////////////////////////////////////////////////////////// @@ -497,9 +633,7 @@ int _glfwInitOS4(void) return GLFW_FALSE; } - OS4_LockPubScreen(); _glfwPollMonitorsOS4(); - OS4_UnlockPubScreen(); OS4_FindApplicationName(); diff --git a/src/os4_joystick.c b/src/os4_joystick.c index bae16c51..28efe7ee 100644 --- a/src/os4_joystick.c +++ b/src/os4_joystick.c @@ -58,11 +58,7 @@ AMIGAINPUT_Close(_GLFWjoystick * joystick) { dprintf("Closing joystick #%d (AI ID=%ld)\n", joystick->os4js.instance_id, joystick->os4js.joystickList[joystick->os4js.instance_id].id); if (joystick->os4js.hwdata) { -#if OLDSDK GLFW_IAIN->AIN_ReleaseDevice(joystick->os4js.hwdata->context, joystick->os4js.hwdata->handle); -#else - GLFW_IAIN->ReleaseDevice(joystick->os4js.hwdata->context, joystick->os4js.hwdata->handle); -#endif _glfw_free(joystick->os4js.hwdata); joystick->os4js.hwdata = NULL; @@ -81,13 +77,9 @@ AMIGAINPUT_Open(_GLFWjoystick * joysticks, int device_index) AIN_DeviceHandle *handle; AIN_DeviceID id = joystick->os4js.joystickList[joystick->os4js.instance_id].id; -#if OLDSDK handle = GLFW_IAIN->AIN_ObtainDevice(_glfw.os4js.joystickContext, id); -#else - handle = GLFW_IAIN->ObtainDevice(_glfw.os4js.joystickContext, id); -#endif - printf("Opening joystick #%ld (AI ID=%ld)\n", joystick->os4js.instance_id, id); + dprintf("Opening joystick #%ld (AI ID=%ld)\n", joystick->os4js.instance_id, id); if (handle) { joystick->os4js.hwdata = _glfw_calloc(1, sizeof(struct joystick_hwdata)); @@ -109,17 +101,11 @@ AMIGAINPUT_Open(_GLFWjoystick * joysticks, int device_index) strncpy(joystick->name, joystick->os4js.joystickList[joystick->os4js.instance_id].name, sizeof(joystick->name) - 1); /* Query number of axes, buttons and hats the device has */ -#if OLDSDK result = result && GLFW_IAIN->AIN_Query(joystick->os4js.hwdata->context, id, AINQ_NUMAXES, 0, &num_axes, 4); result = result && GLFW_IAIN->AIN_Query(joystick->os4js.hwdata->context, id, AINQ_NUMBUTTONS, 0, &num_buttons, 4); result = result && GLFW_IAIN->AIN_Query(joystick->os4js.hwdata->context, id, AINQ_NUMHATS, 0, &num_hats, 4); -#else - result = result && GLFW_IAIN->Query(joystick->os4js.hwdata->context, id, AINQ_NUMAXES, 0, &num_axes, 4); - result = result && GLFW_IAIN->Query(joystick->os4js.hwdata->context, id, AINQ_NUMBUTTONS, 0, &num_buttons, 4); - result = result && GLFW_IAIN->Query(joystick->os4js.hwdata->context, id, AINQ_NUMHATS, 0, &num_hats, 4); -#endif - printf ("Found %d axes, %d buttons, %d hats\n", num_axes, num_buttons, num_hats); + dprintf ("Found %d axes, %d buttons, %d hats\n", num_axes, num_buttons, num_hats); joystick->axisCount = num_axes < MAX_AXES ? num_axes : MAX_AXES; joystick->buttonCount = num_buttons < MAX_BUTTONS ? num_buttons : MAX_BUTTONS; @@ -131,13 +117,8 @@ AMIGAINPUT_Open(_GLFWjoystick * joysticks, int device_index) /* Query offsets in ReadDevice buffer for axes' data */ for (i = 0; i < joystick->axisCount; i++) { -#if OLDSDK result = result && GLFW_IAIN->AIN_Query(joystick->os4js.hwdata->context, id, AINQ_AXIS_OFFSET, i, &(hwdata->axisBufferOffset[i]), 4); result = result && GLFW_IAIN->AIN_Query(joystick->os4js.hwdata->context, id, AINQ_AXISNAME, i, &(hwdata->axisName[i][0]), 32 ); -#else - result = result && GLFW_IAIN->Query(joystick->os4js.hwdata->context, id, AINQ_AXIS_OFFSET, i, &(hwdata->axisBufferOffset[i]), 4); - result = result && GLFW_IAIN->Query(joystick->os4js.hwdata->context, id, AINQ_AXISNAME, i, &(hwdata->axisName[i][0]), 32 ); -#endif } // Sort the axes so that X and Y come first @@ -177,20 +158,12 @@ AMIGAINPUT_Open(_GLFWjoystick * joysticks, int device_index) /* Query offsets in ReadDevice buffer for buttons' data */ for (i = 0; i < joystick->buttonCount; i++) { -#if OLDSDK result = result && GLFW_IAIN->AIN_Query(joystick->os4js.hwdata->context, id, AINQ_BUTTON_OFFSET, i, &(joystick->os4js.hwdata->buttonBufferOffset[i]), 4); -#else - result = result && GLFW_IAIN->Query(joystick->os4js.hwdata->context, id, AINQ_BUTTON_OFFSET, i, &(joystick->os4js.hwdata->buttonBufferOffset[i]), 4); -#endif } /* Query offsets in ReadDevice buffer for hats' data */ for (i = 0; i < joystick->hatCount; i++) { -#if OLDSDK result = result && GLFW_IAIN->AIN_Query(joystick->os4js.hwdata->context, id, AINQ_HAT_OFFSET, i, &(hwdata->hatBufferOffset[i]), 4); -#else - result = result && GLFW_IAIN->Query(joystick->os4js.hwdata->context, id, AINQ_HAT_OFFSET, i, &(hwdata->hatBufferOffset[i]), 4); -#endif } if (result) { @@ -199,19 +172,15 @@ AMIGAINPUT_Open(_GLFWjoystick * joysticks, int device_index) sprintf(guid, "78696e707574%02lx000000000000000000", handle->DeviceID & 0xff); _glfwAllocJoystick(joystick->name, guid, joystick->axisCount, joystick->buttonCount, joystick->hatCount); - printf("Successful\n"); + dprintf("Successful\n"); return 0; } } -#if OLDSDK GLFW_IAIN->AIN_ReleaseDevice (_glfw.os4js.joystickContext, handle); -#else - GLFW_IAIN->ReleaseDevice (_glfw.os4js.joystickContext, handle); -#endif } - printf("Failed\n"); + dprintf("Failed\n"); return GLFW_FALSE; } @@ -229,7 +198,7 @@ AMIGAINPUT_EnumerateJoysticks(AIN_Device *device, void *UserData) BOOL result = FALSE; if (*count < MAX_JOYSTICKS) { - printf("ENUMJOY: id=%ld, type=%ld, axes=%ld, buttons=%ld\n", + dprintf("ENUMJOY: id=%ld, type=%ld, axes=%ld, buttons=%ld\n", *count, (int32)device->Type, (int32)device->NumAxes, @@ -245,35 +214,26 @@ AMIGAINPUT_EnumerateJoysticks(AIN_Device *device, void *UserData) if ((device->NumAxes > 0) && (device->NumButtons > 0)) { /* Then, check whether we can actually obtain the device */ -#if OLDSDK AIN_DeviceHandle *handle = GLFW_IAIN->AIN_ObtainDevice (context, device->DeviceID); -#else - AIN_DeviceHandle *handle = GLFW_IAIN->ObtainDevice (context, device->DeviceID); -#endif - if (handle) { /* Okay. This appears to be a valid device. We'll report it to GLFW. */ joy->id = device->DeviceID; joy->name = _glfw_strdup(device->DeviceName); - printf("Found joystick #%ld (AI ID=%ld) '%s'\n", *count, joy->id, joy->name); + dprintf("Found joystick #%ld (AI ID=%ld) '%s'\n", *count, joy->id, joy->name); (*count)++; -#if OLDSDK GLFW_IAIN->AIN_ReleaseDevice (context, handle); -#else - GLFW_IAIN->ReleaseDevice (context, handle); -#endif result = TRUE; } else - printf("Failed to obtain joystick '%s' (AI ID=%ld) - ignoring.\n", device->DeviceName, device->DeviceID); + dprintf("Failed to obtain joystick '%s' (AI ID=%ld) - ignoring.\n", device->DeviceName, device->DeviceID); } else - printf("Joystick '%s' (AI ID=%ld) has no axes/buttons - ignoring.\n", device->DeviceName, device->DeviceID); + dprintf("Joystick '%s' (AI ID=%ld) has no axes/buttons - ignoring.\n", device->DeviceName, device->DeviceID); } } return result; @@ -285,7 +245,7 @@ AMIGAINPUT_EnumerateJoysticks(AIN_Device *device, void *UserData) GLFWbool _glfwInitJoysticksOS4(void) { - printf("_glfwInitJoysticksOS4\n"); + dprintf("_glfwInitJoysticksOS4\n"); GLFW_AIN_Base = IExec->OpenLibrary("AmigaInput.library", 51); if (GLFW_AIN_Base) { @@ -295,11 +255,7 @@ GLFWbool _glfwInitJoysticksOS4(void) IExec->CloseLibrary(GLFW_AIN_Base); return GLFW_FALSE; } -#if OLDSDK _glfw.os4js.joystickContext = GLFW_IAIN->AIN_CreateContext(1, NULL); -#else - _glfw.os4js.joystickContext = GLFW_IAIN->CreateContext(1, NULL); -#endif if (_glfw.os4js.joystickContext) { struct enumPacket packet = { _glfw.os4js.joystickContext, @@ -307,13 +263,9 @@ GLFWbool _glfwInitJoysticksOS4(void) &_glfw.os4js.joystickList[0] }; -#if OLDSDK BOOL result = GLFW_IAIN->AIN_EnumDevices(_glfw.os4js.joystickContext, AMIGAINPUT_EnumerateJoysticks, &packet); -#else - BOOL result = GLFW_IAIN->EnumDevices(_glfw.os4js.joystickContext, AMIGAINPUT_EnumerateJoysticks, &packet); -#endif - printf("EnumDevices returned %d\n", result); - printf("Found %ld joysticks\n", _glfw.os4js.joystickCount); + dprintf("EnumDevices returned %d\n", result); + dprintf("Found %ld joysticks\n", _glfw.os4js.joystickCount); if (result) { /* @@ -325,14 +277,14 @@ GLFWbool _glfwInitJoysticksOS4(void) int i; for (i = 0; i < _glfw.os4js.joystickCount; i++) { - printf("Add joystick %d\n", i); + dprintf("Add joystick %d\n", i); AMIGAINPUT_Open(_glfw.joysticks, i); } } return GLFW_TRUE; } } else { - printf("Failed to open AmigaInput.library\n"); + dprintf("Failed to open AmigaInput.library\n"); } return GLFW_FALSE; @@ -344,7 +296,7 @@ void _glfwTerminateJoysticksOS4(void) uint32 i; for (i = 0; i < _glfw.os4js.joystickCount; i++) { - printf("_glfw_free joystickList[i].name\n"); + dprintf("_glfw_free joystickList[i].name\n"); AMIGAINPUT_Close(_glfw.joysticks + i); _glfw_free((char *)_glfw.os4js.joystickList[i].name); } @@ -352,12 +304,8 @@ void _glfwTerminateJoysticksOS4(void) _glfw.os4js.joystickCount = 0; if (_glfw.os4js.joystickContext) { - printf("AIN_DeleteContext\n"); -#if OLDSDK + dprintf("AIN_DeleteContext\n"); GLFW_IAIN->AIN_DeleteContext(_glfw.os4js.joystickContext); -#else - GLFW_IAIN->DeleteContext(_glfw.os4js.joystickContext); -#endif _glfw.os4js.joystickContext = NULL; } @@ -370,16 +318,12 @@ int _glfwPollJoystickOS4(_GLFWjoystick* joystick, int mode) struct joystick_hwdata *hwdata = joystick->os4js.hwdata; void *buffer; - //printf("Called %p\n", hwdata); + //dprintf("Called %p\n", hwdata); /* * Poll device for data */ -#if OLDSDK if (hwdata && GLFW_IAIN->AIN_ReadDevice(hwdata->context, hwdata->handle, &buffer)) -#else - if (hwdata && GLFW_IAIN->ReadDevice(hwdata->context, hwdata->handle, &buffer)) -#endif { int i; diff --git a/src/os4_joystick.h b/src/os4_joystick.h index 29915144..2e40b718 100644 --- a/src/os4_joystick.h +++ b/src/os4_joystick.h @@ -24,8 +24,6 @@ // //======================================================================== -#define OLDSDK 1 - #include #include diff --git a/src/os4_monitor.c b/src/os4_monitor.c index d4d0bcac..1bbf01cf 100644 --- a/src/os4_monitor.c +++ b/src/os4_monitor.c @@ -119,29 +119,32 @@ void _glfwPollMonitorsOS4(void) struct DimensionInfo diminfo; APTR handle; ULONG modeid; + _glfw.os4.publicScreen = IIntuition->LockPubScreen(NULL); + if (_glfw.os4.publicScreen != NULL) { + IIntuition->GetScreenAttrs(_glfw.os4.publicScreen, SA_DisplayID, &modeid, TAG_DONE); - IIntuition->GetScreenAttrs(_glfw.os4.publicScreen, SA_DisplayID, &modeid, TAG_DONE); + handle = IGraphics->FindDisplayInfo(modeid); + if (handle) { + if (IGraphics->GetDisplayInfoData(handle, (UBYTE *)&diminfo, sizeof(diminfo), DTAG_DIMS, 0)) { + GLFW_DisplayModeData *data; + data = (GLFW_DisplayModeData *) malloc(sizeof(*data)); + if (data) { + data->modeid = modeid; + data->x = diminfo.Nominal.MinX; + data->y = diminfo.Nominal.MinY; + data->depth = diminfo.MaxDepth; - handle = IGraphics->FindDisplayInfo(modeid); - if (handle) { - if (IGraphics->GetDisplayInfoData(handle, (UBYTE *)&diminfo, sizeof(diminfo), DTAG_DIMS, 0)) { - GLFW_DisplayModeData *data; - data = (GLFW_DisplayModeData *) malloc(sizeof(*data)); - if (data) { - data->modeid = modeid; - data->x = diminfo.Nominal.MinX; - data->y = diminfo.Nominal.MinY; - data->depth = diminfo.MaxDepth; - - _GLFWmonitor* monitor = _glfwAllocMonitor("OS4 Monitor 0", - (int) (mode.width * 25.4f / dpi), - (int) (mode.height * 25.4f / dpi)); - - monitor->userPointer = data; - - _glfwInputMonitor(monitor, GLFW_CONNECTED, _GLFW_INSERT_FIRST); + _GLFWmonitor* monitor = _glfwAllocMonitor("OS4 Monitor 0", + (int) (mode.width * 25.4f / dpi), + (int) (mode.height * 25.4f / dpi)); + + monitor->userPointer = data; + + _glfwInputMonitor(monitor, GLFW_CONNECTED, _GLFW_INSERT_FIRST); + } } } + IIntuition->UnlockPubScreen(NULL, _glfw.os4.publicScreen); } } @@ -249,24 +252,3 @@ void _glfwSetGammaRampOS4(_GLFWmonitor* monitor, const GLFWgammaramp* ramp) /**********************************************************************************************/ /******************************************** PRIVATE METHODS *********************************/ /**********************************************************************************************/ - -BOOL -OS4_LockPubScreen() -{ - _glfw.os4.publicScreen = IIntuition->LockPubScreen(NULL); - - if (_glfw.os4.publicScreen) { - return TRUE; - } else { - dprintf("Failed to lock Workbench screen\n"); - return FALSE; - } -} - -void -OS4_UnlockPubScreen() -{ - if (_glfw.os4.publicScreen) { - IIntuition->UnlockPubScreen(NULL, _glfw.os4.publicScreen); - } -} \ No newline at end of file diff --git a/src/os4_platform.h b/src/os4_platform.h index dbf3040c..4b2c8e5e 100644 --- a/src/os4_platform.h +++ b/src/os4_platform.h @@ -294,7 +294,5 @@ void _glfwUpdateGamepadGUIDOS4(char* guid); # define kprintf(format, args...)((struct ExecIFace *)((*(struct ExecBase **)4)->MainInterface))->DebugPrintF(format, ## args) #endif /* DEBUG */ -BOOL OS4_LockPubScreen(); -void OS4_UnlockPubScreen(); void OS4_IconifyWindow(_GLFWwindow *window); void OS4_UniconifyWindow(_GLFWwindow* window); diff --git a/src/os4_window.c b/src/os4_window.c index 480bf3bd..51a55a0a 100644 --- a/src/os4_window.c +++ b/src/os4_window.c @@ -53,6 +53,7 @@ static void OS4_CreateIconifyGadget(_GLFWwindow * window); static struct DiskObject *OS4_GetDiskObject(); static void OS4_HandleAppIcon(struct AppMessage * msg); static ULONG OS4_BackFill(const struct Hook *hook, struct RastPort *rastport, struct BackFillMessage *message); +static char *UCS4ToUTF8(uint32_t ch, char *dst); #ifndef MAX #define MAX(a, b) ((a) > (b) ? (a) : (b)) @@ -923,21 +924,31 @@ void _glfwPollEventsOS4(void) case IDCMP_RAWKEY: uint8_t rawkey = msg.Code & 0x7F; - //printf("RAWKEY = 0x%x\n", rawkey); + dprintf("RAWKEY = 0x%x\n", rawkey); int key = _glfw.os4.keycodes[rawkey]; int mods = OS4_TranslateState(msg.Qualifier); const int plain = !(mods & (GLFW_MOD_CONTROL | GLFW_MOD_ALT)); if (imsg->Code < 0x80) { - char text[2]; + char text[5] ={0}; + const uint32 unicode = OS4_TranslateUnicode(msg.Code, msg.Qualifier); + if (unicode) { + UCS4ToUTF8(unicode, text); - text[0] = OS4_TranslateUnicode(msg.Code, msg.Qualifier); - text[1] = '\0'; + _glfwInputKey(window, key, rawkey, GLFW_PRESS, mods); + for (int i = 0; i < 4; i++) { + if (text[0] != '\0') + _glfwInputChar(window, text[i], mods, plain); + } + } + else { + text[0] = OS4_TranslateUnicode(msg.Code, msg.Qualifier); + text[1] = '\0'; - _glfwInputKey(window, key, rawkey, GLFW_PRESS, mods); + _glfwInputKey(window, key, rawkey, GLFW_PRESS, mods); - if (text[0] && text[0] < 0x80) { - _glfwInputChar(window, text[0], mods, plain); + if (text[0] && text[0] < 0x80) + _glfwInputChar(window, text[0], mods, plain); } } else { _glfwInputKey(window, key, rawkey, GLFW_RELEASE, mods); @@ -945,14 +956,14 @@ void _glfwPollEventsOS4(void) break; case IDCMP_MOUSEBUTTONS: - //OS4_HandleMouseButtons(_this, &msg); int button = OS4_GetButton(imsg->Code); int state = OS4_GetButtonState(imsg->Code); + int bmods = OS4_TranslateState(msg.Qualifier); _glfwInputMouseClick(window, button, state, - 0); + bmods); break; case IDCMP_EXTENDEDMOUSE: @@ -1197,12 +1208,12 @@ const char* _glfwGetScancodeNameOS4(int scancode) _glfwInputError(GLFW_INVALID_VALUE, "Invalid OS4 scancode %i", scancode); return NULL; } - return _glfw.os4.keynames[_glfw.os4.keycodes[scancode]]; + return _glfw.os4.keynames[scancode]; } int _glfwGetKeyScancodeOS4(int key) { - return key; + return _glfw.os4.scancodes[key]; } void _glfwGetRequiredInstanceExtensionsOS4(char** extensions) @@ -1589,4 +1600,30 @@ OS4_BackFill(const struct Hook *hook, struct RastPort *rastport, struct BackFill igfx->RectFillColor(&bfRastport, rect->MinX, rect->MinY, rect->MaxX, rect->MaxY, 0xFF000000); return 0; +} + +static +char *UCS4ToUTF8(uint32_t ch, char *dst) +{ + uint8_t *p = (uint8_t *)dst; + if (ch <= 0x7F) { + *p = (uint8_t)ch; + ++dst; + } else if (ch <= 0x7FF) { + p[0] = 0xC0 | (uint8_t)((ch >> 6) & 0x1F); + p[1] = 0x80 | (uint8_t)(ch & 0x3F); + dst += 2; + } else if (ch <= 0xFFFF) { + p[0] = 0xE0 | (uint8_t)((ch >> 12) & 0x0F); + p[1] = 0x80 | (uint8_t)((ch >> 6) & 0x3F); + p[2] = 0x80 | (uint8_t)(ch & 0x3F); + dst += 3; + } else { + p[0] = 0xF0 | (uint8_t)((ch >> 18) & 0x07); + p[1] = 0x80 | (uint8_t)((ch >> 12) & 0x3F); + p[2] = 0x80 | (uint8_t)((ch >> 6) & 0x3F); + p[3] = 0x80 | (uint8_t)(ch & 0x3F); + dst += 4; + } + return dst; } \ No newline at end of file