Skip to content

Commit 75eec43

Browse files
committed
reduced SMC useage in _RotateScaleSprite
1 parent a7eddd1 commit 75eec43

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

src/graphx/graphx.asm

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5177,7 +5177,7 @@ gfx_RotateScaleSprite:
51775177
; sinf = _SineTable[angle] * 128 / scale;
51785178
ld a, (ix + 12) ; angle
51795179
call calcSinCosSMC
5180-
push hl ; ld (ix - 3), _smc_dsrs_sinf_1_plus_offset_ix
5180+
push hl ; ld (ix - 3), _smc_dsrs_sinf_1_plus_offset_ix
51815181
; ld (_smc_dsrs_sinf_1_plus_offset_ix),hl ; write smc
51825182

51835183
; The previous code does ~HL instead of -HL. Unsure if intentional.
@@ -5216,12 +5216,12 @@ gfx_RotateScaleSprite:
52165216

52175217
; carry is cleared here
52185218
ld de, (ix - 6) ; dsrs_dys_0
5219-
sbc.s hl, de ; make sure UHL is zero
5220-
ld (iy + (_smc_dsrs_size128_1_minus_dys_0 - _smc_dsrs_base_address)), hl ; write smc
5219+
sbc hl, de
5220+
push hl ; ld (ix - 12), _smc_dsrs_size128_1_minus_dys_0
52215221
add hl, de ; restore HL
52225222
ld de, (ix - 9) ; dsrs_dyc_0
52235223
add hl, de
5224-
ld (iy + (_smc_dsrs_size128_0_plus_dyc_0 - _smc_dsrs_base_address)), hl ; write smc
5224+
push hl ; ld (ix - 15), _smc_dsrs_size128_0_plus_dyc_0
52255225
; carry might be set, but that shouldn't matter for rl c
52265226

52275227
ld a, b
@@ -5246,7 +5246,7 @@ gfx_RotateScaleSprite:
52465246
ld a, d
52475247
add a, l
52485248
ld d, a
5249-
ld hl, (ix - 3)
5249+
ld hl, (ix - 3) ; _smc_dsrs_sinf_1_plus_offset_ix
52505250
or a, a
52515251
sbc.s hl, de ; make sure UHL is zero
52525252
ld (iy + (_smc_dsrs_sinf_1_plus_offset_ix - _smc_dsrs_base_address)), hl
@@ -5274,29 +5274,34 @@ gfx_RotateScaleSprite:
52745274
ld iy, (ix + 9) ; sprite storing to
52755275
ld b, c
52765276
ld (iy + 0), bc
5277-
lea de, iy + 2
52785277

5278+
; by popping these off the stack in a werid way, we can reduce SMC useage
5279+
5280+
pop ix ; _smc_dsrs_size128_0_plus_dyc_0
5281+
pop de ; _smc_dsrs_size128_1_minus_dys_0
52795282
pop hl ; smc = dxc start
5280-
pop ix ; smc = dxs start
52815283

5282-
ex (sp), iy ; pop reg24 \ push iy
5284+
; ys = (dxc - dys) + (size * 128)
5285+
add hl, de ; HL = (dxc - dys) + (size * 128)
52835286

5284-
ld iyh, c ; size * scale / 64
5287+
pop de ; smc = dxs start
52855288

5286-
ld bc, $000000 ; xs = (dxs + dyc) + (size * 128)
5287-
_smc_dsrs_size128_0_plus_dyc_0 := $-3
5288-
_smc_dsrs_base_address := _smc_dsrs_size128_0_plus_dyc_0
5289-
add ix, bc ; de = (dxs + dyc) + (size * 128)
5289+
; xs = (dxs + dyc) + (size * 128)
5290+
add ix, de ; IX = (dxs + dyc) + (size * 128)
52905291

5291-
ld bc, $000000 ; ys = (dxc - dys) + (size * 128)
5292-
_smc_dsrs_size128_1_minus_dys_0 := $-3
5293-
add hl, bc ; hl = (dxc - dys) + (size * 128)
5292+
lea de, iy + 2
5293+
5294+
ex (sp), iy ; pop reg24 \ push iy
5295+
5296+
ld iyh, c ; size * scale / 64
52945297

5298+
; UBC was set to zero from mlt bc awhile back
52955299
jr drawSpriteRotateScale_Begin
52965300
;-------------------------------------------------------------------------------
52975301
_yloop:
52985302
ld bc, $000000 ; smc = cosf
52995303
_smc_dsrs_cosf_1_plus_offset_hl := $-3
5304+
_smc_dsrs_base_address := _smc_dsrs_cosf_1_plus_offset_hl
53005305
add hl, bc ; dxc += cosf
53015306

53025307
ld bc, $000000 ; smc = sinf

0 commit comments

Comments
 (0)