Mouse range

For anything related to IO (joypad, serial, XE...)

Moderator: BigEvilCorporation

Post Reply
Sik
Very interested
Posts: 939
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Mouse range

Post by Sik » Mon Jan 09, 2017 10:31 am

viewtopic.php?f=23&t=2126&p=26956#p26914
The X/Y overflow flags are supposed to be set if the mouse is moved over a distance greater than can be measured. I can't get
them to become set, maybe the mouse supports a fairly wide range of movement.
Stupid question, what's the range actually reported by delta values in the mouse? We were doing some tests with PC mouses, and it turns out they like to clamp the range to -127 to +127 (effectively rendering the overflow flags unused, as the delta never manages to become large enough). It would be nice to know what the Sega Mouse and the Mega Mouse do, maybe their behavior happens to be similar.

Also I imagine a ball-based mouse is going to have a harder time to register a sudden motion like these tests would be doing (due to inertia).
Sik is pronounced as "seek", not as "sick".

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Re: Mouse range

Post by Chilly Willy » Wed Sep 05, 2018 10:13 pm

If overflow is ever set, you ignore x or y (depending on which overflowed), and use +/-256. The sign bit is separate from x and y, so they're actually 9-bit ranges, so -256 to +255.

Here's how I process the mouse packet in Wolf32X

Code: Select all

                mousebuttons = (val >> 16) & 15;
                mx = (val >> 8) & 0xFF;
                // check sign
                if (val & 0x00100000)
                    mx |= 0xFFFFFF00;
                // check overflow
                if (val & 0x00400000)
                    mx = (val & 0x00100000) ? -256 : 256;
                mousexaxis += mx;
                my = val & 0xFF;
                // check sign
                if (val & 0x00200000)
                    my |= 0xFFFFFF00;
                // check overflow
                if (val & 0x00800000)
                    my = (val & 0x00200000) ? -256 : 256;
                mouseyaxis += my;

Post Reply