0100 ; 0110 ; LIFEHACK VERS 1.3s 12/26/90 0120 ; BY WILLIAM TERRY NEWTON 0130 ; M65 SOURCE VERSION 0140 ; 0150 *= $8000 0160 ; 0170 DELAYTM = 80 0180 CELL = 84 0190 SPC = 0 0200 RD = 64 0210 RPTS = 30 0220 SCRNBA = $58 0230 RANDOM = $D20A 0240 MAINARR = $7000 0250 OLDCNT = $7400 0260 NEWCNT = $7800 0270 SCPTR = $D4 0280 MAPTR = $D6 0290 OCPTR = $D8 0300 NCPTR = $DA 0310 COLR1 = $02C5 0320 COLR2 = $02C6 0330 COLR4 = $02C8 0340 KEYCODE = 764 0350 ; 0360 ; SET COLORS 0370 ; INIT SCREND THEN RND START 0380 LDA #220 0390 STA COLR1 0400 LDA #0 0410 STA COLR2 0420 STA COLR4 0430 LDA #0 0440 STA FSFLAG 0450 CLC 0460 LDA SCRNBA 0470 ADC # <960 0480 STA SCREND 0490 LDA SCRNBA+1 0500 ADC # >960 0510 STA SCREND+1 0520 JMP RENTRY 0530 ; RANDOM START IN MAINARR 0540 RANDFLG .BYTE 0 0550 RAND LDA # <MAINARR 0560 STA MAPTR 0570 LDA # >MAINARR 0580 STA MAPTR+1 0590 LDY #0 0600 RAND1 LDA RANDOM 0610 CMP #RD 0620 BCC RAND2 0630 LDA #SPC 0640 .BYTE $2C 0650 RAND2 LDA #CELL 0660 STA (MAPTR),Y 0670 INC MAPTR 0680 BNE RAND3 0690 INC MAPTR+1 0700 RAND3 LDA MAPTR 0710 CMP # <MAINARR+960 0720 BNE RAND1 0730 LDA MAPTR+1 0740 CMP # >MAINARR+960 0750 BNE RAND1 0760 LDA #1 0770 STA RANDFLG 0780 BNE INIT 0790 ; COPY SCREEN TO MAINARR 0800 STLIFE LDA #0 0810 STA RANDFLG 0820 LDA SCRNBA 0830 STA SCPTR 0840 LDA SCRNBA+1 0850 STA SCPTR+1 0860 LDA # <MAINARR 0870 STA MAPTR 0880 LDA # >MAINARR 0890 STA MAPTR+1 0900 LDY #0 0910 STL1 LDA (SCPTR),Y 0920 STA (MAPTR),Y 0930 INC MAPTR 0940 BNE STL2 0950 INC MAPTR+1 0960 STL2 INC SCPTR 0970 BNE STL3 0980 INC SCPTR+1 0990 STL3 LDA MAPTR 1000 CMP # <MAINARR+960 1010 BNE STL1 1020 LDA MAPTR+1 1030 CMP # >MAINARR+960 1040 BNE STL1 1050 ; CLEAR NEW COUNTS 1060 INIT LDA # <NEWCNT 1070 STA NCPTR 1080 LDA # >NEWCNT 1090 STA NCPTR+1 1100 LDY #0 1110 TYA 1120 INIT0 STA (NCPTR),Y 1130 INC NCPTR 1140 BNE INIT0A 1150 INC NCPTR+1 1160 INIT0A LDX NCPTR 1170 CPX # <NEWCNT+1042 1180 BNE INIT0 1190 LDX NCPTR+1 1200 CPX # >NEWCNT+1042 1210 BNE INIT0 1220 ; FOR EACH LIVE CELL IN MAINARR 1230 ; INCREMENT COUNT IN NEWCNT 1240 LDA # <MAINARR 1250 STA MAPTR 1260 LDA # >MAINARR 1270 STA MAPTR+1 1280 LDA # <NEWCNT 1290 STA NCPTR 1300 LDA # >NEWCNT 1310 STA NCPTR+1 1320 INIT1 LDY #0 1330 LDA (MAPTR),Y 1340 CMP #SPC 1350 BEQ INIT2 1360 JSR INCSURR 1370 INIT2 INC MAPTR 1380 BNE INIT3 1390 INC MAPTR+1 1400 INIT3 INC NCPTR 1410 BNE INIT4 1420 INC NCPTR+1 1430 INIT4 LDA MAPTR 1440 CMP # <MAINARR+960 1450 BNE INIT1 1460 LDA MAPTR+1 1470 CMP # >MAINARR+960 1480 BNE INIT1 1490 ; MAIN LOOP... 1500 ; DISPLAY MAINARR ON SCREEN 1510 LOOP LDA #0 1520 STA 77 ; NO FLASH 1530 LDA SCRNBA 1540 STA SCPTR 1550 LDA SCRNBA+1 1560 STA SCPTR+1 1570 LDA # <MAINARR 1580 STA MAPTR 1590 LDA # >MAINARR 1600 STA MAPTR+1 1610 LDY #0 1620 DISP1 LDA (MAPTR),Y 1630 STA (SCPTR),Y 1640 INC SCPTR 1650 BNE DISP2 1660 INC SCPTR+1 1670 DISP2 INC MAPTR 1680 BNE DISP3 1690 INC MAPTR+1 1700 DISP3 LDA MAPTR 1710 CMP # <MAINARR+960 1720 BNE DISP1 1730 LDA MAPTR+1 1740 CMP # >MAINARR+960 1750 BNE DISP1 1760 ; COPY NEWCNTS TO OLDCNTS 1770 ; WITH 41 BYTE OFFSET 1780 LDA # <NEWCNT+41 1790 STA NCPTR 1800 LDA # >NEWCNT+41 1810 STA NCPTR+1 1820 LDA # <OLDCNT 1830 STA OCPTR 1840 LDA # >OLDCNT 1850 STA OCPTR+1 1860 LDY #0 1870 LOOP1 LDA (NCPTR),Y 1880 STA (OCPTR),Y 1890 INC NCPTR 1900 BNE LOOP1A 1910 INC NCPTR+1 1920 LOOP1A INC OCPTR 1930 BNE LOOP1B 1940 INC OCPTR+1 1950 LOOP1B LDA OCPTR 1960 CMP # <OLDCNT+960 1970 BNE LOOP1 1980 LDA OCPTR+1 1990 CMP # >OLDCNT+960 2000 BNE LOOP1 2010 ; FOR EACH CELL CHECK OLDCNTS, 2020 ; MAINARR FOR LIFE/DEATH AND 2030 ; UPDATE NEWCNTS 2040 LDA # <MAINARR 2050 STA MAPTR 2060 LDA # >MAINARR 2070 STA MAPTR+1 2080 LDA # <OLDCNT 2090 STA OCPTR 2100 LDA # >OLDCNT 2110 STA OCPTR+1 2120 LDA # <NEWCNT 2130 STA NCPTR 2140 LDA # >NEWCNT 2150 STA NCPTR+1 2160 LIFE1 LDY #0 2170 LDA (MAPTR),Y 2180 TAX 2190 LDA (OCPTR),Y 2200 CMP #2 2210 BCC LIFE2 2220 CMP #4 2230 BCS LIFE2 2240 CPX #SPC 2250 BNE LIFE3 2260 CMP #3 2270 BNE LIFE3 2280 LDA #CELL 2290 STA (MAPTR),Y 2300 JSR INCSURR 2310 JMP LIFE3 2320 LIFE2 CPX #SPC 2330 BEQ LIFE3 2340 LDA #SPC 2350 STA (MAPTR),Y 2360 JSR DECSURR 2370 LIFE3 INC MAPTR 2380 BNE LIFE3A 2390 INC MAPTR+1 2400 LIFE3A INC OCPTR 2410 BNE LIFE3B 2420 INC OCPTR+1 2430 LIFE3B INC NCPTR 2440 BNE LIFE3C 2450 INC NCPTR+1 2460 LIFE3C LDA MAPTR 2470 CMP # <MAINARR+960 2480 BNE LIFE1 2490 LDA MAPTR+1 2500 CMP # >MAINARR+960 2510 BNE LIFE1 2520 ; BORING LIFE DETECTION 2530 ; RANDOM ONLY 2540 LDA RANDFLG 2550 BEQ BOR9 2560 LDA PC 2570 CMP PC1 2580 BEQ BOR1 2590 CMP PC2 2600 BEQ BOR1 2610 CMP PC3 2620 BEQ BOR1 2630 LDA #0 2640 STA BCNT 2650 BOR1 INC BCNT 2660 LDA BCNT 2670 CMP #RPTS 2680 BCC BOR2 2690 JMP RAND 2700 BOR2 LDA PC2 2710 STA PC3 2720 LDA PC1 2730 STA PC2 2740 LDA PC 2750 STA PC1 2760 ; DELAY IF SLOW 2770 BOR9 LDA FSFLAG 2780 BEQ CHKKEY 2790 LDX #DELAYTM 2800 LDY #DELAYTM 2810 DELLP PHA 2820 PLA 2830 DEX 2840 BNE DELLP 2850 DEY 2860 BNE DELLP 2870 ; CHECK KB, F-FAST S-SLOW 2880 ; ANY OTHER RETURNS TO EDITOR 2890 CHKKEY LDA KEYCODE 2900 CMP #255 2910 BNE CK1 2920 JMP LOOP 2930 CK1 LDX #255 2940 STX 764 2950 CMP #56 2960 BNE CK2 2970 LDA #0 2980 CK1A STA FSFLAG 2990 JMP LOOP 3000 CK2 CMP #62 3010 BNE CK3 3020 LDA #1 3030 BNE CK1A 3040 CK3 RTS 3050 FSFLAG .BYTE 0 3060 ; INC SURROUNDING NEWCNTS 3070 INCSURR LDX #8 3080 IS1 LDY CELLTAB-1,X 3090 LDA (NCPTR),Y 3100 CLC 3110 ADC #1 3120 STA (NCPTR),Y 3130 INC PC 3140 DEX 3150 BNE IS1 3160 RTS 3170 ; DEC SURROUNDING NEWCNTS 3180 DECSURR LDX #8 3190 DS1 LDY CELLTAB-1,X 3200 LDA (NCPTR),Y 3210 SEC 3220 SBC #1 3230 STA (NCPTR),Y 3240 DEC PC 3250 DEX 3260 BNE DS1 3270 RTS 3280 ; CELL OFFSET TABLE,ETC 3290 CELLTAB .BYTE 0 3300 .BYTE 1 3310 .BYTE 2 3320 .BYTE 40 3330 .BYTE 42 3340 .BYTE 80 3350 .BYTE 81 3360 .BYTE 82 3370 PC .BYTE 0 3380 PC1 .BYTE 0 3390 PC2 .BYTE 0 3400 PC3 .BYTE 0 3410 BCNT .BYTE 0 3420 ; 3430 ; STARTUP AND CELL EDITOR 3440 ; 3450 ; RANDOM MODE IS CALLED AFTER 3460 ; ENTRY - EDITOR UPON RETURN 3470 ; FROM RANDOM MODE 3480 ; 3490 SCREND .BYTE 0,0 3500 ; CLEAR SCREEN 3510 EDITOR 3520 LDA SCRNBA 3530 STA SCPTR 3540 LDA SCRNBA+1 3550 STA SCPTR+1 3560 LDA #SPC 3570 LDY #0 3580 CLS1 STA (SCPTR),Y 3590 INC SCPTR 3600 BNE CLS2 3610 INC SCPTR+1 3620 CLS2 LDX SCPTR 3630 CPX SCREND 3640 BNE CLS1 3650 LDX SCPTR+1 3660 CPX SCREND+1 3670 BNE CLS1 3680 ; EDITOR LOOP 3690 ; SET CURSOR POSITION 3700 EDITOR1 LDA SCRNBA 3710 ADC # <500 3720 STA SCPTR 3730 LDA SCRNBA+1 3740 ADC # >500 3750 STA SCPTR+1 3760 ; EDITOR LOOP... 3770 ; INVERT CURSOR AND WAIT FOR KEY 3780 EDLOOP LDY #0 3790 CLC 3800 LDA (SCPTR),Y 3810 ORA #128 3820 STA (SCPTR),Y 3830 ED1 LDA KEYCODE 3840 CMP #255 3850 BEQ ED1 3860 TAX ; KEYCODE IN X 3870 LDA #255 3880 STA KEYCODE 3890 LDA (SCPTR),Y 3900 AND #127 3910 STA (SCPTR),Y 3920 ; SPACE? CHANGE CELL STATE 3930 CPX #33 3940 BNE ED2 3950 CMP #SPC 3960 BNE ED1A 3970 LDA #CELL 3980 .BYTE $2C 3990 ED1A LDA #SPC 4000 STA (SCPTR),Y 4010 JMP EDLOOP 4020 ; R? RANDOM START 4030 ED2 CPX #40 4040 BNE ED3 4050 RENTRY JSR RAND 4060 JMP EDITOR1 4070 ; RET? START LIFE 4080 ED3 CPX #12 4090 BNE ED4 4100 JSR STLIFE 4110 JMP EDITOR1 4120 ; <? CLEAR SCREEN 4130 ED4 CPX #54 4140 BNE ED5 4150 JMP EDITOR 4160 ; -? UP 4170 ED5 CPX #14 4180 BNE ED6 4190 SEC 4200 LDA SCPTR 4210 SBC #40 4220 STA SCPTR 4230 LDA SCPTR+1 4240 SBC #0 4250 STA SCPTR+1 4260 JMP RANGECHK 4270 ; =? DOWN 4280 ED6 CPX #15 4290 BNE ED7 4300 CLC 4310 LDA SCPTR 4320 ADC #40 4330 STA SCPTR 4340 LDA SCPTR+1 4350 ADC #0 4360 STA SCPTR+1 4370 JMP RANGECHK 4380 ; +? LEFT 4390 ED7 CPX #6 4400 BNE ED8 4410 SEC 4420 LDA SCPTR 4430 SBC #1 4440 STA SCPTR 4450 LDA SCPTR+1 4460 SBC #0 4470 STA SCPTR+1 4480 JMP RANGECHK 4490 ; *? RIGHT 4500 ED8 CPX #7 4510 BNE ED9 4520 INC SCPTR 4530 BNE ED8A 4540 INC SCPTR+1 4550 ED8A JMP RANGECHK 4560 ; NOTHING VALID SO LOOP 4570 ED9 JMP EDLOOP 4580 ; CHECK RANGE 4590 ; TOO BIG? 4600 RANGECHK SEC 4610 LDA SCPTR 4620 SBC SCREND 4630 LDA SCPTR+1 4640 SBC SCREND+1 4650 BCS TOOBIG 4660 ; TOO SMALL? 4670 SEC 4680 LDA SCPTR 4690 SBC SCRNBA 4700 LDA SCPTR+1 4710 SBC SCRNBA+1 4720 BCC TOOSMALL 4730 ; OK SO LOOP 4740 OK JMP EDLOOP 4750 ; TOO BIG-SUBTRACT 960 4760 TOOBIG LDA SCPTR 4770 SBC # <960 4780 STA SCPTR 4790 LDA SCPTR+1 4800 SBC # >960 4810 STA SCPTR+1 4820 JMP EDLOOP 4830 ; TOO SMALL-ADD 960 4840 TOOSMALL LDA SCPTR 4850 ADC # <960 4860 STA SCPTR 4870 LDA SCPTR+1 4880 ADC # >960 4890 STA SCPTR+1 4900 JMP EDLOOP 4910 ; END OF SOURCE