Commit 715748fa08b35690b15c0557ad1e92cd73c8fbb3
1 parent
21206a10
added mouse protocol (Igor Kovalenko)
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2150 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
1 changed file
with
54 additions
and
15 deletions
hw/slavio_serial.c
| @@ -42,6 +42,13 @@ | @@ -42,6 +42,13 @@ | ||
| 42 | * | 42 | * |
| 43 | */ | 43 | */ |
| 44 | 44 | ||
| 45 | +/* | ||
| 46 | + * Modifications: | ||
| 47 | + * 2006-Aug-10 Igor Kovalenko : Renamed KBDQueue to SERIOQueue, implemented | ||
| 48 | + * serial mouse queue. | ||
| 49 | + * Implemented serial mouse protocol. | ||
| 50 | + */ | ||
| 51 | + | ||
| 45 | #ifdef DEBUG_SERIAL | 52 | #ifdef DEBUG_SERIAL |
| 46 | #define SER_DPRINTF(fmt, args...) \ | 53 | #define SER_DPRINTF(fmt, args...) \ |
| 47 | do { printf("SER: " fmt , ##args); } while (0) | 54 | do { printf("SER: " fmt , ##args); } while (0) |
| @@ -58,7 +65,7 @@ do { printf("KBD: " fmt , ##args); } while (0) | @@ -58,7 +65,7 @@ do { printf("KBD: " fmt , ##args); } while (0) | ||
| 58 | #endif | 65 | #endif |
| 59 | #ifdef DEBUG_MOUSE | 66 | #ifdef DEBUG_MOUSE |
| 60 | #define MS_DPRINTF(fmt, args...) \ | 67 | #define MS_DPRINTF(fmt, args...) \ |
| 61 | -do { printf("SER: " fmt , ##args); } while (0) | 68 | +do { printf("MSC: " fmt , ##args); } while (0) |
| 62 | #else | 69 | #else |
| 63 | #define MS_DPRINTF(fmt, args...) | 70 | #define MS_DPRINTF(fmt, args...) |
| 64 | #endif | 71 | #endif |
| @@ -71,12 +78,12 @@ typedef enum { | @@ -71,12 +78,12 @@ typedef enum { | ||
| 71 | ser, kbd, mouse, | 78 | ser, kbd, mouse, |
| 72 | } chn_type_t; | 79 | } chn_type_t; |
| 73 | 80 | ||
| 74 | -#define KBD_QUEUE_SIZE 256 | 81 | +#define SERIO_QUEUE_SIZE 256 |
| 75 | 82 | ||
| 76 | typedef struct { | 83 | typedef struct { |
| 77 | - uint8_t data[KBD_QUEUE_SIZE]; | 84 | + uint8_t data[SERIO_QUEUE_SIZE]; |
| 78 | int rptr, wptr, count; | 85 | int rptr, wptr, count; |
| 79 | -} KBDQueue; | 86 | +} SERIOQueue; |
| 80 | 87 | ||
| 81 | typedef struct ChannelState { | 88 | typedef struct ChannelState { |
| 82 | int irq; | 89 | int irq; |
| @@ -86,7 +93,7 @@ typedef struct ChannelState { | @@ -86,7 +93,7 @@ typedef struct ChannelState { | ||
| 86 | chn_type_t type; | 93 | chn_type_t type; |
| 87 | struct ChannelState *otherchn; | 94 | struct ChannelState *otherchn; |
| 88 | uint8_t rx, tx, wregs[16], rregs[16]; | 95 | uint8_t rx, tx, wregs[16], rregs[16]; |
| 89 | - KBDQueue queue; | 96 | + SERIOQueue queue; |
| 90 | CharDriverState *chr; | 97 | CharDriverState *chr; |
| 91 | } ChannelState; | 98 | } ChannelState; |
| 92 | 99 | ||
| @@ -103,13 +110,13 @@ static void serial_receive_byte(ChannelState *s, int ch); | @@ -103,13 +110,13 @@ static void serial_receive_byte(ChannelState *s, int ch); | ||
| 103 | static void put_queue(void *opaque, int b) | 110 | static void put_queue(void *opaque, int b) |
| 104 | { | 111 | { |
| 105 | ChannelState *s = opaque; | 112 | ChannelState *s = opaque; |
| 106 | - KBDQueue *q = &s->queue; | 113 | + SERIOQueue *q = &s->queue; |
| 107 | 114 | ||
| 108 | - KBD_DPRINTF("put: 0x%02x\n", b); | ||
| 109 | - if (q->count >= KBD_QUEUE_SIZE) | 115 | + SER_DPRINTF("put: 0x%02x\n", b); |
| 116 | + if (q->count >= SERIO_QUEUE_SIZE) | ||
| 110 | return; | 117 | return; |
| 111 | q->data[q->wptr] = b; | 118 | q->data[q->wptr] = b; |
| 112 | - if (++q->wptr == KBD_QUEUE_SIZE) | 119 | + if (++q->wptr == SERIO_QUEUE_SIZE) |
| 113 | q->wptr = 0; | 120 | q->wptr = 0; |
| 114 | q->count++; | 121 | q->count++; |
| 115 | serial_receive_byte(s, 0); | 122 | serial_receive_byte(s, 0); |
| @@ -118,14 +125,14 @@ static void put_queue(void *opaque, int b) | @@ -118,14 +125,14 @@ static void put_queue(void *opaque, int b) | ||
| 118 | static uint32_t get_queue(void *opaque) | 125 | static uint32_t get_queue(void *opaque) |
| 119 | { | 126 | { |
| 120 | ChannelState *s = opaque; | 127 | ChannelState *s = opaque; |
| 121 | - KBDQueue *q = &s->queue; | 128 | + SERIOQueue *q = &s->queue; |
| 122 | int val; | 129 | int val; |
| 123 | 130 | ||
| 124 | if (q->count == 0) { | 131 | if (q->count == 0) { |
| 125 | return 0; | 132 | return 0; |
| 126 | } else { | 133 | } else { |
| 127 | val = q->data[q->rptr]; | 134 | val = q->data[q->rptr]; |
| 128 | - if (++q->rptr == KBD_QUEUE_SIZE) | 135 | + if (++q->rptr == SERIO_QUEUE_SIZE) |
| 129 | q->rptr = 0; | 136 | q->rptr = 0; |
| 130 | q->count--; | 137 | q->count--; |
| 131 | } | 138 | } |
| @@ -326,7 +333,7 @@ static uint32_t slavio_serial_mem_readb(void *opaque, target_phys_addr_t addr) | @@ -326,7 +333,7 @@ static uint32_t slavio_serial_mem_readb(void *opaque, target_phys_addr_t addr) | ||
| 326 | case 1: | 333 | case 1: |
| 327 | s->rregs[0] &= ~1; | 334 | s->rregs[0] &= ~1; |
| 328 | clr_rxint(s); | 335 | clr_rxint(s); |
| 329 | - if (s->type == kbd) | 336 | + if (s->type == kbd || s->type == mouse) |
| 330 | ret = get_queue(s); | 337 | ret = get_queue(s); |
| 331 | else | 338 | else |
| 332 | ret = s->rx; | 339 | ret = s->rx; |
| @@ -512,9 +519,41 @@ static void sunmouse_event(void *opaque, | @@ -512,9 +519,41 @@ static void sunmouse_event(void *opaque, | ||
| 512 | ChannelState *s = opaque; | 519 | ChannelState *s = opaque; |
| 513 | int ch; | 520 | int ch; |
| 514 | 521 | ||
| 515 | - // XXX | ||
| 516 | - ch = 0x42; | ||
| 517 | - serial_receive_byte(s, ch); | 522 | + MS_DPRINTF("dx=%d dy=%d buttons=%01x\n", dx, dy, buttons_state); |
| 523 | + | ||
| 524 | + ch = 0x80 | 0x7; /* protocol start byte, no buttons pressed */ | ||
| 525 | + | ||
| 526 | + if (buttons_state & MOUSE_EVENT_LBUTTON) | ||
| 527 | + ch ^= 0x4; | ||
| 528 | + if (buttons_state & MOUSE_EVENT_MBUTTON) | ||
| 529 | + ch ^= 0x2; | ||
| 530 | + if (buttons_state & MOUSE_EVENT_RBUTTON) | ||
| 531 | + ch ^= 0x1; | ||
| 532 | + | ||
| 533 | + put_queue(s, ch); | ||
| 534 | + | ||
| 535 | + ch = dx; | ||
| 536 | + | ||
| 537 | + if (ch > 127) | ||
| 538 | + ch=127; | ||
| 539 | + else if (ch < -127) | ||
| 540 | + ch=-127; | ||
| 541 | + | ||
| 542 | + put_queue(s, ch & 0xff); | ||
| 543 | + | ||
| 544 | + ch = -dy; | ||
| 545 | + | ||
| 546 | + if (ch > 127) | ||
| 547 | + ch=127; | ||
| 548 | + else if (ch < -127) | ||
| 549 | + ch=-127; | ||
| 550 | + | ||
| 551 | + put_queue(s, ch & 0xff); | ||
| 552 | + | ||
| 553 | + // MSC protocol specify two extra motion bytes | ||
| 554 | + | ||
| 555 | + put_queue(s, 0); | ||
| 556 | + put_queue(s, 0); | ||
| 518 | } | 557 | } |
| 519 | 558 | ||
| 520 | void slavio_serial_ms_kbd_init(int base, int irq) | 559 | void slavio_serial_ms_kbd_init(int base, int irq) |