2016-03-27 16:47:28 +00:00
|
|
|
_Sine:: ; 84d9
|
|
|
|
; A simple sine function.
|
|
|
|
; Return d * sin(e) in hl.
|
|
|
|
|
|
|
|
; e is a signed 6-bit value.
|
|
|
|
ld a, e
|
|
|
|
and %111111
|
|
|
|
cp %100000
|
|
|
|
jr nc, .negative
|
|
|
|
call .ApplySineWave
|
|
|
|
ld a, h
|
|
|
|
ret
|
|
|
|
|
|
|
|
.negative
|
|
|
|
and %011111
|
|
|
|
call .ApplySineWave
|
|
|
|
ld a, h
|
2018-01-09 21:39:36 +00:00
|
|
|
xor $ff
|
2016-03-27 16:47:28 +00:00
|
|
|
inc a
|
|
|
|
ret
|
|
|
|
|
|
|
|
.ApplySineWave: ; 84ef
|
|
|
|
ld e, a
|
|
|
|
ld a, d
|
|
|
|
ld d, 0
|
|
|
|
ld hl, .sinewave
|
|
|
|
add hl, de
|
|
|
|
add hl, de
|
|
|
|
ld e, [hl]
|
|
|
|
inc hl
|
|
|
|
ld d, [hl]
|
|
|
|
ld hl, 0
|
|
|
|
; Factor amplitude
|
|
|
|
.multiply
|
|
|
|
srl a
|
|
|
|
jr nc, .even
|
|
|
|
add hl, de
|
|
|
|
.even
|
|
|
|
sla e
|
|
|
|
rl d
|
|
|
|
and a
|
|
|
|
jr nz, .multiply
|
|
|
|
ret
|
|
|
|
|
2016-04-10 19:01:49 +00:00
|
|
|
.sinewave ; 850b
|
2018-02-04 01:40:21 +00:00
|
|
|
; A 32-word table representing a sine wave.
|
|
|
|
; sin(90 degrees) is index $10 with an amplitude of $100.
|
2018-02-03 03:45:42 +00:00
|
|
|
sine_wave 32
|