From dbc1bebf9f980507970c5d6bd6d25c8439a31e1c Mon Sep 17 00:00:00 2001 From: hkz Date: Tue, 7 Oct 2025 11:59:16 +0200 Subject: [PATCH] Begin renaming graphic files to mention they're for HGR --- Makefile | 6 +- src/demo_main.c | 2 +- src/dlog_main.c | 2 +- src/game_graphics_demo.c | 3 - src/{game_graphics.c => game_hgr_graphics.c} | 2 +- src/{game_graphics.h => game_hgr_graphics.h} | 68 ++-- src/game_hgr_graphics_demo.c | 3 + src/game_main.c | 330 +++++++++---------- src/master_main.c | 2 +- 9 files changed, 209 insertions(+), 209 deletions(-) delete mode 100644 src/game_graphics_demo.c rename src/{game_graphics.c => game_hgr_graphics.c} (99%) rename src/{game_graphics.h => game_hgr_graphics.h} (87%) create mode 100644 src/game_hgr_graphics_demo.c diff --git a/Makefile b/Makefile index 53d346b..0f2ef74 100644 --- a/Makefile +++ b/Makefile @@ -23,13 +23,13 @@ INTRO_ASM_SRCS = tk2k_startup_module.s preserve_zero_pages.s INTRO_C_SRCS = intro_main.c utility.c DLOG_ASM_SRCS = tk2k_startup_module.s preserve_zero_pages.s sound.s -DLOG_C_SRCS = dlog_main.c input.c utility.c game_graphics.c line_data.c +DLOG_C_SRCS = dlog_main.c input.c utility.c game_hgr_graphics.c line_data.c GAME_ASM_SRCS = tk2k_startup_module.s preserve_zero_pages.s input_asm.s sound.s -GAME_C_SRCS = game_main.c input.c utility.c game_graphics.c line_data.c game_logic.c arrows_pic.c tiles.c graph_misc_data.c +GAME_C_SRCS = game_main.c input.c utility.c game_hgr_graphics.c line_data.c game_logic.c arrows_pic.c tiles.c graph_misc_data.c DEMO_ASM_SRCS = tk2k_startup_module.s preserve_zero_pages.s input_asm.s sound.s -DEMO_C_SRCS = demo_main.c input.c utility.c game_graphics_demo.c line_data.c game_logic.c arrows_pic.c tiles.c graph_misc_data.c +DEMO_C_SRCS = demo_main.c input.c utility.c game_hgr_graphics_demo.c line_data.c game_logic.c arrows_pic.c tiles.c graph_misc_data.c # Object files MASTER_OBJS = $(MASTER_ASM_SRCS:%.s=%.o) $(MASTER_C_SRCS:%.c=%.o) diff --git a/src/demo_main.c b/src/demo_main.c index 00625b2..65905ee 100644 --- a/src/demo_main.c +++ b/src/demo_main.c @@ -12,7 +12,7 @@ #include "game_data.h" #include "input.h" #include "game_logic.h" -#include "game_graphics.h" +#include "game_hgr_graphics.h" #include "monitor_subroutines.h" #include "sound.h" diff --git a/src/dlog_main.c b/src/dlog_main.c index c371164..98598a3 100644 --- a/src/dlog_main.c +++ b/src/dlog_main.c @@ -3,7 +3,7 @@ #include -#include "game_graphics.h" +#include "game_hgr_graphics.h" #include "monitor_subroutines.h" #include "utility.h" #include "mem_map.h" diff --git a/src/game_graphics_demo.c b/src/game_graphics_demo.c deleted file mode 100644 index f33e2f1..0000000 --- a/src/game_graphics_demo.c +++ /dev/null @@ -1,3 +0,0 @@ -#define _DEMO_MODE_ 1 - -#include "game_graphics.c" diff --git a/src/game_graphics.c b/src/game_hgr_graphics.c similarity index 99% rename from src/game_graphics.c rename to src/game_hgr_graphics.c index bf1ed65..ea7cf50 100644 --- a/src/game_graphics.c +++ b/src/game_hgr_graphics.c @@ -1,4 +1,4 @@ -#include "game_graphics.h" +#include "game_hgr_graphics.h" #include diff --git a/src/game_graphics.h b/src/game_hgr_graphics.h similarity index 87% rename from src/game_graphics.h rename to src/game_hgr_graphics.h index 72fcf99..e4234a7 100644 --- a/src/game_graphics.h +++ b/src/game_hgr_graphics.h @@ -1,34 +1,34 @@ -#ifndef _GAME_GRAPHICS_HEADER_ -#define _GAME_GRAPHICS_HEADER_ - -#include - -#define BRD_DOUBLING_UP(a) (a & 0x01) -#define BRD_DOUBLING_DOWN(a) (a & 0x02) -#define BRD_DOUBLING_LEFT(a) (a & 0x04) -#define BRD_DOUBLING_RIGHT(a) (a & 0x08) - -#define BRD_SKIP_UP(a) (a & 0x10) -#define BRD_SKIP_DOWN(a) (a & 0x20) -#define BRD_SKIP_LEFT(a) (a & 0x40) -#define BRD_SKIP_RIGHT(a) (a & 0x80) - -#define GRAPH_ARROW_UP 0 -#define GRAPH_ARROW_DOWN 1 -#define GRAPH_ARROW_LEFT 2 -#define GRAPH_ARROW_RIGHT 3 - -void initialize_display_buffers(void); -void ddraw_field_borders_on_buffer(uint8_t brd); -void draw_game_background(uint16_t hi_score); -void draw_number(uint16_t n, uint8_t len, uint8_t x, uint8_t y); -void draw_tiles(void); -void ddraw_single_tile(uint8_t offset); -void swap_display_buffers(void); -void clear_display_buffers(void); -void clear_box(uint8_t w, uint8_t h, uint8_t off_x, uint8_t off_y, uint8_t *disp_buf); -void ddraw_direction_arrows(uint8_t dir); -void ddraw_endgame_box(int8_t done, uint16_t score, uint16_t hi_score); -void sync_display1_buffer(void); - -#endif /* _GAME_GRAPHICS_HEADER_ */ +#ifndef _GAME_HGR_GRAPHICS_HEADER_ +#define _GAME_HGR_GRAPHICS_HEADER_ + +#include + +#define BRD_DOUBLING_UP(a) (a & 0x01) +#define BRD_DOUBLING_DOWN(a) (a & 0x02) +#define BRD_DOUBLING_LEFT(a) (a & 0x04) +#define BRD_DOUBLING_RIGHT(a) (a & 0x08) + +#define BRD_SKIP_UP(a) (a & 0x10) +#define BRD_SKIP_DOWN(a) (a & 0x20) +#define BRD_SKIP_LEFT(a) (a & 0x40) +#define BRD_SKIP_RIGHT(a) (a & 0x80) + +#define GRAPH_ARROW_UP 0 +#define GRAPH_ARROW_DOWN 1 +#define GRAPH_ARROW_LEFT 2 +#define GRAPH_ARROW_RIGHT 3 + +void initialize_display_buffers(void); +void ddraw_field_borders_on_buffer(uint8_t brd); +void draw_game_background(uint16_t hi_score); +void draw_number(uint16_t n, uint8_t len, uint8_t x, uint8_t y); +void draw_tiles(void); +void ddraw_single_tile(uint8_t offset); +void swap_display_buffers(void); +void clear_display_buffers(void); +void clear_box(uint8_t w, uint8_t h, uint8_t off_x, uint8_t off_y, uint8_t *disp_buf); +void ddraw_direction_arrows(uint8_t dir); +void ddraw_endgame_box(int8_t done, uint16_t score, uint16_t hi_score); +void sync_display1_buffer(void); + +#endif /* _GAME_HGR_GRAPHICS_HEADER_ */ diff --git a/src/game_hgr_graphics_demo.c b/src/game_hgr_graphics_demo.c new file mode 100644 index 0000000..337c19a --- /dev/null +++ b/src/game_hgr_graphics_demo.c @@ -0,0 +1,3 @@ +#define _DEMO_MODE_ 1 + +#include "game_hgr_graphics.c" diff --git a/src/game_main.c b/src/game_main.c index 1043aff..835cd0f 100644 --- a/src/game_main.c +++ b/src/game_main.c @@ -1,165 +1,165 @@ -#include -#include - -#include - -#include "monitor_subroutines.h" -#include "utility.h" -#include "mem_map.h" -#include "shared_page.h" -#include "state_page.h" -#include "dlog_data.h" -#include "game_data.h" -#include "input.h" -#include "game_logic.h" -#include "game_graphics.h" -#include "monitor_subroutines.h" -#include "sound.h" - -// External initialization requirements -#pragma require __preserve_zp -#pragma require __data_initialization_needed - -#define MOVES_TEXT_X 32 -#define MOVES_TEXT_Y 61 -#define MOVES_TEXT_WIDTH 5 - -#define SCORE_TEXT_X 32 -#define SCORE_TEXT_Y 29 -#define SCORE_TEXT_WIDTH 5 - -#define HIGH_TEXT_X 32 -#define HIGH_TEXT_Y 107 - -#define WIN_SCORE_BONUS 10000 - -static state_page_data* state_page = (state_page_data*)STATE_PAGE; -static shared_page_data *shared_page = (shared_page_data*)SHARED_PAGE; - -void main(void) { - uint16_t moves_count = 0; - uint16_t score = 0; - int8_t done = 0; - - // By default, once we return from this, return to the DLOG module and give the master no command to execute - shared_page->master_command = MASTER_COMMAND_NONE; - shared_page->next_module_idx = 3; // Go to the DLOG module - - dlog_data *dld = (dlog_data *)(shared_page->module_data); - dlog_data *gad = (dlog_data *)(shared_page->module_data); - - // Make sure the buffers are pointing to the correct memory and are clear - clear_display_buffers(); - - // Reset the game, calculate the initial score depending on which tiles we randomly get - score = reset_game(); - - // Load the game - if(gad->mode == GAME_MODE_LOAD) { - gad->mode = GAME_MODE_NORMAL; - - memcpy(get_front_grid(), (void*)(state_page->save_grid), GRID_SIDE * GRID_SIDE); - moves_count = state_page->saved_moves_count; - score = calculate_score(); - - // We loaded an empty save, just restart the game - if (!score) score = reset_game(); - } - - // Draw the initial state of the game - draw_game_background(state_page->hi_score); - draw_number(moves_count, MOVES_TEXT_WIDTH, MOVES_TEXT_X, MOVES_TEXT_Y); - draw_number(score, SCORE_TEXT_WIDTH, SCORE_TEXT_X, SCORE_TEXT_Y); - draw_tiles(); - - // Swap graphical buffers - swap_display_buffers(); - - while(1) { // Game loop - lfsr_update(); - - switch(read_kb()) { - case K_UP: - SND_TAP(); - done = step_game(GAME_STEP_UP); - ddraw_direction_arrows(GRAPH_ARROW_UP); - break; - case K_DOWN: - SND_TAP(); - done = step_game(GAME_STEP_DOWN); - ddraw_direction_arrows(GRAPH_ARROW_DOWN); - break; - case K_LEFT: - SND_TAP(); - done = step_game(GAME_STEP_LEFT); - ddraw_direction_arrows(GRAPH_ARROW_LEFT); - break; - case K_RIGHT: - SND_TAP(); - done = step_game(GAME_STEP_RIGHT); - ddraw_direction_arrows(GRAPH_ARROW_RIGHT); - break; - case K_CTRL_R: - snd_mod_button(); - score = 0; // We'll reset the score - done = -1; - break; - case K_CTRL_S: // The following two will return early - snd_mod_button(); - memcpy((void*)(state_page->save_grid), get_front_grid(), GRID_SIDE * GRID_SIDE); - state_page->saved_moves_count = moves_count; - shared_page->master_command = MASTER_COMMAND_SAVE; - case K_CTRL_L: - snd_mod_button(); - sync_display1_buffer(); - shared_page->next_module_idx = 4; - gad->mode = GAME_MODE_LOAD; - return; - default: - continue; // Do nothing, loop again - } - - // Increase the count of moves we made (unless we lost or reset the game) - if(done >= 0) moves_count++; - - // Draw the number of moves - draw_number(moves_count, MOVES_TEXT_WIDTH, MOVES_TEXT_X, MOVES_TEXT_Y); - - // Draw the moved tiles - draw_tiles(); - - // If we have won, or we got a reset request, break out of this loop - if(done) { - score += (done > 0) ? WIN_SCORE_BONUS : 0; - draw_number(score, SCORE_TEXT_WIDTH, SCORE_TEXT_X, SCORE_TEXT_Y); - swap_display_buffers(); // Make sure we show the latest changes - break; - } - - // Unable to add a tile: we ran out of space and lost!!! - uint8_t random_tile_off = add_random_tile(); - if(!random_tile_off) { - done = -1; // Lost the game - break; - } - - score = calculate_score(); - - // Draw the score - draw_number(score, SCORE_TEXT_WIDTH, SCORE_TEXT_X, SCORE_TEXT_Y); - - swap_display_buffers(); - - // Draw the new tile directly on the front buffer, this way we make it appear with an "animation" - ddraw_single_tile(random_tile_off - 1); - } - - // Sync the display buffers - sync_display1_buffer(); - - dld->mode = (done > 0) ? DLOG_MODE_WIN : DLOG_MODE_LOSE; - dld->score = score; - - - return; -} +#include +#include + +#include + +#include "monitor_subroutines.h" +#include "utility.h" +#include "mem_map.h" +#include "shared_page.h" +#include "state_page.h" +#include "dlog_data.h" +#include "game_data.h" +#include "input.h" +#include "game_logic.h" +#include "game_hgr_graphics.h" +#include "monitor_subroutines.h" +#include "sound.h" + +// External initialization requirements +#pragma require __preserve_zp +#pragma require __data_initialization_needed + +#define MOVES_TEXT_X 32 +#define MOVES_TEXT_Y 61 +#define MOVES_TEXT_WIDTH 5 + +#define SCORE_TEXT_X 32 +#define SCORE_TEXT_Y 29 +#define SCORE_TEXT_WIDTH 5 + +#define HIGH_TEXT_X 32 +#define HIGH_TEXT_Y 107 + +#define WIN_SCORE_BONUS 10000 + +static state_page_data* state_page = (state_page_data*)STATE_PAGE; +static shared_page_data *shared_page = (shared_page_data*)SHARED_PAGE; + +void main(void) { + uint16_t moves_count = 0; + uint16_t score = 0; + int8_t done = 0; + + // By default, once we return from this, return to the DLOG module and give the master no command to execute + shared_page->master_command = MASTER_COMMAND_NONE; + shared_page->next_module_idx = 3; // Go to the DLOG module + + dlog_data *dld = (dlog_data *)(shared_page->module_data); + dlog_data *gad = (dlog_data *)(shared_page->module_data); + + // Make sure the buffers are pointing to the correct memory and are clear + clear_display_buffers(); + + // Reset the game, calculate the initial score depending on which tiles we randomly get + score = reset_game(); + + // Load the game + if(gad->mode == GAME_MODE_LOAD) { + gad->mode = GAME_MODE_NORMAL; + + memcpy(get_front_grid(), (void*)(state_page->save_grid), GRID_SIDE * GRID_SIDE); + moves_count = state_page->saved_moves_count; + score = calculate_score(); + + // We loaded an empty save, just restart the game + if (!score) score = reset_game(); + } + + // Draw the initial state of the game + draw_game_background(state_page->hi_score); + draw_number(moves_count, MOVES_TEXT_WIDTH, MOVES_TEXT_X, MOVES_TEXT_Y); + draw_number(score, SCORE_TEXT_WIDTH, SCORE_TEXT_X, SCORE_TEXT_Y); + draw_tiles(); + + // Swap graphical buffers + swap_display_buffers(); + + while(1) { // Game loop + lfsr_update(); + + switch(read_kb()) { + case K_UP: + SND_TAP(); + done = step_game(GAME_STEP_UP); + ddraw_direction_arrows(GRAPH_ARROW_UP); + break; + case K_DOWN: + SND_TAP(); + done = step_game(GAME_STEP_DOWN); + ddraw_direction_arrows(GRAPH_ARROW_DOWN); + break; + case K_LEFT: + SND_TAP(); + done = step_game(GAME_STEP_LEFT); + ddraw_direction_arrows(GRAPH_ARROW_LEFT); + break; + case K_RIGHT: + SND_TAP(); + done = step_game(GAME_STEP_RIGHT); + ddraw_direction_arrows(GRAPH_ARROW_RIGHT); + break; + case K_CTRL_R: + snd_mod_button(); + score = 0; // We'll reset the score + done = -1; + break; + case K_CTRL_S: // The following two will return early + snd_mod_button(); + memcpy((void*)(state_page->save_grid), get_front_grid(), GRID_SIDE * GRID_SIDE); + state_page->saved_moves_count = moves_count; + shared_page->master_command = MASTER_COMMAND_SAVE; + case K_CTRL_L: + snd_mod_button(); + sync_display1_buffer(); + shared_page->next_module_idx = 4; + gad->mode = GAME_MODE_LOAD; + return; + default: + continue; // Do nothing, loop again + } + + // Increase the count of moves we made (unless we lost or reset the game) + if(done >= 0) moves_count++; + + // Draw the number of moves + draw_number(moves_count, MOVES_TEXT_WIDTH, MOVES_TEXT_X, MOVES_TEXT_Y); + + // Draw the moved tiles + draw_tiles(); + + // If we have won, or we got a reset request, break out of this loop + if(done) { + score += (done > 0) ? WIN_SCORE_BONUS : 0; + draw_number(score, SCORE_TEXT_WIDTH, SCORE_TEXT_X, SCORE_TEXT_Y); + swap_display_buffers(); // Make sure we show the latest changes + break; + } + + // Unable to add a tile: we ran out of space and lost!!! + uint8_t random_tile_off = add_random_tile(); + if(!random_tile_off) { + done = -1; // Lost the game + break; + } + + score = calculate_score(); + + // Draw the score + draw_number(score, SCORE_TEXT_WIDTH, SCORE_TEXT_X, SCORE_TEXT_Y); + + swap_display_buffers(); + + // Draw the new tile directly on the front buffer, this way we make it appear with an "animation" + ddraw_single_tile(random_tile_off - 1); + } + + // Sync the display buffers + sync_display1_buffer(); + + dld->mode = (done > 0) ? DLOG_MODE_WIN : DLOG_MODE_LOSE; + dld->score = score; + + + return; +} diff --git a/src/master_main.c b/src/master_main.c index 4c5b4c0..029a126 100644 --- a/src/master_main.c +++ b/src/master_main.c @@ -34,7 +34,7 @@ static shared_page_data * shared_page = (shared_page_data*)SHARED_PAGE; static const uint8_t file_table[FILE_LIST_LEN][FNAME_LEN] = { { 0x80 | 'L', 0x80 | 'O', 0x80 | 'A', 0x80 | 'D', 0x80 | 'S', 0x00}, // LOADS (this is not an executable, but will be used to show the loading screen). { 0x80 | 'S', 0x80 | 'T', 0x80 | 'A', 0x80 | 'T', 0x80 | 'E', 0x00}, // STATE (this is not an executable, but will be used to save/load the game and scores). - { 0x80 | 'I', 0x80 | 'N', 0x80 | 'T', 0x80 | 'R', 0x80 | 'O', 0x00}, // INTRO (this executable will show the initial presentation picture) + { 0x80 | 'I', 0x80 | 'N', 0x80 | 'T', 0x80 | 'R', 0x80 | 'O', 0x00}, // INTRO (this executable will detect hardware and load the appropriate followup module) { 0x80 | 'D', 0x80 | 'L', 0x80 | 'O', 0x80 | 'G', 0xA0, 0x00}, // DLOG (startup, win, lose dialogs) { 0x80 | 'G', 0x80 | 'A', 0x80 | 'M', 0x80 | 'E', 0xA0, 0x00}, // GAME (the actual game) { 0x80 | 'D', 0x80 | 'E', 0x80 | 'M', 0x80 | 'O', 0xA0, 0x00}, // DEMO (automatic demo)