#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 4 (of 7)."
# Contents:  extern.h memalloc.c parse.c prototyp.h queues.c
# Wrapped by ray@life on Mon Nov  4 22:56:32 1991
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'extern.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'extern.h'\"
else
echo shar: Extracting \"'extern.h'\" \(7179 characters\)
sed "s/^X//" >'extern.h' <<'END_OF_FILE'
X/* extern.h  4-10-91  external declarations of global variables */
X/** Tierra Simulator V3.0: Copyright (c) 1991 Thomas S. Ray **/
X
X#include "license.h"
X
X/*
X#ifndef lint
Xstatic char     sccsid[] = "@(#)extern.h	1.30 10/6/91";
X#endif
X*/
X
X#ifndef LEXTERN_H
X#define LEXTERN_H
X
Xextern FILE  *oufr;
Xextern HpInst  soup;
Xextern I32s  alive;       /* run simulator alive * 1,000,000 instructions */
Xextern I32s  AverageSize; /* average size of cells in soup */
Xextern I32s  BottomReap; /* index of cell bottom reaper queue, last to die */
Xextern I32s  BrkupCou; /* count of output files break.n */
Xextern I32s  BrkupCum; /* cumulative count of bytes output to break.n */
Xextern I32s  BrkupSiz; /* size of output files break.n in K */
Xextern I32s  CellsSize;  /* number of allocated elements in cells array */
Xextern I32s  comsoc;
Xextern I32s  CountFlaw;  /* counter for flaw random number */
Xextern I32s  CountMovMut;
Xextern I32s  CountMutRate;
Xextern I32s  debug;    /* output info to screen for debugging */
Xextern I32s  debug_switch;
Xextern I32s  DiskOut;  /* 0 = no output to disk, 1 = output to disk */
Xextern struct event  Disturb;  /* time of disturbance */
Xextern float DistFreq; /* freq. of disturbance, in multiples of recovery t */
Xextern struct event  DistNext; /* time of next disturbance */
Xextern float DistProp; /* proportion of cells killed in each disturbance */
Xextern I32s  DivSameSiz;  /* 0 = off, 1 = daughter cell must be same size */
Xextern I32s  DivSameGen;  /* 0 = off, 1 = daught cell must be same genotype */
Xextern I32s  DropDead;  /* millions instruction since last divide till dead */
Xextern I32s  extr;       /* which cell to isolate */
Xextern I32s  ExtractCount;
Xextern I32s  FirstOutDisk;
Xextern I32s  fragment; /* 0 = memory not fragmented  1 = memory fragmented  */
Xextern I32s  FreeBlocks;  /* number of free blocks of memory */
Xextern I32s  GeneBnker; /* 0 = don't keep track genotyes, 1 = keep track */
Xextern double Generations; /* elapsed generations (AvgPop/TimeBirth-Death) */
Xextern I8s  **GenInList; /* pointers to soup_in genome names */
Xextern I8s  *GenInBuf;   /* buffer containing soup_in genome names */
Xextern float GenPerBkgMut; /* generations per background mutation */
Xextern float GenPerFlaw; /* generations per flaw */
Xextern float GenPerMovMut; /* generations per move mutation */
Xextern I32s  hangup;/* 0 = exit on error, 1 = hangup on error, for debugging*/
Xextern struct InstDef     id[32];
Xextern struct ArgInstDef  aid[32];
Xextern struct event  InstExe;  /* counter of instructions executed */
Xextern struct inst  is; /* struct for passing info between parse & execute */
Xextern I32s  isolate;  /* isolate the genome of the cell extr */
Xextern struct event  LastDiv;  /* instructions executed at last divide */
Xextern I32s  MaxFreeBlocks; /* number allocated elements in FreeMem array */
Xextern float MaxMalMult; /* multiple of cell size allowed for mal() */
Xextern I8s   mes[5][80];/* array of strings for message passing to frontend */
Xextern I32s  MinCellSize; /* minimum cell size */
Xextern I32s  MinTemplSize; /* minimum template size */
Xextern float  MovPropThrDiv; /* min proportion of daught cell filled by mov */
Xextern I32s  new_soup;  /* 0 = processed soup core, 1 = new soup core */
Xextern I32s  NumCells;  /* present number of cells in soup */
Xextern I32s  num_gen;    /* present number of genotypes saved to disk */
Xextern I32s  num_genq;   /* present number of genotypes in RAM bank */
Xextern I32s  num_genl;   /* present number of genotypes in *gl lists */
Xextern I32s  NumSiz;    /* present number of sizes saved to disk */
Xextern I32s  NumSizq;   /* present number of sizes in RAM bank */
Xextern I32s  NumSizl;   /* present number of sizes in *sl list */
Xextern I32u  ONE;         /* a constant */
Xextern I32s  PhotonSize; /* number of instructions in photon */
Xextern I32s  PhotonWidth; /* amount by which photons slide to determine fit */
Xextern I32s  RamBankSiz; /* number of genotypes stored in RAM */
Xextern I32s  RandIx1, RandIx2, RandIx3; /* for tsrand() */
Xextern I32s  RateFlaw; /* frequency of flaws */
Xextern I32s  RateMovMut;  /* 1 / frequency of mutations per mov event */
Xextern I32s  RateMut;  /* number of instructions per mutations */
Xextern I32s  reaped;    /* 0 = reaper has not killed, 1 = reaper has killed */
Xextern I32s  runflag;
Xextern I32s  SaveFreq; /* frequency of saving core_out, soup_out and list */
Xextern I32s  seed;  /* seed for random number generator */
Xextern I32s  SizDepSlice; /* 0 = slice constant, 1 = slice size dependent */
Xextern I32s  siz_sl;  /* allocated size of *sl array */
Xextern I8s   SLASH;  /* in DOS = \ = 92, in unix = / = 47 */
Xextern I32s  SliceSize;  /* number of instructions executed in each slice */
Xextern I32s  SliceStyle; /* select style of allocating slice size */
Xextern I8s   soup_fn[85];  /* place for soup_in filename */ 
Xextern I32s  SoupBot;  /* index FreeMem struct for bottom of soup memory */
Xextern I32s  SoupTop;  /* index of FreeMem struct for top of soup memory */
Xextern I32s  ThisSlice;  /* index of cell that is currently active */
Xextern I32s  TimeBirth;  /* count of births in each million instruction */
Xextern I32s  TimeDeath;  /* count of deaths in each million instruction */
Xextern double TimePop;   /* sum of ttime * NumCells for each million */
Xextern I32s  TopReap;    /* index of cell at top reaper queue, next to die */
Xextern I32s  TotFlaw;  /* total number of flaws in this run */
Xextern I32s  TotMovMut;  /* total number of move mutations in this run */
Xextern I32s  TotMut;  /* total number of background mutations in this run */
Xextern I32s  WatchExe; /* mark executed instructions in genome in genebank */
Xextern I32s  WatchMov; /* set mov bits in genome in genebank */
Xextern I32s  WatchTem; /* set template bits in genome in genebank */
Xextern I8s   GenebankPath[80]; /* path for genebank */
Xextern I8s   OutPath[80]; /* path for disk output */
Xextern I8s   PhotonWord[80];  /* alphabetic representation of photon */
Xextern Instruction  PhotonInst[80];/*instructional representation of photon */
Xextern Ind   FreeMemCurrent;  /* current amount of free memory in soup */
Xextern float SearchLimit;  /* limit on search, as multiple of average size */
Xextern Ind   Search_limit;/* limit how far address instructions will search */
Xextern Ind   SoupSize;  /* size of soup memory, measured in instructions */
Xextern Pcells  cells;  /* cells array */
Xextern Psl sl;        /* list of size classes for genebanker */
Xextern Pmf FreeMem;  /* free memory array */
Xextern double  PhotonPow;  /* power for photon match slice size */
Xextern double  SlicePow;  /* power for size dependent slice */
Xextern double  TrandArray[98]; /* for trand() */
Xextern float  SavThrMem; /* thresh memory prop. to save genotype */
Xextern float  SavThrPop; /* thresh population prop. to save genotype */
Xextern float  SlicFixFrac; /* fixed fraction of slice size */
Xextern float  SlicRanFrac; /* random fraction of slice size */
Xextern struct gl_index  gq_bot;  /* bottom of gene queue */
Xextern struct gl_index  gq_top;  /* top of gene queue */
Xextern struct LastOut  lo;  /* last data output to disk */
Xextern void (*slicer)();
X
X#endif
END_OF_FILE
if test 7179 -ne `wc -c <'extern.h'`; then
    echo shar: \"'extern.h'\" unpacked with wrong size!
