Skip to content

Commit 36388f3

Browse files
committed
reduced SMC useage in _RotateScaleSprite
1 parent 881b208 commit 36388f3

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
@@ -5176,7 +5176,7 @@ gfx_RotateScaleSprite:
51765176
; sinf = _SineTable[angle] * 128 / scale;
51775177
ld a, (ix + 12) ; angle
51785178
call calcSinCosSMC
5179-
push hl ; ld (ix - 3), _smc_dsrs_sinf_1_plus_offset_ix
5179+
push hl ; ld (ix - 3), _smc_dsrs_sinf_1_plus_offset_ix
51805180
; ld (_smc_dsrs_sinf_1_plus_offset_ix),hl ; write smc
51815181

51825182
; The previous code does ~HL instead of -HL. Unsure if intentional.
@@ -5214,12 +5214,12 @@ gfx_RotateScaleSprite:
52145214

52155215
; carry is cleared here
52165216
ld de, (ix - 6) ; dsrs_dys_0
5217-
sbc.s hl, de ; make sure UHL is zero
5218-
ld (iy + (_smc_dsrs_size128_1_minus_dys_0 - _smc_dsrs_base_address)), hl ; write smc
5217+
sbc hl, de
5218+
push hl ; ld (ix - 12), _smc_dsrs_size128_1_minus_dys_0
52195219
add hl, de ; restore HL
52205220
ld de, (ix - 9) ; dsrs_dyc_0
52215221
add hl, de
5222-
ld (iy + (_smc_dsrs_size128_0_plus_dyc_0 - _smc_dsrs_base_address)), hl ; write smc
5222+
push hl ; ld (ix - 15), _smc_dsrs_size128_0_plus_dyc_0
52235223
; carry might be set, but that shouldn't matter for rl c
52245224

52255225
ld a, b
@@ -5244,7 +5244,7 @@ gfx_RotateScaleSprite:
52445244
ld a, d
52455245
add a, l
52465246
ld d, a
5247-
ld hl, (ix - 3)
5247+
ld hl, (ix - 3) ; _smc_dsrs_sinf_1_plus_offset_ix
52485248
or a, a
52495249
sbc.s hl, de ; make sure UHL is zero
52505250
ld (iy + (_smc_dsrs_sinf_1_plus_offset_ix - _smc_dsrs_base_address)), hl
@@ -5272,29 +5272,34 @@ gfx_RotateScaleSprite:
52725272
ld iy, (ix + 9) ; sprite storing to
52735273
ld b, c
52745274
ld (iy + 0), bc
5275-
lea de, iy + 2
52765275

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

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

5282-
ld iyh, c ; size * scale / 64
5285+
pop de ; smc = dxs start
52835286

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

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

5296+
; UBC was set to zero from mlt bc awhile back
52935297
jr drawSpriteRotateScale_Begin
52945298
;-------------------------------------------------------------------------------
52955299
_yloop:
52965300
ld bc, $000000 ; smc = cosf
52975301
_smc_dsrs_cosf_1_plus_offset_hl := $-3
5302+
_smc_dsrs_base_address := _smc_dsrs_cosf_1_plus_offset_hl
52985303
add hl, bc ; dxc += cosf
52995304

53005305
ld bc, $000000 ; smc = sinf

0 commit comments

Comments
 (0)