Skip to content

Commit e5cef12

Browse files
committed
optimized the inner rotate-scale loop by 1F by changing ld b, 0 to ld b, reg8
1 parent e09e9e9 commit e5cef12

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

src/graphx/graphx.asm

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4904,13 +4904,18 @@ _RotatedScaledSprite_NoClip:
49044904
push ix
49054905
; aligning ix with gfx_RotateScaleSprite allows for code sharing
49064906
ld ix, 3
4907+
lea bc, ix - 3 ; ld bc, 0
49074908
add ix, sp
49084909
ld hl, (ix + 3) ; sprite pointer
4909-
ld a, (hl)
4910-
ld (ix + 16), a ; store sprite size
4910+
ld b, (hl)
4911+
ld (ix + 16), b ; store sprite size
49114912
inc hl
49124913
inc hl
49134914

4915+
; or a, a ; carry already cleared
4916+
dec b
4917+
sbc hl, bc ; offset the sprite pointer by (size - 1) * 256
4918+
49144919
ld (iy + (.dsrs_sprptr_0A - .dsrs_base_address)), hl ; write smc
49154920
ld (iy + (.dsrs_sprptr_0B - .dsrs_base_address)), hl ; write smc
49164921

@@ -5060,7 +5065,7 @@ _RotatedScaledSprite_NoClip:
50605065
ld l, a
50615066
inc l
50625067
mlt hl
5063-
ld b, 0
5068+
ld b, a ; A is a known constant that we can compensate for
50645069
; result is at most 255 * 255 + 255 or 65279. Make sure UBC is zero
50655070
add hl, bc ; y * size + x
50665071

@@ -5117,7 +5122,7 @@ _RotatedScaledSprite_NoClip:
51175122
.dsrs_jump_2 := $-1
51185123
inc l
51195124
mlt hl
5120-
ld b, 0
5125+
ld b, a ; A is a known constant that we can compensate for
51215126
; result is at most 255 * 255 + 255 or 65279. Make sure UBC is zero
51225127
add hl, bc ; y * size + x
51235128

@@ -5166,14 +5171,21 @@ gfx_RotateScaleSprite:
51665171
; arg1 : Pointer to sprite struct output
51675172
push ix
51685173
ld ix, 0
5174+
lea bc, ix + 0 ; ld bc, 0
51695175
add ix, sp
51705176
ld iy, _smc_dsrs_base_address
51715177
ld hl, (ix + 6) ; sprite pointer
5172-
ld a, (hl)
5173-
ld (ix + 16), a ; store sprite size
5178+
ld b, (hl)
5179+
ld (ix + 16), b ; store sprite size
51745180
inc hl
51755181
inc hl
5182+
5183+
; or a, a ; carry already cleared
5184+
dec b
5185+
sbc hl, bc ; offset the sprite pointer by (size - 1) * 256
5186+
51765187
ld (iy + (_smc_dsrs_sprptr_0 - _smc_dsrs_base_address)), hl ; write smc
5188+
51775189
; sinf = _SineTable[angle] * 128 / scale;
51785190
ld a, (ix + 12) ; angle
51795191
call calcSinCosSMC
@@ -5297,6 +5309,7 @@ gfx_RotateScaleSprite:
52975309

52985310
; UBC was set to zero from mlt bc awhile back
52995311
jr drawSpriteRotateScale_Begin
5312+
53005313
;-------------------------------------------------------------------------------
53015314
_yloop:
53025315
ld bc, $000000 ; smc = cosf
@@ -5322,7 +5335,7 @@ _xloop:
53225335
ld l, a
53235336
inc l
53245337
mlt hl
5325-
ld b, 0
5338+
ld b, a ; A is a known constant that we can compensate for
53265339
; result is at most 255 * 255 + 255 or 65279. Make sure UBC is zero
53275340
add hl, bc ; y * size + x
53285341

0 commit comments

Comments
 (0)