Add movement graphics

This commit is contained in:
hkz 2025-07-23 11:19:10 +02:00
commit 457d510384
14 changed files with 114 additions and 22 deletions

View file

@ -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)

BIN
graphics/arrow_hor.aseprite Normal file

Binary file not shown.

BIN
graphics/arrow_hor.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 B

BIN
graphics/arrow_ver.aseprite Normal file

Binary file not shown.

BIN
graphics/arrows.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 121 B

BIN
graphics/arroww.aseprite Normal file

Binary file not shown.

View file

@ -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))

6
src/arrows_pic.c Normal file
View file

@ -0,0 +1,6 @@
#include <stdint.h>
const uint8_t arrows_pic[] = {
0x00, 0x00, 0x00, 0x08, 0x1C, 0x3E, 0x7F,
0x40, 0x60, 0x70, 0x78, 0x70, 0x60, 0x40
};

10
src/arrows_pic.h Normal file
View file

@ -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_ */

View file

@ -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;
}
}
}

View file

@ -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_ */

View file

@ -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;

View file

@ -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);

View file

@ -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();