feat(keyboard): add getkey function

This commit is contained in:
Malo Lecomte 2021-07-16 03:24:01 +02:00
parent a98c35a226
commit d255839400
3 changed files with 44 additions and 1 deletions

19
k/idt.c
View File

@ -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,

13
k/pic/keyboard.c Normal file
View File

@ -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;
}

13
k/pic/keyboard.h Normal file
View File

@ -0,0 +1,13 @@
#ifndef KEYBOARD_H
#define KEYBOARD_H
#define KEYBOARD_IO 0x60
#define KEYBOARD_STATUS 0x64
#define KEYBOARD_RELEASE 0x80
#include <stdint.h>
int8_t getkey(void);
#endif /* !KEYBOARD_H */