summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2010-06-06 10:59:29 +0000
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2010-06-06 10:59:29 +0000
commit3ee3b28f8a57429e33fb2215199025bc31d9dfe1 (patch)
tree4c7b06c5cf5613c60fa281e42c3add3ff1444d9b
parentb2302e4e9b279a11abad118d2380d4eaa073af4c (diff)
downloadrockbox-3ee3b28f8a57429e33fb2215199025bc31d9dfe1.tar.gz
rockbox-3ee3b28f8a57429e33fb2215199025bc31d9dfe1.tar.bz2
rockbox-3ee3b28f8a57429e33fb2215199025bc31d9dfe1.zip
Save the scratchpad state in Sudoku plugin (FS#5737).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26622 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/plugins/sudoku/sudoku.c46
-rw-r--r--apps/plugins/sudoku/sudoku.h1
2 files changed, 38 insertions, 9 deletions
diff --git a/apps/plugins/sudoku/sudoku.c b/apps/plugins/sudoku/sudoku.c
index 02615caac1..f3d9b1e75f 100644
--- a/apps/plugins/sudoku/sudoku.c
+++ b/apps/plugins/sudoku/sudoku.c
@@ -302,6 +302,10 @@ static void save_state(struct sudoku_state_t *state)
{
rb->memcpy(state->savedboard, state->currentboard,
sizeof(state->savedboard));
+#ifdef SUDOKU_BUTTON_POSSIBLE
+ rb->memcpy(state->savedpossible, state->possiblevals,
+ sizeof(state->savedpossible));
+#endif
}
/* Copies the saved to the current board */
@@ -309,6 +313,10 @@ static void restore_state(struct sudoku_state_t *state)
{
rb->memcpy(state->currentboard, state->savedboard,
sizeof(state->savedboard));
+#ifdef SUDOKU_BUTTON_POSSIBLE
+ rb->memcpy(state->possiblevals, state->savedpossible,
+ sizeof(state->possiblevals));
+#endif
}
void default_state(struct sudoku_state_t* state)
@@ -420,10 +428,10 @@ bool load_sudoku(struct sudoku_state_t* state, char* filename)
{
int fd;
size_t n;
- int r = 0, c = 0;
+ int r = 0, c = 0, d = 0;
unsigned int i;
int valid=0;
- char buf[300]; /* A buffer to read a sudoku board from */
+ char buf[500]; /* A buffer to read a sudoku board from */
fd=rb->open(filename, O_RDONLY);
if (fd < 0) {
@@ -432,15 +440,15 @@ bool load_sudoku(struct sudoku_state_t* state, char* filename)
}
rb->strlcpy(state->filename,filename,MAX_PATH);
- n=rb->read(fd,buf,300);
+ n=rb->read(fd,buf,500);
if (n <= 0) {
return(false);
}
rb->close(fd);
-
r=0;
c=0;
i=0;
+ d=0;
while ((i < n) && (r < 9)) {
switch (buf[i]){
case ' ': case '\t':
@@ -458,6 +466,7 @@ bool load_sudoku(struct sudoku_state_t* state, char* filename)
valid=0;
}
c = 0;
+ d = 0;
break;
case '_': case '.':
valid=1;
@@ -485,6 +494,13 @@ bool load_sudoku(struct sudoku_state_t* state, char* filename)
}
c++;
}
+ if((buf[i]>='a' && buf[i] <= 'z') && i < (n-1)
+ && (buf[i+1] >= 'a' && buf[i+1] <= 'z')) {
+ state->possiblevals[r][d]
+ = (((buf[i]-'a') * 26 + buf[i+1]-'a')<<1);
+ i++;
+ d++;
+ }
/* Ignore any other characters */
break;
}
@@ -511,12 +527,15 @@ bool save_sudoku(struct sudoku_state_t* state)
int fd;
int r,c;
int i;
- char line[13];
- char sep[13];
+#ifdef SUDOKU_BUTTON_POSSIBLE
+ int x;
+ char line[41]="...|...|... ; \r\n";
+#else
+ char line[13]="...|...|...\r\n";
+#endif
+ char sep[13]="-----------\r\n";
rb->splash(0, "Saving...");
- rb->memcpy(line,"...|...|...\r\n",13);
- rb->memcpy(sep,"-----------\r\n",13);
if (state->filename[0]==0) {
return false;
@@ -539,6 +558,15 @@ bool save_sudoku(struct sudoku_state_t* state)
i++;
}
}
+#ifdef SUDOKU_BUTTON_POSSIBLE
+ i+=2;
+ for(c=0; c<9; c++) {
+ x = ((state->possiblevals[r][c]>>1)/26);
+ line[i++] = x + 'a';
+ x = ((state->possiblevals[r][c]>>1)%26);
+ line[i++] = x + 'a';
+ }
+#endif
rb->write(fd,line,sizeof(line));
if ((r==2) || (r==5)) {
rb->write(fd,sep,sizeof(sep));
@@ -570,7 +598,7 @@ void clear_board(struct sudoku_state_t* state)
state->y=0;
}
-void update_cell(struct sudoku_state_t* state, int r, int c)
+void update_cell(struct sudoku_state_t* state, int r, int c)
{
/* We have four types of cell:
1) User-entered number
diff --git a/apps/plugins/sudoku/sudoku.h b/apps/plugins/sudoku/sudoku.h
index 8974bd8768..f943a9f5fc 100644
--- a/apps/plugins/sudoku/sudoku.h
+++ b/apps/plugins/sudoku/sudoku.h
@@ -330,6 +330,7 @@ struct sudoku_state_t {
int editmode; /* We are editing the start board */
#ifdef SUDOKU_BUTTON_POSSIBLE
short possiblevals[9][9]; /* possible values a cell could be, user sets them */
+ short savedpossible[9][9]; /* cached copy of possible cell values */
#endif
};