| |
Flavioweb
Registered: Nov 2011 Posts: 463 |
assembly sin gen code request
i need a code (assembly) to gen sin table. I need to set start, end and step value. Someone could help? |
|
| |
iAN CooG
Registered: May 2002 Posts: 3194 |
http://codebase64.org/doku.php?id=base:6502_6510_maths
anyway I'd use wixbouncer or other sintable generators and include the generated table, unless you're going to make a 256byte intro |
| |
Style
Registered: Jun 2004 Posts: 498 |
wouldnt you be better off generating the table in BASIC before running the demo or whatever?
|
| |
Flavioweb
Registered: Nov 2011 Posts: 463 |
is better to have pre-calculated sin, but i want to write my own routine first for learning purpose then to make my code stand alone easy reusable simply changing some bytes... |
| |
tlr
Registered: Sep 2003 Posts: 1790 |
You could use the kernal routines to implement basic-like generation of sine.
Faster would be to use a fixed point implementation of the MacLaurin series of sin(x).
Faster yet would be something like this: http://codebase64.org/doku.php?id=base:generating_approximate_s..
|
| |
iAN CooG
Registered: May 2002 Posts: 3194 |
I already linked the section on codebase64, but went unnoticed I think =) |
| |
ChristopherJam
Registered: Aug 2004 Posts: 1409 |
CORDIC might be an interesting way to go.
There's a decent article on Wikipedia, but basically you start with a vector pointing along the X axis and perform a set series of rotation+scales using matrices whose components are all either 1 or a power of two. Each step you accumulate the angle you've rotated so far (fixed point addition of constant from very small table), and step either CW or CCW, depending if you've currently overshot. The angles get successively smaller, so it's close to a binary search. Total scale factor is a constant, so you can prescale your start vector by the inverse.
You could get away with only two or three distinct step sizes (and hence just hard code 2 or 3 shift amounts) if you were willing to do some extra iterations (say 20 large steps, 20 small).
Thoughts? |
| |
Achim Account closed
Registered: Jan 2010 Posts: 28 |
If you only need some sin-tables: Sinus Creator V2.0 |
| |
Skate
Registered: Jul 2003 Posts: 494 |
I usually choose one of the suggestions above but maybe bresenham's circle algorithm, mid point algorithm or a mixture like below may help you to generate a sine table. if you can draw a circle, you can generate a sine table using one of the x or y coordinates, right? The only problem I see here is not being able to get a certain table length but maybe this can be solved somehow.
http://willperone.net/Code/codecircle.php
Edit: @ChristopherJam: I just checked CORDIC and it looks like a good fit. I didn't know about it before. Thanks for sharing. |
| |
ChristopherJam
Registered: Aug 2004 Posts: 1409 |
@Skate You're welcome.
I've a feeling it was John West (he who co-authored 64doc with Marko Mäkelä) who originally suggested I check it out, some 20 years ago now. I'd forgotten how it worked until I looked it up again for this post. |
| |
ChristopherJam
Registered: Aug 2004 Posts: 1409 |
Hmm, the problem with using Bresenham is each pixel generated is at a constant x-increment from the one before, rather than a constant theta-increment.
However, I was wondering if perhaps you could use something Bresehnham-like to normalise the result of repeatedly doing a fixed rotation, that might otherwise drift in scale? |
... 17 posts hidden. Click here to view all posts.... |
Previous - 1 | 2 | 3 - Next |