From 0e939b5f686c16c8846830bb20dc953d3cc4f72d Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Sat, 8 Sep 2018 14:35:46 +0200 Subject: [PATCH] Keyboard: Better keycode mapping, added CTRL. Maple cleanup. --- core/hw/maple/maple_devs.cpp | 41 +++++++++++++++----------------- core/linux-dist/x11.cpp | 46 +++++++++++++++++++++++------------- 2 files changed, 49 insertions(+), 38 deletions(-) diff --git a/core/hw/maple/maple_devs.cpp b/core/hw/maple/maple_devs.cpp index 6428adac4..44078d31c 100755 --- a/core/hw/maple/maple_devs.cpp +++ b/core/hw/maple/maple_devs.cpp @@ -231,11 +231,11 @@ struct maple_sega_controller: maple_base w8(0x80); } - return MDRS_DataTransfer; + return MDRS_DataTransfer; default: //printf("UNKOWN MAPLE COMMAND %d\n",cmd); - return MDRE_UnknownFunction; + return MDRE_UnknownCmd; } } }; @@ -831,18 +831,18 @@ struct maple_microphone: maple_base return MDRS_DeviceReply;//MDRS_DataTransfer; default: LOGW("maple_microphone::dma UNHANDLED secondword %#010x\n",secondword); - break; + return MDRE_UnknownFunction; } } default: LOGW("maple_microphone::dma UNHANDLED function %#010x\n",function); - break; + return MDRE_UnknownFunction; } } default: LOGW("maple_microphone::dma UNHANDLED MAPLE COMMAND %d\n",cmd); - return MDRE_UnknownFunction; + return MDRE_UnknownCmd; } } }; @@ -934,7 +934,7 @@ struct maple_sega_purupuru : maple_base default: //printf("UNKOWN MAPLE COMMAND %d\n",cmd); - return MDRE_UnknownFunction; + return MDRE_UnknownCmd; } } }; @@ -952,58 +952,55 @@ struct maple_keyboard : maple_base case MDC_DeviceRequest: //caps //4 - w32(1 << 30); + w32(MFID_6_Keyboard); //struct data //3*4 - w32( 0xfe060f00); - w32( 0); - w32( 0); + w32(0x80000502); // US, 104 keys + w32(0); + w32(0); //1 area code w8(0xFF); //1 direction w8(0); - //30 + // Product name (30) for (u32 i = 0; i < 30; i++) { w8((u8)maple_sega_kbd_name[i]); } - //ptr_out += 30; - //60 + // License (60) for (u32 i = 0; i < 60; i++) { w8((u8)maple_sega_brand[i]); } - //ptr_out += 60; - //2 + // Low-consumption standby current (2) w16(0x01AE); - //2 + // Maximum current consumption (2) w16(0x01F5); - return 5; + return MDRS_DeviceStatus; case MDCF_GetCondition: - w32((1 << 30)); + w32(MFID_6_Keyboard); //struct data //int8 shift ; shift keys pressed (bitmask) //1 w8(kb_shift); //int8 led ; leds currently lit //1 w8(kb_led); //int8 key[6] ; normal keys pressed //6 - for (int i=0;i<6;i++) + for (int i = 0; i < 6; i++) { w8(kb_key[i]); } - return 8; + return MDRS_DataTransfer; default: printf("Keyboard: unknown MAPLE COMMAND %d\n", cmd); - - return 7; + return MDRE_UnknownCmd; } } }; diff --git a/core/linux-dist/x11.cpp b/core/linux-dist/x11.cpp index f68e26443..fafa5db6d 100644 --- a/core/linux-dist/x11.cpp +++ b/core/linux-dist/x11.cpp @@ -133,20 +133,20 @@ static void init_kb_map() kb_map[KEY_TAB] = 0x2B; kb_map[KEY_SPACE] = 0x2C; - kb_map[20] = 0x2D; // key right of 0 - kb_map[21] = 0x2E; // key right of previous one - kb_map[34] = 0x2F; // key right of P - kb_map[35] = 0x30; // key right of previous one + kb_map[20] = 0x2D; // - + kb_map[21] = 0x2E; // = + kb_map[34] = 0x2F; // [ + kb_map[35] = 0x30; // ] - //kb_map[94] = 0x31; // \ (US) also 64, not used + kb_map[94] = 0x31; // \ (US) unsure of keycode //32-34 "]", ";" and ":" (the 3 keys right of L) - kb_map[47] = 0x32; - kb_map[48] = 0x33; - kb_map[51] = 0x34; + kb_map[51] = 0x32; // ~ (non-US) *,ยต in FR layout + kb_map[47] = 0x33; // ; + kb_map[48] = 0x34; // ' //35 hankaku/zenkaku / kanji (top left) - kb_map[49] = 0x35; // `~ (US) + kb_map[49] = 0x35; // `~ (US) //36-38 ",", "." and "/" (the 3 keys right of M) kb_map[59] = 0x36; @@ -163,9 +163,9 @@ static void init_kb_map() kb_map[KEY_F12] = 0x45; //46-4E Control keys above cursor keys - kb_map[107] = 0x46; - kb_map[78] = 0x47; - kb_map[127] = 0x48; + kb_map[107] = 0x46; // Print Screen + kb_map[78] = 0x47; // Scroll Lock + kb_map[127] = 0x48; // Pause kb_map[KEY_INS] = 0x49; kb_map[KEY_HOME] = 0x4A; kb_map[KEY_PGUP] = 0x4B; @@ -204,11 +204,20 @@ static void init_kb_map() kb_map[90] = 0x62; //63 "." (Numeric keypad) kb_map[91] = 0x63; - //64 "\" (right of left Shift) - kb_map[94] = 0x64; + //64 #| (non-US) + //kb_map[94] = 0x64; //65 S3 key - //66-86 Not used - //8C-FF Not used + //66-A4 Not used + //A5-DF Reserved + //E0 Left Control + //E1 Left Shift + //E2 Left Alt + //E3 Left S1 + //E4 Right Control + //E5 Right Shift + //E6 Right Alt + //E7 Right S3 + //E8-FF Reserved } static u32 kb_used = 0; @@ -235,6 +244,11 @@ void input_x11_handle() kb_shift &= ~(0x02 | 0x20); else kb_shift |= (0x02 | 0x20); + if (e.xkey.keycode == KEY_LCTRL || e.xkey.keycode == KEY_RCTRL) + if (e.type == KeyRelease) + kb_shift &= ~(0x01 | 0x10); + else + kb_shift |= (0x01 | 0x10); u8 dc_keycode = kb_map[e.xkey.keycode & 0xFF]; if (dc_keycode != 0)