#include <xparameters.h>
#define VRAM_BASEADDR (int *)XPAR_VGA_0_BASEADDR
#define XSIZ 60
#define YSIZ 40
char what( int , int );
void v_puts( int , int , char * );
void v_putc( int , int , char );
static char data1[XSIZ][YSIZ] = {
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
{ 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0,0,0 },
{ 0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0 },
{ 0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
{ 0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0 },
{ 0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0 },
{ 0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0 },
{ 0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
{ 0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
{ 0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
};
static char data2[XSIZ][YSIZ];
int
main()
{
int i,j,num;
static char *banner = "Microblaze Softcore Processor Video System";
v_puts( 0, 0, banner );
for( j=0; j<16; j++ ){
for( i=0; i<16 ; i++ ) {
v_putc( i+64, j+9, 16*j+i );
}
}
for( i=0; i<XSIZ; i++ ){
for( j=0 ; j<YSIZ ; j++ ) {
data2[i][j] = 0;
}
}
while(1) {
for( i=0; i<XSIZ; i++ ){
for( j=0 ; j<YSIZ ; j++ ) {
num=0;
if( what(i-1,j-1) ) num++;
if( what(i-1,j ) ) num++;
if( what(i-1,j+1) ) num++;
if( what(i ,j-1) ) num++;
if( what(i ,j+1) ) num++;
if( what(i+1,j-1) ) num++;
if( what(i+1,j ) ) num++;
if( what(i+1,j+1) ) num++;
if( what(i,j) ) {
if( num == 2 || num == 3 )
data2[i][j]=1;
else
data2[i][j]=0;
} else if( num == 3 ) data2[i][j]=1;
}
}
for( i=0; i<XSIZ; i++ ){
for( j=0 ; j<YSIZ ; j++ ) {
data1[i][j] = data2[i][j];
v_putc( XSIZ-i-1, j+5, data2[i][j] ? '@' : ' ' );
data2[i][j] = 0;
}
}
for( i=0; i<256; i++ ){
for( j=0 ; j<2000 ; j++ ) {
v_putc( 79, 0, i );
}
}
}
}
char what( int i, int j)
{
if( i < 0 ) return 0;
if( j < 0 ) return 0;
if( i == XSIZ ) return 0;
if( j == YSIZ ) return 0;
return data1[i][j];
}
void v_puts( int x, int y, char *str )
{
while( *str != '\0' ) {
v_putc( x++, y, *str++ );
}
}
void v_putc( int x, int y, char ch )
{
int *addr;
addr = VRAM_BASEADDR + (y*80 + x);
*addr = ch;
}
|
data1 [XSIZ] [YSIZ] : The initial-data of the living being
It makes 1, the place not to be 0 in the place where there is a living being.
the penta decathlon (pentadecathlon) as the initial-data and
Arranging in "GURAIDAGAN" (gliderguns)
The title display display
It displays all character sets on the screen.
The Initialization of the data2 array
Every element of the data1 array, it examines the catastasis of the
living being of 8 masus in the neighborhood and it counts the number of
the living being. If there are 2-three living beings around when there is a living being in the center, the center living being survives. If there are three living beings around when there is not a living being
in the center, the living being is born in the center.
It creates the catastasis of the next-generation in the data2 array.
It copies the inside of the data2 array on to the data1 array and it
arranges the catastasis of the living being on the screen.
The laying over loop of 2000 times of 256~ It loops while displaying a
character in the upper right.
what (i, j) : The function which returns the catastasis of the living being
of data1 [i] [j] in the data1 array
v_puts (The haploid-number, y, string) : (The haploid-number, y) It
displays string character string in the screen from the coordinate
v_putc (The haploid-number, y, ch) : (The haploid-number, y) It displays ch
character string in the coordinate
|