A86: Re: Aligned Sprite


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

A86: Re: Aligned Sprite




Let's look at the best 8x8 aligned or grid sprite routine I've seen.  I
think it's Dan Eble's, but I could be wrong:

;=========================================================
; GridPutSprite:
;  Puts an aligned sprite at (E, D), where HL -> Sprite
;=========================================================
; IN : D  = y (0-7 inclusive)
;      E  = x (0-15 inclusive)
;      HL-> sprite
;
; OUT: AF, BC, DE, HL, IX modified
; Current total : 28b/567t (not counting ret)
;=========================================================
GridPutSprite:
 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-> video ram
 add hl,de        ; hl-> video ram + offset
 ld b,8           ; initialize loop counter
 ld de,$10        ; initialize line increment
GPS_Loop:
 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
 djnz GPS_Loop
 ret

This shouldn't be too hard to change to 16x16.  Instead of blitting one byte
at a time, you blit two.  And instead of looping to draw 8 rows, you draw
16.  I will assume that the format for the 16x16 sprites is that they are 16
rows of 2 bytes each (the same format as Assembly Studio 3.0 uses, but
skipping the size bytes).  This will allow for the fastest possible drawing.
Also note that I didn't change the grid coordinates, so they could overlap.
Another note is that you could completely unroll the loop, thus freeing up B
as the loop counter, letting you use BC as the sprite pointer, which would
save about 30 t-states per iteration.  Not worth it, IMHO, due to the huge
increase in size, but if you really need a super fast routine, it's
something to consider.

GridPutSprite16:
 push hl
 pop ix           ; ix-> sprite
 srl d            ; de = 128y+x (16 bytes/row, 8 rows)
 rra
 and $80
 or e             ; add x offset             ** should be < 14, not 15
 ld e,a
 ld hl,$fc00      ; hl-> video ram
 add hl,de        ; hl-> video ram + offset
 ld b,16          ; init loop counter        ** 16 bytes, not 8
 ld de,15         ; init line increment      ** incremented once inside loop
GPS_Loop16:
 ld a,(ix+0)      ; get byte from sprite
 ld (hl),a        ; put byte on screen
 inc ix           ; move to next byte in sprite
 inc hl           ; ** next byte in video memory
 ld a,(ix+0)      ; ** repeat above for the next byte
 ld (hl),a        ;
 inc ix           ;
 add hl,de        ; move to next line on screen
 djnz GPS_Loop16
 ret

-----Original Message-----
From: Dave VanEe <dvanee@dowco.com>
To: assembly-86@lists.ticalc.org <assembly-86@lists.ticalc.org>
Date: Sunday, November 01, 1998 5:56 PM
Subject: A86: Aligned Sprite


>
>Can someone write an AlignedSprite routine for 16x16 sprites? I tried, but
>mine is slow and way to big.
>
>Thanx,
>Dave