21 minutes ago, SlithyMatt said:
There are some very low-hanging fruit that I haven't bothered with so far, in the interest of keeping the working, straightforward implementation of the algorithm in BASIC. I don't think any of these will have a huge impact, but they might shave off a bit of time:
Line 10: Do a pair of VERA register pokes to set screen resolution to 324x240
After line 50: Set up VERA address registers manually for start of bitmap in VRAM ($4000)
Then, replace lines 217-230 with a single line: POKE $9F23,I
Lines 120, 130: Pre-calculate 0.000036/320 and 0.000027/240
After line 160: Calculate X*X and Y*Y
Then, use pre-calculated squares for lines 170 and 180
This area of the plot is not symmetrical, so I don't think you can just do mirroring to save a big chunk of time.
Anything else will take some really digging to come up with optimization. The core driver of the time is the math that just needs to happen.
All very valid points. It is one thing to optimize a 32x22 (or whatever) plot so it shaves a few seconds off something that takes a couple minutes. It is quite another to shave a few seconds off a 320x240 plot that takes literal hours to run.
I'm running a solution right now that does all the horrible unreadable tricks to the BASIC code to try to make it faster. I haven't tried timing the original vs this one (mainly because it takes so long; I need to tweak it to time how long it takes to render a random raster to have something that can be timed, just haven't had time to do that yet). But it seems to work. And it is ugly (and I do not like ugly code unless there is a really good reason, evidence to the contrary notwithstanding).
0 SCREEN0:POKE$9F2D,$07:POKE$9F2F,$20:POKE$9F29,$11:GOSUB12
1 YI=0.000027/240:YZ=0.08784:XS=-0.747345:XI=0.000036/320
2 C0=0:C1=1:C2=2:C4=4:CC=100:CH=256:CA=$4000:CB=153:CE=192:CF=320:CG=355
3 CI=239:CJ=319:POKE$9F20,0:POKE$9F21,$40:POKE$9F22,$10:VP=$9F23
4 FORPY=C0TOCI:XZ=XS:FORPX=C0TOCJ:X=C0:Y=C0:FORI=C0TOCG:X2=X*X:Y2=Y*Y
5 IT=I:IFX2+Y2>C4THENI=CG:NEXT:GOTO7
6 Y=C2*X*Y+YZ:X=X2-Y2+XZ:NEXT
7 I=IT-CC:IFI=CHTHENI=C0
8 B=C0:OS=CA:Y=PY:IFY<CBGOTO11
9 IFY=CBTHENIFPX<CEGOTO11
10 B=C1:OS=-CE:Y=PY-CB
11 POKEVP,I:XZ=XZ+XI:NEXT:YZ=YZ+YI:NEXT:END
12 POKE$9F20,0:POKE$9F21,$40:POKE$9F22,$10:VP=$9F23
13 FORI=1TO320*240:POKEVP,0:NEXT:RETURN
I'll provide some quantitative data later measuring time to rasterize one line in each version, but I think the difference will not be great.