feat(keyboard): add getkey function
This commit is contained in:
parent
a98c35a226
commit
d255839400
19
k/idt.c
19
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,10 +30,24 @@ static struct idt_entry_info infos[] = {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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,
|
||||
struct segment_selector selector,
|
||||
uint32_t type)
|
||||
|
13
k/pic/keyboard.c
Normal file
13
k/pic/keyboard.c
Normal 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
13
k/pic/keyboard.h
Normal 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 */
|
Loading…
Reference in New Issue
Block a user