PS2 mouse IRQ
- Thunder
PS2 mouse IRQ
Post by Thunder »
I'm trying to manage how IRQ12 works, is that the same like IRQ1 or IRQ0. When I'm trying to put code (in IRQ12), that puts pixel at coordinate, but when I press button or move mouse, nothing hapens.
Thanks for help.
- Tim
Re:PS2 mouse IRQ
Post by Tim »
- Pype.Clicker
- Member
Member - Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:PS2 mouse IRQ
Post by Pype.Clicker »
1. the PS2 mouse links at Bona Fide are especially hard to follow: it took me about 2 weeks to get something else than "server did not respond" ... maybe it's just my ISP.
2. those links talk about mouse protocols (between the mouse and the controller), but very little info about programming the PS/2 (or serial :-& -- but i guess this one can be reduced to programming the COMx UART once you know the protocol about bytes etc.).
So if one of you want to make a tutorial about mouse programming and post it at Bona Fide (i won't do it myself: i haven't programmed the mouse yet :p)
So far, i collected a few info, including ISR code from Tim Robinson and PS2 mouse initialisation sequence.
The SearchBot also found several links posted by frank one year ago.
Also remind that prior to receive IRQ12, you must enable this interrupt at the slave PIC (will be #4, iirc) and the cascade interrupt at master PIC (#2).
You must also send a "end of interrupt" to both PICs at the end of your ISR (i.e. "mov al, 20h; out 20h,al; out 0a0h, al").
Note that despites the "mouse packet" is multi-byte, you can only read bytes one by one at the i8042. Thus, it will take 3 mouse interrupts before you actually can decode the message the mouse sent.
- Pype.Clicker
- Member
Member - Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:PS2 mouse IRQ
Post by Pype.Clicker »
Code: Select all
/* These strings nicked from gpm (I_imps2): I don't know how they work... */
static uint8_t s1[] = { 0xF3, 0xC8, 0xF3, 0x64, 0xF3, 0x50, 0 };
static uint8_t s2[] = { 0xF6, 0xE6, 0xF4, 0xF3, 0x64, 0xE8, 0x03, 0 };
after having set the sampling rate for the 3rd axis (wheel), the Micros0ft Intellimouse enables extension (4th byte for wheel).
- Thunder
Re:PS2 mouse IRQ
Post by Thunder »
Now in www.stormos.ten.lt Storm OS PS2 mouse works.
- Thunder
Re:PS2 mouse IRQ
Post by Thunder »
- Brandon
Re:PS2 mouse IRQ
Post by Brandon »
Thanks!
- Thunder
Re:PS2 mouse IRQ
Post by Thunder »
Before taking byte try to check first 2 lower bytes from 0x64, and if ok THEN read byte from 0x60.
For me is the problem that on VMware mouse works fine, but on real PC seems to respond to moves but on screen thust puts the same values x and y ???
Maybe we could solve this problem both ;)
- Tim
Re:PS2 mouse IRQ
Post by Tim »
- Brandon
Re:PS2 mouse IRQ
Post by Brandon »
The first one I get is has bit 4 set (like i've read should always be set in the status byte) plus another bit depending on which way I'm moving the mouse (or if i'm clicking one of the mouse buttons), so i'm guessing this is the correct first byte that i've read about that describes the mouse buttons and direction and any overflow that may have happened.
And the second byte I get has a number that's around 1 or 2 usually, but higher if I move the mouse quickly. However, this number is only non-zero if i'm moving the mouse horizontally. So this seems to be the X translation information.
So the only thing I'm missing is the Y translation information, and that never comes across. I have the interrupt routine display what it reads every time it is called, and it is only called once per mouse move, and it only can read two bytes of information. If I queued the bytes and translated in groups of three, then I would be using the status byte of one movement as the status, the X translation of that same movement as the X translation, and then the status byte of the next movement as the Y translation. This doesn't seem right?
I keep checking the mouse buffer full flag and output buffer full flag between reading scancodes, and there are definitely two valid scancodes for me to read per movement, but there is never a third one, and the first one of the next interrupt is definitely the status byte, so I have no idea what to do.
Thanks for any help anyone can offer!
- Brandon
P.S. I'm using bochs for testing, i dont know if that makes a difference.
- Pype.Clicker
- Member
Member - Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:PS2 mouse IRQ
Post by Pype.Clicker »
btw, what version of BOCHS is it ? did you made sure it has complete support of PS/2 mouse ?
- Brandon
Re:PS2 mouse IRQ
Post by Brandon »
Thanks for all your help.
- Brandon
- Thunder
Re:PS2 mouse IRQ
Post by Thunder »
I'm using VMware workstation 4.0, I get per ONE interrupt all 3 bytesa and it works fine, but when I'm restarting computer and starting my OS it seems not to working... ???
Then how it really is?
Bye
- Tim
Re:PS2 mouse IRQ
Post by Tim »
Code: Select all
bool ps2Isr(device_t *dev, uint8_t irq)
{
if ((in(KEYB_CTRL) & 0x01) != 0)
{
Ps2Mouse *mouse;
mouse = (Ps2Mouse*) dev;
mouse->data[mouse->bytes++] = in(KEYB_PORT);
if (mouse->bytes >= 3 + mouse->has_wheel)
{
ps2StartIo(mouse);
mouse->bytes = 0;
}
return true;
}
return false;
}
- Brandon
Re:PS2 mouse IRQ
Post by Brandon »
Code: Select all
{
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);
}
Code: Select all
Mouse handler, status = 0x35, received scancode 0x8, received scancode 0x1, status = 0x14
Mouse handler, status = 0x35, received scancode 0x0, status = 0x14
If this were run on a computer that only fed one per interrupt, it *should* output something like the following:
Code: Select all
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
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