This repository has been archived on 2024-06-25. You can view files and clone it, but cannot push or open issues or pull requests.
rockOS/kernel/rockos/keyboard.c

71 lines
2.0 KiB
C
Raw Normal View History

2022-07-21 12:20:35 +03:00
#include <rockos/keyboard.h>
#include <rockos/pic.h>
#include <rockos/timer.h>
#include <rockos/hal.h>
#include <string.h>
#define ESC_P 0x01
#define BACKSPACE_P 0x0F
#define ENTER_P 0x1C
#define LEFT_C_P 0x1D
2022-07-22 00:24:26 +03:00
#define LEFT_SHIFT_P 0x2A
2022-07-21 12:20:35 +03:00
#define RIGHT_SHIFT_P 0x36
#define LEFT_ALT_P 0x38
2022-07-22 00:24:26 +03:00
#define CAPS_LOCK_P 0x3A
#define CAPS_LOCK_R 0xBA
2022-07-21 12:20:35 +03:00
static unsigned char interrupt_key;
static uint8_t keyset[89];
static uint64_t keytimes[89];
static unsigned char keymap[89] = {
2022-07-22 00:24:26 +03:00
0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', 0,
'\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', 0, 0,
'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`', 0, '\\',
'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', 0, '*', 0, ' ', 0
};
static unsigned char keymapshift[89] = {
0, 0, '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', 0,
'\t', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', 0, 0,
'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '\"', '`', 0, '|',
'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?', 0, '*', 0, ' ', 0
2022-07-21 12:20:35 +03:00
};
2022-07-22 00:24:26 +03:00
2022-07-21 12:20:35 +03:00
void initialize_keyset() {
memset(keyset, 0, 89);
memset(keytimes, 0, 89);
2022-07-22 00:24:26 +03:00
memset(&keymap[59], 0, 29);
memset(&keymapshift[59], 0, 29);
2022-07-21 12:20:35 +03:00
}
2022-07-22 00:24:26 +03:00
uint8_t caps_lock = 0;
2022-07-21 12:20:35 +03:00
__attribute__((interrupt)) void keyboard_handler(void* frame) {
interrupt_key = inb(0x60);
pic_eoi(1);
2022-07-22 00:24:26 +03:00
if((interrupt_key & 128) == 128) {
if(interrupt_key == CAPS_LOCK_R)
caps_lock = !caps_lock;
2022-07-21 12:20:35 +03:00
keyset[interrupt_key - 0x80] = 0;
} else {
keyset[interrupt_key] = 1;
}
}
2022-07-22 00:24:26 +03:00
unsigned char readkey() {
if((interrupt_key & 128) != 128) {
unsigned char tempkey = interrupt_key;
interrupt_key = 0;
if ((!caps_lock && (keyset[LEFT_SHIFT_P] || keyset[RIGHT_SHIFT_P])) ||
(caps_lock && !keyset[LEFT_SHIFT_P] && !keyset[RIGHT_SHIFT_P])) {
return keymapshift[tempkey];
} else {
return keymap[tempkey];
2022-07-21 12:20:35 +03:00
}
}
return 0;
}