From 3045a1c5f05fa6f6e3cfe73da753b7500e87aff3 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Tue, 24 Nov 2009 21:20:19 +0800 Subject: [PATCH] Altered keyboard driver to correctly support Unicode - Updated Keyboard and VTerm driver to accomodate this - Edited Modules/Makefile.tpl to allow modules to set their own CPPFLAGS - Inconcequential changes elsewhere --- Kernel/Makefile.BuildNum | 2 +- Kernel/drv/kb.c | 53 +++++++++++++------- Kernel/drv/kb_kbdus.h | 8 +-- Kernel/drv/vterm.c | 37 +++++++++++--- Kernel/include/tpl_drv_keyboard.h | 4 +- Kernel/modules.c | 1 + Modules/IPStack/main.c | 2 +- Modules/Makefile.tpl | 4 +- Usermode/Libraries/libreadline.so_src/main.c | 19 ++++--- 9 files changed, 89 insertions(+), 41 deletions(-) diff --git a/Kernel/Makefile.BuildNum b/Kernel/Makefile.BuildNum index a8d43110..05602fee 100644 --- a/Kernel/Makefile.BuildNum +++ b/Kernel/Makefile.BuildNum @@ -1 +1 @@ -BUILD_NUM = 1039 +BUILD_NUM = 1041 diff --git a/Kernel/drv/kb.c b/Kernel/drv/kb.c index 2da26ff1..6c2bf926 100644 --- a/Kernel/drv/kb.c +++ b/Kernel/drv/kb.c @@ -35,17 +35,20 @@ tDevFS_Driver gKB_DevInfo = { } }; tKeybardCallback gKB_Callback = NULL; -Uint8 **gpKB_Map = gpKBDUS; -Uint8 gbaKB_States[256]; +Uint32 **gpKB_Map = gpKBDUS; +Uint8 gbaKB_States[3][256]; int gbKB_ShiftState = 0; int gbKB_CapsState = 0; int gbKB_KeyUp = 0; int giKB_KeyLayer = 0; +#if USE_KERNEL_MAGIC + int gbKB_MagicState = 0; +#endif //Uint64 giKB_ReadBase = 0; -Uint8 gaKB_Buffer[KB_BUFFER_SIZE]; //!< Keyboard Ring Buffer -volatile int giKB_InsertPoint = 0; //!< Writing location marker -volatile int giKB_ReadPoint = 0; //!< Reading location marker -volatile int giKB_InUse = 0; //!< Lock marker +//Uint32 gaKB_Buffer[KB_BUFFER_SIZE]; //!< Keyboard Ring Buffer +//volatile int giKB_InsertPoint = 0; //!< Writing location marker +//volatile int giKB_ReadPoint = 0; //!< Reading location marker +//volatile int giKB_InUse = 0; //!< Lock marker // === CODE === /** @@ -74,6 +77,8 @@ void KB_IRQHandler() // Ignore ACKs if(scancode == 0xFA) { + // Oh man! This is anachic (I'm leaving it here to represent the + // mess that acess once was //kb_lastChar = KB_ACK; return; } @@ -110,40 +115,52 @@ void KB_IRQHandler() if(!ch && !gbKB_KeyUp) Warning("UNK %i %x", giKB_KeyLayer, scancode); - // Reset Layer - giKB_KeyLayer = 0; - // Key Up? if (gbKB_KeyUp) { gbKB_KeyUp = 0; - gbaKB_States[ ch ] = 0; // Unset key state flag + gbaKB_States[giKB_KeyLayer][scancode] = 0; // Unset key state flag + + #if USE_KERNEL_MAGIC + if(ch == KEY_LCTRL) gbKB_MagicState &= ~1; + if(ch == KEY_LALT) gbKB_MagicState &= ~2; + #endif - if( !gbaKB_States[KEY_LSHIFT] && !gbaKB_States[KEY_RSHIFT] ) - gbKB_ShiftState = 0; + if(ch == KEY_LSHIFT) gbKB_ShiftState &= ~1; + if(ch == KEY_RSHIFT) gbKB_ShiftState &= ~2; + // Call callback if(ch != 0 && gKB_Callback) gKB_Callback( ch & 0x80000000 ); + // Reset Layer + giKB_KeyLayer = 0; return; } // Set the bit relating to the key - gbaKB_States[ch] = 1; - if(ch == KEY_LSHIFT || ch == KEY_RSHIFT) - gbKB_ShiftState = 1; + gbaKB_States[giKB_KeyLayer][scancode] = 1; + // Set shift key bits + if(ch == KEY_LSHIFT) gbKB_ShiftState |= 1; + if(ch == KEY_RSHIFT) gbKB_ShiftState |= 2; // Check for Caps Lock if(ch == KEY_CAPSLOCK) { gbKB_CapsState = !gbKB_CapsState; KB_UpdateLEDs(); } + + // Reset Layer + giKB_KeyLayer = 0; // Ignore Non-Printable Characters if(ch == 0) return; // --- Check for Kernel Magic Combos - if(gbaKB_States[KEY_LCTRL] && gbaKB_States[KEY_LALT]) + #if USE_KERNEL_MAGIC + if(ch == KEY_LCTRL) gbKB_MagicState |= 1; + if(ch == KEY_LALT) gbKB_MagicState |= 2; + if(gbKB_MagicState == 3) { switch(ch) { @@ -151,9 +168,11 @@ void KB_IRQHandler() case 'p': Threads_Dump(); break; } } + #endif // Is shift pressed - if(gbKB_ShiftState ^ gbKB_CapsState) + // - Darn ugly hacks !(!x) means (bool)x + if( !(!gbKB_ShiftState) ^ gbKB_CapsState) { switch(ch) { diff --git a/Kernel/drv/kb_kbdus.h b/Kernel/drv/kb_kbdus.h index 4010bbeb..441b19a5 100644 --- a/Kernel/drv/kb_kbdus.h +++ b/Kernel/drv/kb_kbdus.h @@ -3,7 +3,7 @@ #define _KBDUS_H // - BASE (NO PREFIX) -Uint8 gpKBDUS1[256] = { +Uint32 gpKBDUS1[256] = { /*00*/ 0, KEY_ESC, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '\b', '\t', /*10*/ 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', KEY_LCTRL, 'a', 's', /*20*/ 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';','\'', '`', KEY_LSHIFT,'\\', 'z', 'x', 'c', 'v', @@ -25,7 +25,7 @@ Uint8 gpKBDUS1[256] = { /*F0*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; // - 0xE0 Prefixed -Uint8 gpKBDUS2[256] = { +Uint32 gpKBDUS2[256] = { // 0 1 2 3 4 5 6 7 8 9 A B C D E F /*00*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0-F /*10*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, KEY_KPENTER, KEY_RCTRL, 0, 0, @@ -47,7 +47,7 @@ Uint8 gpKBDUS2[256] = { /*F0*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; // - 0xE1 Prefixed -Uint8 gpKBDUS3[256] = { +Uint32 gpKBDUS3[256] = { // 0 1 2 3 4 5 6 7 8 9 A B C D E F /*00*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0-F /*10*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, KEY_PAUSE, 0, 0, @@ -68,6 +68,6 @@ Uint8 gpKBDUS3[256] = { }; -Uint8 *gpKBDUS[3] = { gpKBDUS1, gpKBDUS2, gpKBDUS3 }; +Uint32 *gpKBDUS[3] = { gpKBDUS1, gpKBDUS2, gpKBDUS3 }; #endif diff --git a/Kernel/drv/vterm.c b/Kernel/drv/vterm.c index d33fad98..575d71f9 100644 --- a/Kernel/drv/vterm.c +++ b/Kernel/drv/vterm.c @@ -503,7 +503,7 @@ void VT_KBCallBack(Uint32 Codepoint) if(term->Mode == TERM_MODE_TEXT) { Uint8 buf[6] = {0}; - int len; + int len = 0; // Ignore Modifer Keys if(Codepoint > KEY_MODIFIERS) return; @@ -512,20 +512,43 @@ void VT_KBCallBack(Uint32 Codepoint) switch(Codepoint) { case KEY_LEFT: - buf[0] = '\x1B'; buf[1] = '['; - buf[2] = 'D'; len = 3; + buf[0] = '\x1B'; buf[1] = '['; buf[2] = 'D'; + len = 3; break; case KEY_RIGHT: - buf[0] = '\x1B'; buf[1] = '['; - buf[2] = 'C'; len = 3; + buf[0] = '\x1B'; buf[1] = '['; buf[2] = 'C'; + len = 3; break; + case KEY_UP: + buf[0] = '\x1B'; buf[1] = '['; buf[2] = 'A'; + len = 3; + break; + case KEY_DOWN: + buf[0] = '\x1B'; buf[1] = '['; buf[2] = 'B'; + len = 3; + break; + + case KEY_PGUP: + buf[0] = '\x1B'; buf[1] = '['; buf[2] = '5'; // Some overline also + //len = 4; // Commented out until I'm sure + break; + case KEY_PGDOWN: + len = 0; + break; + + // Attempt to encode in UTF-8 default: len = WriteUTF8( buf, Codepoint ); - //Log("Codepoint = 0x%x", Codepoint); + if(len == 0) { + Warning("Codepoint (%x) is unrepresentable in UTF-8", Codepoint); + } break; } - //Log("len = %i, buf = %s", len, buf); + if(len == 0) { + // Unprintable / Don't Pass + return; + } // Write if( MAX_INPUT_CHARS8 - term->InputWrite >= len ) diff --git a/Kernel/include/tpl_drv_keyboard.h b/Kernel/include/tpl_drv_keyboard.h index 1f330039..e94a1867 100644 --- a/Kernel/include/tpl_drv_keyboard.h +++ b/Kernel/include/tpl_drv_keyboard.h @@ -32,7 +32,7 @@ typedef void (*tKeybardCallback)(Uint32 Key); enum eTplKeyboard_KeyCodes { KEY_ESC = 0x1B, - KEY_NP_MASK = 0x80, //End of ASCII Range + KEY_NP_MASK = 0x40000000, //End of ASCII Range KEY_CAPSLOCK, KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT, @@ -48,7 +48,7 @@ enum eTplKeyboard_KeyCodes { KEY_WIN, KEY_MENU, // Modifiers - KEY_MODIFIERS = 0xC0, + KEY_MODIFIERS = 0x60000000, KEY_LCTRL, KEY_RCTRL, KEY_LALT, KEY_RALT, KEY_LSHIFT, KEY_RSHIFT, diff --git a/Kernel/modules.c b/Kernel/modules.c index 9ae940a6..eec50200 100644 --- a/Kernel/modules.c +++ b/Kernel/modules.c @@ -6,6 +6,7 @@ #include // === PROTOTYPES === + int Modules_LoadBuiltins(); int Module_LoadMem(void *Buffer, Uint Length, char *ArgString); int Module_LoadFile(char *Path, char *ArgString); int Module_int_ResolveDeps(tModule *Info); diff --git a/Modules/IPStack/main.c b/Modules/IPStack/main.c index 7f1e02f4..cf9adf65 100644 --- a/Modules/IPStack/main.c +++ b/Modules/IPStack/main.c @@ -1,6 +1,6 @@ /* * Acess2 IP Stack - * - Address Resolution Protocol + * - Stack Initialisation */ #define DEBUG 0 #define VERSION ((0<<8)|10) diff --git a/Modules/Makefile.tpl b/Modules/Makefile.tpl index 2484610d..0ceb7838 100644 --- a/Modules/Makefile.tpl +++ b/Modules/Makefile.tpl @@ -2,9 +2,11 @@ # Acess2 Module/Driver Templater Makefile # Makefile.tpl +_CPPFLAGS := $(CPPFLAGS) + -include ../../Makefile.cfg -CPPFLAGS = -I../../Kernel/include -I../../Kernel/arch/$(ARCHDIR)/include -DARCH=$(ARCH) +CPPFLAGS = -I../../Kernel/include -I../../Kernel/arch/$(ARCHDIR)/include -DARCH=$(ARCH) $(_CPPFLAGS) CFLAGS = -Wall -Werror -fno-stack-protector $(CPPFLAGS) OBJ := $(addsuffix .$(ARCH),$(OBJ)) diff --git a/Usermode/Libraries/libreadline.so_src/main.c b/Usermode/Libraries/libreadline.so_src/main.c index e145bc0c..f2ddf684 100644 --- a/Usermode/Libraries/libreadline.so_src/main.c +++ b/Usermode/Libraries/libreadline.so_src/main.c @@ -13,7 +13,7 @@ char *Readline(tReadline *Info) { char *ret; - int len, pos, space = 1023; + int len, pos, space = 1023-8-8; // optimised for the heap manager char ch; int scrollbackPos = Info->NumHistory; @@ -148,15 +148,18 @@ char *Readline(tReadline *Info) //if(Length) *Length = len; // Add to history - if( strcmp( Info->History[ Info->NumHistory-1 ], ret) != 0 ) + if( Info->UseHistory ) { - void *tmp; - Info->NumHistory ++; - tmp = realloc( Info->History, Info->NumHistory * sizeof(char*) ); - if(tmp != NULL) + if( strcmp( Info->History[ Info->NumHistory-1 ], ret) != 0 ) { - Info->History = tmp; - Info->History[ Info->NumHistory-1 ] = strdup(ret); + void *tmp; + Info->NumHistory ++; + tmp = realloc( Info->History, Info->NumHistory * sizeof(char*) ); + if(tmp != NULL) + { + Info->History = tmp; + Info->History[ Info->NumHistory-1 ] = strdup(ret); + } } } -- 2.20.1