From: John Hodge Date: Tue, 22 Sep 2009 01:27:47 +0000 (+0800) Subject: Implemented VT_Read(), added stub UTF32 output support, also made WriteUTF8() to... X-Git-Tag: rel0.06~548 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=d84c449919ed7a288945d043a04802d96daf7047;p=tpg%2Facess2.git Implemented VT_Read(), added stub UTF32 output support, also made WriteUTF8() to help --- diff --git a/Kernel/drv/kb.c b/Kernel/drv/kb.c index 013e9536..0de8fe12 100644 --- a/Kernel/drv/kb.c +++ b/Kernel/drv/kb.c @@ -23,7 +23,7 @@ void KB_UpdateLEDs(); // === GLOBALS === MODULE_DEFINE(0, 0x0100, PS2Keybard, KB_Install, NULL, NULL); tDevFS_Driver gKB_DevInfo = { - NULL, "PS2Kb", + NULL, "PS2Keyboard", { .NumACLs = 0, .Size = -1, @@ -181,8 +181,7 @@ void KB_IRQHandler() } } - if(gKB_Callback) - gKB_Callback(ch); + if(gKB_Callback) gKB_Callback(ch); } /** diff --git a/Kernel/drv/vterm.c b/Kernel/drv/vterm.c index b0684ffc..2937b372 100644 --- a/Kernel/drv/vterm.c +++ b/Kernel/drv/vterm.c @@ -8,7 +8,7 @@ // === CONSTANTS === #define NUM_VTS 4 -#define MAX_INPUT_BYTES 64 +#define MAX_INPUT_CHARS 64 #define VT_SCROLLBACK 4 // 4 Screens of text #define DEFAULT_OUTPUT "/Devices/VGA" #define DEFAULT_INPUT "/Devices/PS2Keyboard" @@ -17,11 +17,12 @@ #define DEFAULT_COLOUR (VT_COL_BLACK|(VT_COL_WHITE<<16)) enum eVT_Modes { - VT_MODE_TEXT, - VT_MODE_8BPP, - VT_MODE_16BPP, - VT_MODE_24BPP, - VT_MODE_32BPP, + VT_MODE_TEXT8, // UTF-8 Text Mode (VT100 Emulation) + VT_MODE_TEXT32, // UTF-32 Text Mode (Acess Native) + VT_MODE_8BPP, // 256 Colour Mode + VT_MODE_16BPP, // 16 bit Colour Mode + VT_MODE_24BPP, // 24 bit Colour Mode + VT_MODE_32BPP, // 32 bit Colour Mode NUM_VT_MODES }; @@ -32,8 +33,9 @@ typedef struct { int ViewPos, WritePos; Uint32 CurColour; char Name[2]; - int NumInputBytes; - Uint8 InputBuffer[MAX_INPUT_BYTES]; + int InputRead; + int InputWrite; + Uint32 InputBuffer[MAX_INPUT_CHARS]; union { tVT_Char *Text; Uint32 *Buffer; @@ -48,6 +50,7 @@ tVFS_Node *VT_FindDir(tVFS_Node *Node, char *Name); Uint64 VT_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); Uint64 VT_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); int VT_IOCtl(tVFS_Node *Node, int Id, void *Data); +void VT_KBCallBack(Uint32 Codepoint); void VT_int_PutString(tVTerm *Term, Uint8 *Buffer, Uint Count); int VT_int_ParseEscape(tVTerm *Term, char *Buffer); void VT_int_PutChar(tVTerm *Term, Uint32 Ch); @@ -129,7 +132,7 @@ int VT_Install(char **Arguments) // Create Nodes for( i = 0; i < NUM_VTS; i++ ) { - gVT_Terminals[i].Mode = VT_MODE_TEXT; + gVT_Terminals[i].Mode = VT_MODE_TEXT8; gVT_Terminals[i].Width = DEFAULT_WIDTH; gVT_Terminals[i].Height = DEFAULT_HEIGHT; gVT_Terminals[i].CurColour = DEFAULT_COLOUR; @@ -222,8 +225,37 @@ tVFS_Node *VT_FindDir(tVFS_Node *Node, char *Name) */ Uint64 VT_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) { - //ENTER("pNode XOffset XLength pBuffer", Node, Offset, Length, Buffer); - //LEAVE('i', 0); + int pos = 0; + tVTerm *term = &gVT_Terminals[ Node->Inode ]; + + // Check current mode + switch(term->Mode) + { + case VT_MODE_TEXT8: + while(pos < Length) + { + while(term->InputRead == term->InputWrite) Proc_Yield(); + while(term->InputRead != term->InputWrite) + { + pos += WriteUTF8(Buffer+pos, term->InputBuffer[term->InputRead]); + term->InputRead ++; + } + } + break; + + case VT_MODE_TEXT32: + while(pos < Length) + { + while(term->InputRead == term->InputWrite) Proc_Yield(); + while(term->InputRead != term->InputWrite) + { + ((Uint32*)Buffer)[pos] = term->InputBuffer[term->InputRead]; + pos ++; + term->InputRead ++; + } + } + break; + } return 0; } @@ -240,9 +272,12 @@ Uint64 VT_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) // Write switch( term->Mode ) { - case VT_MODE_TEXT: + case VT_MODE_TEXT8: VT_int_PutString(term, Buffer, Length); break; + case VT_MODE_TEXT32: + //VT_int_PutString32(term, Buffer, Length); + break; } //LEAVE('i', 0); return 0; @@ -257,6 +292,23 @@ int VT_IOCtl(tVFS_Node *Node, int Id, void *Data) return 0; } +/** + * \fn void VT_KBCallBack(Uint32 Codepoint) + * \brief Called on keyboard interrupt + */ +void VT_KBCallBack(Uint32 Codepoint) +{ + tVTerm *term = &gVT_Terminals[giVT_CurrentTerminal]; + + term->InputBuffer[ term->InputWrite ] = Codepoint; + term->InputWrite ++; + term->InputWrite %= MAX_INPUT_CHARS; + if(term->InputRead == term->InputWrite) { + term->InputRead ++; + term->InputRead %= MAX_INPUT_CHARS; + } +} + /** * \fn void VT_int_PutString(tVTerm *Term, Uint8 *Buffer, Uint Count) * \brief Print a string to the Virtual Terminal diff --git a/Kernel/include/common.h b/Kernel/include/common.h index f199ef59..827d8ff0 100644 --- a/Kernel/include/common.h +++ b/Kernel/include/common.h @@ -86,6 +86,7 @@ extern int strpos(char *Str, char Ch); extern int strpos8(char *str, Uint32 search); extern void itoa(char *buf, Uint num, int base, int minLength, char pad); extern int ReadUTF8(Uint8 *str, Uint32 *Val); +extern int WriteUTF8(Uint8 *str, Uint32 Val); // --- Heap --- extern void *malloc(size_t size); extern void *realloc(void *ptr, size_t size); diff --git a/Kernel/lib.c b/Kernel/lib.c index ee9f24e0..c8a0e9f1 100644 --- a/Kernel/lib.c +++ b/Kernel/lib.c @@ -168,6 +168,8 @@ int strpos8(char *str, Uint32 Search) */ int ReadUTF8(Uint8 *str, Uint32 *Val) { + *Val = 0xFFFD; // Assume invalid character + // ASCII if( !(*str & 0x80) ) { *Val = *str; @@ -176,7 +178,6 @@ int ReadUTF8(Uint8 *str, Uint32 *Val) // Middle of a sequence if( (*str & 0xC0) == 0x80 ) { - *Val = -1; return 1; } @@ -217,10 +218,55 @@ int ReadUTF8(Uint8 *str, Uint32 *Val) } // UTF-8 Doesn't support more than four bytes - *Val = -1; return 4; } +/** + * \fn int WriteUTF8(Uint8 *str, Uint32 Val) + * \brief Write a UTF-8 character sequence to a string + */ +int WriteUTF8(Uint8 *str, Uint32 Val) +{ + // ASCII + if( Val < 128 ) { + *str = Val; + return 1; + } + + // Two Byte + if( Val < 0x8000 ) { + *str = 0xC0 | (Val >> 6); + str ++; + *str = 0x80 | (Val & 0x3F); + return 2; + } + + // Three Byte + if( Val < 0x10000 ) { + *str = 0xE0 | (Val >> 12); + str ++; + *str = 0x80 | ((Val >> 6) & 0x3F); + str ++; + *str = 0x80 | (Val & 0x3F); + return 3; + } + + // Four Byte + if( Val < 0x110000 ) { + *str = 0xF0 | (Val >> 18); + str ++; + *str = 0x80 | ((Val >> 12) & 0x3F); + str ++; + *str = 0x80 | ((Val >> 6) & 0x3F); + str ++; + *str = 0x80 | (Val & 0x3F); + return 4; + } + + // UTF-8 Doesn't support more than four bytes + return 0; +} + /** * \fn Uint64 timestamp(int sec, int mins, int hrs, int day, int month, int year) * \brief Converts a date into an Acess Timestamp