about summary refs log tree commit diff
diff options
context:
space:
mode:
authorYour Name <you@example.com>2020-06-24 16:18:09 +0200
committerYour Name <you@example.com>2020-06-24 16:18:09 +0200
commitc7f36d320e4a12ea067794196d693e69c0007a41 (patch)
treef6d1e907151c6704c34c7c64c0d090a343838acb
parentstdlib: add getc() (diff)
downloadpOS-c7f36d320e4a12ea067794196d693e69c0007a41.tar.gz
pOS-c7f36d320e4a12ea067794196d693e69c0007a41.tar.bz2
pOS-c7f36d320e4a12ea067794196d693e69c0007a41.zip
Driver: added basic support for keybinds in the Keyboard driver
-rw-r--r--src/pOS/arch/x86/kernel/drivers/keyboard/include/kbbuf.h3
-rw-r--r--src/pOS/arch/x86/kernel/drivers/keyboard/include/scancodes.h8
-rw-r--r--src/pOS/arch/x86/kernel/drivers/keyboard/kbbuf.cpp41
3 files changed, 49 insertions, 3 deletions
diff --git a/src/pOS/arch/x86/kernel/drivers/keyboard/include/kbbuf.h b/src/pOS/arch/x86/kernel/drivers/keyboard/include/kbbuf.h
index f2e7a91..6b76fa0 100644
--- a/src/pOS/arch/x86/kernel/drivers/keyboard/include/kbbuf.h
+++ b/src/pOS/arch/x86/kernel/drivers/keyboard/include/kbbuf.h
@@ -19,9 +19,10 @@ class KB_BUF
 public:
     static int init(void);
     static int scan(unsigned char code);
-    static void keyboard_enqueue(unsigned char ascii);
     static unsigned char keyboard_dequeue(void);
 private:
+    static void keyboard_enqueue(unsigned char ascii);
+    static int handle_keybind(unsigned char ascii, int type);
     static keyboard_buffer keyboard_buf;
 };
 
diff --git a/src/pOS/arch/x86/kernel/drivers/keyboard/include/scancodes.h b/src/pOS/arch/x86/kernel/drivers/keyboard/include/scancodes.h
index 1555c32..590cef4 100644
--- a/src/pOS/arch/x86/kernel/drivers/keyboard/include/scancodes.h
+++ b/src/pOS/arch/x86/kernel/drivers/keyboard/include/scancodes.h
@@ -14,5 +14,13 @@ extern unsigned char shift_scancode[128];
 #define RSHIFT_PRESS 54
 #define LSHIFT_RELEASE 170
 #define RSHIFT_RELEASE 182
+#define LCTRL_PRESS 29
+#define RCTRL_PRESS 29      //TODO: change
+#define LCTRL_RELEASE 157
+#define RCTRL_RELEASE 157   //TODO: change
+#define LALT_PRESS 56
+#define RALT_PRESS 56       //TODO: change?
+#define LALT_RELEASE 184
+#define RALT_RELEASE 184    //TODO: change?
 
 #endif
diff --git a/src/pOS/arch/x86/kernel/drivers/keyboard/kbbuf.cpp b/src/pOS/arch/x86/kernel/drivers/keyboard/kbbuf.cpp
index f178adf..ceac96b 100644
--- a/src/pOS/arch/x86/kernel/drivers/keyboard/kbbuf.cpp
+++ b/src/pOS/arch/x86/kernel/drivers/keyboard/kbbuf.cpp
@@ -13,6 +13,8 @@ int KB_BUF::init(void)
 int KB_BUF::scan(unsigned char code)
 {
   static bool shifted = 0;
+  static bool ctrled = 0;
+  static bool alted = 0;
   int result = 1;
 
   switch(code)
@@ -56,13 +58,39 @@ int KB_BUF::scan(unsigned char code)
         shifted = false;
         break;
 
+    case LCTRL_PRESS:
+    //case RCTRL_PRESS:
+        ctrled = true;
+        break;
+
+    case LCTRL_RELEASE:
+    //case RCTRL_RELEASE:
+        ctrled = false;
+        break;
+
+    case LALT_PRESS:
+    //case RALT_PRESS:
+        alted = true;
+        break;
+
+    case LALT_RELEASE:
+    //case RALT_RELEASE:
+        alted = false;
+        break;
+
     default:
       if(!(code & 0x80))
       {
+          unsigned char ascii;
         if(shifted)
-            keyboard_enqueue(shift_scancode[code]);
+            ascii = shift_scancode[code];
+        else
+            ascii = scancode[code];
+
+        if(ctrled || alted)
+            handle_keybind(ascii, ctrled ? 1 : -1);
         else
-            keyboard_enqueue(scancode[code]);
+            keyboard_enqueue(ascii);
 
         result = 0;
       }
@@ -72,6 +100,15 @@ int KB_BUF::scan(unsigned char code)
   return result;
 }
 
+int KB_BUF::handle_keybind(unsigned char ascii, int type)
+{
+    UNUSED_VARIABLE(ascii);
+    UNUSED_VARIABLE(type);
+    //if(type == 1); /* CTRL */
+    //else if (type == -1); /* ALT */
+    /* TODO: Signals */
+    return 0;
+}
 
 unsigned char KB_BUF::keyboard_dequeue(void)
 {