home *** CD-ROM | disk | FTP | other *** search
- /* tierra.h 19-8-91 */
- /* type, structure and function definitions for the Tierra simulator */
- /** Tierra Simulator V3.0: Copyright (c) 1991 Thomas S. Ray **/
-
- #include "license.h"
-
- /*
- tierra_h_sccsid: @(#)tierra.h 2.9 10/6/91
- */
-
- #ifndef LTIERRA_H
- #define LTIERRA_H
-
- #include <stdio.h>
- #include <math.h>
- #include <string.h>
- #include <time.h>
- #include "configur.h"
- #include "portable.h"
-
- #define IsBit(seed, bit) (((seed) & (1 << (bit))) ? 1 : 0)
- #define ad(A) ((A) >=0 ? ((A)%SoupSize):((SoupSize-(-(A)%SoupSize))%SoupSize))
- #define mo(A,B) ((A) >=0 ? ((A)%(B)) : (((B)-(-(A)%(B)))%(B)))
-
- #if INSTBITNUM == 5
-
- #ifdef __TURBOC__
- struct Inst {
- unsigned int inst:5;
- unsigned int exec:1;
- unsigned int write:1;
- unsigned int read:1;
- } ;
- #else
- struct Inst {
- unsigned char inst:5;
- unsigned char exec:1;
- unsigned char write:1;
- unsigned char read:1;
- } ;
- #endif
-
- #endif
-
- typedef struct Inst Instruction[PLOIDY];
-
- typedef Instruction Hp HpInst;
- typedef Instruction Fp FpInst;
- typedef Instruction Np NpInst;
- typedef struct Inst Fp FpIns;
-
- typedef I8s GenBits[PLOIDY];
-
- typedef GenBits Hp HpGenB;
-
- typedef struct cell Hp Pcells;
- typedef struct s_list Hp Psl;
- typedef struct g_list Hp Pgl;
- typedef struct mem_fr Hp Pmf;
- typedef I32s Ind; /* index for addressing instructions in soup */
- typedef I32s Num; /* type for use in numerical CPU registers */
- typedef I32s Reg; /* type for use in CPU registers */
- typedef Reg *Preg;
-
- struct InstDef { /* structure for instruction set definitions */
- I8s op; /* op code */
- I8s mn[9]; /* assembler mnemonic */
- void (*execute) P_((I32s)); /* pointer to execute function */
- void (*parse) P_((I32s)); /* pointer to parse function */
- } ;
-
- struct ArgInstDef { /* structure for instruction set definitions */
- I8s op; /* op code */
- I8s mn[9]; /* assembler mnemonic */
- } ;
-
- struct inst { /* struct for passing arguments from parse to execute */
- Preg dreg; /* pointer to destination register */
- I32s dval; /* original destination value */
- FpIns dins; /* pointer to destination instruction */
- I8s dtra; /* destination track */
- I32s dmod; /* destination modulused positive this size */
- I32s dran; /* destination kept in signed range of this value */
-
- Preg dreg2; /* pointer to 2nd destination register */
- I32s dval2; /* original destination value */
- FpIns dins2; /* pointer to 2nd destination instruction */
- I8s dtra2; /* 2nd destination track */
- I32s dmod2; /* 2nd dest modulused positive this size */
- I32s dran2; /* 2nd dest kept in signed range of this value */
-
- Preg sreg; /* pointer to source register */
- FpIns sins; /* pointer to source instruction */
- I32s sval; /* source value */
- I8s stra; /* source track */
-
- Preg sreg2; /* pointer to 2nd source register */
- FpIns sins2; /* pointer to 2nd source instruction */
- I32s sval2; /* 2nd source value */
- I8s stra2; /* 2nd source track */
-
- I8s mode; /* mode of instruction */
- I8s mode2; /* 2nd mode of instruction */
- Ind oip; /* address of instruction being executed: ce->c.ip */
- I8s iip; /* amount to increment instruction pointer */
- I8s dib; /* amount to decrement instruction bank */
- I16s ts; /* size of time slice, used to control central loop */
- } ;
-
- struct event { /* structure for time measured in executed instructions */
- I32s m; /* count of millions of instructions */
- I32s i; /* count of instructions */
- } ;
-
- struct genotype {
- I32s size; /* size class (~species) */
- I8s label[4]; /* genotype label */
- } ;
-
- struct gl_index {
- I32s si; /* size index */
- I32s gi; /* genotype index */
- } ;
-
- struct metabolism { /* structure for metabolic data */
- I32s inst; /* count of instructions executed */
- I32s flags; /* count of flags (error conditions) set */
- I32s mov_daught; /* count of number of instructions moved to daughter */
- I8s BreedTrue; /* 0=not, 1 = this daughter genetically same as parent */
- } ;
-
- struct dem { /* structure for demographic data */
- struct genotype gen; /* size and genotype name of cell */
- I32s fecundity; /* count of number of daughter cells produced */
- I32s flags; /* count of flags (error conditions) set */
- I32s mov_daught; /* count of number of instructions moved to daughter */
- I32s inst; /* count of instructions executed */
- I32s mut; /* 0 = no somatic mutations, >= 1 = somatic mutations */
- I32s flaw; /* 0 = no flaws, >= 1 = flaws */
- struct metabolism d1; /* metabolic data for first daughter */
- struct genotype parent; /* size and genotype name of parent */
- struct gl_index gli; /* index to this genotype in the sl-gl arrays */
- I16s ib; /* instruction bank */
- I32s ni; /* index to cells array of daughter cell */
- I8s is; /* 1 = this cpu is active, in the slicer; 0 = not active */
- I8s dm; /* 0 = mother, 1 = daughter */
- I8s ploidy; /* how many tracks */
- } ;
-
- struct que { /* pointers to previous and next cells in queues */
- I32s n_time; /* index of next cell in slicer queue */
- I32s p_time; /* index of previous cell in slicer queue */
- I32s n_reap; /* index of next cell in reaper queue */
- I32s p_reap; /* index of previous cell in reaper queue */
- } ;
-
- struct mem { /* structure for allocated memory block of cell */
- Ind p; /* location of start of cell memory */
- I32s s; /* size of cell memory */
- } ;
-
- struct cpu { /* structure for registers of virtual cpu */
- Reg re[NUM_REGS]; /* array of registers */
- Reg sp; /* stack pointer */
- Reg st[STACK_SIZE]; /* stack */
- Reg ip; /* instruction pointer */
- I8s fl; /* flag */
- I8s tr; /* which track currently being executed */
- } ;
-
- struct cell { /* structure for cell of organisms */
- struct dem d; /* fecundity and times and dates of birth and death */
- struct que q; /* pointers to previous and next cells in queues */
- struct mem mm; /* main cell memory */
- struct mem md; /* daughter cell memory */
- struct cpu c; /* virtual cpu */
- I8s ld; /* 0 = dead, 1 = alive */
- } ; /* sizeof(struct cell) = XX */
-
- struct mem_fr { /* structure for free memory list */
- Ind p; /* location in soup of free block */
- Ind s; /* size of free block */
- I32s n; /* index of next free block in FreeMem array */
- I8s o; /* 1 = element in use, 0 = element open for use */
- } ; /* sizeof(struct mem_fr) = X */
-
- struct s_list { /* structure for size list */
- I32s size; /* genotype size */
- I32s num; /* number of genotypes of this size */
- I32s num_s; /* number of genotypes of this size saved to disk */
- I32s num_q; /* number of genotypes of this size in gen_queue */
- I32s num_e; /* number of genotypes saved to disk or extant */
- I32s a_num; /* allocated size of *g array */
- Pgl g; /* array of g_list structures */
- } ;
-
- struct g_list { /* structure for genotype list */
- I32s pop; /* current number of adults of this genotype in soup */
- struct genotype gen; /* genotype of creature */
- struct genotype parent; /* genotype of parent genotype (ancestor) */
- I32u bits; /* see below */
- struct metabolism d1; /* metabolic data for first daughter */
- struct metabolism d2; /* metabolic data for second daughter */
- struct event originI; /* time of origin, in instruction time */
- I32s originC; /* time of first origin of genotype, in clock time */
- float MaxPropPop; /* max. propor. of NumCells reached by this gen. */
- float MaxPropInst; /* max. propor. of SoupSize reached by this gen. */
- I8s Fp comments; /* pointer to string containing comments */
- I8s ploidy; /* how many tracks */
- I8s track; /* which track are we on now ... */
- HpInst genome; /* pointer to genome itself */
- HpGenB gbits; /* pointer to genome itself */
- struct gl_index b; /* next (below) in queue */
- struct gl_index a; /* previous (above) in queue */
- } ;
-
- /* definitions of bits:
- bit 0 permanent genotype name
- bit 1 saved to disk
- bit 2 EXs = executes own instructions (self)
- bit 3 EXd = executes daughter's instructions
- bit 4 EXo = executes other cell's instructions
- bit 5 EXf = executes instructions in free memory
- bit 6 EXh = own instructions are executed by other creature (host)
- bit 7 TCs = matches template complement of self
- bit 8 TCd = matches template complement of daughter
- bit 9 TCo = matches template complement of other
- bit 10 TCf = matches template complement of free memory
- bit 11 TCh = own template complement is matched by other creature (host)
- bit 12 TPs = uses template pattern of self
- bit 13 TPd = uses template pattern of daughter
- bit 14 TPo = uses template pattern of other
- bit 15 TPf = uses template pattern of free memory
- bit 16 TPh = own template pattern is used by other creature (host)
- bit 17 MFs = moves instruction from self
- bit 18 MFd = moves instruction from daughter
- bit 19 MFo = moves instruction from other cell
- bit 20 MFf = moves instruction from free memory
- bit 21 MFh = own instructions are moved by other creature (host)
- bit 22 MTs = moves instruction to self
- bit 23 MTd = moves instruction to daughter
- bit 24 MTo = moves instruction to other cell
- bit 25 MTf = moves instruction to free memory
- bit 26 MTh = is written on by another creature (host)
- bit 27 MBs = executing other creatures code, moves inst from self
- bit 28 MBd = executing other creatures code, moves inst from daughter
- bit 29 MBo = executing other creatures code, moves inst from other cell
- bit 30 MBf = executing other creatures code, moves inst from free memory
- bit 31 MBh = other creature uses another cpu to move your instructions
- */
-
- struct LastOut { /* record of last data output to disk */
- I32s time; /* elapsed time */
- I32s ctime; /* millions of instructions */
- I8s bd; /* b = birth, d = death */
- I32s size; /* size of creature */
- I8s label[4]; /* genotype name of creature, e.g., aaa */
- } ;
-
- struct SizList { /* use for output of size list */
- I32s size; /* genome size */
- I32s pos; /* position is sl */
- I32s ext; /* number of saved or extant genotypes of this size */
- I8s dir; /* does a directory for this size exist */
- } ;
-
- typedef struct {
- I8s magic[4];
- I32s g_off;
- I16s size, n, n_alloc;
- } head_t;
-
- typedef struct {
- I8s gen[3];
- I8s pgen[3];
- I16s psize;
- I32u bits;
- I32s originC;
- I16s mpp, mpi;
- I32s ptr; /* reserved for future versions */
- struct event originI;
- struct metabolism d1, d2;
- I8s pt; /* ploidy and track */
- } indx_t;
-
- #ifdef SOCKETS
- /*** new structure for global data *************************************/
-
- #ifndef MAXHOSTNAMELEN
- #include <sys/param.h>
- #endif
-
- #ifndef u_long
- #include <sys/types.h>
- #endif
-
- extern char * ALRealloc P_((char *ptr; u_int size));
-
- /***********************************************************************/
- #endif
-
- #include "prototyp.h"
-
- #endif
-