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
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
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..