Mercurial > lcfOS
annotate cos/kernel/keyboard.c @ 299:674789d9ff37
Added a doc
author | Windel Bouwman |
---|---|
date | Sun, 01 Dec 2013 18:37:23 +0100 |
parents | 8012221dd740 |
children |
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 | |
34
8012221dd740
Fixes for uninitialized data. This causes problems on real machines
windel
parents:
32
diff
changeset
|
34 void keyboard_init() |
8012221dd740
Fixes for uninitialized data. This causes problems on real machines
windel
parents:
32
diff
changeset
|
35 { |
8012221dd740
Fixes for uninitialized data. This causes problems on real machines
windel
parents:
32
diff
changeset
|
36 shiftstate = 0; |
8012221dd740
Fixes for uninitialized data. This causes problems on real machines
windel
parents:
32
diff
changeset
|
37 charAvail = 0; |
8012221dd740
Fixes for uninitialized data. This causes problems on real machines
windel
parents:
32
diff
changeset
|
38 } |
8012221dd740
Fixes for uninitialized data. This causes problems on real machines
windel
parents:
32
diff
changeset
|
39 |
32
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
24
diff
changeset
|
40 void keyboardDriverUpdate() |
24 | 41 { |
32
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
24
diff
changeset
|
42 unsigned char scancode = inb(0x60); |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
24
diff
changeset
|
43 |
24 | 44 switch(scancode) { |
45 case 0x2a: | |
46 shiftstate = 1; | |
47 break; | |
48 case 0xaa: | |
49 shiftstate = 0; | |
50 break; | |
51 default: | |
52 if (scancode < 128) { | |
53 if (charAvail == 0) { | |
54 if (shiftstate == 0) { | |
55 kbdchar = keymap[scancode]; | |
56 } else { | |
57 kbdchar = keymapUPPER[scancode]; | |
58 } | |
59 | |
60 charAvail = 1; | |
61 } | |
62 } else { | |
63 // Key release | |
64 //printf("Unhandled scancode: 0x%x\n", scancode); | |
65 } | |
66 break; | |
67 } | |
68 } | |
69 | |
70 char getChar() | |
71 { | |
72 while (charAvail == 0); | |
73 char c = kbdchar; | |
74 charAvail = 0; | |
75 return c; | |
76 } | |
77 | |
32
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
24
diff
changeset
|
78 // Move to user code: |
24 | 79 void getline(char *buffer, int len) |
80 { | |
81 char c; | |
82 int i = 0; | |
83 while (i < len-1) { | |
84 c = getChar(); | |
85 //printf("%x", c); | |
86 if (c == '\n') { | |
87 // Enter | |
88 break; | |
89 } | |
90 if (c == 0x0e) | |
91 { | |
92 // Backspace | |
93 if (i>0) | |
94 { | |
95 int r, c; | |
96 get_cursor(&r, &c); | |
97 set_cursor(r, c - 1); | |
98 printf(" "); | |
99 set_cursor(r, c - 1); | |
100 i--; | |
101 } | |
102 continue; | |
103 } | |
104 buffer[i] = c; | |
105 printf("%c", c); | |
106 i++; | |
107 } | |
108 buffer[i] = 0; | |
109 } | |
110 |