Life3 *NAME Life3  code% 1000 ( m1% 34*66 2 m2% 34*66 <: Fassemble Pmap1?0=(m1%+35) 256 Zmap1?1=(m1%+35) 256 dmap2?0=(m2%+35) 256 nmap2?1=(m2%+35) 256 x: :  : ?routine=1 init ?routine=2 init :  Y%=0 63*34 34 "Randomising line ";Y%/34  X%=0 31 m1%?(35+Y%+X%)=(255)  X% 'm1%?(35+Y%+31)=m1%?(35+Y%+31) 254  Y% : I=0  ?routine=2  init A%=(0)  "Calculating Generation" ?routine=3  init "t1%=map1?0 ,t2%=map1?1 6map1?0=map2?0 @map1?1=map2?1 Jmap2?0=t1% Tmap2?1=t2% ^"Generation ";I cI=I+1 h 0<>0 r: | : : :  assemble  I%=0 3 3 P%=code%: O%=code% [ OPT I% .map1 B 0 B 0 .map2 B 0 B 0 .routine B 0 .init LD HL,0 ADD HL,SP &LD (ostk),HL 0LD SP,(&1FFE) :XOR A DLD HL,errhan NLD BC,0 XRST &20 bB &75 lLD (obou),A vLD (oerr),HL .start \ ;\ Entry point - parameters in map1%, map2% and routine% \ LD A,(routine) LD HL,(map1) LD DE,(map2) &\ now identify the routine to call CP &01 JR NZ,S1  mapini JR exit .S1 CP &02  JR NZ,S2 * wmap 4JR exit >.S2 RCP &03 \JR NZ,S3 f life pJR exit z.S3 .exit LD HL,(oerr) LD A,(obou) LD BC,0 RST &20 B &75 LD SP,(ostk) RET .errhan RET Z CP &01 JR NZ,err1 RST &20 B &6F LD A,&01 CP A RET $.err1 CP &67 .JR NZ,err2 8LD HL,(oerr) BLD A,(obou) LLD BC,0 VRST &20 `B &75 jLD SP,(ostk) tLD HL,(oerr) ~LD A,&66 INC A SCF JP (HL) .err2 CP A RET .ostk W 0 .oerr W 0 .obou B 0 ] MP_WR = 01 MP_DEF = 02 MP_GRA = 03 MP_DEL = 04  window = "5" [ OPT I% (\ 2\ <\ !F\ mapini - initialise the map Z.mapini dLD HL,wincode AnRST &20 \ Call GN.SOP - null terminated output 'xB &09 \ to the screen B &3A LD HL,255 LD A,window LD BC,MP_GRA &RST &20 \ SYS MAP B &06 \ B &F4 RET \ \ \ 5\ wmap - display the entire map, pointed to by HL \ K\ it is assumed that the map lines are 34 bytes apart (allows 1 either \ side of the map line) ".wmap ,LD DE,0 6.loop2 @LD BC,MP_WR JLD A,window &TRST &20 \ SYS MAP ^B &06 \ hB &F4 rINC DE |LD A,64 CP E RET Z LD BC,34 ADD HL,BC JR loop2 .wincode B 1 B "6" B "#" B "1" B 32 B 32 B 32+51 B 32+8 B 1 &B "2" 0B "C" :B "1" DB 1 NB "S" XB 1 bB "C" lB 0 .life "PUSH HL \ Source map POP IX 'PUSH DE \ Destination map POP IY LD B,64 .l1 \ loop for each line &PUSH BC \ save the count PUSH IX \ save IX PUSH IY \ save IY  lifeline \ do a line (LD BC,34 \ length of a line "POP IY \ restore IY .ADD IY,BC \ point to the next line " POP IX \ restore IX .ADD IX,BC \ point to the next line * POP BC \ restore line count **DJNZ l1 \ and loop till done &4RET \ back to caller >\ H\ *R\ lifeline -- do a single line of life \\ f.lifeline *pLD D,&80 \ Mask for source IX *zLD E,&80 \ Mask for source IY &LD A,0 \ to zero prev-1 #LD (prev),A \ zero centre "LD (prev+1),A\ zero sides 8 lifetest \ returns current column in H (sides) \ and L (centre) LD B,255 *.l2 \ loop for each pixtel in line ;PUSH BC \ save the count - free the registers +LD BC,(prev) \ get previous column $LD A,B \ set up prev1 ADD A,C $LD (prev1),A \ and store it .LD B,H \ copy the current value ' LD C,L \ ... second half $ LD (prev),BC \ and store it $ SRL D 8. JR NC,sl1 \ OK if NC - Don't need to bump IX 8 INC IX \ Bump IX 4B LD D,&80 \ start at the next mask value L .sl1 $` \ Establish new output bit value 8j lifetest \ get column totals H(side) L(centre) t \ ~ \ now to count neighbours  \ , LD A,(prev1) \ get left hand column , ADD A,H \ and right hand sides - ADD A,L \ and right hand centre 0 ADD A,B \ get current column sides  \ \ now set up B as output bit  \ , LD B,0 \ assume no output bit & CP 2 \ remain as is ? + JR NZ,ou1 \ No - try for growth 8 LD B,C \ set output bit to previous value ) JR ou2 \ and set the value ' .ou1 CP 3 \ Growth? " JR NZ,ou2 \ no - death 4 LD B,1 \ non- zero equals output cell )( .ou2 \ Now to clear the output bit +2 LD A,E \ get the output mask "< CPL \ complement &F (IY+0) \ Mask out the bit #P DEC B \ was it set? Z JR NZ,ou3 \ no if NZ "d E \ Set the bit 6n .ou3 LD (IY+0),A \ and save back in place x \  \ bump E (and IY)  \ SRL E 8 JR NC,sl2 \ OK if NC - Don't need to bump IY  INC IY \ Bump IY 4 LD E,&80 \ start at the next mask value  .sl2  \  \ more pixtels?  \ % POP BC \ Get the count DJNZ l2 . RET \ Back for the next line  .prev B 0 " B 0 , .prev1 B 0 J \ +T \ lifetest - count a column based on IX ^ \ "+B$ #A,".J","LIST"+(B),"PROCF" #A *CLI .*:RAM.-/EE.CLI   F A=(0) A=B$ #A,A$,A$ #A A=B$  #A,".J",A$ #A=#A-1 #A,0 (#A 2*ERASE :RAM.-/EE.CLI < 8 F "*CLI .<"+B$ P