PS2 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
User avatar
Omega
Member
Member
Posts: 250
Joined: Sun May 25, 2008 2:04 am
Location: United States
Contact:

PS2 Mouse

Post by Omega »

Hi. I am putting my HDD driver on hold to mess with this mouse driver I built. Everything works good, but I want to steal the TASM install screen mouse thing idea. Basically, the program writes the block cursor to the position of the mouse on screen to simulate the GUI cursor. I figured out that I could do the same with printf and undo my write with the opposite char code, but I cannot figure out how to calibrate the position of my cursor.

What happens is I receive negative values, so I wrote quick abs function but it must be bunk:

Code: Select all

int abs(int num)
{
	if(num<0) {
		int sqrd=num*num;
		int prod=num/sqrd;
		return prod;
	} else {
		return num;
	}
}
However, it seems to be returning OK values. However, when i use the abs function I don't see the printed char anywhere. When I don't use the ABS function I wrote, I do see the char, but it seems like my calibration is bass ackwards because if I scroll up, it scrolls down, left it goes right, right it goes left, down it goes up. I think this is due to the negative values. Any ideas?
Free energy is indeed evil for it absorbs the light.
cg123
Member
Member
Posts: 41
Joined: Wed Sep 27, 2006 2:34 pm

Re: PS2 Mouse

Post by cg123 »

That's not really the best way to get the absolute value of a number. Use something like this:

Code: Select all

int abs(int num) {
    return (num < 0) ? -num : num;
}
User avatar
Omega
Member
Member
Posts: 250
Joined: Sun May 25, 2008 2:04 am
Location: United States
Contact:

Re: PS2 Mouse

Post by Omega »

Wow, thanks a lot. That seemed to fix it. Now I have a problem with it reseting my mouse cords after printing my char, but I will tackle that myself. Thanks a lot for the help.
Free energy is indeed evil for it absorbs the light.
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: PS2 Mouse

Post by jal »

Omega wrote:

Code: Select all

int abs(int num)
{
	if(num<0) {
		int sqrd=num*num;
		int prod=num/sqrd;
		return prod;
	} else {
		return num;
	}
}
Not only is this quite an idiotic way to get an abs value, the formula is of course wrong. 1) "num / (num*num)" will always produce a number smaller than 1 (except if num == 1), so prod always returns 0; 2) since num is negative, dividing it by a positive number will always yield a negative number (so even if you'd divide sqrd by num, which I more or less assume was your intention, you'd get a negative).


JAL
Post Reply