diff --git a/Makefile b/Makefile index 7a783fc..f4bbec5 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,8 @@ LIBS=clib-6502.a ASM_SRCS = tk2k_startup.s C_SRCS = main.c monitor_subroutines.c utility.c \ game_graphics.c game_logic.c input.c \ - line_data.c tiles.c graph_misc_data.c + line_data.c tiles.c graph_misc_data.c \ + arrows_pic.c # Object files OBJS = $(ASM_SRCS:%.s=%.o) $(C_SRCS:%.c=%.o) diff --git a/graphics/arrow_hor.aseprite b/graphics/arrow_hor.aseprite new file mode 100644 index 0000000..1497eab Binary files /dev/null and b/graphics/arrow_hor.aseprite differ diff --git a/graphics/arrow_hor.png b/graphics/arrow_hor.png new file mode 100644 index 0000000..3ce0af9 Binary files /dev/null and b/graphics/arrow_hor.png differ diff --git a/graphics/arrow_ver.aseprite b/graphics/arrow_ver.aseprite new file mode 100644 index 0000000..17c85f1 Binary files /dev/null and b/graphics/arrow_ver.aseprite differ diff --git a/graphics/arrows.png b/graphics/arrows.png new file mode 100644 index 0000000..d3b2b67 Binary files /dev/null and b/graphics/arrows.png differ diff --git a/graphics/arroww.aseprite b/graphics/arroww.aseprite new file mode 100644 index 0000000..31fbd85 Binary files /dev/null and b/graphics/arroww.aseprite differ diff --git a/linker-files/linker.scm b/linker-files/linker.scm index a8ae353..9312ce0 100644 --- a/linker-files/linker.scm +++ b/linker-files/linker.scm @@ -4,11 +4,11 @@ (memory firstPage (address (#x100 . #x1ff)) (section stack)) (memory reserved (address (#x200 . #x7ff)) (type ram)) (memory program (address (#x801 . #x1fff)) (type ram) - (section (programStart #x801) (startup #x80e) code switch idata cdata data_init_table)) -;;; (section (programStart #x801) (startup #x80e) code)) +;;; (section (programStart #x801) (startup #x80e) code switch idata cdata data_init_table)) + (section (programStart #x801) (startup #x80e) code)) (memory displayPage1 (address (#x2000 . #x3fff)) (type ram)) (memory datamem (address (#x4000 . #x91ff)) (type ram) (section cstack zdata data heap)) ;;; usermem goes from 0x4000 to 0x9FFFF (included), we are splitting it -;;; (memory upperData (address (#x9200 . #x9fff)) (type ram) (section switch idata cdata data_init_table)) + (memory upperData (address (#x9200 . #x9fff)) (type ram) (section switch idata cdata data_init_table)) (memory displayPage2 (address (#xa000 . #xbfff)) (type ram)) (memory io (address (#xc000 . #xc0ff)) (type ram)) (memory rombank (address (#xc100 . #xffff)) (type rom)) diff --git a/src/arrows_pic.c b/src/arrows_pic.c new file mode 100644 index 0000000..57f1156 --- /dev/null +++ b/src/arrows_pic.c @@ -0,0 +1,6 @@ +#include + +const uint8_t arrows_pic[] = { + 0x00, 0x00, 0x00, 0x08, 0x1C, 0x3E, 0x7F, + 0x40, 0x60, 0x70, 0x78, 0x70, 0x60, 0x40 +}; diff --git a/src/arrows_pic.h b/src/arrows_pic.h new file mode 100644 index 0000000..cf11666 --- /dev/null +++ b/src/arrows_pic.h @@ -0,0 +1,10 @@ +#ifndef _ARROWS_PIC_HEADER_ +#define _ARROWS_PIC_HEADER_ + +#define ARROWS_WIDTH_BYTES 1 +#define ARROWS_HEIGHT 7 +#define ARROWS_TILES 2 + +extern const uint8_t arrows_pic[]; + +#endif /* _ARROWS_PIC_HEADER_ */ diff --git a/src/game_graphics.c b/src/game_graphics.c index e89f1e2..6ec1252 100644 --- a/src/game_graphics.c +++ b/src/game_graphics.c @@ -11,6 +11,7 @@ #include "charset.h" #include "monitor_subroutines.h" #include "graph_misc_data.h" +#include "arrows_pic.h" #define SCREEN_WIDTH_B 40 #define GRID_CELL_SIDE 35 @@ -143,3 +144,71 @@ void draw_picture(uint8_t w, uint8_t h, uint8_t x, uint8_t y, const uint8_t *dat memcpy(dest + line_offset_map[row + y] + x, data + (w * row), w); } } + +void ddraw_direction_arrows(arrow_direction dir) { + uint8_t pic_buffer[ARROWS_HEIGHT]; + + int8_t start, step, end, flip; + uint8_t ext, x, y; + + switch(dir) { + case ARROW_UP: + x = 2; + y = TOP_OFFSET + 1; + ext = 1; + start = 1; + step = 1; + end = ARROWS_HEIGHT; + flip = 0; + break; + case ARROW_DOWN: + x = 2; + y = TOP_OFFSET + (GRID_SIDE * GRID_CELL_SIDE); + ext = 1; + start = ARROWS_HEIGHT - 1; + step = -1; + end = 0; + flip = 0; + break; + case ARROW_LEFT: + x = 1; + y = TOP_OFFSET + 7; + ext = 0; + start = ARROWS_HEIGHT; + step = 1; + end = (ARROWS_HEIGHT * 2); + flip = 0; + break; + case ARROW_RIGHT: + x = 1 + (GRID_SIDE * (GRID_CELL_SIDE/7)); + y = TOP_OFFSET + 7; + ext = 0; + start = ARROWS_HEIGHT; + step = 1; + end = (ARROWS_HEIGHT * 2); + flip = 1; + break; + default: + return; + } + + uint8_t tot_arrows = (GRID_SIDE * (GRID_CELL_SIDE/7)) - 1; + + if(ext) { // Horizontal lines + uint8_t s_start = x; + for(uint8_t cur_arrow = 0; cur_arrow < tot_arrows; cur_arrow++) { + for(int8_t s = start, row = 0; s != end; s += step, row++) { + front_buf[line_offset_map[y + row] + s_start] = arrows_pic[s]; + } + s_start++; + } + } else { + uint8_t s_start = y; + for(uint8_t cur_arrow = 0; cur_arrow < tot_arrows; cur_arrow++) { + for(int8_t s = start, row = 0; s != end; s += step, row++) { + front_buf[line_offset_map[s_start + row] + x] = flip ? (bit_reverse(arrows_pic[s]) >> 1) : arrows_pic[s]; + } + s_start += ARROWS_HEIGHT; + } + } +} diff --git a/src/game_graphics.h b/src/game_graphics.h index fd9f80d..0f448e8 100644 --- a/src/game_graphics.h +++ b/src/game_graphics.h @@ -13,6 +13,13 @@ #define BRD_SKIP_LEFT(a) (a & 0x40) #define BRD_SKIP_RIGHT(a) (a & 0x80) +typedef enum { + ARROW_UP, + ARROW_DOWN, + ARROW_LEFT, + ARROW_RIGHT +} arrow_direction; + void ddraw_field_borders_on_buffer(uint8_t brd); void draw_game_background(void); void draw_number(uint16_t n, uint8_t len, uint8_t x, uint8_t y); @@ -20,6 +27,6 @@ void draw_tiles(void); void ddraw_single_tile(uint8_t offset); void swap_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(arrow_direction dir); #endif /* _GAME_GRAPHICS_HEADER_ */ diff --git a/src/game_logic.c b/src/game_logic.c index 6d9b305..d23e8d9 100644 --- a/src/game_logic.c +++ b/src/game_logic.c @@ -67,22 +67,22 @@ uint8_t step_game(step_direction dir) { */ switch(dir) { - case UP: + case STEP_UP: start_offset = GRID_SIDE - 1; column_step = GRID_SIDE; row_step = -1; break; - case DOWN: + case STEP_DOWN: start_offset = (GRID_SIDE * GRID_SIDE) - 1; column_step = -GRID_SIDE; row_step = -1; break; - case LEFT: + case STEP_LEFT: start_offset = 0; column_step = 1; row_step = GRID_SIDE; break; - case RIGHT: + case STEP_RIGHT: start_offset = GRID_SIDE - 1; column_step = -1; row_step = GRID_SIDE; diff --git a/src/game_logic.h b/src/game_logic.h index d682390..b8f7266 100644 --- a/src/game_logic.h +++ b/src/game_logic.h @@ -6,10 +6,10 @@ #define GRID_SIDE 5 typedef enum { - UP = 0, - DOWN, - LEFT, - RIGHT + STEP_UP, + STEP_DOWN, + STEP_LEFT, + STEP_RIGHT } step_direction; uint8_t reset_game(void); diff --git a/src/main.c b/src/main.c index cb18fbd..2db13b3 100644 --- a/src/main.c +++ b/src/main.c @@ -61,23 +61,23 @@ __task int main(void) { switch(read_kb()) { case K_UP: BELL1(); - ddraw_field_borders_on_buffer(0x0E); - done = step_game(UP); + done = step_game(STEP_UP); + ddraw_direction_arrows(ARROW_UP); break; case K_DOWN: BELL1(); - ddraw_field_borders_on_buffer(0x0D); - done = step_game(DOWN); + done = step_game(STEP_DOWN); + ddraw_direction_arrows(ARROW_DOWN); break; case K_LEFT: BELL1(); - ddraw_field_borders_on_buffer(0x0B); - done = step_game(LEFT); + done = step_game(STEP_LEFT); + ddraw_direction_arrows(ARROW_LEFT); break; case K_RIGHT: BELL1(); - ddraw_field_borders_on_buffer(0x07); - done = step_game(RIGHT); + done = step_game(STEP_RIGHT); + ddraw_direction_arrows(ARROW_RIGHT); break; default: continue; // Do nothing, loop again @@ -92,7 +92,6 @@ __task int main(void) { // Draw the number of moves draw_number(moves_count, MOVES_TEXT_WIDTH, MOVES_TEXT_X, MOVES_TEXT_Y); - // Draw the moved tiles draw_tiles();