Page 1 of 1

Mouse Driver

Posted: Wed Mar 16, 2011 10:54 am
by melgmry0101b
Hi everyone,
I was writing a mouse driver
But when i went to try it , i found that i can't use keyboard :|
That is my code :

Code: Select all

#include <string.h>
#include <ctype.h>
#include <hal.h>
int x = 0, y = 0;
static volatile int button[3] = {0, 0, 0};
unsigned char data[3];
void left_button_down(int x, int y)
{
}

void left_button_up(int x, int y)
{
}

void right_button_down(int x, int y)
{

}

void right_button_up(int x, int y)
{
}

void middle_button_down(int x, int y)
{
}

void middle_button_up(int x, int y)
{
}

void _cdecl ps2_mouse()
{
    data[0] = inportb(0x60);
    data[1] = inportb(0x60);
    data[2] = inportb(0x60);
    if ((data[0] & 0x01) != button[0])
    {
        button[0] ^= 1;
        if (button[0]) left_button_down(x, y);
        else left_button_up(x, y);
    }
    if ((data[0] & 0x04) != button[1])
    {
        button[1] ^= 1;
        if (button[1]) middle_button_down(x, y);
        else middle_button_up(x, y);
    }
    if ((data[0] & 0x02) != button[2])
    {
        button[2] ^= 1;
        if (button[2]) right_button_down(x, y);
        else right_button_up(x, y);
    }
    if (data[0] & 0x10)
        x += (int)((256 - data[1]) * -1);
    else
        x += (int)data[1];
    if (data[0] & 0x20)
        y += (int) (256 - data[2]);
    else
        y += (int)(data[2] * -1);
    if (y > 184) y = 184;
    else if (y < 0) y = 0;
    if (x > 311) x = 311;
    else if (x < 0) x = 0;
}

void init_ps2_mouse()
{
    int x;
    unsigned char data_read;
    for(x = 0; x < 5; x++)
    {
        outportb(0x64,0xA7);                   
        outportb(0x64,0xA8);
        outportb(0x64,0xD4);
        outportb(0x60,0xF5);
        data_read = inportb(0x60);          
        if (data_read != 0xFA) continue;    
        outportb(0x64,0xD4);
        outportb(0x60,0xFF);
        data_read = inportb(0x60);             
        if (data_read != 0xFA) continue;    
        data_read = inportb(0x60) ;           
        if (data_read != 0xAA) continue;    
 
        outportb(0x64,0xD4);
        outportb(0x60,0xE6);
        data_read = inportb(0x60) ;          
        if (data_read != 0xFA) continue;   
        outportb(0x64,0x20);                   
        data_read = inportb(0x60)  ;          
        data_read |= 0x02;                  
        outportb(0x64,0x60);                    
        outportb(0x60,data_read);           
        outportb(0x64,0xD4);                
        outportb(0x60,0xF4);
        data_read = inportb(0x60) ;           
        if (data_read != 0xFA) continue;    
        break;
    }
	setvect (12, (void (__cdecl &)(void))ps2_mouse);
}

-----------------
Thank you in advance
------------------------

Re: Mouse Driver

Posted: Wed Mar 16, 2011 2:18 pm
by DLBuunk
Ehm, if i read your story correctly, once you tried using the mouse, the keyboard stopped working? How? And the mouse, does it "work" ?

A reasonable debugging step might be checking if the keyboard killing code is in the setup part or in the interrupt handler. For one thing, are you sure it completes the init loop? Have you dumped the contents of the KBC registers? What do they say?

Oh, and one more thing, never forget the mantra "Comment your code, comment your code", this, and properly describing the problem makes it way more likely to get a functional answer from the people at this forum, or for the same sake, anywhere.

Re: Mouse Driver

Posted: Wed Mar 16, 2011 7:28 pm
by Chandra
The only thing I would like to know is, does you mouse code work properly? I mean, do you recieve proper packets from the mouse?
Before worrying about the keyboard, I think it would help to know if the mouse code works as intended. Actually, I can figure out some problem in the mouse code itself, so before we continue, lets make things clear.

Re: Mouse Driver

Posted: Thu Mar 17, 2011 6:44 am
by jrepan
I think the problem is that when you get IRQ you may read only one byte, not all 3. So you need to do something similar to what is done here: http://forum.osdev.org/viewtopic.php?t=10247

Re: Mouse Driver

Posted: Thu Mar 17, 2011 3:17 pm
by melgmry0101b
Hi ,
i will try again