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.
 
... 3 posts hidden. Click here to view all posts....
 
2012-11-26 17:51
Skate

Registered: Jul 2003
Posts: 491
Most of you already know that but i'd like to remind again. When it comes to 256 bytes, there is no "best/shortest" sine table generator routine. It depends on the effect and the "other parts" of the code. I usually merge some other stuff with sine calculation. So, when you check sine calculation block, it can be over 40 bytes but doing more than just sine calculation. Of course base method is important but even if your routine is under 30 bytes, sometimes some other 40+ bytes routine might result a smaller sized effect. That happened to me at least twice. So, don't forget to check all known methods with your 256b effect or it may never reach 256b limit. ;)
2012-11-26 18:09
Burglar

Registered: Dec 2004
Posts: 1033
for a pseudo sine, check You Can't Process This REM Statement with a Normal Brain by cruzer
2012-11-30 10:31
Perplex

Registered: Feb 2009
Posts: 254
Quoting Burglar
for a pseudo sine, check You Can't Process This REM Statement with a Normal Brain by cruzer


Indeed, a parabola is pretty close to a sine curve, and suitable for many demo effects.

http://6581.no/sine_vs_parabola.png
2012-11-30 11:22
Oswald

Registered: Apr 2002
Posts: 5023
well, nobody cares if its a sine or just some nice curve anyway :) except.. I'm wondering how a sine table made of parabolas would affect a 3d rotation. :)
2012-11-30 11:49
enthusi

Registered: May 2004
Posts: 675
Your vectors would just wobble and vary in length between rotation steps.
2012-11-30 11:52
chatGPZ

Registered: Dec 2001
Posts: 11136
so it wouldnt be a big difference for most routines =)
2012-11-30 15:13
Perplex

Registered: Feb 2009
Posts: 254
Quoting Oswald
well, nobody cares if its a sine or just some nice curve anyway :) except.. I'm wondering how a sine table made of parabolas would affect a 3d rotation. :)


http://6581.no/plotball-sine.html

http://6581.no/plotball-parabola.html

Conclusion: don't use parabolas for rotations.
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
Tchad/Jam
Clayboy
Menace/Spaceballs
Herrera64
Viti/Hokuto Force
bOOZElEE
Frostbyte/Artline De..
Twilight/Excess/Arcade
Guests online: 104
Top Demos
1 Next Level  (9.8)
2 Mojo  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Comaland 100%  (9.6)
6 No Bounds  (9.6)
7 Uncensored  (9.6)
8 Wonderland XIV  (9.6)
9 Memento Mori  (9.6)
10 Bromance  (9.5)
Top onefile Demos
1 It's More Fun to Com..  (9.7)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.5)
5 TRSAC, Gabber & Pebe..  (9.5)
6 Rainbow Connection  (9.5)
7 Dawnfall V1.1  (9.5)
8 Quadrants  (9.5)
9 Daah, Those Acid Pil..  (9.5)
10 Birth of a Flower  (9.5)
Top Groups
1 Nostalgia  (9.3)
2 Oxyron  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 Crest  (9.3)
Top Logo Graphicians
1 Sander  (9.9)
2 Facet  (9.6)
3 Mermaid  (9.4)
4 Pal  (9.4)
5 Shine  (9.3)

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