From 7408f50d71c5890bc45055c6fd85b15ea77ef3f4 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Sat, 17 Aug 2019 16:21:37 +0200 Subject: [PATCH] cellKb: improve key conversion --- rpcs3/Emu/Cell/Modules/cellKb.cpp | 165 +++++++++++++----------- rpcs3/Emu/Cell/Modules/cellKb.h | 9 +- rpcs3/Emu/Io/Keyboard.h | 203 ++++++++++++++++++++++++++++++ rpcs3/Emu/Io/KeyboardHandler.cpp | 6 +- rpcs3/Emu/Io/KeyboardHandler.h | 199 +---------------------------- rpcs3/basic_keyboard_handler.cpp | 10 +- rpcs3/emucore.vcxproj | 1 + rpcs3/emucore.vcxproj.filters | 3 + 8 files changed, 314 insertions(+), 282 deletions(-) create mode 100644 rpcs3/Emu/Io/Keyboard.h diff --git a/rpcs3/Emu/Cell/Modules/cellKb.cpp b/rpcs3/Emu/Cell/Modules/cellKb.cpp index e1c9f5254d..0568bcd2d1 100644 --- a/rpcs3/Emu/Cell/Modules/cellKb.cpp +++ b/rpcs3/Emu/Cell/Modules/cellKb.cpp @@ -6,8 +6,6 @@ #include "Emu/Io/KeyboardHandler.h" #include "cellKb.h" - - extern logs::channel sys_io; template<> @@ -93,7 +91,7 @@ error_code cellKbClearBuf(u32 port_no) u16 cellKbCnvRawCode(u32 arrange, u32 mkey, u32 led, u16 rawcode) { - sys_io.trace("cellKbCnvRawCode(arrange=%d, mkey=%d, led=%d, rawcode=%d)", arrange, mkey, led, rawcode); + sys_io.trace("cellKbCnvRawCode(arrange=%d, mkey=%d, led=%d, rawcode=0x%x)", arrange, mkey, led, rawcode); // CELL_KB_RAWDAT if (rawcode <= 0x03 || rawcode == 0x29 || rawcode == 0x35 || (rawcode >= 0x39 && rawcode <= 0x53) || rawcode == 0x65 || rawcode == 0x88 || rawcode == 0x8A || rawcode == 0x8B) @@ -101,94 +99,113 @@ u16 cellKbCnvRawCode(u32 arrange, u32 mkey, u32 led, u16 rawcode) return rawcode | 0x8000; } + const bool is_alt = mkey & (CELL_KB_MKEY_L_ALT | CELL_KB_MKEY_R_ALT); + const bool is_shift = mkey & (CELL_KB_MKEY_L_SHIFT | CELL_KB_MKEY_R_SHIFT); + const bool is_caps_lock = led & (CELL_KB_LED_CAPS_LOCK); + const bool is_num_lock = led & (CELL_KB_LED_NUM_LOCK); + // CELL_KB_NUMPAD - if (rawcode >= 0x59 && rawcode <= 0x61) return (rawcode - 0x28) | 0x4000; // '1' - '9' - if (rawcode == 0x62) return 0x30 | 0x4000; // '0' - if (rawcode == 0x53) return 0x00 | 0x4000; // 'Num Lock' - if (rawcode == 0x54) return 0x2F | 0x4000; // '/' - if (rawcode == 0x55) return 0x2A | 0x4000; // '*' - if (rawcode == 0x56) return 0x2D | 0x4000; // '-' - if (rawcode == 0x57) return 0x2B | 0x4000; // '+' - if (rawcode == 0x58) return 0x0A | 0x4000; // '\n' + + if (is_num_lock) + { + if (rawcode == CELL_KEYC_KPAD_NUMLOCK) return 0x00 | 0x4000; // 'Num Lock' + if (rawcode == CELL_KEYC_KPAD_SLASH) return 0x2F | 0x4000; // '/' + if (rawcode == CELL_KEYC_KPAD_ASTERISK) return 0x2A | 0x4000; // '*' + if (rawcode == CELL_KEYC_KPAD_MINUS) return 0x2D | 0x4000; // '-' + if (rawcode == CELL_KEYC_KPAD_PLUS) return 0x2B | 0x4000; // '+' + if (rawcode == CELL_KEYC_KPAD_ENTER) return 0x0A | 0x4000; // '\n' + if (rawcode == CELL_KEYC_KPAD_0) return 0x30 | 0x4000; // '0' + if (rawcode >= CELL_KEYC_KPAD_1 && rawcode <= CELL_KEYC_KPAD_9) return (rawcode - 0x28) | 0x4000; // '1' - '9' + } // ASCII - const bool is_shift = mkey & (CELL_KB_MKEY_L_SHIFT | CELL_KB_MKEY_R_SHIFT); - const bool is_caps_lock = led & (CELL_KB_LED_CAPS_LOCK); - - auto get_ascii = [is_shift, is_caps_lock](u16 lower, u16 upper) + const auto get_ascii = [is_alt, is_shift, is_caps_lock](u16 raw, u16 shifted = 0, u16 altered = 0) { - return is_shift || is_caps_lock ? upper : lower; + if ((is_shift || is_caps_lock) && shifted) + { + return shifted; + } + else if (is_alt && altered) + { + return altered; + } + return raw; }; if (arrange == CELL_KB_MAPPING_106) // (Japanese) { - if (rawcode == 0x1E) return get_ascii(rawcode + 0x13, 0x21); // '1' or '!' - if (rawcode == 0x1F) return get_ascii(rawcode + 0x13, 0x22); // '2' or '"' - if (rawcode == 0x20) return get_ascii(rawcode + 0x13, 0x23); // '3' or '#' - if (rawcode == 0x21) return get_ascii(rawcode + 0x13, 0x24); // '4' or '$' - if (rawcode == 0x22) return get_ascii(rawcode + 0x13, 0x25); // '5' or '%' - if (rawcode == 0x23) return get_ascii(rawcode + 0x13, 0x26); // '6' or '&' - if (rawcode == 0x24) return get_ascii(rawcode + 0x13, 0x27); // '7' or ''' - if (rawcode == 0x25) return get_ascii(rawcode + 0x13, 0x28); // '8' or '(' - if (rawcode == 0x26) return get_ascii(rawcode + 0x13, 0x29); // '9' or ')' - if (rawcode == 0x27) return get_ascii(0x303, 0x7E); // '0' or '~' + if (rawcode == CELL_KEYC_1) return get_ascii('1', '!'); + if (rawcode == CELL_KEYC_2) return get_ascii('2', '"'); + if (rawcode == CELL_KEYC_3) return get_ascii('3', '#'); + if (rawcode == CELL_KEYC_4) return get_ascii('4', '$'); + if (rawcode == CELL_KEYC_5) return get_ascii('5', '%'); + if (rawcode == CELL_KEYC_6) return get_ascii('6', '&'); + if (rawcode == CELL_KEYC_7) return get_ascii('7', '\''); + if (rawcode == CELL_KEYC_8) return get_ascii('8', '('); + if (rawcode == CELL_KEYC_9) return get_ascii('9', ')'); + if (rawcode == CELL_KEYC_0) return get_ascii('0', '~'); - if (rawcode == 0x2E) return get_ascii(0x5E, 0x7E); // '^' or '~' - if (rawcode == 0x2F) return get_ascii(0x40, 0x60); // '@' or '`' - if (rawcode == 0x30) return get_ascii(0x5B, 0x7B); // '[' or '{' - if (rawcode == 0x32) return get_ascii(0x5D, 0x7D); // ']' or '}' - if (rawcode == 0x33) return get_ascii(0x3B, 0x2B); // ';' or '+' - if (rawcode == 0x34) return get_ascii(0x3A, 0x2A); // ':' or '*' - if (rawcode == 0x87) return get_ascii(rawcode, 0x5F); // '\' or '_' - if (rawcode == 0x36) return get_ascii(0x2C, 0x3C); // ',' or '<' - if (rawcode == 0x37) return get_ascii(0x2E, 0x3E); // '.' or '>' - if (rawcode == 0x38) return get_ascii(0x2F, 0x3F); // '/' or '?' - if (rawcode == 0x89) return get_ascii(0xBE, 0x7C); // '¥' or '|' + if (rawcode == CELL_KEYC_ACCENT_CIRCONFLEX_106) return get_ascii('^', '~'); + if (rawcode == CELL_KEYC_ATMARK_106) return get_ascii('@', '`'); + if (rawcode == CELL_KEYC_LEFT_BRACKET_106) return get_ascii('[', '{'); + if (rawcode == CELL_KEYC_RIGHT_BRACKET_106) return get_ascii(']', '}'); + if (rawcode == CELL_KEYC_SEMICOLON) return get_ascii(';', '+'); + if (rawcode == CELL_KEYC_COLON_106) return get_ascii(':', '*'); + if (rawcode == CELL_KEYC_COMMA) return get_ascii(',', '<'); + if (rawcode == CELL_KEYC_PERIOD) return get_ascii('.', '>'); + if (rawcode == CELL_KEYC_SLASH) return get_ascii('/', '?'); + if (rawcode == CELL_KEYC_BACKSLASH_106) return get_ascii('\\', '_'); + if (rawcode == CELL_KEYC_YEN_106) return get_ascii('¥', '|'); } else if (arrange == CELL_KB_MAPPING_101) // (US) { - if (rawcode == 0x1E) return get_ascii(rawcode + 0x13, 0x21); // '1' or '!' - if (rawcode == 0x1F) return get_ascii(rawcode + 0x13, 0x40); // '2' or '@' - if (rawcode == 0x20) return get_ascii(rawcode + 0x13, 0x23); // '3' or '#' - if (rawcode == 0x21) return get_ascii(rawcode + 0x13, 0x24); // '4' or '$' - if (rawcode == 0x22) return get_ascii(rawcode + 0x13, 0x25); // '5' or '%' - if (rawcode == 0x23) return get_ascii(rawcode + 0x13, 0x5E); // '6' or '^' - if (rawcode == 0x24) return get_ascii(rawcode + 0x13, 0x26); // '7' or '&' - if (rawcode == 0x25) return get_ascii(rawcode + 0x13, 0x2A); // '8' or '*' - if (rawcode == 0x26) return get_ascii(rawcode + 0x13, 0x28); // '9' or '(' - if (rawcode == 0x27) return get_ascii(0x303, 0x29); // '0' or ')' + if (rawcode == CELL_KEYC_1) return get_ascii('1', '!'); + if (rawcode == CELL_KEYC_2) return get_ascii('2', '@'); + if (rawcode == CELL_KEYC_3) return get_ascii('3', '#'); + if (rawcode == CELL_KEYC_4) return get_ascii('4', '$'); + if (rawcode == CELL_KEYC_5) return get_ascii('5', '%'); + if (rawcode == CELL_KEYC_6) return get_ascii('6', '^'); + if (rawcode == CELL_KEYC_7) return get_ascii('7', '&'); + if (rawcode == CELL_KEYC_8) return get_ascii('8', '*'); + if (rawcode == CELL_KEYC_9) return get_ascii('9', '('); + if (rawcode == CELL_KEYC_0) return get_ascii('0', ')'); - if (rawcode == 0x2D) return get_ascii(0x2D, 0x5F); // '-' or '_' - if (rawcode == 0x2E) return get_ascii(0x3D, 0x2B); // '=' or '+' - if (rawcode == 0x2F) return get_ascii(0x5B, 0x7B); // '[' or '{' - if (rawcode == 0x30) return get_ascii(0x5D, 0x7D); // ']' or '}' - if (rawcode == 0x31) return get_ascii(0x5C, 0x7C); // '\' or '|' - if (rawcode == 0x33) return get_ascii(0x3B, 0x3A); // ';' or ':' - if (rawcode == 0x34) return get_ascii(0x27, 0x22); // ''' or '"' - if (rawcode == 0x36) return get_ascii(0x2C, 0x3C); // ',' or '<' - if (rawcode == 0x37) return get_ascii(0x2E, 0x3E); // '.' or '>' - if (rawcode == 0x38) return get_ascii(0x2F, 0x3F); // '/' or '?' + if (rawcode == CELL_KEYC_MINUS) return get_ascii('-', '_'); + if (rawcode == CELL_KEYC_EQUAL_101) return get_ascii('=', '+'); + if (rawcode == CELL_KEYC_LEFT_BRACKET_101) return get_ascii('[', '{'); + if (rawcode == CELL_KEYC_RIGHT_BRACKET_101) return get_ascii(']', '}'); + if (rawcode == CELL_KEYC_BACKSLASH_101) return get_ascii('\\', '|'); + if (rawcode == CELL_KEYC_SEMICOLON) return get_ascii(';', ':'); + if (rawcode == CELL_KEYC_QUOTATION_101) return get_ascii('\'', '"'); + if (rawcode == CELL_KEYC_COMMA) return get_ascii(',', '<'); + if (rawcode == CELL_KEYC_PERIOD) return get_ascii('.', '>'); + if (rawcode == CELL_KEYC_SLASH) return get_ascii('/', '?'); + if (rawcode == CELL_KEYC_BACK_QUOTE) return get_ascii('`', '~'); } else if (arrange == CELL_KB_MAPPING_GERMAN_GERMANY) { - if (rawcode == 0x1E) return get_ascii(rawcode + 0x13, 0x21); // '1' or '!' - if (rawcode == 0x1F) return get_ascii(rawcode + 0x13, 0x22); // '2' or '"' - if (rawcode == 0x20) return rawcode + 0x13; // '3' (or '�') - if (rawcode == 0x21) return get_ascii(rawcode + 0x13, 0x24); // '4' or '$' - if (rawcode == 0x22) return get_ascii(rawcode + 0x13, 0x25); // '5' or '%' - if (rawcode == 0x23) return get_ascii(rawcode + 0x13, 0x26); // '6' or '&' - if (rawcode == 0x24) return get_ascii(rawcode + 0x13, 0x2F); // '7' or '/' - if (rawcode == 0x25) return get_ascii(rawcode + 0x13, 0x28); // '8' or '(' - if (rawcode == 0x26) return get_ascii(rawcode + 0x13, 0x29); // '9' or ')' - if (rawcode == 0x27) return get_ascii(0x303, 0x3D); // '0' or '=' + if (rawcode == CELL_KEYC_1) return get_ascii('1', '!'); + if (rawcode == CELL_KEYC_2) return get_ascii('2', '"'); + if (rawcode == CELL_KEYC_3) return get_ascii('3', '§'); + if (rawcode == CELL_KEYC_4) return get_ascii('4', '$'); + if (rawcode == CELL_KEYC_5) return get_ascii('5', '%'); + if (rawcode == CELL_KEYC_6) return get_ascii('6', '&'); + if (rawcode == CELL_KEYC_7) return get_ascii('7', '/', '{'); + if (rawcode == CELL_KEYC_8) return get_ascii('8', '(', '['); + if (rawcode == CELL_KEYC_9) return get_ascii('9', ')', ']'); + if (rawcode == CELL_KEYC_0) return get_ascii('0', '=', '}'); - if (rawcode == 0x2D) return get_ascii(0x2D, 0x5F); // '-' or '_' - if (rawcode == 0x2E) return 0x5E; // '^' (or '�') - if (rawcode == 0x36) return get_ascii(0x2C, 0x3B); // ',' or ';' - if (rawcode == 0x37) return get_ascii(0x2E, 0x3A); // '.' or ':' - - // TODO: <>#'+*~[]{}\| + if (rawcode == CELL_KEYC_MINUS) return get_ascii('-', '_'); + if (rawcode == CELL_KEYC_ACCENT_CIRCONFLEX_106) return get_ascii('^', '°'); + if (rawcode == CELL_KEYC_COMMA) return get_ascii(',', ';'); + if (rawcode == CELL_KEYC_PERIOD) return get_ascii('.', ':'); + if (rawcode == CELL_KEYC_KPAD_PLUS) return get_ascii('+', '*', '~'); + if (rawcode == CELL_KEYC_LESS) return get_ascii('<', '>', '|'); + if (rawcode == CELL_KEYC_HASHTAG) return get_ascii('#', '\''); + if (rawcode == CELL_KEYC_SSHARP) return get_ascii('ß', '?', '\\'); + if (rawcode == CELL_KEYC_BACK_QUOTE) return get_ascii('´', '`'); + if (rawcode == CELL_KEYC_Q) return get_ascii('q', 'Q', '@'); } if (rawcode >= 0x04 && rawcode <= 0x1D) // 'A' - 'Z' @@ -207,7 +224,7 @@ u16 cellKbCnvRawCode(u32 arrange, u32 mkey, u32 led, u16 rawcode) if (rawcode == 0x2B) return 0x09; // '\t' if (rawcode == 0x2C) return 0x20; // 'space' - // TODO: Add more cases (e.g. what about '`' and '~' on english layouts) and layouts (e.g. german) + // TODO: Add more keys and layouts return 0x0000; } diff --git a/rpcs3/Emu/Cell/Modules/cellKb.h b/rpcs3/Emu/Cell/Modules/cellKb.h index 0461bf978c..3dfaa90b0d 100644 --- a/rpcs3/Emu/Cell/Modules/cellKb.h +++ b/rpcs3/Emu/Cell/Modules/cellKb.h @@ -1,6 +1,7 @@ -#pragma once +#pragma once #include "Utilities/BEType.h" +#include "Emu/Io/Keyboard.h" enum CellKbError : u32 { @@ -14,12 +15,6 @@ enum CellKbError : u32 CELL_KB_ERROR_SYS_SETTING_FAILED = 0x80121008, }; -enum -{ - CELL_KB_MAX_KEYCODES = 62, - CELL_KB_MAX_KEYBOARDS = 127, -}; - struct CellKbInfo { be_t max_connect; diff --git a/rpcs3/Emu/Io/Keyboard.h b/rpcs3/Emu/Io/Keyboard.h new file mode 100644 index 0000000000..c7682c3c88 --- /dev/null +++ b/rpcs3/Emu/Io/Keyboard.h @@ -0,0 +1,203 @@ +#pragma once + +#include "Utilities/types.h" + +enum +{ + CELL_KB_MAX_KEYCODES = 62, + CELL_KB_MAX_KEYBOARDS = 127, +}; + +enum KbPortStatus +{ + CELL_KB_STATUS_DISCONNECTED = 0x00000000, + CELL_KB_STATUS_CONNECTED = 0x00000001, +}; + +enum CellKbReadMode +{ + CELL_KB_RMODE_INPUTCHAR = 0, + CELL_KB_RMODE_PACKET = 1, +}; + +enum CellKbCodeType +{ + CELL_KB_CODETYPE_RAW = 0, + CELL_KB_CODETYPE_ASCII = 1, +}; + +enum KbLedCodes +{ + CELL_KB_LED_NUM_LOCK = 0x00000001, + CELL_KB_LED_CAPS_LOCK = 0x00000002, + CELL_KB_LED_SCROLL_LOCK = 0x00000004, + CELL_KB_LED_COMPOSE = 0x00000008, + CELL_KB_LED_KANA = 0x00000016, +}; + +enum KbMetaKeys +{ + CELL_KB_MKEY_L_CTRL = 0x00000001, + CELL_KB_MKEY_L_SHIFT = 0x00000002, + CELL_KB_MKEY_L_ALT = 0x00000004, + CELL_KB_MKEY_L_WIN = 0x00000008, + CELL_KB_MKEY_R_CTRL = 0x00000010, + CELL_KB_MKEY_R_SHIFT = 0x00000020, + CELL_KB_MKEY_R_ALT = 0x00000040, + CELL_KB_MKEY_R_WIN = 0x00000080, +}; + +enum Keys +{ + // Non-ASCII Raw data + CELL_KEYC_NO_EVENT = 0x00, + CELL_KEYC_E_ROLLOVER = 0x01, + CELL_KEYC_E_POSTFAIL = 0x02, + CELL_KEYC_E_UNDEF = 0x03, + CELL_KEYC_ESCAPE = 0x29, + CELL_KEYC_106_KANJI = 0x35, + CELL_KEYC_CAPS_LOCK = 0x39, + CELL_KEYC_F1 = 0x3a, + CELL_KEYC_F2 = 0x3b, + CELL_KEYC_F3 = 0x3c, + CELL_KEYC_F4 = 0x3d, + CELL_KEYC_F5 = 0x3e, + CELL_KEYC_F6 = 0x3f, + CELL_KEYC_F7 = 0x40, + CELL_KEYC_F8 = 0x41, + CELL_KEYC_F9 = 0x42, + CELL_KEYC_F10 = 0x43, + CELL_KEYC_F11 = 0x44, + CELL_KEYC_F12 = 0x45, + CELL_KEYC_PRINTSCREEN = 0x46, + CELL_KEYC_SCROLL_LOCK = 0x47, + CELL_KEYC_PAUSE = 0x48, + CELL_KEYC_INSERT = 0x49, + CELL_KEYC_HOME = 0x4a, + CELL_KEYC_PAGE_UP = 0x4b, + CELL_KEYC_DELETE = 0x4c, + CELL_KEYC_END = 0x4d, + CELL_KEYC_PAGE_DOWN = 0x4e, + CELL_KEYC_RIGHT_ARROW = 0x4f, + CELL_KEYC_LEFT_ARROW = 0x50, + CELL_KEYC_DOWN_ARROW = 0x51, + CELL_KEYC_UP_ARROW = 0x52, + CELL_KEYC_NUM_LOCK = 0x53, + CELL_KEYC_APPLICATION = 0x65, + CELL_KEYC_KANA = 0x88, + CELL_KEYC_HENKAN = 0x8a, + CELL_KEYC_MUHENKAN = 0x8b, + + // Raw keycodes for ASCII keys + CELL_KEYC_A = 0x04, + CELL_KEYC_B = 0x05, + CELL_KEYC_C = 0x06, + CELL_KEYC_D = 0x07, + CELL_KEYC_E = 0x08, + CELL_KEYC_F = 0x09, + CELL_KEYC_G = 0x0A, + CELL_KEYC_H = 0x0B, + CELL_KEYC_I = 0x0C, + CELL_KEYC_J = 0x0D, + CELL_KEYC_K = 0x0E, + CELL_KEYC_L = 0x0F, + CELL_KEYC_M = 0x10, + CELL_KEYC_N = 0x11, + CELL_KEYC_O = 0x12, + CELL_KEYC_P = 0x13, + CELL_KEYC_Q = 0x14, + CELL_KEYC_R = 0x15, + CELL_KEYC_S = 0x16, + CELL_KEYC_T = 0x17, + CELL_KEYC_U = 0x18, + CELL_KEYC_V = 0x19, + CELL_KEYC_W = 0x1A, + CELL_KEYC_X = 0x1B, + CELL_KEYC_Y = 0x1C, + CELL_KEYC_Z = 0x1D, + CELL_KEYC_1 = 0x1E, + CELL_KEYC_2 = 0x1F, + CELL_KEYC_3 = 0x20, + CELL_KEYC_4 = 0x21, + CELL_KEYC_5 = 0x22, + CELL_KEYC_6 = 0x23, + CELL_KEYC_7 = 0x24, + CELL_KEYC_8 = 0x25, + CELL_KEYC_9 = 0x26, + CELL_KEYC_0 = 0x27, + CELL_KEYC_ENTER = 0x28, + CELL_KEYC_ESC = 0x29, + CELL_KEYC_BS = 0x2A, + CELL_KEYC_TAB = 0x2B, + CELL_KEYC_SPACE = 0x2C, + CELL_KEYC_MINUS = 0x2D, + CELL_KEYC_EQUAL_101 = 0x2E, + CELL_KEYC_ACCENT_CIRCONFLEX_106 = 0x2E, + CELL_KEYC_LEFT_BRACKET_101 = 0x2F, + CELL_KEYC_ATMARK_106 = 0x2F, + CELL_KEYC_RIGHT_BRACKET_101 = 0x30, + CELL_KEYC_LEFT_BRACKET_106 = 0x30, + CELL_KEYC_BACKSLASH_101 = 0x31, + CELL_KEYC_RIGHT_BRACKET_106 = 0x32, + CELL_KEYC_SEMICOLON = 0x33, + CELL_KEYC_QUOTATION_101 = 0x34, + CELL_KEYC_COLON_106 = 0x34, + CELL_KEYC_COMMA = 0x36, + CELL_KEYC_PERIOD = 0x37, + CELL_KEYC_SLASH = 0x38, + //CELL_KEYC_CAPS_LOCK = 0x39, + CELL_KEYC_KPAD_NUMLOCK = 0x53, + CELL_KEYC_KPAD_SLASH = 0x54, + CELL_KEYC_KPAD_ASTERISK = 0x55, + CELL_KEYC_KPAD_MINUS = 0x56, + CELL_KEYC_KPAD_PLUS = 0x57, + CELL_KEYC_KPAD_ENTER = 0x58, + CELL_KEYC_KPAD_1 = 0x59, + CELL_KEYC_KPAD_2 = 0x5A, + CELL_KEYC_KPAD_3 = 0x5B, + CELL_KEYC_KPAD_4 = 0x5C, + CELL_KEYC_KPAD_5 = 0x5D, + CELL_KEYC_KPAD_6 = 0x5E, + CELL_KEYC_KPAD_7 = 0x5F, + CELL_KEYC_KPAD_8 = 0x60, + CELL_KEYC_KPAD_9 = 0x61, + CELL_KEYC_KPAD_0 = 0x62, + CELL_KEYC_KPAD_PERIOD = 0x63, + CELL_KEYC_BACKSLASH_106 = 0x87, + CELL_KEYC_YEN_106 = 0x89, + + // Made up helper codes (Maybe there's a real code somewhere hidden in the SDK) + CELL_KEYC_LESS = 0x90, + CELL_KEYC_HASHTAG = 0x91, + CELL_KEYC_SSHARP = 0x92, + CELL_KEYC_BACK_QUOTE = 0x93 +}; + +enum CellKbMappingType : s32 +{ + CELL_KB_MAPPING_101 = 0, + CELL_KB_MAPPING_106 = 1, + CELL_KB_MAPPING_106_KANA = 2, + CELL_KB_MAPPING_GERMAN_GERMANY = 3, + CELL_KB_MAPPING_SPANISH_SPAIN = 4, + CELL_KB_MAPPING_FRENCH_FRANCE = 5, + CELL_KB_MAPPING_ITALIAN_ITALY = 6, + CELL_KB_MAPPING_DUTCH_NETHERLANDS = 7, + CELL_KB_MAPPING_PORTUGUESE_PORTUGAL = 8, + CELL_KB_MAPPING_RUSSIAN_RUSSIA = 9, + CELL_KB_MAPPING_ENGLISH_UK = 10, + CELL_KB_MAPPING_KOREAN_KOREA = 11, + CELL_KB_MAPPING_NORWEGIAN_NORWAY = 12, + CELL_KB_MAPPING_FINNISH_FINLAND = 13, + CELL_KB_MAPPING_DANISH_DENMARK = 14, + CELL_KB_MAPPING_SWEDISH_SWEDEN = 15, + CELL_KB_MAPPING_CHINESE_TRADITIONAL = 16, + CELL_KB_MAPPING_CHINESE_SIMPLIFIED = 17, + CELL_KB_MAPPING_SWISS_FRENCH_SWITZERLAND = 18, + CELL_KB_MAPPING_SWISS_GERMAN_SWITZERLAND = 19, + CELL_KB_MAPPING_CANADIAN_FRENCH_CANADA = 20, + CELL_KB_MAPPING_BELGIAN_BELGIUM = 21, + CELL_KB_MAPPING_POLISH_POLAND = 22, + CELL_KB_MAPPING_PORTUGUESE_BRAZIL = 23, + CELL_KB_MAPPING_TURKISH_TURKEY = 24 +}; diff --git a/rpcs3/Emu/Io/KeyboardHandler.cpp b/rpcs3/Emu/Io/KeyboardHandler.cpp index b902055b88..0c247437d8 100644 --- a/rpcs3/Emu/Io/KeyboardHandler.cpp +++ b/rpcs3/Emu/Io/KeyboardHandler.cpp @@ -89,7 +89,7 @@ void KeyboardHandlerBase::Key(u32 code, bool pressed) } else { - data.keycode[data.len % KB_MAX_KEYCODES] = { CELL_KEYC_NO_EVENT, button.m_outKeyCode }; + data.keycode[data.len % CELL_KB_MAX_KEYCODES] = { CELL_KEYC_NO_EVENT, button.m_outKeyCode }; } } else @@ -107,11 +107,11 @@ void KeyboardHandlerBase::Key(u32 code, bool pressed) } else { - data.keycode[data.len % KB_MAX_KEYCODES] = { kcode, 0 }; + data.keycode[data.len % CELL_KB_MAX_KEYCODES] = { kcode, 0 }; } } - data.len = std::min(data.len + 1, (int)KB_MAX_KEYCODES); + data.len = std::min(data.len + 1, (int)CELL_KB_MAX_KEYCODES); } else { diff --git a/rpcs3/Emu/Io/KeyboardHandler.h b/rpcs3/Emu/Io/KeyboardHandler.h index 9982bc84a0..469b5e033f 100644 --- a/rpcs3/Emu/Io/KeyboardHandler.h +++ b/rpcs3/Emu/Io/KeyboardHandler.h @@ -1,201 +1,11 @@ #pragma once -#include "Utilities/types.h" +#include "Keyboard.h" #include -// TODO: HLE info (constants, structs, etc.) should not be available here - extern u16 cellKbCnvRawCode(u32 arrange, u32 mkey, u32 led, u16 rawcode); // (TODO: Can it be problematic to place SysCalls in middle of nowhere?) -enum KbPortStatus -{ - CELL_KB_STATUS_DISCONNECTED = 0x00000000, - CELL_KB_STATUS_CONNECTED = 0x00000001, -}; - -enum CellKbReadMode -{ - CELL_KB_RMODE_INPUTCHAR = 0, - CELL_KB_RMODE_PACKET = 1, -}; - -enum CellKbCodeType -{ - CELL_KB_CODETYPE_RAW = 0, - CELL_KB_CODETYPE_ASCII = 1, -}; - -enum KbLedCodes -{ - CELL_KB_LED_NUM_LOCK = 0x00000001, - CELL_KB_LED_CAPS_LOCK = 0x00000002, - CELL_KB_LED_SCROLL_LOCK = 0x00000004, - CELL_KB_LED_COMPOSE = 0x00000008, - CELL_KB_LED_KANA = 0x00000016, -}; - -enum KbMetaKeys -{ - CELL_KB_MKEY_L_CTRL = 0x00000001, - CELL_KB_MKEY_L_SHIFT = 0x00000002, - CELL_KB_MKEY_L_ALT = 0x00000004, - CELL_KB_MKEY_L_WIN = 0x00000008, - CELL_KB_MKEY_R_CTRL = 0x00000010, - CELL_KB_MKEY_R_SHIFT = 0x00000020, - CELL_KB_MKEY_R_ALT = 0x00000040, - CELL_KB_MKEY_R_WIN = 0x00000080, -}; - -enum Keys -{ - // Non-ASCII Raw data - CELL_KEYC_NO_EVENT = 0x00, - CELL_KEYC_E_ROLLOVER = 0x01, - CELL_KEYC_E_POSTFAIL = 0x02, - CELL_KEYC_E_UNDEF = 0x03, - CELL_KEYC_ESCAPE = 0x29, - CELL_KEYC_106_KANJI = 0x35, - CELL_KEYC_CAPS_LOCK = 0x39, - CELL_KEYC_F1 = 0x3a, - CELL_KEYC_F2 = 0x3b, - CELL_KEYC_F3 = 0x3c, - CELL_KEYC_F4 = 0x3d, - CELL_KEYC_F5 = 0x3e, - CELL_KEYC_F6 = 0x3f, - CELL_KEYC_F7 = 0x40, - CELL_KEYC_F8 = 0x41, - CELL_KEYC_F9 = 0x42, - CELL_KEYC_F10 = 0x43, - CELL_KEYC_F11 = 0x44, - CELL_KEYC_F12 = 0x45, - CELL_KEYC_PRINTSCREEN = 0x46, - CELL_KEYC_SCROLL_LOCK = 0x47, - CELL_KEYC_PAUSE = 0x48, - CELL_KEYC_INSERT = 0x49, - CELL_KEYC_HOME = 0x4a, - CELL_KEYC_PAGE_UP = 0x4b, - CELL_KEYC_DELETE = 0x4c, - CELL_KEYC_END = 0x4d, - CELL_KEYC_PAGE_DOWN = 0x4e, - CELL_KEYC_RIGHT_ARROW = 0x4f, - CELL_KEYC_LEFT_ARROW = 0x50, - CELL_KEYC_DOWN_ARROW = 0x51, - CELL_KEYC_UP_ARROW = 0x52, - CELL_KEYC_NUM_LOCK = 0x53, - CELL_KEYC_APPLICATION = 0x65, - CELL_KEYC_KANA = 0x88, - CELL_KEYC_HENKAN = 0x8a, - CELL_KEYC_MUHENKAN = 0x8b, - - // Raw keycodes for ASCII keys - CELL_KEYC_A = 0x04, - CELL_KEYC_B = 0x05, - CELL_KEYC_C = 0x06, - CELL_KEYC_D = 0x07, - CELL_KEYC_E = 0x08, - CELL_KEYC_F = 0x09, - CELL_KEYC_G = 0x0A, - CELL_KEYC_H = 0x0B, - CELL_KEYC_I = 0x0C, - CELL_KEYC_J = 0x0D, - CELL_KEYC_K = 0x0E, - CELL_KEYC_L = 0x0F, - CELL_KEYC_M = 0x10, - CELL_KEYC_N = 0x11, - CELL_KEYC_O = 0x12, - CELL_KEYC_P = 0x13, - CELL_KEYC_Q = 0x14, - CELL_KEYC_R = 0x15, - CELL_KEYC_S = 0x16, - CELL_KEYC_T = 0x17, - CELL_KEYC_U = 0x18, - CELL_KEYC_V = 0x19, - CELL_KEYC_W = 0x1A, - CELL_KEYC_X = 0x1B, - CELL_KEYC_Y = 0x1C, - CELL_KEYC_Z = 0x1D, - CELL_KEYC_1 = 0x1E, - CELL_KEYC_2 = 0x1F, - CELL_KEYC_3 = 0x20, - CELL_KEYC_4 = 0x21, - CELL_KEYC_5 = 0x22, - CELL_KEYC_6 = 0x23, - CELL_KEYC_7 = 0x24, - CELL_KEYC_8 = 0x25, - CELL_KEYC_9 = 0x26, - CELL_KEYC_0 = 0x27, - CELL_KEYC_ENTER = 0x28, - CELL_KEYC_ESC = 0x29, - CELL_KEYC_BS = 0x2A, - CELL_KEYC_TAB = 0x2B, - CELL_KEYC_SPACE = 0x2C, - CELL_KEYC_MINUS = 0x2D, - CELL_KEYC_EQUAL_101 = 0x2E, - CELL_KEYC_ACCENT_CIRCONFLEX_106 = 0x2E, - CELL_KEYC_LEFT_BRACKET_101 = 0x2F, - CELL_KEYC_ATMARK_106 = 0x2F, - CELL_KEYC_RIGHT_BRACKET_101 = 0x30, - CELL_KEYC_LEFT_BRACKET_106 = 0x30, - CELL_KEYC_BACKSLASH_101 = 0x31, - CELL_KEYC_RIGHT_BRACKET_106 = 0x32, - CELL_KEYC_SEMICOLON = 0x33, - CELL_KEYC_QUOTATION_101 = 0x34, - CELL_KEYC_COLON_106 = 0x34, - CELL_KEYC_COMMA = 0x36, - CELL_KEYC_PERIOD = 0x37, - CELL_KEYC_SLASH = 0x38, - //CELL_KEYC_CAPS_LOCK = 0x39, - CELL_KEYC_KPAD_NUMLOCK = 0x53, - CELL_KEYC_KPAD_SLASH = 0x54, - CELL_KEYC_KPAD_ASTERISK = 0x55, - CELL_KEYC_KPAD_MINUS = 0x56, - CELL_KEYC_KPAD_PLUS = 0x57, - CELL_KEYC_KPAD_ENTER = 0x58, - CELL_KEYC_KPAD_1 = 0x59, - CELL_KEYC_KPAD_2 = 0x5A, - CELL_KEYC_KPAD_3 = 0x5B, - CELL_KEYC_KPAD_4 = 0x5C, - CELL_KEYC_KPAD_5 = 0x5D, - CELL_KEYC_KPAD_6 = 0x5E, - CELL_KEYC_KPAD_7 = 0x5F, - CELL_KEYC_KPAD_8 = 0x60, - CELL_KEYC_KPAD_9 = 0x61, - CELL_KEYC_KPAD_0 = 0x62, - CELL_KEYC_KPAD_PERIOD = 0x63, - CELL_KEYC_BACKSLASH_106 = 0x87, - CELL_KEYC_YEN_106 = 0x89, -}; - -enum CellKbMappingType : s32 -{ - CELL_KB_MAPPING_101, - CELL_KB_MAPPING_106, - CELL_KB_MAPPING_106_KANA, - CELL_KB_MAPPING_GERMAN_GERMANY, - CELL_KB_MAPPING_SPANISH_SPAIN, - CELL_KB_MAPPING_FRENCH_FRANCE, - CELL_KB_MAPPING_ITALIAN_ITALY, - CELL_KB_MAPPING_DUTCH_NETHERLANDS, - CELL_KB_MAPPING_PORTUGUESE_PORTUGAL, - CELL_KB_MAPPING_RUSSIAN_RUSSIA, - CELL_KB_MAPPING_ENGLISH_UK, - CELL_KB_MAPPING_KOREAN_KOREA, - CELL_KB_MAPPING_NORWEGIAN_NORWAY, - CELL_KB_MAPPING_FINNISH_FINLAND, - CELL_KB_MAPPING_DANISH_DENMARK, - CELL_KB_MAPPING_SWEDISH_SWEDEN, - CELL_KB_MAPPING_CHINESE_TRADITIONAL, - CELL_KB_MAPPING_CHINESE_SIMPLIFIED, - CELL_KB_MAPPING_SWISS_FRENCH_SWITZERLAND, - CELL_KB_MAPPING_SWISS_GERMAN_SWITZERLAND, - CELL_KB_MAPPING_CANADIAN_FRENCH_CANADA, - CELL_KB_MAPPING_BELGIAN_BELGIUM, - CELL_KB_MAPPING_POLISH_POLAND, - CELL_KB_MAPPING_PORTUGUESE_BRAZIL, - CELL_KB_MAPPING_TURKISH_TURKEY -}; - enum QtKeys { Key_Shift = 0x01000020, @@ -209,15 +19,12 @@ enum QtKeys Key_Super_R = 0x01000054 }; -static const u32 KB_MAX_KEYBOARDS = 127; -static const u32 KB_MAX_KEYCODES = 62; - struct KbInfo { u32 max_connect; u32 now_connect; u32 info; - u8 status[KB_MAX_KEYBOARDS]; + u8 status[CELL_KB_MAX_KEYBOARDS]; }; struct KbData @@ -225,7 +32,7 @@ struct KbData u32 led; u32 mkey; s32 len; - std::pair keycode[KB_MAX_KEYCODES]; + std::pair keycode[CELL_KB_MAX_KEYCODES]; KbData() : led(0) diff --git a/rpcs3/basic_keyboard_handler.cpp b/rpcs3/basic_keyboard_handler.cpp index 94383d1c61..6b5e46ab18 100644 --- a/rpcs3/basic_keyboard_handler.cpp +++ b/rpcs3/basic_keyboard_handler.cpp @@ -250,7 +250,6 @@ void basic_keyboard_handler::LoadSettings() m_keyboards[0].m_buttons.emplace_back(Qt::Key_9, CELL_KEYC_9); m_keyboards[0].m_buttons.emplace_back(Qt::Key_0, CELL_KEYC_0); - m_keyboards[0].m_buttons.emplace_back(Qt::Key_Return, CELL_KEYC_ENTER); m_keyboards[0].m_buttons.emplace_back(Qt::Key_Backspace, CELL_KEYC_BS); m_keyboards[0].m_buttons.emplace_back(Qt::Key_Tab, CELL_KEYC_TAB); @@ -265,11 +264,18 @@ void basic_keyboard_handler::LoadSettings() m_keyboards[0].m_buttons.emplace_back(Qt::Key_Backslash, CELL_KEYC_BACKSLASH_101); m_keyboards[0].m_buttons.emplace_back(Qt::Key_BracketRight, CELL_KEYC_RIGHT_BRACKET_106); m_keyboards[0].m_buttons.emplace_back(Qt::Key_Semicolon, CELL_KEYC_SEMICOLON); - m_keyboards[0].m_buttons.emplace_back(Qt::Key_QuoteDbl, CELL_KEYC_QUOTATION_101); + m_keyboards[0].m_buttons.emplace_back(Qt::Key_Apostrophe, CELL_KEYC_QUOTATION_101); m_keyboards[0].m_buttons.emplace_back(Qt::Key_Colon, CELL_KEYC_COLON_106); m_keyboards[0].m_buttons.emplace_back(Qt::Key_Comma, CELL_KEYC_COMMA); m_keyboards[0].m_buttons.emplace_back(Qt::Key_Period, CELL_KEYC_PERIOD); m_keyboards[0].m_buttons.emplace_back(Qt::Key_Slash, CELL_KEYC_SLASH); m_keyboards[0].m_buttons.emplace_back(Qt::Key_Backslash, CELL_KEYC_BACKSLASH_106); m_keyboards[0].m_buttons.emplace_back(Qt::Key_yen, CELL_KEYC_YEN_106); + + // Made up helper buttons + m_keyboards[0].m_buttons.emplace_back(Qt::Key_Less, CELL_KEYC_LESS); + m_keyboards[0].m_buttons.emplace_back(Qt::Key_NumberSign, CELL_KEYC_HASHTAG); + m_keyboards[0].m_buttons.emplace_back(Qt::Key_ssharp, CELL_KEYC_SSHARP); + m_keyboards[0].m_buttons.emplace_back(Qt::Key_QuoteLeft, CELL_KEYC_BACK_QUOTE); + m_keyboards[0].m_buttons.emplace_back(Qt::Key_acute, CELL_KEYC_BACK_QUOTE); } diff --git a/rpcs3/emucore.vcxproj b/rpcs3/emucore.vcxproj index f2a96e9695..e94bb10a36 100644 --- a/rpcs3/emucore.vcxproj +++ b/rpcs3/emucore.vcxproj @@ -372,6 +372,7 @@ + diff --git a/rpcs3/emucore.vcxproj.filters b/rpcs3/emucore.vcxproj.filters index c54746fa5e..d25b7f219f 100644 --- a/rpcs3/emucore.vcxproj.filters +++ b/rpcs3/emucore.vcxproj.filters @@ -1540,5 +1540,8 @@ Emu\GPU\RSX + + Emu\Io + \ No newline at end of file