Espresso 0.0.1a

This commit is contained in:
2025-06-17 15:50:07 -05:00
parent eeea3b2d86
commit fca025a9bf
24 changed files with 1080 additions and 600 deletions

View File

@ -1,6 +1,7 @@
#include <stdio.h>
#include <port_io.h>
#include <tty.h>
#include <stdlib.h>
#include <drivers/ps2_keyboard.h>
@ -27,10 +28,20 @@
#define KEYBOARD_IRQ 1
bool ps2keyboard_initialized = false;
/* State for shift key */
static bool shift_pressed = false;
/* State for caps-lock key */
static bool capslock_pressed = false;
volatile char current_char;
volatile char* current_string = NULL;
volatile int32_t current_length = 0;
volatile int32_t capacity = 0;
static const char scancode_map[128] = {
0, 27, '1','2','3','4','5','6','7','8','9','0','-','=','\b', /* Backspace */
'\t', // Tab
@ -51,6 +62,55 @@ static const char scancode_map[128] = {
void keyboard_init(void)
{
outb(0x64, 0xAE); /* Enable keyboard interface (often optional, but here for safety) */
ps2keyboard_initialized = true;
}
char get_char(void)
{
return current_char;
}
char* get_string(void)
{
return current_string;
}
static void append_char(char c)
{
if (current_length + 1 >= capacity)
{
/* Need more space (+1 for '\0') */
int new_capacity = (capacity == 0) ? 16 : capacity * 2;
char* new_str = (char*)malloc(new_capacity);
if (!new_str) {
return;
}
if (current_string)
{
memcpy(new_str, current_string, current_length);
free(current_string);
}
current_string = new_str;
capacity = new_capacity;
}
current_string[current_length] = c;
current_length++;
current_string[current_length] = '\0'; /* Maintain null terminator */
}
static void free_current_string(void)
{
if (current_string)
{
free(current_string);
current_string = NULL;
current_length = 0;
capacity = 0;
}
}
void keyboard_handler(void) {
@ -67,6 +127,12 @@ void keyboard_handler(void) {
shift_pressed = false;
return;
}
else if (scancode == 0x3A)
{
capslock_pressed = !capslock_pressed;
return;
}
if (scancode & 0x80)
{
@ -74,7 +140,7 @@ void keyboard_handler(void) {
} else
{
char c = scancode_map[scancode];
if (shift_pressed && c >= 'a' && c <= 'z') {
if ((shift_pressed ^ capslock_pressed) && c >= 'a' && c <= 'z') {
c -= 32; /* Convert to uppercase */
}
else if (shift_pressed)
@ -84,7 +150,17 @@ void keyboard_handler(void) {
if (c)
{
printf("%c", c);
current_char = c;
if (c == '\n')
{
free_current_string();
}
else
{
append_char(c);
printf("%c", c);
}
}
}
}