I think that if I were to only read one scancode at a time it would still work fine. It's just that there happen to be two ready by the time the interrupt is called (maybe because of bochs), and my code reads both of them. I was having trouble getting my code to work (because of the PIC resetting problem), so I tried to mimic linux and see if that helped. Here's my interrupt code:
Code:
{
unsigned char status = inportb(0x64);
printf("Mouse handler, status = 0x%X", status);
while (status & KBD_STAT_OUT_BUFF_FULL)
{
unsigned char scancode = inportb(0x60);
if (status & KBD_STAT_MOUSE_OUT_BUFF_FULL)
printf(", received scancode 0x%X", scancode);
status = inportb(0x64);
}
printf(", status = 0x%X\n", status);
}
Here's an example output for moving the mouse right one pixel:
Code:
Mouse handler, status = 0x35, received scancode 0x8, received scancode 0x1, status = 0x14
Mouse handler, status = 0x35, received scancode 0x0, status = 0x14
This is because I'm reading the scancodes as long as there is one available, instead of just an if to test if one is available, so I can read more than one if it is available.
If this were run on a computer that only fed one per interrupt, it *should* output something like the following:
Code:
Mouse handler, status = 0x35, received scancode 0x8, status = 0x14
Mouse handler, status = 0x35, received scancode 0x1, status = 0x14
Mouse handler, status = 0x35, received scancode 0x0, status = 0x14
So this way, it should work if there is only one, or even if all threee are available per interrupt (btw, i modified my code with just an if instead of a while, and it DID read just one scancode per interrupt correctly)
Also, this code will be merged with the keyboard interrupt handler, and if the mouse outbuffer full flag is set the scancode will be sent to the mouse queue, otherwise it will be sent to the keyboard queue, that is why the check for mouse output buffer full is inside the while loop for the keyboard buffer being full.
- Brandon