Re: A86: Findpixl Wars


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

Re: A86: Findpixl Wars



On Tue, 5 Aug 1997, James Yopp wrote:

> Dan's routine revisited.  Line beginning with a '!' have been changed.  
> This routine is 38b/136t without counting the 'ret' or using push/pop.  
> Haha!  I never thought I'd see this small of a FindPixel routine.
                                 ^^^^^^^^^^
If you're willing to trade 7 t-states for 4 bytes (a good ratio, IMHO),
then use this routine, which is 34b/143t without ret or stack ops. Once
you figure out what it's doing, maybe you can optimize this one, too. I
suggest drawing diagrams. :)

;-----------------------------------------------------------------------
; Input:  D=y, E=x
; Output: A=mask, HL->byte in vid mem
;-----------------------------------------------------------------------

FindPixel:
        ld a,e
        and $07         ; a = bit offset
        ld c,a
        ld b,0
        ld hl,FP_Bits
        add hl,bc
        ld b,(hl)       ; b = bitmask for (hl)
;56 t-states to this point
        ld h,d		; h = y
        ld l,e		; l = x
        sla l
        add hl,hl       ; do a multi-half-byte shift
        add hl,hl
        add hl,hl       ; this might cause a carry
        rla             ;  put carry in A
        add hl,hl       ; this might too
        rla             ;  put carry in A
        ld l,h          ; swap bytes
        or  $FC
        ld h,a          ; hl -> byte in video mem
    
        ld a,b          ; now a = bitmask for (hl)
;143 t-states to this point
        ret

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

.end

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


References: