Propeller Manual

Table Of Contents
Appendix B: Math Samples and Function Tables
Propeller Manual v1.1 · Page 385
Sine Table ($E000-$F001)
The sine table provides 2,049 unsigned 16-bit sine samples spanning from 0° to 90°,
inclusively (0.0439° resolution).
A small amount of assembly code can mirror and flip the sine table samples to create a full-
cycle sine/cosine lookup routine that has 13-bit angle resolution and 17-bit sample resolution:
' Get sine/cosine
'
' quadrant: 1 2 3 4
' angle: $0000..$07FF $0800..$0FFF $1000..$17FF $1800..$1FFF
' table index: $0000..$07FF $0800..$0001 $0000..$07FF $0800..$0001
' mirror: +offset -offset +offset -offset
' flip: +sample +sample -sample -sample
'
' on entry: sin[12..0] holds angle (0° to just under 360°)
' on exit: sin holds signed value ranging from $0000FFFF ('1') to
' $FFFF0001 ('-1')
'
getcos add sin,sin_90 'for cosine, add 90°
getsin test sin,sin_90 wc 'get quadrant 2|4 into c
test sin_sin_180 wz 'get quadrant 3|4 into nz
negc sin,sin 'if quadrant 2|4, negate offset
or sin,sin_table 'or in sin table address >> 1
shl sin,#1 'shift left to get final word address
rdword sin,sin 'read word sample from $E000 to $F000
negnz sin,sin 'if quadrant 3|4, negate sample
getsin_ret
getcos_ret ret '39..54 clocks
'(variance due to HUB sync on RDWORD)
sin_90 long $0800
sin_180 long $1000
sin_table long $E000 >> 1 'sine table base shifted right
sin long 0
As with the log and anti-log tables, linear interpolation could be applied to the sine table to
achieve higher resolution.