Re: A86: FindPixl


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

Re: A86: FindPixl



On Mon, 4 Aug 1997, James Yopp wrote:

> 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 

Here is a good FindPixel routine.  It is 150 t-cycles, not including the 
"ret."  Additionally, it does not use self-modifying code, which, though
not as cool as James' solution, is generally considered good style. 
Finally, please notice that my version takes slightly different input and
leaves BC modified.  To push and pop BC would increase the routine size to
41 bytes (I believe the same as James') and increase the number of 
t-states to 171.

;----------------------------------------------------
; FindPixel
;   Input: D = Y, E = X
;   Result: BC modified
;           HL -> byte address of pixel in LCD memory
;           A = pixel bitmask (one bit is set)
;  Screen layout:
;  +----------------+
;  |        0       |
;  |                |
;  |0            127|
;  |                |
;  |       63       |
;  +----------------+
;----------------------------------------------------

FindPixel:
        ld a,e
        and $07         ; a = bit offset
        ld b,0
        ld c,a
        ld hl,FP_Bits
        add hl,bc
        ld b,(hl)       ; b = bitmask for (hl)
;56 t-states up to this point
        ld a,d
        rlca            ; multiply y by 4
        rlca
        ld l,a
        ld h,0
        add hl,hl       ; multiply y by 4 again
        add hl,hl       ;   because there are 16 bytes in a pixel row
        ld a,e
        rrca            ; divide x by 8 (8 pixels/byte)
        rrca
        rrca
        and $0F
        ld c,a
        ld a,b          ; now a = bitmask for (hl)
        ld b,$FC
        add hl,bc       ; hl -> byte in LCD memory
;150 t-states up to this point
        ret

FP_Bits: .db $80,$40,$20,$10,$08,$04,$02,$01

;---------------------------------------------------------

> 
> Please feel free to send me fan mail.
> 

Please feel free to send me ways to improve my code.

--------
Dan Eble (mailto:eble@cis.ohio-state.edu)
         (http://www.cis.ohio-state.edu/~eble)






References: