| |
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? |
|
... 17 posts hidden. Click here to view all posts.... |
| |
Glasnost Account closed
Registered: Aug 2011 Posts: 26 |
There is a fast and simple approximation.
Calculate first the hyperbolic approximated sine described earlier (sinH)
Then correct with this:
sin = 0.225 * (sinH * sinH - sinH) + sinH;
0.1% error in worst case compared to the real sinus..
Found it on...
http://lab.polygonal.de/2007/07/18/fast-and-accurate-sinecosine..
...but the link is not working anymore.. |
| |
Skate
Registered: Jul 2003 Posts: 494 |
Thanks Glasnost, nice article there.
P.S: You can reach the page using the archive.org's link below. (takes a while to load, be patient)
http://web.archive.org/web/20101229221122/http://lab.polygonal... |
| |
SIDWAVE Account closed
Registered: Apr 2002 Posts: 2238 |
i havent really ever seen a C64 sine gen in asm.
i use a basic line we made 25 years ago, then mod it for moves.
another way is to use excell spreadsheet, and generate curves from formulas there, and export to c64.
what i want to say really, is, why dont someone make a c64 tool ? if its so important, then make a c64 generator. ?
:) |
| |
Cruzer
Registered: Dec 2001 Posts: 1048 |
SIDWave: Nowadays you can just use an assembler script to generate stuff like that. E.g. KickAss where you have access to all the basic math functions from Java. What this discussion is about is generating it in machine code, in order to avoid having to load it from disk. |
| |
iAN CooG
Registered: May 2002 Posts: 3195 |
Jan: are you joking? apart that it's explained on codbase how to do it in asm, there is a plethora of native sinus table generators, I even mentioned one in my 1st post (wix bouncer), and if in doubt just search sinus:
http://csdb.dk/search/?seinsel=releases&search=sinus&all=1 |
| |
Wisdom
Registered: Dec 2001 Posts: 90 |
Working link for the article Glasnost referred to:
http://lab.polygonal.de/?p=205
|
| |
ChristopherJam
Registered: Aug 2004 Posts: 1409 |
Might be an interesting challenge to make a 'fewest bytes' sine table generator, criteria "can generate a 256 entry table for floor(128.5+127*sin(i*pi/128.0))", with errors of no more than +-1, at least 170 entries exact.
Of course, it's possible a delta compression scheme might end up winning out over a calculation.. and any entry of more than 256 bytes of code is pretty much an automatic fail! |
| |
Graham Account closed
Registered: Dec 2002 Posts: 990 |
Small sin?
10 FORI=0TO255:POKE4096+I,SIN(I*π/128)*127.5+128:NEXT
Is probably the shortest :)
Other than that a 65 bytes table + small mirror routine will probably be smaller than any real calculation or compression routine:
LDX #$40
LDY #$00
lp LDA sinsrc,X
STA sin,X
STA sin+64,Y
EOR #$FF
STA sin+128,X
STA sin+192,Y
INY
DEX
BPL lp
|
| |
Cruzer
Registered: Dec 2001 Posts: 1048 |
I'm also usually using Graham's mirror trick in bigger productions, even with only a 64 byte table. :)
For 256b'ers I have this extremely inaccurate but only 46 bytes long polynomial pseudo sine generator...
.var sineAmp = $100
.var loStart
.var loAddAdd
.if (sineAmp == $40) {
.eval loStart = $1c
.eval loAddAdd = $03
}
.if (sineAmp == $80) {
.eval loStart = $18
.eval loAddAdd = $07
}
.if (sineAmp == $100) {
.eval loStart = $14
.eval loAddAdd = $0f
}
lda #$00
pha
tax
ldy #$40
loop:
loAdd: lda #loStart
adc #loAddAdd
sta loAdd+1
bcc lo
inc hiAdd+1
clc
lo: adc #$00
sta lo+1
pla
hiAdd: adc #$00
pha
sta sine,x
sta sine+$bf,y
eor #sineAmp-1
sta sine+$80,x
sta sine-$80+$bf,y
inx
dey
bne loop
For an amplitude of $100 the max deviation is 7, with an avg of about 2.5. So it doesn't quite comply with Christopher's requirements, but it produces a smooth curve, which is usually good enough for plasmas, DYCP's, etc. For 3D calculations it probably needs to be more accureate though. |
| |
Skate
Registered: Jul 2003 Posts: 494 |
I use a very similar routine with Cruzer's. Mine is shorter in a way but there are some initialization rules! :)
this part is taken from my Little Circles of Life product's source code.
...
tSin = $5f00
...
value = $3c ; 16 bits
delta = $3e ; 16 bits
...
* = $0326
!word codeStartAddress
codeStartAddress
; fill&clear memory
- lda #$f6 : setByte = *-1 ; !word $f6a9
sta ($2b),y
iny
bne -
inc $2c
ldx $2c
cpx #$10
bcc -
sty setByte
bpl -
;sinus calculation
ldx #$40
- pha
clc
adc value
sta value
lda tSin+$c0-1,y
adc delta+1
sta tSin+$c0,y
sta tSin+$80-1,x
eor #$ff
sta tSin+$00-1,x
sta tSin+$40,y
pla
adc #$10
bcc +
inc delta+1
+ iny
dex
bne -
very dirty trick at the beginning, i admit it. :) but since this start-up routine fills $1000-$7fff with zero and sinus tables are placed in that area, sinus calculation routine takes only 39 bytes. but of course, if we try to make a stand alone sinus generator, it would take more bytes just like Cruzer's routine.
My point is, you can always use the benefit of your "already required" parts of your effect for shorter sine gen routines. This applies to almost every routine of course, this is just a little example.
For instance, i had to clean up the bitmap area for my effect, anyway. Why not using the same routine for cleaning up the sinus tables area and make an optimization like above without spending any extra bytes?
P.S: This $f6 (or $ff) is a must if you use the $0326 start up trick. I use $f6 to fill the video ram to use as background and foreground colors for my effect and gain 2 more bytes. This is the real "coder colors" case i guess. :) |
Previous - 1 | 2 | 3 - Next |