[keyb] Keyboard support of sorts

This commit is contained in:
Kevin Lange 2011-01-16 13:45:51 -05:00
parent 14325e9972
commit f5d2053132
5 changed files with 70 additions and 1 deletions

View File

@ -7,7 +7,7 @@ install: kernel
cp kernel /mnt/kernel
umount /mnt
kernel: start.o link.ld main.o vga.o gdt.o idt.o isrs.o irq.o timer.o
kernel: start.o link.ld main.o vga.o gdt.o idt.o isrs.o irq.o timer.o kbd.o
ld -m elf_i386 -T link.ld -o kernel *.o
%.o: %.c

Binary file not shown.

View File

@ -45,4 +45,8 @@ extern void timer_install();
extern int timer_ticks;
extern void timer_wait(int ticks);
/* Keyboard */
extern void keyboard_install();
extern void keyboard_wait();
#endif

64
kbd.c Normal file
View File

@ -0,0 +1,64 @@
#include <system.h>
char kbd_us[128] = {
0, 27,
'1','2','3','4','5','6','7','8','9','0',
'-','=','\b',
'\t', /* tab */
'q','w','e','r','t','y','u','i','o','p','[',']','\n',
0, /* control */
'a','s','d','f','g','h','j','k','l',';','\'', '`',
0, /* left shift */
'\\','z','x','c','v','b','n','m',',','.','/',
0, /* right shift */
'*',
0, /* alt */
' ', /* space */
0, /* caps lock */
0, /* F1 [59] */
0, 0, 0, 0, 0, 0, 0, 0,
0, /* ... F10 */
0, /* 69 num lock */
0, /* scroll lock */
0, /* home */
0, /* up */
0, /* page up */
'-',
0, /* left arrow */
0,
0, /* right arrow */
'+',
0, /* 79 end */
0, /* down */
0, /* page down */
0, /* insert */
0, /* delete */
0, 0, 0,
0, /* F11 */
0, /* F12 */
0, /* everything else */
};
void
keyboard_handler(
struct regs *r
) {
unsigned char scancode;
scancode = inportb(0x60);
if (scancode & 0x80) {
/* key up */
} else {
putch(kbd_us[scancode]);
}
}
void
keyboard_install() {
/* IRQ installer */
irq_install_handler(1, keyboard_handler);
}
void
keyboard_wait() {
while(inportb(0x64) & 2);
}

1
main.c
View File

@ -152,6 +152,7 @@ main() {
irq_install();
__asm__ __volatile__("sti");
timer_install();
keyboard_install();
init_video();
puts("Good Morning!\n");
beer();