Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
 Welcome to our latest new user Harvey ! (Registered 2024-11-25) You are not logged in - nap
CSDb User Forums


Forums > CSDb Entries > Release id #172238 : Waves 16k
2018-12-09 10:09
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

 
... 18 posts hidden. Click here to view all posts....
 
2018-12-11 16:15
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.
2018-12-11 16:20
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
2018-12-11 16:23
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.
2018-12-11 16:24
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)
2018-12-11 16:33
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.
2018-12-11 16:34
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
2018-12-11 16:35
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
2018-12-11 16:46
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
2018-12-11 18:21
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?
2018-12-11 19:03
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
Previous - 1 | 2 | 3 - 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
Ghost/Quantum
Barfly/Extend
Mibri/ATL^MSL^PRX
Murphy/Exceed
rexbeng
Mojzesh/TGR🇬🇧
hedning/G★P
Stryyker/Tide
Isildur/Samar
Guests online: 89
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Mojo  (9.6)
6 The Demo Coder  (9.6)
7 Uncensored  (9.6)
8 Wonderland XIV  (9.6)
9 Comaland 100%  (9.6)
10 What Is The Matrix 2  (9.6)
Top onefile Demos
1 Layers  (9.6)
2 Party Elk 2  (9.6)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.6)
5 Libertongo  (9.5)
6 Rainbow Connection  (9.5)
7 Onscreen 5k  (9.5)
8 Morph  (9.5)
9 Dawnfall V1.1  (9.5)
10 It's More Fun to Com..  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Nostalgia  (9.3)
5 Censor Design  (9.3)
Top Webmasters
1 Slaygon  (9.6)
2 Perff  (9.6)
3 Morpheus  (9.5)
4 Sabbi  (9.5)
5 CreaMD  (9.1)

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