Ricky Spanish Posted March 24 Share Posted March 24 Would this be as optimized as it will get, or is there still room for improvement with OSS BASIC XE for speed/efficiency etc. Thanks. 1 FAST 165 DIM Q(158) 170 LS=10:MC=81:FOR I=0 TO LS-1:FOR J=0 TO 7:Q(78+I*8+J)=8-J:NEXT J:NEXT I 180 FOR I=0 TO 77:READ X:Q(I)=X:NEXT I:Z=Q(24):L=0:T=L:Q(158)=L:DC=T 190 CX=Q(L):CY=Q(L+12):D=64:D2=D*2:H=D-1:I=L*16+1 200 GRAPHICS 11 210 IF D<=1 THEN GOTO 270 220 FOR Y=T TO 191 STEP D 230 B=CY+(Y-96)/4*Z 240 FOR X=0 TO 79 250 A=CX+(X-40)*Z 260 COLOR 1 270 PLOT X,Y 280 R=0:I=R:R2=R:I2=R 290 FOR C1=0 TO MC-1 300 J=R2-I2+A 310 I=(2*R*I)+B 320 R=J:R2=R*R:I2=I*I 330 C=C1 340 IF (R2+I2)<4 THEN NEXT C1 350 COLOR Q(C+78) 360 PLOT X,Y 370 DRAWTO X,Y+H 380 NEXT X 390 NEXT Y 400 GOTO 270 410 Data 0,-0.170337,-0.745107298,-.462160300,-1.6487359367 411 Data -0.17485,-1.287769,.3150751,-1.9990959,-1.192101,-0.747227,-1.457758 420 Data 0,-1.06506,-0.15020534,-.5823998,0,-1.071623,.063761,.02918,-0.000000063,0.3061769,0.105766,-0.001353 430 Data 0.05,.000001,.000002,.0001,.000001,0.000045,.000004,.0004,.00000003,.00001,0.000147,0.00002 440 Data 254,2,32,14,18,16,238,242,240,1,1,1,0,11,11,11 450 Data 0,0,0,0,2,.5,0,0,2,.5,0,0,2,.5,0,1,1,1,0,1,1,1,0,0,0,0 Quote Link to comment Share on other sites More sharing options...
_The Doctor__ Posted March 24 Share Posted March 24 if you aren't restoring to or pointing to specific data block, putting as many things on a line as possible helps. Same thing goes for command lines get as many on a line as possible. only using another line when something needs to go to it specifically you still want to follow all the order of operation speed ups of Atari Basic, it helps when FAST mode fails. Looks like you've done pretty well in that regard. You still want to compress line numbers down to as small a series of digits and get as much on a line as possible, while FAST mode does do addressing of the line ahead of time it still helps for the process of doing that or if FAST fails keeps things moving as best as possible. 1 Quote Link to comment Share on other sites More sharing options...
pirx Posted March 26 Share Posted March 26 the algo is flawed, it needs a rewrite. maybe this hacky way of jumping inside FOR and skipping NEXT is OK for a small program, but it will definitely fail in the long run (return stack gets clobbered). smol opty: D*2 is slower than D+D. divide very bad. floating point generally extremely bad, especially such a smol number as .00000003. at the end everything is integers, so maybe some kind of a rethink with integers would help. some kind of a precalced data maybe 1 1 Quote Link to comment Share on other sites More sharing options...
Ricky Spanish Posted March 26 Author Share Posted March 26 35 minutes ago, pirx said: the algo is flawed, it needs a rewrite. maybe this hacky way of jumping inside FOR and skipping NEXT is OK for a small program, but it will definitely fail in the long run (return stack gets clobbered). smol opty: D*2 is slower than D+D. divide very bad. floating point generally extremely bad, especially such a smol number as .00000003. at the end everything is integers, so maybe some kind of a rethink with integers would help. some kind of a precalced data maybe Thanks for the heads up. I'll look closer. Quote Link to comment Share on other sites More sharing options...
Rybags Posted March 26 Share Posted March 26 (edited) Probably some gain to be had by stacking statements on a line rather than just 1 per line. Possibly reordering so that the main loops are closer to the start though I think Basic XE doesn't suffer the same bad search speed for branches that Atari Basic does. Where there's complex calculations - if there's stuff like integer multiplies on a sequence of numbers in a loop you can often get speed gain by just precalculating and storing the results in an array for later reference. Edited March 26 by Rybags 1 Quote Link to comment Share on other sites More sharing options...
Ricky Spanish Posted March 27 Author Share Posted March 27 1 hour ago, Rybags said: Probably some gain to be had by stacking statements on a line rather than just 1 per line. Possibly reordering so that the main loops are closer to the start though I think Basic XE doesn't suffer the same bad search speed for branches that Atari Basic does. Where there's complex calculations - if there's stuff like integer multiplies on a sequence of numbers in a loop you can often get speed gain by just precalculating and storing the results in an array for later reference. Thanks. I'll rewrite it. Quote Link to comment Share on other sites More sharing options...
FifthPlayer Posted March 27 Share Posted March 27 5 hours ago, Rybags said: Possibly reordering so that the main loops are closer to the start though I think Basic XE doesn't suffer the same bad search speed for branches that Atari Basic does. It does not. The FAST keyword precalculates the branch points, so it does not have to search for the destination of a branch the way Atari Basic does. 1 Quote Link to comment Share on other sites More sharing options...
Ricky Spanish Posted March 27 Author Share Posted March 27 So, rewrote the program. 10 Fast :Dim Q(158):Graphics 11 15 Ls=10:Mc=81:For I=0 To Ls-1:For J=0To 7:Q(78+I*8+J)=8-J:Next J:Next I 20 For I=0 To 77:Read X:Q(I)=X:Next I:Z=Q(24):L=0:T=L:Q(158)=L:Dc=T 25 Cx=Q(L):Cy=Q(L+12):D=64:D2=D*2:H=D-1:I=L*16+1 30 On D<=1 Goto 55 35 For Y=T To 191 Step D:B=Cy+(Y-96)/4*Z:For X=0 To 79:A=Cx+(X-40)*Z:Color 1:Plot X,Y 40 R=0:I=R:R2=R:I2=R:For C1=0 To Mc-1:J=R2-I2+A 45 I=(2*R*I)+B:R=J:R2=R*R:I2=I*I:C=C1:If (R2+I2)<4 Then Next C1 50 Color Q(C+78):Plot X,Y:Drawto X,Y+H 55 Poke 77,0:Goto 65 60 Goto 25 65 If D>1 Then Next X:Next Y:D2=D2/2:D=D2:T=D/2:H=T-1:Goto 35 70 Goto 70 75 Data 0,-0.170337,-0.745107298,-.462160300,-1.6487359367,-0.17485,-1.287769 80 Data .3150751,-1.9990959,-1.192101,-0.747227,-1.457758,0,-1.06506,-0.15020534,-.5823998,0 85 Data -1.071623,.063761,.02918,-0,0.3061769,0.105766,-0.001353,0.05,0,0,0,0,0,0,0,0,0,0,0 90 Data 254,2,32,14,18,16,238,242,240,1,1,1,0,11,11,11,0,0,0,0,2,.5,0,0,2,.5,0,0,2,.5,0,1,1,1,0,1,1,1,0,0,0,0 Quote Link to comment Share on other sites More sharing options...
dmsc Posted March 27 Share Posted March 27 (edited) Hi! 2 hours ago, Ricky Spanish said: So, rewrote the program. 10 Fast :Dim Q(158):Graphics 11 15 Ls=10:Mc=81:For I=0 To Ls-1:For J=0To 7:Q(78+I*8+J)=8-J:Next J:Next I 20 For I=0 To 77:Read X:Q(I)=X:Next I:Z=Q(24):L=0:T=L:Q(158)=L:Dc=T 25 Cx=Q(L):Cy=Q(L+12):D=64:D2=D*2:H=D-1:I=L*16+1 30 On D<=1 Goto 55 35 For Y=T To 191 Step D:B=Cy+(Y-96)/4*Z:For X=0 To 79:A=Cx+(X-40)*Z:Color 1:Plot X,Y 40 R=0:I=R:R2=R:I2=R:For C1=0 To Mc-1:J=R2-I2+A 45 I=(2*R*I)+B:R=J:R2=R*R:I2=I*I:C=C1:If (R2+I2)<4 Then Next C1 50 Color Q(C+78):Plot X,Y:Drawto X,Y+H 55 Poke 77,0:Goto 65 60 Goto 25 65 If D>1 Then Next X:Next Y:D2=D2/2:D=D2:T=D/2:H=T-1:Goto 35 70 Goto 70 75 Data 0,-0.170337,-0.745107298,-.462160300,-1.6487359367,-0.17485,-1.287769 80 Data .3150751,-1.9990959,-1.192101,-0.747227,-1.457758,0,-1.06506,-0.15020534,-.5823998,0 85 Data -1.071623,.063761,.02918,-0,0.3061769,0.105766,-0.001353,0.05,0,0,0,0,0,0,0,0,0,0,0 90 Data 254,2,32,14,18,16,238,242,240,1,1,1,0,11,11,11,0,0,0,0,2,.5,0,0,2,.5,0,0,2,.5,0,1,1,1,0,1,1,1,0,0,0,0 You did not rewrite the program, only rearranged it a little. Your program is an adaptation of an Atari BASIC 10-liner, from this post: https://workshop88.com/oldblog/index.php/2021/03/21/an-interactive-mandelbrot-set-explorer-in-10-lines-of-atari-basic/ Being a 10-liner, it is written to be as concise as possible, without much regard for speed - but the algorithm is a standard mandelbrot plotter. Try to understand the code and write it again without the NEXTs inside the IFs, and without all the unneeded gotos. Have Fun! Edited March 27 by dmsc clarify it is for Atari BASIC. 2 Quote Link to comment Share on other sites More sharing options...
Ricky Spanish Posted March 27 Author Share Posted March 27 12 minutes ago, dmsc said: Try to understand the code and write it again without the NEXTs inside the IFs, and without all the unneeded gotos. will do ! Quote Link to comment Share on other sites More sharing options...
Ricky Spanish Posted March 28 Author Share Posted March 28 curiously though, what's the problem with putting NEXT inside a IF statement ? Quote Link to comment Share on other sites More sharing options...
_The Doctor__ Posted March 28 Share Posted March 28 55 Poke 77,0:Goto 65 60 Goto 25 delete :GOTO 65 DELETE 60 they serve no purpose to get started, I see DMSC pointed out another possible issue IF with a NEXT it's possible to call for for a NEXT after the FOR count has been expended. This usually not a great idea. Quote Link to comment Share on other sites More sharing options...
Ricky Spanish Posted March 28 Author Share Posted March 28 1 hour ago, _The Doctor__ said: 55 Poke 77,0:Goto 65 60 Goto 25 delete :GOTO 65 DELETE 60 they serve no purpose to get started, I see DMSC pointed out another possible issue IF with a NEXT it's possible to call for for a NEXT after the FOR count has been expended. This usually not a great idea. yeah I got rid of the goto's. Why isn't it a great idea ? I couldn't find any reason for it in my books (PDF). It's only interrupting the FOR/NEXT, no ? Quote Link to comment Share on other sites More sharing options...
Ricky Spanish Posted March 28 Author Share Posted March 28 (edited) Apon further research, the program is skipping the rest of the code within the "FOR" loop and moving on to the next iteration when the condition in the "IF" statement is met. So, how would it be rewritten to accomplish the same task ? Assuming it needs to be rewritten. 10 Fast :Dim Q(158):Graphics 11 15 Ls=10:Mc=81:For I=0 To Ls-1:For J=0 To 7:Q(78+I*8+J)=8-J:Next J:Next I 20 For I=0 To 77:Read X:Q(I)=X:Next I:Z=Q(24):L=0:T=L:Q(158)=L:Dc=T 25 Cx=Q(L):Cy=Q(L+12):D=64:D2=D*2:H=D-1:I=L*16+1 30 On D<=1 Goto 55 35 For Y=T To 191 Step D:B=Cy+(Y-96)/4*Z:For X=0 To 79:A=Cx+(X-40)*Z:Color 1:Plot X,Y 40 R=0:I=R:R2=R:I2=R:For C1=0 To Mc-1:J=R2-I2+A 45 I=(2*R*I)+B:R=J:R2=R*R:I2=I*I:C=C1:If (R2+I2)<4 Then Next C1 50 Color Q(C+78):Plot X,Y:Drawto X,Y+H 55 Poke 77,0 65 Next X:Next Y:D2=D2/2:D=D2:T=D/2:H=T-1:Goto 35 70 Goto 70 same data statement as above. Thanks. Edited March 28 by Ricky Spanish my grammar sucks. Quote Link to comment Share on other sites More sharing options...
_The Doctor__ Posted March 28 Share Posted March 28 What does the display look like at this point? Quote Link to comment Share on other sites More sharing options...
Ricky Spanish Posted March 29 Author Share Posted March 29 1 hour ago, _The Doctor__ said: What does the display look like at this point? Best if you run it with Altirra or if you have real hardware & BASIC XE. Quote Link to comment Share on other sites More sharing options...
dmsc Posted March 29 Share Posted March 29 Hi! 4 hours ago, Ricky Spanish said: Apon further research, the program is skipping the rest of the code within the "FOR" loop and moving on to the next iteration when the condition in the "IF" statement is met. So, how would it be rewritten to accomplish the same task ? Assuming it needs to be rewritten. 10 Fast :Dim Q(158):Graphics 11 15 Ls=10:Mc=81:For I=0 To Ls-1:For J=0 To 7:Q(78+I*8+J)=8-J:Next J:Next I 20 For I=0 To 77:Read X:Q(I)=X:Next I:Z=Q(24):L=0:T=L:Q(158)=L:Dc=T 25 Cx=Q(L):Cy=Q(L+12):D=64:D2=D*2:H=D-1:I=L*16+1 30 On D<=1 Goto 55 35 For Y=T To 191 Step D:B=Cy+(Y-96)/4*Z:For X=0 To 79:A=Cx+(X-40)*Z:Color 1:Plot X,Y 40 R=0:I=R:R2=R:I2=R:For C1=0 To Mc-1:J=R2-I2+A 45 I=(2*R*I)+B:R=J:R2=R*R:I2=I*I:C=C1:If (R2+I2)<4 Then Next C1 50 Color Q(C+78):Plot X,Y:Drawto X,Y+H 55 Poke 77,0 65 Next X:Next Y:D2=D2/2:D=D2:T=D/2:H=T-1:Goto 35 70 Goto 70 same data statement as above. Thanks. My question is: what are you trying to accomplish? Your program is still very hard to understand, you still have lines (like line 30 and line 70) that do not do anything, you are using variables instead of numbers in line 40 (I=R instead of I=0), the Q stores 6 different arrays of data, most of that not necessary, the color table is not appropriate for graphics 11, etc. ¿Do you want a faster mandelbrot program? There are faster languages for that. ¿Do you want to learn BASIC XE? Then, your code is not written using any BASIC XE special statements. Have Fun! 1 Quote Link to comment Share on other sites More sharing options...
Ricky Spanish Posted March 29 Author Share Posted March 29 Ok well just trying to learn. Accomplish ? Well, as you know that 10-liner goes much past the character per line limit. Wanted to see if I could modify it without all the fancy original programs bells & whistles & perhaps speed it up. Sorry for wasting time. Quote Link to comment Share on other sites More sharing options...
_The Doctor__ Posted March 29 Share Posted March 29 (edited) You realize when typing in POKE 82,0 then you use the abbreviations and skip any extra spaces etc when typing those in. Let the Atari expand them. when listing it will all be there but you have to squish it all back down to make changes else it will cut everything off after 3 rows in a line number Edited March 29 by _The Doctor__ Quote Link to comment Share on other sites More sharing options...
dmsc Posted March 29 Share Posted March 29 Hi! 25 minutes ago, Ricky Spanish said: Ok well just trying to learn. Accomplish ? Well, as you know that 10-liner goes much past the character per line limit. Wanted to see if I could modify it without all the fancy original programs bells & whistles & perhaps speed it up. Then, I think you could start with this simplified program, IMHO it is easier to understand: 100 MC=15 110 Z=0.05 120 T=0 130 CX=0 140 CY=0 150 D=64:D2=D*2:H=D-1 200 GRAPHICS 11 210 WHILE D>1 220 FOR Y=T TO 191 STEP D 230 B=CY+(Y-96)/4*Z 240 FOR X=0 TO 79 250 A=CX+(X-40)*Z 260 COLOR 1 270 PLOT X,Y 280 R=0:I=0:R2=0:I2=0 290 C=MC 300 WHILE (R2+I2<4) AND C 310 J=R2-I2+A 320 I=(2*R*I)+B 330 R=J:R2=R*R:I2=I*I 340 C=C-1 350 ENDWHILE 360 COLOR C 370 PLOT X,Y 380 DRAWTO X,Y+H 390 NEXT X 400 POKE 77,0 400 NEXT Y 410 D2=D2/2:D=D2:T=D/2:H=T-1 420 ENDWHILE 430 GOTO 430 The inner loop is the same as the original, but now it uses a WHILE loop instead of FOR, so the exit condition is clearer. Now, you could try to make it faster: - You could change the starting condition (R=0, I=0,R2=0,I2=0) with the condition after the first iteration: R=A,I=B,R2=R*R,I2=I*I, this will make the code faster because you are doing one less loop - You could lower MC and see if the mandelbrot has enough resolution still You could also rewrite it in TurboBasic XL, it should be faster, and TurboBasic has better structured programming so could be simplified a little. Have Fun! 2 Quote Link to comment Share on other sites More sharing options...
Ricky Spanish Posted March 30 Author Share Posted March 30 (edited) On 3/28/2024 at 9:34 PM, dmsc said: Have Fun! learned a lot from your example, thanks. PS the higher the resolution, the better. Edited March 30 by Ricky Spanish Quote Link to comment Share on other sites More sharing options...
ivop Posted March 31 Share Posted March 31 If you want really fast, you could try porting this to the Atari: https://github.com/davidgiven/bogomandel Interesting write ups on his blog. Links are in the README.md. Have fun! 1 1 Quote Link to comment Share on other sites More sharing options...
Ricky Spanish Posted March 31 Author Share Posted March 31 3 hours ago, ivop said: you could try porting this to the Atari that's more @dmsc area of expertise. my programming abilities aren't to much above a apes. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.