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
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
32
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 24
diff changeset
34 void keyboardDriverUpdate()
24
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
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
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
38 switch(scancode) {
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
39 case 0x2a:
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
40 shiftstate = 1;
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
41 break;
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
42 case 0xaa:
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
43 shiftstate = 0;
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
44 break;
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
45 default:
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
46 if (scancode < 128) {
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
47 if (charAvail == 0) {
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
48 if (shiftstate == 0) {
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
49 kbdchar = keymap[scancode];
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
50 } else {
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
51 kbdchar = keymapUPPER[scancode];
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
52 }
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
53
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
54 charAvail = 1;
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
55 }
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 // Key release
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
58 //printf("Unhandled scancode: 0x%x\n", scancode);
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 break;
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 }
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
63
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
64 char getChar()
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 while (charAvail == 0);
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
67 char c = kbdchar;
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
68 charAvail = 0;
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
69 return c;
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
70 }
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
71
32
3a6a9b929db0 Added initial ramdisk and some virtual file system functions
windel
parents: 24
diff changeset
72 // Move to user code:
24
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
73 void getline(char *buffer, int len)
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
74 {
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
75 char c;
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
76 int i = 0;
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
77 while (i < len-1) {
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
78 c = getChar();
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
79 //printf("%x", c);
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
80 if (c == '\n') {
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
81 // Enter
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
82 break;
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
83 }
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
84 if (c == 0x0e)
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
85 {
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
86 // Backspace
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
87 if (i>0)
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
88 {
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
89 int r, c;
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
90 get_cursor(&r, &c);
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
91 set_cursor(r, c - 1);
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
92 printf(" ");
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
93 set_cursor(r, c - 1);
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
94 i--;
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
95 }
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
96 continue;
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
97 }
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
98 buffer[i] = c;
d8627924d40d Split up in more files and reboot command
windel
parents:
diff changeset
99 printf("%c", c);
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 buffer[i] = 0;
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