home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 3
/
PDCD_3.iso
/
utilities
/
utilsf
/
gol
/
!Gol
/
c
/
life
< prev
Wrap
Text File
|
1993-10-22
|
2KB
|
98 lines
#include "$.Apps.C.DeskTopC.RISC_OSLib.h.akbd"
#include "kernel.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "life.h"
extern void GOL_err(const char *format,...);
#define bit_collect(bmap, bits) \
((bmap[((bits>>0)&7) | ((bits>>3)&56) | ((bits>>6)&448)]?1:0) \
|(bmap[((bits>>1)&7) | ((bits>>4)&56) | ((bits>>7)&448)]?2:0) \
|(bmap[((bits>>2)&7) | ((bits>>5)&56) | ((bits>>8)&448)]?4:0) \
|(bmap[((bits>>3)&7) | ((bits>>6)&56) | ((bits>>9)&448)]?8:0))
void life_table(rules, table)
char *rules;
char *table;
{Value count;
for (count=0x40000; count--; ) table[count]=bit_collect(rules, count);
}
void life_count(rules, counts, mask)
char *rules;
Value *counts;
Value mask;
{Value count;
Value bits;
for (count=512; count--; )
{bits=count&mask;
bits=((bits>>0)&1)+((bits>>1)&1)+((bits>>2)&1)+
((bits>>3)&1)+((bits>>4)&1)+((bits>>5)&1)+
((bits>>6)&1)+((bits>>7)&1)+((bits>>8)&1);
if (counts[bits]==lSET) rules[count]=1;
else if (counts[bits]==lLEAVE) rules[count]=(count>>4)&1;
else rules[count]=0;
}
}
void life_wrap(wh, base)
u_int wh;
u_int *base;
{u_int *temp;
u_int t1,t2;
u_int count;
u_int width=(wh&0xffff)>>2;
u_int height=(wh>>16);
temp=base;
for (count=height-2; count--;)
{temp=&(temp[width]);
t1=temp[0]; t2=temp[width-1];
t1|=(t2>>30)&1; t2|=(t1&2)<<30;
temp[0]=t1; temp[width-1]=t2;
}
temp=base;
memcpy(temp, &(temp[(height-2)*width]), width*4); temp=&(temp[width]);
memcpy(&(temp[(height-2)*width]), temp, width*4);
}
void life_unwrap(wh, base)
u_int wh;
u_int *base;
{u_int width=(wh&0xffff)>>2;
u_int height=(wh>>16);
memset((char *)&(base[0]), 0, width<<2);
base=&(base[width]);
for (wh=height-2; wh--; )
{*(base+0)&=0xfffffffe;
base+=width;
*(base-1)&=0x7fffffff;
}
memset((char *)&(base[0]), 0, width<<2);
}
void life_random(wh, base, seed)
u_int wh;
u_int *base;
u_int seed;
{u_int size=((wh&0xffff)>>2)*(wh>>16);
u_int v,c;
RANDOMIZE(v, c, seed);
while (size--) base[size]=RANDOM(v, c);
}