PS/2 keyboard lowercase support

This commit is contained in:
Arnau Camprubí 2022-06-20 18:05:28 +02:00
pare 16eac4556d
commit 95f823c2c3

Veure arxiu

@ -1,3 +1,4 @@
#include <stdbool.h>
#include "../lib/string.h" #include "../lib/string.h"
#include "keyboard.h" #include "keyboard.h"
#include "../arch/i686/isr.h" #include "../arch/i686/isr.h"
@ -6,16 +7,19 @@
#include "../lib/stdio.h" #include "../lib/stdio.h"
#include "../shell.h" #include "../shell.h"
static bool g_caps_lock = false;
static bool g_shift = false;
static char g_key_buffer[256]; static char g_key_buffer[256];
static const char g_sc_ascii[128] = { static const char g_sc_ascii[128] = {
'?', '?', '1', '2', '3', '4', '5', '6', '?', '?', '1', '2', '3', '4', '5', '6',
'7', '8', '9', '0', '-', '=', '?', '?', '7', '8', '9', '0', '-', '=', '?', '?',
'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i',
'O', 'P', '[', ']', '?', '?', 'A', 'S', 'o', 'p', '[', ']', '?', '?', 'a', 's',
'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';',
'\'', '`', '?', '\\', 'Z', 'X', 'C', 'V', '\'', '`', '?', '\\', 'z', 'x', 'c', 'v',
'B', 'N', 'M', ',', '.', '/', '?', '?', 'b', 'n', 'm', ',', '.', '/', '?', '?',
'?', ' ' '?', ' '
}; };
@ -25,8 +29,10 @@ static void user_input(char *str){
static void keyboard_callback(){ static void keyboard_callback(){
uint8_t scancode = i686_inb(0x60); uint8_t scancode = i686_inb(0x60);
//printf("KEYBOARD (%i)!\n", scancode); if(scancode == 0x2A) g_shift = true; // Shift pressed
if(scancode < 128){ // If it's a "pressed" event, not "released" else if(scancode == 0x2A + 128) g_shift = false; // Shift released
else if(scancode == 0x3A) g_caps_lock = !g_caps_lock; // Caps lock pressed
else if(scancode < 128){ // If it's a "pressed" event, not "released"
if(scancode == 0x0E){ // Backspace if(scancode == 0x0E){ // Backspace
putc('\b'); putc('\b');
g_key_buffer[strlen(g_key_buffer)-1] = '\0'; g_key_buffer[strlen(g_key_buffer)-1] = '\0';
@ -37,13 +43,15 @@ static void keyboard_callback(){
g_key_buffer[0] = '\0'; g_key_buffer[0] = '\0';
} }
else{ else{
putc(g_sc_ascii[scancode]); char c = g_sc_ascii[scancode];
if(c >= 'a' && c <= 'z' && g_shift != g_caps_lock) c += 'A' - 'a';
putc(c);
// strlen() works here because char[] is the same as // strlen() works here because char[] is the same as
// char*, and both are null-terminated, so they are // char*, and both are null-terminated, so they are
// exactly the same // exactly the same
int len = strlen(g_key_buffer); int len = strlen(g_key_buffer);
g_key_buffer[len] = g_sc_ascii[scancode]; g_key_buffer[len] = c;
g_key_buffer[len+1] = '\0'; g_key_buffer[len+1] = '\0';
} }
} }