Skip to content

Commit

Permalink
Initial commit docview function
Browse files Browse the repository at this point in the history
  • Loading branch information
ifilot committed Sep 12, 2024
1 parent 15c3017 commit 09e7cff
Show file tree
Hide file tree
Showing 16 changed files with 345 additions and 83 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"stdlib.h": "c",
"menu.h": "c",
"video.h": "c",
"random": "c"
"random": "c",
"docview.h": "c"
}
}
Binary file modified assets/fonts/font_8x8.psd
Binary file not shown.
6 changes: 3 additions & 3 deletions assets/scripts/create_fontmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ def create_fontmap_16(infile, outfile, rows):
for k,x in enumerate(range(0,8)):
px = img.getpixel((j*16+x, i*16+y))
if px[3] > 150:
b |= (1 << (8-k-1))
b |= (1 << (7-k))
data.append(b)

# last 8 columns
b = np.uint8(0x00)
for k,x in enumerate(range(8,16)):
px = img.getpixel((j*16+x, i*16+y))
if px[3] > 150:
b |= (1 << (8-k-1))
b |= (1 << (7-k))
data.append(b)

with open(outfile, 'wb') as f:
Expand All @@ -74,7 +74,7 @@ def create_fontmap_8(infile, outfile, rows):
for k,x in enumerate(range(0,8)):
px = img.getpixel((j*8+x, i*8+y))
if px[3] > 150:
b |= (1 << (8-k-1))
b |= (1 << (7-k))
data.append(b)

with open(outfile, 'wb') as f:
Expand Down
Binary file modified assets/tiles/cx16-kakuro-tiles.pyxel
Binary file not shown.
Binary file modified assets/tiles/font-tiles-8.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/font-tiles.pyxel
Binary file not shown.
Binary file modified assets/tiles/menu-tiles.pyxel
Binary file not shown.
17 changes: 17 additions & 0 deletions src/KAKURO.TXT
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
KAKURO
------

Kakuro is a logic-based number puzzle game, often described as a cross between a
crossword and Sudoku. In this game, players fill a grid with digits from 1 to 9,
with the objective of matching the sum of numbers in each row or column to a
given target. However, no number can be repeated within a single sum. Each clue
is represented as a small number in a black cell, dictating the sum of the
digits to be placed in the adjacent white cells.

For the Commander X16, Kakuro offers a nostalgic experience, blending the
puzzle's classic challenge with the retro charm of 8-bit computing. Players
navigate the grid using the mouse and inputting numbers via keyboard. The game
tests mathematical reasoning and strategic thinking, making it an engaging
pastime for puzzle enthusiasts and retro gaming fans alike. The simplistic yet
captivating design ensures that Kakuro on the Commander X16 is both a mental
workout and a tribute to vintage gaming.
1 change: 1 addition & 0 deletions src/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#define RAMBANK_TILE 0x03
#define RAMBANK_COLSWAP 0x04
#define RAMBANK_SCREEN 0x05
#define RAMBANK_DOCVIEW 0x06

// puzzledata settings
#define TLDT_REVEALED (1 << 4)
Expand Down
150 changes: 150 additions & 0 deletions src/docview.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/**************************************************************************
* *
* Author: Ivo Filot <ivo@ivofilot.nl> *
* *
* CX16-KAKURO is free software: *
* you can redistribute it and/or modify it under the terms of the *
* GNU General Public License as published by the Free Software *
* Foundation, either version 3 of the License, or (at your option) *
* any later version. *
* *
* CX16-KAKURO is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty *
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see http://www.gnu.org/licenses/. *
* *
**************************************************************************/

#include "docview.h"

