Mouse Port

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
Philip
Member
Member
Posts: 59
Joined: Thu Mar 06, 2008 11:37 pm
Location: Singapore

Mouse Port

Post by Philip »

anybody has information about mouse port to use instructions like in al,mouseport etc. ? i tried to search google but could not find any :?
eddyb

Post by eddyb »

Code: Select all

#include <system.h>
//Mouse.inc by SANiK
//License: Use as you wish, except to cause damage
char mouse_cycle=0;     //unsigned char
signed char mouse_byte[3], mouse_ex[3];    //signed char
signed char mouse_x=0;         //signed char
signed char mouse_y=0;         //signed char
int mouse_but_1=0;
int mouse_but_2=0;
int mm_n[3]={0,0,0,};


//Mouse functions
void mouse_handler(struct iregs *a_r) //struct regs *a_r (not used but just there)
{
  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_but_1 = (mouse_byte[0] % 2);
	  mouse_but_2 = ((mouse_byte[0] % 4) - (mouse_byte[0] % 2)) / 2;
      mouse_cycle=0;
	  mouse_ex[0] = mouse_byte[0];
	  mm_n[0]=1;
	  mouse_ex[1] = mouse_byte[1];
	  mm_n[1]=1;
	  mouse_ex[2] = mouse_byte[2];
	  mm_n[2]=1;
      break;
	  
  }


}


inline void mouse_wait(char a_type) //unsigned char
{
  unsigned int _time_out=100000; //unsigned int
  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(char a_write) //unsigned char
{
  //Wait to be able to send a command
  mouse_wait(1);
  //Tell the mouse we are sending a command
  outportb(0x64, 0xD4);
  //Wait for the final part
  mouse_wait(1);
  //Finally write
  outportb(0x60, a_write);
}

char mouse_read()
{
  //Get's response from mouse
  mouse_wait(0);
  return inportb(0x60);
}

void mouse_install()
{
  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);
}


char get_mouse(int n)
{
	if(mm_n[n]==1)
	{
		mm_n[n]=0;
		return mouse_ex[n];
		
	}
	else
		return 0;
}
this is mine, from a tut;
to use: install mouse (mouse_intall), and when u want, get the data by using get_mouse(data type)

data type is 0 for butt, 1 for x(as movement), and 2 for y(as movement);

NOTE: y is negative, to use it: y = -y;
User avatar
Philip
Member
Member
Posts: 59
Joined: Thu Mar 06, 2008 11:37 pm
Location: Singapore

Post by Philip »

from your code i see the mouse port is 60h and 64h
these are also the ports for keyboard
should they be the same like this? how to distinguish between keyboard and mouse input from port 60h? :?
User avatar
lukem95
Member
Member
Posts: 536
Joined: Fri Aug 03, 2007 6:03 am
Location: Cambridge, UK

Post by lukem95 »

the mouse and keyboard use the same ports. its the commands that are different
~ Lukem95 [ Cake ]
Release: 0.08b
Image
User avatar
Philip
Member
Member
Posts: 59
Joined: Thu Mar 06, 2008 11:37 pm
Location: Singapore

Post by Philip »

i already google for the term "port 60h" but only got results about keyboard but mouse. anybody has document about accessing mouse through port 60h please?
User avatar
lukem95
Member
Member
Posts: 536
Joined: Fri Aug 03, 2007 6:03 am
Location: Cambridge, UK

Post by lukem95 »

look for the ps/2 keyboard spec. it has mouse stuff there.

also osdever.net has lots of stuff on keyboard and mouse.

please try looking harder.
~ Lukem95 [ Cake ]
Release: 0.08b
Image
hmachine
Posts: 9
Joined: Sat Mar 08, 2008 11:47 am

mouse port

Post by hmachine »

Search osdev for "enable mouse" and you will see my post.
On that page I'm post 2 links for mouse and keyboard.
-----------------------------
Kosovo is Serbia!!!
User avatar
inflater
Member
Member
Posts: 1309
Joined: Thu Sep 28, 2006 10:32 am
Location: Slovakia
Contact:

Post by inflater »

hmachine wrote:Kosovo is Serbia!!!
The resistance is coming :shock:
-sorry for OT :oops:
My web site: http://inflater.wz.cz (Slovak)
Derrick operating system: http://derrick.xf.cz (Slovak and English :P)
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post by Dex »

If you see here:

Code: Select all

 //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); 
 } 
 
You will see 0xD4 ; this command is for mouse
And in this thread you will find a link to my realmode mouse driver, if you want asm example, plus links to ps2 info.
http://www.osdev.org/phpBB2/viewtopic.php?t=16448
User avatar
Philip
Member
Member
Posts: 59
Joined: Thu Mar 06, 2008 11:37 pm
Location: Singapore

Post by Philip »

your posts are very valuable
thanks a lot :)
Post Reply