The program coding (Conway's Game of Life)


In this exercise, it takes up Conway's game of life as the example of the program.
Conway's Game of Life is following living being simulation.
Because the video module which was created this time is a character-type display, it is OK if writing the character code of the character to want to display in the video memory at the part to want to display.
It set the first address of the video memory of the video module to "0x45000000" in the hardware design. When making a coordinate at the part to want to write when making this "VRAM_BASEADDR" X, Y
(int *) VRAM_BASEADDR + The Y * 80
+ The X
It writes in the address which is.


The LIFE gaming program by the programming language communications security,COMSEC is as follows.


The sauce The comment
#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,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2[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

It creates this program as the software project.

The program of Microblade uses a software development tool, SDK. "Export Design" in the navigatorIt presses "Export &Launch SDK" if click. is new and "Export to SDK/ Launch SDK" window in computer graphics are displayed in the icon.

" Because Workspace Launcher" starts up, it sets "Workspace" directory appropriately and it presses OK. (It creates program directory in the directory of life which started up xps first and it will should make this place Workspace.)



Following SDK window in computer graphics starts up.



Next, it creates a software project. " In the Project Explorer" tab, it pushes the right button of the Mus and it chooses "New"->"Project...".
" Because the New Project" window in computer graphics starts up, it chooses "Application Project" in "Xilinx" and it presses Next.




" In Application Project"
Project name : life
It changes boiling and it presses "Next".



By next "Templates"
Available Templates : Empty Application
It changes boiling and it presses "Finish".



Project "life_bsp" for the project "life" to create a life gaming and the library of program which the experiment board needs is created by this.

Next, "life" should be added in the "Project Explorer" tab. It clicks the right of the Mus in the office of productivity, technology and innovation of "life" like the following figure and it chooses "New"->"Source File" on the left of the Mus.



" It inputs "life.c" in the office of productivity, technology and innovation of "Source file:" of the New Source File" window in computer graphics and it presses "Finish".



" The "life.c" tabulation appears newly next to the Project Explorer" tab and a model comment is displayed.
It inputs the program which is specified above to this place and it saves it.



By saving a file, it compiles a program automatically and it is changed into the file of the form that the processor can be understood.
After the compilation exit, it is displayed as follows at the "Console" tab.
make all
Building file :  / src/life.c Invoking : MicroBlaze gcc compiler
mb-gcc, Wall, O0, g3, c, fmessage-length=0-I.  /  /
life_bsp/microblaze_0/include-mlittle-endian
- mxl-barrel-shift, mxl-pattern-compare, mcpu=v8.50.c-mno-xl-soft-mul
- Wl, --no-relax, ffunction-sections, fdata-sections, the
maximum-mixing-depth-the microprocessor
- MF"src/life.d", MT"src/life.d"-o
"src/life.o" ".  / src/life.c" Finished building :
/ src/life.c

Building target : life.elf
Invoking : MicroBlaze gcc linker
mb-gcc, Wl, T-Wl  / src/lscript.ld-L.  /  / life_bsp/microblaze_0/lib,
mlittle-endian, mxl-barrel-shift, mxl-pattern-compare, mcpu=v8.50.c,
mno-xl-soft-mul-Wl, --no-relax-Wl, --gc-sections-o
"life.elf" / src/life.o    -Wl, --start-group, lxil,
lgcc-lc, --end-group Finished building target : life.elf

Invoking : MicroBlaze Print Size
mb-size life.elf    |tee "life.elf.size"
   text    data       bss           dec     hex filename
   3406         2672         4480           10558      293e     life.elf
Finished building : life.elf.size

Invoking : Xilinx ELF Check
elfcheck life.elf-hw  /  / life_hw_platform/system.xml-pe microblaze_0
   |tee "life.elf.elfcheck" elfcheck Xilinx EDK 14.7 Build
EDK_P.20131013 Copyright (c) 1995-2012 Xilinx, Inc.  All rights
reserved.

Command Line : elfcheck-hw  /  / life_hw_platform/system.xml-pe
microblaze_0 life.elf

ELF file : life.elf
elfcheck passed.
Finished building : life.elf.elfcheck

"life.elf" which is a file for the execution is generated by this.

Then, actually, it attempts to do an operations check.
| Back |Top |Next |