wyoos icon indicating copy to clipboard operation
wyoos copied to clipboard

OS Part 7 : Mouse observations

Open mpetch opened this issue 8 years ago • 0 comments

I like your idea of the video series, keep up the good work! A couple of observations regarding the mouse. The mouse X (buffer[1]) and Y (buffer[2]) values are actually part of a 9-bit 2s complement value. Bit 8 (top bit) for X is actually in buffer[0] at bit 4, and Bit 8 (top bit) for Y is in buffer[0] at bit 5. These bits should be taken into account or you could be interpreting some values from the mouse incorrectly. Something like this should work:

/* Bit 4 of buffer[0] is X's sign bit
   Bit 5 of buffer[0] is Y's sign bit */
x += buffer[1] - (0x100 & (buffer[0] << (8-4)));
y -= buffer[2] - (0x100 & (buffer[0] << (8-5)));`

Of course with code as I suggest buffer would be an array of 3 uint8_t, and x and y would have to be a signed integer big enough to hold the values you need (int16_t or int32_t).

mpetch avatar Sep 03 '16 22:09 mpetch