@@ -4584,98 +4584,98 @@ d_18: ld bc,(ix-17)
4584
4584
4585
4585
;-------------------------------------------------------------------------------
4586
4586
gfx_FlipSpriteY:
4587
- ; Flips an array horizontally about the center vertical axis
4587
+ ; Flips a sprite horizontally about the center vertical axis
4588
4588
; Arguments:
4589
4589
; arg0 : Pointer to sprite struct input
4590
4590
; arg1 : Pointer to sprite struct output
4591
4591
; Returns:
4592
4592
; arg1 : Pointer to sprite struct output
4593
4593
ld iy , 0
4594
4594
add iy , sp
4595
- push ix
4596
- ld ix , (iy + 3 )
4597
- ld a , (ix + 0 ) ; a = width of sprite
4595
+ ld de , (iy + 3 )
4596
+ ld a , (de) ; a = width of sprite
4597
+ inc .s bc ; clear UBC
4598
+
4598
4599
sbc hl , hl
4599
4600
ld l , a
4600
4601
ld c , a
4601
- push hl
4602
- ld (.width) , a
4603
- add hl , hl
4604
- ld (.delta) , hl ; width*2
4605
- ld a , (ix + 1 ) ; a = height of sprite
4606
- pop hl
4607
- lea de , ix + 2
4602
+
4603
+ inc de
4604
+ ld a , (de) ; a = height of sprite
4605
+
4606
+ inc de
4608
4607
add hl , de
4609
- ld ix , (iy + 6 )
4610
- ld (ix + 1 ) , a ; store height to width
4611
- ld (ix + 0 ) , c ; store width to height
4612
- lea de , ix + 2 ; de -> sprite data
4613
- ex ( sp ) , ix ; restore stack frame
4608
+ ld de , (iy + 6 ) ; de -> sprite data
4609
+ push de
4610
+ inc de
4611
+ ld (de) , a ; store height
4612
+ ld iyh , a
4613
+ ; inc de ; use the inc de inside the loop instead
4614
4614
. loop :
4615
- ld b , 0
4616
- .width := $ - 1
4617
- ld c , a
4615
+ ld b , c ; width
4618
4616
.pixelloop:
4619
4617
dec hl
4618
+ inc de
4620
4619
ld a , (hl)
4621
4620
ld (de) , a ; store the new pixel data
4622
- inc de
4623
4621
djnz .pixelloop
4624
- ld a , c
4625
- ld bc , 0
4626
- .delta := $ - 3
4622
+ ; hl += delta * 2
4627
4623
add hl , bc
4628
- dec a
4624
+ add hl , bc
4625
+ dec iyh
4629
4626
jr nz , . loop
4630
4627
pop hl
4628
+ ld (hl) , c ; store width (the loop preserves c)
4631
4629
ret
4632
4630
4633
4631
;-------------------------------------------------------------------------------
4634
4632
gfx_FlipSpriteX:
4635
- ; Flip a sprite vertically about the center horizontal axis
4633
+ ; Flips a sprite vertically about the center horizontal axis
4636
4634
; Arguments:
4637
4635
; arg0 : Pointer to sprite struct input
4638
4636
; arg1 : Pointer to sprite struct output
4639
4637
; Returns:
4640
4638
; arg1 : Pointer to sprite struct output
4641
- ld iy , 0
4642
- add iy , sp
4643
- push ix
4644
- ld ix , (iy + 3 )
4645
- xor a , a
4646
- sub a , (ix + 0 )
4647
- ld (.delta) , a
4648
- neg
4649
- ld (.width) , a
4650
- ld l , (ix + 1 )
4651
- ld c , l
4652
- dec l
4653
- ld h , a
4654
- mlt hl
4655
- lea de , ix + 2
4656
- add hl , de
4657
- ld ix , (iy + 6 )
4658
- ld (ix + 0 ) , a
4659
- ld (ix + 1 ) , c
4660
- lea de , ix + 2
4661
- push ix
4639
+ ld iy , 6
4640
+ lea hl , iy
4641
+ ld c , l ; prevent underflow from ldi
4642
+ add hl , sp
4643
+ ld de , (hl)
4644
+ push de ; return value
4645
+ dec hl
4646
+ dec hl
4647
+ dec hl
4648
+ ld hl , (hl)
4649
+
4650
+ xor a , a
4651
+ ld b , (hl)
4652
+ sub a , b
4653
+ ld (.delta) , a
4654
+ ld iyl , b ; (.width)
4655
+ ldi ; copy width
4656
+
4657
+ ld a , (hl)
4658
+ ld c , a
4659
+ ldi ; copy height (and decrement C)
4660
+
4661
+ mlt bc
4662
+ add hl , bc
4662
4663
. loop :
4663
- ld bc , 0
4664
- .width := $ - 3
4664
+ lea bc , iy ; (.width)
4665
4665
ldir
4666
- ld bc ,- 1
4667
- .delta := $ - 3
4668
- add hl , bc
4669
- add hl , bc
4666
+ dec bc ; ld bc, -1
4667
+ ld c , - 1
4668
+ .delta := $ - 1
4669
+ add hl , bc
4670
+ add hl , bc
4670
4671
dec a
4671
- jr nz , . loop
4672
+ jr nz , .loop
4672
4673
pop hl
4673
- pop ix
4674
4674
ret
4675
4675
4676
4676
;-------------------------------------------------------------------------------
4677
4677
gfx_RotateSpriteC:
4678
- ; Rotates an array 90 degress clockwise
4678
+ ; Rotates a sprite 90 degress clockwise
4679
4679
; Arguments:
4680
4680
; arg0 : Pointer to sprite struct input
4681
4681
; arg1 : Pointer to sprite struct output
@@ -4756,29 +4756,33 @@ gfx_RotateSpriteCC:
4756
4756
4757
4757
;-------------------------------------------------------------------------------
4758
4758
gfx_RotateSpriteHalf:
4759
- ; Rotates an array 180 degrees
4759
+ ; Rotates a sprite 180 degrees
4760
4760
; Arguments:
4761
4761
; arg0 : Pointer to sprite struct input
4762
4762
; arg1 : Pointer to sprite struct output
4763
4763
; Returns:
4764
4764
; arg1 : Pointer to sprite struct output
4765
- ld iy , 0
4766
- add iy , sp
4767
- ld hl , (iy + 3 )
4768
- ld c , (hl) ; c = width
4765
+ ld hl , 6
4766
+ add hl , sp
4767
+ ld de , (hl) ; output sprite
4768
+ dec hl
4769
+ dec hl
4770
+ dec hl
4771
+ ld hl , (hl) ; input sprite
4772
+ ld c , (hl) ; c = width
4769
4773
inc hl
4770
- ld b , (hl) ; b = height
4771
- ld iy , (iy + 6 )
4772
- ld (iy + 0 ) , bc
4774
+ ld b , (hl) ; b = height
4775
+ ex de , hl
4776
+ ld (hl) , bc
4777
+ ex de , hl
4773
4778
mlt bc
4774
- add hl , bc
4775
- lea de , iy
4779
+ add hl , bc
4776
4780
push de
4777
4781
. loop :
4778
4782
inc de
4779
4783
inc de
4780
4784
ldd
4781
- jp pe , . loop
4785
+ jp pe , .loop
4782
4786
pop hl
4783
4787
ret
4784
4788
0 commit comments