Skip to content

Commit

Permalink
Polishing artwork
Browse files Browse the repository at this point in the history
  • Loading branch information
ifilot committed Sep 1, 2024
1 parent 0f73f18 commit e4100d0
Show file tree
Hide file tree
Showing 13 changed files with 129 additions and 33 deletions.
Binary file modified assets/tiles/cx16-kakuro-tiles.pyxel
Binary file not shown.
Binary file modified assets/tiles/menu-tiles.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/tiles/menu-tiles.pyxel
Binary file not shown.
Binary file modified assets/tiles/tiles.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ KAKURO.PRG: *.c *.h *.s TILES.DAT MTILES.DAT PUZZLE.DAT SDIGITS.DAT FONTMAP.DAT
$(CC) -O -o KAKURO.PRG -t cx16 -C kakuro.cfg *.c *.s *.lib

TILES.DAT: ../assets/tiles/tiles.png ../assets/scripts/convert_tilemap.py
$(PYTHON) ../assets/scripts/convert_tilemap.py tiles.png TILES.DAT 2
$(PYTHON) ../assets/scripts/convert_tilemap.py tiles.png TILES.DAT 4

MTILES.DAT: ../assets/tiles/menu-tiles.png ../assets/scripts/convert_tilemap.py
$(PYTHON) ../assets/scripts/convert_tilemap.py menu-tiles.png MTILES.DAT 6
Expand Down
12 changes: 6 additions & 6 deletions src/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
#define _CONSTANTS_H

// graphics positioning in VRAM
#define TILEBASE_MENU 0x0000 // 6*16 tiles at 8bpp
#define TILEBASE_GAME 0x6000 // 2*16 tiles at 8bpp
#define TILEBASE_CUSTOM 0x8000 // 2*16 tiles at 8bpp
#define TILEBASE_FONT 0xA000 // 8 * 16 tiles at 1bpp
#define MAPBASE0 0xC000 // 64 x 64 tiles
#define MAPBASE1 0xD000 // 64 x 64 tiles
#define TILEBASE_MENU 0x00000 // 6*16 tiles at 8bpp
#define TILEBASE_GAME 0x06000 // 2*16 tiles at 8bpp
#define TILEBASE_CUSTOM 0x0A000 // 4*16 tiles at 8bpp
#define MAPBASE0 0x0D000 // 64 x 64 tiles
#define TILEBASE_FONT 0x14000 // 8 * 16 tiles at 1bpp
#define MAPBASE1 0x16000 // 64 x 64 tiles
#define PALETTEBASE 0x1FA20
#define PALETTEBYTE 0x00
#define BANKED_RAM 0xA000
Expand Down
1 change: 1 addition & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ void main() {

// enable mouse
init_mouse();
set_mouse_pointer(0x30);

// load sound engine
init_sound();
Expand Down
89 changes: 69 additions & 20 deletions src/puzzle.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ void build_puzzle(uint8_t puzzle_id) {
set_puzzle_status(current_puzzle_id+1, idx, 0, 0, 0);

// keep track of time
print_clock_border(28, 31);
game_start_time = clock();
prevtotal = -1;
}
Expand Down Expand Up @@ -283,7 +284,7 @@ void puzzle_handle_mouse() {
asm("jsr $FF6B");
asm("sta %v", mouse_buttons);
}
gamestate |= GAME_QUIT;
puzzle_quit();
}
} else {
set_tile(1, 38, 0x08, 0x00, LAYER0);
Expand Down Expand Up @@ -371,22 +372,7 @@ void puzzle_handle_keyboard() {
}
}
} else if(keycode == KEYCODE_ESCAPE) {

save_screen_state();
build_window(12,5,2,30);
printtext("Are you sure you want to quit?", 12, 5, 0x12);
printtext("YES (Y) / NO (N)", 13, 5, 0x12);

while(keycode != 'Y' && keycode != 'N') {
asm("jsr $FFE4");
asm("sta %v", keycode);
sound_fill_buffers();
}
if(keycode == 'Y') {
gamestate |= GAME_QUIT;
} else {
restore_screen_state();
}
puzzle_quit();
}
}

