blob: 2fae83c6ffea781b2350b3b6a2c740ca1d6cf5a9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
#include "keyboard.h"
#include <stdlib.h>
/*
* https://wiki.osdev.org/%228042%22_PS/2_Controller
* https://wiki.osdev.org/PS/2_Keyboard
*/
constexpr uint8_t comm_enable_first_ps2 = 0xae;
constexpr uint8_t comm_read_ctrl_config = 0x20;
constexpr uint8_t comm_write_ctrl_config = 0x60;
constexpr uint8_t dat_enable_scanning = 0xf4;
Keyboard::Keyboard() : InterruptHandler(0x01) {
// eat all previous keystrikes
while (commstatport.read() & 0x1) {
[[maybe_unused]] auto _c = dataport.read();
}
commstatport.write(comm_enable_first_ps2);
commstatport.write(comm_read_ctrl_config);
const uint8_t conf = (dataport.read() | 1) & ~0x10;
commstatport.write(comm_write_ctrl_config);
dataport.write(conf);
dataport.write(dat_enable_scanning);
}
cpu_state_t* Keyboard::trigger(cpu_state_t* cpu) {
const auto key = dataport.read();
if (key < 0x80) {
switch (key) {
case 0x04:
printk('3');
break;
case 0x05:
printk('4');
break;
case 0x06:
printk('5');
break;
case 0x07:
printk('6');
break;
case 0x08:
printk('7');
break;
case 0x09:
printk('8');
break;
case 0x0A:
printk('9');
break;
case 0x0B:
printk('0');
break;
case 0x10:
printk('q');
break;
case 0x11:
printk('w');
break;
case 0x12:
printk('e');
break;
case 0x13:
printk('r');
break;
case 0x14:
printk('t');
break;
case 0x15:
printk('y');
break;
case 0x16:
printk('u');
break;
case 0x17:
printk('i');
break;
case 0x18:
printk('o');
break;
case 0x19:
printk('p');
break;
case 0x1E:
printk('a');
break;
case 0x1F:
printk('s');
break;
case 0x20:
printk('d');
break;
case 0x21:
printk('f');
break;
case 0x22:
printk('g');
break;
case 0x23:
printk('h');
break;
case 0x24:
printk('j');
break;
case 0x25:
printk('k');
break;
case 0x26:
printk('l');
break;
case 0x2C:
printk('z');
break;
case 0x2D:
printk('x');
break;
case 0x2E:
printk('c');
break;
case 0x2F:
printk('v');
break;
case 0x30:
printk('b');
break;
case 0x31:
printk('n');
break;
case 0x32:
printk('m');
break;
case 0x33:
printk(',');
break;
case 0x34:
printk('.');
break;
case 0x35:
printk('/');
break;
case 0x1C:
printk('\n');
break;
case 0x39:
printk(' ');
break;
default:
printk("keyboard interrupt: ", uhex{key}, "\n");
break;
}
}
return cpu;
}
|