Okay wow i forgot to commit a bunch of stuff

I added some work on a keyboard driver here
also changed the emulation system, since bochs was giving me headaches when it came to keyboard input
added some todo stuff.. probably some cleanup, idk
This commit is contained in:
2025-06-03 19:08:45 -04:00
parent ca77157344
commit af92026a74
11 changed files with 160 additions and 156 deletions

View File

@ -1,126 +1,95 @@
#include <stdbool.h>
#include <stdint.h>
#include <queue.h>
#ifdef __TESTING__
#include <kernel/_kernel.h>
#include <stdio.h>
#endif
#include <kernel/x86/keyb.h>
#include <kernel/x86/io.h>
bool is_shift_down = false;
queue kb_cmd_queue;
// current plan is to create a a multi d array
//
//
// 16 entries each for each scan code... so
// 0x01..0x0F (15)/ this is the top row, so esc - 1..0, etc
// 0x10..0x1F (16) ...
// 0x20..0x2F ...
// these arrays will keep a 0/1 flag to see if these keys are pressed
// as a stort of state machine
// this will also let us tell multiple keys pressed
//
// another more simple version, which i could start with
//
// is do a Single character as currently pressed
// and a bitflag we can mask for leftshift, leftctrl, right shift, right ctrl, alt, etc being pressed down
//
//
//
struct keyboard_state keyb_state;
void init_kb(void)
{
#ifdef __TESTING__
puts("Initializing keyboard driver!");
#endif
init_queue(&kb_cmd_queue);
keyb_state.leds = 0;
queue_kb_command(KEYB_CMD_ENABLE_SCANNING);
queue_kb_command(KEYB_CMD_SET_DEFAULT_PARAMS);
//queue_kb_command(KEYB_CMD_SET_TYPEMATIC);
//queue_kb_command(0x1F);
send_kb_commands();
#ifdef __TESTING__
puts("Initialized keyboard driver!");
#endif
}
void queue_kb_command(uint8_t command)
{enqueue(&kb_cmd_queue, command);}
void send_kb_commands(void)
{
int i;
uint8_t resp, cmd;
while (!queue_is_empty(&kb_cmd_queue)) {
cmd = queue_peek(&kb_cmd_queue);
for (i = 0; i < KEYB_CMD_RETRIES; i++) {
outb(KEYB_PORT, cmd);
io_wait();
resp = inb(KEYB_PORT);
io_wait();
switch(resp) {
case KEYB_RESP_ACK:
break;
case KEYB_RESP_RESEND:
continue;
default:
break;
}
}
dequeue(&kb_cmd_queue);
}
}
kb_key_press_t decode_scancode(uint8_t scancode)
{return (kb_key_press_t) scancode;}
// TODO: check the shift scan code as a boolean, if yes ... blah blah
char decode_key_enum(kb_key_press_t keycode)
{
switch(keycode) {
case KEY_Q:
return (is_shift_down) ? 'Q' : 'q';
case KEY_W:
return (is_shift_down) ? 'W' : 'w';
case KEY_E:
return (is_shift_down) ? 'E' : 'e';
case KEY_R:
return (is_shift_down) ? 'R' : 'r';
case KEY_T:
return (is_shift_down) ? 'T' : 't';
case KEY_Y:
return (is_shift_down) ? 'Y' : 'y';
case KEY_U:
return (is_shift_down) ? 'U' : 'u';
case KEY_I:
return (is_shift_down) ? 'I' : 'i';
case KEY_O:
return (is_shift_down) ? 'O' : 'o';
case KEY_P:
return (is_shift_down) ? 'P' : 'p';
case KEY_A:
return (is_shift_down) ? 'A' : 'a';
case KEY_S:
return (is_shift_down) ? 'S' : 's';
case KEY_D:
return (is_shift_down) ? 'D' : 'd';
case KEY_F:
return (is_shift_down) ? 'F' : 'f';
case KEY_G:
return (is_shift_down) ? 'G' : 'g';
case KEY_H:
return (is_shift_down) ? 'H' : 'h';
case KEY_J:
return (is_shift_down) ? 'J' : 'j';
case KEY_K:
return (is_shift_down) ? 'K' : 'k';
case KEY_L:
return (is_shift_down) ? 'L' : 'l';
case KEY_Z:
return (is_shift_down) ? 'Z' : 'z';
case KEY_X:
return (is_shift_down) ? 'X' : 'x';
case KEY_C:
return (is_shift_down) ? 'C' : 'c';
case KEY_V:
return (is_shift_down) ? 'V' : 'v';
case KEY_B:
return (is_shift_down) ? 'B' : 'b';
case KEY_N:
return (is_shift_down) ? 'N' : 'n';
case KEY_M:
return (is_shift_down) ? 'M' : 'm';
case KEY_1:
return (is_shift_down) ? '!' : '1';
case KEY_2:
return (is_shift_down) ? '@' : '2';
case KEY_3:
return (is_shift_down) ? '#' : '3';
case KEY_4:
return (is_shift_down) ? '$' : '4';
case KEY_5:
return (is_shift_down) ? '%' : '5';
case KEY_6:
return (is_shift_down) ? '^' : '6';
case KEY_7:
return (is_shift_down) ? '&' : '7';
case KEY_8:
return (is_shift_down) ? '*' : '8';
case KEY_9:
return (is_shift_down) ? '(' : '9';
case KEY_0:
return (is_shift_down) ? ')' : '0';
case KEY_MINUS:
return (is_shift_down) ? '_' : '-';
case KEY_EQUALS:
return (is_shift_down) ? '=' : '+';
case KEY_LEFT_BRACKET:
return (is_shift_down) ? '{' : '[';
case KEY_RIGHT_BRACKET:
return (is_shift_down) ? '}' : ']';
case KEY_BACKSLASH:
return (is_shift_down) ? '|' : '\\';
case KEY_SEMICOLON:
return (is_shift_down) ? ':' : ';';
case KEY_SINGLE_QUOTE:
return (is_shift_down) ? '\"' : '\'';
case KEY_COMMA:
return (is_shift_down) ? '<' : ',';
case KEY_PERIOD:
return (is_shift_down) ? '>' : '.';
case KEY_FORWARDSLASH:
return (is_shift_down) ? '?' : '/';
case KEY_BACK_TICK:
return (is_shift_down) ? '~' : '`';
case KEY_ENTER:
return '\n';
case KEY_SPACE:
return ' ';
case KEY_LEFT_SHIFT:
case KEY_RIGHT_SHIFT:
is_shift_down = true;
return '\0';
case KEY_LEFT_SHIFT_R:
case KEY_RIGHT_SHIFT_R:
is_shift_down = false;
return '\0'; // TODO: should i send a character on a no op key?
default:
return '\0';
}
}