NEORV32 Software Framework Documentation
The NEORV32 RISC-V Processor
Loading...
Searching...
No Matches
main.c File Reference

Conway's game of life in a UART terminal. More...

#include <neorv32.h>

Macros

User configuration
#define BAUD_RATE   19200
 
#define NUM_CELLS_X   160
 
#define NUM_CELLS_Y   40
 
#define GEN_DELAY   500
 
#define CELL_DEAD   (' ')
 
#define CELL_ALIVE   ('#')
 

Functions

void clear_universe (int u)
 
void set_cell (int u, int x, int y)
 
int get_cell (int u, int x, int y)
 
int get_neighborhood (int u, int x, int y)
 
void print_universe (int u)
 
int pop_count (int u)
 
int main (void)
 

Variables

uint8_t universe [2][NUM_CELLS_X/8][NUM_CELLS_Y]
 

Detailed Description

Conway's game of life in a UART terminal.

Author
Stephan Nolting

Macro Definition Documentation

◆ BAUD_RATE

#define BAUD_RATE   19200

UART BAUD rate

◆ CELL_ALIVE

#define CELL_ALIVE   ('#')

Symbol for alive cell

◆ CELL_DEAD

#define CELL_DEAD   (' ')

Symbol for dead cell

◆ GEN_DELAY

#define GEN_DELAY   500

Delay between generations in ms

◆ NUM_CELLS_X

#define NUM_CELLS_X   160

Universe x size (has to be a multiple of 8)

◆ NUM_CELLS_Y

#define NUM_CELLS_Y   40

Universe y size

Function Documentation

◆ clear_universe()

void clear_universe ( int u)

Kill all cells in universe.

Parameters
[in]uUniverse select (0 or 1).

◆ get_cell()

int get_cell ( int u,
int x,
int y )

Get state of cell.

Parameters
[in]uUniverse select (0 or 1).
[in]xX coordinate of cell.
[in]yY coordinate of cell.
Returns
Cell is dead when 0, cell is alive when 1.

◆ get_neighborhood()

int get_neighborhood ( int u,
int x,
int y )

Get number of living cells in neighborhood.

Parameters
[in]uUniverse select (0 or 1).
[in]xX coordinate of the neighborhood's center cell.
[in]yY coordinate of the neighborhood's center cell.
Returns
Number of living cells in neighborhood (0..9).

◆ main()

int main ( void )

Conway's Game of Life.

Note
This program requires the UART to be synthesized (the TRNG is optional).
Returns
0 if execution was successful

◆ pop_count()

int pop_count ( int u)

Count living cells in universe.

Parameters
[in]uUniverse select (0 or 1).
Returns
Number of living cells.

◆ print_universe()

void print_universe ( int u)

Print universe via UARt.

Parameters
[in]uUniverse select (0 or 1).

◆ set_cell()

void set_cell ( int u,
int x,
int y )

Make cell alive.

Parameters
[in]uUniverse select (0 or 1).
[in]xX coordinate of cell.
[in]yY coordinate of cell.

Variable Documentation

◆ universe

uint8_t universe[2][NUM_CELLS_X/8][NUM_CELLS_Y]

The universe