From d255839400f91c13d00b02e6f169404d0295470a Mon Sep 17 00:00:00 2001 From: Malo Lecomte Date: Fri, 16 Jul 2021 03:24:01 +0200 Subject: [PATCH] feat(keyboard): add getkey function --- k/idt.c | 19 ++++++++++++++++++- k/pic/keyboard.c | 13 +++++++++++++ k/pic/keyboard.h | 13 +++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 k/pic/keyboard.c create mode 100644 k/pic/keyboard.h diff --git a/k/idt.c b/k/idt.c index 0197e15..db4ab15 100644 --- a/k/idt.c +++ b/k/idt.c @@ -1,5 +1,8 @@ #include "idt.h" #include "stdio.h" +#include "pic.h" +#include "io.h" +#include "pic/keyboard.h" static struct idt idt = { 0 }; @@ -27,8 +30,22 @@ static struct idt_entry_info infos[] = { void handle_interrupt(struct int_args *args) { + if (args->int_code >= 32) + { + int8_t key = getkey(); + if (key >= 0) + { + printf("%d\r\n", key); + } + + outb(MASTER_PORT_A, OCW2_EOI); + + return; + } + printf("INTERRUPT: %d, error code: %d\r\n", args->int_code, args->err_code); - return; + + asm volatile("cli; hlt"); } static struct idt_entry create_idt_entry(uint32_t offset, diff --git a/k/pic/keyboard.c b/k/pic/keyboard.c new file mode 100644 index 0000000..d4bfd08 --- /dev/null +++ b/k/pic/keyboard.c @@ -0,0 +1,13 @@ +#include "pic/keyboard.h" +#include "io.h" +#include "stdio.h" + +int8_t getkey(void) +{ + uint8_t key = inb(KEYBOARD_IO); + + if (key & KEYBOARD_RELEASE) + return -1; + + return key; +} diff --git a/k/pic/keyboard.h b/k/pic/keyboard.h new file mode 100644 index 0000000..dd09e7d --- /dev/null +++ b/k/pic/keyboard.h @@ -0,0 +1,13 @@ +#ifndef KEYBOARD_H +#define KEYBOARD_H + +#define KEYBOARD_IO 0x60 +#define KEYBOARD_STATUS 0x64 + +#define KEYBOARD_RELEASE 0x80 + +#include + +int8_t getkey(void); + +#endif /* !KEYBOARD_H */