1000 ; 1010 ; ML FOR HODGEPODGE MACHINE 1020 ; WTN 4/24/89 VERSION 1.0 1030 ; LM 1-18-92 1040 *= $9000 1050 ; 1060 NEWCELLS = $5000 1070 GUARD1 = NEWCELLS+$1E00 1080 OLDCELLS = GUARD1+81 1090 GUARD2 = OLDCELLS+$1E00 1100 ; 1110 OLDPTR = $D4 1120 NEWPTR = $D6 1130 PNTR1 = $D8 1140 PNTR2 = $DA 1150 TEMP = $DC 1160 KEY = $2FC 1170 RANDOM = $D20A 1180 ; 1190 JMP HPSTART 1200 JMP CONTINUE 1210 ; 1220 NS .BYTE 50 ; NO. OF STATES 1230 K1 .BYTE 1 ; CONST 1 1240 K2 .BYTE 1 ; CONST 2 1250 G .BYTE 12 ; INFECT RATE 1260 GENCNT .BYTE 0,0,0 ; GENER CNT 1270 ; 1280 TABLE .BYTE 0,1,2,80,81,82,160,161,162 1290 CURCELL .BYTE 0 1300 NSPL1 .BYTE 0 1310 AC .BYTE 0 1320 BC .BYTE 0 1330 CC .BYTE 0 1340 SC .BYTE 0,0 1350 PX .BYTE 0 1360 PY .BYTE 0 1370 PC .BYTE 0 1380 ; 1390 HPSTART LDA #0 1400 STA GENCNT 1410 STA GENCNT+1 1420 STA GENCNT+2 1430 ; 1440 ; RANDOM START IN OLDCELLS 1450 ; 1460 LDA # <OLDCELLS 1470 STA OLDPTR 1480 LDA # >OLDCELLS 1490 STA OLDPTR+1 1500 LDY #0 1510 RINIT1 LDA RANDOM 1520 CMP NS 1530 BCS RINIT1 1540 ;LSR A 1550 STA (OLDPTR),Y 1560 INC OLDPTR 1570 BNE RINIT2 1580 INC OLDPTR+1 1590 RINIT2 LDA OLDPTR 1600 CMP # <OLDCELLS+$1E00 1610 BNE RINIT1 1620 LDA OLDPTR+1 1630 CMP # >OLDCELLS+$1E00 1640 BNE RINIT1 1650 ; 1660 ; ZERO OUT GUARD BANDS AND SET 1670 ; NSPL1 TO NS+1, BASE TO SCREEN 1680 ; 1690 CONTINUE LDA #0 1700 TAX 1710 ZGD1 STA GUARD1,X 1720 STA GUARD2,X 1730 INX 1740 CPX #81 1750 BNE ZGD1 1760 LDX NS 1770 INX 1780 STX NSPL1 1790 JSR INITBA 1800 ; 1810 ; MAIN LOOP 1820 ; 1830 MAINLOOP JSR DISPARR 1840 JMP GENER 1850 ; 1860 ; DISPLAY OLDCELLS 1870 ; 1880 LASTY .BYTE 0 1890 DISPARR LDA #0 1900 STA PX 1910 STA PY 1920 STA 77 ; NO FLASHING 1930 LDA # <OLDCELLS 1940 STA OLDPTR 1950 LDA # >OLDCELLS 1960 STA OLDPTR+1 1970 LDA #255 1980 STA LASTY 1990 DISP1 LDY #0 2000 LDA (OLDPTR),Y 2010 STA DIVDND 2020 LDA NSPL1 2030 LSR A 2040 LSR A 2050 STA DIVSOR 2060 JSR DIVIDE8 2070 LDA QUOTNT 2080 LDX PX 2090 LDY PY 2100 CPY LASTY 2110 BEQ DISP1A 2120 STY LASTY 2130 JSR PLOT 2140 JMP DISP1B 2150 DISP1A JSR PLOTX 2160 DISP1B LDA PX 2170 CLC 2180 ADC #2 2190 CMP #160 2200 BNE DISP2 2210 INC PY 2220 LDA #0 2230 DISP2 STA PX 2240 INC OLDPTR 2250 BNE DISP3 2260 INC OLDPTR+1 2270 DISP3 LDA OLDPTR 2280 CMP # <OLDCELLS+$1E00 2290 BNE DISP1 2300 LDA OLDPTR+1 2310 CMP # >OLDCELLS+$1E00 2320 BNE DISP1 2330 RTS 2340 ; 2350 ; GENERATE NEW CELLS 2360 ; 2370 GENER LDA # <OLDCELLS-81 2380 STA OLDPTR 2390 LDA # >OLDCELLS-81 2400 STA OLDPTR+1 2410 LDA # <NEWCELLS 2420 STA NEWPTR 2430 LDA # >NEWCELLS 2440 STA NEWPTR+1 2450 ; 2460 ; GET CURRENT CELL 2470 ; 2480 GENLOOP LDY #81 2490 LDA (OLDPTR),Y 2500 STA CURCELL 2510 ; 2520 ; IF ILL NEWCELL=0 2530 ; 2540 CMP NS 2550 BCC GEN1 2560 LDA #0 2570 TAY 2580 STA (NEWPTR),Y 2590 JMP GENLPE 2600 ; 2610 ; ELSE TOTAL SC STATES AC #INFECT 2620 ; BC #ILL FOR 9 CELL NEIGHBORHOOD 2630 ; 2640 GEN1 LDA #0 2650 STA SC 2660 STA SC+1 2670 STA AC 2680 STA BC 2690 TAX 2700 GETN1 LDY TABLE,X 2710 LDA (OLDPTR),Y 2720 STA CC 2730 CLC 2740 ADC SC 2750 STA SC 2760 LDA #0 2770 ADC SC+1 2780 STA SC+1 2790 LDA CC 2800 BEQ GETN3 2810 CMP NS 2820 BNE GETN2 2830 INC BC 2840 BNE GETN3 2850 GETN2 INC AC 2860 GETN3 INX 2870 CPX #9 2880 BNE GETN1 2890 ; 2900 ; IF CURCELL=0 THEN 2910 ; REGA=[AC/K1]+[BC/K2] 2920 ; 2930 LDA CURCELL 2940 BNE GEN2 2950 LDA AC 2960 STA DIVDND 2970 LDA K1 2980 STA DIVSOR 2990 JSR DIVIDE8 3000 LDA QUOTNT 3010 STA TEMP 3020 LDA BC 3030 STA DIVDND 3040 LDA K2 3050 STA DIVSOR 3060 JSR DIVIDE8 3070 LDA QUOTNT 3080 CLC 3090 ADC TEMP 3100 JMP GEN3 3110 ; 3120 ; ELSE REGA=[SC/AC]+G (MAX NS) 3130 ; 3140 GEN2 JSR INFRULE 3150 ; 3160 ; NEWCELL=REGA AND LOOP 3170 ; 3180 GEN3 LDY #0 3190 STA (NEWPTR),Y 3200 GENLPE INC OLDPTR 3210 BNE GEN5 3220 INC OLDPTR+1 3230 GEN5 INC NEWPTR 3240 BNE GEN6 3250 INC NEWPTR+1 3260 GEN6 LDA NEWPTR 3270 CMP # <NEWCELLS+$1E00 3280 BEQ GEN7 3290 JMP GENLOOP 3300 GEN7 LDA NEWPTR+1 3310 CMP # >NEWCELLS+$1E00 3320 BEQ GEN8 3330 JMP GENLOOP 3340 GEN8 LDA KEY 3350 CMP #28 3360 BNE CHKEY1 3370 ABORT LDA #255 3380 STA KEY 3390 RTS 3400 ; 3410 ; COPY NEWCELLS TO OLDCELLS 3420 ; 3430 CHKEY1 LDA # <NEWCELLS 3440 STA NEWPTR 3450 LDA # >NEWCELLS 3460 STA NEWPTR+1 3470 LDA # <OLDCELLS 3480 STA OLDPTR 3490 LDA # >OLDCELLS 3500 STA OLDPTR+1 3510 LDY #0 3520 GEN9 LDA (NEWPTR),Y 3530 STA (OLDPTR),Y 3540 INC NEWPTR 3550 BNE GEN10 3560 INC NEWPTR+1 3570 GEN10 INC OLDPTR 3580 BNE GEN11 3590 INC OLDPTR+1 3600 GEN11 LDA NEWPTR 3610 CMP # <NEWCELLS+$1E00 3620 BNE GEN9 3630 LDA NEWPTR+1 3640 CMP # >NEWCELLS+$1E00 3650 BNE GEN9 3660 INC GENCNT 3670 BNE GEN12 3680 INC GENCNT+1 3690 BNE GEN12 3700 INC GENCNT+2 3710 GEN12 JMP MAINLOOP 3720 ; 3730 ; 16 TO 8 DIVIDE 3740 ; 3750 DIV16 LDA DIVDND+1 3760 BEQ DIVIDE8 3770 LDA #0 3780 LDY #16 3790 D16UP ASL DIVDND 3800 ROL DIVDND+1 3810 ROL A 3820 CMP DIVSOR 3830 BCC D16DOWN 3840 SBC DIVSOR 3850 D16DOWN ROL QUOTNT 3860 DEY 3870 BNE D16UP 3880 RTS 3890 ; 3900 ; 8 TO 8 DIVIDE 3910 ; 3920 DIVIDE8 LDA DIVSOR 3930 CMP #1 3940 BNE DIV8A 3950 LDA DIVDND 3960 STA QUOTNT 3970 RTS 3980 DIV8A CMP #2 3990 BNE DIV8B 4000 LDA DIVDND 4010 LSR A 4020 STA QUOTNT 4030 RTS 4040 DIV8B LDA #0 4050 LDY #8 4060 DIVUP ASL DIVDND 4070 ROL A 4080 CMP DIVSOR 4090 BCC DIVDN 4100 SBC DIVSOR 4110 DIVDN ROL QUOTNT 4120 DEY 4130 BNE DIVUP 4140 RTS 4150 ; 4160 DIVDND .BYTE 0,0 4170 DIVSOR .BYTE 0 4180 QUOTNT .BYTE 0 4190 ; 4200 INFRULE LDA AC 4210 CMP #1 4220 BEQ INFR10 4230 CMP #2 4240 BNE INFR2 4250 LSR SC+1 4260 ROR SC 4270 JMP INFR10 4280 INFR2 CMP #4 4290 BNE INFR3 4300 LSR SC+1 4310 ROR SC 4320 LSR SC+1 4330 ROR SC 4340 JMP INFR10 4350 INFR3 CMP #8 4360 BNE INFR4 4370 LSR SC+1 4380 ROR SC 4390 LSR SC+1 4400 ROR SC 4410 LSR SC+1 4420 ROR SC 4430 JMP INFR10 4440 INFR4 STA DIVSOR 4450 LDA SC 4460 STA DIVDND 4470 LDA SC+1 4480 STA DIVDND+1 4490 JSR DIV16 4500 LDA QUOTNT 4510 JMP INFR11 4520 INFR10 LDA SC 4530 INFR11 CLC 4540 ADC G 4550 BVS INFRTOBG 4560 CMP NSPL1 4570 BCC INFROK 4580 INFRTOBG LDA NS 4590 INFROK RTS 4600 ; 4610 BYADR = $E0 4620 OLDBY = $E2 4630 NEWBY = $E3 4640 DLIST = $E4 4650 PXCOL = $E6 4660 PXNUM = $E7 4670 BASE .BYTE 0,0 4680 ; 4690 ; GET START OF BITMAP 4700 ; 4710 INITBA LDA $58 4720 STA BASE 4730 LDA $59 4740 STA BASE+1 4750 RTS 4810 ; 4820 ; PLOT PIXEL X,Y COLOR A 4830 ; 4840 BYADRY .BYTE 0,0 4850 PLOT STA PXCOL 4860 TYA 4870 STA BYADRY 4880 STA PNTR2 4890 LDA #0 4900 STA BYADRY+1 4910 STA PNTR2+1 4920 LDY #5 4930 PLOT1 ASL BYADRY 4940 ROL BYADRY+1 4950 DEY 4960 BNE PLOT1 4970 LDY #3 4980 PLOT2 ASL PNTR2 4990 ROL PNTR2+1 5000 DEY 5010 BNE PLOT2 5020 CLC 5030 LDA BYADRY 5040 ADC PNTR2 5050 STA BYADRY 5060 LDA BYADRY+1 5070 ADC PNTR2+1 5080 STA BYADRY+1 5090 CLC 5100 LDA BYADRY 5110 ADC BASE 5120 STA BYADRY 5130 LDA BYADRY+1 5140 ADC BASE+1 5150 STA BYADRY+1 5160 LDA PXCOL 5170 PLOTX STA PXCOL 5180 TXA 5190 AND #3 5200 STA PXNUM 5210 TXA 5220 LSR A 5230 LSR A 5240 CLC 5250 ADC BYADRY 5260 STA BYADR 5270 LDA #0 5280 ADC BYADRY+1 5290 STA BYADR+1 5300 LDY #0 5310 LDA (BYADR),Y 5320 STA OLDBY 5330 LDY PXNUM 5340 LDA BITMASK,Y 5350 TAX 5360 AND OLDBY 5370 STA OLDBY 5380 TXA 5390 EOR #255 5400 STA NEWBY 5410 LDY PXCOL 5420 LDA COLMASK,Y 5430 AND NEWBY 5440 ORA OLDBY 5450 LDY #0 5460 STA (BYADR),Y 5470 RTS 5480 ; 5490 ; TABLES 5500 ; 5510 BITMASK .BYTE $0F ; DOUBLE PIXELS 5520 .BYTE $0F 5530 .BYTE $F0 5540 .BYTE $F0 5550 COLMASK .BYTE 0 5560 .BYTE 85 5570 .BYTE 170 5580 .BYTE 255 5590 ZZZ .BYTE 0