[A83] Re: Question(bit checking)


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

[A83] Re: Question(bit checking)




>From: Mike3465@aol.com
>
>Ok, i would like to make it so that some basic
>flags in my game, could all be combined into 1
>variable (well, 8 on/off flags would go into
>1 spot in memory)
>Ok, i was wondering how i would do this. I have
>a rough idea, but i was wondering if there was
>anyway to optimise it for speed?
>
>(checking the binary value of 11110111 for
>the 4th value, or, to get 0)
>
>ld a,%11110111
>sra a
>sra a
>sra a
>sra a
>and 1
>
>so i could have a function like this?
>
>(a = number to check, b= bit to check,
>returns a, the value of the bit)
>
>BitFinder:
>     sra a
>     djnz BitFinder
>     and 1
>     ret
>is that the best i could do? just wondering,
>and also, is that correct? ^_^
>
>thanks

Another option might be this:

; input: hl->number to check; b=bit to check
; output: nz if flag is set

BitFinder:
     ld   a,%10000000
BitFinderLoop:
     rlca
     djnz BitFinderLoop
     and  (hl)
     ret

_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.