A86: Better Aligned Sprite Routine


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

A86: Better Aligned Sprite Routine



On Mon, 1 Sep 1997, Ricci Adams wrote:

>   This is an updated version of the sprite routine I recived from Trent
> Lillehaugen last week.  This version allows you to put the sprite in any of
> the 8x8 squares on the screen.  To call this, use:
>


Here's a more efficient aligned sprite routine.  As far as I know, IX has
no enduring purpose in the TI system software.  (I have not tested this
routine.)  Push/pop of IX adds 4 bytes and 29 t-states.  Push/pop of other
registers adds 2 bytes and 21 t-states.

This routine is 2/3 the size of the previously posted routine and executes
in about 3/4 of the time.  (Push/pop of IX makes it about 8/10.)  Is there
room for more optimization?  (James?)

; original total: 42b/753t (not counting ret)
; current total : 28b/567t (not counting ret)

; IN : D  = y (0-7 inclusive)
;      E  = x (0-15 inclusive)
;      HL-> sprite
;
; OUT: AF, BC, DE, HL, IX modified

DrawPic:
        push hl
        pop ix          ; ix-> sprite

        srl d           ; de = 128y+x (16 bytes/row, 8 rows)
        rra
        and $80
        or e            ; add x offset (remember x <= 15)
        ld e,a

        ld hl,$FC00     ; hl-> vid mem
        add hl,de       ; hl-> vid mem + offset


        ld b,8          ; initialize loop counter
        ld de,$0010     ; initialize line increment

; originally 30b/126t to this point
; now 19b/90t to this point

DrawPicLoop:
        ld a,(ix+0)     ; get byte from sprite
        ld (hl),a       ; put byte on screen
        inc ix          ; move to next byte in sprite
        add hl,de       ; move to next line on screen

; originally 10b/66t inside loop
; now 7b/47t inside loop

        djnz DrawPicLoop
        ret

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


References: