| |
Heaven Account closed
Registered: Jul 2008 Posts: 102 |
Release id #172238 : Waves 16k
<Post edited by moderator on 11/12-2018 15:33>
ldx #0 ;top = 0
;we use Xreg as top
loop_fractal_line cpx #0
bpl @+ ;if x<0 go to drawing
jmp exit_fractal_line
@ lda sx2,x ;dx = abs(sx2-sx1)
sec
sbc sx1,x
bcs @+
eor #$FF
adc #1
@ cmp #2 ;if dx<2 skip to plot point
bcs subdiv_fractal_line
ldy sx1,x
lda sy1,x
sta heights,y
dex
bne loop_fractal_line
beq loop_fractal_line
subdiv_fractal_line lsr ;ed = dx/4
lsr
sta edge_displacement
lda sx2,x ;sx2 = int((sx1+sx2)/2)
sta sx2+1,x ;use it to copy to top+1
clc
adc sx1,x
lsr
sta sx2,x
sta sx1+1,x ;copy to top+1 also
lda sy2,x ;sy2 = int((sy1+sy2)/2)
sta sy2+1,x ;use it to copy to top+1
clc
adc sy1,x
lsr
sta sy2,x
lda st2,x ;st2 = st1+st2
sta st2+1,x ;use it to copy to top+1
clc
adc st1,x
sta st2,x
sta st1+1,x ;copy to top+1 also
bvs @+ ;if v<>0 skip displacement
bmi n_equal_1
lda sy2,x ;n == 0
clc ;sy2 += ed
adc edge_displacement
sta sy2,x
jmp @+
n_equal_1 lda sy2,x ;n == 1
sec ;sy2 -= ed
sbc edge_displacement
sta sy2,x
@ ;Copy new Y to top+1
lda sy2,x
sta sy1+1,x
inx ;top += 1
jmp loop_fractal_line
exit_fractal_line
|
|
| |
chatGPZ
Registered: Dec 2001 Posts: 11354 |
that would be so much better with a 'code' tag =D |
| |
Bitbreaker
Registered: Oct 2002 Posts: 504 |
So much precious cycles waster with sec/clc and no illegal spotted :-( |
| |
Heaven Account closed
Registered: Jul 2008 Posts: 102 |
@Bitbreaker...
yeah... ;)
we Atarians do not use illegals often due to 65816 boards :D.
no honestly. Axis teached me last week first time AXS e.g. so first time I used any illegal was LAX in Arsantica 3 and the Voxel... :D |
| |
Bitbreaker
Registered: Oct 2002 Posts: 504 |
All the lsr could be replaced with an asr #$fe and thus carry will stay clear and clc can be dropped, and i see even more potential :-) (sta sy2,x being stored and loaded again just on the next step, a comparision would suffice on the abs function, and that would save a sec) |
| |
Cruzer
Registered: Dec 2001 Posts: 1048 |
What
Groepaz
said |
| |
iAN CooG
Registered: May 2002 Posts: 3187 |
I edited the 1st post to reformat it with the code tags |
| |
Heaven Account closed
Registered: Jul 2008 Posts: 102 |
@bitbreaker
ah thx. I guess I will revisit the fractal core. :D
btw. if you wonder what ST1 and ST2 is. It's what Carpenter calls "node tag values" and those represent the characteristics of the line (e.h. "mountain" or "cloud" etc).
so... say fractline(0,100,4 to 319,100,4) will be different to fractline(0,100,20 to 319,100,4). Even Tag1 4 and Tag2 5 should be different.
http://old.siggraph.org/publications/rarities/carpenter-1980sup.. |
| |
Heaven Account closed
Registered: Jul 2008 Posts: 102 |
Quote: All the lsr could be replaced with an asr #$fe and thus carry will stay clear and clc can be dropped, and i see even more potential :-) (sta sy2,x being stored and loaded again just on the next step, a comparision would suffice on the abs function, and that would save a sec)
another idea was exchange x reg with y reg as I moved the height array into ZP... just saw in c64debugger that STA height,y is $00xx.... |
| |
Bitbreaker
Registered: Oct 2002 Posts: 504 |
If things happen linearly one could also push bytes to stack instead of storing and read them back with lda $0100,y
Interrupts should not matter, as they add bytes at the bottom end. X gets interesting as index then again as tsx fethes the proper position in stack for indexed reads again. |
| |
Bitbreaker
Registered: Oct 2002 Posts: 504 |
the cpx #0 can also be omitted, as this point is eitehr reached after ldx, dex, inx that all set the minus-flag anyway, also
bne loop_fractal_line
beq loop_fractal_line
can be replaced by a jmp |
| |
Oswald
Registered: Apr 2002 Posts: 5086 |
as far as I understand this is a recursive line routine except at each subdiv step it semi randomly decides if y should be displaced or not, + or -, while displacement value is /2-ed on each subdiv step. |
| |
Heaven Account closed
Registered: Jul 2008 Posts: 102 |
Quote: the cpx #0 can also be omitted, as this point is eitehr reached after ldx, dex, inx that all set the minus-flag anyway, also
bne loop_fractal_line
beq loop_fractal_line
can be replaced by a jmp
the atari version has JMP but I thought that BNE/BEQ combo is faster as 3 cycles vs 2 (assuming no page boundary crossing happened... dont tell me that I do cross :D) |
| |
Bitbreaker
Registered: Oct 2002 Posts: 504 |
jmp takes 3 cycles, a taken branch as well, so your combo takes 3 or 5 cycles and one byte more than a jmp. |
| |
Heaven Account closed
Registered: Jul 2008 Posts: 102 |
Quote: jmp takes 3 cycles, a taken branch as well, so your combo takes 3 or 5 cycles and one byte more than a jmp.
haha... Jez... so I misoptimised it and me thought I am clever :D |
| |
Bitbreaker
Registered: Oct 2002 Posts: 504 |
ldx #0 ;top = 0
loop_fractal_line
lda sx2,x ;dx = abs(sx2-sx1)
sec
sbc sx1,x
bcs @+
eor #$FF
adc #1
@
cmp #2 ;if dx<2 skip to plot point
bcs subdiv_fractal_line
ldy sx1,x
lda sy1,x
sta heights,y
dex
bmi exit_fractal_line
subdiv_fractal_line
lsr ;ed = dx/4
asr #$fe
sta edge_displacement
lda sx2,x ;sx2 = int((sx1+sx2)/2)
sta sx2+1,x ;use it to copy to top+1
adc sx1,x
asr #$fe
sta sx2,x
sta sx1+1,x ;copy to top+1 also
lda sy2,x ;sy2 = int((sy1+sy2)/2)
sta sy2+1,x ;use it to copy to top+1
adc sy1,x
asr #$fe
sta sy2,x
lda st2,x ;st2 = st1+st2
sta st2+1,x ;use it to copy to top+1
adc st1,x
sta st2,x
sta st1+1,x ;copy to top+1 also
bvs @+ ;if v<>0 skip displacement
bmi n_equal_1
lda sy2,x ;n == 0
;maybe can be omitted if previous addition does never overrun?
clc ;sy2 += ed
adc edge_displacement
sta sy2,x
jmp cont1
n_equal_1
lda sy2,x ;n == 1
sec ;sy2 -= ed
sbc edge_displacement
sta sy2,x
sta sy1+1,x
inx ;top += 1
bpl loop_fractal_line
bmi exit_fractal_line
@ ;Copy new Y to top+1
lda sy2,x
cont1
sta sy1+1,x
inx ;top += 1
bpl loop_fractal_line
exit_fractal_line
Have not tried it, might be completely broken now, but that are things i see at a first glance to try. I understand that unrolling is not an option in a 16k intro :-) The storing on stack/zp is still an option as it takes two/one cycle off the stores.
You might also want to do more code duplication instead of the jmp cont1 |
| |
Heaven Account closed
Registered: Jul 2008 Posts: 102 |
thanks. will have a look later and upload a version with the new "core".
and
sec
sbc sx1,x
bcs @+
eor #$FF
adc #1
I am wondering why I did not use that for ages :D |
| |
Heaven Account closed
Registered: Jul 2008 Posts: 102 |
actually it stucks in the fractal loop... need to check why.
maybe as my assembler has no ASR so I looked at Graham's opcode matrix and would say its $4b? |
| |
Heaven Account closed
Registered: Jul 2008 Posts: 102 |
Quote: thanks. will have a look later and upload a version with the new "core".
and
sec
sbc sx1,x
bcs @+
eor #$FF
adc #1
I am wondering why I did not use that for ages :D
ok. me getting old... it's mine :D |
| |
Heaven Account closed
Registered: Jul 2008 Posts: 102 |
ldx #0 ;top = 0
;we use Xreg as top
loop_fractal_line cpx #0
bmi exit_fractal_line
@ lda sx2,x ;dx = abs(sx2-sx1)
sec
sbc sx1,x
bcs @+
eor #$FF
adc #1
@ cmp #2 ;if dx<2 skip to plot point
bcs subdiv_fractal_line
ldy sx1,x
lda sy1,x
sta heights,y
dex
jmp loop_fractal_line
subdiv_fractal_line lsr ;ed = dx/4
alr #$fe ;c = 0 a div 2
sta edge_displacement
lda sx2,x ;sx2 = int((sx1+sx2)/2)
sta sx2+1,x ;use it to copy to top+1
adc sx1,x
alr #$fe
sta sx2,x
sta sx1+1,x ;copy to top+1 also
lda sy2,x ;sy2 = int((sy1+sy2)/2)
sta sy2+1,x ;use it to copy to top+1
adc sy1,x
alr #$fe
sta sy2,x
lda st2,x ;st2 = st1+st2
sta st2+1,x ;use it to copy to top+1
adc st1,x
sta st2,x
sta st1+1,x ;copy to top+1 also
bvs @+ ;if v<>0 skip displacement
bmi n_equal_1
lda sy2,x ;n == 0
clc ;sy2 += ed
adc edge_displacement
sta sy2,x
jmp @+
n_equal_1 lda sy2,x ;n == 1
sec ;sy2 -= ed
sbc edge_displacement
sta sy2,x
@ ;Copy new Y to top+1
lda sy2,x
sta sy1+1,x
inx ;top += 1
jmp loop_fractal_line
exit_fractal_line
slightly optimised with my new friend ALR #$fe |
| |
Bitbreaker
Registered: Oct 2002 Posts: 504 |
you still should get rid of the cpx #0 decision :-) You can do that already on the branches from inx/dex ;-) |
| |
Rastah Bar Account closed
Registered: Oct 2012 Posts: 336 |
Quoting Heaven
btw. if you wonder what ST1 and ST2 is. It's what Carpenter calls "node tag values" and those represent the characteristics of the line (e.h. "mountain" or "cloud" etc).
so... say fractline(0,100,4 to 319,100,4) will be different to fractline(0,100,20 to 319,100,4). Even Tag1 4 and Tag2 5 should be different.
http://old.siggraph.org/publications/rarities/carpenter-1980sup..
Thanks for the link! Btw, is this the same kind of algorithm that is behind the change disk part of Old Men in Used Cars ? |
| |
Heaven Account closed
Registered: Jul 2008 Posts: 102 |
yup.
http://www.evilshirt.com/_ataristuff/dsr_waves_opt_packed.zip
including the new core... don't see much difference... but haven't meassured the rendering time... |
| |
Heaven Account closed
Registered: Jul 2008 Posts: 102 |
Quote: Quoting Heaven
btw. if you wonder what ST1 and ST2 is. It's what Carpenter calls "node tag values" and those represent the characteristics of the line (e.h. "mountain" or "cloud" etc).
so... say fractline(0,100,4 to 319,100,4) will be different to fractline(0,100,20 to 319,100,4). Even Tag1 4 and Tag2 5 should be different.
http://old.siggraph.org/publications/rarities/carpenter-1980sup..
Thanks for the link! Btw, is this the same kind of algorithm that is behind the change disk part of Old Men in Used Cars ?
i doubt as this looks like a "classic voxel" animation.
but Voxel maps can be generated by midline displacement... and me using a grid while voxel uses "screen collums" and RoF uses collum height drawing (front to back) same like later commanche... so yeah some tech is used later ;) |
| |
Heaven Account closed
Registered: Jul 2008 Posts: 102 |
Quote: you still should get rid of the cpx #0 decision :-) You can do that already on the branches from inx/dex ;-)
now as more as I look at it it's most annoying thing :D. |
| |
Heaven Account closed
Registered: Jul 2008 Posts: 102 |
And this doc describes the “flag based” displacement:
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.85.378..
As we see Carpenter was already at Lucasfilm 1986 |
| |
Heaven Account closed
Registered: Jul 2008 Posts: 102 |
https://youtu.be/OaCiNi1Y5pE
this is the Atari 800 version with my new "core" but it has 3d calc (camx,camy plus persptrans with fastmul)...
;)
and here the c64 "core" without 3d and precalced nodepos on the A8...
https://youtu.be/jxYKiNWMznU |
| |
Bitbreaker
Registered: Oct 2002 Posts: 504 |
I expect a c64 demo in two years that shows the effect as fast :-) |
| |
Heaven Account closed
Registered: Jul 2008 Posts: 102 |
actually i am now precalculating those "x fract" tables as in a non camera moving scenario all line length are fix...
so code will only do y1 to y2 displacement in realtime. |