a5f825852c52 — Laurens Holst 3 years ago
PSGTone/Noise/Envelope: Reduce the number of shifts done in Math_Pow2.
3 files changed, 11 insertions(+), 4 deletions(-)

M src/modules/PSGEnvelope.asm
M src/modules/PSGNoise.asm
M src/modules/PSGTone.asm
M src/modules/PSGEnvelope.asm +5 -2
@@ 47,7 47,10 @@ PSGEnvelope: MACRO ?psg, ?channel, ?shap
 PSGEnvelope_GetPeriod:
 	ld hl,0AAABH  ; de = hl * (1 / 1.5)
 	muluw hl,bc
-	ld hl,-10773  ; (69 / 12 - log2(440) - log2(256) + log2(3579545) - 16) * 2048
+	ld hl,5611  ; (69 / 12 - log2(440) - log2(256) + log2(3579545) - 8) * 2048
 	and a
 	sbc hl,de
-	jp Math_Pow2
+	call Math_Pow2
+	ld l,h
+	ld h,e
+	ret

          
M src/modules/PSGNoise.asm +3 -1
@@ 33,10 33,12 @@ PSGNoise: MACRO ?psg, ?channel, ?key, ?k
 PSGNoise_GetPeriod:
 	ld hl,0AAABH  ; de = hl * (1 / 1.5)
 	muluw hl,bc
-	ld hl,-14869  ; (69 / 12 - 6 - log2(440) - log2(16) + log2(3579545) - 16) * 2048
+	ld hl,1515  ; (69 / 12 - 6 - log2(440) - log2(16) + log2(3579545) - 8) * 2048
 	and a
 	sbc hl,de
 	call Math_Pow2
+	ld l,h
+	ld h,e
 	ld a,l
 	and ~1FH
 	or h

          
M src/modules/PSGTone.asm +3 -1
@@ 49,10 49,12 @@ PSGTone: MACRO ?psg, ?channel, ?key, ?ke
 PSGTone_GetPeriod:
 	ld hl,0AAABH  ; de = hl * (1 / 1.5)
 	muluw hl,bc
-	ld hl,-2580  ; (69 / 12 - log2(440) - log2(16) + log2(3579545) - 16) * 2048
+	ld hl,13803  ; (69 / 12 - log2(440) - log2(16) + log2(3579545) - 8) * 2048
 	and a
 	sbc hl,de
 	call Math_Pow2
+	ld l,h
+	ld h,e
 	ld a,h
 	and ~0FH
 	ret z