How to get packets and such for PS/2 mouse

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
earlz

How to get packets and such for PS/2 mouse

Post by earlz »

I have read a tutorial but the only problem is it don't tell how I get the packet data or how to send it a command
blip

Re:How to get packets and such for PS/2 mouse

Post by blip »

You need to enable the IRQ at the PIC (IRQ12 for auxilliary port and IRQ2 for slave PIC) and KBC (bit1 of the command byte, accessed by using commands 20h and 60h), enable the auxilliary device (bit5 in the command byte), and setup a handler to store incoming bytes. Each interrupt will only supply one byte so you will have to reassemble the packet from the individual bytes you stored earlier. However before you can get this information you must tell the mouse to send it to you whenever it's got it, so set it to stream mode. You send bytes to the mouse by sending command 0D4h to the KBC and then send the byte to the data port. Every command is acknowledged with 0FAh. This all assumes you know the mouse is present in the auxilliary port.

I hope I'm not forgetting something...

http://www.computer-engineering.org/ Gives info on the KBC and keyboard in the keyboard doc and mouse info in the keyboard one so read both.
http://www.mega-tokyo.com/osfaq/MouseInput and related threads links at the bottom

Edit: Not only will you have to send the Set Stream Mode command (0EAh) but you also may have to send Enable Data Reporting (0F4h).
durand
Member
Member
Posts: 193
Joined: Wed Dec 21, 2005 12:00 am
Location: South Africa
Contact:

Re:How to get packets and such for PS/2 mouse

Post by durand »

This website has some nice code for the PS2 mouse:

http://www.ragestorm.net/samples

You just need to convert anything required to protected mode.. which shouldn't be a lot.
earlz

Re:How to get packets and such for PS/2 mouse

Post by earlz »

Hi I'm having some troubles getting this to display correctly
I'm trying to keep the mouse from going off the screen but this is just not working

Code: Select all

      //cwin->width is the current screen width and same for cwin->height
      //mouse_x and mouse_y is the movement data, Mouse1.mouse_x and such is what the X for the mouse is 
      if(get_bit(5,mouse_byte[0])==0){
         Mouse1.mouse_x=Mouse1.mouse_x+mouse_x;
          if(Mouse1.mouse_x>cwin->width){Mouse1.mouse_x=cwin->width-2;}
      }else{
         Mouse1.mouse_x=Mouse1.mouse_x-mouse_x;
          if(Mouse1.mouse_x>cwin->width){Mouse1.mouse_x=1;} //no sign bit
     }
     //mouse_y=mouse_y;
     //mouse_x=mouse_x/4;
     if(get_bit(6,mouse_byte[0])==0){ //0 is not signed anythignn else is signed
        Mouse1.mouse_y=Mouse1.mouse_y-mouse_y;
          if(Mouse1.mouse_y>cwin->height){Mouse1.mouse_y=1;}
     }else{
        Mouse1.mouse_y=Mouse1.mouse_y+mouse_y;
          if(Mouse1.mouse_y>cwin->height){Mouse1.mouse_y=cwin->height-2;}
     }
Post Reply