diff --git a/Makefile b/Makefile index 7fb5ea8..80bef68 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ LIBS=clib-6502.a # Common source files ASM_SRCS = tk2k_startup.s C_SRCS = main.c monitor_subroutines.c utility.c \ - game_graphics.c + game_graphics.c game_logic.c # Object files OBJS = $(ASM_SRCS:%.s=%.o) $(C_SRCS:%.c=%.o) diff --git a/src/game_logic.c b/src/game_logic.c new file mode 100644 index 0000000..8bf9235 --- /dev/null +++ b/src/game_logic.c @@ -0,0 +1,29 @@ +#include "game_logic.h" + +static uint8_t game_grid_alpha[GRID_WIDTH * GRID_HEIGHT]; +static uint8_t game_grid_beta[GRID_WIDTH * GRID_HEIGHT]; + +static uint8_t *front_grid = game_grid_alpha; +static uint8_t *back_grid = game_grid_beta; + +void swap_grids(void); + +void swap_grids(void) { + uint8_t *temp = front_grid; + + front_grid = back_grid; + back_grid = temp; +} + +uint8_t *get_current_grid(void) { + return front_grid; +} + +uint8_t *step_game(step_direction dir) { + // TODO: Update the grid state calculating the new state in the back grid + + + swap_grids(); + + return front_grid; +} diff --git a/src/game_logic.h b/src/game_logic.h new file mode 100644 index 0000000..94057cb --- /dev/null +++ b/src/game_logic.h @@ -0,0 +1,19 @@ +#ifndef _GAME_LOGIC_HEADER_ +#define _GAME_LOGIC_HEADER_ + +#include + +#define GRID_WIDTH 5 +#define GRID_HEIGHT 5 + +typedef enum { + UP, + DOWN, + LEFT, + RIGHT +} step_direction; + +uint8_t *get_current_grid(void); +uint8_t *step_game(step_direction dir); + +#endif /* _GAME_LOGIC_HEADER_ */