Espresso 0.0.1d

This commit is contained in:
2025-07-03 20:30:21 -05:00
parent 8648637b51
commit 078ca8169b
14 changed files with 337 additions and 28 deletions

View File

@ -36,15 +36,22 @@ static bool shift_pressed = false;
/* State for caps-lock key */
static bool capslock_pressed = false;
volatile char current_char;
/* Used for arrow keys among others */
static bool extended = false;
static bool is_new_char = false;
static bool is_new_key = false;
volatile unsigned char current_char;
volatile char* current_string = NULL;
volatile int32_t current_length = 0;
volatile int32_t capacity = 0;
volatile uint16_t current_key;
static const char scancode_map[128] = {
0, 27, '1','2','3','4','5','6','7','8','9','0','-','=','\b', /* Backspace */
'\t', // Tab
'\t', /* Tab */
'q','w','e','r','t','y','u','i','o','p','[',']','\n', /* Enter */
0, /* Control */
'a','s','d','f','g','h','j','k','l',';','\'','`',
@ -67,7 +74,46 @@ void keyboard_init(void)
char get_char(void)
{
return current_char;
/*
ASCII code 5 (Enquiry) is/was used in legacy systems meant for requesting a response from a remote terminal or device.
For example, one system might send ENQ (ASCII 5), and the receiver could reply with ACK (ASCII 6) to indicate its ready or still online.
In modern computing, ENQ is largely obsolete:
- Terminal emulators, shells, operating systems, and network protocols generally do not use ENQ.
- It's not used in text files, programming, or standard communications.
- It may still appear in legacy systems, embedded devices, or proprietary serial protocols, but that's niche.
*/
char temp = 5;
if (is_new_char)
{
temp = current_char;
}
is_new_char = false;
return temp;
}
uint16_t get_key(void)
{
uint16_t temp = 0xFFFA;
if (is_new_key)
{
temp = current_key;
is_new_key = false;
}
else if (is_new_char)
{
temp = (uint16_t)current_char;
is_new_char = false;
}
return temp;
}
char* get_string(void)
@ -118,7 +164,8 @@ static void free_current_string(void)
}
}
void keyboard_handler(void) {
void keyboard_handler(void)
{
uint8_t scancode = inb(PS2_DATA_PORT);
/* Handle shift press/release */
@ -137,41 +184,76 @@ void keyboard_handler(void) {
capslock_pressed = !capslock_pressed;
return;
}
else if (scancode == 0xE0)
{
extended = true;
return;
}
if (scancode & 0x80)
{
/* Key release event, ignore for now */
} else
extended = false;
}
else
{
char c = scancode_map[scancode];
if ((shift_pressed ^ capslock_pressed) && c >= 'a' && c <= 'z') {
uint16_t c = (uint16_t)scancode_map[scancode];
if ((shift_pressed ^ capslock_pressed) && ((char)c >= 'a') && ((char)c <= 'z'))
{
c -= 32; /* Convert to uppercase */
}
else if (shift_pressed)
{
c = (char) terminal_get_shifted((unsigned char) c);
c = (uint16_t) terminal_get_shifted((unsigned char) c);
}
if (scancode == 0x1C) {
/*if (scancode == 0x1C) {
printf("\n");
return;
}
}*/
if (extended)
{
switch (scancode)
{
case 0x48:
c = KEY_ARROW_UP;
break;
case 0x50:
c = KEY_ARROW_DOWN;
break;
case 0x4B:
c = KEY_ARROW_LEFT;
break;
case 0x4D:
c = KEY_ARROW_RIGHT;
break;
default:
c = KEY_NONE;
break;
}
current_key = c;
is_new_key = true;
extended = false;
return;
}
if (c)
{
current_char = c;
is_new_char = true;
if (c == '\n')
{
free_current_string();
}
else
{
append_char(c);
printf("%c", c);
}
append_char(c);
}
}
}