Skip to content

Commit 1fe8bfb

Browse files
committed
optimized sprite flip/rotate90
1 parent 7b3f947 commit 1fe8bfb

File tree

1 file changed

+70
-66
lines changed

1 file changed

+70
-66
lines changed

src/graphx/graphx.asm

Lines changed: 70 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -4586,98 +4586,98 @@ d_18: ld bc,(ix-17)
45864586

45874587
;-------------------------------------------------------------------------------
45884588
gfx_FlipSpriteY:
4589-
; Flips an array horizontally about the center vertical axis
4589+
; Flips a sprite horizontally about the center vertical axis
45904590
; Arguments:
45914591
; arg0 : Pointer to sprite struct input
45924592
; arg1 : Pointer to sprite struct output
45934593
; Returns:
45944594
; arg1 : Pointer to sprite struct output
45954595
ld iy,0
45964596
add iy,sp
4597-
push ix
4598-
ld ix,(iy+3)
4599-
ld a,(ix+0) ; a = width of sprite
4597+
ld de,(iy+3)
4598+
ld a,(de) ; a = width of sprite
4599+
inc.s bc ; clear UBC
4600+
46004601
sbc hl,hl
46014602
ld l,a
46024603
ld c,a
4603-
push hl
4604-
ld (.width),a
4605-
add hl,hl
4606-
ld (.delta),hl ; width*2
4607-
ld a,(ix+1) ; a = height of sprite
4608-
pop hl
4609-
lea de,ix+2
4604+
4605+
inc de
4606+
ld a,(de) ; a = height of sprite
4607+
4608+
inc de
46104609
add hl,de
4611-
ld ix,(iy+6)
4612-
ld (ix+1),a ; store height to width
4613-
ld (ix+0),c ; store width to height
4614-
lea de,ix+2 ; de -> sprite data
4615-
ex (sp),ix ; restore stack frame
4610+
ld de,(iy+6) ; de -> sprite data
4611+
push de
4612+
inc de
4613+
ld (de),a ; store height
4614+
ld iyh, a
4615+
; inc de ; use the inc de inside the loop instead
46164616
.loop:
4617-
ld b,0
4618-
.width := $-1
4619-
ld c,a
4617+
ld b,c ; width
46204618
.pixelloop:
46214619
dec hl
4620+
inc de
46224621
ld a,(hl)
46234622
ld (de),a ; store the new pixel data
4624-
inc de
46254623
djnz .pixelloop
4626-
ld a,c
4627-
ld bc,0
4628-
.delta := $-3
4624+
; hl += delta * 2
46294625
add hl,bc
4630-
dec a
4626+
add hl,bc
4627+
dec iyh
46314628
jr nz,.loop
46324629
pop hl
4630+
ld (hl),c ; store width (the loop preserves c)
46334631
ret
46344632

46354633
;-------------------------------------------------------------------------------
46364634
gfx_FlipSpriteX:
4637-
; Flip a sprite vertically about the center horizontal axis
4635+
; Flips a sprite vertically about the center horizontal axis
46384636
; Arguments:
46394637
; arg0 : Pointer to sprite struct input
46404638
; arg1 : Pointer to sprite struct output
46414639
; Returns:
46424640
; arg1 : Pointer to sprite struct output
4643-
ld iy,0
4644-
add iy,sp
4645-
push ix
4646-
ld ix,(iy+3)
4647-
xor a,a
4648-
sub a,(ix+0)
4649-
ld (.delta),a
4650-
neg
4651-
ld (.width),a
4652-
ld l,(ix+1)
4653-
ld c,l
4654-
dec l
4655-
ld h,a
4656-
mlt hl
4657-
lea de,ix+2
4658-
add hl,de
4659-
ld ix,(iy+6)
4660-
ld (ix+0),a
4661-
ld (ix+1),c
4662-
lea de,ix+2
4663-
push ix
4641+
ld iy, 6
4642+
lea hl, iy
4643+
ld c, l ; prevent underflow from ldi
4644+
add hl, sp
4645+
ld de, (hl)
4646+
push de ; return value
4647+
dec hl
4648+
dec hl
4649+
dec hl
4650+
ld hl, (hl)
4651+
4652+
xor a, a
4653+
ld b, (hl)
4654+
sub a, b
4655+
ld (.delta), a
4656+
ld iyl, b ; (.width)
4657+
ldi ; copy width
4658+
4659+
ld a, (hl)
4660+
ld c, a
4661+
ldi ; copy height (and decrement C)
4662+
4663+
mlt bc
4664+
add hl, bc
46644665
.loop:
4665-
ld bc,0
4666-
.width := $-3
4666+
lea bc, iy ; (.width)
46674667
ldir
4668-
ld bc,-1
4669-
.delta := $-3
4670-
add hl,bc
4671-
add hl,bc
4668+
dec bc ; ld bc, -1
4669+
ld c, -1
4670+
.delta := $-1
4671+
add hl, bc
4672+
add hl, bc
46724673
dec a
4673-
jr nz,.loop
4674+
jr nz, .loop
46744675
pop hl
4675-
pop ix
46764676
ret
46774677

46784678
;-------------------------------------------------------------------------------
46794679
gfx_RotateSpriteC:
4680-
; Rotates an array 90 degress clockwise
4680+
; Rotates a sprite 90 degress clockwise
46814681
; Arguments:
46824682
; arg0 : Pointer to sprite struct input
46834683
; arg1 : Pointer to sprite struct output
@@ -4758,29 +4758,33 @@ gfx_RotateSpriteCC:
47584758

47594759
;-------------------------------------------------------------------------------
47604760
gfx_RotateSpriteHalf:
4761-
; Rotates an array 180 degrees
4761+
; Rotates a sprite 180 degrees
47624762
; Arguments:
47634763
; arg0 : Pointer to sprite struct input
47644764
; arg1 : Pointer to sprite struct output
47654765
; Returns:
47664766
; arg1 : Pointer to sprite struct output
4767-
ld iy,0
4768-
add iy,sp
4769-
ld hl,(iy+3)
4770-
ld c,(hl) ; c = width
4767+
ld hl, 6
4768+
add hl, sp
4769+
ld de, (hl) ; output sprite
4770+
dec hl
4771+
dec hl
4772+
dec hl
4773+
ld hl, (hl) ; input sprite
4774+
ld c, (hl) ; c = width
47714775
inc hl
4772-
ld b,(hl) ; b = height
4773-
ld iy,(iy+6)
4774-
ld (iy+0),bc
4776+
ld b, (hl) ; b = height
4777+
ex de, hl
4778+
ld (hl), bc
4779+
ex de, hl
47754780
mlt bc
4776-
add hl,bc
4777-
lea de,iy
4781+
add hl, bc
47784782
push de
47794783
.loop:
47804784
inc de
47814785
inc de
47824786
ldd
4783-
jp pe,.loop
4787+
jp pe, .loop
47844788
pop hl
47854789
ret
47864790

0 commit comments

Comments
 (0)