Skip to content

Instantly share code, notes, and snippets.

@lhz
Last active March 26, 2018 10:04
Show Gist options
  • Save lhz/db17064f21134607f7ea2b88aa61ce8f to your computer and use it in GitHub Desktop.
Save lhz/db17064f21134607f7ea2b88aa61ce8f to your computer and use it in GitHub Desktop.
Sine generator
SineGenerate:
lea Sine + 8, a0
move.l #$7FFF6216, d6 ; 2*cos(π/512) >> 2
move.l #253, d7
.Loop:
move.l -4(a0), d0 ; A = sin(i)
move.l d6, d1 ; B = 2*cos(π/512) >> 2
move.l d0, d2
move.l d1, d3
swap d2 ; d2.w = Ah
swap d3 ; d3.w = Bh
mulu.w d2, d1
lsr.l #7, d1
lsr.l #7, d1 ; d1.l = Ah*Bl >> 14
mulu.w d3, d0
lsr.l #7, d0
lsr.l #7, d0 ; d0.l = Al*Bh >> 14
mulu.w d2, d3
lsl.l #2, d3 ; d3.l = Ah*Bh << 2
add.l d0, d1
add.l d3, d1
sub.l -8(a0), d1 ; sin(i)*2*cos(π/512) - sin(i-1)
tst.l (a0)+ ; Skip precalculated value
bne.s .Skip
move.l d1, -4(a0)
.Skip:
dbf d7, .Loop
rts
Sine:
dc.l $00000000, $01921F0F ; sin(0), sin(π/512)
dcb.l 126, 0
dc.l $B504F333, $B6206B9E ; sin(π/4), sin(π/4 + π/512)
dcb.l 126, 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment