[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] ps2 mouse cleanups/fixes
From: |
Herbert Poetzl |
Subject: |
[Qemu-devel] ps2 mouse cleanups/fixes |
Date: |
Sat, 27 May 2006 21:18:00 +0200 |
User-agent: |
Mutt/1.5.6i |
Hi Folks!
here is a cleanup/fix to the ps2 mouse emulation done
by qemu: according to the ps2 protocol specification
the dx and dy values are 9 bit 2's complement where
the most significant bit appears as a sign bit in the
first byte. similar for dz but 4 bit 2's complement
here with or without sign extension (IM/Explorer)
best,
Herbert
diff -NurpP qemu-cvs20060522/hw/ps2.c qemu-cvs20060522/hw/ps2.c
--- qemu-cvs20060522/hw/ps2.c 2006-04-12 23:09:07.000000000 +0200
+++ qemu-cvs20060522/hw/ps2.c 2006-05-23 03:30:37.000000000 +0200
@@ -246,44 +247,36 @@ void ps2_keyboard_set_translation(void *
s->translate = mode;
}
+#define min(a,b) ((a<b)?a:b)
+#define max(a,b) ((a>b)?a:b)
+
static void ps2_mouse_send_packet(PS2MouseState *s)
{
unsigned int b;
int dx1, dy1, dz1;
- dx1 = s->mouse_dx;
- dy1 = s->mouse_dy;
- dz1 = s->mouse_dz;
- /* XXX: increase range to 8 bits ? */
- if (dx1 > 127)
- dx1 = 127;
- else if (dx1 < -127)
- dx1 = -127;
- if (dy1 > 127)
- dy1 = 127;
- else if (dy1 < -127)
- dy1 = -127;
- b = 0x08 | ((dx1 < 0) << 4) | ((dy1 < 0) << 5) | (s->mouse_buttons & 0x07);
+ dx1 = min(max(s->mouse_dx,-256),255);
+ dy1 = min(max(s->mouse_dy,-256),255);
+
+ b = (s->mouse_buttons & 0x07) | 0x08 |
+ ((dx1 & 0x100) >> 4) | ((dy1 & 0x100) >> 3);
+
ps2_queue(&s->common, b);
ps2_queue(&s->common, dx1 & 0xff);
ps2_queue(&s->common, dy1 & 0xff);
- /* extra byte for IMPS/2 or IMEX */
+
switch(s->mouse_type) {
default:
+ dz1 = s->mouse_dz;
break;
- case 3:
- if (dz1 > 127)
- dz1 = 127;
- else if (dz1 < -127)
- dz1 = -127;
+ case 3: /* Intellimouse */
+ dz1 = min(max(s->mouse_dz,-8),7);
ps2_queue(&s->common, dz1 & 0xff);
break;
- case 4:
- if (dz1 > 7)
- dz1 = 7;
- else if (dz1 < -7)
- dz1 = -7;
- b = (dz1 & 0x0f) | ((s->mouse_buttons & 0x18) << 1);
+ case 4: /* Intellimouse Explorer */
+ dz1 = min(max(s->mouse_dz,-8),7);
+ b = (dz1 & 0x08f) |
+ ((s->mouse_buttons & 0x18) << 1);
ps2_queue(&s->common, b);
break;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Qemu-devel] ps2 mouse cleanups/fixes,
Herbert Poetzl <=