fi
# end of 'extern.h'
fi
if test -f 'memalloc.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'memalloc.c'\"
else
echo shar: Extracting \"'memalloc.c'\" \(10141 characters\)
sed "s/^X//" >'memalloc.c' <<'END_OF_FILE'
X/* memalloc.c  28-10-91 memory allocation routines for the Tierra simulator */
X/** Tierra Simulator V3.0: Copyright (c) 1991 Thomas S. Ray **/
X
X#include "license.h"
X
X#ifndef lint
Xstatic char     memalloc_sccsid[] = "%W%     %G%";
X#endif
X
X#include <sys/types.h>
X#include "tierra.h"
X#include "extern.h"
X
X#ifdef SOCKETS
X
X#include "allayer.h"
X#include "tlayer.h"
X
X#endif
X
X/* check to see if cell has write privelage at address */
XI8s  IsPriv(ce, a)
XPcells  ce;
XInd  a;
X{
X#ifdef ERROR
X    if(a >= SoupSize || a < 0)
X    {   sprintf(mes[0],"IsPriv error: address %ld not in soup", a);
X        if (!hangup)
X            FEMessage(1);
X        else
X        {   sprintf(mes[1],"system being saved to disk");
X            FEMessage(2);
X        }
X        while(hangup) ;
X        WriteSoup(1);
X        exit(0);
X    }
X#endif
X    if(IsInsideCell(ce, a)) return 1;
X    return IsFree(a);
X}
X
XI8s IsBitPriv(ce,a,mode,track)
XPcells  ce;
XInd     a; /* address being checked */
XI8s     mode, track;
X    /* modes: 1 bit = execute, 2 bit = write, 4 bit = read */
X{   if(a < 0 || a >= SoupSize)
X        return 0;
X    if(IsInsideCell(ce,a))
X        return 1;
X    else
X        switch(mode)
X        {   case 1: return !soup[a][track].exec;
X            case 2: return !soup[a][track].write;
X            case 4: return !soup[a][track].read;
X            case 6: return (!soup[a][track].read) && (!soup[a][track].write);
X            default: return 0;
X        }
X}
X
X/* check to see if address is inside allocated memory cell ce */
XI8s  IsInsideCell(ce, a)
XPcells  ce;
XInd  a;
X{
X#ifdef ERROR
X    if(a >= SoupSize || a < 0)
X    {   sprintf(mes[0],"IsInsideCell error: address %ld not in soup", a);
X        if (!hangup)
X            FEMessage(1);
X        else
X        {   sprintf(mes[1],"system being saved to disk");
X            FEMessage(2);
X        }
X        while(hangup) ;
X        WriteSoup(1);
X        exit(0);
X    }
X#endif
X    if((ce->mm.p <= a && a < ce->mm.p + ce->mm.s) || (ce->md.s > 0 &&
X       (ce->md.p <= a && a < ce->md.p + ce->md.s))) return 1; return 0;
X}
X
X/* check to see if address is free, not allocated by any cell */
XI8s  IsFree(a)
XInd  a;
X{   I32s  j;
X    I32s  mp;  /* index to element of FreeMem array */
X    Pmf   f;
X
X#ifdef ERROR
X    if(a >= SoupSize || a < 0)
X    {   sprintf(mes[0],"IsFree error: address %ld not in soup", a);
X        if (!hangup)
X            FEMessage(1);
X        else
X        {   sprintf(mes[1],"system being saved to disk");
X            FEMessage(2);
X        }
X        while(hangup) ;
X        WriteSoup(1);
X        exit(0);
X    }
X#endif
X    f = FreeMem;     /* abbreviation for FreeMem */
X    mp = FreeMem->n; /* this is the first free block */
X    if(a < (f + mp)->p) return 0; j = 1;
X        /* find block whose end is equal or above a: */
X    while((f + mp)->p + (f + mp)->s < a)
X    {   mp = (f + mp)->n; j++;
X        if(j > FreeBlocks) return 0;
X    } /* is a in free block: */
X    if((f + mp)->p <= a && a < (f + mp)->p + (f + mp)->s) return 1;
X    return 0;
X}
X
Xvoid  WhichCell(a, ci, md) /* find cell with address a */
XInd  a;      /* note: a must be in a cell!, call IsFree() before */
XI32s  *ci;   /* WhichCell() to find out if a is in a cell or not */
XI8s   *md;
X{   I32s  i;
X
X    for(i = 2; i < CellsSize; i++)
X    {   if((cells + i)->ld && (cells + i)->mm.p <= a &&
X           ((cells + i)->mm.p + (cells + i)->mm.s - 1) >= a)
X        { *ci = i; *md = 'm'; break; }
X        if((cells + i)->ld && (cells + i)->md.p <= a &&
X           ((cells + i)->md.p + (cells + i)->md.s - 1) >= a)
X        { *ci = i; *md = 'd'; break; }
X    }
X}
X
XInd  MemAlloc(size)
XI32s  *size;
X{   I32s  j; /* counts the physical order of the free block we are indexing */
X    I32s  mb; /* memory block index */
X    I32s  pb; /* previous memory block index */
X    Ind   ti; /* temporary instruction location index, for return value */
X
X    if(!*size || !FreeBlocks) { *size = 0; return 0; }
X    mb = FreeMem->n; /* this is the first free block */
X    pb = 0; /* this is SoupBot */
X    j = 1; /* counts the physical order of the free block we are indexing */
X    while((FreeMem + mb)->s < *size)  /* find big enough free block */
X    {   pb = mb;
X        mb = (FreeMem + mb)->n;
X        j++;
X        if(j > FreeBlocks) /* if memory is very fragmented, reap some: */
X        {   if(FreeMemCurrent > 3 * *size) fragment = 1;
X            *size = 0; return 0;
X        }
X    }
X    fragment = 0;
X    FreeMemCurrent -= *size;
X    if((FreeMem + mb)->s == *size)  /* free block is exactly the right size */
X    {   (FreeMem + pb)->n = (FreeMem + mb)->n;
X        (FreeMem + mb)->o = 0;
X        FreeBlocks--;
X        if((FreeMem + mb)->p > SoupSize)
X        {   sprintf(mes[0],"Tierra memalloc() error 1");
X            FEMessage(1);
X        }
X
X#ifdef SOCKETS
X	TRepBirth( (FreeMem + mb)->p, *size );
X#endif
X
X        return (FreeMem + mb)->p;
X    }
X    if((FreeMem + mb)->s > *size)  /* free block bigger than needed */
X    {   ti = (FreeMem + mb)->p;
X        if(ti > SoupSize)
X        {   sprintf(mes[0],"Tierra memalloc() error 2");
X            FEMessage(1);
X        }
X        (FreeMem + mb)->p += *size;
X        if((FreeMem + mb)->p > SoupSize)
X        {   sprintf(mes[0],"Tierra memalloc() error 3");
X            FEMessage(1);
X        }
X        (FreeMem + mb)->s -= *size;
X        if((FreeMem + mb)->s > SoupSize)
X        {   sprintf(mes[0],"Tierra memalloc() error 4");
X            FEMessage(1);
X        }
X
X#ifdef SOCKETS
X	TRepBirth( ti, *size );
X#endif
X
X        return ti;
X    }
X    return 0;
X}
X
Xvoid MemDealloc(p, size)
XInd  p;
XI32s  size;
X{   I32s  i, j, a, b, ola, olb, bt;
X    Ind   bb, ab, at, pt;
X    Pmf   f, tf;
X
X#ifdef SOCKETS
X    TRepDeath( p, size );
X#endif
X
X#ifdef ERROR
X    if(p < 0L || !size || p >= SoupSize)
X    {   sprintf(mes[0],"Tierra memory deallocation error 1");
X        if (!hangup)
X            FEMessage(1);
X        else
X        {   sprintf(mes[1],"system being saved to disk");
X            FEMessage(2);
X        }
X        while(hangup) ;
X        WriteSoup(1);
X        exit(0);
X    }
X#endif
X    f = FreeMem;          /* abbreviation for FreeMem */
X    a = (f + SoupBot)->n; /* a will index free block above */
X    b = SoupBot;          /* b will index free block below */
X    j = 1L;
X    while(p >= (f + a)->p) /* find free block above block to be deallocated */
X    {   if(j > FreeBlocks) break;
X        b = a; a = (f + a)->n; j++;
X    }
X#ifdef ERROR
X    if(p > (f + a)->p)
X    {   sprintf(mes[0],"Tierra memory deallocation error 2");
X        if (!hangup)
X            FEMessage(1);
X        else
X        {   sprintf(mes[1],"system being saved to disk");
X            FEMessage(2);
X        }
X        while(hangup) ;
X        WriteSoup(1);
X        exit(0);
X    }
X#endif
X    bb = (f + b)->p;                   /* bb is address of bottom of b */
X        /* bt is address of top of b */
X    bt = (f + b)->p + (f + b)->s - 1L;
X    ab = (f + a)->p;                   /* ab is address of bottom of a */
X    at = (f + a)->p + (f + a)->s - 1L;  /* at is address of top of a */
X    pt = p + size - 1L;                 /* pt is address of top of p */
X    if(pt > SoupSize - 1L)
X    {   sprintf(mes[0],"Tierra deallocation inconsistency 0");
X        FEMessage(1);
X        pt = SoupSize - 1L;
X        size = pt - p + 1L;
X    }
X    if(bt > (p - 1L))
X    {   sprintf(mes[0],"Tierra deallocation inconsistency 1");
X        FEMessage(1);
X    }
X    if(pt > ab - 1L)
X    {   sprintf(mes[0],"Tierra deallocation inconsistency 2");
X        FEMessage(1);
X    }
X    if(bt >= p - 1L) olb = 1L; else olb = 0L;   /* overlap with block below */
X    if(pt >= ab - 1L) ola = 1L; else ola = 0L;  /* overlap with block above */
X        /* if block to be deallocated overlaps free blocks above and below: */
X    if(ola && olb)
X    {   if(b == SoupBot)
X        {   FreeMemCurrent += ab - p;
X            (f + a)->s = at - p + 1L;
X            (f + a)->p = p; return ;
X        }
X        if(a == SoupTop)
X        {   FreeMemCurrent += pt - bt;
X            (f + b)->s = pt - bb + 1L; return;
X        }
X        FreeMemCurrent += ab - bt - 1L;
X        (f + b)->s = at - bb + 1L;
X        (f + b)->n = (f + a)->n;
X            /* neutralize f + a: */
X        (f + a)->o = (I8s ) 0; (f + a)->p = (f + a)->s = 0L; (f + a)->n = a;
X        FreeBlocks--; return;
X    }       /* block to be deallocated overlaps only free block above: */
X    if(ola && a != SoupTop)
X    {   FreeMemCurrent += ab - p;
X        (f + a)->s = at - p + 1L;
X        (f + a)->p = p; return ;
X    }       /* block to be deallocated overlaps only free block below */
X    if(olb && b != SoupBot)
X    {   FreeMemCurrent += pt - bt;
X        (f + b)->s = pt - bb + 1L; return ;
X    }
X    j = 0L;  /* block to be deallocated does not overlap any free block */
X    while((FreeMem + j)->o)
X    {   if(++j == MaxFreeBlocks)
X        {   MaxFreeBlocks += 10L;
X            tf = (Pmf) threalloc((I8s Hp) FreeMem,
X                (I32u) MaxFreeBlocks * sizeof(struct mem_fr));
X            if(tf == NULL)
X            {   sprintf(mes[0],"Tierra memalloc realloc error, exiting");
X                if (!hangup)
X                    FEMessage(1);
X                else
X                {   sprintf(mes[1],"system being saved to disk");
X                    FEMessage(2);
X                }
X                while(hangup) ;
X                WriteSoup(1);
X                exit(0);
X            }
X            else f = FreeMem = tf;
X                if (!hangup)
X                    FEMessage(1);
X                else
X                {   sprintf(mes[1],"system being saved to disk");
X                    FEMessage(2);
X                }
X#ifdef __TURBOC__
X            sprintf(mes[0],"coreleft = %lu  MemDealloc (FreeMem)",coreleft());
X            FEMessage(1);
X#endif
X            sprintf(mes[0],"lmemalloc: realloc, MaxFreeBlocks = %ld",
X                MaxFreeBlocks);
X            FEMessage(1);
X            for(i = MaxFreeBlocks - 10L; i < MaxFreeBlocks; i++)
X            {   (f + i)->n = i;
X                (f + i)->o = (I8s ) 0; (f + i)->p = (f + i)->s = 0L;
X            }
X        }
X    }
X    (f + j)->o = (I8s ) 1;
X    (f + j)->n = a; (f + b)->n = j; FreeBlocks++;
X    (f + j)->p = p;
X    (f + j)->s = size;
X    FreeMemCurrent += size;
X}
END_OF_FILE
if test 10141 -ne `wc -c <'memalloc.c'`; then
    echo shar: \"'memalloc.c'\" unpacked with wrong size!