Expand All @@ -411,7 +397,8 @@ void puzzle_generate_clues() {
idx++;
}
build_clue_tile_right(vrampos, c);
set_tile(offset_y + i*2, offset_x + j*2+1, 0x20+vrampos, 0x00, 0);
set_tile(offset_y + i*2, offset_x + j*2+1,
((TILEBASE_CUSTOM - TILEBASE_GAME) >> 8)+vrampos, 0x00, 0);
vrampos++;
}

Expand All @@ -425,7 +412,8 @@ void puzzle_generate_clues() {
idx += puzzlecols;
}
build_clue_tile_down(vrampos, c);
set_tile(offset_y + i*2+1, offset_x + j*2, 0x20+vrampos, 0x00, 0);
set_tile(offset_y + i*2+1, offset_x + j*2,
((TILEBASE_CUSTOM - TILEBASE_GAME) >> 8)+vrampos, 0x00, 0);
vrampos++;
}
}
Expand Down Expand Up @@ -499,7 +487,7 @@ void puzzle_color_numbers() {
*/
void show_game_time() {
calculate_game_time();
printtext(game_timebuffer, 29, 32, 0x15);
print_clock(game_timebuffer, 28, 31);
}

/**
Expand Down Expand Up @@ -632,6 +620,35 @@ void puzzle_complete() {
gamestate |= GAME_COMPLETE;
}

/**
* @brief Routine to invoke when user wants to quit the puzzle
*
*/
void puzzle_quit() {
static uint8_t keycode = 0xFF;
save_screen_state();
build_window(12,5,2,30);
printtext("Are you sure you want to quit?", 12, 5, 0x12);
printtext("YES (Y) / NO (N)", 13, 5, 0x12);

// consume previous keycode
while(keycode != 0) {
asm("jsr $FFE4");
asm("sta %v", keycode);
}

while(keycode != 'Y' && keycode != 'N') {
asm("jsr $FFE4");
asm("sta %v", keycode);
sound_fill_buffers();
}
if(keycode == 'Y') {
gamestate |= GAME_QUIT;
} else {
restore_screen_state();
}
}

/**
* @brief Auxiliary function that computes the game time and stores it in buffer
*
Expand Down Expand Up @@ -746,4 +763,36 @@ void build_window(uint8_t y, uint8_t x, uint8_t h, uint8_t w) {
set_tile(y+i-1, x+j-1, 0x00, 0x00, LAYER1);
}
}
}

/**
* @brief Print the border around the clock
*
* @param y y-position
* @param x x-position
*/
void print_clock_border(uint8_t y, uint8_t x) {
uint8_t i;
set_tile(y-1, x-1, 0x22, 0x00, LAYER0); // top left
set_tile(y, x-1, 0x21, 0x00, LAYER0); // mid left
set_tile(y+1, x-1, 0x22, MIRROR_Y, LAYER0); // bottom left
for(i=0; i<8; i++) {
set_tile(y-1, x+i, 0x20, 0x00, LAYER0);
set_tile(y+1, x+i, 0x20, MIRROR_Y, LAYER0);
}
set_tile(y-1, x+8, 0x22, MIRROR_X, LAYER0); // top right
set_tile(y, x+8, 0x21, MIRROR_X, LAYER0); // mid right
set_tile(y+1, x+8, 0x22, MIRROR_XY, LAYER0); // bottom right
}

void print_clock(const char* s, uint8_t y, uint8_t x) {
while(*s != 0) {
if(*s == ':') {
set_tile(y, x, 0x3A, 0x00, LAYER0);
} else {
set_tile(y, x, *s - '0' + 0x30, 0x00, LAYER0);
}
x++;
s++;
}
}
22 changes: 22 additions & 0 deletions src/puzzle.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ uint8_t get_nr_incorrect_tiles();
*/
void puzzle_complete();

/**
* @brief Routine to invoke when user wants to quit the puzzle
*
*/
void puzzle_quit();

/**
* @brief Auxiliary function that computes the game time
*
Expand Down Expand Up @@ -179,4 +185,20 @@ void wait_for_key(uint8_t key);
*/
void build_window(uint8_t y, uint8_t x, uint8_t h, uint8_t w);

/**
* @brief Print the border around the clock
*
* @param y y-position
* @param x x-position
*/
void print_clock_border(uint8_t y, uint8_t x);

/**
* @brief Print clock
*
* @param y y-position on screen
* @param x x-position on screen
*/
void print_clock(const char* s, uint8_t y, uint8_t x);

#endif // _PUZZLE_H
2 changes: 1 addition & 1 deletion src/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
#
# This BASH file is made for MINGW64 BASH
#
../../emulator-win/x16emu.exe -c02 -prg KAKURO.PRG -run -debug -capture -dump RB
../../emulator-win/x16emu.exe -c02 -prg KAKURO.PRG -run -scale 2 -debug -capture
4 changes: 2 additions & 2 deletions src/tile.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void build_clue_tile_right(uint16_t vrampos, uint8_t value) {


// reset pointer and copy to VRAM
ptr_des = (uint8_t*)(0xA000 + 8 * 4 * 10 + 256);
ptr_des = (uint8_t*)(BANKED_RAM + 8 * 4 * 10 + 256);
map_base_addr = TILEBASE_CUSTOM + 256 * vrampos;
VERA.address = map_base_addr;
VERA.address_hi = map_base_addr >> 16;
Expand Down Expand Up @@ -164,7 +164,7 @@ void build_clue_tile_down(uint16_t vrampos, uint8_t value) {
}

// reset pointer and copy to VRAM
ptr_des = (uint8_t*)(0xA000 + 8 * 4 * 10 + 256);
ptr_des = (uint8_t*)(BANKED_RAM + 8 * 4 * 10 + 256);
map_base_addr = TILEBASE_CUSTOM + 256 * vrampos;
VERA.address = map_base_addr;
VERA.address_hi = map_base_addr >> 16;
Expand Down
21 changes: 19 additions & 2 deletions src/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ void set_tilebase_layer0(uint16_t addr) {
* @brief Load the tiles from file into video memory
*
*/
void load_tiles(const char* filename, uint16_t addr) {
void load_tiles(const char* filename, uint32_t addr) {
cbm_k_setnam(filename);
cbm_k_setlfs(0, 8, 2);
cbm_k_load(2, addr);
cbm_k_load(2 + (addr >> 16), addr);
}

/**
Expand Down Expand Up @@ -284,4 +284,21 @@ void restore_screen_state() {

asm("lda 0");
asm("sta 0");
}

/**
* @brief Set the mouse pointer
*
* @param tile_id which tile to use
*/
void set_mouse_pointer(uint8_t tile_id) {
unsigned long sprite_addr = 0x1FC00;
uint32_t graph_addr = TILEBASE_MENU + (tile_id << 8);

VERA.address = sprite_addr;
VERA.address_hi = sprite_addr >> 16;
VERA.address_hi |= 0b10000;

VERA.data0 = graph_addr >> 5;
VERA.data0 = (graph_addr >> 13) | (1 << 7);
}
9 changes: 8 additions & 1 deletion src/video.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void init_screen();
* @brief Load the tiles from file into memory
*
*/
void load_tiles(const char* filename, uint16_t addr);
void load_tiles(const char* filename, uint32_t addr);

/**
* @brief Set the tilebase offset for layer0
Expand Down Expand Up @@ -119,4 +119,11 @@ void save_screen_state();
*/
void restore_screen_state();

/**
* @brief Set the mouse pointer
*
* @param tile_id which tile to use
*/
void set_mouse_pointer(uint8_t tile_id);

#endif // _VIDEO_H

0 comments on commit e4100d0

Please sign in to comment.