mirror of
https://codeberg.org/hkzlab/TK2048.git
synced 2025-12-25 14:42:16 +11:00
Add code to use the charset in ROM
This commit is contained in:
parent
8f877d4677
commit
4ea5c7147e
9 changed files with 60 additions and 4 deletions
BIN
graphics/extracted_charset.png
Normal file
BIN
graphics/extracted_charset.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
BIN
graphics/moves.aseprite
Normal file
BIN
graphics/moves.aseprite
Normal file
Binary file not shown.
BIN
graphics/scores.aseprite
Normal file
BIN
graphics/scores.aseprite
Normal file
Binary file not shown.
23
src/charset.h
Normal file
23
src/charset.h
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#ifndef _CHARSET_HEADER_
|
||||
#define _CHARSET_HEADER_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// @ A B C D E F G H I
|
||||
// J K L M N O P Q R S
|
||||
// T U V W X Y Z [ \ ]
|
||||
// ^ _ ! " # $ % & ' (
|
||||
// ) * + , - . / 0 1 2
|
||||
// 3 4 5 6 7 8 9 : ; <
|
||||
// = > ?
|
||||
// Then graphic characters follow
|
||||
|
||||
#define ALPHA_OFFSET 8
|
||||
#define SYMBOL_OFFSET (28 * 8)
|
||||
#define NUM_OFFSET (48 * 8)
|
||||
|
||||
#define CHAR_HEIGHT 8
|
||||
|
||||
const uint8_t* const CHARSET = (uint8_t*)0xF200;
|
||||
|
||||
#endif /* _CHARSET_HEADER_ */
|
||||
|
|
@ -8,6 +8,7 @@
|
|||
#include "line_data.h"
|
||||
#include "game_logic.h"
|
||||
#include "tiles.h"
|
||||
#include "charset.h"
|
||||
#include "monitor_subroutines.h"
|
||||
|
||||
#define SCREEN_WIDTH_B 40
|
||||
|
|
@ -61,6 +62,20 @@ void ddraw_single_tile(uint8_t offset) {
|
|||
}
|
||||
}
|
||||
|
||||
void draw_number(uint16_t n, uint8_t len, uint8_t x, uint8_t y) {
|
||||
uint8_t buf[len];
|
||||
|
||||
// Decode the number into the buffer
|
||||
num_to_decbuf(n, len, buf);
|
||||
|
||||
for(uint8_t row = 0; row < CHAR_HEIGHT; row++) {
|
||||
uint16_t offset = line_offset_map[y + row];
|
||||
for(uint8_t col = 0; col < len; col++) {
|
||||
back_buf[(offset + (len - 1) - col) + x] = CHARSET[NUM_OFFSET + (buf[col] * CHAR_HEIGHT) + row];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void draw_tiles(void) {
|
||||
uint8_t* grid = get_front_grid();
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
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);
|
||||
void draw_tiles(void);
|
||||
void ddraw_single_tile(uint8_t offset);
|
||||
|
||||
|
|
|
|||
16
src/main.c
16
src/main.c
|
|
@ -26,6 +26,10 @@ 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
|
||||
|
||||
__task int main(void) {
|
||||
uint16_t moves_count = 0;
|
||||
|
||||
|
|
@ -37,6 +41,7 @@ __task int main(void) {
|
|||
reset_game();
|
||||
|
||||
draw_game_background();
|
||||
draw_number(moves_count, MOVES_TEXT_WIDTH, MOVES_TEXT_X, MOVES_TEXT_Y);
|
||||
draw_tiles();
|
||||
|
||||
while(1) { // Game loop
|
||||
|
|
@ -45,22 +50,22 @@ __task int main(void) {
|
|||
switch(read_kb()) {
|
||||
case K_UP:
|
||||
BELL1();
|
||||
ddraw_field_borders_on_buffer(0x1F);
|
||||
ddraw_field_borders_on_buffer(0x0E);
|
||||
state = step_game(UP);
|
||||
break;
|
||||
case K_DOWN:
|
||||
BELL1();
|
||||
ddraw_field_borders_on_buffer(0x2F);
|
||||
ddraw_field_borders_on_buffer(0x0D);
|
||||
state = step_game(DOWN);
|
||||
break;
|
||||
case K_LEFT:
|
||||
BELL1();
|
||||
ddraw_field_borders_on_buffer(0x4F);
|
||||
ddraw_field_borders_on_buffer(0x0B);
|
||||
state = step_game(LEFT);
|
||||
break;
|
||||
case K_RIGHT:
|
||||
BELL1();
|
||||
ddraw_field_borders_on_buffer(0x8F);
|
||||
ddraw_field_borders_on_buffer(0x07);
|
||||
state = step_game(RIGHT);
|
||||
break;
|
||||
default:
|
||||
|
|
@ -73,6 +78,9 @@ __task int main(void) {
|
|||
// If we have won, break out of this loop
|
||||
if(state.done) break;
|
||||
|
||||
// Draw the number of moves
|
||||
draw_number(moves_count, MOVES_TEXT_WIDTH, MOVES_TEXT_X, MOVES_TEXT_Y);
|
||||
|
||||
// Draw the moved tiles
|
||||
draw_tiles();
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,14 @@
|
|||
#include "monitor_subroutines.h"
|
||||
#include "line_data.h"
|
||||
|
||||
void num_to_decbuf(uint16_t n, uint8_t len, uint8_t *buf) {
|
||||
|
||||
for(uint8_t idx = 0; idx < len; idx++) {
|
||||
buf[idx] = n % 10;
|
||||
n /= 10;
|
||||
}
|
||||
}
|
||||
|
||||
// https://stackoverflow.com/questions/2602823/in-c-c-whats-the-simplest-way-to-reverse-the-order-of-bits-in-a-byte
|
||||
uint8_t bit_reverse(uint8_t b) {
|
||||
b = (b & 0xF0) >> 4 | (b & 0x0F) << 4;
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
|
||||
|
||||
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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue