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 > How easy is it to calculate sine tables from the bare bones in ML?
2008-08-05 09:52
Conrad

Registered: Nov 2006
Posts: 849
How easy is it to calculate sine tables from the bare bones in ML?

Hi!

I'd like to have a go at coding my own routine of calculating sine/cosine tables without use of the BASIC interpreters (pi, sin(), etc) and just use pure ML instead.

Can I ask, how easy (or how SMALL) is this to do? Do I need to do additional algorithms like factorial or are there KERNAL routines for that (if any)? Multiplication code is no problem as I've seen articles on those, I'm just thinking about the rest of math involved with sine calculation.

Thanx in advance.
2008-08-05 10:22
enthusi

Registered: May 2004
Posts: 677
Im probably the wrong person to answer this :)
but you can easyly abuse the BASIC routines in ML as well. Just set up the FAC etc adresses and launch the routines.

OR if you want it really basic withou BASIC routines you can do the Taylor-approach
sin(x)=x-1/x^3+1/x^5 etc.

There probably smarter ways around though *g*
2008-08-05 10:25
doynax
Account closed

Registered: Oct 2004
Posts: 212
You can generate a sine wave iteratively easily enough. Basically you just massage the trigonometric product formula a bit..
sin(x - y) + sin(x + y) = 2 * sin x * cos y <=>
sin(x + y) = 2 * sin x * cos y - sin(x - y)
Where 'y' is your step and x is the index being calculated. In other words we end up basing the next sine on the previous two, through a multiplication by a constant and a subtraction.
k = 2 * cos d

sin[i + d] = sin[i] * k - sin[i - d]
Now I guess if you apply a scaling/steps width such that the constant becomes a nice simple power-of-two then this could be implemented with less code then invoking the basic ROM functions.
Please note that it takes quite a bit of fixed-point precision to get decent values, and you may want to consider exploiting a bit of symmetry to generate the rest of the table from the first quadrant or so.
2008-08-05 10:34
Skate

Registered: Jul 2003
Posts: 494
There are some 256b intros with source code which generates sine tables. Check this one for example.

Too(C)o(M)p(L)ex

Of course try to learn it, not copy & paste it.
2008-08-05 10:38
Radiant

Registered: Sep 2004
Posts: 639
To avoid nasty multiplications you could approximate a circle using an accelerating vector. I think it was Zed Yago who suggested this solution on IRC some time ago, and it sounds good enough for me.
2008-08-05 10:58
Conrad

Registered: Nov 2006
Posts: 849
Thanks everyone for your help! I have a rough idea what to do now! :)

radiantx: what's an accelerating vector? Is it related to I/O registers or is a much more complex formula? Again, I could ask Yago myself :)
2008-08-05 11:02
WVL

Registered: Mar 2002
Posts: 902
Quote: Thanks everyone for your help! I have a rough idea what to do now! :)

radiantx: what's an accelerating vector? Is it related to I/O registers or is a much more complex formula? Again, I could ask Yago myself :)


I guess yago meant that you can approximate a sine with 2 parabolas, and to calculate those you only need to have an acceleration (which matches the amplitude and 'length' of the sine you want.)
2008-08-05 11:06
Cruzer

Registered: Dec 2001
Posts: 1048
@Skate: Too bad it's some ugly sines that are generated that way. It's really just a couple of reverse parabolas, which is not the same as a real sine.
2008-08-05 11:07
Conrad

Registered: Nov 2006
Posts: 849
Ah, now I get ya, after looking up on parabolas ;).
Thanks again, all! .... off to code.

cruzer: that's okay, quick'n'dirty is all I need.
2008-08-05 11:18
Shadow
Account closed

Registered: Apr 2002
Posts: 355
Anyone have an example on how to access the BASIC routines from asm to generate a sine? Also how compact is such a routine, are we talking like 50 bytes or 500 bytes?
2008-08-05 11:22
JackAsser

Registered: Jun 2002
Posts: 2014
Anything you come up with, plz write a small article about it and post it on codebase. Mkaytnku.
 
... 22 posts hidden. Click here to view all posts....
 
Previous - 1 | 2 | 3 | 4 - 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
LordCrass
Guests online: 84
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 Triad  (9.3)
5 Censor Design  (9.3)
Top Musicians
1 Rob Hubbard  (9.7)
2 Mutetus  (9.7)
3 Jeroen Tel  (9.7)
4 Linus  (9.6)
5 Stinsen  (9.6)

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