OpenCores
URL https://opencores.org/ocsvn/neorv32/neorv32/trunk

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [sw/] [example/] [game_of_life/] [main.c] - Diff between revs 20 and 22

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 20 Rev 22
Line 52... Line 52...
#define NUM_CELLS_X   160
#define NUM_CELLS_X   160
/** Universe y size */
/** Universe y size */
#define NUM_CELLS_Y   40
#define NUM_CELLS_Y   40
/** Delay between generations in ms */
/** Delay between generations in ms */
#define GEN_DELAY     500
#define GEN_DELAY     500
 
/** Symbol for dead cell */
 
#define CELL_DEAD  (' ')
 
/** Symbol for alive cell */
 
#define CELL_ALIVE ('#')
/**@}*/
/**@}*/
 
 
 
 
 
 
/**********************************************************************//**
/**********************************************************************//**
Line 170... Line 174...
        for (y=0; y<NUM_CELLS_Y; y++) {
        for (y=0; y<NUM_CELLS_Y; y++) {
 
 
          cell = get_cell(u, x, y); // state of current cell
          cell = get_cell(u, x, y); // state of current cell
          n = get_neighborhood(u, x, y); // number of living neighbor cells
          n = get_neighborhood(u, x, y); // number of living neighbor cells
 
 
          // classic rule set
          // -- classic rule set --
 
          // if center cell is dead -> cell comes to life when there are exactly 3 living cells around
 
          // if center cell is alive -> stay alive if there are 2 or three living cells around
 
          // else -> cell is/becomes dead
          if (((cell == 0) && (n == 3)) || ((cell != 0) && ((n == 2) || (n == 3)))) {
          if (((cell == 0) && (n == 3)) || ((cell != 0) && ((n == 2) || (n == 3)))) {
            set_cell((u + 1) & 1, x, y);
            set_cell((u + 1) & 1, x, y);
          }
          }
 
 
        } // y
        } // y
Line 212... Line 219...
  for (y=0; y<NUM_CELLS_Y; y++) {
  for (y=0; y<NUM_CELLS_Y; y++) {
    neorv32_uart_putc('|');
    neorv32_uart_putc('|');
 
 
    for (x=0; x<NUM_CELLS_X; x++) {
    for (x=0; x<NUM_CELLS_X; x++) {
      if (get_cell(u, x, y))
      if (get_cell(u, x, y))
        neorv32_uart_putc('#');
        neorv32_uart_putc((char)CELL_ALIVE);
      else
      else
        neorv32_uart_putc(' ');
        neorv32_uart_putc((char)CELL_DEAD);
    }
    }
 
 
    // end of line
    // end of line
    neorv32_uart_putc('|');
    neorv32_uart_putc('|');
    neorv32_uart_putc('\r');
    neorv32_uart_putc('\r');

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.