From 4607b5aba5c7713b2bb3a6d8aaa0bfddd7dc40c1 Mon Sep 17 00:00:00 2001 From: xamidev Date: Sun, 28 Dec 2025 11:06:33 +0100 Subject: [PATCH] holy SHIFT --- src/io/term.c | 27 +++++++++++++++++++-- src/io/term.h | 1 + src/kbd/ps2.c | 66 ++++++++++++++++++++++++++++----------------------- src/kbd/ps2.h | 18 +++++++++++--- 4 files changed, 77 insertions(+), 35 deletions(-) diff --git a/src/io/term.c b/src/io/term.c index f2a913c..0852355 100644 --- a/src/io/term.c +++ b/src/io/term.c @@ -66,7 +66,19 @@ static void draw_char(char c, int px, int py, int fg, int bg) } } -static void putchar(char c) +static void erase_char(int px, int py) +{ + for (size_t y=0; y= framebuffer->width) { cursor.x = 0; @@ -87,7 +110,7 @@ static void putchar(char c) cursor.x++; } -// Overhead that could be avoided, right? +// Overhead that could be avoided, right? (for printf) void _putchar(char character) { putchar(character); diff --git a/src/io/term.h b/src/io/term.h index c7bcf5c..a240768 100644 --- a/src/io/term.h +++ b/src/io/term.h @@ -3,6 +3,7 @@ int term_init(); void kputs(const char* str); +void putchar(char c); enum TermColors { diff --git a/src/kbd/ps2.c b/src/kbd/ps2.c index 6565a71..3af8242 100644 --- a/src/kbd/ps2.c +++ b/src/kbd/ps2.c @@ -4,6 +4,7 @@ #include "../io/printf.h" #include "ps2.h" #include +#include "../io/term.h" // The key status bitfield will be used to see if ALT, CONTROL, or SHIFT is pressed uint8_t key_status = 0b00000000; @@ -156,50 +157,55 @@ void keyboard_handler() // Key release (bit 7 set) if (scancode & 0x80) { - if (key_status & SHIFT_PRESSED) + unsigned char code = scancode & 0x7F; + switch (code) { - serial_kputs("SHIFT was released!\n"); - key_status &= ~(1 << 0); // Unset SHIFT bit + // Clear the corresponding bit if corresponding key is released + case LEFT_SHIFT_PRESSED: + case RIGHT_SHIFT_PRESSED: + key_status &= ~SHIFT_PRESSED_BIT; + break; + case CTRL_PRESSED: + key_status &= ~CTRL_PRESSED_BIT; + break; + case ALT_PRESSED: + key_status &= ~ALT_PRESSED_BIT; + break; } - if (key_status & ALT_PRESSED) - { - serial_kputs("ALT was released!\n"); - key_status &= ~(1 << 1); // Unset ALT bit - } - - if (key_status & CTRL_PRESSED) - { - serial_kputs("CTRL was released!\n"); - key_status &= ~(1 << 2); // Unset CTRL bit - } + // Send EOI + outb(0x20, 0x20); + return; } else { // Key press - unsigned char character; - - switch (keymap[scancode]) + switch (scancode) { - case SHIFT: - serial_kputs("SHIFT "); - key_status |= (1 << 0); // SHIFT bit + // Set bits for corresponding special key press + case LEFT_SHIFT_PRESSED: + case RIGHT_SHIFT_PRESSED: + key_status |= SHIFT_PRESSED_BIT; break; - case ALT: - serial_kputs("ALT "); - key_status |= (1 << 1); + case CTRL_PRESSED: + key_status |= CTRL_PRESSED_BIT; break; - case CTRL: - serial_kputs("CTRL "); - key_status |= (1 << 2); + case ALT_PRESSED: + key_status |= ALT_PRESSED_BIT; break; + default: - character = (key_status & SHIFT_PRESSED) ? keymap_shifted[scancode] : keymap[scancode]; - printf("%c", character); - break; + { + // Should we get a SHIFTED char or a regular one? + unsigned char c = (key_status & SHIFT_PRESSED_BIT) ? keymap_shifted[scancode] : keymap[scancode]; + + if (c) + { + putchar(c); + } + } } - // Should we get a SHIFTED char or a regular one? serial_kputs("key pressed!\n"); } diff --git a/src/kbd/ps2.h b/src/kbd/ps2.h index 2ad8457..5b1c207 100644 --- a/src/kbd/ps2.h +++ b/src/kbd/ps2.h @@ -3,9 +3,9 @@ void keyboard_handler(); -#define SHIFT_PRESSED 0b00000001 -#define ALT_PRESSED 0b00000010 -#define CTRL_PRESSED 0b00000100 +#define SHIFT_PRESSED_BIT 0b00000001 +#define ALT_PRESSED_BIT 0b00000010 +#define CTRL_PRESSED_BIT 0b00000100 enum SpecialKeys { @@ -14,6 +14,18 @@ enum SpecialKeys CTRL = 253 }; +enum SpecialScancodes +{ + LEFT_SHIFT_PRESSED = 0x2A, + LEFT_SHIFT_RELEASED = 0xAA, + RIGHT_SHIFT_PRESSED = 0x36, + RIGHT_SHIFT_RELEASED = 0xB6, + CTRL_PRESSED = 0x1D, + CTRL_RELEASED = 0x9D, + ALT_PRESSED = 0x38, + ALT_RELEASED = 0xB8 +}; + enum KeyboardLayout { US,