Page 1 of 1
enable mouse interrupt
Posted: Sat Mar 08, 2008 12:22 pm
by hmachine
My english is bad so ...
I'm enable this stuff :
1:mouse interrapt writing to status register at 0x64
2:mouse interface -||-
3:mouse reporting
Problem is: My handler is never called!
Maybe must enable irq 2, if so how i to do that?
I have keyboard handler, and that works fine.
I'm programming os in real mode.
Thanx
Posted: Sat Mar 08, 2008 1:12 pm
by lukem95
Code: Select all
/* CakeOS */
#include <system.h>
//Mouse Driver
//Some code based on code by SANiK
volatile unsigned char mouse_cycle=0;
volatile char mouse_byte[3];
volatile int mouse_x=0;
volatile unsigned char mouse_y=0;
static int dx, dy;
static char cursor[8] = {0xf0, 0xe0, 0xe0, 0x90, 0x8, 0x0, 0x0, 0x0};
//Static functions prototypes
static void mouse_wait(unsigned char a_type);
static unsigned char mouse_read();
static void mouse_write(unsigned char a_write);
extern int graphical_mode;
extern int g_wd, g_ht;
//Mouse functions
static void mouse_handler(registers_t regs)
{
if(!graphical_mode)
return;
switch(mouse_cycle)
{
case 0:
mouse_byte[0]=inb(0x60);
mouse_cycle++;
break;
case 1:
mouse_byte[1]=inb(0x60);
mouse_cycle++;
break;
case 2:
mouse_byte[2]=inb(0x60);
//mouse_x=mouse_byte[1];
//mouse_y=mouse_byte[2];
mouse_cycle=0;
dx = (mouse_byte[0] & 0x10) ? mouse_byte[1] - 256 : mouse_byte[1];
dy = (mouse_byte[0] & 0x20) ? -(mouse_byte[2] - 256) : -mouse_byte[2];
if (dx > 5 || dx < -5)
dx *= 4;
if (dy > 5 || dy < -5)
dy *= 4;
mouse_x += dx;
mouse_y += dy;
if (mouse_x > g_wd) mouse_x = g_wd;
if (mouse_x < 1) mouse_x = 1;
if (mouse_y > g_ht) mouse_y = g_ht;
if (mouse_y < 1) mouse_y = 1;
break;
}
int i, l;
int j = mouse_x;
int h = mouse_y;
int c;
//Print mouse - TODO: mouse
refresh_screen();
for (l = 0; l < 8; l++)
{
for (i = 8; i > 0; i--)
{
if ((cursor[l] & (1<<i)))
c = 9;
else
c = g_read_pixel(j, h); // Don't overwrite background
g_put_pixel(j++, h, c);
}
h++;
j = mouse_x;
}
}
static void mouse_wait(unsigned char a_type)
{
unsigned int _time_out=100000;
if(a_type==0)
{
while(_time_out--) //Data
{
if((inb(0x64) & 1)==1)
{
return;
}
}
return;
}
else
{
while(_time_out--) //Signal
{
if((inb(0x64) & 2)==0)
{
return;
}
}
return;
}
}
static void mouse_write(unsigned char a_write)
{
//Wait to be able to send a command
mouse_wait(1);
//Tell the mouse we are sending a command
outb(0x64, 0xD4);
//Wait for the final part
mouse_wait(1);
//Finally write
outb(0x60, a_write);
}
static unsigned char mouse_read()
{
//Get's response from mouse
mouse_wait(0);
return inb(0x60);
}
void init_ps2_mouse()
{
unsigned char _status;
//Enable the auxiliary mouse device
mouse_wait(1);
outb(0x64, 0xA8);
//Enable the interrupts
mouse_wait(1);
outb(0x64, 0x20);
mouse_wait(0);
_status=(inb(0x60) | 2);
mouse_wait(1);
outb(0x64, 0x60);
mouse_wait(1);
outb(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
register_interrupt_handler(IRQ12, &mouse_handler);
}
int detect_ps2_mouse()
{
unsigned char tmp = mouse_read();
if(tmp != 0xFA)
return 0; //No mouse
else
return 1; //Mouse there
}
This is my ps/2 mouse code. It works fine for me, hope it helps you
Enable mouse
Posted: Sat Mar 08, 2008 2:12 pm
by hmachine
Thanx.I wrote some code in asm for my mouse handler:
install_int0x12:
cli
push es
xor ax,ax
mov es,ax
mov [es:0x12*4],m_hn
mov [es:0x12*4+2],cs
pop es
sti
;m_hn is address of handler label
Is this code ok?
Re: Enable mouse
Posted: Sat Mar 08, 2008 4:11 pm
by Dex
Yes and no try this address:
Code: Select all
install_int0x12:
cli
push ds
xor ax,ax
mov ds,ax
mov WORD[ds:74h*4+0],m_hn
mov WORD[ds:74h*4+2],cs
pop ds
sti
;some more code here
;m_hn is address of handler label
Here is a realmode basic mouse driver, i code for MiniDOS, written in fasm, it may help ?.
It user's direct hardware, no int 33h.
Re: Enable mouse
Posted: Sat Mar 08, 2008 6:34 pm
by hmachine
Dex wrote:
Here is a realmode basic mouse driver, i code for MiniDOS, written in fasm, it may help ?.
It user's direct hardware, no int 33h.
thanx. I'll try that.
My pc is gone to heaven(power supply stop working...),so when I fix that, vmware will be in full speed (my fency toshiba is without fdd).
Sorry 4 bad english...
enable mouse
Posted: Sun Mar 09, 2008 1:31 am
by hmachine
Here is some resources that i use to learn about programming keyboard and mouse:
http://www.computer-engineering.org/ps2keyboard/
On this page you can find scan code sets(1,2,3).
http://www.computer-engineering.org/ps2mouse/
This page contain informations about ps/2 mouse and extended mouse(mouse with 5 buttons).
Hope this will help someone.[/url]