[kbd] Clean up the keyboard a bit.

This commit is contained in:
Kevin Lange 2011-10-22 19:32:03 -05:00
parent d24dca3329
commit 732e660a37

View File

@ -9,6 +9,13 @@
#include <system.h>
#define KEY_UP_MASK 0x80
#define KEY_CODE_MASK 0x7F
#define KEY_CTRL_MASK 0x40
#define KEY_DEVICE 0x60
#define KEY_PENDING 0x64
/* A bit-map to store the keyboard states */
struct keyboard_states {
uint32_t shift : 1;
@ -97,9 +104,15 @@ char kbd_us_l2[128] = {
};
/*
* "Normal" key handler
* Used for visible text keys and handles
* application of shift/alt/control
*
* Shells out to putch() to do most of the work.
*/
void norm(int scancode) {
if (scancode & 0x80) {
if (scancode & KEY_UP_MASK) {
return;
}
if (!kbd_us[scancode]) {
@ -108,7 +121,7 @@ void norm(int scancode) {
if (keyboard_state.shift) {
putch(kbd_us_l2[scancode]);
} else if (keyboard_state.ctrl) {
int out = (int)(kbd_us_l2[scancode] - 0x40);
int out = (int)(kbd_us_l2[scancode] - KEY_CTRL_MASK);
if (out < 0 || out > 0x1F) {
putch(kbd_us[scancode]);
} else {
@ -119,28 +132,44 @@ void norm(int scancode) {
}
}
/*
* Toggle Shift
*/
void shft(int scancode) {
keyboard_state.shift ^= 1;
}
/*
* Toggle Alt
*/
void altk(int scancode) {
keyboard_state.alt ^= 1;
}
/*
* Toggle Control
*/
void ctlk(int scancode) {
keyboard_state.ctrl ^= 1;
}
/*
* Function keys
*/
void func(int scancode) {
if (scancode & 0x80) {
if (scancode & KEY_UP_MASK) {
return;
}
kprintf("[NOTICE] Function key %d pressed\n", scancode);
}
/*
* "Special" keys
* Extra keys on your keyboard will produce these
* sorts of key presses.
*/
void spec(int scancode) {
if (scancode & 0x80) {
if (scancode & KEY_UP_MASK) {
return;
}
switch (scancode) {
@ -197,13 +226,13 @@ keyboard_handler(
struct regs *r
) {
unsigned char scancode;
scancode = inportb(0x60);
scancode = inportb(KEY_DEVICE);
if (keyboard_direct_handler) {
keyboard_direct_handler(scancode);
return;
}
keyboard_handler_t handler;
handler = key_method[(int)scancode & 0x7f];
handler = key_method[(int)scancode & KEY_CODE_MASK];
if (handler) {
handler(scancode);
}
@ -219,7 +248,7 @@ keyboard_install() {
void
keyboard_wait() {
while(inportb(0x64) & 2);
while(inportb(KEY_PENDING) & 2);
}
/*
@ -232,7 +261,8 @@ putch(
if (keyboard_buffer_handler) {
keyboard_buffer_handler(c);
} else {
if (c == 3) {
if (c == 3 /* ^L */) {
/* Find the next task that isn't the kernel and kill it */
__volatile__ task_t * prev_task = current_task;
while (current_task && !current_task->id) {
current_task = current_task->next;
@ -241,6 +271,7 @@ putch(
kprintf("Killing task %d!\n", current_task->id);
kexit(1);
} else {
/* The only available task /is/ the kernel. Run away! */
current_task = prev_task;
}
return;