mouse.htm


//Mouse.c //Defines #define MOUSE_WAIT_DATA 0 //Waits for the mouse to respond #define MOUSE_WAIT_SIGNAL 1 //Waits for the mouse to enter a "receive/wait for signal" state //Globals byte mouse_cycle=0; //Byte sbyte mouse_byte[3]; //Signed Byte sbyte mouse_x=0; //Signed Byte sbyte mouse_y=0; //Signed Byte //Mouse functions void mouse_handler(Regs *a_r) { switch(mouse_cycle) { case 0: mouse_byte[0]=inportb(0x60); mouse_cycle++; break; case 1: mouse_byte[1]=inportb(0x60); mouse_cycle++; break; case 2: mouse_byte[2]=inportb(0x60); mouse_x=mouse_byte[1]; mouse_y=mouse_byte[2]; mouse_cycle=0; break; } } inline void mouse_wait(byte a_type) { dword time_out=100000; if(a_type==0) { while(time_out--) //Data { if((inportb(0x64) & 1)==1) { return; } } return; } else { while(time_out--) //Signal { if((inportb(0x64) & 2)==0) { return; } } return; } } inline void mouse_write(byte a_write) { //Wait to be able to send a command mouse_wait(MOUSE_WAIT_SIGNAL); //Tell the mouse we are sending a command outportb(0x64, 0xD4); //Wait for the final part mouse_wait(MOUSE_WAIT_SIGNAL); //Finally write outportb(0x60, a_write); } byte mouse_read() { //Get's response from mouse mouse_wait(MOUSE_WAIT_DATA); return inportb(0x60); } void mouse_install() { byte status; //Enable the auxiliary mouse device mouse_wait(MOUSE_WAIT_SIGNAL); outportb(0x64, 0xA8); //Enable the interrupts mouse_wait(MOUSE_WAIT_SIGNAL); outportb(0x64, 0x20); mouse_wait(MOUSE_WAIT_DATA); status=(inportb(0x60) | 2); mouse_wait(MOUSE_WAIT_SIGNAL); outportb(0x64, 0x60); mouse_wait(MOUSE_WAIT_SIGNAL); outportb(0x60, status); //Tell the mouse to use default settings mouse_write(0xF6); mouse_read(); //Mouse returns an Acknowledge signal //Enable the mouse mouse_write(0xF4); mouse_read(); //Mouse returns an Acknowledge signal //Setup the mouse handler irq_installHandler(12, mouse_handler); }

Rate article