Mouse Driver
Posted: Wed Mar 16, 2011 10:54 am
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 :
-----------------
Thank you in advance
------------------------
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
------------------------