Commit bec9d989dba24e5ce4f94fcbccc841769a510bae

Authored by bellard
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,53 +43,62 @@
43 #define ADB_MODEM 5 43 #define ADB_MODEM 5
44 #define ADB_MISC 7 44 #define ADB_MISC 7
45 45
  46 +/* error codes */
  47 +#define ADB_RET_NOTPRESENT (-2)
  48 +
46 int adb_request(ADBBusState *s, uint8_t *obuf, const uint8_t *buf, int len) 49 int adb_request(ADBBusState *s, uint8_t *obuf, const uint8_t *buf, int len)
47 { 50 {
48 ADBDevice *d; 51 ADBDevice *d;
49 int devaddr, cmd, i; 52 int devaddr, cmd, i;
50 53
51 cmd = buf[0] & 0xf; 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 for(i = 0; i < s->nb_devices; i++) { 65 for(i = 0; i < s->nb_devices; i++) {
65 d = &s->devices[i]; 66 d = &s->devices[i];
66 if (d->devaddr == devaddr) { 67 if (d->devaddr == devaddr) {
67 return d->devreq(d, obuf, buf, len); 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 int adb_poll(ADBBusState *s, uint8_t *obuf) 75 int adb_poll(ADBBusState *s, uint8_t *obuf)
74 { 76 {
75 ADBDevice *d; 77 ADBDevice *d;
76 int olen, i; 78 int olen, i;
  79 + uint8_t buf[1];
77 80
78 olen = 0; 81 olen = 0;
79 for(i = 0; i < s->nb_devices; i++) { 82 for(i = 0; i < s->nb_devices; i++) {
80 if (s->poll_index >= s->nb_devices) 83 if (s->poll_index >= s->nb_devices)
81 s->poll_index = 0; 84 s->poll_index = 0;
82 d = &s->devices[s->poll_index]; 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 break; 92 break;
  93 + }
  94 + s->poll_index++;
87 } 95 }
88 return olen; 96 return olen;
89 } 97 }
90 98
91 ADBDevice *adb_register_device(ADBBusState *s, int devaddr, 99 ADBDevice *adb_register_device(ADBBusState *s, int devaddr,
92 ADBDeviceRequest *devreq, 100 ADBDeviceRequest *devreq,
  101 + ADBDeviceReset *devreset,
93 void *opaque) 102 void *opaque)
94 { 103 {
95 ADBDevice *d; 104 ADBDevice *d;
@@ -99,6 +108,7 @@ ADBDevice *adb_register_device(ADBBusState *s, int devaddr, @@ -99,6 +108,7 @@ ADBDevice *adb_register_device(ADBBusState *s, int devaddr,
99 d->bus = s; 108 d->bus = s;
100 d->devaddr = devaddr; 109 d->devaddr = devaddr;
101 d->devreq = devreq; 110 d->devreq = devreq;
  111 + d->devreset = devreset;
102 d->opaque = opaque; 112 d->opaque = opaque;
103 return d; 113 return d;
104 } 114 }
@@ -166,10 +176,10 @@ static int adb_kbd_poll(ADBDevice *d, uint8_t *obuf) @@ -166,10 +176,10 @@ static int adb_kbd_poll(ADBDevice *d, uint8_t *obuf)
166 adb_keycode = pc_to_adb_keycode[keycode | 0x80]; 176 adb_keycode = pc_to_adb_keycode[keycode | 0x80];
167 else 177 else
168 adb_keycode = pc_to_adb_keycode[keycode & 0x7f]; 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 ext_keycode = 0; 183 ext_keycode = 0;
174 break; 184 break;
175 } 185 }
@@ -180,10 +190,13 @@ static int adb_kbd_poll(ADBDevice *d, uint8_t *obuf) @@ -180,10 +190,13 @@ static int adb_kbd_poll(ADBDevice *d, uint8_t *obuf)
180 static int adb_kbd_request(ADBDevice *d, uint8_t *obuf, 190 static int adb_kbd_request(ADBDevice *d, uint8_t *obuf,
181 const uint8_t *buf, int len) 191 const uint8_t *buf, int len)
182 { 192 {
  193 + KBDState *s = d->opaque;
183 int cmd, reg, olen; 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 cmd = buf[0] & 0xc; 202 cmd = buf[0] & 0xc;
@@ -214,6 +227,9 @@ static int adb_kbd_request(ADBDevice *d, uint8_t *obuf, @@ -214,6 +227,9 @@ static int adb_kbd_request(ADBDevice *d, uint8_t *obuf,
214 break; 227 break;
215 case ADB_READREG: 228 case ADB_READREG:
216 switch(reg) { 229 switch(reg) {
  230 + case 0:
  231 + olen = adb_kbd_poll(d, obuf);
  232 + break;
217 case 1: 233 case 1:
218 break; 234 break;
219 case 2: 235 case 2:
@@ -237,7 +253,7 @@ void adb_kbd_init(ADBBusState *bus) @@ -237,7 +253,7 @@ void adb_kbd_init(ADBBusState *bus)
237 ADBDevice *d; 253 ADBDevice *d;
238 KBDState *s; 254 KBDState *s;
239 s = qemu_mallocz(sizeof(KBDState)); 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 d->handler = 1; 257 d->handler = 1;
242 qemu_add_kbd_event_handler(adb_kbd_put_keycode, d); 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,24 +307,29 @@ static int adb_mouse_poll(ADBDevice *d, uint8_t *obuf)
291 dx &= 0x7f; 307 dx &= 0x7f;
292 dy &= 0x7f; 308 dy &= 0x7f;
293 309
294 - if (s->buttons_state & MOUSE_EVENT_LBUTTON) 310 + if (!(s->buttons_state & MOUSE_EVENT_LBUTTON))
295 dy |= 0x80; 311 dy |= 0x80;
296 - if (s->buttons_state & MOUSE_EVENT_RBUTTON) 312 + if (!(s->buttons_state & MOUSE_EVENT_RBUTTON))
297 dx |= 0x80; 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 static int adb_mouse_request(ADBDevice *d, uint8_t *obuf, 320 static int adb_mouse_request(ADBDevice *d, uint8_t *obuf,
306 const uint8_t *buf, int len) 321 const uint8_t *buf, int len)
307 { 322 {
  323 + MouseState *s = d->opaque;
308 int cmd, reg, olen; 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 cmd = buf[0] & 0xc; 335 cmd = buf[0] & 0xc;
@@ -337,6 +358,9 @@ static int adb_mouse_request(ADBDevice *d, uint8_t *obuf, @@ -337,6 +358,9 @@ static int adb_mouse_request(ADBDevice *d, uint8_t *obuf,
337 break; 358 break;
338 case ADB_READREG: 359 case ADB_READREG:
339 switch(reg) { 360 switch(reg) {
  361 + case 0:
  362 + olen = adb_mouse_poll(d, obuf);
  363 + break;
340 case 1: 364 case 1:
341 break; 365 break;
342 case 3: 366 case 3:
@@ -356,7 +380,7 @@ void adb_mouse_init(ADBBusState *bus) @@ -356,7 +380,7 @@ void adb_mouse_init(ADBBusState *bus)
356 MouseState *s; 380 MouseState *s;
357 381
358 s = qemu_mallocz(sizeof(MouseState)); 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 d->handler = 2; 384 d->handler = 2;
361 qemu_add_mouse_event_handler(adb_mouse_event, d); 385 qemu_add_mouse_event_handler(adb_mouse_event, d);
362 } 386 }