Wednesday, May 25, 2022

Fractal in BASIC for the CoCo 3

And a good old fractal program I ported a year and a half ago. 

Most of these I did just to show how much faster BASIC would have been if Microsoft had used the 6809 multiply instruction for the floating point multiply.  The patch uses the stack for temporary storage, and the code would be even faster if temporary variables had been placed on the direct page... but I didn't want to take the time to learn what I could or could not use by studying the ROM disassembly.  I've spent enough time rewriting the MC-10 ROM already.

1 POKE 65497,0
2 AD=VAL("&HFA0C")
3 FORI=0 TO 64:READ B$:A=VAL("&H"+B$)
4 POKE AD+I,A:NEXT
REM $BB00 JMP $FA0C
5 POKE VAL("&HBB02"),VAL("&H7E"):POKE VAL("&HBB03"),VAL("&HFA"):POKE VAL("&HBB04"),VAL("&H0C")
7 FOR I = 0 to 15:PALETTE I,I:NEXT I
10 HGR2
10 HSCREEN 2 : HCOLOR 1,3
20 XC = -0.5 : REM CENTER COORD X
30 YC = 0 : REM " " Y
40 S = 2 : REM SCALE
45 IT = 20 : REM ITERATIONS
50 XR = S * (280 / 192): REM TOTAL RANGE OF X
50 XR = S * (320 / 192): REM TOTAL RANGE OF X
60 YR = S : REM " " " Y
70 X0 = XC - (XR/2) : REM MIN VALUE OF X
80 X1 = XC + (XR/2) : REM MAX " " X
90 Y0 = YC - (YR/2) : REM MIN " " Y
100 Y1 = YC + (YR/2) : REM MAX " " Y
110 XM = XR / 279 : REM SCALING FACTOR FOR X
110 XM = XR / 319 : REM SCALING FACTOR FOR X
120 YM = YR / 191 : REM " " " Y
130 FOR YI = 0 TO 3 : REM INTERLEAVE
140 FOR YS = 0+YI TO 188+YI STEP 4 : REM Y SCREEN COORDINATE
145 HCOLOR=3 : HPLOT 0,YS TO 279,YS
145 HLINE(0,YS)-(319,YS),PRESET
150 FOR XS = 0 TO 278 STEP 2 : REM X SCREEN COORDINATE
150 FOR XS = 0 TO 318 STEP 2 : REM X SCREEN COORDINATE
170 X = XS * XM + X0 : REM TRANSL SCREEN TO TRUE X
180 Y = YS * YM + Y0 : REM TRANSL SCREEN TO TRUE Y
190 ZX = 0
200 ZY = 0
210 XX = 0
220 YY = 0
230 FOR I = 0 TO IT
240 ZY = 2 * ZX * ZY + Y
250 ZX = XX - YY + X
260 XX = ZX * ZX
270 YY = ZY * ZY
280 C = IT-I
290 IF XX+YY >= 4 GOTO 301
300 NEXT I
301 IF C >= 8 THEN C = C - 8 : GOTO 301
301 IF C >= 16 THEN C = C - 16 : GOTO 301
310 HCOLOR = C : HPLOT XS, YS TO XS+1, YS
310 HCOLOR C:HLINE(XS, YS)-(XS+1, YS),PSET
320 NEXT XS
330 NEXT YS
340 NEXT YI
350 END
REM ROM PATCH 1 - 65 bytes
1000 DATA 32,79,E7,60,96,60,3D,ED,63,E6,60,96,5E,3D,ED,61,E6,60,96,5D
1001 DATA 3D,ED,65,E6,60,96,5F,3D,E3,62,ED,62,EC,65,E9,61,89,00,ED,60
1002 DATA EC,63,D3,15,97,16,D7,63,EC,61,D9,14,99,13,DD,14,A6,60,89,00
1003 DATA 97,13,32,67,39

No comments:

Post a Comment