A86: Super fast GridPutSprite


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

A86: Super fast GridPutSprite




Out of curiosity, I decided to unroll the GridPutSprite routine, and the
results are great.  Almost a two times speed increase.  The time goes from
567 t-states down to 289.  The byte size increases from 28 to 44.  Not bad
at all.  An added bonus is that you can now pass in the address to draw it
to, making it great for greyscale or virtual screens (or both!).  Since it's
twice the speed, you could draw to a two greyscale planes in the time it
took to draw to a single screen!

          Time   Bytes
         +-----+------+
Loop     | 567 |  28  |
Unrolled | 289 |  44  |
         +-----+------+
Diff.    | 278 |  16  |
Result   | 51% | 157% | (unrolled / loop)
         +-----+------+
    (this chart proves how beneficial unrolling loops can be)

;=====================================================================
; GridPutSprite:
;  Puts an aligned sprite at (E, D), where BC -> Sprite
;=====================================================================
; IN : D  = y (0-7 inclusive)
;      E  = x (0-15 inclusive)
;      BC -> sprite
;      HL -> screen buffer to draw to ($fc00)
;
; OUT: AF, BC, DE, HL modified
; Current total : 44b/289t (not counting ret)
;=====================================================================
GridPutSprite:
 srl d          ; de = 128y+x (16 bytes/row, 8 rows)
 rra
 and $80
 or e           ; add x offset (remember x <= 15)
 ld e,a
 add hl,de      ; hl-> address + offset
 ld de,$10      ; initialize line increment
 ld a,(bc)      ; get byte from sprite
 ld (hl),a      ; put byte on screen
 inc bc         ; move to next byte in sprite
 add hl,de      ; move to next line on screen
 ld a,(bc)      ; {2}
 ld (hl),a      ; ...
 inc bc         ; ..
 add hl,de      ; .
 ld a,(bc)      ; {3}
 ld (hl),a      ; ...
 inc bc         ; ..
 add hl,de      ; .
 ld a,(bc)      ; {4}
 ld (hl),a      ; ...
 inc bc         ; ..
 add hl,de      ; .
 ld a,(bc)      ; {5}
 ld (hl),a      ; ...
 inc bc         ; ..
 add hl,de      ; .
 ld a,(bc)      ; {6}
 ld (hl),a      ; ...
 inc bc         ; ..
 add hl,de      ; .
 ld a,(bc)      ; {7}
 ld (hl),a      ; ...
 inc bc         ; ..
 add hl,de      ; .
 ld a,(bc)      ; {8}
 ld (hl),a      ; ...
 ret

Enjoy!

--
David Phillips <electrum@tfs.net>
ICQ: 13811951
AOL/AIM: Electrum32
86 Central: http://www.tfs.net/~electrum/


Follow-Ups: