Page 1 of 1

PS2 Mouse

Posted: Sun Jul 13, 2008 9:59 pm
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?

Re: PS2 Mouse

Posted: Sun Jul 13, 2008 10:01 pm
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;
}

Re: PS2 Mouse

Posted: Sun Jul 13, 2008 10:11 pm
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.

Re: PS2 Mouse

Posted: Mon Jul 14, 2008 4:39 am
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