root / hw / pckbd.c @ 89344d5a
History | View | Annotate | Download (20.7 kB)
1 | 80cabfad | bellard | /*
|
---|---|---|---|
2 | 80cabfad | bellard | * QEMU PC keyboard emulation
|
3 | 80cabfad | bellard | *
|
4 | 80cabfad | bellard | * Copyright (c) 2003 Fabrice Bellard
|
5 | 80cabfad | bellard | *
|
6 | 80cabfad | bellard | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | 80cabfad | bellard | * of this software and associated documentation files (the "Software"), to deal
|
8 | 80cabfad | bellard | * in the Software without restriction, including without limitation the rights
|
9 | 80cabfad | bellard | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | 80cabfad | bellard | * copies of the Software, and to permit persons to whom the Software is
|
11 | 80cabfad | bellard | * furnished to do so, subject to the following conditions:
|
12 | 80cabfad | bellard | *
|
13 | 80cabfad | bellard | * The above copyright notice and this permission notice shall be included in
|
14 | 80cabfad | bellard | * all copies or substantial portions of the Software.
|
15 | 80cabfad | bellard | *
|
16 | 80cabfad | bellard | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | 80cabfad | bellard | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | 80cabfad | bellard | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | 80cabfad | bellard | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | 80cabfad | bellard | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | 80cabfad | bellard | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | 80cabfad | bellard | * THE SOFTWARE.
|
23 | 80cabfad | bellard | */
|
24 | 80cabfad | bellard | #include "vl.h" |
25 | 80cabfad | bellard | |
26 | 80cabfad | bellard | /* debug PC keyboard */
|
27 | 80cabfad | bellard | //#define DEBUG_KBD
|
28 | 80cabfad | bellard | |
29 | 80cabfad | bellard | /* debug PC keyboard : only mouse */
|
30 | 80cabfad | bellard | //#define DEBUG_MOUSE
|
31 | 80cabfad | bellard | |
32 | 80cabfad | bellard | /* Keyboard Controller Commands */
|
33 | 80cabfad | bellard | #define KBD_CCMD_READ_MODE 0x20 /* Read mode bits */ |
34 | 80cabfad | bellard | #define KBD_CCMD_WRITE_MODE 0x60 /* Write mode bits */ |
35 | 80cabfad | bellard | #define KBD_CCMD_GET_VERSION 0xA1 /* Get controller version */ |
36 | 80cabfad | bellard | #define KBD_CCMD_MOUSE_DISABLE 0xA7 /* Disable mouse interface */ |
37 | 80cabfad | bellard | #define KBD_CCMD_MOUSE_ENABLE 0xA8 /* Enable mouse interface */ |
38 | 80cabfad | bellard | #define KBD_CCMD_TEST_MOUSE 0xA9 /* Mouse interface test */ |
39 | 80cabfad | bellard | #define KBD_CCMD_SELF_TEST 0xAA /* Controller self test */ |
40 | 80cabfad | bellard | #define KBD_CCMD_KBD_TEST 0xAB /* Keyboard interface test */ |
41 | 80cabfad | bellard | #define KBD_CCMD_KBD_DISABLE 0xAD /* Keyboard interface disable */ |
42 | 80cabfad | bellard | #define KBD_CCMD_KBD_ENABLE 0xAE /* Keyboard interface enable */ |
43 | 80cabfad | bellard | #define KBD_CCMD_READ_INPORT 0xC0 /* read input port */ |
44 | 80cabfad | bellard | #define KBD_CCMD_READ_OUTPORT 0xD0 /* read output port */ |
45 | 80cabfad | bellard | #define KBD_CCMD_WRITE_OUTPORT 0xD1 /* write output port */ |
46 | 80cabfad | bellard | #define KBD_CCMD_WRITE_OBUF 0xD2 |
47 | 80cabfad | bellard | #define KBD_CCMD_WRITE_AUX_OBUF 0xD3 /* Write to output buffer as if |
48 | 80cabfad | bellard | initiated by the auxiliary device */
|
49 | 80cabfad | bellard | #define KBD_CCMD_WRITE_MOUSE 0xD4 /* Write the following byte to the mouse */ |
50 | 80cabfad | bellard | #define KBD_CCMD_DISABLE_A20 0xDD /* HP vectra only ? */ |
51 | 80cabfad | bellard | #define KBD_CCMD_ENABLE_A20 0xDF /* HP vectra only ? */ |
52 | 80cabfad | bellard | #define KBD_CCMD_RESET 0xFE |
53 | 80cabfad | bellard | |
54 | 80cabfad | bellard | /* Keyboard Commands */
|
55 | 80cabfad | bellard | #define KBD_CMD_SET_LEDS 0xED /* Set keyboard leds */ |
56 | 80cabfad | bellard | #define KBD_CMD_ECHO 0xEE |
57 | 80cabfad | bellard | #define KBD_CMD_GET_ID 0xF2 /* get keyboard ID */ |
58 | 80cabfad | bellard | #define KBD_CMD_SET_RATE 0xF3 /* Set typematic rate */ |
59 | 80cabfad | bellard | #define KBD_CMD_ENABLE 0xF4 /* Enable scanning */ |
60 | 80cabfad | bellard | #define KBD_CMD_RESET_DISABLE 0xF5 /* reset and disable scanning */ |
61 | 80cabfad | bellard | #define KBD_CMD_RESET_ENABLE 0xF6 /* reset and enable scanning */ |
62 | 80cabfad | bellard | #define KBD_CMD_RESET 0xFF /* Reset */ |
63 | 80cabfad | bellard | |
64 | 80cabfad | bellard | /* Keyboard Replies */
|
65 | 80cabfad | bellard | #define KBD_REPLY_POR 0xAA /* Power on reset */ |
66 | 80cabfad | bellard | #define KBD_REPLY_ACK 0xFA /* Command ACK */ |
67 | 80cabfad | bellard | #define KBD_REPLY_RESEND 0xFE /* Command NACK, send the cmd again */ |
68 | 80cabfad | bellard | |
69 | 80cabfad | bellard | /* Status Register Bits */
|
70 | 80cabfad | bellard | #define KBD_STAT_OBF 0x01 /* Keyboard output buffer full */ |
71 | 80cabfad | bellard | #define KBD_STAT_IBF 0x02 /* Keyboard input buffer full */ |
72 | 80cabfad | bellard | #define KBD_STAT_SELFTEST 0x04 /* Self test successful */ |
73 | 80cabfad | bellard | #define KBD_STAT_CMD 0x08 /* Last write was a command write (0=data) */ |
74 | 80cabfad | bellard | #define KBD_STAT_UNLOCKED 0x10 /* Zero if keyboard locked */ |
75 | 80cabfad | bellard | #define KBD_STAT_MOUSE_OBF 0x20 /* Mouse output buffer full */ |
76 | 80cabfad | bellard | #define KBD_STAT_GTO 0x40 /* General receive/xmit timeout */ |
77 | 80cabfad | bellard | #define KBD_STAT_PERR 0x80 /* Parity error */ |
78 | 80cabfad | bellard | |
79 | 80cabfad | bellard | /* Controller Mode Register Bits */
|
80 | 80cabfad | bellard | #define KBD_MODE_KBD_INT 0x01 /* Keyboard data generate IRQ1 */ |
81 | 80cabfad | bellard | #define KBD_MODE_MOUSE_INT 0x02 /* Mouse data generate IRQ12 */ |
82 | 80cabfad | bellard | #define KBD_MODE_SYS 0x04 /* The system flag (?) */ |
83 | 80cabfad | bellard | #define KBD_MODE_NO_KEYLOCK 0x08 /* The keylock doesn't affect the keyboard if set */ |
84 | 80cabfad | bellard | #define KBD_MODE_DISABLE_KBD 0x10 /* Disable keyboard interface */ |
85 | 80cabfad | bellard | #define KBD_MODE_DISABLE_MOUSE 0x20 /* Disable mouse interface */ |
86 | 80cabfad | bellard | #define KBD_MODE_KCC 0x40 /* Scan code conversion to PC format */ |
87 | 80cabfad | bellard | #define KBD_MODE_RFU 0x80 |
88 | 80cabfad | bellard | |
89 | 80cabfad | bellard | /* Mouse Commands */
|
90 | 80cabfad | bellard | #define AUX_SET_SCALE11 0xE6 /* Set 1:1 scaling */ |
91 | 80cabfad | bellard | #define AUX_SET_SCALE21 0xE7 /* Set 2:1 scaling */ |
92 | 80cabfad | bellard | #define AUX_SET_RES 0xE8 /* Set resolution */ |
93 | 80cabfad | bellard | #define AUX_GET_SCALE 0xE9 /* Get scaling factor */ |
94 | 80cabfad | bellard | #define AUX_SET_STREAM 0xEA /* Set stream mode */ |
95 | 80cabfad | bellard | #define AUX_POLL 0xEB /* Poll */ |
96 | 80cabfad | bellard | #define AUX_RESET_WRAP 0xEC /* Reset wrap mode */ |
97 | 80cabfad | bellard | #define AUX_SET_WRAP 0xEE /* Set wrap mode */ |
98 | 80cabfad | bellard | #define AUX_SET_REMOTE 0xF0 /* Set remote mode */ |
99 | 80cabfad | bellard | #define AUX_GET_TYPE 0xF2 /* Get type */ |
100 | 80cabfad | bellard | #define AUX_SET_SAMPLE 0xF3 /* Set sample rate */ |
101 | 80cabfad | bellard | #define AUX_ENABLE_DEV 0xF4 /* Enable aux device */ |
102 | 80cabfad | bellard | #define AUX_DISABLE_DEV 0xF5 /* Disable aux device */ |
103 | 80cabfad | bellard | #define AUX_SET_DEFAULT 0xF6 |
104 | 80cabfad | bellard | #define AUX_RESET 0xFF /* Reset aux device */ |
105 | 80cabfad | bellard | #define AUX_ACK 0xFA /* Command byte ACK. */ |
106 | 80cabfad | bellard | |
107 | 80cabfad | bellard | #define MOUSE_STATUS_REMOTE 0x40 |
108 | 80cabfad | bellard | #define MOUSE_STATUS_ENABLED 0x20 |
109 | 80cabfad | bellard | #define MOUSE_STATUS_SCALE21 0x10 |
110 | 80cabfad | bellard | |
111 | 80cabfad | bellard | #define KBD_QUEUE_SIZE 256 |
112 | 80cabfad | bellard | |
113 | 80cabfad | bellard | typedef struct { |
114 | 6f51f6b5 | bellard | uint8_t aux[KBD_QUEUE_SIZE]; |
115 | 80cabfad | bellard | uint8_t data[KBD_QUEUE_SIZE]; |
116 | 80cabfad | bellard | int rptr, wptr, count;
|
117 | 80cabfad | bellard | } KBDQueue; |
118 | 80cabfad | bellard | |
119 | 80cabfad | bellard | typedef struct KBDState { |
120 | 6f51f6b5 | bellard | KBDQueue queue; |
121 | 80cabfad | bellard | uint8_t write_cmd; /* if non zero, write data to port 60 is expected */
|
122 | 80cabfad | bellard | uint8_t status; |
123 | 80cabfad | bellard | uint8_t mode; |
124 | 80cabfad | bellard | /* keyboard state */
|
125 | 80cabfad | bellard | int kbd_write_cmd;
|
126 | 80cabfad | bellard | int scan_enabled;
|
127 | 80cabfad | bellard | /* mouse state */
|
128 | 80cabfad | bellard | int mouse_write_cmd;
|
129 | 80cabfad | bellard | uint8_t mouse_status; |
130 | 80cabfad | bellard | uint8_t mouse_resolution; |
131 | 80cabfad | bellard | uint8_t mouse_sample_rate; |
132 | 80cabfad | bellard | uint8_t mouse_wrap; |
133 | 80cabfad | bellard | uint8_t mouse_type; /* 0 = PS2, 3 = IMPS/2, 4 = IMEX */
|
134 | 80cabfad | bellard | uint8_t mouse_detect_state; |
135 | 80cabfad | bellard | int mouse_dx; /* current values, needed for 'poll' mode */ |
136 | 80cabfad | bellard | int mouse_dy;
|
137 | 80cabfad | bellard | int mouse_dz;
|
138 | 80cabfad | bellard | uint8_t mouse_buttons; |
139 | 80cabfad | bellard | } KBDState; |
140 | 80cabfad | bellard | |
141 | 80cabfad | bellard | KBDState kbd_state; |
142 | 80cabfad | bellard | |
143 | 80cabfad | bellard | /* update irq and KBD_STAT_[MOUSE_]OBF */
|
144 | 80cabfad | bellard | /* XXX: not generating the irqs if KBD_MODE_DISABLE_KBD is set may be
|
145 | 80cabfad | bellard | incorrect, but it avoids having to simulate exact delays */
|
146 | 80cabfad | bellard | static void kbd_update_irq(KBDState *s) |
147 | 80cabfad | bellard | { |
148 | 6f51f6b5 | bellard | KBDQueue *q = &s->queue; |
149 | 80cabfad | bellard | int irq12_level, irq1_level;
|
150 | 80cabfad | bellard | |
151 | 80cabfad | bellard | irq1_level = 0;
|
152 | 80cabfad | bellard | irq12_level = 0;
|
153 | 80cabfad | bellard | s->status &= ~(KBD_STAT_OBF | KBD_STAT_MOUSE_OBF); |
154 | 6f51f6b5 | bellard | if (q->count != 0) { |
155 | 80cabfad | bellard | s->status |= KBD_STAT_OBF; |
156 | 6f51f6b5 | bellard | if (q->aux[q->rptr]) {
|
157 | 80cabfad | bellard | s->status |= KBD_STAT_MOUSE_OBF; |
158 | 80cabfad | bellard | if (s->mode & KBD_MODE_MOUSE_INT)
|
159 | 80cabfad | bellard | irq12_level = 1;
|
160 | 80cabfad | bellard | } else {
|
161 | 80cabfad | bellard | if ((s->mode & KBD_MODE_KBD_INT) &&
|
162 | 80cabfad | bellard | !(s->mode & KBD_MODE_DISABLE_KBD)) |
163 | 80cabfad | bellard | irq1_level = 1;
|
164 | 80cabfad | bellard | } |
165 | 80cabfad | bellard | } |
166 | 80cabfad | bellard | pic_set_irq(1, irq1_level);
|
167 | 80cabfad | bellard | pic_set_irq(12, irq12_level);
|
168 | 80cabfad | bellard | } |
169 | 80cabfad | bellard | |
170 | 80cabfad | bellard | static void kbd_queue(KBDState *s, int b, int aux) |
171 | 80cabfad | bellard | { |
172 | 6f51f6b5 | bellard | KBDQueue *q = &s->queue; |
173 | 80cabfad | bellard | |
174 | 80cabfad | bellard | #if defined(DEBUG_MOUSE) || defined(DEBUG_KBD)
|
175 | 80cabfad | bellard | if (aux)
|
176 | 80cabfad | bellard | printf("mouse event: 0x%02x\n", b);
|
177 | 80cabfad | bellard | #ifdef DEBUG_KBD
|
178 | 80cabfad | bellard | else
|
179 | 80cabfad | bellard | printf("kbd event: 0x%02x\n", b);
|
180 | 80cabfad | bellard | #endif
|
181 | 80cabfad | bellard | #endif
|
182 | 80cabfad | bellard | if (q->count >= KBD_QUEUE_SIZE)
|
183 | 80cabfad | bellard | return;
|
184 | 6f51f6b5 | bellard | q->aux[q->wptr] = aux; |
185 | 80cabfad | bellard | q->data[q->wptr] = b; |
186 | 80cabfad | bellard | if (++q->wptr == KBD_QUEUE_SIZE)
|
187 | 80cabfad | bellard | q->wptr = 0;
|
188 | 80cabfad | bellard | q->count++; |
189 | 80cabfad | bellard | kbd_update_irq(s); |
190 | 80cabfad | bellard | } |
191 | 80cabfad | bellard | |
192 | 63066f4f | bellard | static void pc_kbd_put_keycode(void *opaque, int keycode) |
193 | 80cabfad | bellard | { |
194 | 63066f4f | bellard | KBDState *s = opaque; |
195 | 80cabfad | bellard | kbd_queue(s, keycode, 0);
|
196 | 80cabfad | bellard | } |
197 | 80cabfad | bellard | |
198 | b41a2cd1 | bellard | static uint32_t kbd_read_status(void *opaque, uint32_t addr) |
199 | 80cabfad | bellard | { |
200 | b41a2cd1 | bellard | KBDState *s = opaque; |
201 | 80cabfad | bellard | int val;
|
202 | 80cabfad | bellard | val = s->status; |
203 | 80cabfad | bellard | #if defined(DEBUG_KBD)
|
204 | 80cabfad | bellard | printf("kbd: read status=0x%02x\n", val);
|
205 | 80cabfad | bellard | #endif
|
206 | 80cabfad | bellard | return val;
|
207 | 80cabfad | bellard | } |
208 | 80cabfad | bellard | |
209 | b41a2cd1 | bellard | static void kbd_write_command(void *opaque, uint32_t addr, uint32_t val) |
210 | 80cabfad | bellard | { |
211 | b41a2cd1 | bellard | KBDState *s = opaque; |
212 | 80cabfad | bellard | |
213 | 80cabfad | bellard | #ifdef DEBUG_KBD
|
214 | 80cabfad | bellard | printf("kbd: write cmd=0x%02x\n", val);
|
215 | 80cabfad | bellard | #endif
|
216 | 80cabfad | bellard | switch(val) {
|
217 | 80cabfad | bellard | case KBD_CCMD_READ_MODE:
|
218 | 80cabfad | bellard | kbd_queue(s, s->mode, 0);
|
219 | 80cabfad | bellard | break;
|
220 | 80cabfad | bellard | case KBD_CCMD_WRITE_MODE:
|
221 | 80cabfad | bellard | case KBD_CCMD_WRITE_OBUF:
|
222 | 80cabfad | bellard | case KBD_CCMD_WRITE_AUX_OBUF:
|
223 | 80cabfad | bellard | case KBD_CCMD_WRITE_MOUSE:
|
224 | 80cabfad | bellard | case KBD_CCMD_WRITE_OUTPORT:
|
225 | 80cabfad | bellard | s->write_cmd = val; |
226 | 80cabfad | bellard | break;
|
227 | 80cabfad | bellard | case KBD_CCMD_MOUSE_DISABLE:
|
228 | 80cabfad | bellard | s->mode |= KBD_MODE_DISABLE_MOUSE; |
229 | 80cabfad | bellard | break;
|
230 | 80cabfad | bellard | case KBD_CCMD_MOUSE_ENABLE:
|
231 | 80cabfad | bellard | s->mode &= ~KBD_MODE_DISABLE_MOUSE; |
232 | 80cabfad | bellard | break;
|
233 | 80cabfad | bellard | case KBD_CCMD_TEST_MOUSE:
|
234 | 80cabfad | bellard | kbd_queue(s, 0x00, 0); |
235 | 80cabfad | bellard | break;
|
236 | 80cabfad | bellard | case KBD_CCMD_SELF_TEST:
|
237 | 80cabfad | bellard | s->status |= KBD_STAT_SELFTEST; |
238 | 80cabfad | bellard | kbd_queue(s, 0x55, 0); |
239 | 80cabfad | bellard | break;
|
240 | 80cabfad | bellard | case KBD_CCMD_KBD_TEST:
|
241 | 80cabfad | bellard | kbd_queue(s, 0x00, 0); |
242 | 80cabfad | bellard | break;
|
243 | 80cabfad | bellard | case KBD_CCMD_KBD_DISABLE:
|
244 | 80cabfad | bellard | s->mode |= KBD_MODE_DISABLE_KBD; |
245 | 80cabfad | bellard | kbd_update_irq(s); |
246 | 80cabfad | bellard | break;
|
247 | 80cabfad | bellard | case KBD_CCMD_KBD_ENABLE:
|
248 | 80cabfad | bellard | s->mode &= ~KBD_MODE_DISABLE_KBD; |
249 | 80cabfad | bellard | kbd_update_irq(s); |
250 | 80cabfad | bellard | break;
|
251 | 80cabfad | bellard | case KBD_CCMD_READ_INPORT:
|
252 | 80cabfad | bellard | kbd_queue(s, 0x00, 0); |
253 | 80cabfad | bellard | break;
|
254 | 80cabfad | bellard | case KBD_CCMD_READ_OUTPORT:
|
255 | 80cabfad | bellard | /* XXX: check that */
|
256 | 80cabfad | bellard | #ifdef TARGET_I386
|
257 | 80cabfad | bellard | val = 0x01 | (((cpu_single_env->a20_mask >> 20) & 1) << 1); |
258 | 80cabfad | bellard | #else
|
259 | 80cabfad | bellard | val = 0x01;
|
260 | 80cabfad | bellard | #endif
|
261 | 80cabfad | bellard | if (s->status & KBD_STAT_OBF)
|
262 | 80cabfad | bellard | val |= 0x10;
|
263 | 80cabfad | bellard | if (s->status & KBD_STAT_MOUSE_OBF)
|
264 | 80cabfad | bellard | val |= 0x20;
|
265 | 80cabfad | bellard | kbd_queue(s, val, 0);
|
266 | 80cabfad | bellard | break;
|
267 | 80cabfad | bellard | #ifdef TARGET_I386
|
268 | 80cabfad | bellard | case KBD_CCMD_ENABLE_A20:
|
269 | b41a2cd1 | bellard | cpu_x86_set_a20(cpu_single_env, 1);
|
270 | 80cabfad | bellard | break;
|
271 | 80cabfad | bellard | case KBD_CCMD_DISABLE_A20:
|
272 | b41a2cd1 | bellard | cpu_x86_set_a20(cpu_single_env, 0);
|
273 | 80cabfad | bellard | break;
|
274 | 80cabfad | bellard | #endif
|
275 | 80cabfad | bellard | case KBD_CCMD_RESET:
|
276 | d7d02e3c | bellard | qemu_system_reset_request(); |
277 | 80cabfad | bellard | break;
|
278 | 80cabfad | bellard | case 0xff: |
279 | 80cabfad | bellard | /* ignore that - I don't know what is its use */
|
280 | 80cabfad | bellard | break;
|
281 | 80cabfad | bellard | default:
|
282 | 80cabfad | bellard | fprintf(stderr, "qemu: unsupported keyboard cmd=0x%02x\n", val);
|
283 | 80cabfad | bellard | break;
|
284 | 80cabfad | bellard | } |
285 | 80cabfad | bellard | } |
286 | 80cabfad | bellard | |
287 | b41a2cd1 | bellard | static uint32_t kbd_read_data(void *opaque, uint32_t addr) |
288 | 80cabfad | bellard | { |
289 | b41a2cd1 | bellard | KBDState *s = opaque; |
290 | 80cabfad | bellard | KBDQueue *q; |
291 | 6f51f6b5 | bellard | int val, index, aux;
|
292 | 80cabfad | bellard | |
293 | 6f51f6b5 | bellard | q = &s->queue; |
294 | 80cabfad | bellard | if (q->count == 0) { |
295 | 80cabfad | bellard | /* NOTE: if no data left, we return the last keyboard one
|
296 | 80cabfad | bellard | (needed for EMM386) */
|
297 | 80cabfad | bellard | /* XXX: need a timer to do things correctly */
|
298 | 80cabfad | bellard | index = q->rptr - 1;
|
299 | 80cabfad | bellard | if (index < 0) |
300 | 80cabfad | bellard | index = KBD_QUEUE_SIZE - 1;
|
301 | 80cabfad | bellard | val = q->data[index]; |
302 | 80cabfad | bellard | } else {
|
303 | 6f51f6b5 | bellard | aux = q->aux[q->rptr]; |
304 | 80cabfad | bellard | val = q->data[q->rptr]; |
305 | 80cabfad | bellard | if (++q->rptr == KBD_QUEUE_SIZE)
|
306 | 80cabfad | bellard | q->rptr = 0;
|
307 | 80cabfad | bellard | q->count--; |
308 | 80cabfad | bellard | /* reading deasserts IRQ */
|
309 | 6f51f6b5 | bellard | if (aux)
|
310 | 80cabfad | bellard | pic_set_irq(12, 0); |
311 | 6f51f6b5 | bellard | else
|
312 | 6f51f6b5 | bellard | pic_set_irq(1, 0); |
313 | 80cabfad | bellard | } |
314 | 80cabfad | bellard | /* reassert IRQs if data left */
|
315 | 80cabfad | bellard | kbd_update_irq(s); |
316 | 80cabfad | bellard | #ifdef DEBUG_KBD
|
317 | 80cabfad | bellard | printf("kbd: read data=0x%02x\n", val);
|
318 | 80cabfad | bellard | #endif
|
319 | 80cabfad | bellard | return val;
|
320 | 80cabfad | bellard | } |
321 | 80cabfad | bellard | |
322 | 80cabfad | bellard | static void kbd_reset_keyboard(KBDState *s) |
323 | 80cabfad | bellard | { |
324 | 80cabfad | bellard | s->scan_enabled = 1;
|
325 | 80cabfad | bellard | } |
326 | 80cabfad | bellard | |
327 | 80cabfad | bellard | static void kbd_write_keyboard(KBDState *s, int val) |
328 | 80cabfad | bellard | { |
329 | 80cabfad | bellard | switch(s->kbd_write_cmd) {
|
330 | 80cabfad | bellard | default:
|
331 | 80cabfad | bellard | case -1: |
332 | 80cabfad | bellard | switch(val) {
|
333 | 80cabfad | bellard | case 0x00: |
334 | 80cabfad | bellard | kbd_queue(s, KBD_REPLY_ACK, 0);
|
335 | 80cabfad | bellard | break;
|
336 | 80cabfad | bellard | case 0x05: |
337 | 80cabfad | bellard | kbd_queue(s, KBD_REPLY_RESEND, 0);
|
338 | 80cabfad | bellard | break;
|
339 | 80cabfad | bellard | case KBD_CMD_GET_ID:
|
340 | 80cabfad | bellard | kbd_queue(s, KBD_REPLY_ACK, 0);
|
341 | 80cabfad | bellard | kbd_queue(s, 0xab, 0); |
342 | 80cabfad | bellard | kbd_queue(s, 0x83, 0); |
343 | 80cabfad | bellard | break;
|
344 | 80cabfad | bellard | case KBD_CMD_ECHO:
|
345 | 80cabfad | bellard | kbd_queue(s, KBD_CMD_ECHO, 0);
|
346 | 80cabfad | bellard | break;
|
347 | 80cabfad | bellard | case KBD_CMD_ENABLE:
|
348 | 80cabfad | bellard | s->scan_enabled = 1;
|
349 | 80cabfad | bellard | kbd_queue(s, KBD_REPLY_ACK, 0);
|
350 | 80cabfad | bellard | break;
|
351 | 80cabfad | bellard | case KBD_CMD_SET_LEDS:
|
352 | 80cabfad | bellard | case KBD_CMD_SET_RATE:
|
353 | 80cabfad | bellard | s->kbd_write_cmd = val; |
354 | 80cabfad | bellard | kbd_queue(s, KBD_REPLY_ACK, 0);
|
355 | 80cabfad | bellard | break;
|
356 | 80cabfad | bellard | case KBD_CMD_RESET_DISABLE:
|
357 | 80cabfad | bellard | kbd_reset_keyboard(s); |
358 | 80cabfad | bellard | s->scan_enabled = 0;
|
359 | 80cabfad | bellard | kbd_queue(s, KBD_REPLY_ACK, 0);
|
360 | 80cabfad | bellard | break;
|
361 | 80cabfad | bellard | case KBD_CMD_RESET_ENABLE:
|
362 | 80cabfad | bellard | kbd_reset_keyboard(s); |
363 | 80cabfad | bellard | s->scan_enabled = 1;
|
364 | 80cabfad | bellard | kbd_queue(s, KBD_REPLY_ACK, 0);
|
365 | 80cabfad | bellard | break;
|
366 | 80cabfad | bellard | case KBD_CMD_RESET:
|
367 | 80cabfad | bellard | kbd_reset_keyboard(s); |
368 | 80cabfad | bellard | kbd_queue(s, KBD_REPLY_ACK, 0);
|
369 | 80cabfad | bellard | kbd_queue(s, KBD_REPLY_POR, 0);
|
370 | 80cabfad | bellard | break;
|
371 | 80cabfad | bellard | default:
|
372 | 80cabfad | bellard | kbd_queue(s, KBD_REPLY_ACK, 0);
|
373 | 80cabfad | bellard | break;
|
374 | 80cabfad | bellard | } |
375 | 80cabfad | bellard | break;
|
376 | 80cabfad | bellard | case KBD_CMD_SET_LEDS:
|
377 | 80cabfad | bellard | kbd_queue(s, KBD_REPLY_ACK, 0);
|
378 | 80cabfad | bellard | s->kbd_write_cmd = -1;
|
379 | 80cabfad | bellard | break;
|
380 | 80cabfad | bellard | case KBD_CMD_SET_RATE:
|
381 | 80cabfad | bellard | kbd_queue(s, KBD_REPLY_ACK, 0);
|
382 | 80cabfad | bellard | s->kbd_write_cmd = -1;
|
383 | 80cabfad | bellard | break;
|
384 | 80cabfad | bellard | } |
385 | 80cabfad | bellard | } |
386 | 80cabfad | bellard | |
387 | 80cabfad | bellard | static void kbd_mouse_send_packet(KBDState *s) |
388 | 80cabfad | bellard | { |
389 | 80cabfad | bellard | unsigned int b; |
390 | 80cabfad | bellard | int dx1, dy1, dz1;
|
391 | 80cabfad | bellard | |
392 | 80cabfad | bellard | dx1 = s->mouse_dx; |
393 | 80cabfad | bellard | dy1 = s->mouse_dy; |
394 | 80cabfad | bellard | dz1 = s->mouse_dz; |
395 | 80cabfad | bellard | /* XXX: increase range to 8 bits ? */
|
396 | 80cabfad | bellard | if (dx1 > 127) |
397 | 80cabfad | bellard | dx1 = 127;
|
398 | 80cabfad | bellard | else if (dx1 < -127) |
399 | 80cabfad | bellard | dx1 = -127;
|
400 | 80cabfad | bellard | if (dy1 > 127) |
401 | 80cabfad | bellard | dy1 = 127;
|
402 | 80cabfad | bellard | else if (dy1 < -127) |
403 | 80cabfad | bellard | dy1 = -127;
|
404 | 80cabfad | bellard | b = 0x08 | ((dx1 < 0) << 4) | ((dy1 < 0) << 5) | (s->mouse_buttons & 0x07); |
405 | 80cabfad | bellard | kbd_queue(s, b, 1);
|
406 | 80cabfad | bellard | kbd_queue(s, dx1 & 0xff, 1); |
407 | 80cabfad | bellard | kbd_queue(s, dy1 & 0xff, 1); |
408 | 80cabfad | bellard | /* extra byte for IMPS/2 or IMEX */
|
409 | 80cabfad | bellard | switch(s->mouse_type) {
|
410 | 80cabfad | bellard | default:
|
411 | 80cabfad | bellard | break;
|
412 | 80cabfad | bellard | case 3: |
413 | 80cabfad | bellard | if (dz1 > 127) |
414 | 80cabfad | bellard | dz1 = 127;
|
415 | 80cabfad | bellard | else if (dz1 < -127) |
416 | 80cabfad | bellard | dz1 = -127;
|
417 | 80cabfad | bellard | kbd_queue(s, dz1 & 0xff, 1); |
418 | 80cabfad | bellard | break;
|
419 | 80cabfad | bellard | case 4: |
420 | 80cabfad | bellard | if (dz1 > 7) |
421 | 80cabfad | bellard | dz1 = 7;
|
422 | 80cabfad | bellard | else if (dz1 < -7) |
423 | 80cabfad | bellard | dz1 = -7;
|
424 | 80cabfad | bellard | b = (dz1 & 0x0f) | ((s->mouse_buttons & 0x18) << 1); |
425 | 80cabfad | bellard | kbd_queue(s, b, 1);
|
426 | 80cabfad | bellard | break;
|
427 | 80cabfad | bellard | } |
428 | 80cabfad | bellard | |
429 | 80cabfad | bellard | /* update deltas */
|
430 | 80cabfad | bellard | s->mouse_dx -= dx1; |
431 | 80cabfad | bellard | s->mouse_dy -= dy1; |
432 | 80cabfad | bellard | s->mouse_dz -= dz1; |
433 | 80cabfad | bellard | } |
434 | 80cabfad | bellard | |
435 | 63066f4f | bellard | static void pc_kbd_mouse_event(void *opaque, |
436 | 63066f4f | bellard | int dx, int dy, int dz, int buttons_state) |
437 | 80cabfad | bellard | { |
438 | 63066f4f | bellard | KBDState *s = opaque; |
439 | 80cabfad | bellard | |
440 | 80cabfad | bellard | /* check if deltas are recorded when disabled */
|
441 | 80cabfad | bellard | if (!(s->mouse_status & MOUSE_STATUS_ENABLED))
|
442 | 80cabfad | bellard | return;
|
443 | 80cabfad | bellard | |
444 | 80cabfad | bellard | s->mouse_dx += dx; |
445 | 80cabfad | bellard | s->mouse_dy -= dy; |
446 | 80cabfad | bellard | s->mouse_dz += dz; |
447 | 92cb7d54 | bellard | /* XXX: SDL sometimes generates nul events: we delete them */
|
448 | 92cb7d54 | bellard | if (s->mouse_dx == 0 && s->mouse_dy == 0 && s->mouse_dz == 0 && |
449 | 92cb7d54 | bellard | s->mouse_buttons == buttons_state) |
450 | 92cb7d54 | bellard | return;
|
451 | 80cabfad | bellard | s->mouse_buttons = buttons_state; |
452 | 80cabfad | bellard | |
453 | 80cabfad | bellard | if (!(s->mouse_status & MOUSE_STATUS_REMOTE) &&
|
454 | 6f51f6b5 | bellard | (s->queue.count < (KBD_QUEUE_SIZE - 16))) {
|
455 | 80cabfad | bellard | for(;;) {
|
456 | 80cabfad | bellard | /* if not remote, send event. Multiple events are sent if
|
457 | 80cabfad | bellard | too big deltas */
|
458 | 80cabfad | bellard | kbd_mouse_send_packet(s); |
459 | 80cabfad | bellard | if (s->mouse_dx == 0 && s->mouse_dy == 0 && s->mouse_dz == 0) |
460 | 80cabfad | bellard | break;
|
461 | 80cabfad | bellard | } |
462 | 80cabfad | bellard | } |
463 | 80cabfad | bellard | } |
464 | 80cabfad | bellard | |
465 | 80cabfad | bellard | static void kbd_write_mouse(KBDState *s, int val) |
466 | 80cabfad | bellard | { |
467 | 80cabfad | bellard | #ifdef DEBUG_MOUSE
|
468 | 80cabfad | bellard | printf("kbd: write mouse 0x%02x\n", val);
|
469 | 80cabfad | bellard | #endif
|
470 | 80cabfad | bellard | switch(s->mouse_write_cmd) {
|
471 | 80cabfad | bellard | default:
|
472 | 80cabfad | bellard | case -1: |
473 | 80cabfad | bellard | /* mouse command */
|
474 | 80cabfad | bellard | if (s->mouse_wrap) {
|
475 | 80cabfad | bellard | if (val == AUX_RESET_WRAP) {
|
476 | 80cabfad | bellard | s->mouse_wrap = 0;
|
477 | 80cabfad | bellard | kbd_queue(s, AUX_ACK, 1);
|
478 | 80cabfad | bellard | return;
|
479 | 80cabfad | bellard | } else if (val != AUX_RESET) { |
480 | 80cabfad | bellard | kbd_queue(s, val, 1);
|
481 | 80cabfad | bellard | return;
|
482 | 80cabfad | bellard | } |
483 | 80cabfad | bellard | } |
484 | 80cabfad | bellard | switch(val) {
|
485 | 80cabfad | bellard | case AUX_SET_SCALE11:
|
486 | 80cabfad | bellard | s->mouse_status &= ~MOUSE_STATUS_SCALE21; |
487 | 80cabfad | bellard | kbd_queue(s, AUX_ACK, 1);
|
488 | 80cabfad | bellard | break;
|
489 | 80cabfad | bellard | case AUX_SET_SCALE21:
|
490 | 80cabfad | bellard | s->mouse_status |= MOUSE_STATUS_SCALE21; |
491 | 80cabfad | bellard | kbd_queue(s, AUX_ACK, 1);
|
492 | 80cabfad | bellard | break;
|
493 | 80cabfad | bellard | case AUX_SET_STREAM:
|
494 | 80cabfad | bellard | s->mouse_status &= ~MOUSE_STATUS_REMOTE; |
495 | 80cabfad | bellard | kbd_queue(s, AUX_ACK, 1);
|
496 | 80cabfad | bellard | break;
|
497 | 80cabfad | bellard | case AUX_SET_WRAP:
|
498 | 80cabfad | bellard | s->mouse_wrap = 1;
|
499 | 80cabfad | bellard | kbd_queue(s, AUX_ACK, 1);
|
500 | 80cabfad | bellard | break;
|
501 | 80cabfad | bellard | case AUX_SET_REMOTE:
|
502 | 80cabfad | bellard | s->mouse_status |= MOUSE_STATUS_REMOTE; |
503 | 80cabfad | bellard | kbd_queue(s, AUX_ACK, 1);
|
504 | 80cabfad | bellard | break;
|
505 | 80cabfad | bellard | case AUX_GET_TYPE:
|
506 | 80cabfad | bellard | kbd_queue(s, AUX_ACK, 1);
|
507 | 80cabfad | bellard | kbd_queue(s, s->mouse_type, 1);
|
508 | 80cabfad | bellard | break;
|
509 | 80cabfad | bellard | case AUX_SET_RES:
|
510 | 80cabfad | bellard | case AUX_SET_SAMPLE:
|
511 | 80cabfad | bellard | s->mouse_write_cmd = val; |
512 | 80cabfad | bellard | kbd_queue(s, AUX_ACK, 1);
|
513 | 80cabfad | bellard | break;
|
514 | 80cabfad | bellard | case AUX_GET_SCALE:
|
515 | 80cabfad | bellard | kbd_queue(s, AUX_ACK, 1);
|
516 | 80cabfad | bellard | kbd_queue(s, s->mouse_status, 1);
|
517 | 80cabfad | bellard | kbd_queue(s, s->mouse_resolution, 1);
|
518 | 80cabfad | bellard | kbd_queue(s, s->mouse_sample_rate, 1);
|
519 | 80cabfad | bellard | break;
|
520 | 80cabfad | bellard | case AUX_POLL:
|
521 | 80cabfad | bellard | kbd_queue(s, AUX_ACK, 1);
|
522 | 80cabfad | bellard | kbd_mouse_send_packet(s); |
523 | 80cabfad | bellard | break;
|
524 | 80cabfad | bellard | case AUX_ENABLE_DEV:
|
525 | 80cabfad | bellard | s->mouse_status |= MOUSE_STATUS_ENABLED; |
526 | 80cabfad | bellard | kbd_queue(s, AUX_ACK, 1);
|
527 | 80cabfad | bellard | break;
|
528 | 80cabfad | bellard | case AUX_DISABLE_DEV:
|
529 | 80cabfad | bellard | s->mouse_status &= ~MOUSE_STATUS_ENABLED; |
530 | 80cabfad | bellard | kbd_queue(s, AUX_ACK, 1);
|
531 | 80cabfad | bellard | break;
|
532 | 80cabfad | bellard | case AUX_SET_DEFAULT:
|
533 | 80cabfad | bellard | s->mouse_sample_rate = 100;
|
534 | 80cabfad | bellard | s->mouse_resolution = 2;
|
535 | 80cabfad | bellard | s->mouse_status = 0;
|
536 | 80cabfad | bellard | kbd_queue(s, AUX_ACK, 1);
|
537 | 80cabfad | bellard | break;
|
538 | 80cabfad | bellard | case AUX_RESET:
|
539 | 80cabfad | bellard | s->mouse_sample_rate = 100;
|
540 | 80cabfad | bellard | s->mouse_resolution = 2;
|
541 | 80cabfad | bellard | s->mouse_status = 0;
|
542 | f34c9d6f | bellard | s->mouse_type = 0;
|
543 | 80cabfad | bellard | kbd_queue(s, AUX_ACK, 1);
|
544 | 80cabfad | bellard | kbd_queue(s, 0xaa, 1); |
545 | 80cabfad | bellard | kbd_queue(s, s->mouse_type, 1);
|
546 | 80cabfad | bellard | break;
|
547 | 80cabfad | bellard | default:
|
548 | 80cabfad | bellard | break;
|
549 | 80cabfad | bellard | } |
550 | 80cabfad | bellard | break;
|
551 | 80cabfad | bellard | case AUX_SET_SAMPLE:
|
552 | 80cabfad | bellard | s->mouse_sample_rate = val; |
553 | 80cabfad | bellard | /* detect IMPS/2 or IMEX */
|
554 | 80cabfad | bellard | switch(s->mouse_detect_state) {
|
555 | 80cabfad | bellard | default:
|
556 | 80cabfad | bellard | case 0: |
557 | 80cabfad | bellard | if (val == 200) |
558 | 80cabfad | bellard | s->mouse_detect_state = 1;
|
559 | 80cabfad | bellard | break;
|
560 | 80cabfad | bellard | case 1: |
561 | 80cabfad | bellard | if (val == 100) |
562 | 80cabfad | bellard | s->mouse_detect_state = 2;
|
563 | 80cabfad | bellard | else if (val == 200) |
564 | 80cabfad | bellard | s->mouse_detect_state = 3;
|
565 | 80cabfad | bellard | else
|
566 | 80cabfad | bellard | s->mouse_detect_state = 0;
|
567 | 80cabfad | bellard | break;
|
568 | 80cabfad | bellard | case 2: |
569 | 80cabfad | bellard | if (val == 80) |
570 | 80cabfad | bellard | s->mouse_type = 3; /* IMPS/2 */ |
571 | 80cabfad | bellard | s->mouse_detect_state = 0;
|
572 | 80cabfad | bellard | break;
|
573 | 80cabfad | bellard | case 3: |
574 | 80cabfad | bellard | if (val == 80) |
575 | 80cabfad | bellard | s->mouse_type = 4; /* IMEX */ |
576 | 80cabfad | bellard | s->mouse_detect_state = 0;
|
577 | 80cabfad | bellard | break;
|
578 | 80cabfad | bellard | } |
579 | 80cabfad | bellard | kbd_queue(s, AUX_ACK, 1);
|
580 | 80cabfad | bellard | s->mouse_write_cmd = -1;
|
581 | 80cabfad | bellard | break;
|
582 | 80cabfad | bellard | case AUX_SET_RES:
|
583 | 80cabfad | bellard | s->mouse_resolution = val; |
584 | 80cabfad | bellard | kbd_queue(s, AUX_ACK, 1);
|
585 | 80cabfad | bellard | s->mouse_write_cmd = -1;
|
586 | 80cabfad | bellard | break;
|
587 | 80cabfad | bellard | } |
588 | 80cabfad | bellard | } |
589 | 80cabfad | bellard | |
590 | b41a2cd1 | bellard | void kbd_write_data(void *opaque, uint32_t addr, uint32_t val) |
591 | 80cabfad | bellard | { |
592 | b41a2cd1 | bellard | KBDState *s = opaque; |
593 | 80cabfad | bellard | |
594 | 80cabfad | bellard | #ifdef DEBUG_KBD
|
595 | 80cabfad | bellard | printf("kbd: write data=0x%02x\n", val);
|
596 | 80cabfad | bellard | #endif
|
597 | 80cabfad | bellard | |
598 | 80cabfad | bellard | switch(s->write_cmd) {
|
599 | 80cabfad | bellard | case 0: |
600 | 80cabfad | bellard | kbd_write_keyboard(s, val); |
601 | 80cabfad | bellard | break;
|
602 | 80cabfad | bellard | case KBD_CCMD_WRITE_MODE:
|
603 | 80cabfad | bellard | s->mode = val; |
604 | 80cabfad | bellard | kbd_update_irq(s); |
605 | 80cabfad | bellard | break;
|
606 | 80cabfad | bellard | case KBD_CCMD_WRITE_OBUF:
|
607 | 80cabfad | bellard | kbd_queue(s, val, 0);
|
608 | 80cabfad | bellard | break;
|
609 | 80cabfad | bellard | case KBD_CCMD_WRITE_AUX_OBUF:
|
610 | 80cabfad | bellard | kbd_queue(s, val, 1);
|
611 | 80cabfad | bellard | break;
|
612 | 80cabfad | bellard | case KBD_CCMD_WRITE_OUTPORT:
|
613 | 80cabfad | bellard | #ifdef TARGET_I386
|
614 | b41a2cd1 | bellard | cpu_x86_set_a20(cpu_single_env, (val >> 1) & 1); |
615 | 80cabfad | bellard | #endif
|
616 | 80cabfad | bellard | if (!(val & 1)) { |
617 | d7d02e3c | bellard | qemu_system_reset_request(); |
618 | 80cabfad | bellard | } |
619 | 80cabfad | bellard | break;
|
620 | 80cabfad | bellard | case KBD_CCMD_WRITE_MOUSE:
|
621 | 80cabfad | bellard | kbd_write_mouse(s, val); |
622 | 80cabfad | bellard | break;
|
623 | 80cabfad | bellard | default:
|
624 | 80cabfad | bellard | break;
|
625 | 80cabfad | bellard | } |
626 | 80cabfad | bellard | s->write_cmd = 0;
|
627 | 80cabfad | bellard | } |
628 | 80cabfad | bellard | |
629 | d7d02e3c | bellard | static void kbd_reset(void *opaque) |
630 | 80cabfad | bellard | { |
631 | d7d02e3c | bellard | KBDState *s = opaque; |
632 | 80cabfad | bellard | KBDQueue *q; |
633 | 80cabfad | bellard | |
634 | 80cabfad | bellard | s->kbd_write_cmd = -1;
|
635 | 80cabfad | bellard | s->mouse_write_cmd = -1;
|
636 | 80cabfad | bellard | s->mode = KBD_MODE_KBD_INT | KBD_MODE_MOUSE_INT; |
637 | 80cabfad | bellard | s->status = KBD_STAT_CMD | KBD_STAT_UNLOCKED; |
638 | 6f51f6b5 | bellard | q = &s->queue; |
639 | 6f51f6b5 | bellard | q->rptr = 0;
|
640 | 6f51f6b5 | bellard | q->wptr = 0;
|
641 | 6f51f6b5 | bellard | q->count = 0;
|
642 | 80cabfad | bellard | } |
643 | 80cabfad | bellard | |
644 | 675376f2 | bellard | static void kbd_save(QEMUFile* f, void* opaque) |
645 | 675376f2 | bellard | { |
646 | 675376f2 | bellard | KBDState *s = (KBDState*)opaque; |
647 | 675376f2 | bellard | |
648 | 675376f2 | bellard | qemu_put_8s(f, &s->write_cmd); |
649 | 675376f2 | bellard | qemu_put_8s(f, &s->status); |
650 | 675376f2 | bellard | qemu_put_8s(f, &s->mode); |
651 | 675376f2 | bellard | qemu_put_be32s(f, &s->kbd_write_cmd); |
652 | 675376f2 | bellard | qemu_put_be32s(f, &s->scan_enabled); |
653 | 675376f2 | bellard | qemu_put_be32s(f, &s->mouse_write_cmd); |
654 | 675376f2 | bellard | qemu_put_8s(f, &s->mouse_status); |
655 | 675376f2 | bellard | qemu_put_8s(f, &s->mouse_resolution); |
656 | 675376f2 | bellard | qemu_put_8s(f, &s->mouse_sample_rate); |
657 | 675376f2 | bellard | qemu_put_8s(f, &s->mouse_wrap); |
658 | 675376f2 | bellard | qemu_put_8s(f, &s->mouse_type); |
659 | 675376f2 | bellard | qemu_put_8s(f, &s->mouse_detect_state); |
660 | 675376f2 | bellard | qemu_put_be32s(f, &s->mouse_dx); |
661 | 675376f2 | bellard | qemu_put_be32s(f, &s->mouse_dy); |
662 | 675376f2 | bellard | qemu_put_be32s(f, &s->mouse_dz); |
663 | 675376f2 | bellard | qemu_put_8s(f, &s->mouse_buttons); |
664 | 675376f2 | bellard | } |
665 | 675376f2 | bellard | |
666 | 675376f2 | bellard | static int kbd_load(QEMUFile* f, void* opaque, int version_id) |
667 | 675376f2 | bellard | { |
668 | 675376f2 | bellard | KBDState *s = (KBDState*)opaque; |
669 | 675376f2 | bellard | |
670 | 675376f2 | bellard | if (version_id != 1) |
671 | 675376f2 | bellard | return -EINVAL;
|
672 | 675376f2 | bellard | qemu_get_8s(f, &s->write_cmd); |
673 | 675376f2 | bellard | qemu_get_8s(f, &s->status); |
674 | 675376f2 | bellard | qemu_get_8s(f, &s->mode); |
675 | 675376f2 | bellard | qemu_get_be32s(f, &s->kbd_write_cmd); |
676 | 675376f2 | bellard | qemu_get_be32s(f, &s->scan_enabled); |
677 | 675376f2 | bellard | qemu_get_be32s(f, &s->mouse_write_cmd); |
678 | 675376f2 | bellard | qemu_get_8s(f, &s->mouse_status); |
679 | 675376f2 | bellard | qemu_get_8s(f, &s->mouse_resolution); |
680 | 675376f2 | bellard | qemu_get_8s(f, &s->mouse_sample_rate); |
681 | 675376f2 | bellard | qemu_get_8s(f, &s->mouse_wrap); |
682 | 675376f2 | bellard | qemu_get_8s(f, &s->mouse_type); |
683 | 675376f2 | bellard | qemu_get_8s(f, &s->mouse_detect_state); |
684 | 675376f2 | bellard | qemu_get_be32s(f, &s->mouse_dx); |
685 | 675376f2 | bellard | qemu_get_be32s(f, &s->mouse_dy); |
686 | 675376f2 | bellard | qemu_get_be32s(f, &s->mouse_dz); |
687 | 675376f2 | bellard | qemu_get_8s(f, &s->mouse_buttons); |
688 | 675376f2 | bellard | return 0; |
689 | 675376f2 | bellard | } |
690 | 675376f2 | bellard | |
691 | 80cabfad | bellard | void kbd_init(void) |
692 | 80cabfad | bellard | { |
693 | b41a2cd1 | bellard | KBDState *s = &kbd_state; |
694 | b41a2cd1 | bellard | |
695 | b41a2cd1 | bellard | kbd_reset(s); |
696 | 675376f2 | bellard | register_savevm("pckbd", 0, 1, kbd_save, kbd_load, s); |
697 | b41a2cd1 | bellard | register_ioport_read(0x60, 1, 1, kbd_read_data, s); |
698 | b41a2cd1 | bellard | register_ioport_write(0x60, 1, 1, kbd_write_data, s); |
699 | b41a2cd1 | bellard | register_ioport_read(0x64, 1, 1, kbd_read_status, s); |
700 | b41a2cd1 | bellard | register_ioport_write(0x64, 1, 1, kbd_write_command, s); |
701 | 63066f4f | bellard | |
702 | 63066f4f | bellard | qemu_add_kbd_event_handler(pc_kbd_put_keycode, s); |
703 | 63066f4f | bellard | qemu_add_mouse_event_handler(pc_kbd_mouse_event, s); |
704 | d7d02e3c | bellard | qemu_register_reset(kbd_reset, s); |
705 | 80cabfad | bellard | } |