feat(keyboard): add getkey function

This commit is contained in:
aliamelo committed 2021-07-16 03:24:01 +02:00
1 parent a98c35a226
commit d255839400
3 files changed
+44 -1

No files matched your search

+18 -1
View File
@@ -1,5 +1,8 @@
#include "idt.h" #include "idt.h"
#include "stdio.h" #include "stdio.h"
#include "pic.h"
#include "io.h"
#include "pic/keyboard.h"
static struct idt idt = { 0 }; static struct idt idt = { 0 };
@@ -27,10 +30,24 @@ static struct idt_entry_info infos[] = {
void handle_interrupt(struct int_args *args) void handle_interrupt(struct int_args *args)
{ {
printf("INTERRUPT: %d, error code: %d\r\n", args->int_code, args->err_code); if (args->int_code >= 32)
{
int8_t key = getkey();
if (key >= 0)
{
printf("%d\r\n", key);
}
outb(MASTER_PORT_A, OCW2_EOI);
return; return;
} }
printf("INTERRUPT: %d, error code: %d\r\n", args->int_code, args->err_code);
asm volatile("cli; hlt");
}
static struct idt_entry create_idt_entry(uint32_t offset, static struct idt_entry create_idt_entry(uint32_t offset,
struct segment_selector selector, struct segment_selector selector,
uint32_t type) uint32_t type)
+13
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
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 */
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.