Skip to content

Commit 28d6c04

Browse files
committed
optimized sprite flip/rotate90
1 parent e28a846 commit 28d6c04

File tree

1 file changed

+60
-54
lines changed

1 file changed

+60
-54
lines changed

src/graphx/graphx.asm

Lines changed: 60 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4602,98 +4602,100 @@ d_18: ld bc,(ix-17)
46024602

46034603
;-------------------------------------------------------------------------------
46044604
gfx_FlipSpriteY:
4605-
; Flips an array horizontally about the center vertical axis
4605+
; Flips a sprite vertically about the center horizontal axis
46064606
; Arguments:
46074607
; arg0 : Pointer to sprite struct input
46084608
; arg1 : Pointer to sprite struct output
46094609
; Returns:
46104610
; arg1 : Pointer to sprite struct output
46114611
ld iy,0
46124612
add iy,sp
4613-
push ix
4614-
ld ix,(iy+3)
4615-
ld a,(ix+0) ; a = width of sprite
4613+
ld de,(iy+3)
4614+
ld a,(de) ; a = width of sprite
4615+
inc.s bc ; clear UBC
4616+
46164617
sbc hl,hl
46174618
ld l,a
46184619
ld c,a
4619-
push hl
4620-
ld (.width),a
4621-
add hl,hl
4622-
ld (.delta),hl ; width*2
4623-
ld a,(ix+1) ; a = height of sprite
4624-
pop hl
4625-
lea de,ix+2
4620+
4621+
inc de
4622+
ld a,(de) ; a = height of sprite
4623+
4624+
inc de
46264625
add hl,de
4627-
ld ix,(iy+6)
4628-
ld (ix+1),a ; store height to width
4629-
ld (ix+0),c ; store width to height
4630-
lea de,ix+2 ; de -> sprite data
4631-
ex (sp),ix ; restore stack frame
4626+
ld de,(iy+6) ; de -> sprite data
4627+
push de
4628+
inc de
4629+
ld (de),a ; store height to width
4630+
ld iyh, a
4631+
; inc de ; use the inc de inside the loop instead
46324632
.loop:
4633-
ld b,0
4634-
.width := $-1
4635-
ld c,a
4633+
ld b,c ; width
46364634
.pixelloop:
46374635
dec hl
4636+
inc de
46384637
ld a,(hl)
46394638
ld (de),a ; store the new pixel data
4640-
inc de
46414639
djnz .pixelloop
4642-
ld a,c
4643-
ld bc,0
4644-
.delta := $-3
4640+
; hl += delta * 2
46454641
add hl,bc
4646-
dec a
4642+
add hl,bc
4643+
dec iyh
46474644
jr nz,.loop
46484645
pop hl
4646+
ld (hl),c ; store width to height (the loop preserves c)
46494647
ret
46504648

46514649
;-------------------------------------------------------------------------------
46524650
gfx_FlipSpriteX:
4653-
; Flip a sprite vertically about the center horizontal axis
4651+
; Flips a sprite horizontally about the center vertical axis
46544652
; Arguments:
46554653
; arg0 : Pointer to sprite struct input
46564654
; arg1 : Pointer to sprite struct output
46574655
; Returns:
46584656
; arg1 : Pointer to sprite struct output
46594657
ld iy,0
46604658
add iy,sp
4661-
push ix
4662-
ld ix,(iy+3)
4659+
ld hl,(iy+3)
46634660
xor a,a
4664-
sub a,(ix+0)
4661+
sub a,(hl)
4662+
inc hl
46654663
ld (.delta),a
46664664
neg
46674665
ld (.width),a
4668-
ld l,(ix+1)
4669-
ld c,l
4670-
dec l
4671-
ld h,a
4672-
mlt hl
4673-
lea de,ix+2
4666+
4667+
ld e,(hl)
4668+
inc hl
4669+
ld c,e
4670+
dec e
4671+
ld d,a
4672+
mlt de
46744673
add hl,de
4675-
ld ix,(iy+6)
4676-
ld (ix+0),a
4677-
ld (ix+1),c
4678-
lea de,ix+2
4679-
push ix
4674+
ld de,(iy+6) ; de -> sprite data
4675+
push de
4676+
ex de, hl
4677+
ld (hl),c ; store width to height
4678+
ex de, hl
4679+
inc de
4680+
ld (de),a ; store height to width
4681+
inc de
46804682
.loop:
46814683
ld bc,0
46824684
.width := $-3
46834685
ldir
4684-
ld bc,-1
4685-
.delta := $-3
4686+
dec bc ; ld bc, -1
4687+
ld c,-1
4688+
.delta := $-1
46864689
add hl,bc
46874690
add hl,bc
46884691
dec a
46894692
jr nz,.loop
46904693
pop hl
4691-
pop ix
46924694
ret
46934695

46944696
;-------------------------------------------------------------------------------
46954697
gfx_RotateSpriteC:
4696-
; Rotates an array 90 degress clockwise
4698+
; Rotates a sprite 90 degress clockwise
46974699
; Arguments:
46984700
; arg0 : Pointer to sprite struct input
46994701
; arg1 : Pointer to sprite struct output
@@ -4774,29 +4776,33 @@ gfx_RotateSpriteCC:
47744776

47754777
;-------------------------------------------------------------------------------
47764778
gfx_RotateSpriteHalf:
4777-
; Rotates an array 180 degrees
4779+
; Rotates a sprite 180 degrees
47784780
; Arguments:
47794781
; arg0 : Pointer to sprite struct input
47804782
; arg1 : Pointer to sprite struct output
47814783
; Returns:
47824784
; arg1 : Pointer to sprite struct output
4783-
ld iy,0
4784-
add iy,sp
4785-
ld hl,(iy+3)
4786-
ld c,(hl) ; c = width
4785+
ld hl, 6
4786+
add hl, sp
4787+
ld de, (hl) ; output sprite
4788+
dec hl
4789+
dec hl
4790+
dec hl
4791+
ld hl, (hl) ; input sprite
4792+
ld c, (hl) ; c = width
47874793
inc hl
4788-
ld b,(hl) ; b = height
4789-
ld iy,(iy+6)
4790-
ld (iy+0),bc
4794+
ld b, (hl) ; b = height
4795+
ex de, hl
4796+
ld (hl), bc
4797+
ex de, hl
47914798
mlt bc
4792-
add hl,bc
4793-
lea de,iy
4799+
add hl, bc
47944800
push de
47954801
.loop:
47964802
inc de
47974803
inc de
47984804
ldd
4799-
jp pe,.loop
4805+
jp pe, .loop
48004806
pop hl
48014807
ret
48024808

0 commit comments

Comments
 (0)