/**
* @brief Initialize screen
*
*/
void docview_init_screen() {
// set scaling (resolution: 640 x 480)
VERA.display.hscale = 128;
VERA.display.vscale = 128;

// layer 0
// This layer contains the game background and the puzzle background; this
// includes all 'static' squares
set_tilebase_layer0(TILEBASE_MENU);

// layer 1
// On this layer, the values that the user fills in for the tiles are shown
VERA.layer1.config = (1 << 3) | (2 << 4) | (1 << 6); // T256C
VERA.layer1.tilebase = (TILEBASE_FONT8 >> 9); // 16 x 16 tiles
VERA.layer1.mapbase = MAPBASE1 >> 9;

// enable both layers
VERA.display.video |= 0b00110000;

// enable sprites
//VERA.display.video |= 0b01000000;

docview_clear_screen();
}

/**
* @brief Prepare screen to write text to it
*
*/
void docview_clear_screen() {
fill_layer(TILE_BACKGROUND, LAYER0, PALETTEBYTE, 64, 64);
fill_layer(0x20, LAYER1, 0x00, 64, 128);
}

/**
* @brief Write string to screen
*
* @param s
*/
void docview_write_string(const char* s) {
uint8_t x = 0;
uint8_t y = 0;
uint32_t map_base_addr = MAPBASE1 + (y << 7 + x) * 2;

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


while(*s != '\0') {
VERA.data0 = *s - 0x20;
VERA.data0 = 0x02;

x++;
if(x >= 80) {
x = 0;
y++;
map_base_addr = MAPBASE1 + (y << 7 + x) * 2;
VERA.address = map_base_addr;
VERA.address_hi = map_base_addr >> 16;
VERA.address_hi |= 0b10000;
}

s++;
}
}

/**
* @brief Load file into memory
*
* @param s
*/
void docview_load_file(const char* s) {
uint8_t *ptr;
asm("lda #%b", RAMBANK_DOCVIEW);
asm("sta 0");

// load puzzle into memory
cbm_k_setnam(s);
cbm_k_setlfs(0, 8, 2);
ptr = (uint8_t*)(cbm_k_load(0, BANKED_RAM));
*ptr = 0x00; // write terminating byte

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

/**
* @brief Print file contents onto screen
*/
void docview_show_file() {
uint8_t x = 0;
uint8_t y = 0;
uint8_t *s = (uint8_t*)(BANKED_RAM);
uint32_t map_base_addr = MAPBASE1 + (y << 7 + x) * 2;

// set docview ram bank
asm("lda #%b", RAMBANK_DOCVIEW);
asm("sta 0");

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

while(*s != '\0') {
if(*s == 0x0A) {
x = 0;
y++;
map_base_addr = MAPBASE1 + (y << 7 + x) * 2;
VERA.address = map_base_addr;
VERA.address_hi = map_base_addr >> 16;
VERA.address_hi |= 0b10000;
} else {
VERA.data0 = *s - 0x20;
VERA.data0 = 0x12;
}

s++;
}

// return to original ram bank
asm("lda 0");
asm("sta 0");
}
59 changes: 59 additions & 0 deletions src/docview.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**************************************************************************
* *
* Author: Ivo Filot <ivo@ivofilot.nl> *
* *
* CX16-KAKURO is free software: *
* you can redistribute it and/or modify it under the terms of the *
* GNU General Public License as published by the Free Software *
* Foundation, either version 3 of the License, or (at your option) *
* any later version. *
* *
* CX16-KAKURO is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty *
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see http://www.gnu.org/licenses/. *
* *
**************************************************************************/

#ifndef _DOCVIEW_H
#define _DOCVIEW_H

#include <ascii_charmap.h>

#include "video.h"

/**
* @brief Initialize screen
*
*/
void docview_init_screen();

/**
* @brief Prepare screen to write text to it
*
*/
void docview_clear_screen();

/**
* @brief Write string to screen
*
* @param s
*/
void docview_write_string(const char* s);

/**
* @brief Load file into memory
*
* @param s
*/
void docview_load_file(const char* s);

/**
* @brief Print file contents onto screen
*/
void docview_show_file();

#endif // _DOCVIEW_H
Loading

0 comments on commit 09e7cff

Please sign in to comment.