diff --git a/kernel/arch/idt/idt.c b/kernel/arch/idt/idt.c index cdb8661..f0fd2c7 100644 --- a/kernel/arch/idt/idt.c +++ b/kernel/arch/idt/idt.c @@ -31,6 +31,7 @@ void exception_handler(unsigned int i) //kinfo("Sending EOI instruction to KEYB"); #endif unsigned char in = inb(0x60); + char to_print = decode_key_enum(decode_scancode(in)); if (to_print != '\0') printf("%c", to_print); diff --git a/kernel/arch/io/keyb.c b/kernel/arch/io/keyb.c index acad79f..9145ff0 100644 --- a/kernel/arch/io/keyb.c +++ b/kernel/arch/io/keyb.c @@ -1,4 +1,5 @@ #include +#include #include diff --git a/kernel/include/kernel/x86/keyb.h b/kernel/include/kernel/x86/keyb.h index b50e880..7330bbf 100644 --- a/kernel/include/kernel/x86/keyb.h +++ b/kernel/include/kernel/x86/keyb.h @@ -3,6 +3,20 @@ #ifndef ARCH_KEYB_H #define ARCH_KEYB_H +#define KEYB_DATA_PORT (0x60) +#define KEYB_STATUS_PORT (0x64) +#define KEYB_COMMAND_PORT (0x64) + + +#define KEYB_RESP_ERR (0x00) +#define KEYB_RESP_SELF_TEST_PASSED (0xAA) +#define KEYB_RESP_ECHO (0xEE) +#define KEYB_RESP_ACK (0xFA) +#define KEYB_RESP_SELF_TEST_FAILED (0xFC) +#define KEYB_RESP_SELF_TEST_FAILED_TWO (0xFD) +#define KEYB_RESP_RESEND (0xFE) +#define KEYB_RESP_ERR_TWO (0xFF) + typedef enum { KEY_ESC = 0x01, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, KEY_8, KEY_9, KEY_0, @@ -58,8 +72,10 @@ typedef enum { KEY_F12_R, } kb_key_press_t; -kb_key_press_t decode_scancode(uint8_t scancode); + + +kb_key_press_t decode_scancode(uint8_t scancode); char decode_key_enum(kb_key_press_t keycode); #endif diff --git a/libc/include/queue.h b/libc/include/queue.h new file mode 100644 index 0000000..c0ae547 --- /dev/null +++ b/libc/include/queue.h @@ -0,0 +1,25 @@ +#include + +#ifndef QUEUE_H +#define QUEUE_H + +#define MAX_QUEUE_SIZE 100 + +typedef struct { + uint8_t items[MAX_QUEUE_SIZE]; + short front; + short rear; +} queue; + +void init_queue(queue* q); + +bool queue_is_empty(queue* q); +bool queue_is_full(queue* q); + +void enqueue(queue* q, uint8_t val); +void dequeue(queue* q); + +uint8_t queue_peek(queue* q); + + +#endif diff --git a/libc/queue/queue.c b/libc/queue/queue.c new file mode 100644 index 0000000..1553aba --- /dev/null +++ b/libc/queue/queue.c @@ -0,0 +1,53 @@ +#ifdef __TESTING__ +#include +#endif + +#include +#include + +#include + +void init_queue(queue *q) +{ + q->front = -1; + q->rear = 0; +} + +bool queue_is_empty(queue *q) + {return (q->front == q->rear - 1);} ; // TODO: if this returns true, shouldn't we just be re-init-ing because we have the space to take up that used array +bool queue_is_full(queue *q) + {return (q->rear == MAX_QUEUE_SIZE);} // TODO: this is an error for SURE + +void enqueue(queue *q, uint8_t val) +{ + if (queue_is_full(q)) { +#ifdef __TESTING__ + kwarn("Queue being added to is full!!"); // TODO add a way to print like code lines and addresses to stack trace this +#endif + return; + } + q->items[q->rear++] = val; +} + +void dequeue(queue* q) +{ + if (queue_is_empty(q)) { +#ifdef __TESTING__ + kwarn("Queue thats already empty is trying to be removed from!!!"); // TODO same as above +#endif + return; + } + q->front++; +} + +uint8_t peek(queue* q) +{ + if (queue_is_empty(q)) { +#ifdef __TESTING__ + kwarn("Peeking an empty queue!"); +#endif + return -1; + + } + return q->items[q->front + 1]; +}