fi
# end of 'memalloc.c'
fi
if test -f 'parse.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'parse.c'\"
else
echo shar: Extracting \"'parse.c'\" \(10255 characters\)
sed "s/^X//" >'parse.c' <<'END_OF_FILE'
X/* parse.c  28-10-91  parser functions for the tierra simulator */
X/** Tierra Simulator V3.0: Copyright (c) 1991 Thomas S. Ray **/
X
X#include "license.h"
X
X#ifndef lint
Xstatic char     sccsid[] = "%W%     %G%";
X#endif
X
X#include "tierra.h"
X#include "extern.h"
X
X#if INST == 1
X
X/* in INST == 1, the array of registers maps into the registers ax, bx, cx, dx
X   as follows:  c.re[0] = ax, c.re[1] = bx, c.re[2] = cx, c.re[3] = dx */
X
Xvoid SetFlag(ce)
XPcells  ce;
X{   ce->c.fl = 1; }
X
Xvoid pnop(ci) /* do nothing */
XI32s  ci;
X{   is.iip = is.dib = 1; }
X
Xvoid por1(ci) /* flip low order bit of cx */
XI32s  ci;
X{   Pcells  ce = cells + ci;
X
X    is.dreg = &(ce->c.re[2]);
X    is.dval = ce->c.re[2];
X    is.iip = is.dib = 1;
X    is.dran = SoupSize;
X}
X
Xvoid pshl(ci) /* shift left all register of cx */
XI32s  ci;
X{   Pcells  ce = cells + ci;
X
X    is.dreg = &(ce->c.re[2]);
X    is.dval = ce->c.re[2];
X    is.iip = is.dib = 1;
X    is.dran = SoupSize;
X}
X
Xvoid pzero(ci) /* cx = 0 */
XI32s  ci;
X{   Pcells  ce = cells + ci;
X
X    is.dreg = &(ce->c.re[2]);
X    is.sval = 0;
X    is.iip = is.dib = 1;
X}
X
Xvoid pif_cz(ci) /* execute next instruction only if cx == 0 */
XI32s  ci;
X{   Pcells  ce = cells + ci;
X
X    is.sval = ce->c.re[2];
X    is.iip = is.dib = 1;
X}
X
Xvoid psub_ab(ci) /* cx = ax - bx */
XI32s  ci;
X{   Pcells  ce = cells + ci;
X
X    is.dreg = &(ce->c.re[2]);
X    is.sval = ce->c.re[0];
X    is.sval2 = -ce->c.re[1];
X    is.iip = is.dib = 1;
X    is.dran = SoupSize;
X}
X
Xvoid psub_ac(ci) /* ax = ax - cx */
XI32s  ci;
X{   Pcells  ce = cells + ci;
X
X    is.dreg = &(ce->c.re[0]);
X    is.sval = ce->c.re[0];
X    is.sval2 = -ce->c.re[2];
X    is.iip = is.dib = 1;
X    is.dmod = SoupSize;
X}
X
Xvoid pinc_a(ci) /* ax++ */
XI32s  ci;
X{   Pcells  ce = cells + ci;
X
X    is.dreg = &(ce->c.re[0]);
X    is.sval = ce->c.re[0];
X    is.sval2 = 1;
X    is.iip = is.dib = 1;
X    is.dmod = SoupSize;
X}
X
Xvoid pinc_b(ci) /* bx++ */
XI32s  ci;
X{   Pcells  ce = cells + ci;
X
X    is.dreg = &(ce->c.re[1]);
X    is.sval = ce->c.re[1];
X    is.sval2 = 1;
X    is.iip = is.dib = 1;
X    is.dmod = SoupSize;
X}
X
Xvoid pdec_c(ci) /* cx-- */
XI32s  ci;
X{   Pcells  ce = cells + ci;
X
X    is.dreg = &(ce->c.re[2]);
X    is.sval = ce->c.re[2];
X    is.sval2 = -1;
X    is.iip = is.dib = 1;
X    is.dran = SoupSize;
X}
X
Xvoid pinc_c(ci) /* cx++ */
XI32s  ci;
X{   Pcells  ce = cells + ci;
X
X    is.dreg = &(ce->c.re[2]);
X    is.sval = ce->c.re[2];
X    is.sval2 = 1;
X    is.iip = is.dib = 1;
X    is.dran = SoupSize;
X}
X
Xvoid ppush_ax(ci) /* push ax onto stack */
XI32s  ci;
X{   Pcells  ce = cells + ci;
X
X    is.sval = ce->c.re[0];
X    is.iip = is.dib = 1;
X}
X
Xvoid ppush_bx(ci) /* push bx onto stack */
XI32s  ci;
X{   Pcells  ce = cells + ci;
X
X    is.sval = ce->c.re[1];
X    is.iip = is.dib = 1;
X}
X
Xvoid ppush_cx(ci) /* push cx onto stack */
XI32s  ci;
X{   Pcells  ce = cells + ci;
X
X    is.sval = ce->c.re[2];
X    is.iip = is.dib = 1;
X}
X
Xvoid ppush_dx(ci) /* push dx onto stack */
XI32s  ci;
X{   Pcells  ce = cells + ci;
X
X    is.sval = ce->c.re[3];
X    is.iip = is.dib = 1;
X}
X
Xvoid ppop_ax(ci) /* pop ax off of stack */
XI32s  ci;
X{   Pcells  ce = cells + ci;
X
X    is.dreg = &(ce->c.re[0]);
X    is.iip = is.dib = 1;
X    is.dmod = SoupSize;
X}
X
Xvoid ppop_bx(ci) /* pop bx off of stack */
XI32s  ci;
X{   Pcells  ce = cells + ci;
X
X    is.dreg = &(ce->c.re[1]);
X    is.iip = is.dib = 1;
X    is.dmod = SoupSize;
X}
X
Xvoid ppop_cx(ci) /* pop cx off of stack */
XI32s  ci;
X{   Pcells  ce = cells + ci;
X
X    is.dreg = &(ce->c.re[2]);
X    is.iip = is.dib = 1;
X    is.dran = SoupSize;
X}
X
Xvoid ppop_dx(ci) /* pop dx off of stack */
XI32s  ci;
X{   Pcells  ce = cells + ci;
X
X    is.dreg = &(ce->c.re[3]);
X    is.iip = is.dib = 1;
X    is.dran = SoupSize;
X}
X
Xvoid ptjmp(ci) /* outward template jump */
XI32s  ci;
X{   Pcells  ce = cells + ci;
X    I32s    a, s = 0;
X
X    is.dreg  = &(ce->c.ip); /* destination register for address */
X    is.dreg2 = &(ce->c.re[3]); /* destination register for template size */
X    a = ad(ce->c.ip + 1); /* a = address of start of template */
X    while(1) /* find size of template, s = size */
X    {   if(soup[ad(a + s)][ce->c.tr].inst != 0 &&
X           soup[ad(a + s)][ce->c.tr].inst != 1)
X            break;
X        s++;
X    }
X    is.sval2 = s;  /* size of template */
X    is.dran2 = SoupSize;
X    is.dmod  = SoupSize;
X    is.dval  = ad(a + s + 1); /* start address for forward search */
X    is.dval2 = ad(a - s - 1); /* start address for backward search */
X    is.mode  = 0; /* outward jump */
X    is.mode2 = 0; /* complementary templates */
X    is.iip = 0; is.dib = 1;
X}
X
Xvoid ptjmpb(ci) /* backward template jump */
XI32s  ci;
X{   Pcells  ce = cells + ci;
X    I32s    a, s = 0;
X
X    is.dreg  = &(ce->c.ip); /* destination register for address */
X    is.dreg2 = &(ce->c.re[3]); /* destination register for template size */
X    a = ad(ce->c.ip + 1); /* a = address of start of template */
X    while(1) /* find size of template, s = size */
X    {   if(soup[ad(a + s)][ce->c.tr].inst != 0 &&
X           soup[ad(a + s)][ce->c.tr].inst != 1)
X            break;
X        s++;
X    }
X    is.sval2 = s;  /* size of template */
X    is.dran2 = SoupSize;
X    is.dmod  = SoupSize;
X    is.dval  = ad(a + s + 1); /* start address for forward search */
X    is.dval2 = ad(a - s - 1); /* start address for backward search */
X    is.mode  = 2; /* backward jump */
X    is.mode2 = 0; /* complementary templates */
X    is.iip = 0; is.dib = 1;
X}
X
Xvoid ptcall(ci) /* push ip to stack, outward template jump */
XI32s  ci;
X{   Pcells  ce = cells + ci;
X    I32s    a, s = 0;
X
X    is.dreg  = &(ce->c.ip); /* destination register for address */
X    is.dreg2 = &(ce->c.re[3]); /* destination register for template size */
X    a = ad(ce->c.ip + 1); /* a = address of start of template */
X    while(1) /* find size of template, s = size */
X    {   if(soup[ad(a + s)][ce->c.tr].inst != 0 &&
X           soup[ad(a + s)][ce->c.tr].inst != 1)
X            break;
X        s++;
X    }
X    is.sval  = ce->c.ip + s + 1;    /* address to be pushed onto stack */
X    is.sval2 = s;  /* size of template */
X    is.dran2 = SoupSize;
X    is.dmod  = SoupSize;
X    is.dval  = ad(a + s + 1); /* start address for forward search */
X    is.dval2 = ad(a - s - 1); /* start address for backward search */
X    is.mode  = 0; /* outward jump */
X    is.mode2 = 0; /* complementary templates */
X    is.iip = 0; is.dib = 1;
X}
X
Xvoid pret(ci) /* pop ip from stack */
XI32s  ci;
X{   Pcells  ce = cells + ci;
X
X    is.dreg = &(ce->c.ip);
X    is.iip = 0; is.dib = 1;
X    is.dmod = SoupSize;
X}
X
Xvoid pmov_dc(ci) /* dx = cx */
XI32s  ci;
X{   Pcells  ce = cells + ci;
X
X    is.dreg = &(ce->c.re[3]);
X    is.sval = ce->c.re[2];
X    is.iip = is.dib = 1;
X}
X
Xvoid pmov_ba(ci) /* bx = ax */
XI32s  ci;
X{   Pcells  ce = cells + ci;
X
X    is.dreg = &(ce->c.re[1]);
X    is.sval = ce->c.re[0];
X    is.iip = is.dib = 1;
X}
X
Xvoid pmov_iab(ci)
XI32s  ci;
X{   Pcells  ce = cells + ci;
X
X    is.dins = &soup[ce->c.re[0]][ce->c.tr];
X    is.sins = &soup[ce->c.re[1]][ce->c.tr];
X    is.dval = ce->c.re[0];
X    is.sval = ce->c.re[1];
X    is.dtra = is.stra = ce->c.tr;
X    is.iip = is.dib = 1;
X}
X
Xvoid padr(ci) /* search outward for template, return address in ax */
XI32s  ci; /* return template size in cx */
X{   Pcells  ce = cells + ci;
X    I32s    a, s = 0;
X
X    is.dreg  = &(ce->c.re[0]); /* destination register for address */
X    is.dreg2 = &(ce->c.re[2]); /* destination register for template size */
X    a = ad(ce->c.ip + 1); /* a = address of start of template */
X    while(1) /* find size of template, s = size */
X    {   if(soup[ad(a + s)][ce->c.tr].inst != 0 &&
X           soup[ad(a + s)][ce->c.tr].inst != 1)
X            break;
X        s++;
X    }
X    is.sval2 = s;  /* size of template */
X    is.dran2 = SoupSize;
X    is.dmod  = SoupSize;
X    is.dval  = ad(a + s + 1); /* start address for forward search */
X    is.dval2 = ad(a - s - 1); /* start address for backward search */
X    is.mode  = 0; /* outward jump */
X    is.mode2 = 0; /* complementary templates */
X    is.iip = 0; is.dib = 1;
X}
X
Xvoid padrb(ci) /* search backward for template, return address in ax */
XI32s  ci; /* return template size in cx */
X{   Pcells  ce = cells + ci;
X    I32s    a, s = 0;
X
X    is.dreg  = &(ce->c.re[0]); /* destination register for address */
X    is.dreg2 = &(ce->c.re[2]); /* destination register for template size */
X    a = ad(ce->c.ip + 1); /* a = address of start of template */
X    while(1) /* find size of template, s = size */
X    {   if(soup[ad(a + s)][ce->c.tr].inst != 0 &&
X           soup[ad(a + s)][ce->c.tr].inst != 1)
X            break;
X        s++;
X    }
X    is.sval2 = s;  /* size of template */
X    is.dran2 = SoupSize;
X    is.dmod  = SoupSize;
X    is.dval  = ad(a + s + 1); /* start address for forward search */
X    is.dval2 = ad(a - s - 1); /* start address for backward search */
X    is.mode  = 2; /* backward jump */
X    is.mode2 = 0; /* complementary templates */
X    is.iip = s + 1; is.dib = 1;
X}
X
Xvoid padrf(ci) /* search forward for template, return address in ax */
XI32s  ci; /* return template size in cx */
X{   Pcells  ce = cells + ci;
X    I32s    a, s = 0;
X
X    is.dreg  = &(ce->c.re[0]); /* destination register for address */
X    is.dreg2 = &(ce->c.re[2]); /* destination register for template size */
X    a = ad(ce->c.ip + 1); /* a = address of start of template */
X    while(1) /* find size of template, s = size */
X    {   if(soup[ad(a + s)][ce->c.tr].inst != 0 &&
X           soup[ad(a + s)][ce->c.tr].inst != 1)
X            break;
X        s++;
X    }
X    is.sval2 = s;  /* size of template */
X    is.dran2 = SoupSize;
X    is.dmod  = SoupSize;
X    is.dval  = ad(a + s + 1); /* start address for forward search */
X    is.dval2 = ad(a - s - 1); /* start address for backward search */
X    is.mode  = 1; /* forward jump */
X    is.mode2 = 0; /* complementary templates */
X    is.iip = s + 1; is.dib = 1;
X}
X
Xvoid pmal(ci)  /* allocate space for a new cell */
XI32s  ci;  /* allocate space for a new cell */
X{   Pcells  ce = cells + ci;
X
X    is.dreg = &(ce->c.re[0]);
X    is.sval = ce->c.re[2];
X    is.dmod = SoupSize;
X    is.dtra = ce->c.tr;
X    is.mode = 2; /* only write privelages protected */
X    is.iip = is.dib = 1;
X}
X
Xvoid pdivide(ci)  /* give life to new cell by puting in queue */
XI32s  ci;
X{   is.mode = 2;  /* full division */
X    is.iip = is.dib = 1;
X}
X
X#endif  /* end of INST 1 */
END_OF_FILE
if test 10255 -ne `wc -c <'parse.c'`; then
    echo shar: \"'parse.c'\" unpacked with wrong size!
