Re: A83: Negative or positive?


[Prev][Next][Index][Thread]

Re: A83: Negative or positive?




Sorry bout the extremely late post, but can't you just use the sign flag?

ld a,(number)
cp 50
jp z,a_is_fifty
jp p,a_is_greater_than_fifty
jp m,a_is_less_than_fifty

The p stands for plus and the m minus (meaning positive or negative). I know 
all this does is check the 7th bit, but i think it might save a few bytes.

                                                        Bud
In a message dated 3/1/2000 11:20:37 AM Eastern Standard Time, 
marcputs@hetnet.nl writes:

<< 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 >>


Follow-Ups: