Mouse Driver Problems

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.
Lprogster
Member
Member
Posts: 174
Joined: Tue Nov 14, 2006 11:59 am

Post by Lprogster »

...

Thanks,
Lster
Last edited by Lprogster on Tue Oct 23, 2007 11:16 am, edited 2 times in total.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

Lprogster wrote:One last question though...

The unsigned char array stores the 3 bytes from the mouse. If I'm right, bute 0 is x, byte 1 is y and byte 2 is status. I'm not quite sure how to interpret them though.

Say I have 2 variables that store the cursors x and y positions. Why doesn't this work:

Code: Select all

void anim ( )
{

	MOUSEDATA q;
	int x = 160 , y = 100; // Center of the screen
	for ( ; ; )
	{
		GetMouseData ( &q );
		x += sign ( q.xmove ); // How should this interpret the data?
		y += sign ( q.ymove );
		pix ( x , y , 15 );
	}
}
I hope I'm being coherent enough.

Anyhow - thank you for the code,
Lster
Here's what I do:

Code: Select all

// gets and returns the mouse data
// note: all data seems to come in back-to-front. don't ask me why
void GetMouseData( MOUSEDATA* data )
{
	if( readable )
	{
		data->xmove = bytes[0];
		data->ymove = bytes[1];
		data->MouseStatus.status = bytes[2];
		readable = 0;
	}
}
bytes[0] is xmove, bytes[1] is ymove, bytes[2] is the status.

Now, to interpret this, you just have to do some simple math:

Code: Select all

x += ( q.xmove * 1 );
y += ( q.ymove * -1 );
You could even have sensitivity settings and change the '*1' to '*sens' or something like that.

If you do a dump of the xmove and ymove values you'll see why the above works.

Edit: the mouse co-ords send properly in QEMU, but few other commands work. You can assume if it works in Bochs it'll work on bare hardware though, as my PS2 driver works properly.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

pcmattman wrote:You can assume if it works in Bochs it'll work on bare hardware though
Don't. Bochs is just an emulator with its own flaws. Code running on bochs is not guaranteed to run on real PCs. Even if you are able to run something on all virtual machines and emulators, it isn't a guarantuee for success on real hardware. However, by that time it has become rather likely.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

Combuster wrote:Don't. Bochs is just an emulator with its own flaws. Code running on bochs is not guaranteed to run on real PCs.
Assume is not the same as 'take as fact'. To assume generally means that you are taking an educated guess.

You are right, though.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

Assume is not the same as 'take as fact'.
No, but I'm allowed to warn for common misconceptions, aka bad assumptions, no?

[rant] In fact, I've had several cases that code running in bochs doesnt run on real hardware. All of which were caused by incomplete emulation. [/rant]
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

Ok, ok, point made.

My ATAPI detection code fails every time (locks up...). Works in Bochs and QEMU though. Funny that.
User avatar
os64dev
Member
Member
Posts: 553
Joined: Sat Jan 27, 2007 3:21 pm
Location: Best, Netherlands

Post by os64dev »

isn't there a saying like 'assumption is the mother of all fuckups'. I tend to live by this rule. If you have to assume something... don't and make it explicit. This will save you a lot of troubles later on..

my 2ct
Author of COBOS
Lprogster
Member
Member
Posts: 174
Joined: Tue Nov 14, 2006 11:59 am

Post by Lprogster »

Hi, I'm back - been away for a while...

I still can't get it working :(. One thing - does it matter that I'm getting "Mouse not acknowledged {1}.Mouse not acknowledged {2}." printed on screen?

Thanks,
Lster
User avatar
os64dev
Member
Member
Posts: 553
Joined: Sat Jan 27, 2007 3:21 pm
Location: Best, Netherlands

Post by os64dev »

It seems that you enable irq's but don't use them. Which can be bad.., considering the mouse needs some to time (order milli seconds) to reply. If i look at your read mouse function it returns the value obtained from port 0x60 whether it is updated or not and thus returns immediatly (order of microseconds). In short the outcome of your driver is to be expected.

So to fix the issue you have to enable interrupts with an interrupt handler to store the data into a buffer or you will have to adapt the mouseread to polling mode with a check if new data is available (status port 0x64 i guess).

regards
Author of COBOS
Lprogster
Member
Member
Posts: 174
Joined: Tue Nov 14, 2006 11:59 am

Post by Lprogster »

Thanks for the quick reply :).
...

Any ideas? Thanks,
Lster
Post Reply