1 | #include "types.h" |
---|---|
2 | #include "x86.h" |
3 | #include "defs.h" |
4 | #include "kbd.h" |
5 | |
6 | int |
7 | kbdgetc(void) |
8 | { |
9 | static uint shift; |
10 | static uchar *charcode[4] = { |
11 | normalmap, shiftmap, ctlmap, ctlmap |
12 | }; |
13 | uint st, data, c; |
14 | |
15 | st = inb(KBSTATP); |
16 | if((st & KBS_DIB) == 0) |
17 | return -1; |
18 | data = inb(KBDATAP); |
19 | |
20 | if(data == 0xE0){ |
21 | shift |= E0ESC; |
22 | return 0; |
23 | } else if(data & 0x80){ |
24 | // Key released |
25 | data = (shift & E0ESC ? data : data & 0x7F); |
26 | shift &= ~(shiftcode[data] | E0ESC); |
27 | return 0; |
28 | } else if(shift & E0ESC){ |
29 | // Last character was an E0 escape; or with 0x80 |
30 | data |= 0x80; |
31 | shift &= ~E0ESC; |
32 | } |
33 | |
34 | shift |= shiftcode[data]; |
35 | shift ^= togglecode[data]; |
36 | c = charcode[shift & (CTL | SHIFT)][data]; |
37 | if(shift & CAPSLOCK){ |
38 | if('a' <= c && c <= 'z') |
39 | c += 'A' - 'a'; |
40 | else if('A' <= c && c <= 'Z') |
41 | c += 'a' - 'A'; |
42 | } |
43 | return c; |
44 | } |
45 | |
46 | void |
47 | kbdintr(void) |
48 | { |
49 | consoleintr(kbdgetc); |
50 | } |
51 |