@@ -4586,98 +4586,98 @@ d_18: ld bc,(ix-17)
4586
4586
4587
4587
;-------------------------------------------------------------------------------
4588
4588
gfx_FlipSpriteY:
4589
- ; Flips an array horizontally about the center vertical axis
4589
+ ; Flips a sprite horizontally about the center vertical axis
4590
4590
; Arguments:
4591
4591
; arg0 : Pointer to sprite struct input
4592
4592
; arg1 : Pointer to sprite struct output
4593
4593
; Returns:
4594
4594
; arg1 : Pointer to sprite struct output
4595
4595
ld iy , 0
4596
4596
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
+
4600
4601
sbc hl , hl
4601
4602
ld l , a
4602
4603
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
4610
4609
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
4616
4616
. loop :
4617
- ld b , 0
4618
- .width := $ - 1
4619
- ld c , a
4617
+ ld b , c ; width
4620
4618
.pixelloop:
4621
4619
dec hl
4620
+ inc de
4622
4621
ld a , (hl)
4623
4622
ld (de) , a ; store the new pixel data
4624
- inc de
4625
4623
djnz .pixelloop
4626
- ld a , c
4627
- ld bc , 0
4628
- .delta := $ - 3
4624
+ ; hl += delta * 2
4629
4625
add hl , bc
4630
- dec a
4626
+ add hl , bc
4627
+ dec iyh
4631
4628
jr nz , . loop
4632
4629
pop hl
4630
+ ld (hl) , c ; store width (the loop preserves c)
4633
4631
ret
4634
4632
4635
4633
;-------------------------------------------------------------------------------
4636
4634
gfx_FlipSpriteX:
4637
- ; Flip a sprite vertically about the center horizontal axis
4635
+ ; Flips a sprite vertically about the center horizontal axis
4638
4636
; Arguments:
4639
4637
; arg0 : Pointer to sprite struct input
4640
4638
; arg1 : Pointer to sprite struct output
4641
4639
; Returns:
4642
4640
; 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
4664
4665
. loop :
4665
- ld bc , 0
4666
- .width := $ - 3
4666
+ lea bc , iy ; (.width)
4667
4667
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
4672
4673
dec a
4673
- jr nz , . loop
4674
+ jr nz , .loop
4674
4675
pop hl
4675
- pop ix
4676
4676
ret
4677
4677
4678
4678
;-------------------------------------------------------------------------------
4679
4679
gfx_RotateSpriteC:
4680
- ; Rotates an array 90 degress clockwise
4680
+ ; Rotates a sprite 90 degress clockwise
4681
4681
; Arguments:
4682
4682
; arg0 : Pointer to sprite struct input
4683
4683
; arg1 : Pointer to sprite struct output
@@ -4758,29 +4758,33 @@ gfx_RotateSpriteCC:
4758
4758
4759
4759
;-------------------------------------------------------------------------------
4760
4760
gfx_RotateSpriteHalf:
4761
- ; Rotates an array 180 degrees
4761
+ ; Rotates a sprite 180 degrees
4762
4762
; Arguments:
4763
4763
; arg0 : Pointer to sprite struct input
4764
4764
; arg1 : Pointer to sprite struct output
4765
4765
; Returns:
4766
4766
; 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
4771
4775
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
4775
4780
mlt bc
4776
- add hl , bc
4777
- lea de , iy
4781
+ add hl , bc
4778
4782
push de
4779
4783
. loop :
4780
4784
inc de
4781
4785
inc de
4782
4786
ldd
4783
- jp pe , . loop
4787
+ jp pe , .loop
4784
4788
pop hl
4785
4789
ret
4786
4790
0 commit comments