Mercurial > lcfOS
annotate cos/kernel/keyboard.c @ 32:3a6a9b929db0
Added initial ramdisk and some virtual file system functions
author | windel |
---|---|
date | Fri, 13 Jan 2012 18:18:17 +0100 |
parents | d8627924d40d |
children | 8012221dd740 |
rev | line source |
---|---|
24 | 1 #include "kernel.h" |
2 | |
3 static int shiftstate = 0; | |
4 static volatile uint8_t charAvail = 0; | |
5 static volatile char kbdchar = ' '; | |
6 | |
32
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
24
diff
changeset
|
7 // TODO: move to user land: |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
24
diff
changeset
|
8 static char keymap[128] = |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
24
diff
changeset
|
9 { |
24 | 10 '?','?','1','2', '3', '4', '5','6', '7', '8','9', '0', '-','=', 0xe, '?', |
11 'q','w','e','r', 't', 'y', 'u','i', 'o', 'p','[', ']', '\n','?', 'a', 's', | |
12 'd','f','g','h', 'j', 'k', 'l',';', '\'', '?','?', '?', 'z','x', 'c', 'v', | |
13 'b','n','m',',', '.', '/', '?','?', '?', ' ','?', '?', '?','?', '?', '?', | |
14 | |
15 '?','?','?','?', '?', '?', '?','?', '?', '?','?', '?', '?','?', '?', '?', | |
16 '?','?','?','?', '?', '?', '?','?', '?', '?','?', '?', '?','?', '?', '?', | |
17 '?','?','?','?', '?', '?', '?','?', '?', '?','?', '?', '?','?', '?', '?', | |
18 '?','?','?','?', '?', '?', '?','?', '?', '?','?', '?', '?','?', '?', '?' | |
19 }; | |
20 | |
32
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
24
diff
changeset
|
21 static char keymapUPPER[128] = |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
24
diff
changeset
|
22 { |
24 | 23 '?','?','!','@', '#', '$', '%','^', '&', '*','(', ')', '_','+', '?', '?', |
24 'Q','W','E','R', 'T', 'Y', 'U','I', 'O', 'P','{', '}', '|','?', 'A', 'S', | |
25 'D','F','G','H', 'J', 'K', 'L',':', '"', '?','?', '?', 'Z','X', 'C', 'V', | |
26 'B','N','M','<', '>', '?', '?','?', '?', ' ','?', '?', '?','?', '?', '?', | |
27 | |
28 '?','?','?','?', '?', '?', '?','?', '?', '?','?', '?', '?','?', '?', '?', | |
29 '?','?','?','?', '?', '?', '?','?', '?', '?','?', '?', '?','?', '?', '?', | |
30 '?','?','?','?', '?', '?', '?','?', '?', '?','?', '?', '?','?', '?', '?', | |
31 '?','?','?','?', '?', '?', '?','?', '?', '?','?', '?', '?','?', '?', '?' | |
32 }; | |
33 | |
32
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
24
diff
changeset
|
34 void keyboardDriverUpdate() |
24 | 35 { |
32
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
24
diff
changeset
|
36 unsigned char scancode = inb(0x60); |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
24
diff
changeset
|
37 |
24 | 38 switch(scancode) { |
39 case 0x2a: | |
40 shiftstate = 1; | |
41 break; | |
42 case 0xaa: | |
43 shiftstate = 0; | |
44 break; | |
45 default: | |
46 if (scancode < 128) { | |
47 if (charAvail == 0) { | |
48 if (shiftstate == 0) { | |
49 kbdchar = keymap[scancode]; | |
50 } else { | |
51 kbdchar = keymapUPPER[scancode]; | |
52 } | |
53 | |
54 charAvail = 1; | |
55 } | |
56 } else { | |
57 // Key release | |
58 //printf("Unhandled scancode: 0x%x\n", scancode); | |
59 } | |
60 break; | |
61 } | |
62 } | |
63 | |
64 char getChar() | |
65 { | |
66 while (charAvail == 0); | |
67 char c = kbdchar; | |
68 charAvail = 0; | |
69 return c; | |
70 } | |
71 | |
32
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
24
diff
changeset
|
72 // Move to user code: |
24 | 73 void getline(char *buffer, int len) |
74 { | |
75 char c; | |
76 int i = 0; | |
77 while (i < len-1) { | |
78 c = getChar(); | |
79 //printf("%x", c); | |
80 if (c == '\n') { | |
81 // Enter | |
82 break; | |
83 } | |
84 if (c == 0x0e) | |
85 { | |
86 // Backspace | |
87 if (i>0) | |
88 { | |
89 int r, c; | |
90 get_cursor(&r, &c); | |
91 set_cursor(r, c - 1); | |
92 printf(" "); | |
93 set_cursor(r, c - 1); | |
94 i--; | |
95 } | |
96 continue; | |
97 } | |
98 buffer[i] = c; | |
99 printf("%c", c); | |
100 i++; | |
101 } | |
102 buffer[i] = 0; | |
103 } | |
104 |