mirror of
https://github.com/cfenollosa/os-tutorial.git
synced 2024-10-27 20:34:19 +00:00
Added backspace fix and caps using shift
This commit is contained in:
parent
8c58d5f63b
commit
f6cd08f822
@ -8,7 +8,9 @@
|
|||||||
|
|
||||||
#define BACKSPACE 0x0E
|
#define BACKSPACE 0x0E
|
||||||
#define ENTER 0x1C
|
#define ENTER 0x1C
|
||||||
|
#define LSHIFT_DOWN 0x2a
|
||||||
|
#define LSHIFT_UP 0xaa
|
||||||
|
int caps = 0;
|
||||||
static char key_buffer[256];
|
static char key_buffer[256];
|
||||||
|
|
||||||
#define SC_MAX 57
|
#define SC_MAX 57
|
||||||
@ -19,26 +21,33 @@ const char *sc_name[] = { "ERROR", "Esc", "1", "2", "3", "4", "5", "6",
|
|||||||
"LShift", "\\", "Z", "X", "C", "V", "B", "N", "M", ",", ".",
|
"LShift", "\\", "Z", "X", "C", "V", "B", "N", "M", ",", ".",
|
||||||
"/", "RShift", "Keypad *", "LAlt", "Spacebar"};
|
"/", "RShift", "Keypad *", "LAlt", "Spacebar"};
|
||||||
const char sc_ascii[] = { '?', '?', '1', '2', '3', '4', '5', '6',
|
const char sc_ascii[] = { '?', '?', '1', '2', '3', '4', '5', '6',
|
||||||
'7', '8', '9', '0', '-', '=', '?', '?', 'Q', 'W', 'E', 'R', 'T', 'Y',
|
'7', '8', '9', '0', '-', '=', '?', '?', 'q', 'w', 'e', 'r', 't', 'y',
|
||||||
'U', 'I', 'O', 'P', '[', ']', '?', '?', 'A', 'S', 'D', 'F', 'G',
|
'u', 'i', 'o', 'p', '[', ']', '?', '?', 'a', 's', 'd', 'f', 'g',
|
||||||
'H', 'J', 'K', 'L', ';', '\'', '`', '?', '\\', 'Z', 'X', 'C', 'V',
|
'h', 'j', 'k', 'l', ';', '\'', '`', '?', '\\', 'z', 'x', 'c', 'v',
|
||||||
'B', 'N', 'M', ',', '.', '/', '?', '?', '?', ' '};
|
'b', 'n', 'm', ',', '.', '/', '?', '?', '?', ' '};
|
||||||
|
|
||||||
static void keyboard_callback(registers_t regs) {
|
static void keyboard_callback(registers_t regs) {
|
||||||
/* The PIC leaves us the scancode in port 0x60 */
|
/* The PIC leaves us the scancode in port 0x60 */
|
||||||
u8 scancode = port_byte_in(0x60);
|
u8 scancode = port_byte_in(0x60);
|
||||||
|
if (scancode == LSHIFT_UP){caps=0;}
|
||||||
if (scancode > SC_MAX) return;
|
if (scancode > SC_MAX) return;
|
||||||
if (scancode == BACKSPACE) {
|
if (scancode == BACKSPACE) {
|
||||||
|
if (key_buffer[0] != '\0') {
|
||||||
backspace(key_buffer);
|
backspace(key_buffer);
|
||||||
kprint_backspace();
|
kprint_backspace();
|
||||||
|
}
|
||||||
} else if (scancode == ENTER) {
|
} else if (scancode == ENTER) {
|
||||||
kprint("\n");
|
kprint("\n");
|
||||||
user_input(key_buffer); /* kernel-controlled function */
|
user_input(key_buffer); /* kernel-controlled function */
|
||||||
key_buffer[0] = '\0';
|
key_buffer[0] = '\0';
|
||||||
|
}else if (scancode == LSHIFT_DOWN) {
|
||||||
|
if (caps == 0) {
|
||||||
|
caps++;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
char letter = sc_ascii[(int)scancode];
|
char letter = sc_ascii[(int)scancode];
|
||||||
/* Remember that kprint only accepts char[] */
|
/* Remember that kprint only accepts char[] */
|
||||||
|
if (caps == 1) {letter = chrupper(letter)};
|
||||||
char str[2] = {letter, '\0'};
|
char str[2] = {letter, '\0'};
|
||||||
append(key_buffer, letter);
|
append(key_buffer, letter);
|
||||||
kprint(str);
|
kprint(str);
|
||||||
|
Loading…
Reference in New Issue
Block a user