Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > sin/cos table generator
2012-11-17 18:59
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.
 
... 10 posts hidden. Click here to view all posts....
 
2012-12-01 07:37
Graham
Account closed

Registered: Dec 2002
Posts: 990
Using parabolas as sines will look strange on other applications aswell. The first derivation of a "parabola-sine" would be a triangle wave which will definitely look less smooth than a real sine.
2012-12-01 12:01
Karoshier
Account closed

Registered: May 2010
Posts: 15
Perplex: oh well, the rotation with the parabola approximation you pointed out might be not as good as the one with the sine, but honestly I like the twist it adds to it :P
2012-12-16 17:49
Internium
Account closed

Registered: Feb 2012
Posts: 3
This could be also a good method to approximate a sine: http://devmaster.net/forums/topic/4648-fast-and-accurate-sineco.. They use the Maclaurin series.
Previous - 1 | 2 - Next
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
encore
Mike
ΛΛdZ
WVL/Xenon
MWR/Visdom
grennouille
deetsay
rime/Fancy Rats
Peacemaker/CENSOR/Hi..
Mibri/ATL^MSL^PRX
Guests online: 127
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 Edge of Disgrace  (9.6)
6 What Is The Matrix 2  (9.6)
7 The Demo Coder  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 No Listen  (9.6)
2 Layers  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 Dawnfall V1.1  (9.5)
7 Rainbow Connection  (9.5)
8 Onscreen 5k  (9.5)
9 Morph  (9.5)
10 Libertongo  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Censor Design  (9.3)
5 Triad  (9.3)
Top Logo Graphicians
1 t0m3000  (10)
2 Sander  (9.8)
3 Mermaid  (9.5)
4 Facet  (9.4)
5 Shine  (9.4)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.032 sec.