1000 ; 1010 ; LIFE 96 BY 160 02/03/92 WTN 1020 ; 1030 GUARD1 = $5300 1040 COUNT = $5400 ;HN=NEW LN=OLD 1050 GUARD2 = $9000 1060 STATE = $9100 ; TO 9FFF 1070 *= $A000 1080 JMP GENERATE ;PRODUCE 1 GEN 1090 JMP INITIALIZE ;INIT TO BM 1100 JMP RANDOMSTART ;RANDOM INIT 1110 POPULATION .BYTE 0,0 1120 DENSITY .BYTE 64 ;RND START DENS 1130 RPTS .BYTE 30 ;# REPEATS UNTIL 1140 ITSDEAD .BYTE 127;1 IF REPEATING 1150 MONO .BYTE 0 ;1 DISPLAYS MONO 1160 PCNT .BYTE 0,0 1170 DEAD .BYTE 0 1180 ; 1190 ; INITIALIZE COUNT ARRAYS 1200 ; 1210 INITIALIZE 1220 ; INIT STBL TO COLOR OR MONO 1230 LDA MONO 1240 BEQ INIT005 1250 LDA #85 1260 STA STBL+1 1270 STA STBL+2 1280 STA STBL+3 1290 BNE INIT007 1300 INIT005 LDA #85 1310 STA STBL+1 1320 LDA #170 1330 STA STBL+2 1340 LDA #255 1350 STA STBL+3 1360 ; COPY BITMAP TO STATE 1370 INIT007 LDA $58 1380 STA $D4 1390 LDA $59 1400 STA $D5 1410 LDA # <STATE 1420 STA $D6 1430 LDA # >STATE 1440 STA $D7 1450 LDY #0 1460 INIT010 LDA ($D4),Y 1470 STA ($D6),Y 1480 INY 1490 BNE INIT010 1500 INC $D5 1510 INC $D7 1520 LDA $D7 1530 CMP # >STATE+3840 1540 BNE INIT010 1550 ; ZERO COUNT ARRAY 1560 INIT035 LDX #0 1570 STX PCNT 1580 STX PCNT+1 1590 LDA # <COUNT 1600 STA $D4 1610 LDA # >COUNT 1620 STA $D5 1630 INIT040 TXA 1640 STA ($D4),Y 1650 INY 1660 BNE INIT040 1670 INC $D5 1680 LDA $D5 1690 CMP # >COUNT+15360 1700 BNE INIT040 1710 ; INC SURR COUNTS FOR EACH ON CELL 1720 LDA # <COUNT 1730 STA $D4 1740 LDA # >COUNT 1750 STA $D5 1760 LDA # <STATE 1770 STA $D6 1780 LDA # >STATE 1790 STA $D7 1800 INIT100 LDY #0 1810 LDA $D4 1820 AND #3 1830 TAX 1840 LDA ($D6),Y 1850 AND BMASK1,X 1860 BEQ INIT110 1870 JSR INCSURR 1880 LDA MONO 1890 BEQ INIT110 1900 LDA #1 1910 JSR PUTSTATE 1920 INIT110 INC $D4 1930 BNE INIT120 1940 INC $D5 1950 INIT120 LDA $D4 1960 AND #3 1970 BNE INIT100 1980 INC $D6 1990 BNE INIT130 2000 INC $D7 2010 INIT130 LDA $D6 2020 CMP # <STATE+3840 2030 BNE INIT100 2040 LDA $D7 2050 CMP # >STATE+3840 2060 BNE INIT100 2070 ; ARRAYS INITIALIZED 2080 LDA #0 2090 STA BCNT ;ZERO BORING COUNT 2100 STA DEAD ;IT'S NOT DEAD 2110 LDA PCNT ;UPDATE POP 2120 STA POPULATION 2130 LDA PCNT+1 2140 STA POPULATION+1 2150 RTS 2160 BMASK1 .BYTE 192,48,12,3 2170 ;PUT A IN STATE ARRAY 2180 BITMASK .BYTE 63,207,243,252 2190 PUTSTATE TAX 2200 LDA STBL,X 2210 PHA 2220 LDA $D4 2230 AND #3 2240 TAX 2250 LDY #0 2260 LDA ($D6),Y 2270 AND BITMASK,X 2280 STA $D8 2290 PLA 2300 AND BMASK1,X 2310 ORA $D8 2320 STA ($D6),Y 2330 RTS 2340 STBL .BYTE 0,85,170,255 2350 ; 2360 ; GENERATE 1 NEW GENERATION 2370 ; 2380 GENERATE 2390 ; DISPLAY PREV GENERATION 2400 LDA # <STATE 2410 STA $D4 2420 LDA # >STATE 2430 STA $D5 2440 LDA $58 2450 STA $D6 2460 LDA $59 2470 STA $D7 2480 LDY #0 2490 GEN150 LDA ($D4),Y 2500 STA ($D6),Y 2510 INY 2520 BNE GEN150 2530 INC $D5 2540 INC $D7 2550 LDA $D5 2560 CMP # >STATE+3840 2570 BNE GEN150 2580 ; UPDATE STATUS 2590 LDA PCNT 2600 STA POPULATION 2610 LDA PCNT+1 2620 STA POPULATION+1 2630 LDA DEAD 2640 STA ITSDEAD 2650 ; COPY NEW COUNTS TO OLD COUNTS 2660 ; (TRANSFER UPPER TO LOWER NIB) 2670 LDA # <COUNT 2680 STA $D4 2690 LDA # >COUNT 2700 STA $D5 2710 LDY #0 2720 GEN010 LDA ($D4),Y 2730 BEQ GEN012 ;DONT SHIFT 0 2740 AND #$F0 2750 STA $D8 2760 LSR A 2770 LSR A 2780 LSR A 2790 LSR A 2800 ORA $D8 2810 STA ($D4),Y 2820 GEN012 INY 2830 BNE GEN010 2840 INC $D5 2850 LDA $D5 2860 CMP # >COUNT+15360 2870 BNE GEN010 2880 ;FOR EACH CELL... 2890 ; IF STATE=0 2900 ; IF COUNT=3 STATE=1 INCSURR 2910 ; IF STATE>0 2920 ; IF COUNT=2 STATE=2 2930 ; ELSE IF COUNT=3 STATE=3 2940 ; ELSE STATE=0 DECSURR 2950 LDA # <COUNT 2960 STA $D4 2970 LDA # >COUNT 2980 STA $D5 2990 LDA # <STATE 3000 STA $D6 3010 LDA # >STATE 3020 STA $D7 3030 LDX #0 3040 GEN020 LDY #0 3050 LDA ($D6),Y 3060 AND BMASK1,X 3070 BNE GEN050 ; GO IF ALIVE 3080 LDA ($D4),Y 3090 BEQ GEN100 3100 AND #$0F ; GET OLD COUNT 3110 CMP #3 3120 BNE GEN100 3130 JSR INCSURR ;BIRTH 3140 LDA #1 3150 BNE GEN060 3160 GEN050 LDA ($D4),Y 3170 AND #$0F 3180 CMP #2 ;SURV BY 2 3190 BEQ GEN060 3200 CMP #3 3210 BEQ GEN060 3220 JSR DECSURR ; DEATH 3230 LDA #0 3240 GEN060 JSR PUTSTATE 3250 GEN100 INC $D4 3260 BNE GEN110 3270 INC $D5 3280 GEN110 LDA $D4 3290 AND #3 3300 TAX 3310 BNE GEN020 3320 INC $D6 3330 BNE GEN020 3340 INC $D7 3350 LDA $D7 3360 CMP # >STATE+3840 3370 BNE GEN020 3380 ; DONE WITH ONE GENERATION 3390 JMP BORING 3400 ; RANDOM START 3410 RANDOMSTART 3420 LDA #0 3430 STA $D4 3440 LDA # <STATE 3450 STA $D6 3460 LDA # >STATE 3470 STA $D7 3480 RAND005 LDA #0 3490 TAY 3500 STA ($D6),Y 3510 RAND010 LDA $D20A ;RAND # GEN 3520 CMP DENSITY 3530 BCS RAND020 3540 LDA #1 3550 JSR PUTSTATE 3560 RAND020 INC $D4 3570 LDA $D4 3580 AND #3 3590 BNE RAND010 3600 INC $D6 3610 BNE RAND030 3620 INC $D7 3630 RAND030 LDA $D6 3640 CMP # <STATE+3840 3650 BNE RAND005 3660 LDA $D7 3670 CMP # >STATE+3840 3680 BNE RAND005 3690 JMP INIT035 3700 ; BORING LIFE DETECTION 3710 PC1 .BYTE 0 3720 PC2 .BYTE 0 3730 PC3 .BYTE 0 3740 BCNT .BYTE 0 3750 BORING LDA PCNT 3760 CMP PC1 3770 BEQ BOR1 3780 CMP PC2 3790 BEQ BOR1 3800 CMP PC3 3810 BEQ BOR1 3820 LDA #0 3830 STA BCNT 3840 BOR1 INC BCNT 3850 LDA BCNT 3860 CMP RPTS 3870 BCC BOR2 3880 LDA #1 3890 BNE BOR9 3900 BOR2 LDA PC2 3910 STA PC3 3920 LDA PC1 3930 STA PC2 3940 LDA PCNT 3950 STA PC1 3960 LDA #0 3970 BOR9 STA DEAD 3980 RTS 3990 INCSURR LDY #0 4000 SEC 4010 LDA $D4 4020 SBC #161 4030 STA $D8 4040 LDA $D5 4050 SBC #0 4060 STA $D9 4070 CLC 4080 LDA ($D8),Y 4090 ADC #16 4100 STA ($D8),Y 4110 INY 4120 CLC 4130 LDA ($D8),Y 4140 ADC #16 4150 STA ($D8),Y 4160 INY 4170 CLC 4180 LDA ($D8),Y 4190 ADC #16 4200 STA ($D8),Y 4210 SEC 4220 LDA $D4 4230 SBC #1 4240 STA $D8 4250 LDA $D5 4260 SBC #0 4270 STA $D9 4280 LDY #0 4290 CLC 4300 LDA ($D8),Y 4310 ADC #16 4320 STA ($D8),Y 4330 INY 4340 INY 4350 CLC 4360 LDA ($D8),Y 4370 ADC #16 4380 STA ($D8),Y 4390 LDY #160 4400 CLC 4410 LDA ($D8),Y 4420 ADC #16 4430 STA ($D8),Y 4440 INY 4450 CLC 4460 LDA ($D8),Y 4470 ADC #16 4480 STA ($D8),Y 4490 INY 4500 CLC 4510 LDA ($D8),Y 4520 ADC #16 4530 STA ($D8),Y 4540 INC PCNT 4550 BNE INC050 4560 INC PCNT+1 4570 INC050 RTS 4580 DECSURR LDY #0 4590 SEC 4600 LDA $D4 4610 SBC #161 4620 STA $D8 4630 LDA $D5 4640 SBC #0 4650 STA $D9 4660 LDA ($D8),Y 4670 SBC #16 4680 STA ($D8),Y 4690 INY 4700 SEC 4710 LDA ($D8),Y 4720 SBC #16 4730 STA ($D8),Y 4740 INY 4750 SEC 4760 LDA ($D8),Y 4770 SBC #16 4780 STA ($D8),Y 4790 SEC 4800 LDA $D4 4810 SBC #1 4820 STA $D8 4830 LDA $D5 4840 SBC #0 4850 STA $D9 4860 LDY #0 4870 LDA ($D8),Y 4880 SBC #16 4890 STA ($D8),Y 4900 INY 4910 INY 4920 SEC 4930 LDA ($D8),Y 4940 SBC #16 4950 STA ($D8),Y 4960 LDY #160 4970 SEC 4980 LDA ($D8),Y 4990 SBC #16 5000 STA ($D8),Y 5010 INY 5020 SEC 5030 LDA ($D8),Y 5040 SBC #16 5050 STA ($D8),Y 5060 INY 5070 SEC 5080 LDA ($D8),Y 5090 SBC #16 5100 STA ($D8),Y 5110 SEC 5120 LDA PCNT 5130 SBC #1 5140 STA PCNT 5150 LDA PCNT+1 5160 SBC #0 5170 STA PCNT+1 5180 RTS 5190 ZZZ .BYTE 0