Re: LZ: flags


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

Re: LZ: flags



Will Stokes (3D Diamond productions) wrote:
> 
>                                    wstokes@vertex.ucls.uchicago.edu
>                                    http://www.uic.edu/~hhstokes/index.html
>                                    Will Stokes
> 
> Ok, here is a quit question. I have almost finnished my first game for
> zshell and have run into a small problem by all means. I have never
> learned how to use flags and now I need to.
> 
> Here's the q. Say I have variable "sf" and I want to know is sf is less
> then or equal to 0 (less then 1). How do I do this using flags? Can't use
> < anymore. Any help would be appreciated.


You use CP 1. Then the carry flag will be set if the subtraction (cp is
just an ordinary subtraction except that the result isn't stored anyway)
needs a borrow. In your case, 0-1 needs a borrow. I DON'T know how this
will work with negative numbers, since -1 also can be read as 255...
You can check for negative numbers this way though:


 ld a,(sf)
 or a                ; same as cp 0 but shorter
 jr z,LessThanOne    ; a = 0
 bit 7,a             ; test if the last bit is set, which means a negative
                     ; numbers (or a number bigger than 127)
 jr nz,LessThanOne   ; the bit is set, jump to LessThanOne


<pre>
-- 
Real name: Jimmy Mårdell
Email....: mailto:mja@algonet.se
IRC-name.: Yarin
WWW......: http://www.algonet.se/~mja


"Strap me down with disillusion 
  Tie me up in lifelines
   Nothing stops my thoughts from breeding
    Nothing's stopping my mind" - Leather Strip
</pre>


References: