holy SHIFT

This commit is contained in:
2025-12-28 11:06:33 +01:00
parent cc36c768cf
commit 4607b5aba5
4 changed files with 77 additions and 35 deletions

View File

@@ -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<FONT_HEIGHT; y++)
{
for (size_t x=0; x<8; x++)
{
// Black
putpixel(px+x, py+y, 0);
}
}
}
void putchar(char c)
{ {
if (c == '\n') if (c == '\n')
{ {
@@ -75,6 +87,17 @@ static void putchar(char c)
return; return;
} }
// Improperly handled.
// When we're on an empty line it should get to the upper line's last character
if (c == '\b')
{
cursor.x--;
int px = cursor.x * FONT_WIDTH;
int py = cursor.y * FONT_HEIGHT;
erase_char(px, py);
return;
}
if ((cursor.x+1)*FONT_WIDTH >= framebuffer->width) if ((cursor.x+1)*FONT_WIDTH >= framebuffer->width)
{ {
cursor.x = 0; cursor.x = 0;
@@ -87,7 +110,7 @@ static void putchar(char c)
cursor.x++; cursor.x++;
} }
// Overhead that could be avoided, right? // Overhead that could be avoided, right? (for printf)
void _putchar(char character) void _putchar(char character)
{ {
putchar(character); putchar(character);

View File

@@ -3,6 +3,7 @@
int term_init(); int term_init();
void kputs(const char* str); void kputs(const char* str);
void putchar(char c);
enum TermColors enum TermColors
{ {

View File

@@ -4,6 +4,7 @@
#include "../io/printf.h" #include "../io/printf.h"
#include "ps2.h" #include "ps2.h"
#include <stdint.h> #include <stdint.h>
#include "../io/term.h"
// The key status bitfield will be used to see if ALT, CONTROL, or SHIFT is pressed // The key status bitfield will be used to see if ALT, CONTROL, or SHIFT is pressed
uint8_t key_status = 0b00000000; uint8_t key_status = 0b00000000;
@@ -156,50 +157,55 @@ void keyboard_handler()
// Key release (bit 7 set) // Key release (bit 7 set)
if (scancode & 0x80) if (scancode & 0x80)
{ {
if (key_status & SHIFT_PRESSED) unsigned char code = scancode & 0x7F;
switch (code)
{ {
serial_kputs("SHIFT was released!\n"); // Clear the corresponding bit if corresponding key is released
key_status &= ~(1 << 0); // Unset SHIFT bit 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) // Send EOI
{ outb(0x20, 0x20);
serial_kputs("ALT was released!\n"); return;
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
}
} }
else else
{ {
// Key press // Key press
unsigned char character; switch (scancode)
switch (keymap[scancode])
{ {
case SHIFT: // Set bits for corresponding special key press
serial_kputs("SHIFT "); case LEFT_SHIFT_PRESSED:
key_status |= (1 << 0); // SHIFT bit case RIGHT_SHIFT_PRESSED:
key_status |= SHIFT_PRESSED_BIT;
break; break;
case ALT: case CTRL_PRESSED:
serial_kputs("ALT "); key_status |= CTRL_PRESSED_BIT;
key_status |= (1 << 1);
break; break;
case CTRL: case ALT_PRESSED:
serial_kputs("CTRL "); key_status |= ALT_PRESSED_BIT;
key_status |= (1 << 2);
break; break;
default: default:
character = (key_status & SHIFT_PRESSED) ? keymap_shifted[scancode] : keymap[scancode]; {
printf("%c", character); // Should we get a SHIFTED char or a regular one?
break; 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"); serial_kputs("key pressed!\n");
} }

View File

@@ -3,9 +3,9 @@
void keyboard_handler(); void keyboard_handler();
#define SHIFT_PRESSED 0b00000001 #define SHIFT_PRESSED_BIT 0b00000001
#define ALT_PRESSED 0b00000010 #define ALT_PRESSED_BIT 0b00000010
#define CTRL_PRESSED 0b00000100 #define CTRL_PRESSED_BIT 0b00000100
enum SpecialKeys enum SpecialKeys
{ {
@@ -14,6 +14,18 @@ enum SpecialKeys
CTRL = 253 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 enum KeyboardLayout
{ {
US, US,