[comp.sys.ibm.pc] Serial Mouse Data Format

lharris@gpu.utcs.toronto.edu (Leonard Harris) (06/05/88)

Does anyone know the details of the format of serial data coming
from a serial mouse such as the Microsoft mouse.  I'd like to be
able to control it directly from a program without having to
go through their drivers.
Any info would be most welcome
/leonard

kevin@calvin.EE.CORNELL.EDU (Kevin Tubbs) (06/06/88)

In article <1988Jun5.120653.7373@gpu.utcs.toronto.edu> lharris@gpu.utcs.toronto.edu (Leonard Harris) writes:
>Does anyone know the details of the format of serial data coming
>from a serial mouse such as the Microsoft mouse.  I'd like to be
>able to control it directly from a program without having to
>go through their drivers.

I'll post this since many others might benefit, and it doesn't take much space.
By the way, the $49.95 serial mouse from Radio Shack is a Microsoft compatible.

Three bytes are returned whenever the mouse is moved or the position of a   
switch changes.  They are as follows:

1st byte:  1  L   R   X7  X6  Y7  Y6
2nd byte:  0  X5  X4  X3  X2  X1  X0
3rd byte:  0  Y5  Y4  Y3  Y2  Y1  Y0

L = 1 if left button is pressed, R = 1 if right button is pressed.
X and Y are 8 bit signed integers.  Left movement is -X, right movement is
+X, Up movement is -Y, down movement is +Y.  The magnitude of |X| or |Y|
is the number of "mickeys" (no kidding!) that the mouse has moved since the
last report.  Mouse drivers typically divide the mickeys by some constant
to get the desired mouse sesnsitivity.

The mouse transmits these reports at 1200 baud, 7-2-N.  The above format is 
actually easy to figure out if you just look at the raw mouse output while
you move it around, which is how we did it.
-- 
Kevin Tubbs, 5152 Upson, Cornell University, Ithaca NY, 14853  (607) 255-8703
kevin@calvin.ee.cornell.edu  {uunet,rochester}!cornell!calvin!kevin

kevin@calvin.EE.CORNELL.EDU (Kevin Tubbs) (06/07/88)

Well, I blew it.  The mouse format for the first byte is:
1st byte:  1  L   R   Y7  Y6  X7  X6     <---- correct

instead of :
>1st byte:  1  L   R   X7  X6  Y7  Y6    <---- WRONG 

and the remaining bytes are correct:

>2nd byte:  0  X5  X4  X3  X2  X1  X0
>3rd byte:  0  Y5  Y4  Y3  Y2  Y1  Y0

Sorry about that.
-- 
Kevin Tubbs, 5152 Upson, Cornell University, Ithaca NY, 14853  (607) 255-8703
kevin@calvin.ee.cornell.edu  {uunet,rochester}!cornell!calvin!kevin

dale@wucs1.UUCP (Dale Frye) (06/07/88)

In article <1988Jun5.120653.7373@gpu.utcs.toronto.edu>, lharris@gpu.utcs.toronto.edu (Leonard Harris) writes:
> 
> Does anyone know the details of the format of serial data coming
> from a serial mouse such as the Microsoft mouse.  I'd like to be
> able to control it directly from a program without having to
> go through their drivers.
> Any info would be most welcome

I working from memory so I might miss a detail or two.

1200 baud
7 data bits
no parity
1 stop bit

Each time you move the mouse or press or release a button 3 bytes are sent.
These three bytes are literally seperated by 1 stop bit so make certain your
software can empty the buffer (i.e. read the data) of the UART before the
next charater is recieved. Suggest using interrupts.

The three bytes are:

1st byte:  sign bits for x and y directions
	   bits for status of buttons
	   the high order bit is always set to 1 (this is a good way to
		  check for this byte as the next two bytes always have
		  this bit set to 0)
2nd byte:  delta x - change in x position -- 6 bits only
	     I think this is 2's comp. for neg. numbers. (I don't remember) 
	     The sign bit is in the first byte.
3nd byte:   delta y -- same as above


I did this a few years ago so please verify this info.  I called Microsoft
for this info. They said it was against corp. policy to release it. One hour
later using debug and a small BASIC program, I came up with thiese results.

Dale Frye @ Washington University in St. Louis

bright@Data-IO.COM (Walter Bright) (06/10/88)

In article <1988Jun5.120653.7373@gpu.utcs.toronto.edu> lharris@gpu.utcs.toronto.edu (Leonard Harris) writes:
>Does anyone know the details of the format of serial data coming
>from a serial mouse such as the Microsoft mouse.

The Microsoft serial mouse sends 3 byte sequences as follows:

Bit	6	5	4	3	2	1	0
-----------------------------------------------------------
Byte 1	1	L	R	Y7	Y6	X7	X6
Byte 2	0	X5	X4	X3	X2	X1	X0
Byte 3	0	Y5	Y4	Y3	Y2	Y1	Y0

The L and R are the mouse button states, 1 means down.
The X and Y values are signed, and represent the number of mickeys travelled.
The 1 in bit 6 is so you can recognize the start of the sequence.

One interesting side effect is that there is no room for a bit for
a middle button (3 button mice use a different format).

This info is gleaned from the Logitech tech manual. I have the Microsoft
Mouse programmer's manual, but there is no mention of this in it. There is
also no information about the differences between the bus mouse and the
serial mouse. I was rather annoyed at this after spending the extra bucks for
the technical manual.