Commit bec9d989dba24e5ce4f94fcbccc841769a510bae
1 parent
cab84d98
fixed register 0 usage - fixed mouse buttons
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1009 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
1 changed file
with
55 additions
and
31 deletions
hw/adb.c
... | ... | @@ -43,53 +43,62 @@ |
43 | 43 | #define ADB_MODEM 5 |
44 | 44 | #define ADB_MISC 7 |
45 | 45 | |
46 | +/* error codes */ | |
47 | +#define ADB_RET_NOTPRESENT (-2) | |
48 | + | |
46 | 49 | int adb_request(ADBBusState *s, uint8_t *obuf, const uint8_t *buf, int len) |
47 | 50 | { |
48 | 51 | ADBDevice *d; |
49 | 52 | int devaddr, cmd, i; |
50 | 53 | |
51 | 54 | cmd = buf[0] & 0xf; |
52 | - devaddr = buf[0] >> 4; | |
53 | - if (buf[1] == ADB_BUSRESET) { | |
54 | - obuf[0] = 0x00; | |
55 | - obuf[1] = 0x00; | |
56 | - return 2; | |
57 | - } | |
58 | - if (cmd == ADB_FLUSH) { | |
59 | - obuf[0] = 0x00; | |
60 | - obuf[1] = 0x00; | |
61 | - return 2; | |
55 | + if (cmd == ADB_BUSRESET) { | |
56 | + for(i = 0; i < s->nb_devices; i++) { | |
57 | + d = &s->devices[i]; | |
58 | + if (d->devreset) { | |
59 | + d->devreset(d); | |
60 | + } | |
61 | + } | |
62 | + return 0; | |
62 | 63 | } |
63 | - | |
64 | + devaddr = buf[0] >> 4; | |
64 | 65 | for(i = 0; i < s->nb_devices; i++) { |
65 | 66 | d = &s->devices[i]; |
66 | 67 | if (d->devaddr == devaddr) { |
67 | 68 | return d->devreq(d, obuf, buf, len); |
68 | 69 | } |
69 | 70 | } |
70 | - return 0; | |
71 | + return ADB_RET_NOTPRESENT; | |
71 | 72 | } |
72 | 73 | |
74 | +/* XXX: move that to cuda ? */ | |
73 | 75 | int adb_poll(ADBBusState *s, uint8_t *obuf) |
74 | 76 | { |
75 | 77 | ADBDevice *d; |
76 | 78 | int olen, i; |
79 | + uint8_t buf[1]; | |
77 | 80 | |
78 | 81 | olen = 0; |
79 | 82 | for(i = 0; i < s->nb_devices; i++) { |
80 | 83 | if (s->poll_index >= s->nb_devices) |
81 | 84 | s->poll_index = 0; |
82 | 85 | d = &s->devices[s->poll_index]; |
83 | - olen = d->devreq(d, obuf, NULL, 0); | |
84 | - s->poll_index++; | |
85 | - if (olen) | |
86 | + buf[0] = ADB_READREG | (d->devaddr << 4); | |
87 | + olen = adb_request(s, obuf + 1, buf, 1); | |
88 | + /* if there is data, we poll again the same device */ | |
89 | + if (olen > 0) { | |
90 | + obuf[0] = buf[0]; | |
91 | + olen++; | |
86 | 92 | break; |
93 | + } | |
94 | + s->poll_index++; | |
87 | 95 | } |
88 | 96 | return olen; |
89 | 97 | } |
90 | 98 | |
91 | 99 | ADBDevice *adb_register_device(ADBBusState *s, int devaddr, |
92 | 100 | ADBDeviceRequest *devreq, |
101 | + ADBDeviceReset *devreset, | |
93 | 102 | void *opaque) |
94 | 103 | { |
95 | 104 | ADBDevice *d; |
... | ... | @@ -99,6 +108,7 @@ ADBDevice *adb_register_device(ADBBusState *s, int devaddr, |
99 | 108 | d->bus = s; |
100 | 109 | d->devaddr = devaddr; |
101 | 110 | d->devreq = devreq; |
111 | + d->devreset = devreset; | |
102 | 112 | d->opaque = opaque; |
103 | 113 | return d; |
104 | 114 | } |
... | ... | @@ -166,10 +176,10 @@ static int adb_kbd_poll(ADBDevice *d, uint8_t *obuf) |
166 | 176 | adb_keycode = pc_to_adb_keycode[keycode | 0x80]; |
167 | 177 | else |
168 | 178 | adb_keycode = pc_to_adb_keycode[keycode & 0x7f]; |
169 | - obuf[0] = (d->devaddr << 4) | 0x0c; | |
170 | - obuf[1] = adb_keycode | (keycode & 0x80); | |
171 | - obuf[2] = 0xff; | |
172 | - olen = 3; | |
179 | + obuf[0] = adb_keycode | (keycode & 0x80); | |
180 | + /* NOTE: could put a second keycode if needed */ | |
181 | + obuf[1] = 0xff; | |
182 | + olen = 2; | |
173 | 183 | ext_keycode = 0; |
174 | 184 | break; |
175 | 185 | } |
... | ... | @@ -180,10 +190,13 @@ static int adb_kbd_poll(ADBDevice *d, uint8_t *obuf) |
180 | 190 | static int adb_kbd_request(ADBDevice *d, uint8_t *obuf, |
181 | 191 | const uint8_t *buf, int len) |
182 | 192 | { |
193 | + KBDState *s = d->opaque; | |
183 | 194 | int cmd, reg, olen; |
184 | 195 | |
185 | - if (!buf) { | |
186 | - return adb_kbd_poll(d, obuf); | |
196 | + if ((buf[0] & 0x0f) == ADB_FLUSH) { | |
197 | + /* flush keyboard fifo */ | |
198 | + s->wptr = s->rptr = s->count = 0; | |
199 | + return 0; | |
187 | 200 | } |
188 | 201 | |
189 | 202 | cmd = buf[0] & 0xc; |
... | ... | @@ -214,6 +227,9 @@ static int adb_kbd_request(ADBDevice *d, uint8_t *obuf, |
214 | 227 | break; |
215 | 228 | case ADB_READREG: |
216 | 229 | switch(reg) { |
230 | + case 0: | |
231 | + olen = adb_kbd_poll(d, obuf); | |
232 | + break; | |
217 | 233 | case 1: |
218 | 234 | break; |
219 | 235 | case 2: |
... | ... | @@ -237,7 +253,7 @@ void adb_kbd_init(ADBBusState *bus) |
237 | 253 | ADBDevice *d; |
238 | 254 | KBDState *s; |
239 | 255 | s = qemu_mallocz(sizeof(KBDState)); |
240 | - d = adb_register_device(bus, ADB_KEYBOARD, adb_kbd_request, s); | |
256 | + d = adb_register_device(bus, ADB_KEYBOARD, adb_kbd_request, NULL, s); | |
241 | 257 | d->handler = 1; |
242 | 258 | qemu_add_kbd_event_handler(adb_kbd_put_keycode, d); |
243 | 259 | } |
... | ... | @@ -291,24 +307,29 @@ static int adb_mouse_poll(ADBDevice *d, uint8_t *obuf) |
291 | 307 | dx &= 0x7f; |
292 | 308 | dy &= 0x7f; |
293 | 309 | |
294 | - if (s->buttons_state & MOUSE_EVENT_LBUTTON) | |
310 | + if (!(s->buttons_state & MOUSE_EVENT_LBUTTON)) | |
295 | 311 | dy |= 0x80; |
296 | - if (s->buttons_state & MOUSE_EVENT_RBUTTON) | |
312 | + if (!(s->buttons_state & MOUSE_EVENT_RBUTTON)) | |
297 | 313 | dx |= 0x80; |
298 | 314 | |
299 | - obuf[0] = (d->devaddr << 4) | 0x0c; | |
300 | - obuf[1] = dy; | |
301 | - obuf[2] = dx; | |
302 | - return 3; | |
315 | + obuf[0] = dy; | |
316 | + obuf[1] = dx; | |
317 | + return 2; | |
303 | 318 | } |
304 | 319 | |
305 | 320 | static int adb_mouse_request(ADBDevice *d, uint8_t *obuf, |
306 | 321 | const uint8_t *buf, int len) |
307 | 322 | { |
323 | + MouseState *s = d->opaque; | |
308 | 324 | int cmd, reg, olen; |
309 | 325 | |
310 | - if (!buf) { | |
311 | - return adb_mouse_poll(d, obuf); | |
326 | + if ((buf[0] & 0x0f) == ADB_FLUSH) { | |
327 | + /* flush mouse fifo */ | |
328 | + s->buttons_state = s->last_buttons_state; | |
329 | + s->dx = 0; | |
330 | + s->dy = 0; | |
331 | + s->dz = 0; | |
332 | + return 0; | |
312 | 333 | } |
313 | 334 | |
314 | 335 | cmd = buf[0] & 0xc; |
... | ... | @@ -337,6 +358,9 @@ static int adb_mouse_request(ADBDevice *d, uint8_t *obuf, |
337 | 358 | break; |
338 | 359 | case ADB_READREG: |
339 | 360 | switch(reg) { |
361 | + case 0: | |
362 | + olen = adb_mouse_poll(d, obuf); | |
363 | + break; | |
340 | 364 | case 1: |
341 | 365 | break; |
342 | 366 | case 3: |
... | ... | @@ -356,7 +380,7 @@ void adb_mouse_init(ADBBusState *bus) |
356 | 380 | MouseState *s; |
357 | 381 | |
358 | 382 | s = qemu_mallocz(sizeof(MouseState)); |
359 | - d = adb_register_device(bus, ADB_MOUSE, adb_mouse_request, s); | |
383 | + d = adb_register_device(bus, ADB_MOUSE, adb_mouse_request, NULL, s); | |
360 | 384 | d->handler = 2; |
361 | 385 | qemu_add_mouse_event_handler(adb_mouse_event, d); |
362 | 386 | } | ... | ... |