fi
# end of 'parse.c'
fi
if test -f 'prototyp.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'prototyp.h'\"
else
echo shar: Extracting \"'prototyp.h'\" \(7656 characters\)
sed "s/^X//" >'prototyp.h' <<'END_OF_FILE'
X/* prototyp.h 28-10-91 */
X/* function prototypes for tierra simulator, included at end of tierra.h */
X/** Tierra Simulator V3.0: Copyright (c) 1991 Thomas S. Ray **/
X
X#include "license.h"
X
X/*
Xtierra_h_sccsid: @(#)prototyp.h	1.5	9/21/91
X*/
X
X#ifndef PROTOTYP_H
X#define PROTOTYP_H 
X
Xextern void DivideBookeep P_((I32s  ci, I32s  ni));
Xextern void OutDisk P_((I8s  bd, Pcells  nc));
Xextern void ReapBookeep P_((I32s  ci));
Xextern void MutBookeep P_((Ind  i));
Xextern void plan P_((void));
Xextern void extract P_((I32s  ci));
Xextern void GetGenFileList P_((void));
Xextern void InitGList P_((Pgl  g, I32s  si, I32s  gi, I32s  size));
Xextern void find_gl P_((struct genotype  *g, struct gl_index  *gli));
Xextern void CheckGenotype P_((I32s  ci, struct gl_index  *gli));
Xextern void IsNewSize P_((I32s  ci, struct gl_index  *gli));
Xextern I8s  IsInGenQueue P_((I32s  ci, struct gl_index  *gli));
Xextern I8s  IsInGenBank P_((I32s  ci, struct gl_index  *gli));
Xextern void NewGenotype P_((I32s  ci, struct gl_index  *gli));
Xextern I32u WhoIs P_((I32s  *ci, Ind  a));
Xextern void AddToGl P_((struct gl_index  *gli));
Xextern I8s  IsSameGen P_((I32s  size, HpInst  g1, HpInst  g2));
Xextern void AddTopGenQueue P_((struct gl_index  *gli));
Xextern void MovToTopGenQueue P_((struct gl_index  *gli));
Xextern void DelBotGenQueue P_((void));
Xextern void IncrLbl P_((I8s  *lbln, I8s  *lblo));
Xextern void MaxLbl P_((I8s  *lbl, I8s  *s));
Xextern I32s Lbl2Int P_((I8s  *s));
Xextern void Int2Lbl P_((I32s  i, I8s  *s));
Xextern void DelGenFile P_((Pgl  tgl));
Xextern FILE *open_ar P_((I8s  *file, I16s  size, I8s  format, I16s  mode));
Xextern head_t read_head P_((FILE  *fp));
Xextern void write_head P_((FILE  *fp, head_t  *head));
Xextern indx_t *read_indx P_((FILE  *fp, head_t  *head));
Xextern void write_indx P_((FILE  *fp, head_t  *head, indx_t  *indx));
Xextern I32s find_gen P_((indx_t  indx[], I8s  *gen, I32s  n));
Xextern Pgl get_gen P_((FILE  *fp, head_t  *head, indx_t  *indxn, I32s  n));
Xextern I32s add_gen P_((FILE  *fp, head_t  *head, indx_t  **indx, Pgl  gen));
Xextern I16s GetAscGen P_((Pgl  g, I8s  ifile[]));
Xextern void WritAscFile P_((Pgl  g, I8s  *file));
Xextern void WritGenFile P_((Pgl  g, I8s  file[]));
Xextern I16s GetGenFormat P_((Pgl  g,I8s  file[]));
Xextern Ascii2Ebcdic P_((I8s  *s));
Xextern Ebcdic2Ascii P_((I8s  *s));
Xextern void WritEcoF P_((I32u  bits, FILE  *ouf));
Xextern void SetBit P_((I32u  *seed, I32u  bit, I32u  value));
Xextern void nop P_((I32s  ci));
Xextern void or1 P_((I32s  ci));
Xextern void shl P_((I32s  ci));
Xextern void if_cz P_((I32s  ci));
Xextern void math P_((I32s  ci));
Xextern void push P_((I32s  ci));
Xextern void pop P_((I32s  ci));
Xextern void tcall P_((I32s  ci));
Xextern void call P_((I32s  ci));
Xextern void mov P_((I32s  ci));
Xextern void movdd P_((I32s  ci));
Xextern void movdi P_((I32s  ci));
Xextern void movid P_((I32s  ci));
Xextern void movii P_((I32s  ci));
Xextern void adr P_((I32s  ci));
Xextern void mal P_((I32s  ci));
Xextern void chmode P_((I32s  ci));
Xextern void malchm P_((I32s  ci));
Xextern void divide P_((I32s  ci));
Xextern void CheckCells P_((void));
Xextern I32s flaw P_((I32s  ci));
Xextern Ind template
X    P_((Ind  f, Ind  b, I32s  tz, I8s  dir, I8s  mode, I32s  ci));
Xextern Ind btemplate
X    P_((Ind  f, Ind  b, I32s  tz, I8s  dir, I8s  mode, I32s  ci));
Xextern I8s  IsPriv P_((Pcells  ce, Ind  a));
Xextern I8s IsBitPriv P_((Pcells  ce, Ind  a, I8s  mode, I8s  track));
Xextern I8s  IsInsideCell P_((Pcells  ce, Ind  a));
Xextern I8s  IsFree P_((Ind  a));
Xextern void  WhichCell P_((Ind  a, I32s  *ci, I8s  *md));
Xextern Ind  MemAlloc P_((I32s  *size));
Xextern void MemDealloc P_((Ind  p, I32s  size));
Xextern void SetFlag P_((Pcells  ce));
Xextern void thfree P_((I8s Hp  ptr));
Xextern I8s Hp threalloc P_((I8s Hp  ptr, I32u  siz));
Xextern I8s Hp thcalloc P_((I32u  num, I32u  siz));
Xextern I32u tfread P_((I8s Hp  ptr, I32s  size, I32s  n, FILE  *stream));
Xextern I32u tfwrite P_((I8s Hp  ptr, I32s  size, I32s  n, FILE  *stream));
Xextern I32u ffs P_((I32s  x));
Xextern void IncrSliceQueue P_((void));
Xextern void EntBotSlicer P_((I32s  ci));
Xextern void UpReaper P_((I32s  ci));
Xextern void DownReaper P_((I32s  ci));
Xextern void UpRprIf P_((I32s  ci));
Xextern void DownReperIf P_((I32s  ci));
Xextern void EntBotReaper P_((I32s  ci));
Xextern void RmvFrmReaper P_((I32s  ci));
Xextern void RmvFrmSlicer P_((I32s  ci));
Xextern void SlicerPhoton P_((void));
Xextern I32s PhotonFit P_((Ind  a, I8s  *PhotonInst, I32s  PhotonSize));
Xextern I32s PhotonSlide
X    P_((Ind  a, I8s  *PhotonInst, I32s  PhotonSize, I32s  PhotonWidth));
Xextern void PhotonTranslate P_((I8s  *PhotonInst, I8s  *PhotonWord));
Xextern void SlicerQueue P_((void));
Xextern void RanSlicerQueue P_((void));
Xextern void CoreWarSocket P_((I8s  bd, Ind  p, I32s  size));
Xextern void CoreWarBalloon P_((void));
Xextern void setup_tcp_socket P_((void));
Xextern void shutd P_((I32s  sig, I32s  code, I32s  *scp, I8s  *addr));
Xextern int main P_((int  argc, char  *argv[]));
Xextern void life P_((void));
Xextern void TimeSlice P_((I32s  ci, I32s  size_slice));
Xextern I16s FetchDecode P_((I32s  ci));
Xextern void IncrementIp P_((I32s  ci));
Xextern void SystemWork P_((I32s  ci));
Xextern void mutate P_((void));
Xextern void mut_site P_((HpInst  s, I8s  t));
Xextern void ReapCheck P_((void));
Xextern void reaper P_((I8s  ex));
Xextern I32s SubEvent
X    P_((struct event  *event1, struct event  *event2, struct event  *result));
Xextern I32s tlrand P_((void));
Xextern I16s tirand P_((void));
Xextern I16u tuirand P_((void));
Xextern I8s tcrand P_((void));
Xextern I8u tucrand P_((void));
Xextern void tsrand P_((I32s  seed));
Xextern double tdrand P_((void));
Xextern I8s GetAVar P_((I8s  data[85]));
Xextern void GetSoup P_((void));
Xextern void StupGenLists P_((void));
Xextern void GetNewSoup P_((void));
Xextern void ReadACreature P_((I8s  *crit, Pcells  ce, I32s  ci, HpInst  si));
Xextern void GetOldSoup P_((FILE  *inf));
Xextern void WriteSoup P_((I8s  close_disk));
Xextern I16s glcmp P_((const void  *gl1, const void  *gl2));
Xextern I16s slcmp P_((const void  *sl1, const void  *sl2));
Xextern void InitCell P_((I32s  ci));
Xextern void GenExExe P_((I32s  ci, Ind  adrt));
Xextern void GenExMov P_((I32s  ci, I32s  to, I32s  from));
Xextern void GenExTemp P_((Ind  adrt, I32s  ci, I32s  tsize));
Xextern void FEMessage P_((I8s  n));
Xextern void FEError P_((I8s  n));
Xextern void FEStartup P_((void));
Xextern void FEPlan P_((I32s  MaxPop, I32s  MaxMem,
X            struct genotype  *MaxGenPop, struct genotype  *MaxGenMem));
X
X#if INST == 1
X
Xextern void pnop P_((I32s  ci));
Xextern void por1 P_((I32s  ci));
Xextern void pshl P_((I32s  ci));
Xextern void pzero P_((I32s  ci));
Xextern void pif_cz P_((I32s  ci));
Xextern void psub_ab P_((I32s  ci));
Xextern void psub_ac P_((I32s  ci));
Xextern void pinc_a P_((I32s  ci));
Xextern void pinc_b P_((I32s  ci));
Xextern void pdec_c P_((I32s  ci));
Xextern void pinc_c P_((I32s  ci));
Xextern void ppush_ax P_((I32s  ci));
Xextern void ppush_bx P_((I32s  ci));
Xextern void ppush_cx P_((I32s  ci));
Xextern void ppush_dx P_((I32s  ci));
Xextern void ppop_ax P_((I32s  ci));
Xextern void ppop_bx P_((I32s  ci));
Xextern void ppop_cx P_((I32s  ci));
Xextern void ppop_dx P_((I32s  ci));
Xextern void ptjmp P_((I32s  ci));
Xextern void ptjmpb P_((I32s  ci));
Xextern void ptcall P_((I32s  ci));
Xextern void pret P_((I32s  ci));
Xextern void pmov_dc P_((I32s  ci));
Xextern void pmov_ba P_((I32s  ci));
Xextern void pmov_iab P_((I32s  ci));
Xextern void padr P_((I32s  ci));
Xextern void padrb P_((I32s  ci));
Xextern void padrf P_((I32s  ci));
Xextern void pmal P_((I32s  ci));
Xextern void pdivide P_((I32s  ci));
X
X#endif /* INST == 1 */
X
X#endif
END_OF_FILE
if test 7656 -ne `wc -c <'prototyp.h'`; then
    echo shar: \"'prototyp.h'\" unpacked with wrong size!
