annotate cos/kernel/keyboard.c @ 220:3f6c30a5d234

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