Mouse's weird behaviour

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
Rival
Posts: 11
Joined: Sat Feb 05, 2011 6:05 am
Location: I gotta go

Mouse's weird behaviour

Post by Rival »

Hello everyone,

I'm new to the forum but not new to this site. Me and my friend have been developing and OS for several months and finally we've decided to follow separate tracks. Now, I've written my own OS and I'm currently stuck at the very weird behaviour of the mouse.If I uninstall and then reinstall the mouse, the mouse starts to send strange packets and the cursor seems to go violent. I think the mouse has entered unknown mode but I'm not sure which. Here's the code to install and uninstall the mouse:

Code: Select all

void mouse_install()
{

unsigned char _status;
	
	mouse_wait(1);	/*let's now enable the mouse port to generate interrupts*/
	outportb(0x64,0xA8);
	
	mouse_wait(1);	/*modify the "compaq status byte", to enable the interrupt*/
	outportb(0x64,0x20);

	mouse_wait(0);
	_status=(inportb(0x60) | 2);
	
	mouse_wait(1);
	outportb(0x64,0x60);
	mouse_wait(1);
	outportb(0x60,_status);
		
mouse_write(0xF6);	/*Tell the mouse to use default settings*/
mouse_read();		/*Acknowledge*/

mouse_write(0xF4);		/*Enable Data Reporting*/
mouse_read();

	
	irq_install_handler(12, mouse_handler);
}

void mouse_uninstall()
{

unsigned char _status;
	mouse_show();
	
	mouse_wait(1);	/*disable the auxillary mouse device*/
	outportb(0x64,0xA7);	
			
mouse_write(0xF5);		/*Disable Data Reporting*/
mouse_read();

	
	irq_uninstall_handler(12);
	mouse_hide();
}
I tried updating the mouse_uninstall() code as much as I could including restoring original compaq status byte etc. but I don't seem to dig my way out.
What I'm surprised to see is that there's no any strange behaviour if I run this code under emulator. But under real hardware, the mouse starts to behave strange, sending random packets. I think the mouse is in some different mode. I even tried sending the 'Reset' Command to the mouse but then it starts to behave strange even under the emulator as it wouldn't do before(at least not under an emulator). This means that nor the hardware is faulty nor the emulator(MS virtual PC). I would highly appreciate if someone would help me or at least push in the right direction.

Thanks for any help.
--Rival
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Re: Mouse's weird behaviour

Post by bewing »

Mice do not have complex electronics. They only have one or two modes, and certainly no "unknown" ones.

The one thing that is most difficult with mouse packets is keeping them aligned properly on packet boundaries. If your driver and your mouse get out of sync on "where the beginning of the mouse data packet is", then you are likely to see exactly the behavior that you are describing. So, I am guessing that is what is happening.

Unfortunately, fixing it is also quite hard. The code that you have posted all looks fine, but is almost certainly not where the problem is happening.
Post Reply