1000 ; 1010 ; ITERATION CODE FOR PLOTTING 1020 ; MANDELBROT AND JULIA SETS. 1030 ; PROG BY TERRY NEWTON 9-21-90 1040 ; changed orig 8-26-91 1050 ; ITERATE(AC,BC,LIMIT,AZ,BZ): 1060 ; RETURNS ITERATION COUNT FOR 1070 ; POINT AT AC,BC UP TO LIMIT. 1080 ; AC,BC ARE ACE C FP VARIABLES 1090 ; LIMIT IS 16 BIT INTEGER 1100 ; AZ,BZ IS JULIA PLANE LOCATION 1110 ; 1120 ; TRANSFORM(COUNT,BANDF): 1130 ; RETURNS PIXEL COLOR 1 TO 3 1140 ; 1150 ; FIXED POINT MATH FORMAT... 1160 ; 1 BYTE SIGN (0 OR 255) 1170 ; 5 BIT INT 27 BIT FRACTION 1180 ; 1190 ; MAC65 SOURCE VERSION 1200 ; (ATTRACTOR DETECTION) 1210 ; 1220 *= $7000 1230 ; 1240 F1S = $D4 1250 F1D = $D5 1260 F1C = $D6 1270 F1B = $D7 1280 F1A = $D8 1290 F2S = $D9 1300 F2D = $DA 1310 F2C = $DB 1320 F2B = $DC 1330 F2A = $DD 1340 F3S = $DE 1350 F3D = $DF 1360 F3C = $E0 1370 F3B = $E1 1380 F3A = $E2 1390 FPPTR1 = $CB 1400 FPPTR2 = $CD 1410 CONVREG = $E3 ; TO E8 1420 CONVACC = $E9 ; TO ED 1430 TEMP = $F0 1440 TEMP1 = $F1 1450 TEMP2 = $F2 1460 PNTR = $EE ; TO EF 1470 ATTARR = $7800 1480 ; 1490 ; ITERATION ENTRY... 1500 ; 1510 JMP CONVDAT 1520 ; 1530 ; TRANSFORM ENTRY... 1540 ; 1550 JMP TRANSFRM 1560 ; 1570 ; DATA BLOCK 1580 ; 1590 AC .BYTE 0,0,0,0,0 1600 BC .BYTE 0,0,0,0,0 1610 AZ .BYTE 0,0,0,0,0 1620 BZ .BYTE 0,0,0,0,0 1630 AS .BYTE 0,0,0,0,0 1640 BS .BYTE 0,0,0,0,0 1650 COUNT .BYTE 0,0 1660 LIMIT .BYTE 0,0 1670 CP01 .BYTE 0,20,122,225,0 1680 ACFP .BYTE 0,0 1690 BCFP .BYTE 0,0 1700 AZFP .BYTE 0,0 1710 BZFP .BYTE 0,0 1720 ATTFLG .BYTE 0 1730 ; 1740 ; GET PARAMETERS FROM ACE C 1750 ; 1760 ; GET AC,BC POINTERS 1770 CONVDAT LDY #0 1780 LDA ($C6),Y 1790 STA ACFP 1800 INY 1810 LDA ($C6),Y 1820 STA ACFP+1 1830 INY 1840 LDA ($C6),Y 1850 STA BCFP 1860 INY 1870 LDA ($C6),Y 1880 STA BCFP+1 1890 ; GET LIMIT 1900 INY 1910 LDA ($C6),Y 1920 STA LIMIT 1930 INY 1940 LDA ($C6),Y 1950 STA LIMIT+1 1960 ; GET AZ,BZ POINTERS 1970 INY 1980 LDA ($C6),Y 1990 STA AZFP 2000 INY 2010 LDA ($C6),Y 2020 STA AZFP+1 2030 INY 2040 LDA ($C6),Y 2050 STA BZFP 2060 INY 2070 LDA ($C6),Y 2080 STA BZFP+1 2090 ; 2100 ; CONVERT AC,BC,AZ,BZ TO FIXED 2110 ; 2120 LDA ACFP 2130 STA FPPTR1 2140 LDA ACFP+1 2150 STA FPPTR1+1 2160 LDA # <AC 2170 STA FPPTR2 2180 LDA # >AC 2190 STA FPPTR2+1 2200 JSR CONVFIX 2210 LDA BCFP 2220 STA FPPTR1 2230 LDA BCFP+1 2240 STA FPPTR1+1 2250 LDA # <BC 2260 STA FPPTR2 2270 LDA # >BC 2280 STA FPPTR2+1 2290 JSR CONVFIX 2300 LDA AZFP 2310 STA FPPTR1 2320 LDA AZFP+1 2330 STA FPPTR1+1 2340 LDA # <AZ 2350 STA FPPTR2 2360 LDA # >AZ 2370 STA FPPTR2+1 2380 JSR CONVFIX 2390 LDA BZFP 2400 STA FPPTR1 2410 LDA BZFP+1 2420 STA FPPTR1+1 2430 LDA # <BZ 2440 STA FPPTR2 2450 LDA # >BZ 2460 STA FPPTR2+1 2470 JSR CONVFIX 2480 JMP ITERATE 2490 ; 2500 ; CONVERT FP AT FPPTR1 TO 2510 ; FIXED AT FPPTR2 2520 ; 2530 CONVFIX LDY #5 2540 CONV1 LDA (FPPTR1),Y 2550 STA CONVREG,Y 2560 DEY 2570 BPL CONV1 2580 JSR FPTOFIX 2590 LDY #4 2600 CONV2 LDA CONVACC,Y 2610 STA (FPPTR2),Y 2620 DEY 2630 BPL CONV2 2640 RTS 2650 ; 2660 ; CONVERT CONVREG FP TO FIX 2670 ; RESULT IN CONVACC 2680 ; 2690 FPTOFIX 2700 ; GET SIGN 2710 LDA CONVREG 2720 PHA 2730 AND #127 2740 STA CONVREG 2750 PLA 2760 AND #128 2770 BEQ FPFX00 2780 LDA #255 2790 FPFX00 STA CONVACC 2800 ; CONV CONVREG TO DD.DDDDDDDD 2810 ; IN BCD BY MAKING EXP 64 2820 FPFX05 LDA CONVREG 2830 CMP #64 2840 BEQ FPFX10 2850 BPL MOVEL 2860 MOVER INC CONVREG 2870 LDA CONVREG+4 2880 STA CONVREG+5 2890 LDA CONVREG+3 2900 STA CONVREG+4 2910 LDA CONVREG+2 2920 STA CONVREG+3 2930 LDA CONVREG+1 2940 STA CONVREG+2 2950 LDA #0 2960 STA CONVREG+1 2970 BEQ FPFX05 2980 MOVEL DEC CONVREG 2990 LDA CONVREG+2 3000 STA CONVREG+1 3010 LDA CONVREG+3 3020 STA CONVREG+2 3030 LDA CONVREG+4 3040 STA CONVREG+3 3050 LDA CONVREG+5 3060 STA CONVREG+4 3070 LDA #0 3080 STA CONVREG+5 3090 BEQ FPFX05 3100 ; NOW GET DIGITS 3110 FPFX10 LDA #0 3120 STA CONVACC+1 3130 STA CONVACC+2 3140 STA CONVACC+3 3150 STA CONVACC+4 3160 LDX #4 3170 FPFX20 LDA CONVREG+1,X 3180 PHA 3190 AND #15 3200 STA TEMP 3210 PLA 3220 AND #240 3230 LSR A 3240 LSR A 3250 LSR A 3260 LSR A 3270 PHA 3280 ASL A 3290 ASL A 3300 ASL A 3310 ADC TEMP 3320 STA TEMP 3330 PLA 3340 ASL A 3350 ADC TEMP 3360 STA F1D 3370 LDA #0 3380 STA F1C 3390 STA F1B 3400 STA F1A 3410 JSR DIV100X 3420 CLC 3430 LDA F1A 3440 ADC CONVACC+4 3450 STA CONVACC+4 3460 LDA F1B 3470 ADC CONVACC+3 3480 STA CONVACC+3 3490 LDA F1C 3500 ADC CONVACC+2 3510 STA CONVACC+2 3520 LDA F1D 3530 ADC CONVACC+1 3540 STA CONVACC+1 3550 DEX 3560 BPL FPFX20 3570 ; CONVACC NOW IN BY.BY,BY,BY 3580 ; FORMAT-CONVERT TO 5 BIT INT 3590 ; WITH 27 BIT FRACTION 3600 LDX #3 3610 FPFX30 ASL CONVACC+4 3620 ROL CONVACC+3 3630 ROL CONVACC+2 3640 ROL CONVACC+1 3650 DEX 3660 BNE FPFX30 3670 RTS 3680 ; 3690 ; DIVIDE BY 100 X TIMES 3700 ; NO ACTION IF X IS 0 3710 ; 3720 DIV100X CPX #0 3730 BEQ D100X9 3740 TXA 3750 PHA ; SAVE X REG 3760 TAY 3770 ; MULTIPLY BY .01 Y TIMES 3780 D100X1 LDX #3 3790 D100X2 LDA CP01,X 3800 STA F2D,X 3810 DEX 3820 BPL D100X2 3830 JSR MULFIX 3840 LDX #3 3850 D100X3 LDA F3D,X 3860 STA F1D,X 3870 DEX 3880 BPL D100X3 3890 ; DEC Y THEN LOOP IF MORE 3900 DEY 3910 BNE D100X1 3920 PLA ; RESTORE X REG 3930 TAX 3940 D100X9 RTS 3950 ; 3960 ; FIXED POINT MULTIPLY 3970 ; F3 EQ F1 TIMES F2 3980 ; 3990 MULFIX LDA F1S 4000 EOR F2S 4010 STA F3S 4020 LDA #0 4030 STA F3A 4040 STA F3B 4050 STA F3C 4060 STA F3D 4070 LDX #33 4080 CLC 4090 MFX10 ROR F3D 4100 ROR F3C 4110 ROR F3B 4120 ROR F3A 4130 ROR F2D 4140 ROR F2C 4150 ROR F2B 4160 ROR F2A 4170 BCC MFX20 4180 CLC 4190 LDA F1A 4200 ADC F3A 4210 STA F3A 4220 LDA F1B 4230 ADC F3B 4240 STA F3B 4250 LDA F1C 4260 ADC F3C 4270 STA F3C 4280 LDA F1D 4290 ADC F3D 4300 STA F3D 4310 MFX20 DEX 4320 BNE MFX10 4330 LDX #5 4340 CLC 4350 MFX30 ROL F2D 4360 ROL F3A 4370 ROL F3B 4380 ROL F3C 4390 ROL F3D 4400 DEX 4410 BNE MFX30 4420 RTS 4430 ; 4440 ; FIXED POINT ADD 4450 ; F3 EQ F1 PLUS F2 4460 ; 4470 ADDFIX LDA F1S 4480 CMP F2S 4490 BEQ AFX10 4500 ; PUT POS IN F1, NEG IN F2 4510 LDA F1S 4520 BEQ AFX05 4530 LDX #4 4540 AFX03 LDA F1S,X 4550 TAY 4560 LDA F2S,X 4570 STA F1S,X 4580 TYA 4590 STA F2S,X 4600 DEX 4610 BPL AFX03 4620 ; COMPLEMENT F2D TO F2A 4630 AFX05 LDA F2D 4640 EOR #255 4650 STA F2D 4660 LDA F2C 4670 EOR #255 4680 STA F2C 4690 LDA F2B 4700 EOR #255 4710 STA F2B 4720 LDA F2A 4730 EOR #255 4740 STA F2A 4750 INC F2A 4760 BNE AFX10 4770 INC F2B 4780 BNE AFX10 4790 INC F2C 4800 BNE AFX10 4810 INC F2D 4820 ; F3D A EQ F1D A PLUS F2D A 4830 AFX10 CLC 4840 LDA F1A 4850 ADC F2A 4860 STA F3A 4870 LDA F1B 4880 ADC F2B 4890 STA F3B 4900 LDA F1C 4910 ADC F2C 4920 STA F3C 4930 LDA F1D 4940 ADC F2D 4950 STA F3D 4960 ; F3S EQ F1S 4970 LDA F1S 4980 STA F3S 4990 ; IF F2S - & F1S + & F3D>127 5000 ; THEN COMP AND INV SIGN 5010 LDA F2S 5020 BEQ AFX20 5030 LDA F1S 5040 BNE AFX20 5050 LDA F3D 5060 AND #128 5070 BEQ AFX20 5080 LDA F3S 5090 EOR #255 5100 STA F3S 5110 LDA F3D 5120 EOR #255 5130 STA F3D 5140 LDA F3C 5150 EOR #255 5160 STA F3C 5170 LDA F3B 5180 EOR #255 5190 STA F3B 5200 LDA F3A 5210 EOR #255 5220 STA F3A 5230 INC F3A 5240 BNE AFX20 5250 INC F3B 5260 BNE AFX20 5270 INC F3C 5280 BNE AFX20 5290 INC F3D 5300 AFX20 RTS 5310 ; 5320 ; MEMORY TO F1... 5330 ; 5340 MTOF1 STX PNTR 5350 STY PNTR+1 5360 LDY #4 5370 MTOF1A LDA (PNTR),Y 5380 STA F1S,Y 5390 DEY 5400 BPL MTOF1A 5410 RTS 5420 ; 5430 ; MEMORY TO F2... 5440 ; 5450 MTOF2 STX PNTR 5460 STY PNTR+1 5470 LDY #4 5480 MTOF2A LDA (PNTR),Y 5490 STA F2S,Y 5500 DEY 5510 BPL MTOF2A 5520 RTS 5530 ; 5540 ; F3 TO MEMORY... 5550 ; 5560 F3TOM STX PNTR 5570 STY PNTR+1 5580 LDY #4 5590 F3TOM1 LDA F3S,Y 5600 STA (PNTR),Y 5610 DEY 5620 BPL F3TOM1 5630 RTS 5640 ; 5650 ; F3 TO F1... 5660 ; 5670 F3TO1 LDX #4 5680 F3TO1A LDA F3S,X 5690 STA F1S,X 5700 DEX 5710 BPL F3TO1A 5720 RTS 5730 ; 5740 ; FIND COUNT VALUE FOR AC,BC 5750 ; 5760 ITERATE LDA #0 5770 STA COUNT 5780 STA COUNT+1 5790 JSR ITERSQ 5800 ; 5810 ; LOOP 5820 ; BZ=AZ*BZ*2+BC 5830 ; 5840 ITER1 LDX # <AZ 5850 LDY # >AZ 5860 JSR MTOF1 5870 LDX # <BZ 5880 LDY # >BZ 5890 JSR MTOF2 5900 JSR MULFIX 5910 JSR F3TO1 5920 ASL F1A 5930 ROL F1B 5940 ROL F1C 5950 ROL F1D 5960 LDX # <BC 5970 LDY # >BC 5980 JSR MTOF2 5990 JSR ADDFIX 6000 LDX # <BZ 6010 LDY # >BZ 6020 JSR F3TOM 6030 ; 6040 ; AZ = AS-BS+AC 6050 ; 6060 LDX # <AS 6070 LDY # >AS 6080 JSR MTOF1 6090 LDX # <BS 6100 LDY # >BS 6110 JSR MTOF2 6120 LDA F2S 6130 EOR #255 6140 STA F2S 6150 JSR ADDFIX 6160 JSR F3TO1 6170 LDX # <AC 6180 LDY # >AC 6190 JSR MTOF2 6200 JSR ADDFIX 6210 LDX # <AZ 6220 LDY # >AZ 6230 JSR F3TOM 6240 JSR ITERSQ 6250 JMP ITER1Z 6260 ; 6270 ; AS=AZ*AZ BS=BZ*BZ 6280 ; 6290 ITERSQ LDX # <AZ 6300 LDY # >AZ 6310 JSR MTOF1 6320 LDX # <AZ 6330 LDY # >AZ 6340 JSR MTOF2 6350 JSR MULFIX 6360 LDX # <AS 6370 LDY # >AS 6380 JSR F3TOM 6390 LDX # <BZ 6400 LDY # >BZ 6410 JSR MTOF1 6420 LDX # <BZ 6430 LDY # >BZ 6440 JSR MTOF2 6450 JSR MULFIX 6460 LDX # <BS 6470 LDY # >BS 6480 JMP F3TOM 6490 ITER1Z 6500 ; 6510 ; SKIP POINT IF REPEAT VALUES 6520 ; ENCOUNTERED (ATTRACTOR DET) 6530 ; 6540 LDA ATTFLG 6550 BNE SKPATT 6560 JMP ITERCNT 6570 SKPATT 6580 LDY COUNT 6590 LDA AZ+1 6600 STA ATTARR,Y 6610 LDA AZ+2 6620 STA ATTARR+$0100,Y 6630 LDA AZ+3 6640 STA ATTARR+$0200,Y 6650 LDA BZ+1 6660 STA ATTARR+$0300,Y 6670 LDA BZ+2 6680 STA ATTARR+$0400,Y 6690 LDA BZ+3 6700 STA ATTARR+$0500,Y 6710 TYA 6720 BEQ ITERCNT 6730 LSR A 6740 TAY 6750 LDA AZ+3 6760 CMP ATTARR+$0200,Y 6770 BNE ITERCNT 6780 LDA AZ+2 6790 CMP ATTARR+$0100,Y 6800 BNE ITERCNT 6810 LDA AZ+1 6820 CMP ATTARR,Y 6830 BNE ITERCNT 6840 LDA BZ+3 6850 CMP ATTARR+$0500,Y 6860 BNE ITERCNT 6870 LDA BZ+2 6880 CMP ATTARR+$0400,Y 6890 BNE ITERCNT 6900 LDA BZ+1 6910 CMP ATTARR+$0300,Y 6920 BNE ITERCNT 6930 ; ATTRACTOR FOUND 6940 LDA LIMIT 6950 STA COUNT 6960 LDA LIMIT+1 6970 STA COUNT+1 6980 LDA #1 6990 STA ATTFLG 7000 JMP ITER4 7010 ITERCNT 7020 ; 7030 ; INC COUNT AND LOOP IF 7040 ; COUNT<LIMIT OR AS+BS < 4 7050 ; 7060 INC COUNT 7070 BNE ITER2 7080 INC COUNT+1 7090 ITER2 LDA COUNT 7100 CMP LIMIT 7110 BNE ITER3 7120 LDA COUNT+1 7130 CMP LIMIT+1 7140 BNE ITER3 7150 LDA #1 7160 STA ATTFLG 7170 JMP ITER4 7180 ITER3 LDX # <AS 7190 LDY # >AS 7200 JSR MTOF1 7210 LDX # <BS 7220 LDY # >BS 7230 JSR MTOF2 7240 JSR ADDFIX 7250 LDA F3D 7260 CMP #32 7270 BCS ITER3A 7280 JMP ITER1 7290 ITER3A LDA #0 7300 STA ATTFLG 7310 ; 7320 ; RETURN VALUE OF COUNT 7330 ; 7340 ITER4 LDA COUNT 7350 LDX COUNT+1 7360 RTS 7370 ; 7380 ; TRANSFORM FUNCTION TO REDUCE 7390 ; COUNT TO PIXEL COLOR 7400 ; CALL WITH ITERCNT,BANDF 7410 ; RETURNS PIXCOL 1 TO 3 7420 ; 7430 QCNT = $D4 7440 BANDF = $D6 7450 PXCOL = $D7 7460 DIVDND = $D8 7470 DIVSOR = $DA 7480 QUOTNT = $DB 7490 ; 7500 TRANSFRM LDY #0 7510 LDA ($C6),Y 7520 STA COUNT 7530 INY 7540 LDA ($C6),Y 7550 STA COUNT+1 7560 INY 7570 LDA ($C6),Y 7580 STA BANDF 7590 LDA #0 7600 STA QCNT 7610 STA QCNT+1 7620 STA PXCOL 7630 ; 7640 ; QCNT=QCNT+QCNT/BANDF+1 7650 ; 7660 TPXLOOP LDA QCNT 7670 STA DIVDND 7680 LDA QCNT+1 7690 STA DIVDND+1 7700 LDA BANDF 7710 STA DIVSOR 7720 JSR DIV16 7730 SEC 7740 LDA QCNT 7750 ADC QUOTNT 7760 STA QCNT 7770 LDA QCNT+1 7780 ADC QUOTNT+1 7790 STA QCNT+1 7800 ; INC PXCOL, IF >2 THEN 0 7810 INC PXCOL 7820 LDA PXCOL 7830 CMP #3 7840 BNE TPX1 7850 LDA #0 7860 STA PXCOL 7870 ; LOOP IF QCNT<COUNT 7880 TPX1 SEC 7890 LDA QCNT 7900 SBC COUNT 7910 LDA QCNT+1 7920 SBC COUNT+1 7930 BCC TPXLOOP 7940 ; RETURN PIXEL COLOR +1 7950 INC PXCOL 7960 LDA PXCOL 7970 LDX #0 7980 RTS 7990 ; 8000 ; 16 BY 8 TO 16 DIVIDE ROUTINE 8010 ; 8020 DIV16 LDA #0 8030 LDY #16 8040 D16UP ASL DIVDND 8050 ROL DIVDND+1 8060 ROL A 8070 CMP DIVSOR 8080 BCC D16DOWN 8090 SBC DIVSOR 8100 D16DOWN ROL QUOTNT 8110 ROL QUOTNT+1 8120 DEY 8130 BNE D16UP 8140 RTS 8150 ; 8160 ; END OF SOURCE 8170 ; 8180 ZZZZ .BYTE 0