Re: A83: Negative or positive?
[Prev][Next][Index][Thread]
Re: A83: Negative or positive?
On 1 Mar 00, at 17:19, Marc Puts wrote:
Hi,
Again, thanks for your help, it got me a lot further. But
now I'm stuck again. This is my question...
In my program, a sprite moves from the left to the right
of the screen, and back. I do this by using a variable
sprite_x and a variable speed.
At the begin of the program, Speed=1 and Sprite_x=44
Then I do Add Sprite_x, Speed (well, I use a and e instead, but
this is
just the explanation)
I do this until Sprite_X > 90. At that point, I neg speed, and repeat
the whole thing, until Sprite_X < 6. It works great.
At an other place in the program, I want to check if the
sprite is currently moving left or right, so I want to check
if speed is positive or negative. That's where I'm stuck now.
How can I do it?
I tried this:
ld a,(speed)
cp 0
jp c,A_Is_Negative
jp A_Is_Positive_Or_Zero
It doesn't seem to work. It looks like speed is never negative.
I reverse it using neg, but this is the result:
Speed | after Neg
-----------------
1 | 255
2 | 254
3 | 253
4 | 252
and so on...
It seems that Speed is never negative! I think that's somewhere
logical, because Speed is an 8-bit variable. On the other hand,
it's not possible, because the sprite does move from the right
to the left, as I decribed above.
So, how can I check if Speed is positive or negative?
Greetings & thanx, Marc
Answer: Try comparing bit 7, which if you look at it in signed format,
looks like this:
Speed After neg
1 255 (this is really -1!)
2 254 (Really -2)
if you look at it like 7 bits with the 8th bit as a negative sign, you'll
catch on.
Follow-Ups:
References: