Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.80 KB | None | 0 0
  1. #include <system.h>
  2.  
  3. /* KBDUS means US Keyboard Layout. This is a scancode table
  4. *  used to layout a standard US keyboard. I have left some
  5. *  comments in to give you an idea of what key is what, even
  6. *  though I set it's array index to 0. You can change that to
  7. *  whatever you want using a macro, if you wish! */
  8.  
  9.  
  10. unsigned char KBDUS[128] =
  11. {
  12.     0,  27, '!', '"', '4', '$', '%', '&', '/', '(', /* 9 */
  13.   ')', '=', '_', 0, '\b',   /* Backspace */
  14.   '\t',         /* Tab */
  15.   'Q', 'W', 'E', 'R',   /* 19 */
  16.   'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', '\n',     /* Enter key */
  17.     0,          /* 29   - Control */
  18.   'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', /* 39 */
  19.  '\'', '`',   1,        /* Left shift */
  20.  '\\', 'Z', 'X', 'C', 'V', 'B', 'N',            /* 49 */
  21.   'M', '?', 0, '/',   0,                    /* Right shift */
  22.   '*',
  23.     0,  /* Alt */
  24.   ' ',  /* Space bar */
  25.     2,  /* Caps lock */
  26.     0,  /* 59 - F1 key ... > */
  27.     0,   0,   0,   0,   0,   0,   0,   0,
  28.     0,  /* < ... F10 */
  29.     0,  /* 69 - Num lock*/
  30.     0,  /* Scroll Lock */
  31.     0,  /* Home key */
  32.     0,  /* Up Arrow */
  33.     0,  /* Page Up */
  34.   '-',
  35.     0,  /* Left Arrow */
  36.     0,
  37.     0,  /* Right Arrow */
  38.   '+',
  39.     0,  /* 79 - End key*/
  40.     0,  /* Down Arrow */
  41.     0,  /* Page Down */
  42.     0,  /* Insert Key */
  43.     0,  /* Delete Key */
  44.     0,   0,   0,
  45.     0,  /* F11 Key */
  46.     0,  /* F12 Key */
  47.     0,  /* All other keys are undefined */
  48. };
  49.  
  50. unsigned char kbdus[128] =
  51. {
  52.     0,  27, '1', '2', '3', '4', '5', '6', '7', '8', /* 9 */
  53.   '9', '0', '-', '=', '\b', /* Backspace */
  54.   '\t',         /* Tab */
  55.   'q', 'w', 'e', 'r',   /* 19 */
  56.   't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n',     /* Enter key */
  57.     0,          /* 29   - Control */
  58.   'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', /* 39 */
  59.  '\'', '`',   1,        /* Left shift */
  60.  '\\', 'z', 'x', 'c', 'v', 'b', 'n',            /* 49 */
  61.   'm', ',', '.', '/',   0,                  /* Right shift */
  62.   '*',
  63.     0,  /* Alt */
  64.   ' ',  /* Space bar */
  65.     2,  /* Caps lock */
  66.     0,  /* 59 - F1 key ... > */
  67.     0,   0,   0,   0,   0,   0,   0,   0,
  68.     0,  /* < ... F10 */
  69.     0,  /* 69 - Num lock*/
  70.     0,  /* Scroll Lock */
  71.     0,  /* Home key */
  72.     0,  /* Up Arrow */
  73.     0,  /* Page Up */
  74.   '-',
  75.     0,  /* Left Arrow */
  76.     0,
  77.     0,  /* Right Arrow */
  78.   '+',
  79.     0,  /* 79 - End key*/
  80.     0,  /* Down Arrow */
  81.     0,  /* Page Down */
  82.     0,  /* Insert Key */
  83.     0,  /* Delete Key */
  84.     0,   0,   0,
  85.     0,  /* F11 Key */
  86.     0,  /* F12 Key */
  87.     0,  /* All other keys are undefined */
  88. };
  89.  
  90. /* Handles the keyboard interrupt */
  91. void keyboard_handler(struct regs *r)
  92. {
  93.     unsigned char scancode;
  94.     unsigned short int SHIFT = 0;
  95.     unsigned short int CAPS = 0;
  96.  
  97.     /* Read from the keyboard's data buffer */
  98.     scancode = inportb(0x60);
  99.  
  100.     /* If the top bit of the byte we read from the keyboard is
  101.     *  set, that means that a key has just been released */
  102.    
  103.     //En castellano: si el bit mas significativo del byte leido desde el teclado esta en alto, significa q acabas de soltar la tecla
  104.     if (scancode & 0x80)
  105.     {
  106.         if(kbdus[scancode]  == 1) //Si suelto LEFT SHIFT
  107.          {
  108.              SHIFT = 0;   //Bajo su FLAG
  109.             }
  110.     }
  111.     else
  112.     {
  113.          if(kbdus[scancode] == 1)   //Si apreto LEFT SHIFT. En la funcion kdus esta mapeado de tal manera que
  114.          {                          // cuando se aprete shift, se devuelva un 1
  115.              SHIFT = 1;     //Subo su FLAG
  116.             }
  117.          if(kbdus[scancode] == 2)   //Si apreto CAPS LOCK. Lo mismo para el CAPSLOCK o BLOQMAYUS, se devuelve un 2 del arreglo kbdus
  118.          {
  119.              CAPS++;
  120.             }
  121.            
  122.          if( (SHIFT == 1) || ((CAPS%2)==1) )    //Si estoy apretando SHIFT o aprete CAPSLOCK un nΒΊ impar de veces
  123.          {                                      //voy a la tabla de mayusculas
  124.              putch(KBDUS[scancode]);
  125.             }
  126.          else    putch(kbdus[scancode]);
  127.     }
  128. }
  129.  
  130. /* Installs the keyboard handler into IRQ1 */
  131. void keyboard_install()
  132. {
  133.     irq_install_handler(1, keyboard_handler);
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement