From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Fk4IY-0001N2-4m for qemu-devel@nongnu.org; Sat, 27 May 2006 15:18:06 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Fk4IV-0001KX-Bj for qemu-devel@nongnu.org; Sat, 27 May 2006 15:18:05 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Fk4IV-0001KU-6M for qemu-devel@nongnu.org; Sat, 27 May 2006 15:18:03 -0400 Received: from [212.16.62.50] (helo=mail.13thfloor.at) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1Fk4Ng-00058S-8E for qemu-devel@nongnu.org; Sat, 27 May 2006 15:23:24 -0400 Date: Sat, 27 May 2006 21:18:00 +0200 From: Herbert Poetzl Message-ID: <20060527191759.GA6834@MAIL.13thfloor.at> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Subject: [Qemu-devel] ps2 mouse cleanups/fixes Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Qemu mailing list 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) ((ab)?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; }