Macro factors out sine code, just like sine data, since it's used 5 times

This commit is contained in:
Rangi
2018-02-03 21:11:55 -05:00
parent 271aa20b73
commit 73ea7c6326
9 changed files with 127 additions and 411 deletions

View File

@@ -52,3 +52,50 @@ endc
endr
and x
ENDM
calc_sine_wave: MACRO
; input: a = a signed 6-bit value
; output: a = d * sin(a * pi/32)
and %111111
cp %100000
jr nc, .negative\@
call .apply\@
ld a, h
ret
.negative\@
and %011111
call .apply\@
ld a, h
xor $ff
inc a
ret
.apply\@
ld e, a
ld a, d
ld d, 0
if _NARG == 1
ld hl, \1
else
ld hl, .sinetable\@
endc
add hl, de
add hl, de
ld e, [hl]
inc hl
ld d, [hl]
ld hl, 0
.multiply\@ ; factor amplitude
srl a
jr nc, .even\@
add hl, de
.even\@
sla e
rl d
and a
jr nz, .multiply\@
ret
if _NARG == 0
.sinetable\@
sine_table 32
endc
ENDM

View File

@@ -111,7 +111,15 @@ menu_coords: MACRO
ENDM
sine_wave: MACRO
bcd: MACRO
rept _NARG
dn ((\1) % 100) / 10, (\1) % 10
shift
endr
ENDM
sine_table: MACRO
; \1 samples of sin(x) from x=0 to x<32768 (pi radians)
x = 0
rept \1
@@ -119,11 +127,3 @@ rept \1
x = x + DIV(32768, \1) ; a circle has 65536 "degrees"
endr
ENDM
bcd: MACRO
rept _NARG
dn ((\1) % 100) / 10, (\1) % 10
shift
endr
ENDM