Hey folks!
I propose we all look for the fastest Sprite routine possible.
Studying Mateo's great tutorial "Drawing Sprite" ...
( https://ce-programming.github.io/documentation/tutorials/asm/drawing-sprites/ )
I wondered if we could find optimisations for this sprite routine:
Code:
Here is my attempt:
Code:
EDIT: I just put "ld bc,0" before "di"
I propose we all look for the fastest Sprite routine possible.
Studying Mateo's great tutorial "Drawing Sprite" ...
( https://ce-programming.github.io/documentation/tutorials/asm/drawing-sprites/ )
I wondered if we could find optimisations for this sprite routine:
Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; DrawSprite
; inputs:
; bc = x
; l = y
; de = pointer to sprite
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
DrawSprite:
ld h,lcdWidth/2 ; hl=160
mlt hl ; 160*y
add hl,hl ; hl*2
add hl,bc ; add x
ld bc,vRam
add hl,bc ; offset vRam
ld a,(de) ; width
ld (SpriteWidthSMC),a
inc de
ld a,(de) ; height
inc de
ex de,hl
drawSpriteLoop:
SpriteWidthSMC: =$+1
ld bc,0
push de
ldir ; draw line
pop de
ex de,hl
ld bc,lcdWidth
add hl,bc ; move down
ex de,hl
dec a
jr nz,drawSpriteLoop
ret
Here is my attempt:
Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; DrawSprite
; inputs:
; bc = x
; l = y
; de = pointer to sprite
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
DrawSprite:
ld h,lcdWidth/2 ; hl=160
mlt hl ; 160*y
add hl,hl ; hl*2
add hl,bc ; add x
ex de,hl
ld ix,vRam
add ix,de ; offset vRam
ld a,(hl) ; width
ld (SpriteWidthSMC),a
inc hl
ld a,(hl) ; height
inc hl
ld bc,0
di
ld (stpo+1),sp
ld sp,lcdWidth
drawSpriteLoop:
SpriteWidthSMC: =$+1
ld c,0
lea de,ix+0 ; now de=ix
ldir ; draw line
add ix,sp ; move down
dec a
jr nz,drawSpriteLoop
stpo:
ld sp,0
di
ret
EDIT: I just put "ld bc,0" before "di"