From 3a754b53ded69e07467c20c26ca1936efaac277b Mon Sep 17 00:00:00 2001
From: Jeffitus <49927060+Jeffitus@users.noreply.github.com>
Date: Sat, 4 Apr 2020 21:24:52 -0500
Subject: [PATCH] Ready for release, I think
---
README.md | 13 ++-
changelog.md | 5 +
src/defines.h | 8 +-
src/drawing.c | 31 ++++---
src/drawing.h | 6 +-
src/font/HELVE29.fnt | Bin 7936 -> 7936 bytes
src/font/calvetica.inc | 26 +++---
src/game.c | 157 +++++++++++++++++++++++--------
src/game.h | 3 +-
src/gfx/convimg.yaml | 4 +-
src/gfx/gfx.h | 1 -
src/gfx/pencil_selected.c | 44 ---------
src/gfx/pencil_selected.h | 18 ----
src/main.c | 58 ++----------
src/menu.c | 190 ++++++++++++++++++++++++++++++++++++--
src/menu.h | 8 +-
src/solve.c | 33 ++++---
src/solve.h | 12 +--
18 files changed, 396 insertions(+), 221 deletions(-)
create mode 100644 changelog.md
delete mode 100644 src/gfx/pencil_selected.c
delete mode 100644 src/gfx/pencil_selected.h
diff --git a/README.md b/README.md
index d918198..4185117 100644
--- a/README.md
+++ b/README.md
@@ -4,4 +4,15 @@ By Jeffitus
This is a Sudoku game for TI-CE (ez80) calculators.
-Written in C using the community libraries and toolchain.
\ No newline at end of file
+Written in C using the community libraries and toolchain.
+
+Check out the Cemetech topic [here](https://ceme.tech/t16261).
+
+## Building
+You can build this using the [CE C toolchain](https://github.com/CE-Programming/toolchain). Follow the instructions there to install, then enter `make` when you are in the \Sudoku-CE\ directory.
+
+## How to play
+Use the arrow keys and 2nd to navigate and select options in menus. You can also use clear to quit or go back. In-game, use the arrow keys to move around the grid, the numpad to enter a number in the selected cell, and graph to toggle the pencil mode. If the pencil in the botton right of the screen is filled in blue, pencil mode is activated. The game will automatically check if you have won when the grid is filled.
+
+## Credits
+This game was made by Jeffitus, with some help from MateoConLechuga and jacobly on the Cemetech forums. Also, thanks to DrDnar for his ce-fonts repository, where I found the main font used for this game.
\ No newline at end of file
diff --git a/changelog.md b/changelog.md
new file mode 100644
index 0000000..8c8fc21
--- /dev/null
+++ b/changelog.md
@@ -0,0 +1,5 @@
+# Sudoku CE Changelog
+
+## Version 1.0
+- First release
+- Only basic functionality: puzzle generation, input numbers and pencil marks, reveal solution
\ No newline at end of file
diff --git a/src/defines.h b/src/defines.h
index 882f3c0..a6d6c98 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -7,8 +7,10 @@
#define UNDEFINED (1 << 23)
#define PENCIL_MARKS (511 << 14)
#define PENCIL_MARK(n) (1 << (13 + n))
+#define SOLUTION_DATA 240
+#define SOLUTION(n) ((n & SOLUTION_DATA) >> 4)
/*For cases where want just the value or just the data*/
-#define DATA UNDEFINED & PENCIL_MARKS
+#define DATA (UNDEFINED & PENCIL_MARKS & SOLUTION_DATA)
#define VALUE 15
#define EASY 40
@@ -20,4 +22,6 @@
#define BLACK 1
#define WHITE 2
-#define ONE_SECOND 32768
\ No newline at end of file
+#define ONE_SECOND 32768
+
+extern uint24_t puzzle[9][9];
\ No newline at end of file
diff --git a/src/drawing.c b/src/drawing.c
index 05ab78a..c7c8b0a 100644
--- a/src/drawing.c
+++ b/src/drawing.c
@@ -21,9 +21,6 @@
#include "gfx/gfx.h"
#include "font/myfonts.h"
-extern uint24_t puzzle[9][9];
-extern uint8_t solution[9][9];
-
void draw_three_boxes(uint8_t pos) {
uint8_t i;
uint8_t cell_size = (PLAYING_GRID_SIZE - 1) / 9;
@@ -54,14 +51,15 @@ bool draw_puzzle(void) {
fontlib_SetCursorPosition(j * PLAYING_GRID_SIZE / 9 + j / 3 + 6 + PUZZLE_X, i * PLAYING_GRID_SIZE / 9 + i / 3 + 6 + PUZZLE_Y);
if (!(puzzle[i][j] & UNDEFINED)) {
fontlib_SetForegroundColor(BLACK);
- fontlib_DrawUInt(puzzle[i][j], 1);
- }
- if (puzzle[i][j] & UNDEFINED && ((puzzle[i][j] & VALUE) != 0)) {
- fontlib_SetForegroundColor(BLUE);
fontlib_DrawUInt(puzzle[i][j] & VALUE, 1);
}
- if (puzzle[i][j] == 128) {
- puzzle_filled = false;
+ if (puzzle[i][j] & UNDEFINED) {
+ if ((puzzle[i][j] & VALUE) == 0) {
+ puzzle_filled = false;
+ } else {
+ fontlib_SetForegroundColor(BLUE);
+ fontlib_DrawUInt(puzzle[i][j] & VALUE, 1);
+ }
}
}
}
@@ -95,6 +93,9 @@ void draw_timer(uint24_t timer_count) {
seconds = timer_count % 60;
+ gfx_SetColor(WHITE);
+ gfx_FillRectangle_NoClip(240, 2, 32, 54);
+
fontlib_SetCursorPosition(240, 2);
fontlib_DrawUInt(hours, 2);
fontlib_DrawString(":");
@@ -105,15 +106,15 @@ void draw_timer(uint24_t timer_count) {
fontlib_DrawUInt(seconds, 2);
}
-void draw_string_special(char string[]) {
- int i;
- for (i = 0; i <= strlen(string); i++) {
- if (string[i] == 'y') {
+void draw_string(char string[]) {
+ char *s;
+ for (s = string; *s; ++s) {
+ if (strchr("gpqy,", *s) != NULL) {
fontlib_ShiftCursorPosition(0, 5);
- fontlib_DrawGlyph('y');
+ fontlib_DrawGlyph(*s);
fontlib_ShiftCursorPosition(0, -5);
} else {
- fontlib_DrawGlyph(string[i]);
+ fontlib_DrawGlyph(*s);
}
}
}
\ No newline at end of file
diff --git a/src/drawing.h b/src/drawing.h
index a7ecc0a..6b72b74 100644
--- a/src/drawing.h
+++ b/src/drawing.h
@@ -3,6 +3,6 @@ void draw_grid(void);
bool draw_puzzle(void);
void draw_pencils(uint8_t row, uint8_t col);
void draw_timer(uint24_t timer_count);
-/* neccessary because the font is modified to be smaller, so any case of 'y' have to be handled specially :/
- basically just does fontlib_DrawString but changes cursor position for 'y' I will only add 'g' when I need to use it eventually */
-void draw_string_special(char string[]);
\ No newline at end of file
+/* Neccessary because the font is modified to be smaller, so any case like 'y' has to be handled specially :/
+ basically just does fontlib_DrawString but changes cursor position for 'y', etc. Right now only a few characters are implemented. */
+void draw_string(char string[]);
\ No newline at end of file
diff --git a/src/font/HELVE29.fnt b/src/font/HELVE29.fnt
index 992ef97dfc5dec42b0cf2990579dcf8e6b88a885..0a1775a366b57361b315f8730a959197ef2663a6 100644
GIT binary patch
delta 144
zcmZp$Yp~nk!OCV}AfUj&u-T7w5u1vQ&4B|62?+)U1`-kyJUl#XY-|-3KqdlIRBRUE
z5nxo}x3?$&s!S-bu;*uBFtF#}@Sy;x4G0Q8Y%nlLc+fD}jn{PYesNx=4+kc9@vagy
ax3>Vx8(7$zgBg>(`1Dx8tj!gC9RdJ7h9%@*eWW3Ok}WGghzmJ
qav-1jWN%®*~xplUdn+{L?!6)48QFnI!x(&R8c+07Mv9RdIrS{FS4
diff --git a/src/font/calvetica.inc b/src/font/calvetica.inc
index ee859e3..b29099b 100644
--- a/src/font/calvetica.inc
+++ b/src/font/calvetica.inc
@@ -62,7 +62,7 @@
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00,
0x03, 0x00, 0x03, 0xF0, 0x3F, 0xF0, 0x3F, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x30, 0x30, 0x10, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7E, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x06, 0x06, 0x0C, 0x0C, 0x0C, 0x18, 0x18, 0x18,
0x30, 0x30, 0x30, 0x60, 0x60, 0x60, 0xC0, 0xC0, 0xC0, 0x00, 0x07, 0xC0, 0x1F, 0xE0, 0x38, 0x60,
@@ -168,9 +168,9 @@
0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0xF8, 0x7F, 0xF8, 0x7F, 0x70, 0x00, 0x60, 0x00, 0xE0,
0x00, 0xC0, 0x01, 0x80, 0x01, 0x80, 0x03, 0x00, 0x07, 0x00, 0x0E, 0x00, 0x0C, 0x00, 0x1C, 0x00,
0x38, 0x00, 0x30, 0x00, 0x70, 0xFC, 0xFF, 0xFC, 0xFF, 0x3C, 0x3C, 0x30, 0x30, 0x30, 0x30, 0x30,
-0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0xC0, 0xC0, 0x60, 0x60, 0x60, 0x30,
+0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x3C, 0x3C, 0xC0, 0xC0, 0x60, 0x60, 0x60, 0x30,
0x30, 0x30, 0x18, 0x18, 0x18, 0x0C, 0x0C, 0x0C, 0x06, 0x06, 0x06, 0x78, 0x78, 0x18, 0x18, 0x18,
-0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x0E, 0x00, 0x1F,
+0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x78, 0x78, 0x00, 0x0E, 0x00, 0x1F,
0x80, 0x3B, 0xC0, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -187,14 +187,14 @@
0x60, 0x30, 0x70, 0x70, 0x38, 0xF0, 0x3F, 0xB0, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80, 0x07, 0xE0, 0x1F, 0x70, 0x38, 0x30, 0x30, 0x18, 0x60, 0xF8, 0x7F, 0xF8,
0x7F, 0x00, 0x60, 0x00, 0x30, 0x38, 0x38, 0xF0, 0x1F, 0xC0, 0x07, 0x1C, 0x3C, 0x30, 0x30, 0x30,
-0xFC, 0xFC, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB0, 0x0F, 0xF0, 0x3F, 0x70, 0x38, 0x30, 0x70, 0x30, 0x60,
-0x30, 0x60, 0x30, 0x60, 0x30, 0x60, 0x30, 0x70, 0x70, 0x38, 0xF0, 0x3F, 0xB0, 0x0F, 0x00, 0x30,
+0xFC, 0xFC, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0xB0, 0x0F, 0xF0, 0x3F,
+0x70, 0x38, 0x30, 0x70, 0x30, 0x60, 0x30, 0x60, 0x30, 0x60, 0x30, 0x60, 0x30, 0x70, 0x70, 0x38,
+0xF0, 0x3F, 0xB0, 0x0F, 0x30, 0x00, 0x30, 0x00, 0x60, 0x30, 0xE0, 0x3F, 0x80, 0x0F, 0x00, 0x30,
0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x37, 0xC0, 0x3F, 0xC0, 0x38, 0x60, 0x30,
0x60, 0x30, 0x60, 0x30, 0x60, 0x30, 0x60, 0x30, 0x60, 0x30, 0x60, 0x30, 0x60, 0x30, 0x60, 0x30,
0x30, 0x30, 0x00, 0x00, 0x00, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
-0x30, 0x30, 0x30, 0x00, 0x00, 0x00, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
-0x30, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0xE0, 0x30, 0xC0, 0x31,
+0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
+0xF0, 0xC0, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0xE0, 0x30, 0xC0, 0x31,
0x80, 0x33, 0x00, 0x37, 0x00, 0x3E, 0x00, 0x3F, 0x80, 0x3B, 0x80, 0x31, 0xC0, 0x31, 0xE0, 0x30,
0x60, 0x30, 0x70, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
0x30, 0x30, 0x30, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -204,11 +204,11 @@
0x00, 0x00, 0x00, 0x37, 0xC0, 0x3F, 0xC0, 0x38, 0x60, 0x30, 0x60, 0x30, 0x60, 0x30, 0x60, 0x30,
0x60, 0x30, 0x60, 0x30, 0x60, 0x30, 0x60, 0x30, 0x60, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xC0, 0x0F, 0xF0, 0x3F, 0x70, 0x38, 0x38, 0x70, 0x18, 0x60, 0x18, 0x60,
-0x18, 0x60, 0x18, 0x60, 0x38, 0x70, 0x70, 0x38, 0xF0, 0x3F, 0xC0, 0x0F, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x37, 0xF0, 0x3F, 0x70, 0x38, 0x38, 0x30, 0x18, 0x30,
-0x18, 0x30, 0x18, 0x30, 0x18, 0x30, 0x38, 0x30, 0x70, 0x38, 0xF0, 0x3F, 0xC0, 0x37, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB0, 0x0F, 0xF0, 0x3F, 0x70, 0x38, 0x30, 0x70,
-0x30, 0x60, 0x30, 0x60, 0x30, 0x60, 0x30, 0x60, 0x30, 0x70, 0x70, 0x38, 0xF0, 0x3F, 0xB0, 0x0F,
+0x18, 0x60, 0x18, 0x60, 0x38, 0x70, 0x70, 0x38, 0xF0, 0x3F, 0xC0, 0x0F, 0xC0, 0x37, 0xF0, 0x3F,
+0x70, 0x38, 0x38, 0x30, 0x18, 0x30, 0x18, 0x30, 0x18, 0x30, 0x18, 0x30, 0x38, 0x30, 0x70, 0x38,
+0xF0, 0x3F, 0xC0, 0x37, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0xB0, 0x0F,
+0xF0, 0x3F, 0x70, 0x38, 0x30, 0x70, 0x30, 0x60, 0x30, 0x60, 0x30, 0x60, 0x30, 0x60, 0x30, 0x70,
+0x70, 0x38, 0xF0, 0x3F, 0xB0, 0x0F, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x33, 0x37, 0x3C, 0x38, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0xC0, 0x3F, 0xC0,
0x70, 0x00, 0x60, 0x00, 0x78, 0x80, 0x3F, 0xC0, 0x0F, 0xE0, 0x01, 0x60, 0x00, 0xE0, 0x60, 0xC0,
diff --git a/src/game.c b/src/game.c
index 37a0d7e..89ed48c 100644
--- a/src/game.c
+++ b/src/game.c
@@ -21,9 +21,6 @@
#include "gfx/gfx.h"
#include "font/myfonts.h"
-extern uint24_t puzzle[9][9];
-extern uint8_t solution[9][9];
-
void game_loop(void) {
uint8_t i;
uint8_t j;
@@ -45,6 +42,14 @@ void game_loop(void) {
bool puzzle_filled;
bool win;
+ bool quit;
+
+ char pause_menu_title[] = "Paused";
+ char *pause_menu_options[] = {
+ "Resume",
+ "Give up",
+ "Quit"
+ };
selected_col = 0;
selected_row = 0;
@@ -58,12 +63,50 @@ void game_loop(void) {
num = 0;
win = false;
+ quit = false;
- draw_grid();
+ fontlib_SetForegroundColor(BLACK);
+ draw_grid();
setup_timer();
do {
+
+ if (pencil_mode) {
+ gfx_SetColor(BLUE);
+ gfx_HorizLine_NoClip(288, 204, 26);
+ gfx_HorizLine_NoClip(288, 237, 26);
+ gfx_VertLine_NoClip(284, 208, 26);
+ gfx_VertLine_NoClip(317, 208, 26);
+ gfx_FillRectangle_NoClip(285, 205, 32, 32);
+ } else {
+ gfx_SetColor(WHITE);
+ gfx_FillRectangle_NoClip(283, 203, 36, 36);
+ }
+ gfx_TransparentSprite_NoClip(pencil, 283, 203);
+
+ gfx_SetColor(WHITE);
+ gfx_FillRectangle_NoClip(prev_col * (CELL_SIZE + 1) + prev_col / 3 + 1 + PUZZLE_X, prev_row * (CELL_SIZE + 1) + prev_row / 3 + 1 + PUZZLE_Y, CELL_SIZE, CELL_SIZE);
+ gfx_SetColor(BLUE);
+ gfx_Rectangle_NoClip(selected_col * (CELL_SIZE + 1) + selected_col / 3 + 1 + PUZZLE_X, selected_row * (CELL_SIZE + 1) + selected_row / 3 + 1 + PUZZLE_Y, CELL_SIZE, CELL_SIZE);
+ if (!(puzzle[prev_row][prev_col] & VALUE)) {
+ draw_pencils(prev_row, prev_col);
+ }
+ puzzle_filled = draw_puzzle();
+
+ prev_row = selected_row;
+ prev_col = selected_col;
+
+ if (timer_IntStatus & TIMER1_RELOADED) {
+ timer_count++;
+ draw_timer(timer_count);
+ timer_IntAcknowledge = TIMER1_RELOADED;
+ }
+
+ if (puzzle_filled) {
+ win = win_check();
+ }
+
kb_Scan();
arrows = kb_Data[7];
@@ -91,12 +134,7 @@ void game_loop(void) {
}
}
- if (!prevkey) {
- counter = 0;
- }
- prevkey = arrows;
-
- if (numpad && (puzzle[selected_row][selected_col] & UNDEFINED)) {
+ if (numpad && (puzzle[selected_row][selected_col] & UNDEFINED) && !prevkey) {
switch (kb_Data[3]) {
case kb_0:
num = 0;
@@ -150,42 +188,49 @@ void game_loop(void) {
}
/*toggle pencil mode*/
- if (kb_Data[1] & kb_2nd) {
+ if (kb_Data[1] & kb_Graph && !prevkey) {
pencil_mode = !pencil_mode;
}
- if (pencil_mode) {
- gfx_Sprite_NoClip(pencil_selected, 283, 203);
- } else {
- gfx_Sprite_NoClip(pencil, 283, 203);
+ if (kb_Data[6] & kb_Clear && !prevkey) {
+ /* To avoid exploiting the timer by holding down [clear] */
+ gfx_FillScreen(WHITE);
+ gfx_BlitBuffer();
+ wait_for_key_release();
+ switch (basic_menu(pause_menu_title, pause_menu_options, 2)) {
+ case 0:
+ draw_grid();
+ break;
+ case 1:
+ reveal_solution();
+ quit = true;
+ break;
+ case 2:
+ quit = true;
+ break;
+ }
}
- gfx_SetColor(WHITE);
- gfx_FillRectangle_NoClip(prev_col * (CELL_SIZE + 1) + prev_col / 3 + 1 + PUZZLE_X, prev_row * (CELL_SIZE + 1) + prev_row / 3 + 1 + PUZZLE_Y, CELL_SIZE, CELL_SIZE);
- gfx_SetColor(BLUE);
- gfx_Rectangle_NoClip(selected_col * (CELL_SIZE + 1) + selected_col / 3 + 1 + PUZZLE_X, selected_row * (CELL_SIZE + 1) + selected_row / 3 + 1 + PUZZLE_Y, CELL_SIZE, CELL_SIZE);
- if (!(puzzle[prev_row][prev_col] & VALUE)) {
- draw_pencils(prev_row, prev_col);
- }
- puzzle_filled = draw_puzzle();
-
- if (puzzle_filled) {
- win = win_check();
+ if (!prevkey) {
+ counter = 0;
}
-
- gfx_BlitBuffer();
+ prevkey = arrows | numpad | kb_Data[1] & kb_Graph | kb_Data[6] & kb_Clear;
counter++;
- if (timer_IntStatus & TIMER1_RELOADED) {
- timer_count++;
- draw_timer(timer_count);
- timer_IntAcknowledge = TIMER1_RELOADED;
- }
-
- prev_row = selected_row;
- prev_col = selected_col;
- } while (!(kb_Data[6] & kb_Clear) && !win);
+ gfx_BlitBuffer();
+ } while (!quit && !win);
+ if (win) {
+ fontlib_SetForegroundColor(BLACK);
+ fontlib_SetCursorPosition(255, 101);
+ draw_string("You");
+ fontlib_SetCursorPosition(254, 119);
+ draw_string("Win!");
+ gfx_BlitBuffer();
+ wait_for_key_release();
+ wait_for_key_press();
+ wait_for_key_release();
+ }
}
bool win_check(void) {
@@ -244,15 +289,31 @@ bool win_check(void) {
void generate_puzzle(uint8_t difficulty) {
uint8_t i;
+ uint8_t j;
uint8_t row;
uint8_t col;
- solve_sudoku(solution);
+ solve_sudoku();
+
+ for (i = 0; i < 9; i++) {
+ for (j = 0; j < 9; j++) {
+ puzzle[i][j] <<= 4;
+ }
+ }
+
for (i = 0; i < difficulty; i++) {
do {
row = randInt(0,8);
col = randInt(0,8);
- } while (puzzle[row][col] != 0);
- puzzle[row][col] = solution[row][col];
+ } while ((puzzle[row][col] & VALUE) != 0);
+ puzzle[row][col] |= SOLUTION(puzzle[row][col]);
+ }
+
+ for (i = 0; i < 9; i++) {
+ for (j = 0; j < 9; j++) {
+ if ((puzzle[i][j] & VALUE) == 0) {
+ puzzle[i][j] |= UNDEFINED;
+ }
+ }
}
}
@@ -264,4 +325,20 @@ void setup_timer(void) {
timer_1_ReloadValue = timer_1_Counter = ONE_SECOND;
timer_Control = TIMER1_ENABLE | TIMER1_32K | TIMER1_0INT | TIMER1_DOWN;
+}
+
+void reveal_solution(void) {
+ uint8_t i;
+ uint8_t j;
+
+ for (i = 0; i < 9; i++) {
+ for (j = 0; j < 9; j++) {
+ puzzle[i][j] |= SOLUTION(puzzle[i][j] & SOLUTION_DATA);
+ }
+ }
+
+ draw_grid();
+ draw_puzzle();
+ wait_for_key_press();
+ wait_for_key_release();
}
\ No newline at end of file
diff --git a/src/game.h b/src/game.h
index 6968669..ad3830f 100644
--- a/src/game.h
+++ b/src/game.h
@@ -1,4 +1,5 @@
void game_loop(void);
bool win_check(void);
void generate_puzzle(uint8_t difficulty);
-void setup_timer(void);
\ No newline at end of file
+void setup_timer(void);
+void reveal_solution(void);
\ No newline at end of file
diff --git a/src/gfx/convimg.yaml b/src/gfx/convimg.yaml
index 5977a38..eb6dc03 100644
--- a/src/gfx/convimg.yaml
+++ b/src/gfx/convimg.yaml
@@ -6,10 +6,10 @@ output: c
- sprites
palette: sudoku_palette
- images: automatic
+ images:
+ - pencil_selected.png
convert: sprites
palette: sudoku_palette
images:
- pencil.png
- - pencil_selected.png
\ No newline at end of file
diff --git a/src/gfx/gfx.h b/src/gfx/gfx.h
index fc72669..eae0deb 100644
--- a/src/gfx/gfx.h
+++ b/src/gfx/gfx.h
@@ -7,7 +7,6 @@ extern "C" {
#include "sudoku_palette.h"
#include "pencil.h"
-#include "pencil_selected.h"
#ifdef __cplusplus
}
diff --git a/src/gfx/pencil_selected.c b/src/gfx/pencil_selected.c
deleted file mode 100644
index 11e897e..0000000
--- a/src/gfx/pencil_selected.c
+++ /dev/null
@@ -1,44 +0,0 @@
-unsigned char pencil_selected_data[1298] =
-{
- 0x24,0x24,0x02,0x02,0x02,0x02,0x02,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
- 0x01,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x02,0x02,0x02,0x02,0x02,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x02,0x02,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x02,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x01,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,
- 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x01,0x01,0x01,
- 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x01,0x01,0x00,
- 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00,
- 0x00,0x01,0x01,0x00,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,
- 0x01,0x01,0x01,0x01,0x00,0x01,0x01,0x00,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,
- 0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x01,0x01,0x00,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x01,0x01,0x01,0x01,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x01,0x01,0x00,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x01,0x01,0x01,0x01,0x00,0x00,0x01,0x01,0x00,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x00,0x01,0x01,0x01,0x01,0x00,0x01,0x01,0x00,0x00,0x00,0x01,0x01,0x00,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x01,0x01,0x01,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,
- 0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x01,0x01,0x00,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x00,0x01,0x01,0x01,0x01,0x01,0x01,
- 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
- 0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,
- 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
- 0x01,0x01,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x01,0x01,0x01,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x00,0x00,0x01,0x01,0x01,0x00,0x00,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,
- 0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x00,0x01,0x01,0x01,0x00,0x00,0x00,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x01,0x01,0x00,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x01,0x01,
- 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
- 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
- 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x01,0x01,
- 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x01,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x01,0x02,0x02,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x01,0x02,0x02,0x02,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x02,0x02,0x02,0x02,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
- 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x02,0x02,0x02,0x02,0x02
-};
diff --git a/src/gfx/pencil_selected.h b/src/gfx/pencil_selected.h
deleted file mode 100644
index 1d7123f..0000000
--- a/src/gfx/pencil_selected.h
+++ /dev/null
@@ -1,18 +0,0 @@
-#ifndef pencil_selected_include_file
-#define pencil_selected_include_file
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define pencil_selected_width 36
-#define pencil_selected_height 36
-#define pencil_selected_size 1298
-#define pencil_selected ((gfx_sprite_t*)pencil_selected_data)
-extern unsigned char pencil_selected_data[1298];
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/src/main.c b/src/main.c
index f384c50..28fdb1d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -33,69 +33,31 @@
/*
for each element of puzzle array:
bits 0-3: number
+bits 4-7: solution number (shown if the player gives up)
bits 14-22: contain pencil data
bit 23: set if undefined, cleared if immutable
*/
-/*uint24_t puzzle[9][9] = {
- {0,2,7,0,5,4,0,9,6},
+uint24_t puzzle[9][9] = {
+ {0,2,7,1,5,4,3,9,6},
{9,6,5,3,2,7,1,4,8},
{3,4,1,6,8,9,7,5,2},
- {5,0,3,4,0,8,2,0,1},
+ {5,9,3,4,6,8,2,7,1},
{4,7,2,5,1,3,6,8,9},
{6,1,8,9,7,2,4,3,5},
- {7,8,0,2,3,0,9,1,0},
+ {7,8,6,2,3,5,9,1,4},
{1,5,4,7,9,6,8,2,3},
{2,3,9,8,4,1,5,6,7}
-};*/
-
-uint24_t puzzle[9][9] = {
- {0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0}
-};
-
-uint8_t solution[9][9] = {
- {0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0}
};
+/*uint24_t puzzle[9][9] = {0};*/
void main(void) {
- uint8_t i;
- uint8_t j;
-
- int difficulty;
-
srandom(rtc_Time());
-
- difficulty = EASY;
- /*generate_puzzle(difficulty);
- for (i = 0; i < 9; i++) {
- for (j = 0; j < 9; j++) {
- if (puzzle[i][j] == 0) {
- puzzle[i][j] |= UNDEFINED;
- }
- }
- }*/
-
gfx_Begin();
gfx_SetPalette(sudoku_palette, sizeof_sudoku_palette, 0);
+ gfx_SetTransparentColor(WHITE);
fontlib_SetFont(calvetica, 0);
+ fontlib_SetTransparency(true);
gfx_SetDrawBuffer();
- /*game_loop();*/
- menu_loop();
+ main_menu();
gfx_End();
-}
-
+}
\ No newline at end of file
diff --git a/src/menu.c b/src/menu.c
index 96cc18a..d485ca1 100644
--- a/src/menu.c
+++ b/src/menu.c
@@ -21,24 +21,196 @@
#include "gfx/gfx.h"
#include "font/myfonts.h"
-uint8_t menu_loop(void) {
+uint8_t basic_menu(char title[], char *options[], uint8_t quit_option) {
uint8_t i;
uint8_t selected;
+ uint24_t center;
+ bool prevkey;
+
+ selected = 0;
+ prevkey = false;
+
+ do {
+ gfx_FillScreen(WHITE);
+ gfx_SetColor(BLACK);
+
+ fontlib_SetForegroundColor(BLACK);
+
+ center = center_cursor_x(title);
+
+ fontlib_SetCursorPosition(center, 10);
+ draw_string(title);
+
+ gfx_HorizLine_NoClip(center, 33, fontlib_GetStringWidth(title));
+
+ gfx_SetColor(BLUE);
+ center = center_cursor_x(options[selected]);
+ gfx_FillCircle_NoClip(center, selected * 30 + 50, 13);
+ gfx_FillRectangle_NoClip(center, selected * 30 + 37, fontlib_GetStringWidth(options[selected]), 27);
+ gfx_FillCircle_NoClip(center + fontlib_GetStringWidth(options[selected]), selected * 30 + 50, 13);
+
+ for (i = 0; i < quit_option + 1; i++) {
+ fontlib_SetCursorPosition(center_cursor_x(options[i]), i * 30 + 40);
+ if (i == selected) {
+ fontlib_SetForegroundColor(WHITE);
+ draw_string(options[i]);
+ } else {
+ fontlib_SetForegroundColor(BLACK);
+ draw_string(options[i]);
+ }
+ }
+
+ kb_Scan();
+
+ if (kb_Data[7] && !prevkey) {
+ switch (kb_Data[7]) {
+ case kb_Up:
+ selected--;
+ if (selected > quit_option + 1) {
+ selected = quit_option;
+ }
+ break;
+ case kb_Down:
+ selected++;
+ if (selected == quit_option + 1) {
+ selected = 0;
+ }
+ break;
+ default:
+ break;
+ }
+ }
+
+ if (kb_Data[6] & kb_Clear) {
+ selected = quit_option;
+ }
+
+ prevkey = kb_Data[7];
+
+ gfx_BlitBuffer();
+ } while (!(kb_Data[6] & kb_Clear || kb_Data[1] & kb_2nd));
+ while (kb_Data[6] & kb_Clear || kb_Data[1] & kb_2nd) {
+ kb_Scan();
+ }
+ return selected;
+}
+
+uint24_t center_cursor_x(char string[]) {
+ return 160 - fontlib_GetStringWidth(string) / 2;
+}
+
+void main_menu(void) {
+ uint8_t i;
+ uint8_t j;
+ char title[] = "Sudoku CE";
char *options[] = {
"Play",
"About",
"Quit"
};
+ char generate_message[] = "Generating Puzzle...";
+ uint8_t difficulty;
+ bool quit;
+ quit = false;
- selected = 0;
do {
- gfx_FillScreen(WHITE);
- for (i = 0; i < 3; i++) {
- fontlib_SetCursorPosition(2, i * 20 + 2);
- draw_string_special(options[i]);
+ switch (basic_menu(title, options, 2)) {
+ case 0:
+ difficulty = difficulty_select();
+ if (!difficulty) {
+ break;
+ } else {
+ gfx_FillScreen(WHITE);
+ fontlib_SetCursorPosition(center_cursor_x(generate_message), 10);
+ draw_string(generate_message);
+ gfx_BlitBuffer();
+ /* Reset puzzle to zeroes */
+ for (i = 0; i < 9; i++) {
+ for (j = 0; j < 9; j++) {
+ puzzle[i][j] = 0;
+ }
+ }
+ generate_puzzle(difficulty);
+ game_loop();
+ break;
+ }
+ game_loop();
+ break;
+ case 1:
+ about_screen();
+ break;
+ case 2:
+ quit = true;
+ break;
}
- gfx_BlitBuffer();
- } while (!os_GetCSC());
- return 0;
+ } while (!quit);
+}
+
+void about_screen(void) {
+ gfx_FillScreen(WHITE);
+ fontlib_SetForegroundColor(BLACK);
+ fontlib_SetCursorPosition(10, 10);
+ draw_string("Sudoku CE was made by");
+ fontlib_SetCursorPosition(10, 33);
+ draw_string("Jeffitus, with some help");
+ fontlib_SetCursorPosition(10, 56);
+ draw_string("from MateoConLechuga and");
+ fontlib_SetCursorPosition(10, 79);
+ /* sorry jacobly the 'j' looked too bad with the modified font */
+ draw_string("Jacobly.");
+ fontlib_SetCursorPosition(10, 102);
+ draw_string("Use the arrow keys and");
+ fontlib_SetCursorPosition(10, 125);
+ draw_string("numpad to fill in the grid,");
+ fontlib_SetCursorPosition(10, 148);
+ draw_string("[graph] to toggle pencil");
+ fontlib_SetCursorPosition(10, 171);
+ draw_string("mode, and [clear] to quit.");
+ fontlib_SetForegroundColor(BLUE);
+ fontlib_SetCursorPosition(10, 213);
+ draw_string("https://ceme.tech/t16261");
+ gfx_BlitBuffer();
+ wait_for_key_press();
+ wait_for_key_release();
+}
+
+uint8_t difficulty_select(void) {
+ char title[] = "Select a Difficulty";
+ char *options[] = {
+ "Easy",
+ "Medium",
+ "Hard",
+ "Very Hard",
+ "Back"
+ };
+
+ uint8_t difficulty;
+ difficulty = 0;
+
+ switch (basic_menu(title, options, 4)) {
+ case 0:
+ difficulty = EASY;
+ break;
+ case 1:
+ difficulty = MEDIUM;
+ break;
+ case 2:
+ difficulty = HARD;
+ break;
+ case 3:
+ difficulty = VERY_HARD;
+ break;
+ case 4:
+ difficulty = 0;
+ break;
+ }
+ return difficulty;
+}
+
+void wait_for_key_press(void) {
+ while (!kb_AnyKey());
}
+void wait_for_key_release(void) {
+ while (kb_AnyKey());
+}
\ No newline at end of file
diff --git a/src/menu.h b/src/menu.h
index b7e58b1..239708d 100644
--- a/src/menu.h
+++ b/src/menu.h
@@ -1 +1,7 @@
-uint8_t menu_loop(void);
+uint8_t basic_menu(char title[], char *options[], uint8_t quit_option);
+uint24_t center_cursor_x(char string[]);
+void main_menu(void);
+uint8_t difficulty_select(void);
+void about_screen(void);
+void wait_for_key_press(void);
+void wait_for_key_release(void);
\ No newline at end of file
diff --git a/src/solve.c b/src/solve.c
index 1cd554d..32db535 100644
--- a/src/solve.c
+++ b/src/solve.c
@@ -21,7 +21,6 @@
#include "gfx/gfx.h"
#include "font/myfonts.h"
-
void swap(uint8_t *a, uint8_t *b) {
uint8_t temp;
temp = *a;
@@ -39,7 +38,7 @@ void shuffle_array(uint8_t array[9]) {
}
-bool solve_sudoku(uint8_t grid[9][9]) {
+bool solve_sudoku(void) {
uint8_t row;
uint8_t col;
uint8_t i;
@@ -47,7 +46,7 @@ bool solve_sudoku(uint8_t grid[9][9]) {
uint8_t number_list[9] = {1,2,3,4,5,6,7,8,9};
row = 0;
col = 0;
- if (!find_unassigned_cell(grid, &row, &col)) {
+ if (!find_unassigned_cell(&row, &col)) {
return true;
}
@@ -55,25 +54,25 @@ bool solve_sudoku(uint8_t grid[9][9]) {
for (i = 0; i < 8; i++) {
num = number_list[i];
- if (valid_value(grid, row, col, num)) {
- grid[row][col] = num;
+ if (valid_value(row, col, num)) {
+ puzzle[row][col] = num;
- if (solve_sudoku(grid)) {
+ if (solve_sudoku()) {
return true;
}
- grid [row][col] = 0;
+ puzzle [row][col] = 0;
}
}
return false;
}
-bool find_unassigned_cell(uint8_t grid[9][9], uint8_t *p_row, uint8_t *p_col) {
+bool find_unassigned_cell(uint8_t *p_row, uint8_t *p_col) {
uint8_t row;
uint8_t col;
for (row = 0; row < 9; row++) {
for (col = 0; col < 9; col++) {
- if (grid[row][col] == 0) {
+ if (puzzle[row][col] == 0) {
*p_row = row;
*p_col = col;
return true;
@@ -83,32 +82,32 @@ bool find_unassigned_cell(uint8_t grid[9][9], uint8_t *p_row, uint8_t *p_col) {
return false;
}
-bool used_in_row(uint8_t grid[9][9], uint8_t row, uint8_t num) {
+bool used_in_row(uint8_t row, uint8_t num) {
uint8_t col;
for (col = 0; col < 9; col++) {
- if (grid[row][col] == num) {
+ if (puzzle[row][col] == num) {
return true;
}
}
return false;
}
-bool used_in_col(uint8_t grid[9][9], uint8_t col, uint8_t num) {
+bool used_in_col(uint8_t col, uint8_t num) {
uint8_t row;
for (row = 0; row < 9; row++) {
- if (grid[row][col] == num) {
+ if (puzzle[row][col] == num) {
return true;
}
}
return false;
}
-bool used_in_box(uint8_t grid[9][9], uint8_t start_row, uint8_t start_col, uint8_t num) {
+bool used_in_box(uint8_t start_row, uint8_t start_col, uint8_t num) {
uint8_t row;
uint8_t col;
for (row = 0; row < 3; row++) {
for (col = 0; col < 3; col++) {
- if (grid[row + start_row][col + start_col] == num) {
+ if (puzzle[row + start_row][col + start_col] == num) {
return true;
}
}
@@ -116,6 +115,6 @@ bool used_in_box(uint8_t grid[9][9], uint8_t start_row, uint8_t start_col, uint8
return false;
}
-bool valid_value(uint8_t grid [9][9], uint8_t row, uint8_t col, uint8_t num) {
- return !used_in_row(grid, row, num) && !used_in_col(grid, col, num) && !used_in_box(grid, row - row%3, col - col%3, num) && grid[row][col] == 0;
+bool valid_value(uint8_t row, uint8_t col, uint8_t num) {
+ return !used_in_row(row, num) && !used_in_col(col, num) && !used_in_box(row - row%3, col - col%3, num) && puzzle[row][col] == 0;
}
\ No newline at end of file
diff --git a/src/solve.h b/src/solve.h
index b11f9c9..1b35e58 100644
--- a/src/solve.h
+++ b/src/solve.h
@@ -1,7 +1,7 @@
void shuffle_array(uint8_t array[9]);
-bool solve_sudoku(uint8_t grid[9][9]);
-bool find_unassigned_cell(uint8_t grid[9][9], uint8_t *p_row, uint8_t *p_col);
-bool used_in_row(uint8_t grid[9][9], uint8_t row, uint8_t num);
-bool used_in_col(uint8_t grid[9][9], uint8_t col, uint8_t num);
-bool used_in_box(uint8_t grid[9][9], uint8_t start_row, uint8_t start_col, uint8_t num);
-bool valid_value(uint8_t grid[9][9], uint8_t row, uint8_t col, uint8_t num);
\ No newline at end of file
+bool solve_sudoku(void);
+bool find_unassigned_cell(uint8_t *p_row, uint8_t *p_col);
+bool used_in_row(uint8_t row, uint8_t num);
+bool used_in_col(uint8_t col, uint8_t num);
+bool used_in_box(uint8_t start_row, uint8_t start_col, uint8_t num);
+bool valid_value(uint8_t row, uint8_t col, uint8_t num);
\ No newline at end of file