Rudi Account closed
Registered: May 2010 Posts: 125 |
sin/cos table generator
this is my sine table generator:
for(;x<256;){a+=b;b+=c;*s++=0xf-((a+t)>>3);x++==127?c=-c:0;}
not implemented on c64 yet.
it is harmonic oscillator based on simple physics.
a and b are initial seeds.
this one will work on 8-bit with a little offset-tweaking,
between the region[0..59] where x+=95 and y+=22.
the drawback is its amplitude will be something like -16 -> 16.
tweaking might be required. or an additional byte for bigger values.
i found some interesting areas while running through all possible states for b and c regions (total 65536 states) but none of them where perfect.
the table (after offsetting) looks something like this:
9,11,13,15,16,18,19,21,22,23,24,25,26,26,27,27,28,28,28,28,27,27,26,26,25,24,23, 22,21,19,18,16,15,13,11,9,8,6,5,4,3,2,1,1,0,0,0,0,0,0,0,0,1,1,2,3,4,5,6
i want to fit the code as tiny as possible
the code would probably more or less look something like this;
in loop:
adc b
pha
lda b
adc c
pha
lda #$f
sbc (a+t) ror,3
inx
cpx #127
beq chg_sign
sta [table]
of course this would not be usable for a demo.
but intros in 256b size or less, i hope it might bring some ideas if anyone is interested.
im not sure if my code is very useable but just too give you an idea. if anyone know any other/better tricks please let me know. im kind of tired, i wish there could be another byte to increase the sine-amplitude resolution. |