AlgorithMan-de / wyoos

Source codes for the "Write your own Operating System" video-series on YouTube
http://wyoos.org
GNU General Public License v3.0
719 stars 222 forks source link

OS Part 7 : Mouse observations #1

Open mpetch opened 7 years ago

mpetch commented 7 years ago

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).