diff --git a/Makefile b/Makefile index e9c5027..7a783fc 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ 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 + line_data.c tiles.c graph_misc_data.c # Object files OBJS = $(ASM_SRCS:%.s=%.o) $(C_SRCS:%.c=%.o) diff --git a/graphics/moves.png b/graphics/moves.png new file mode 100644 index 0000000..6c3b882 Binary files /dev/null and b/graphics/moves.png differ diff --git a/graphics/score.png b/graphics/score.png new file mode 100644 index 0000000..50c3b8a Binary files /dev/null and b/graphics/score.png differ diff --git a/linker-files/linker.scm b/linker-files/linker.scm index 8df2b9e..a8ae353 100644 --- a/linker-files/linker.scm +++ b/linker-files/linker.scm @@ -8,7 +8,7 @@ ;;; (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/game_graphics.c b/src/game_graphics.c index 4d06df3..e89f1e2 100644 --- a/src/game_graphics.c +++ b/src/game_graphics.c @@ -10,6 +10,7 @@ #include "tiles.h" #include "charset.h" #include "monitor_subroutines.h" +#include "graph_misc_data.h" #define SCREEN_WIDTH_B 40 #define GRID_CELL_SIDE 35 @@ -25,6 +26,7 @@ static uint8_t *back_buf = (uint8_t*)DISPLAY_PAGE_2; // Every square is 35x35 pixels void draw_field_borders_on_buffer(uint8_t brd, uint8_t* buf); +void draw_picture(uint8_t w, uint8_t h, uint8_t x, uint8_t y, const uint8_t *data, uint8_t *dest); void ddraw_field_borders_on_buffer(uint8_t brd) { draw_field_borders_on_buffer(brd, front_buf); @@ -36,6 +38,10 @@ void draw_game_background(void) { // Draw the borders draw_field_borders_on_buffer(0x0F, buf); + + // Draw required pics + draw_picture(SCORE_PIC_WIDTH_BYTES, SCORE_PIC_HEIGHT, 31, 14, score_pic_data, buf); + draw_picture(MOVES_PIC_WIDTH_BYTES, MOVES_PIC_HEIGHT, 31, 45, moves_pic_data, buf); // Copy the data from display page 1 to 2 memcpy((void*)DISPLAY_PAGE_2, (void*)DISPLAY_PAGE_1, DISPLAY_PAGE_SIZE); @@ -87,10 +93,7 @@ void draw_tiles(void) { uint8_t col = tile % GRID_SIDE; uint8_t row = tile / GRID_SIDE; - for(uint8_t h = 0; h < TILE_HEIGHT; h++) { - memcpy(back_buf + line_offset_map[TOP_OFFSET + 7 + (row * GRID_CELL_SIDE) + h] + LEFT_OFFSET_B + 1 + (col * GRID_CELL_SIDE/7), - tile_data + (TILE_WIDTH_BYTES * h), TILE_WIDTH_BYTES); - } + draw_picture(TILE_WIDTH_BYTES, TILE_HEIGHT, LEFT_OFFSET_B + 1 + (col * GRID_CELL_SIDE/7), TOP_OFFSET + 7 + (row * GRID_CELL_SIDE), tile_data, back_buf); } } @@ -98,6 +101,17 @@ void draw_tiles(void) { draw_field_borders_on_buffer(0x0F, back_buf); } +// Note that the horizontal values here are in group of 7 pixels +void clear_box(uint8_t w, uint8_t h, uint8_t off_x, uint8_t off_y, uint8_t *disp_buf) { + for(uint8_t y = off_y; y < off_y + h; y++) { + uint16_t line_counter = line_offset_map[y]; + + for(uint8_t x = off_x; x < off_x + w; x++) { + disp_buf[line_counter + x] = 0; + } + } +} + void swap_display_buffers(void) { uint8_t *temp = front_buf; front_buf = back_buf; @@ -123,3 +137,9 @@ void draw_field_borders_on_buffer(uint8_t brd, uint8_t* buf) { buf[line_offset_map[row + TOP_OFFSET] + LEFT_OFFSET_B + (GRID_SIDE * (GRID_CELL_SIDE/7)) + 1] = BRD_SKIP_RIGHT(brd) ? 0x00 : (BRD_DOUBLING_RIGHT(brd) ? 0x03 : 0x01); } } + +void draw_picture(uint8_t w, uint8_t h, uint8_t x, uint8_t y, const uint8_t *data, uint8_t *dest) { + for(uint8_t row = 0; row < h; row++) { + memcpy(dest + line_offset_map[row + y] + x, data + (w * row), w); + } +} diff --git a/src/game_graphics.h b/src/game_graphics.h index da1db86..fd9f80d 100644 --- a/src/game_graphics.h +++ b/src/game_graphics.h @@ -19,5 +19,7 @@ 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_box(uint8_t w, uint8_t h, uint8_t off_x, uint8_t off_y, uint8_t *disp_buf); + #endif /* _GAME_GRAPHICS_HEADER_ */ diff --git a/src/graph_misc_data.c b/src/graph_misc_data.c new file mode 100644 index 0000000..1098e0d --- /dev/null +++ b/src/graph_misc_data.c @@ -0,0 +1,21 @@ +#include + +const uint8_t score_pic_data[] = { + 0x00, 0x2C, 0x40, 0x40, 0x03, 0x05, 0x30, 0x00, 0x00, 0x7B, 0x70, 0x63, 0x06, 0x7B, 0x70, 0x0F, 0x00, 0x0F, + 0x78, 0x57, 0x0B, 0x47, 0x39, 0x00, 0x40, 0x03, 0x3C, 0x2E, 0x4E, 0x63, 0x39, 0x00, 0x60, 0x00, 0x3C, 0x1B, + 0x2E, 0x61, 0x39, 0x00, 0x00, 0x07, 0x5E, 0x1F, 0x6E, 0x71, 0x18, 0x00, 0x40, 0x1D, 0x4E, 0x0C, 0x66, 0x1D, + 0x7E, 0x03, 0x00, 0x3A, 0x0E, 0x4E, 0x67, 0x07, 0x7C, 0x01, 0x00, 0x30, 0x07, 0x0E, 0x77, 0x02, 0x0C, 0x00, + 0x00, 0x3C, 0x07, 0x66, 0x33, 0x06, 0x06, 0x00, 0x40, 0x1B, 0x47, 0x46, 0x3B, 0x0D, 0x06, 0x00, 0x30, 0x0F, + 0x23, 0x6E, 0x19, 0x0E, 0x7F, 0x00, 0x78, 0x01, 0x3E, 0x78, 0x18, 0x1C, 0x3F, 0x00, 0x18, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00 +}; + +const uint8_t moves_pic_data[] = { + 0x00, 0x06, 0x00, 0x1C, 0x06, 0x30, 0x00, 0x0B, 0x00, 0x3E, 0x0C, 0x36, 0x0E, 0x72, 0x6F, 0x1E, 0x00, 0x7F, + 0x0A, 0x5D, 0x06, 0x3A, 0x60, 0x03, 0x00, 0x57, 0x4D, 0x72, 0x0E, 0x3F, 0x70, 0x00, 0x40, 0x6F, 0x46, 0x71, + 0x26, 0x39, 0x18, 0x00, 0x50, 0x33, 0x67, 0x71, 0x47, 0x1B, 0x60, 0x01, 0x60, 0x19, 0x67, 0x30, 0x67, 0x7F, + 0x33, 0x07, 0x60, 0x15, 0x73, 0x3C, 0x67, 0x7C, 0x41, 0x0E, 0x70, 0x4C, 0x73, 0x38, 0x37, 0x0C, 0x00, 0x0C, + 0x68, 0x5C, 0x33, 0x1E, 0x1F, 0x06, 0x00, 0x0F, 0x30, 0x4C, 0x31, 0x1C, 0x1F, 0x06, 0x70, 0x06, 0x38, 0x26, + 0x71, 0x0E, 0x0E, 0x7F, 0x6C, 0x03, 0x38, 0x66, 0x41, 0x07, 0x07, 0x3F, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x06, 0x00 +}; diff --git a/src/graph_misc_data.h b/src/graph_misc_data.h new file mode 100644 index 0000000..3626703 --- /dev/null +++ b/src/graph_misc_data.h @@ -0,0 +1,14 @@ +#ifndef _GRAPH_MISC_DATA_HEADER_ +#define _GRAPH_MISC_DATA_HEADER_ + +#include + +#define SCORE_PIC_WIDTH_BYTES 8 +#define SCORE_PIC_HEIGHT 14 +extern const uint8_t score_pic_data[]; + +#define MOVES_PIC_WIDTH_BYTES 8 +#define MOVES_PIC_HEIGHT 14 +extern const uint8_t moves_pic_data[]; + +#endif /* _GRAPH_MISC_DATA_HEADER_ */ diff --git a/src/main.c b/src/main.c index f9c87fa..cb18fbd 100644 --- a/src/main.c +++ b/src/main.c @@ -26,12 +26,12 @@ void init(void) { memset((void*)DISPLAY_PAGE_2, 0, DISPLAY_PAGE_SIZE); } -#define MOVES_TEXT_X 28 -#define MOVES_TEXT_Y 14 -#define MOVES_TEXT_WIDTH 4 +#define MOVES_TEXT_X 32 +#define MOVES_TEXT_Y 61 +#define MOVES_TEXT_WIDTH 5 -#define SCORE_TEXT_X 28 -#define SCORE_TEXT_Y 22 +#define SCORE_TEXT_X 32 +#define SCORE_TEXT_Y 29 #define SCORE_TEXT_WIDTH 5 __task int main(void) { diff --git a/src/utility.c b/src/utility.c index 57e49c2..06fc881 100644 --- a/src/utility.c +++ b/src/utility.c @@ -40,54 +40,7 @@ uint16_t lfsr_update(void) { return lfsr; } -// Note that the horizontal values here are in group of 7 pixels -void clear_box(uint8_t w, uint8_t h, uint8_t off_x, uint8_t off_y, uint8_t *disp_buf) { - for(uint8_t y = off_y; y < off_y + h; y++) { - uint16_t line_counter = line_offset_map[y]; - - for(uint8_t x = off_x; x < off_x + w; x++) { - disp_buf[line_counter + x] = 0; - } - } -} - -void draw_pic(uint16_t w, uint8_t h, uint8_t off_x, uint8_t off_y, const uint8_t *data, uint8_t *disp_buf) { - uint8_t remainder = 0; - uint8_t remainder_size = 0; - uint8_t pic_width_bytes = w / 8 + ((w % 8) ? 1 : 0); - uint16_t counter; - - for(uint8_t row = 0; row < h; row++) { - uint8_t screen_row = row + off_y; - counter = line_offset_map[screen_row] + (off_x/7); - - remainder = 0; - remainder_size = 0; - - // MSB is the color indicator - for(uint8_t column = 0; column < pic_width_bytes; column++) { - uint8_t pix_data = data[(pic_width_bytes * row) + column]; - uint8_t conv_data = (pix_data << remainder_size) | remainder; - remainder_size++; - remainder = (pix_data >> (8 - remainder_size)) & 0x7F; - disp_buf[counter++] = conv_data & 0x7F; - - if(remainder_size == 7) { - disp_buf[counter++] = remainder & 0x7F; - remainder = 0; - remainder_size = 0; - } - } - - if(remainder_size != 0) { - uint8_t mask = ~((1 << remainder_size) - 1); - disp_buf[counter] = (disp_buf[counter] & mask) | (remainder & 0x7F); - counter++; - } - } -} - - +/* void print_line(const char* line, uint8_t off_x, uint8_t off_y) { POKEZ(ZP_CV, off_y); @@ -112,3 +65,4 @@ void print_line(const char* line, uint8_t off_x, uint8_t off_y) { COUT1(' '|0x80); WAIT(0xFF); } +*/ diff --git a/src/utility.h b/src/utility.h index 09b55dc..6723446 100644 --- a/src/utility.h +++ b/src/utility.h @@ -22,8 +22,6 @@ void num_to_decbuf(uint16_t n, uint8_t len, uint8_t *buf); uint8_t bit_reverse(uint8_t b); uint8_t bit_count(uint8_t b); uint16_t lfsr_update(void); -void clear_box(uint8_t w, uint8_t h, uint8_t off_x, uint8_t off_y, uint8_t *disp_buf); -void draw_pic(uint16_t w, uint8_t h, uint8_t off_x, uint8_t off_y, const uint8_t *data, uint8_t *disp_buf); -void print_line(const char* line, uint8_t off_x, uint8_t off_y); +//void print_line(const char* line, uint8_t off_x, uint8_t off_y); #endif /* _UTILITY_HEADER_ */