mirror of
https://codeberg.org/hkzlab/TK2048.git
synced 2025-12-25 14:52:15 +11:00
add score and moves
This commit is contained in:
parent
1a3635fc9a
commit
640c197525
11 changed files with 71 additions and 62 deletions
2
Makefile
2
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)
|
||||
|
|
|
|||
BIN
graphics/moves.png
Normal file
BIN
graphics/moves.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 327 B |
BIN
graphics/score.png
Normal file
BIN
graphics/score.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 300 B |
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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_ */
|
||||
|
|
|
|||
21
src/graph_misc_data.c
Normal file
21
src/graph_misc_data.c
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#include <stdint.h>
|
||||
|
||||
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
|
||||
};
|
||||
14
src/graph_misc_data.h
Normal file
14
src/graph_misc_data.h
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#ifndef _GRAPH_MISC_DATA_HEADER_
|
||||
#define _GRAPH_MISC_DATA_HEADER_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#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_ */
|
||||
10
src/main.c
10
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) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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_ */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue