[keyb] Shift / ctrl / alt

This commit is contained in:
Kevin Lange 2011-01-21 21:48:17 -06:00
parent 018fe42d40
commit 3e17b661bb
2 changed files with 118 additions and 16 deletions

View File

@ -1,5 +1,13 @@
#include <system.h> #include <system.h>
struct keyboard_states {
uint32_t shift : 1;
uint32_t alt : 1;
uint32_t ctrl : 1;
} keyboard_state;
typedef void (*keyboard_handler_t)(int scancode);
char kbd_us[128] = { char kbd_us[128] = {
0, 27, 0, 27,
'1','2','3','4','5','6','7','8','9','0', '1','2','3','4','5','6','7','8','9','0',
@ -39,21 +47,111 @@ char kbd_us[128] = {
0, /* everything else */ 0, /* everything else */
}; };
char kbd_us_l2[128] = {
0, 27,
'!','@','#','$','%','^','&','*','(',')',
'_','+','\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 norm(int scancode) {
if (scancode & 0x80) {
return;
}
if (!kbd_us[scancode]) {
return;
}
if (keyboard_state.shift) {
putch(kbd_us_l2[scancode]);
} else if (keyboard_state.ctrl) {
putch('^');
putch(kbd_us_l2[scancode]);
} else {
putch(kbd_us[scancode]);
}
}
void shft(int scancode) {
keyboard_state.shift ^= 1;
}
void altk(int scancode) {
keyboard_state.alt ^= 1;
}
void ctlk(int scancode) {
keyboard_state.ctrl ^= 1;
}
void func(int scancode) {
}
keyboard_handler_t key_method[] = {
/* 00 */ NULL, NULL, norm, norm, norm, norm, norm, norm,
/* 08 */ norm, norm, norm, norm, norm, norm, norm, norm,
/* 10 */ norm, norm, norm, norm, norm, norm, norm, norm,
/* 18 */ norm, norm, norm, norm, norm, ctlk, norm, norm,
/* 20 */ norm, norm, norm, norm, norm, norm, norm, norm,
/* 28 */ norm, norm, shft, norm, norm, norm, norm, norm,
/* 30 */ norm, norm, norm, norm, norm, norm, shft, norm,
/* 38 */ altk, norm, NULL, func, func, func, func, func,
/* 40 */ func, func, func, func, func, NULL, NULL, NULL,
/* 48 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
/* 50 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, func,
/* 58 */ func, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
/* 60 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
/* 68 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
/* 70 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
/* 78 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
};
void void
keyboard_handler( keyboard_handler(
struct regs *r struct regs *r
) { ) {
unsigned char scancode; unsigned char scancode;
scancode = inportb(0x60); scancode = inportb(0x60);
if (scancode & 0x80) { keyboard_handler_t handler;
/* key up */ handler = key_method[(int)scancode & 0x7f];
} else { if (handler) {
if (kbd_us[scancode] == 'q') { handler(scancode);
/* Page Fault Time */
uint32_t *ptr = (uint32_t *)0xA0000000;
uint32_t do_page_fault = *ptr;
}
putch(kbd_us[scancode]);
} }
} }

18
main.c
View File

@ -152,19 +152,23 @@ dump_multiboot(
int int
main(struct multiboot *mboot_ptr) { main(struct multiboot *mboot_ptr) {
mboot_ptr = copy_multiboot(mboot_ptr); mboot_ptr = copy_multiboot(mboot_ptr);
gdt_install();
idt_install(); /* Boot Stage 1 */
isrs_install(); gdt_install(); /* Global descriptor table */
irq_install(); idt_install(); /* IDT */
init_video(); isrs_install(); /* Interrupt service requests */
irq_install(); /* Hardware interrupt requests */
init_video(); /* VGA driver */
settextcolor(12,0); settextcolor(12,0);
kprintf("[%s %s]\n", KERNEL_UNAME, KERNEL_VERSION_STRING); kprintf("[%s %s]\n", KERNEL_UNAME, KERNEL_VERSION_STRING);
paging_install(mboot_ptr->mem_upper); paging_install(mboot_ptr->mem_upper);
dump_multiboot(mboot_ptr); dump_multiboot(mboot_ptr);
resettextcolor();
/* Boot Stage 2 */
timer_install(); timer_install();
keyboard_install(); keyboard_install();
/* Yes, yes, these are #define'd strings, consider this a nice test of kprintf */
resettextcolor();
return 0; return 0;
} }