fi
# end of 'prototyp.h'
fi
if test -f 'queues.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'queues.c'\"
else
echo shar: Extracting \"'queues.c'\" \(7886 characters\)
sed "s/^X//" >'queues.c' <<'END_OF_FILE'
X/* queues.c  28-10-91  Artificial Life simulator */
X/** Tierra Simulator V3.0: Copyright (c) 1991 Thomas S. Ray **/
X
X#include "license.h"
X
X#ifndef lint
Xstatic char     sccsid[] = "%W%     %G%";
X#endif
X
X#include "tierra.h"
X#include "extern.h"
X
Xvoid IncrSliceQueue() /* increment slicer queue */
X{   ThisSlice = (cells + ThisSlice)->q.n_time;
X    while(!(cells + ThisSlice)->ld) /* get dead cells out of queue */
X        RmvFrmSlicer(ThisSlice);
X}
X
Xvoid EntBotSlicer(ci)
XI32s  ci;
X{   Pcells  ce; /* new cell being added to bottom of slicer queue */
X    Pcells  tc; /* ThisSlice cell */
X    Pcells  pc; /* previous slice cell */
X
X    ce = cells + ci; tc = cells + ThisSlice; pc = cells + tc->q.p_time;
X#ifdef ERROR
X    if(ce->q.n_time != ce->q.p_time && NumCells > 1)
X    {   sprintf(mes[0],
X            "Tierra EntBotSlicer() error: cell already in slicer queue");
X        if (!hangup)
X            FEMessage(1);
X        else
X        {   sprintf(mes[1],"system being saved to disk");
X            FEMessage(2);
X        }
X        while(hangup) ;
X        WriteSoup(1);
X        exit(0);
X    }
X#endif
X    pc->q.n_time = ci; /* previous slice points to ce */
X    ce->q.p_time = tc->q.p_time; /* ce points back at previous slice */
X    ce->q.n_time = ThisSlice; /* ce points to this slice */
X    tc->q.p_time = ci; /* this slice points back at ce */
X}
X
Xvoid UpReaper(ci) /* move cell up the reaper queue */
XI32s  ci;
X{   I32s  pi2, pi, ni; /* 2 previous, previous and next cells in reaper */
X    Pcells  pe2;
X    Pcells  pe;
X    Pcells  ne;
X    Pcells  ce;
X
X    if(ci == TopReap) return;
X    ce = cells + ci;    /* ce is cell to be moved up in reaper */
X#ifdef ERROR
X    if(ce->q.n_reap == ce->q.p_reap && NumCells > 1)
X    {   sprintf(mes[0],"Tierra UpReaper() error: cell not in reaper queue");
X        if (!hangup)
X            FEMessage(1);
X        else
X        {   sprintf(mes[1],"system being saved to disk");
X            FEMessage(2);
X        }
X        while(hangup) ;
X        WriteSoup(1);
X        exit(0);
X    }
X#endif
X    ni = ce->q.n_reap;  /* ni is index of next cell in reaper */
X    ne = cells + ni;    /* ne is next cell in reaper */
X    pi = ce->q.p_reap;  /* pi is index of previous cell in reaper */
X    pe = cells + pi;    /* pe is previous cell in reaper */
X    pi2 = pe->q.p_reap; /* pi2 is index of 2nd previous cell in reaper */
X    pe2 = cells + pi2;  /* pe2 is 2nd previous cell in reaper */
X    ne->q.p_reap = pi;  /* ni points back to pi */
X    ce->q.p_reap = pi2; /* ci points back to pi2 */
X    ce->q.n_reap = pi;  /* ci points ahead to pi */
X    pe->q.p_reap = ci;  /* pi points back to ci */
X    pe->q.n_reap = ni;  /* pi points ahead to ni */
X    pe2->q.n_reap = ci; /* pi2 points ahead to ci */
X    if(ci == BottomReap)
X        BottomReap = pi;
X    if(pi == TopReap)
X        TopReap = ci;
X}
X
Xvoid DownReaper(ci)
XI32s  ci;
X{   I32s  pi, ni, ni2; /* 2 previous, previous and next cells in reaper */
X    Pcells  pe;
X    Pcells  ce;
X    Pcells  ne;
X    Pcells  ne2;
X
X    if(ci == BottomReap) return;
X    ce = cells + ci;    /* ce is cell to be moved down in reaper */
X#ifdef ERROR
X    if(ce->q.n_reap == ce->q.p_reap && NumCells > 1)
X    {   sprintf(mes[0],"Tierra DownReaper() error: cell not in reaper queue");
X        if (!hangup)
X            FEMessage(1);
X        else
X        {   sprintf(mes[1],"system being saved to disk");
X            FEMessage(2);
X        }
X        while(hangup) ;
X        WriteSoup(1);
X        exit(0);
X    }
X#endif
X    ni = ce->q.n_reap;  /* ni is index of next cell in reaper */
X    ne = cells + ni;    /* ne is next cell in reaper */
X    ni2 = ne->q.n_reap; /* ni2 is index of 2nd next cell in reaper */
X    ne2 = cells + ni2;  /* ne2 is 2nd next cell in reaper */
X    pi = ce->q.p_reap;  /* pi is index of previous cell in reaper */
X    pe = cells + pi;    /* pe is previous cell in reaper */
X    pe->q.n_reap = ni;  /* pi points ahead to ni */
X    ce->q.n_reap = ni2; /* ci points ahead to ni2 */
X    ce->q.p_reap = ni;  /* ci points back to ni */
X    ne->q.n_reap = ci;  /* ni points ahead to ci */
X    ne->q.p_reap = pi;  /* ni points back to pi */
X    ne2->q.p_reap = ci; /* ni2 points back to ci */
X    if(ci == TopReap)
X        TopReap = ni;
X    if(ni == BottomReap)
X        BottomReap = ci;
X}
X
Xvoid UpRprIf(ci)
XI32s  ci;
X{   if((cells + ci)->d.flags >= (cells + (cells + ci)->q.p_reap)->d.flags)
X    UpReaper(ci);
X}
X
Xvoid DownReperIf(ci)
XI32s  ci;
X{   if((cells + ci)->d.flags <= (cells + (cells + ci)->q.n_reap)->d.flags)
X    DownReaper(ci);
X}
X
Xvoid EntBotReaper(ci)
XI32s  ci;
X{   Pcells  ce; /* cell to be added to the bottom of reaper queue */
X    Pcells  be; /* cell presently at bottom of reaper queue */
X
X    ce = cells + ci; be = cells + BottomReap;
X#ifdef ERROR
X    if(ce->q.n_reap != ce->q.p_reap && NumCells > 1)
X    {   sprintf(mes[0],
X            "Tierra EntBotReaper() error: cell already in reaper queue");
X        if (!hangup)
X            FEMessage(1);
X        else
X        {   sprintf(mes[1],"system being saved to disk");
X            FEMessage(2);
X        }
X        while(hangup) ;
X        WriteSoup(1);
X        exit(0);
X    }
X#endif
X    ce->q.p_reap = BottomReap; /* new cell points back to old BottomReap */
X    ce->q.n_reap = 1; /* new cell points ahead to dummy bottom */
X    be->q.n_reap = ci; /* old BottomReap cell now points ahead to ce */
X    (cells + 1)->q.p_reap = ci;
X    BottomReap = ci; /* BottomReap is now ci */
X}
X
Xvoid RmvFrmReaper(ci)
XI32s  ci;
X{   Pcells  ce; /* cell to be removed from reaper queue */
X    Pcells  nc; /* next cell in reaper queue */
X    Pcells  pc; /* previous cell in reaper queue */
X
X    ce = cells + ci; nc = cells + ce->q.n_reap; pc = cells + ce->q.p_reap;
X#ifdef ERROR
X    if(ce->q.n_reap == ce->q.p_reap && NumCells > 1)
X    {   sprintf(mes[0],
X            "Tierra RmvFrmReaper() error: cell not in reaper queue");
X        if (!hangup)
X            FEMessage(1);
X        else
X        {   sprintf(mes[1],"system being saved to disk");
X            FEMessage(2);
X        }
X        while(hangup) ;
X        WriteSoup(1);
X        exit(0);
X    }
X#endif
X    if(ci == TopReap) /* TopReap changed to next cell in queue */
X        TopReap = ce->q.n_reap;
X    if(ci == BottomReap) /* BottomReap changed to previous cell in queue */
X        BottomReap = ce->q.p_reap;
X        /* previous cell points ahead to next cell: */
X    pc->q.n_reap = ce->q.n_reap;
X        /* next cell points back to previous cell: */
X    nc->q.p_reap = ce->q.p_reap;
X    ce->q.p_reap = ce->q.n_reap = ci; /* initialize reap queue this cell */
X#ifdef ERROR
X    if(ce->q.n_time != ce->q.p_time && NumCells > 1)
X    {   sprintf(mes[0],
X            "Tierra RmvFrmReaper() error: cell still in slicer queue");
X        if (!hangup)
X            FEMessage(1);
X        else
X        {   sprintf(mes[1],"system being saved to disk");
X            FEMessage(2);
X        }
X        while(hangup) ;
X        WriteSoup(1);
X        exit(0);
X    }
X#endif
X}
X
Xvoid RmvFrmSlicer(ci)
XI32s  ci;
X{   Pcells  ce; /* cell to be removed from slicer queue */
X    Pcells  nc; /* next cell in slicer queue */
X    Pcells  pc; /* previous cell in slicer queue */
X
X    ce = cells + ci; nc = cells + ce->q.n_time; pc = cells + ce->q.p_time;
X#ifdef ERROR
X    if(ce->q.n_time == ce->q.p_time && NumCells > 1)
X    {   sprintf(mes[0],
X            "Tierra RmvFrmSlicer() error: cell not in slicer queue");
X        if (!hangup)
X            FEMessage(1);
X        else
X        {   sprintf(mes[1],"system being saved to disk");
X            FEMessage(2);
X        }
X        while(hangup) ;
X        WriteSoup(1);
X        exit(0);
X    }
X#endif
X        /* previous cell points ahead to next cell: */
X    pc->q.n_time = ce->q.n_time;
X        /* next cell points back to previous cell: */
X    nc->q.p_time = ce->q.p_time;
X    if(ci == ThisSlice)
X        ThisSlice = ce->q.n_time;
X    ce->q.n_time = ce->q.p_time = ci; /* initialize slice queue this cell */
X}
END_OF_FILE
if test 7886 -ne `wc -c <'queues.c'`; then
    echo shar: \"'queues.c'\" unpacked with wrong size!
fi
# end of 'queues.c'
fi
echo shar: End of archive 4 \(of 7\).
cp /dev/null ark4isdone
MISSING=""
for I in 1 2 3 4 5 6 7 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 7 archives.
    echo "Please see the README file(s) 
    for detailed instructions"
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0
