Altered keyboard driver to correctly support Unicode
[tpg/acess2.git] / Kernel / drv / vterm.c
index 09f85ff..575d71f 100644 (file)
@@ -197,7 +197,6 @@ int VT_Install(char **Arguments)
 void VT_InitOutput()
 {
        giVT_OutputDevHandle = VFS_Open(gsVT_OutputDevice, VFS_OPENFLAG_WRITE);
-       LOG("giVT_OutputDevHandle = %x\n", giVT_OutputDevHandle);
        VT_SetTerminal( 0 );
 }
 
@@ -208,7 +207,6 @@ void VT_InitOutput()
 void VT_InitInput()
 {
        giVT_InputDevHandle = VFS_Open(gsVT_InputDevice, VFS_OPENFLAG_READ);
-       LOG("giVT_InputDevHandle = %x\n", giVT_InputDevHandle);
        if(giVT_InputDevHandle == -1)   return ;
        VFS_IOCtl(giVT_InputDevHandle, KB_IOCTL_SETCALLBACK, VT_KBCallBack);
 }
@@ -495,9 +493,9 @@ void VT_KBCallBack(Uint32 Codepoint)
                case KEY_F11:   VT_SetTerminal(10);     return;
                case KEY_F12:   VT_SetTerminal(11);     return;
                case KEY_PGUP:
-                       break;
+                       return;
                case KEY_PGDOWN:
-                       break;
+                       return;
                }
        }
        
@@ -505,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;
@@ -514,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 )
@@ -896,7 +917,7 @@ void VT_int_ChangeMode(tVTerm *Term, int NewMode)
 Uint8  *VT_Font_GetChar(Uint32 Codepoint);
 
 // === GLOBALS ===
-int    giVT_CharWidth = FONT_WIDTH;
+int    giVT_CharWidth = FONT_WIDTH+1;
 int    giVT_CharHeight = FONT_HEIGHT;
 
 // === CODE ===
@@ -909,13 +930,14 @@ void VT_Font_Render(Uint32 Codepoint, void *Buffer, int Pitch, Uint32 BGC, Uint3
        Uint8   *font;
        Uint32  *buf = Buffer;
         int    x, y;
+       
        font = VT_Font_GetChar(Codepoint);
        
        for(y = 0; y < FONT_HEIGHT; y ++)
        {
                for(x = 0; x < FONT_WIDTH; x ++)
                {
-                       if(*font & (1 << (FONT_WIDTH-x)))
+                       if(*font & (1 << (FONT_WIDTH-x-1)))
                                buf[x] = FGC;
                        else
                                buf[x] = BGC;

UCC git Repository :: git.ucc.asn.au