Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <system.h>
- /* KBDUS means US Keyboard Layout. This is a scancode table
- * used to layout a standard US keyboard. I have left some
- * comments in to give you an idea of what key is what, even
- * though I set it's array index to 0. You can change that to
- * whatever you want using a macro, if you wish! */
- unsigned char KBDUS[128] =
- {
- 0, 27, '!', '"', '4', '$', '%', '&', '/', '(', /* 9 */
- ')', '=', '_', 0, '\b', /* Backspace */
- '\t', /* Tab */
- 'Q', 'W', 'E', 'R', /* 19 */
- 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', '\n', /* Enter key */
- 0, /* 29 - Control */
- 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', /* 39 */
- '\'', '`', 1, /* Left shift */
- '\\', 'Z', 'X', 'C', 'V', 'B', 'N', /* 49 */
- 'M', '?', 0, '/', 0, /* Right shift */
- '*',
- 0, /* Alt */
- ' ', /* Space bar */
- 2, /* Caps lock */
- 0, /* 59 - F1 key ... > */
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, /* < ... F10 */
- 0, /* 69 - Num lock*/
- 0, /* Scroll Lock */
- 0, /* Home key */
- 0, /* Up Arrow */
- 0, /* Page Up */
- '-',
- 0, /* Left Arrow */
- 0,
- 0, /* Right Arrow */
- '+',
- 0, /* 79 - End key*/
- 0, /* Down Arrow */
- 0, /* Page Down */
- 0, /* Insert Key */
- 0, /* Delete Key */
- 0, 0, 0,
- 0, /* F11 Key */
- 0, /* F12 Key */
- 0, /* All other keys are undefined */
- };
- unsigned char kbdus[128] =
- {
- 0, 27, '1', '2', '3', '4', '5', '6', '7', '8', /* 9 */
- '9', '0', '-', '=', '\b', /* Backspace */
- '\t', /* Tab */
- 'q', 'w', 'e', 'r', /* 19 */
- 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', /* Enter key */
- 0, /* 29 - Control */
- 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', /* 39 */
- '\'', '`', 1, /* Left shift */
- '\\', 'z', 'x', 'c', 'v', 'b', 'n', /* 49 */
- 'm', ',', '.', '/', 0, /* Right shift */
- '*',
- 0, /* Alt */
- ' ', /* Space bar */
- 2, /* Caps lock */
- 0, /* 59 - F1 key ... > */
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, /* < ... F10 */
- 0, /* 69 - Num lock*/
- 0, /* Scroll Lock */
- 0, /* Home key */
- 0, /* Up Arrow */
- 0, /* Page Up */
- '-',
- 0, /* Left Arrow */
- 0,
- 0, /* Right Arrow */
- '+',
- 0, /* 79 - End key*/
- 0, /* Down Arrow */
- 0, /* Page Down */
- 0, /* Insert Key */
- 0, /* Delete Key */
- 0, 0, 0,
- 0, /* F11 Key */
- 0, /* F12 Key */
- 0, /* All other keys are undefined */
- };
- /* Handles the keyboard interrupt */
- void keyboard_handler(struct regs *r)
- {
- unsigned char scancode;
- unsigned short int SHIFT = 0;
- unsigned short int CAPS = 0;
- /* Read from the keyboard's data buffer */
- scancode = inportb(0x60);
- /* If the top bit of the byte we read from the keyboard is
- * set, that means that a key has just been released */
- //En castellano: si el bit mas significativo del byte leido desde el teclado esta en alto, significa q acabas de soltar la tecla
- if (scancode & 0x80)
- {
- if(kbdus[scancode] == 1) //Si suelto LEFT SHIFT
- {
- SHIFT = 0; //Bajo su FLAG
- }
- }
- else
- {
- if(kbdus[scancode] == 1) //Si apreto LEFT SHIFT. En la funcion kdus esta mapeado de tal manera que
- { // cuando se aprete shift, se devuelva un 1
- SHIFT = 1; //Subo su FLAG
- }
- if(kbdus[scancode] == 2) //Si apreto CAPS LOCK. Lo mismo para el CAPSLOCK o BLOQMAYUS, se devuelve un 2 del arreglo kbdus
- {
- CAPS++;
- }
- if( (SHIFT == 1) || ((CAPS%2)==1) ) //Si estoy apretando SHIFT o aprete CAPSLOCK un nΒΊ impar de veces
- { //voy a la tabla de mayusculas
- putch(KBDUS[scancode]);
- }
- else putch(kbdus[scancode]);
- }
- }
- /* Installs the keyboard handler into IRQ1 */
- void keyboard_install()
- {
- irq_install_handler(1, keyboard_handler);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement