/* LIFE.C */  #define MODE 21 /* graphics mode 5 */#define XMAX 79#define YMAX 47#define SIZE 5100  char c,ex[1000],ey[1000],nx[1000],ny[1000],tx[SIZE],numb[10],change;int ncells,x,y,d,t,col,z,xmin,xmax,ymin,ymax,e,n,count,xt,yt,cell;  main() $(  printf("\f\d\d\tThe game of LIFE\n\n");  printf("Use joystick #1 to move one cell\n  at a time.\n");  printf("Use arrow keys (without control key)\n  followed by a number to move more\n");  printf("  than one cell\n");  printf("Press  Δ  to move diagonally\n");  printf("\d Ό  will turn cursor off (erase mode)\n");  printf(" Ύ  will turn cursor on.\n\nPress space bar to start, or to stop.\n");  position(2,22);  printf("Press space to begin.\n");  getkey();  graphics(MODE);  dpoke(0x80,tx);  dpoke(0x82,&x);  dpoke(0x84,&y);  dpoke(0x86,&cell);  while(1) $( /* place ncells */    clear(&c,&change-&c);    poke(764,255);    x=xmax=xmin=XMAX/2;    y=ymax=ymin=YMAX/2;    count=change=0;    z=3;    graphics(MODE-16); /* allows text window */    position(0,0);    while(!inkey()) $(      col=0;      while((d=stick(0)) == 15 && peek(764) == 255) $(        color(col++);        col=col&3;        plot(x,y);        if(change != z) $( /* print only if color is changed */          if(z == 0) printf(">>off<<\n",cls());          else printf(">>on<< \n",cls());          change=z;        $)      $)      color(z);      plot(x,y);      tx[(x<<6)+y]=z;      if(d<15) $(        if(z == 3) adjust(); /* check for x and y boundaries */        for(t=0;t <= 300;t++);        place(d);        continue;      $)      c=getkey();      if(c == '<') $(        z=0;        continue;      $)      if(c == '>') $(        z=3;        continue;      $)      if(c == ' ') break;      d=15;      if(c == '+') d=11;      if(c == '*') d=7;      if(c == '-') d=14;      if(c == '=') d=13;      if(c == 'D' || c == 'd') $(        printf("Press arrow key to indicate direction.");        c=getkey();        if(c == '+') d=111;        if(c == '*') d=17;        if(c == '-') d=114;        if(c == '=') d=113;      $)      printf("Press number, or '.' if greater than 9.\n",cls());      if((n=getkey()) != '.') n-='0';      else $(        printf("Number?");        gets(numb);        n=atoi(numb);      $)      color(z);      for(t=0;t<n;++t) $(        place(d);        if(z == 3) $(          plot(x,y);          tx[(x<<6)+y]=z;          adjust();        $)        tx[(x<<6)+y]=z;      $)    $)    life();  $)$)cls() $(  printf("\n\n\n\n\u\u\u");$)adjust() $(  if(x<xmin) xmin=x;  if(x>xmax) xmax=x;  if(y<ymin) ymin=y;  if(y>ymax) ymax=y;$)life() $(/* change ncells */  poke(764,255);  graphics(MODE+32);  while(!inkey()) $(    e=n=0;    yt=ymax+2;    xt=xmax+2;    for(y=ymin-1;y<yt;++y) $(      for(x=xmin-1;x<xt;++x) $(        ncells=kount(); /* count the surronding ncells */        if((cell) && (ncells<3 || ncells>4)) $(          ex[e]=x; /* erase cell due to overcrowding */          ey[e++]=y;        $)        else if(ncells == 3) $(          nx[n]=x; /* new cell or keep the old cell */          ny[n++]=y;        $)      $)    $)    if(n) ++count;    else $(      graphics(MODE-16); /* allows text window */      printf("%d generations\n",count);      printf("\nPress space to continue\n");      getkey();      return;    $)    color(0);    for(t=0;t<e;++t) $( /* erase */      plot(ex[t],ey[t]);      tx[((ex[t]<<6)+ey[t])]=0;    $)    xmax=xmin=*nx;    ymax=ymin=*ny;    color(3);    for(t=0;t<n;++t) $(      plot(nx[t],ny[t]);      tx[(nx[t]<<6)+ny[t]]=1;      if((c=nx[t])<xmin) xmin=c;      else if(c>xmax) xmax=c;      if((c=ny[t])>ymax) ymax=c;      else if(c<ymin) ymin=c;    $)    if(xmin<1) xmin=1;    if(ymin<1) ymin=1;    if(ymax>YMAX-2) ymax=YMAX-2;    if(xmax>XMAX-2) xmax=XMAX-2;  $)$)kount()  asm 0x600;place(data)int data;$(  if(data == 11) --x;  if(data == 7) ++x;  if(data == 13) ++y;  if(data == 14) --y;  if(data == 111) $(    --x;    ++y;  $)  if(data == 17) $(    ++x;    ++y;  $)  if(data == 113) $(    --y;    ++x;  $)  if(data == 114) $(    --y;    --x;  $)  if(x<1) x=1;  if(y<1) y=1;  if(y>YMAX) y=YMAX;  if(x>XMAX) x=XMAX;$)