A86: FindPixl


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

A86: FindPixl



Here's a great FindPixel routine... You may want to use it even when we 
find the ROM FindPixel.  It executes in 181 cycles, no matter where the 
bit you're looking for is on the screen (This is good for games).  This 
one finds a pixel in the videoMem.  If you want it to work like the old 
'85 findpixel, just change "ld hl, $FC" to "ld hl, $00".  The start of 
our first library, maybe?

FP:                             ;This is a VERY FAST, highly optimized

        push    bc              ;routine. 181 CYCLES CONSTANT!!!!

        ld      a, b            ;For the routine down after we add hl 
and de

        ld      h, $FC

        ld      l, b

        SRL     l

        SRL     l

        SRL     l

        ld      b, 0            ;16-Bit shifting

        SLA     c

        SLA     c

        SLA     c               ;The first two bits would put it out of

        RL      b               ;bounds anyway, so we don't rotate until 
now.

        SLA     c

        RL      b

        add     hl, bc

        cpl                     ;Bits go from 7 to 0, not 0 to 7!!!

        and     7

        RLA                     ;Use this because it's only 1 byte, and 4

        RLA                     ;T-States.

        RLA

        or      $C7             ;Make our own opcode for the bitsetting

        ld      (ChgBit), a

        xor     a

        .db     $CB             ;Set X, a is $CBC7. bits 3-5 set which 
bit.

ChgBit: .db     $00

        pop     bc

        ret

Please feel free to send me fan mail.

James


Follow-Ups: