Kernel - Cleaning up a little (implemented MIN and MAX functions)
[tpg/acess2.git] / Modules / Input / PS2KbMouse / kb.c
index d8ef32e..56c98c2 100644 (file)
@@ -5,8 +5,8 @@
 #include <acess.h>
 #include <modules.h>
 #include <fs_devfs.h>
-#include <tpl_drv_common.h>
-#include <tpl_drv_keyboard.h>
+#include <api_drv_common.h>
+#include <api_drv_keyboard.h>
 #include "kb_kbdus.h"
 
 // === CONSTANTS ===
@@ -20,9 +20,7 @@ extern void   Heap_Stats(void);
 
 // === PROTOTYPES ===
  int   KB_Install(char **Arguments);
-void   KB_IRQHandler(int IRQNum);
-void   KB_AddBuffer(char ch);
-Uint64 KB_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Dest);
+void   KB_HandleScancode(Uint8 scancode);
 void   KB_UpdateLEDs(void);
  int   KB_IOCtl(tVFS_Node *Node, int Id, void *Data);
 
@@ -32,7 +30,6 @@ tDevFS_Driver gKB_DevInfo = {
        {
        .NumACLs = 0,
        .Size = 0,
-       //.Read = KB_Read,
        .IOCtl = KB_IOCtl
        }
 };
@@ -55,19 +52,6 @@ Uint8        gbaKB_States[3][256];
  */
 int KB_Install(char **Arguments)
 {
-       
-       IRQ_AddHandler(1, KB_IRQHandler);
-       
-       {
-               Uint8   temp;
-               // Attempt to get around a strange bug in Bochs/Qemu by toggling
-               // the controller on and off
-               temp = inb(0x61);
-               outb(0x61, temp | 0x80);
-               outb(0x61, temp & 0x7F);
-               inb(0x60);      // Clear keyboard buffer
-       }
-       
        DevFS_AddDevice( &gKB_DevInfo );
        //Log("KB_Install: Installed");
        return MODULE_ERR_OK;
@@ -77,16 +61,11 @@ int KB_Install(char **Arguments)
  * \brief Called on a keyboard IRQ
  * \param IRQNum       IRQ number (unused)
  */
-void KB_IRQHandler(int IRQNum)
+void KB_HandleScancode(Uint8 scancode)
 {
-       Uint8   scancode;
        Uint32  ch;
-       // int  keyNum;
-
-       // Check port 0x64 to tell if this is from the aux port
-       //if( inb(0x64) & 0x20 )        return;
+        int    bCaseSwitch = (gbKB_ShiftState != 0) != (gbKB_CapsState != 0);
 
-       scancode = inb(0x60); // Read from the keyboard's data buffer
        //Log_Debug("Keyboard", "scancode = %02x", scancode);
 
        // Ignore ACKs
@@ -121,12 +100,23 @@ void KB_IRQHandler(int IRQNum)
                gbKB_KeyUp = 1;
        }
        #endif
+       
+       if( gKB_Callback )
+               gKB_Callback( (giKB_KeyLayer << 8) | scancode | KEY_ACTION_RAWSYM );
 
        // Translate
-       ch = gpKB_Map[giKB_KeyLayer][scancode];
+       ch = gpKB_Map[giKB_KeyLayer*2+bCaseSwitch][scancode];
+       // - Unknown characters in the shift layer fall through to lower
+       if(bCaseSwitch && ch == 0)
+               ch = gpKB_Map[giKB_KeyLayer*2][scancode];
        // Check for unknown key
-       if(!ch && !gbKB_KeyUp)
-               Log_Warning("Keyboard", "UNK %i %x", giKB_KeyLayer, scancode);
+       if(!ch)
+       {
+               if(!gbKB_KeyUp)
+                       Log_Warning("Keyboard", "UNK %i %x", giKB_KeyLayer, scancode);
+//             return ;
+               // Can pass through to ensure each raw message has a up/down with it
+       }
 
        // Key Up?
        if (gbKB_KeyUp)
@@ -143,14 +133,21 @@ void KB_IRQHandler(int IRQNum)
                if(ch == KEY_RSHIFT)    gbKB_ShiftState &= ~2;
 
                // Call callback
-               if(ch != 0 && gKB_Callback)
-                       gKB_Callback( ch & 0x80000000 );
+               if(gKB_Callback)        gKB_Callback( ch | KEY_ACTION_RELEASE );
 
                // Reset Layer
                giKB_KeyLayer = 0;
                return;
        }
 
+       // Refire?
+       if( gbaKB_States[giKB_KeyLayer][scancode] == 1 )
+       {
+               if(gKB_Callback)        gKB_Callback(ch | KEY_ACTION_REFIRE);
+               giKB_KeyLayer = 0;
+               return ;
+       }
+
        // Set the bit relating to the key
        gbaKB_States[giKB_KeyLayer][scancode] = 1;
        // Set shift key bits
@@ -163,12 +160,6 @@ void KB_IRQHandler(int IRQNum)
                KB_UpdateLEDs();
        }
 
-       // Reset Layer
-       giKB_KeyLayer = 0;
-
-       // Ignore Non-Printable Characters
-       if(ch == 0)             return;
-
        // --- Check for Kernel Magic Combos
        #if USE_KERNEL_MAGIC
        if(ch == KEY_LCTRL) {
@@ -212,42 +203,11 @@ void KB_IRQHandler(int IRQNum)
        }
        #endif
 
-       // Capitals required?
-       if( (gbKB_ShiftState != 0) != (gbKB_CapsState != 0))
-       {
-               // TODO: Move this to the keyboard map header
-               switch(ch)
-               {
-               case 0: break;
-               case '`':       ch = '~';       break;
-               case '1':       ch = '!';       break;
-               case '2':       ch = '@';       break;
-               case '3':       ch = '#';       break;
-               case '4':       ch = '$';       break;
-               case '5':       ch = '%';       break;
-               case '6':       ch = '^';       break;
-               case '7':       ch = '&';       break;
-               case '8':       ch = '*';       break;
-               case '9':       ch = '(';       break;
-               case '0':       ch = ')';       break;
-               case '-':       ch = '_';       break;
-               case '=':       ch = '+';       break;
-               case '[':       ch = '{';       break;
-               case ']':       ch = '}';       break;
-               case '\\':      ch = '|';       break;
-               case ';':       ch = ':';       break;
-               case '\'':      ch = '"';       break;
-               case ',':       ch = '<';       break;
-               case '.':       ch = '>';       break;
-               case '/':       ch = '?';       break;
-               default:
-                       if('a' <= ch && ch <= 'z')
-                               ch -= 0x20;
-                       break;
-               }
-       }
+       if(gKB_Callback)
+               gKB_Callback(ch | KEY_ACTION_PRESS);
 
-       if(gKB_Callback && ch != 0)     gKB_Callback(ch);
+       // Reset Layer
+       giKB_KeyLayer = 0;
 }
 
 /**
@@ -260,11 +220,8 @@ void KB_UpdateLEDs(void)
 
        leds = (gbKB_CapsState ? 4 : 0);
 
-       while( inb(0x64) & 2 ); // Wait for bit 2 to unset
-       outb(0x60, 0xED);       // Send update command
-
-       while( inb(0x64) & 2 ); // Wait for bit 2 to unset
-       outb(0x60, leds);
+       // TODO: Update LEDS
+       Log_Warning("Keyboard", "TODO: Update LEDs");
 }
 
 static const char      *csaIOCTL_NAMES[] = {DRV_IOCTLNAMES, DRV_KEYBAORD_IOCTLNAMES, NULL};

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