Mouse driver problems...
Posted: Mon Aug 03, 2009 7:37 am
Hello,
I'm coding a mouse driver now.
Here's my code:
Sometimes Y is empty. Why? (Running it in QEMU).
Message that I pressed a button appears sometimes, but not when I'm really pressing a button.
P.S Mouse init code:
Help, please!
--Andrew
I'm coding a mouse driver now.
Here's my code:
Code: Select all
unsigned char mouse_cycle=0; //unsigned char
char mouse_bytes[3]; //signed char
char mouse_x=0; //signed char
char mouse_y=0; //signed char
char str[32]; // for IntToChar
//Mouse functions
void mouse_handler() //struct regs *a_r (not used but just there) (let's try without them, huh?)
{
switch(mouse_cycle)
{
case 0:
mouse_bytes[0]=inportb(0x60);
mouse_cycle++;
break;
case 1:
mouse_bytes[1]=inportb(0x60);
mouse_cycle++;
break;
case 2:
mouse_bytes[2]=inportb(0x60);
mouse_x=mouse_bytes[1];
mouse_y=mouse_bytes[2];
puts ("X: ");
IntToChar(mouse_x); // converts int to char[], result in char str[32]
puts (str);
puts (" Y: ");
IntToChar(mouse_y);
puts (str);
puts ("\n");
if (mouse_bytes[0] & 0x4)
puts("Middle button is pressed!\n");
if (mouse_bytes[0] & 0x2)
puts("Right button is pressed!\n");
if (mouse_bytes[0] & 0x1)
puts("Left button is pressed!\n");
mouse_cycle=0;
break;
}
}
Message that I pressed a button appears sometimes, but not when I'm really pressing a button.
P.S Mouse init code:
Code: Select all
void mouse_install()
{
unsigned char _status; //unsigned char
//Enable the auxiliary mouse device
mouse_wait(1);
outportb(0x64, 0xA8);
//Enable the interrupts
mouse_wait(1);
outportb(0x64, 0x20);
mouse_wait(0);
_status=(inportb(0x60) | 2);
mouse_wait(1);
outportb(0x64, 0x60);
mouse_wait(1);
outportb(0x60, _status);
//Tell the mouse to use default settings
mouse_write(0xF6);
mouse_read(); //Acknowledge
//Enable the mouse
mouse_write(0xF4);
mouse_read(); //Acknowledge
//Setup the mouse handler
irq_install_handler(12, mouse_handler);
}
--Andrew