summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2006-03-03 08:14:44 +0000
committerDaniel Stenberg <daniel@haxx.se>2006-03-03 08:14:44 +0000
commit220fafdd72eab05eb49cf6811d15d6618a168910 (patch)
treec90ef2fe3e9bb932197ac3ff5b305dd39a66204e
parente248eac20fc75566605aee705c130e0fa456aced (diff)
downloadrockbox-220fafdd72eab05eb49cf6811d15d6618a168910.tar.gz
rockbox-220fafdd72eab05eb49cf6811d15d6618a168910.zip
Code Police raid. Mostly changed // comments and indented to Rockbox style.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8894 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/plugins/fire.c2
-rw-r--r--apps/plugins/firmware_flash.c4
-rw-r--r--apps/plugins/grayscale.c4
-rw-r--r--apps/plugins/jpeg.c8
-rw-r--r--apps/plugins/mandelbrot.c12
-rw-r--r--apps/plugins/metronome.c4
-rw-r--r--apps/plugins/midi2wav.c12
-rw-r--r--apps/plugins/minesweeper.c6
-rw-r--r--apps/plugins/mp3_encoder.c134
-rw-r--r--apps/plugins/plasma.c2
-rw-r--r--apps/plugins/star.c12
-rw-r--r--apps/plugins/starfield.c4
-rw-r--r--apps/plugins/sudoku.c1389
-rw-r--r--apps/plugins/video.c495
-rw-r--r--apps/plugins/wav2wv.c2
15 files changed, 1068 insertions, 1022 deletions
diff --git a/apps/plugins/fire.c b/apps/plugins/fire.c
index 64c9fa9371..722f2bfc2e 100644
--- a/apps/plugins/fire.c
+++ b/apps/plugins/fire.c
@@ -404,4 +404,4 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
404 return ret; 404 return ret;
405} 405}
406 406
407#endif // #ifdef HAVE_LCD_BITMAP 407#endif /* #ifdef HAVE_LCD_BITMAP */
diff --git a/apps/plugins/firmware_flash.c b/apps/plugins/firmware_flash.c
index fa77a33697..1fc6b07a89 100644
--- a/apps/plugins/firmware_flash.c
+++ b/apps/plugins/firmware_flash.c
@@ -362,13 +362,13 @@ tCheckResult CheckFirmwareFile(char* filename, int chipsize, bool is_romless)
362 } 362 }
363 363
364 if (fileleft == 256*1024) 364 if (fileleft == 256*1024)
365 { // original dumped firmware file has no CRC nor platform ID 365 { /* original dumped firmware file has no CRC nor platform ID */
366 has_crc = false; 366 has_crc = false;
367 } 367 }
368 else 368 else
369 { 369 {
370 has_crc = true; 370 has_crc = true;
371 fileleft -= sizeof(unsigned); // exclude the last 4 bytes 371 fileleft -= sizeof(unsigned); /* exclude the last 4 bytes */
372 } 372 }
373 373
374 /* do some sanity checks */ 374 /* do some sanity checks */
diff --git a/apps/plugins/grayscale.c b/apps/plugins/grayscale.c
index 4ca2ba09b3..dfb48785cf 100644
--- a/apps/plugins/grayscale.c
+++ b/apps/plugins/grayscale.c
@@ -328,11 +328,11 @@ int main(void)
328 328
329enum plugin_status plugin_start(struct plugin_api* api, void* parameter) 329enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
330{ 330{
331 rb = api; // copy to global api pointer 331 rb = api; /* copy to global api pointer */
332 (void)parameter; 332 (void)parameter;
333 333
334 return main(); 334 return main();
335} 335}
336 336
337#endif // #ifdef HAVE_LCD_BITMAP 337#endif /* #ifdef HAVE_LCD_BITMAP */
338 338
diff --git a/apps/plugins/jpeg.c b/apps/plugins/jpeg.c
index a39e6dc933..62d6f1efe9 100644
--- a/apps/plugins/jpeg.c
+++ b/apps/plugins/jpeg.c
@@ -1235,7 +1235,7 @@ void build_lut(struct jpeg* p_jpeg)
1235 } 1235 }
1236 else 1236 else
1237 { 1237 {
1238 // error 1238 /* error */
1239 } 1239 }
1240 1240
1241} 1241}
@@ -1429,7 +1429,7 @@ int jpeg_decode(struct jpeg* p_jpeg, unsigned char* p_pixel[3],
1429 int k_need; /* AC coefficients needed up to here */ 1429 int k_need; /* AC coefficients needed up to here */
1430 int zero_need; /* init the block with this many zeros */ 1430 int zero_need; /* init the block with this many zeros */
1431 1431
1432 int last_dc_val[3] = {0, 0, 0}; // or 128 for chroma? 1432 int last_dc_val[3] = {0, 0, 0}; /* or 128 for chroma? */
1433 int store_offs[4]; /* memory offsets: order of Y11 Y12 Y21 Y22 U V */ 1433 int store_offs[4]; /* memory offsets: order of Y11 Y12 Y21 Y22 U V */
1434 int restart = p_jpeg->restart_interval; /* MCUs until restart marker */ 1434 int restart = p_jpeg->restart_interval; /* MCUs until restart marker */
1435 1435
@@ -1483,7 +1483,7 @@ int jpeg_decode(struct jpeg* p_jpeg, unsigned char* p_pixel[3],
1483 1483
1484 for(y=0; y<p_jpeg->y_mbl && bs.next_input_byte <= bs.input_end; y++) 1484 for(y=0; y<p_jpeg->y_mbl && bs.next_input_byte <= bs.input_end; y++)
1485 { 1485 {
1486 for (i=0; i<3; i++) // scan line init 1486 for (i=0; i<3; i++) /* scan line init */
1487 { 1487 {
1488 p_byte[i] = p_line[i]; 1488 p_byte[i] = p_line[i];
1489 p_line[i] += skip_strip[i]; 1489 p_line[i] += skip_strip[i];
@@ -1567,7 +1567,7 @@ int jpeg_decode(struct jpeg* p_jpeg, unsigned char* p_pixel[3],
1567 skip_line[ci]); 1567 skip_line[ci]);
1568 } 1568 }
1569 } /* for blkn */ 1569 } /* for blkn */
1570 p_byte[0] += skip_mcu[0]; // unrolled for (i=0; i<3; i++) loop 1570 p_byte[0] += skip_mcu[0]; /* unrolled for (i=0; i<3; i++) loop */
1571 p_byte[1] += skip_mcu[1]; 1571 p_byte[1] += skip_mcu[1];
1572 p_byte[2] += skip_mcu[2]; 1572 p_byte[2] += skip_mcu[2];
1573 if (p_jpeg->restart_interval && --restart == 0) 1573 if (p_jpeg->restart_interval && --restart == 0)
diff --git a/apps/plugins/mandelbrot.c b/apps/plugins/mandelbrot.c
index d4e399c057..6fe6b352e0 100644
--- a/apps/plugins/mandelbrot.c
+++ b/apps/plugins/mandelbrot.c
@@ -321,14 +321,14 @@ void recalc_parameters(void)
321void init_mandelbrot_set(void) 321void init_mandelbrot_set(void)
322{ 322{
323#if CONFIG_LCD == LCD_SSD1815 /* Recorder, Ondio. */ 323#if CONFIG_LCD == LCD_SSD1815 /* Recorder, Ondio. */
324 x_min = -38L<<22; // -2.375<<26 324 x_min = -38L<<22; /* -2.375<<26 */
325 x_max = 15L<<22; // 0.9375<<26 325 x_max = 15L<<22; /* 0.9375<<26 */
326#else /* all others (square pixels) */ 326#else /* all others (square pixels) */
327 x_min = -36L<<22; // -2.25<<26 327 x_min = -36L<<22; /* -2.25<<26 */
328 x_max = 12L<<22; // 0.75<<26 328 x_max = 12L<<22; /* 0.75<<26 */
329#endif 329#endif
330 y_min = -19L<<22; // -1.1875<<26 330 y_min = -19L<<22; /* -1.1875<<26 */
331 y_max = 19L<<22; // 1.1875<<26 331 y_max = 19L<<22; /* 1.1875<<26 */
332 recalc_parameters(); 332 recalc_parameters();
333} 333}
334 334
diff --git a/apps/plugins/metronome.c b/apps/plugins/metronome.c
index c7200300f3..8e185b58a9 100644
--- a/apps/plugins/metronome.c
+++ b/apps/plugins/metronome.c
@@ -746,7 +746,7 @@ void play_tock(void) {
746 746
747void calc_period(void) 747void calc_period(void)
748{ 748{
749 period = 61440/bpm-1; // (60*1024)/bpm; 749 period = 61440/bpm-1; /* (60*1024)/bpm; */
750} 750}
751 751
752 752
@@ -904,7 +904,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter){
904 rb = api; 904 rb = api;
905 905
906 if (MET_IS_PLAYING) 906 if (MET_IS_PLAYING)
907 MET_PLAY_STOP; // stop audio IS 907 MET_PLAY_STOP; /* stop audio IS */
908 908
909#if CONFIG_CODEC != SWCODEC 909#if CONFIG_CODEC != SWCODEC
910 rb->bitswap(sound, sizeof(sound)); 910 rb->bitswap(sound, sizeof(sound));
diff --git a/apps/plugins/midi2wav.c b/apps/plugins/midi2wav.c
index d0d46612b6..d4d5166fe0 100644
--- a/apps/plugins/midi2wav.c
+++ b/apps/plugins/midi2wav.c
@@ -23,7 +23,7 @@
23/* Only define LOCAL_DSP on Simulator or else we're asking for trouble */ 23/* Only define LOCAL_DSP on Simulator or else we're asking for trouble */
24#if defined(SIMULATOR) 24#if defined(SIMULATOR)
25 /*Enable this to write to the soundcard via a /dsv/dsp symlink in */ 25 /*Enable this to write to the soundcard via a /dsv/dsp symlink in */
26 //#define LOCAL_DSP 26 /*#define LOCAL_DSP */
27#endif 27#endif
28 28
29 29
@@ -39,7 +39,7 @@
39 39
40#include "../../plugin.h" 40#include "../../plugin.h"
41 41
42//#include "../codecs/lib/xxx2wav.h" 42/*#include "../codecs/lib/xxx2wav.h" */
43 43
44PLUGIN_HEADER 44PLUGIN_HEADER
45 45
@@ -200,14 +200,14 @@ int midimain(void * filename)
200 * why this happens. 200 * why this happens.
201 */ 201 */
202 202
203 outputBuffer[outputBufferPosition]=outputSampleOne&0XFF; // Low byte first 203 outputBuffer[outputBufferPosition]=outputSampleOne&0XFF; /* Low byte first */
204 outputBufferPosition++; 204 outputBufferPosition++;
205 outputBuffer[outputBufferPosition]=outputSampleOne>>8; //High byte second 205 outputBuffer[outputBufferPosition]=outputSampleOne>>8; /*High byte second */
206 outputBufferPosition++; 206 outputBufferPosition++;
207 207
208 outputBuffer[outputBufferPosition]=outputSampleTwo&0XFF; // Low byte first 208 outputBuffer[outputBufferPosition]=outputSampleTwo&0XFF; /* Low byte first */
209 outputBufferPosition++; 209 outputBufferPosition++;
210 outputBuffer[outputBufferPosition]=outputSampleTwo>>8; //High byte second 210 outputBuffer[outputBufferPosition]=outputSampleTwo>>8; /*High byte second */
211 outputBufferPosition++; 211 outputBufferPosition++;
212 212
213 213
diff --git a/apps/plugins/minesweeper.c b/apps/plugins/minesweeper.c
index c855f8a99d..23d6e07157 100644
--- a/apps/plugins/minesweeper.c
+++ b/apps/plugins/minesweeper.c
@@ -33,7 +33,7 @@ use F3 to see how many mines are left (supposing all your flags are correct)
33 33
34PLUGIN_HEADER 34PLUGIN_HEADER
35 35
36//what the minesweeper() function can return 36/*what the minesweeper() function can return */
37#define MINESWEEPER_USB 3 37#define MINESWEEPER_USB 3
38#define MINESWEEPER_QUIT 2 38#define MINESWEEPER_QUIT 2
39#define MINESWEEPER_LOSE 1 39#define MINESWEEPER_LOSE 1
@@ -402,10 +402,10 @@ int minesweeper(void)
402 402
403 while(true){ 403 while(true){
404 404
405 //clear the screen buffer 405 /*clear the screen buffer */
406 rb->lcd_clear_display(); 406 rb->lcd_clear_display();
407 407
408 //display the mine field 408 /*display the mine field */
409 for(i=0;i<height;i++){ 409 for(i=0;i<height;i++){
410 for(j=0;j<width;j++){ 410 for(j=0;j<width;j++){
411#if LCD_DEPTH > 1 411#if LCD_DEPTH > 1
diff --git a/apps/plugins/mp3_encoder.c b/apps/plugins/mp3_encoder.c
index f4f6b56f22..e5b7cc8f6e 100644
--- a/apps/plugins/mp3_encoder.c
+++ b/apps/plugins/mp3_encoder.c
@@ -1,15 +1,15 @@
1// Shine is an MP3 encoder 1/* Shine is an MP3 encoder
2// Copyright (C) 1999-2000 Gabriel Bouvigne 2 * Copyright (C) 1999-2000 Gabriel Bouvigne
3// 3 *
4// This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5// modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6// License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7// version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8// 8 *
9// This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12// Library General Public License for more details. 12 * Library General Public License for more details. */
13 13
14#define samp_per_frame 1152 14#define samp_per_frame 1152
15#define samp_per_frame2 576 15#define samp_per_frame2 576
@@ -112,55 +112,55 @@ struct huffcodetab {
112}; 112};
113 113
114/* !!!!!!!! start of IRAM area: do not insert before x_int1 array !!!!!!!!!!!!! */ 114/* !!!!!!!! start of IRAM area: do not insert before x_int1 array !!!!!!!!!!!!! */
115short x_int0 [HAN_SIZE] IBSS_ATTR; // 1024 Bytes 115short x_int0 [HAN_SIZE] IBSS_ATTR; /* 1024 Bytes */
116int mdct_freq [2][2][samp_per_frame2] IBSS_ATTR; // 9216 Bytes 116int mdct_freq [2][2][samp_per_frame2] IBSS_ATTR; /* 9216 Bytes */
117short x_int1 [HAN_SIZE] IBSS_ATTR; // 1024 Bytes 117short x_int1 [HAN_SIZE] IBSS_ATTR; /* 1024 Bytes */
118/* !!!!!!!!!!!!!!!!!!!!! here you may insert other data !!!!!!!!!!!!!!!!!!!!!!! */ 118/* !!!!!!!!!!!!!!!!!!!!! here you may insert other data !!!!!!!!!!!!!!!!!!!!!!! */
119uint8 int2idx [4096] IBSS_ATTR; // 4096 Bytes 119uint8 int2idx [4096] IBSS_ATTR; /* 4096 Bytes */
120enct8 enc_data [2][2][samp_per_frame2] IBSS_ATTR; // 4608 Bytes 120enct8 enc_data [2][2][samp_per_frame2] IBSS_ATTR; /* 4608 Bytes */
121short y_int [64] IBSS_ATTR; // 256 Bytes 121short y_int [64] IBSS_ATTR; /* 256 Bytes */
122int off [2] IBSS_ATTR; // 16 Bytes 122int off [2] IBSS_ATTR; /* 16 Bytes */
123int scalefac_long[23] IBSS_ATTR; // 96 Bytes 123int scalefac_long[23] IBSS_ATTR; /* 96 Bytes */
124int mdct_in [36] IBSS_ATTR; // 144 Bytes 124int mdct_in [36] IBSS_ATTR; /* 144 Bytes */
125int sb_sample [2][3][18][SBLIMIT] IBSS_ATTR; // 13824 Bytes 125int sb_sample [2][3][18][SBLIMIT] IBSS_ATTR; /* 13824 Bytes */
126BF_Data CodedData IBSS_ATTR; // 1040 Bytes 126BF_Data CodedData IBSS_ATTR; /* 1040 Bytes */
127int ca_int [8] IBSS_ATTR; // 32 Bytes 127int ca_int [8] IBSS_ATTR; /* 32 Bytes */
128int cs_int [8] IBSS_ATTR; // 32 Bytes 128int cs_int [8] IBSS_ATTR; /* 32 Bytes */
129int win_int [18][36] IBSS_ATTR; // 2592 Bytes 129int win_int [18][36] IBSS_ATTR; /* 2592 Bytes */
130short filter_int [SBLIMIT][64] IBSS_ATTR; // 8192 Bytes 130short filter_int [SBLIMIT][64] IBSS_ATTR; /* 8192 Bytes */
131short enwindow_int[512] IBSS_ATTR; // 1024 Bytes 131short enwindow_int[512] IBSS_ATTR; /* 1024 Bytes */
132uint8 ht_count1 [2][2][16] IBSS_ATTR; // 64 Bytes 132uint8 ht_count1 [2][2][16] IBSS_ATTR; /* 64 Bytes */
133uint16 t1HB [ 4] IBSS_ATTR; // Bytes 133uint16 t1HB [ 4] IBSS_ATTR; /* Bytes */
134uint16 t2HB [ 9] IBSS_ATTR; // Bytes 134uint16 t2HB [ 9] IBSS_ATTR; /* Bytes */
135uint16 t3HB [ 9] IBSS_ATTR; // Bytes 135uint16 t3HB [ 9] IBSS_ATTR; /* Bytes */
136uint16 t5HB [ 16] IBSS_ATTR; // Bytes 136uint16 t5HB [ 16] IBSS_ATTR; /* Bytes */
137uint16 t6HB [ 16] IBSS_ATTR; // Bytes 137uint16 t6HB [ 16] IBSS_ATTR; /* Bytes */
138uint16 t7HB [ 36] IBSS_ATTR; // Bytes 138uint16 t7HB [ 36] IBSS_ATTR; /* Bytes */
139uint16 t8HB [ 36] IBSS_ATTR; // Bytes 139uint16 t8HB [ 36] IBSS_ATTR; /* Bytes */
140uint16 t9HB [ 36] IBSS_ATTR; // Bytes 140uint16 t9HB [ 36] IBSS_ATTR; /* Bytes */
141uint16 t10HB [ 64] IBSS_ATTR; // Bytes 141uint16 t10HB [ 64] IBSS_ATTR; /* Bytes */
142uint16 t11HB [ 64] IBSS_ATTR; // Bytes 142uint16 t11HB [ 64] IBSS_ATTR; /* Bytes */
143uint16 t12HB [ 64] IBSS_ATTR; // Bytes 143uint16 t12HB [ 64] IBSS_ATTR; /* Bytes */
144uint16 t13HB [256] IBSS_ATTR; // Bytes 144uint16 t13HB [256] IBSS_ATTR; /* Bytes */
145uint16 t15HB [256] IBSS_ATTR; // Bytes 145uint16 t15HB [256] IBSS_ATTR; /* Bytes */
146uint16 t16HB [256] IBSS_ATTR; // Bytes 146uint16 t16HB [256] IBSS_ATTR; /* Bytes */
147uint16 t24HB [256] IBSS_ATTR; // Bytes 147uint16 t24HB [256] IBSS_ATTR; /* Bytes */
148uint8 t1l [ 4] IBSS_ATTR; // Bytes 148uint8 t1l [ 4] IBSS_ATTR; /* Bytes */
149uint8 t2l [ 9] IBSS_ATTR; // Bytes 149uint8 t2l [ 9] IBSS_ATTR; /* Bytes */
150uint8 t3l [ 9] IBSS_ATTR; // Bytes 150uint8 t3l [ 9] IBSS_ATTR; /* Bytes */
151uint8 t5l [ 16] IBSS_ATTR; // Bytes 151uint8 t5l [ 16] IBSS_ATTR; /* Bytes */
152uint8 t6l [ 16] IBSS_ATTR; // Bytes 152uint8 t6l [ 16] IBSS_ATTR; /* Bytes */
153uint8 t7l [ 36] IBSS_ATTR; // Bytes 153uint8 t7l [ 36] IBSS_ATTR; /* Bytes */
154uint8 t8l [ 36] IBSS_ATTR; // Bytes 154uint8 t8l [ 36] IBSS_ATTR; /* Bytes */
155uint8 t9l [ 36] IBSS_ATTR; // Bytes 155uint8 t9l [ 36] IBSS_ATTR; /* Bytes */
156uint8 t10l [ 64] IBSS_ATTR; // Bytes 156uint8 t10l [ 64] IBSS_ATTR; /* Bytes */
157uint8 t11l [ 64] IBSS_ATTR; // Bytes 157uint8 t11l [ 64] IBSS_ATTR; /* Bytes */
158uint8 t12l [ 64] IBSS_ATTR; // Bytes 158uint8 t12l [ 64] IBSS_ATTR; /* Bytes */
159uint8 t13l [256] IBSS_ATTR; // Bytes 159uint8 t13l [256] IBSS_ATTR; /* Bytes */
160uint8 t15l [256] IBSS_ATTR; // Bytes 160uint8 t15l [256] IBSS_ATTR; /* Bytes */
161uint8 t16l [256] IBSS_ATTR; // Bytes 161uint8 t16l [256] IBSS_ATTR; /* Bytes */
162uint8 t24l [256] IBSS_ATTR; // Bytes 162uint8 t24l [256] IBSS_ATTR; /* Bytes */
163struct huffcodetab ht [HTN] IBSS_ATTR; // Bytes 163struct huffcodetab ht [HTN] IBSS_ATTR; /* Bytes */
164 164
165static const uint8 ht_count1_const[2][2][16] = 165static const uint8 ht_count1_const[2][2][16] =
166{ { { 1, 5, 4, 5, 6, 5, 4, 4, 7, 3, 6, 0, 7, 2, 3, 1 }, /* table0 */ 166{ { { 1, 5, 4, 5, 6, 5, 4, 4, 7, 3, 6, 0, 7, 2, 3, 1 }, /* table0 */
@@ -240,7 +240,7 @@ const struct huffcodetab ht_const[HTN] =
240{ 2, 2, 0, 0, t1HB, t1l}, 240{ 2, 2, 0, 0, t1HB, t1l},
241{ 3, 3, 0, 0, t2HB, t2l}, 241{ 3, 3, 0, 0, t2HB, t2l},
242{ 3, 3, 0, 0, t3HB, t3l}, 242{ 3, 3, 0, 0, t3HB, t3l},
243{ 0, 0, 0, 0, NULL, NULL},// Apparently not used 243{ 0, 0, 0, 0, NULL, NULL},/* Apparently not used */
244{ 4, 4, 0, 0, t5HB, t5l}, 244{ 4, 4, 0, 0, t5HB, t5l},
245{ 4, 4, 0, 0, t6HB, t6l}, 245{ 4, 4, 0, 0, t6HB, t6l},
246{ 6, 6, 0, 0, t7HB, t7l}, 246{ 6, 6, 0, 0, t7HB, t7l},
@@ -250,7 +250,7 @@ const struct huffcodetab ht_const[HTN] =
250{ 8, 8, 0, 0,t11HB, t11l}, 250{ 8, 8, 0, 0,t11HB, t11l},
251{ 8, 8, 0, 0,t12HB, t12l}, 251{ 8, 8, 0, 0,t12HB, t12l},
252{16,16, 0, 0,t13HB, t13l}, 252{16,16, 0, 0,t13HB, t13l},
253{ 0, 0, 0, 0, NULL, NULL},// Apparently not used 253{ 0, 0, 0, 0, NULL, NULL},/* Apparently not used */
254{16,16, 0, 0,t15HB, t15l}, 254{16,16, 0, 0,t15HB, t15l},
255{16,16, 1, 1,t16HB, t16l}, 255{16,16, 1, 1,t16HB, t16l},
256{16,16, 2, 3,t16HB, t16l}, 256{16,16, 2, 3,t16HB, t16l},
@@ -1025,7 +1025,7 @@ int count_bit(enct8 ix[samp_per_frame2], unsigned int start, unsigned int end, u
1025 ylen = h->ylen; 1025 ylen = h->ylen;
1026 1026
1027 if(table > 15) 1027 if(table > 15)
1028 { // ESC-table is used 1028 { /* ESC-table is used */
1029 linbits = h->linbits; 1029 linbits = h->linbits;
1030 for(i=start; i<end; i+=2) 1030 for(i=start; i<end; i+=2)
1031 { 1031 {
@@ -1532,7 +1532,7 @@ void filter_subband(short *buffer, int s[SBLIMIT], int k)
1532#endif 1532#endif
1533 1533
1534 /* 147456=72*2048 */ 1534 /* 147456=72*2048 */
1535 for(i=SBLIMIT; i--; ) // SBLIMIT: 32 1535 for(i=SBLIMIT; i--; ) /* SBLIMIT: 32 */
1536 { 1536 {
1537 short *filt = filter_int[i]; 1537 short *filt = filter_int[i];
1538 1538
@@ -1691,11 +1691,11 @@ void compress(void)
1691 memcpy(ht , ht_const , sizeof(ht )); 1691 memcpy(ht , ht_const , sizeof(ht ));
1692 1692
1693 /* I don't know, wether this is really necessary */ 1693 /* I don't know, wether this is really necessary */
1694 ht[ 0].table = NULL; ht[ 0].hlen = NULL;// Apparently not used 1694 ht[ 0].table = NULL; ht[ 0].hlen = NULL;/* Apparently not used */
1695 ht[ 1].table = t1HB; ht[ 1].hlen = t1l; 1695 ht[ 1].table = t1HB; ht[ 1].hlen = t1l;
1696 ht[ 2].table = t2HB; ht[ 2].hlen = t2l; 1696 ht[ 2].table = t2HB; ht[ 2].hlen = t2l;
1697 ht[ 3].table = t3HB; ht[ 3].hlen = t3l; 1697 ht[ 3].table = t3HB; ht[ 3].hlen = t3l;
1698 ht[ 4].table = NULL; ht[ 4].hlen = NULL;// Apparently not used 1698 ht[ 4].table = NULL; ht[ 4].hlen = NULL;/* Apparently not used */
1699 ht[ 5].table = t5HB; ht[ 5].hlen = t5l; 1699 ht[ 5].table = t5HB; ht[ 5].hlen = t5l;
1700 ht[ 6].table = t6HB; ht[ 6].hlen = t6l; 1700 ht[ 6].table = t6HB; ht[ 6].hlen = t6l;
1701 ht[ 7].table = t7HB; ht[ 7].hlen = t7l; 1701 ht[ 7].table = t7HB; ht[ 7].hlen = t7l;
@@ -1705,7 +1705,7 @@ void compress(void)
1705 ht[11].table = t11HB; ht[11].hlen = t11l; 1705 ht[11].table = t11HB; ht[11].hlen = t11l;
1706 ht[12].table = t12HB; ht[12].hlen = t12l; 1706 ht[12].table = t12HB; ht[12].hlen = t12l;
1707 ht[13].table = t13HB; ht[13].hlen = t13l; 1707 ht[13].table = t13HB; ht[13].hlen = t13l;
1708 ht[14].table = NULL; ht[14].hlen = NULL;// Apparently not used 1708 ht[14].table = NULL; ht[14].hlen = NULL;/* Apparently not used */
1709 ht[15].table = t15HB; ht[15].hlen = t15l; 1709 ht[15].table = t15HB; ht[15].hlen = t15l;
1710 ht[16].table = t16HB; ht[16].hlen = t16l; 1710 ht[16].table = t16HB; ht[16].hlen = t16l;
1711 ht[17].table = t16HB; ht[17].hlen = t16l; 1711 ht[17].table = t16HB; ht[17].hlen = t16l;
diff --git a/apps/plugins/plasma.c b/apps/plugins/plasma.c
index 934def4434..c6e76a965b 100644
--- a/apps/plugins/plasma.c
+++ b/apps/plugins/plasma.c
@@ -326,7 +326,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
326{ 326{
327 int ret; 327 int ret;
328 328
329 rb = api; // copy to global api pointer 329 rb = api; /* copy to global api pointer */
330 (void)parameter; 330 (void)parameter;
331 if (rb->global_settings->backlight_timeout > 0) 331 if (rb->global_settings->backlight_timeout > 0)
332 rb->backlight_set_timeout(1);/* keep the light on */ 332 rb->backlight_set_timeout(1);/* keep the light on */
diff --git a/apps/plugins/star.c b/apps/plugins/star.c
index 5b100707d0..f5f281bf13 100644
--- a/apps/plugins/star.c
+++ b/apps/plugins/star.c
@@ -448,19 +448,19 @@ static void star_display_text(char *str, bool waitkey)
448 448
449 line[chars_for_line] = '\0'; 449 line[chars_for_line] = '\0';
450 450
451 // test if we have cutted a word. If it is the case we don't have to 451 /* test if we have cutted a word. If it is the case we don't have to */
452 // skip the space 452 /* skip the space */
453 if (i == chars_by_line && chars_for_line == chars_by_line) 453 if (i == chars_by_line && chars_for_line == chars_by_line)
454 first_char_index += chars_for_line; 454 first_char_index += chars_for_line;
455 else 455 else
456 first_char_index += chars_for_line + 1; 456 first_char_index += chars_for_line + 1;
457 457
458 // print the line on the screen 458 /* print the line on the screen */
459 rb->lcd_putsxy(0, current_line * char_height, line); 459 rb->lcd_putsxy(0, current_line * char_height, line);
460 460
461 // if the number of line showed on the screen is equals to the 461 /* if the number of line showed on the screen is equals to the */
462 // maximum number of line we can show, we wait for a key pressed to 462 /* maximum number of line we can show, we wait for a key pressed to */
463 // clear and show the remaining text. 463 /* clear and show the remaining text. */
464 current_line++; 464 current_line++;
465 if (current_line == lines_by_screen || *ptr_char == '\0') 465 if (current_line == lines_by_screen || *ptr_char == '\0')
466 { 466 {
diff --git a/apps/plugins/starfield.c b/apps/plugins/starfield.c
index 032b6acf7c..388d59bb9d 100644
--- a/apps/plugins/starfield.c
+++ b/apps/plugins/starfield.c
@@ -267,7 +267,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
267{ 267{
268 int ret; 268 int ret;
269 269
270 rb = api; // copy to global api pointer 270 rb = api; /* copy to global api pointer */
271 (void)parameter; 271 (void)parameter;
272 if (rb->global_settings->backlight_timeout > 0) 272 if (rb->global_settings->backlight_timeout > 0)
273 rb->backlight_set_timeout(1);/* keep the light on */ 273 rb->backlight_set_timeout(1);/* keep the light on */
@@ -277,4 +277,4 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
277 return ret; 277 return ret;
278} 278}
279 279
280#endif // #ifdef HAVE_LCD_BITMAP 280#endif /* #ifdef HAVE_LCD_BITMAP */
diff --git a/apps/plugins/sudoku.c b/apps/plugins/sudoku.c
index 4db3fd6950..ece0fbb564 100644
--- a/apps/plugins/sudoku.c
+++ b/apps/plugins/sudoku.c
@@ -240,19 +240,19 @@ typedef unsigned int Bitset;
240#define false 0 240#define false 0
241 241
242typedef struct _Sudoku { 242typedef struct _Sudoku {
243 Bitset table[SIZE][SIZE]; 243 Bitset table[SIZE][SIZE];
244}Sudoku; 244}Sudoku;
245 245
246typedef struct _Stats { 246typedef struct _Stats {
247 int numTries; 247 int numTries;
248 int backTracks; 248 int backTracks;
249 int numEmpty; 249 int numEmpty;
250 bool solutionFound; 250 bool solutionFound;
251}Stats; 251}Stats;
252 252
253typedef struct _Options { 253typedef struct _Options {
254 bool allSolutions; 254 bool allSolutions;
255 bool uniquenessCheck; 255 bool uniquenessCheck;
256}Options; 256}Options;
257 257
258void sudoku_init(Sudoku* sud); 258void sudoku_init(Sudoku* sud);
@@ -268,589 +268,635 @@ int sudoku_get(Sudoku* sud, int x, int y, bool* original);
268#define ALL_BITS (BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5) | BIT(6) | BIT(7) | BIT(8) | BIT(9)) 268#define ALL_BITS (BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5) | BIT(6) | BIT(7) | BIT(8) | BIT(9))
269 269
270/* initialize a sudoku problem, should be called before using set or get */ 270/* initialize a sudoku problem, should be called before using set or get */
271void sudoku_init(Sudoku* sud){ 271void sudoku_init(Sudoku* sud)
272 int y, x; 272{
273 for (y = 0; y < SIZE; y++){ 273 int y, x;
274 for (x = 0; x < SIZE; x++){ 274 for (y = 0; y < SIZE; y++){
275 sud->table[x][y] = ALL_BITS; 275 for (x = 0; x < SIZE; x++){
276 sud->table[x][y] = ALL_BITS;
277 }
276 } 278 }
277 }
278} 279}
279 280
280/* set the number at a particular x and y column */ 281/* set the number at a particular x and y column */
281void sudoku_set(Sudoku* sud, int x, int y, int num, bool original){ 282void sudoku_set(Sudoku* sud, int x, int y, int num, bool original)
282 int i, j; 283{
283 int bx, by; 284 int i, j;
284 Bitset orig; 285 int bx, by;
285 286 Bitset orig;
286 // clear the row and columns 287
287 for (i = 0; i < SIZE; i++){ 288 /* clear the row and columns */
288 BIT_CLEAR(sud->table[i][y], num); 289 for (i = 0; i < SIZE; i++){
289 BIT_CLEAR(sud->table[x][i], num); 290 BIT_CLEAR(sud->table[i][y], num);
290 } 291 BIT_CLEAR(sud->table[x][i], num);
291 // clear the block
292 bx = x - (x % BLOCK);
293 by = y - (y % BLOCK);
294 for (i = 0; i < BLOCK; i++){
295 for (j = 0; j < BLOCK; j++){
296 BIT_CLEAR(sud->table[bx+j][by+i], num);
297 } 292 }
298 } 293 /* clear the block */
299 // mark the table 294 bx = x - (x % BLOCK);
300 orig = original ? ORIGINAL_BIT : 0; 295 by = y - (y % BLOCK);
301 sud->table[x][y] = BIT(num) | MARK_BIT | orig; 296 for (i = 0; i < BLOCK; i++){
297 for (j = 0; j < BLOCK; j++){
298 BIT_CLEAR(sud->table[bx+j][by+i], num);
299 }
300 }
301 /* mark the table */
302 orig = original ? ORIGINAL_BIT : 0;
303 sud->table[x][y] = BIT(num) | MARK_BIT | orig;
302} 304}
303 305
304/* get the number at a particular x and y column, if this 306/* get the number at a particular x and y column, if this
305 is not unique return 0 */ 307 is not unique return 0 */
306int sudoku_get(Sudoku* sud, int x, int y, bool* original){ 308int sudoku_get(Sudoku* sud, int x, int y, bool* original)
307 Bitset val = sud->table[x][y]; 309{
308 int result = 0; 310 Bitset val = sud->table[x][y];
309 int i; 311 int result = 0;
310 312 int i;
311 if (original){ 313
312 *original = val & ORIGINAL_BIT; 314 if (original) {
313 } 315 *original = val & ORIGINAL_BIT;
314 for (i = 1; i <= SIZE; i++){
315 if (BIT_TEST(val, i)){
316 if (result != 0){
317 return 0;
318 }
319 result = i;
320 } 316 }
321 } 317 for (i = 1; i <= SIZE; i++){
322 return result; 318 if (BIT_TEST(val, i)){
319 if (result != 0){
320 return 0;
321 }
322 result = i;
323 }
324 }
325 return result;
323} 326}
324 327
325/* returns true if this is a valid problem, this is necessary because the input 328/* returns true if this is a valid problem, this is necessary because the input
326 problem might be degenerate which breaks the solver algorithm. */ 329 problem might be degenerate which breaks the solver algorithm. */
327static bool is_valid(const Sudoku* sud){ 330static bool is_valid(const Sudoku* sud)
328 int x, y; 331{
329 332 int x, y;
330 for (y = 0; y < SIZE; y++){ 333
331 for (x = 0; x < SIZE; x++){ 334 for (y = 0; y < SIZE; y++){
332 if ((sud->table[x][y] & ALL_BITS) == 0){ 335 for (x = 0; x < SIZE; x++){
333 return false; 336 if ((sud->table[x][y] & ALL_BITS) == 0){
334 } 337 return false;
338 }
339 }
335 } 340 }
336 } 341 return true;
337 return true;
338} 342}
339 343
340/* scan the table for the most constrained item, giving all it's options, 344/* scan the table for the most constrained item, giving all it's options, sets
341 sets the best x and y coordinates, the number of options and the options for that coordinate and 345 the best x and y coordinates, the number of options and the options for
342 returns true if the puzzle is finished */ 346 that coordinate and returns true if the puzzle is finished */
343static bool scan(const Sudoku* sud, int* rX, int* rY, int *num, int* options){ 347static bool scan(const Sudoku* sud, int* rX, int* rY, int *num, int* options)
344 int x, y, i, j; 348{
345 int bestCount = SIZE+1; 349 int x, y, i, j;
346 Bitset val; 350 int bestCount = SIZE+1;
347 bool allMarked = true; 351 Bitset val;
348 352 bool allMarked = true;
349 for (y = 0; y < SIZE; y++){ 353
350 for (x = 0; x < SIZE; x++){ 354 for (y = 0; y < SIZE; y++){
351 Bitset val = sud->table[x][y]; 355 for (x = 0; x < SIZE; x++){
352 int i; 356 Bitset val = sud->table[x][y];
353 int count = 0; 357 int i;
354 358 int count = 0;
355 if (val & MARK_BIT){ 359
356 // already set 360 if (val & MARK_BIT) {
357 continue; 361 /* already set */
358 } 362 continue;
359 allMarked = false; 363 }
360 for (i = 1; i <= SIZE; i++){ 364 allMarked = false;
361 if (BIT_TEST(val, i)){ 365 for (i = 1; i <= SIZE; i++){
362 count++; 366 if (BIT_TEST(val, i)){
363 } 367 count++;
364 } 368 }
365 if (count < bestCount){ 369 }
366 bestCount = count; 370 if (count < bestCount){
367 *rX = x; 371 bestCount = count;
368 *rY = y; 372 *rX = x;
369 if (count == 0){ 373 *rY = y;
370 // can't possibly be beaten 374 if (count == 0){
371 *num = 0; 375 /* can't possibly be beaten */
372 return false; 376 *num = 0;
377 return false;
378 }
379 }
373 } 380 }
374 }
375 } 381 }
376 } 382 /* now copy into options */
377 // now copy into options 383 *num = bestCount;
378 *num = bestCount; 384 val = sud->table[*rX][*rY];
379 val = sud->table[*rX][*rY]; 385 for (i = 1, j = 0; i <= SIZE; i++){
380 for (i = 1, j = 0; i <= SIZE; i++){ 386 if (BIT_TEST(val, i)){
381 if (BIT_TEST(val, i)){ 387 options[j++] = i;
382 options[j++] = i; 388 }
383 } 389 }
384 } 390 return allMarked;
385 return allMarked;
386} 391}
387 392
388static bool solve(Sudoku* sud, Stats* stats, const Options* options); 393static bool solve(Sudoku* sud, Stats* stats, const Options* options);
389 394
390/* try a particular option and return true if that gives a solution 395/* try a particular option and return true if that gives a solution or false
391 or false if it doesn't, restores board on backtracking */ 396 if it doesn't, restores board on backtracking */
392static bool spawn_option(Sudoku* sud, Stats* stats, const Options* options, int x, int y, int num){ 397static bool spawn_option(Sudoku* sud, Stats* stats, const Options* options,
393 Sudoku copy; 398 int x, int y, int num)
394 399{
395 rb->memcpy(&copy,sud,sizeof(Sudoku)); 400 Sudoku copy;
396 sudoku_set(&copy, x, y, num, false);
397 stats->numTries += 1;
398 if (solve(&copy, stats, options)){
399 if (!options->allSolutions && stats->solutionFound){
400 rb->memcpy(sud,&copy,sizeof(Sudoku));
401 }
402 return true;
403 }else{
404 stats->backTracks++;
405 }
406 return false;
407}
408 401
409/* solve a sudoku problem, returns true if there is a solution and false otherwise. 402 rb->memcpy(&copy,sud,sizeof(Sudoku));
410 stats is used to track statisticss */ 403 sudoku_set(&copy, x, y, num, false);
411static bool solve(Sudoku* sud, Stats* stats, const Options* options){ 404 stats->numTries += 1;
412 while (true){ 405 if (solve(&copy, stats, options)){
413 int x, y, i, num; 406 if (!options->allSolutions && stats->solutionFound){
414 int places[SIZE]; 407 rb->memcpy(sud,&copy,sizeof(Sudoku));
415 408 }
416 if (scan(sud, &x, &y, &num, places)){
417 // a solution was found!
418 if (options->uniquenessCheck && stats->solutionFound){
419 //printf("\n\t... But the solution is not unique!\n");
420 return true;
421 }
422 stats->solutionFound = true;
423 if (options->allSolutions || options->uniquenessCheck){
424 //printf("\n\tSolution after %d iterations\n", stats->numTries);
425 //sudoku_print(sud);
426 return false;
427 }else{
428 return true; 409 return true;
429 } 410 }else{
411 stats->backTracks++;
430 } 412 }
431 if (num == 0){ 413 return false;
432 // can't be satisfied 414}
433 return false; 415
434 } 416/* solve a sudoku problem, returns true if there is a solution and false
435 // try all the places (except the last one) 417 otherwise. stats is used to track statisticss */
436 for (i = 0; i < num-1; i++){ 418static bool solve(Sudoku* sud, Stats* stats, const Options* options)
437 if (spawn_option(sud, stats, options, x, y, places[i])){ 419{
438 // solution found! 420 while (true){
439 if (!options->allSolutions && stats->solutionFound){ 421 int x, y, i, num;
440 return true; 422 int places[SIZE];
423
424 if (scan(sud, &x, &y, &num, places)){
425 /* a solution was found! */
426 if (options->uniquenessCheck && stats->solutionFound){
427 /*printf("\n\t... But the solution is not unique!\n"); */
428 return true;
429 }
430 stats->solutionFound = true;
431 if (options->allSolutions || options->uniquenessCheck){
432 /*printf("\n\tSolution after %d iterations\n", stats->numTries); */
433 /*sudoku_print(sud); */
434 return false;
435 }
436 else{
437 return true;
438 }
441 } 439 }
442 } 440 if (num == 0){
441 /* can't be satisfied */
442 return false;
443 }
444 /* try all the places (except the last one) */
445 for (i = 0; i < num-1; i++){
446 if (spawn_option(sud, stats, options, x, y, places[i])){
447 /* solution found! */
448 if (!options->allSolutions && stats->solutionFound){
449 return true;
450 }
451 }
452 }
453 /* take the last place ourself */
454 stats->numTries += 1;
455 sudoku_set(sud, x, y, places[num-1], false);
443 } 456 }
444 // take the last place ourself
445 stats->numTries += 1;
446 sudoku_set(sud, x, y, places[num-1], false);
447 }
448} 457}
449 458
450/******** END OF IMPORTED CODE */ 459/******** END OF IMPORTED CODE */
451 460
452 461
453/* A wrapper function between the Sudoku plugin and the above solver code */ 462/* A wrapper function between the Sudoku plugin and the above solver code */
454void sudoku_solve(struct sudoku_state_t* state) { 463void sudoku_solve(struct sudoku_state_t* state)
455 bool ret; 464{
456 Stats stats; 465 bool ret;
457 Options options; 466 Stats stats;
458 Sudoku sud; 467 Options options;
459 bool original; 468 Sudoku sud;
460 int r,c; 469 bool original;
461 470 int r,c;
462 /* Initialise the parameters */ 471
463 sudoku_init(&sud); 472 /* Initialise the parameters */
464 rb->memset(&stats,0,sizeof(stats)); 473 sudoku_init(&sud);
465 options.allSolutions=false; 474 rb->memset(&stats,0,sizeof(stats));
466 options.uniquenessCheck=false; 475 options.allSolutions=false;
467 476 options.uniquenessCheck=false;
468 /* Convert Rockbox format into format for solver */ 477
469 for (r=0;r<9;r++) { 478 /* Convert Rockbox format into format for solver */
470 for (c=0;c<9;c++) { 479 for (r=0;r<9;r++) {
471 if (state->startboard[r][c]!='0') { 480 for (c=0;c<9;c++) {
472 sudoku_set(&sud, c, r, state->startboard[r][c]-'0', true); 481 if (state->startboard[r][c]!='0') {
473 } 482 sudoku_set(&sud, c, r, state->startboard[r][c]-'0', true);
483 }
484 }
474 } 485 }
475 }
476 486
477 // need to check for degenerate input problems ... 487 /* need to check for degenerate input problems ... */
478 if (is_valid(&sud)){ 488 if (is_valid(&sud)){
479 ret = solve(&sud, &stats, &options); 489 ret = solve(&sud, &stats, &options);
480 } else { 490 } else {
481 ret = false; 491 ret = false;
482 } 492 }
483 493
484 if (ret) { 494 if (ret) {
485 /* Populate the board with the solution. */ 495 /* Populate the board with the solution. */
486 for (r=0;r<9;r++) { 496 for (r=0;r<9;r++) {
487 for (c=0;c<9;c++) { 497 for (c=0;c<9;c++) {
488 state->currentboard[r][c]='0'+sudoku_get(&sud, c, r, &original); 498 state->currentboard[r][c]='0'+
489 } 499 sudoku_get(&sud, c, r, &original);
500 }
501 }
502 } else {
503 rb->splash(HZ*2, true, "Solve failed");
490 } 504 }
491 } else {
492 rb->splash(HZ*2, true, "Solve failed");
493 }
494 505
495 return; 506 return;
496} 507}
497 508
498 509
499void clear_state(struct sudoku_state_t* state) 510void clear_state(struct sudoku_state_t* state)
500{ 511{
501 int r,c; 512 int r,c;
502 513
503 state->filename[0]=0; 514 state->filename[0]=0;
504 for (r=0;r<9;r++) { 515 for (r=0;r<9;r++) {
505 for (c=0;c<9;c++) { 516 for (c=0;c<9;c++) {
506 state->startboard[r][c]='0'; 517 state->startboard[r][c]='0';
507 state->currentboard[r][c]='0'; 518 state->currentboard[r][c]='0';
508#ifdef SUDOKU_BUTTON_POSSIBLE 519#ifdef SUDOKU_BUTTON_POSSIBLE
509 state->possiblevals[r][c]=0; 520 state->possiblevals[r][c]=0;
510#endif 521#endif
522 }
511 } 523 }
512 }
513 524
514 state->x=0; 525 state->x=0;
515 state->y=0; 526 state->y=0;
516 state->editmode=0; 527 state->editmode=0;
517} 528}
518 529
519/* Load game - only ".ss" is officially supported, but any sensible 530/* Load game - only ".ss" is officially supported, but any sensible
520 text representation (one line per row) may load. 531 text representation (one line per row) may load.
521*/ 532*/
522bool load_sudoku(struct sudoku_state_t* state, char* filename) { 533bool load_sudoku(struct sudoku_state_t* state, char* filename)
523 int fd; 534{
524 size_t n; 535 int fd;
525 int r = 0, c = 0; 536 size_t n;
526 unsigned int i; 537 int r = 0, c = 0;
527 int valid=0; 538 unsigned int i;
528 char buf[300]; /* A buffer to read a sudoku board from */ 539 int valid=0;
529 540 char buf[300]; /* A buffer to read a sudoku board from */
530 fd=rb->open(filename, O_RDONLY); 541
531 if (fd < 0) { 542 fd=rb->open(filename, O_RDONLY);
532 rb->splash(HZ*2, true, "Can not open"); 543 if (fd < 0) {
533 LOGF("Invalid sudoku file: %s\n",filename); 544 rb->splash(HZ*2, true, "Can not open");
534 return(false); 545 LOGF("Invalid sudoku file: %s\n",filename);
535 }
536
537 rb->strncpy(state->filename,filename,MAX_PATH);
538 n=rb->read(fd,buf,300);
539 if (n <= 0) {
540 return(false);
541 }
542 rb->close(fd);
543
544 r=0;
545 c=0;
546 i=0;
547 while ((i < n) && (r < 9)) {
548 switch (buf[i]){
549 case ' ': case '\t':
550 if (c > 0)
551 valid=1;
552 break;
553 case '|':
554 case '*':
555 case '-':
556 case '\r':
557 break;
558 case '\n':
559 if (valid) {
560 r++;
561 valid=0;
562 }
563 c = 0;
564 break;
565 case '_': case '.':
566 valid=1;
567 if (c >= SIZE || r >= SIZE){
568 LOGF("ERROR: sudoku problem is the wrong size (%d,%d)\n", c, r);
569 return(false); 546 return(false);
570 } 547 }
571 c++; 548
572 break; 549 rb->strncpy(state->filename,filename,MAX_PATH);
573 default: 550 n=rb->read(fd,buf,300);
574 if (((buf[i]>='A') && (buf[i]<='I')) || ((buf[i]>='0') && (buf[i]<='9'))) { 551 if (n <= 0) {
575 valid=1; 552 return(false);
576 if (r >= SIZE || c >= SIZE){ 553 }
577 LOGF("ERROR: sudoku problem is the wrong size (%d,%d)\n", c, r); 554 rb->close(fd);
578 return(false); 555
579 } 556 r=0;
580 if ((buf[i]>='0') && (buf[i]<='9')) { 557 c=0;
581 state->startboard[r][c]=buf[i]; 558 i=0;
582 state->currentboard[r][c]=buf[i]; 559 while ((i < n) && (r < 9)) {
583 } else { 560 switch (buf[i]){
584 state->currentboard[r][c]='1'+(buf[i]-'A'); 561 case ' ': case '\t':
562 if (c > 0)
563 valid=1;
564 break;
565 case '|':
566 case '*':
567 case '-':
568 case '\r':
569 break;
570 case '\n':
571 if (valid) {
572 r++;
573 valid=0;
574 }
575 c = 0;
576 break;
577 case '_': case '.':
578 valid=1;
579 if (c >= SIZE || r >= SIZE){
580 LOGF("ERROR: sudoku problem is the wrong size (%d,%d)\n",
581 c, r);
582 return(false);
583 }
584 c++;
585 break;
586 default:
587 if (((buf[i]>='A') && (buf[i]<='I')) ||
588 ((buf[i]>='0') && (buf[i]<='9'))) {
589 valid=1;
590 if (r >= SIZE || c >= SIZE){
591 LOGF("ERROR: sudoku problem is the wrong size "
592 "(%d,%d)\n", c, r);
593 return(false);
594 }
595 if ((buf[i]>='0') && (buf[i]<='9')) {
596 state->startboard[r][c]=buf[i];
597 state->currentboard[r][c]=buf[i];
598 } else {
599 state->currentboard[r][c]='1'+(buf[i]-'A');
600 }
601 c++;
602 }
603 /* Ignore any other characters */
604 break;
585 } 605 }
586 c++; 606 i++;
587 }
588 /* Ignore any other characters */
589 break;
590 } 607 }
591 i++;
592 }
593 608
594 /* Save a copy of the saved state - so we can reload without 609 /* Save a copy of the saved state - so we can reload without using the
595 using the disk */ 610 disk */
596 rb->memcpy(state->savedboard,state->currentboard,81); 611 rb->memcpy(state->savedboard,state->currentboard,81);
597 return(true); 612 return(true);
598} 613}
599 614
600bool save_sudoku(struct sudoku_state_t* state) { 615bool save_sudoku(struct sudoku_state_t* state)
601 int fd; 616{
602 int r,c; 617 int fd;
603 int i; 618 int r,c;
604 char line[16]; 619 int i;
605 char sep[16]; 620 char line[16];
621 char sep[16];
606 622
607 rb->memcpy(line,"...|...|...\r\n",13); 623 rb->memcpy(line,"...|...|...\r\n",13);
608 rb->memcpy(sep,"-----------\r\n",13); 624 rb->memcpy(sep,"-----------\r\n",13);
609 625
610 if (state->filename[0]==0) { 626 if (state->filename[0]==0) {
611 return false; 627 return false;
612 } 628 }
613 629
614 fd=rb->open(state->filename, O_WRONLY|O_CREAT); 630 fd=rb->open(state->filename, O_WRONLY|O_CREAT);
615 if (fd >= 0) { 631 if (fd >= 0) {
616 for (r=0;r<9;r++) { 632 for (r=0;r<9;r++) {
617 i=0; 633 i=0;
618 for (c=0;c<9;c++) { 634 for (c=0;c<9;c++) {
619 if (state->startboard[r][c]!='0') { 635 if (state->startboard[r][c]!='0') {
620 line[i]=state->startboard[r][c]; 636 line[i]=state->startboard[r][c];
621 } else if (state->currentboard[r][c]!='0') { 637 } else if (state->currentboard[r][c]!='0') {
622 line[i]='A'+(state->currentboard[r][c]-'1'); 638 line[i]='A'+(state->currentboard[r][c]-'1');
623 } else { 639 } else {
624 line[i]='.'; 640 line[i]='.';
641 }
642 i++;
643 if ((c==2) || (c==5)) {
644 i++;
645 }
646 }
647 rb->write(fd,line,sizeof(line)-1);
648 if ((r==2) || (r==5)) {
649 rb->write(fd,sep,sizeof(sep)-1);
650 }
625 } 651 }
626 i++; 652 /* Add a blank line at end */
627 if ((c==2) || (c==5)) { i++; } 653 rb->write(fd,"\r\n",2);
628 } 654 rb->close(fd);
629 rb->write(fd,line,sizeof(line)-1); 655 /* Save a copy of the saved state - so we can reload without
630 if ((r==2) || (r==5)) { 656 using the disk */
631 rb->write(fd,sep,sizeof(sep)-1); 657 rb->memcpy(state->savedboard,state->currentboard,81);
632 } 658 return true;
659 } else {
660 return false;
633 } 661 }
634 /* Add a blank line at end */
635 rb->write(fd,"\r\n",2);
636 rb->close(fd);
637 /* Save a copy of the saved state - so we can reload without
638 using the disk */
639 rb->memcpy(state->savedboard,state->currentboard,81);
640 return true;
641 } else {
642 return false;
643 }
644} 662}
645 663
646void restore_state(struct sudoku_state_t* state) 664void restore_state(struct sudoku_state_t* state)
647{ 665{
648 rb->memcpy(state->currentboard,state->savedboard,81); 666 rb->memcpy(state->currentboard,state->savedboard,81);
649} 667}
650 668
651void clear_board(struct sudoku_state_t* state) 669void clear_board(struct sudoku_state_t* state)
652{ 670{
653 int r,c; 671 int r,c;
654 672
655 for (r=0;r<9;r++) { 673 for (r=0;r<9;r++) {
656 for (c=0;c<9;c++) { 674 for (c=0;c<9;c++) {
657 state->currentboard[r][c]=state->startboard[r][c]; 675 state->currentboard[r][c]=state->startboard[r][c];
676 }
658 } 677 }
659 } 678 state->x=0;
660 state->x=0; 679 state->y=0;
661 state->y=0;
662} 680}
663 681
664void update_cell(struct sudoku_state_t* state, int r, int c) 682void update_cell(struct sudoku_state_t* state, int r, int c)
665{ 683{
666 /* We have four types of cell: 684 /* We have four types of cell:
667 1) User-entered number 685 1) User-entered number
668 2) Starting number 686 2) Starting number
669 3) Cursor in cell 687 3) Cursor in cell
670 */ 688 */
671 689
672 if ((r==state->y) && (c==state->x)) { 690 if ((r==state->y) && (c==state->x)) {
673 rb->lcd_bitmap_part(sudoku_inverse,0,BITMAP_HEIGHT*(state->currentboard[r][c]-'0'),BITMAP_STRIDE, 691 rb->lcd_bitmap_part(sudoku_inverse,0,
674 XOFS+cellxpos[c],YOFS+cellypos[r],CELL_WIDTH,CELL_HEIGHT); 692 BITMAP_HEIGHT*(state->currentboard[r][c]-'0'),
675 } else { 693 BITMAP_STRIDE,
694 XOFS+cellxpos[c],YOFS+cellypos[r],CELL_WIDTH,
695 CELL_HEIGHT);
696 } else {
676 if (state->startboard[r][c]!='0') { 697 if (state->startboard[r][c]!='0') {
677 rb->lcd_bitmap_part(sudoku_start,0,BITMAP_HEIGHT*(state->startboard[r][c]-'0'),BITMAP_STRIDE, 698 rb->lcd_bitmap_part(sudoku_start,0,
678 XOFS+cellxpos[c],YOFS+cellypos[r],CELL_WIDTH,CELL_HEIGHT); 699 BITMAP_HEIGHT*(state->startboard[r][c]-'0'),
700 BITMAP_STRIDE,
701 XOFS+cellxpos[c],YOFS+cellypos[r],
702 CELL_WIDTH,CELL_HEIGHT);
679 } else { 703 } else {
680 rb->lcd_bitmap_part(sudoku_normal,0,BITMAP_HEIGHT*(state->currentboard[r][c]-'0'),BITMAP_STRIDE, 704 rb->lcd_bitmap_part(sudoku_normal,0,
681 XOFS+cellxpos[c],YOFS+cellypos[r],CELL_WIDTH,CELL_HEIGHT); 705 BITMAP_HEIGHT*(state->currentboard[r][c]-'0'),
706 BITMAP_STRIDE,
707 XOFS+cellxpos[c],YOFS+cellypos[r],
708 CELL_WIDTH,CELL_HEIGHT);
682 } 709 }
683 } 710 }
684 711
685 rb->lcd_update_rect(cellxpos[c],cellypos[r],CELL_WIDTH,CELL_HEIGHT); 712 rb->lcd_update_rect(cellxpos[c],cellypos[r],CELL_WIDTH,CELL_HEIGHT);
686} 713}
687 714
688 715
689void display_board(struct sudoku_state_t* state) 716void display_board(struct sudoku_state_t* state)
690{ 717{
691 int r,c; 718 int r,c;
692 719
693 /* Clear the display buffer */ 720 /* Clear the display buffer */
694 rb->lcd_clear_display(); 721 rb->lcd_clear_display();
695 722
696 /* Draw the gridlines - differently for different targets */ 723 /* Draw the gridlines - differently for different targets */
697 724
698#if LCD_HEIGHT > 64 725#if LCD_HEIGHT > 64
699 /* Large targets - draw single/double lines */ 726 /* Large targets - draw single/double lines */
700 for (r=0;r<9;r++) { 727 for (r=0;r<9;r++) {
701 rb->lcd_hline(XOFS,XOFS+BOARD_WIDTH-1,YOFS+cellypos[r]-1); 728 rb->lcd_hline(XOFS,XOFS+BOARD_WIDTH-1,YOFS+cellypos[r]-1);
702 rb->lcd_vline(XOFS+cellxpos[r]-1,YOFS,YOFS+BOARD_HEIGHT-1); 729 rb->lcd_vline(XOFS+cellxpos[r]-1,YOFS,YOFS+BOARD_HEIGHT-1);
703 if ((r % 3)==0) { 730 if ((r % 3)==0) {
704 rb->lcd_hline(XOFS,XOFS+BOARD_WIDTH-1,YOFS+cellypos[r]-2); 731 rb->lcd_hline(XOFS,XOFS+BOARD_WIDTH-1,YOFS+cellypos[r]-2);
705 rb->lcd_vline(XOFS+cellxpos[r]-2,YOFS,YOFS+BOARD_HEIGHT-1); 732 rb->lcd_vline(XOFS+cellxpos[r]-2,YOFS,YOFS+BOARD_HEIGHT-1);
733 }
706 } 734 }
707 } 735 rb->lcd_hline(XOFS,XOFS+BOARD_WIDTH-1,YOFS+cellypos[8]+CELL_HEIGHT);
708 rb->lcd_hline(XOFS,XOFS+BOARD_WIDTH-1,YOFS+cellypos[8]+CELL_HEIGHT); 736 rb->lcd_hline(XOFS,XOFS+BOARD_WIDTH-1,YOFS+cellypos[8]+CELL_HEIGHT+1);
709 rb->lcd_hline(XOFS,XOFS+BOARD_WIDTH-1,YOFS+cellypos[8]+CELL_HEIGHT+1); 737 rb->lcd_vline(XOFS+cellxpos[8]+CELL_WIDTH,YOFS,YOFS+BOARD_HEIGHT-1);
710 rb->lcd_vline(XOFS+cellxpos[8]+CELL_WIDTH,YOFS,YOFS+BOARD_HEIGHT-1); 738 rb->lcd_vline(XOFS+cellxpos[8]+CELL_WIDTH+1,YOFS,YOFS+BOARD_HEIGHT-1);
711 rb->lcd_vline(XOFS+cellxpos[8]+CELL_WIDTH+1,YOFS,YOFS+BOARD_HEIGHT-1);
712#elif (LCD_HEIGHT==64) 739#elif (LCD_HEIGHT==64)
713 /* Small targets - draw dotted/single lines */ 740 /* Small targets - draw dotted/single lines */
714 for (r=0;r<9;r++) { 741 for (r=0;r<9;r++) {
715 if ((r % 3)==0) { 742 if ((r % 3)==0) {
716 /* Solid Line */ 743 /* Solid Line */
717 rb->lcd_hline(XOFS,XOFS+BOARD_WIDTH-1,YOFS+cellypos[r]-1); 744 rb->lcd_hline(XOFS,XOFS+BOARD_WIDTH-1,YOFS+cellypos[r]-1);
718 rb->lcd_vline(XOFS+cellxpos[r]-1,YOFS,YOFS+BOARD_HEIGHT-1); 745 rb->lcd_vline(XOFS+cellxpos[r]-1,YOFS,YOFS+BOARD_HEIGHT-1);
719 } else { 746 } else {
720 /* Dotted line */ 747 /* Dotted line */
721 for (c=XOFS;c<XOFS+BOARD_WIDTH;c+=2) { 748 for (c=XOFS;c<XOFS+BOARD_WIDTH;c+=2) {
722 rb->lcd_drawpixel(c,YOFS+cellypos[r]-1); 749 rb->lcd_drawpixel(c,YOFS+cellypos[r]-1);
723 } 750 }
724 for (c=YOFS;c<YOFS+BOARD_HEIGHT;c+=2) { 751 for (c=YOFS;c<YOFS+BOARD_HEIGHT;c+=2) {
725 rb->lcd_drawpixel(XOFS+cellxpos[r]-1,c); 752 rb->lcd_drawpixel(XOFS+cellxpos[r]-1,c);
726 } 753 }
754 }
727 } 755 }
728 } 756 rb->lcd_hline(XOFS,XOFS+BOARD_WIDTH-1,YOFS+cellypos[8]+CELL_HEIGHT);
729 rb->lcd_hline(XOFS,XOFS+BOARD_WIDTH-1,YOFS+cellypos[8]+CELL_HEIGHT); 757 rb->lcd_vline(XOFS+cellxpos[8]+CELL_WIDTH,YOFS,YOFS+BOARD_HEIGHT-1);
730 rb->lcd_vline(XOFS+cellxpos[8]+CELL_WIDTH,YOFS,YOFS+BOARD_HEIGHT-1);
731#else 758#else
732 #error SUDOKU: Unsupported LCD height 759#error SUDOKU: Unsupported LCD height
733#endif 760#endif
734 761
735#ifdef SUDOKU_BUTTON_POSSIBLE 762#ifdef SUDOKU_BUTTON_POSSIBLE
736 rb->lcd_vline(XOFSSCRATCHPAD,YOFS,YOFS+BOARD_HEIGHT-1); 763 rb->lcd_vline(XOFSSCRATCHPAD,YOFS,YOFS+BOARD_HEIGHT-1);
737 rb->lcd_vline(XOFSSCRATCHPAD+CELL_WIDTH+1,YOFS,YOFS+BOARD_HEIGHT-1); 764 rb->lcd_vline(XOFSSCRATCHPAD+CELL_WIDTH+1,YOFS,YOFS+BOARD_HEIGHT-1);
738 for (r=0;r<9;r++) { 765 for (r=0;r<9;r++) {
739#if LCD_HEIGHT > 64 766#if LCD_HEIGHT > 64
740 /* Large targets - draw single/double lines */ 767 /* Large targets - draw single/double lines */
741 rb->lcd_hline(XOFSSCRATCHPAD,XOFSSCRATCHPAD+CELL_WIDTH+1, 768 rb->lcd_hline(XOFSSCRATCHPAD,XOFSSCRATCHPAD+CELL_WIDTH+1,
742 YOFS+cellypos[r]-1); 769 YOFS+cellypos[r]-1);
743 if ((r % 3)==0) 770 if ((r % 3)==0)
744 rb->lcd_hline(XOFSSCRATCHPAD,XOFSSCRATCHPAD+CELL_WIDTH+1, 771 rb->lcd_hline(XOFSSCRATCHPAD,XOFSSCRATCHPAD+CELL_WIDTH+1,
745 YOFS+cellypos[r]-2); 772 YOFS+cellypos[r]-2);
746#elif LCD_HEIGHT == 64 773#elif LCD_HEIGHT == 64
747 /* Small targets - draw dotted/single lines */ 774 /* Small targets - draw dotted/single lines */
748 if ((r % 3)==0) { 775 if ((r % 3)==0) {
749 /* Solid Line */ 776 /* Solid Line */
750 rb->lcd_hline(XOFSSCRATCHPAD,XOFSSCRATCHPAD+CELL_WIDTH+1, 777 rb->lcd_hline(XOFSSCRATCHPAD,XOFSSCRATCHPAD+CELL_WIDTH+1,
751 YOFS+cellypos[r]-1); 778 YOFS+cellypos[r]-1);
752 } else { 779 } else {
753 /* Dotted line */ 780 /* Dotted line */
754 for (c=XOFSSCRATCHPAD;c<XOFSSCRATCHPAD+CELL_WIDTH+1;c+=2) { 781 for (c=XOFSSCRATCHPAD;c<XOFSSCRATCHPAD+CELL_WIDTH+1;c+=2) {
755 rb->lcd_drawpixel(c,YOFS+cellypos[r]-1); 782 rb->lcd_drawpixel(c,YOFS+cellypos[r]-1);
756 } 783 }
757 } 784 }
758#endif 785#endif
759 if ((r>0) && state->possiblevals[state->y][state->x]&(1<<(r))) 786 if ((r>0) && state->possiblevals[state->y][state->x]&(1<<(r)))
760 rb->lcd_bitmap_part(sudoku_normal,0,BITMAP_HEIGHT*r,BITMAP_STRIDE, 787 rb->lcd_bitmap_part(sudoku_normal,0,BITMAP_HEIGHT*r,BITMAP_STRIDE,
761 XOFSSCRATCHPAD+1,YOFS+cellypos[r-1], 788 XOFSSCRATCHPAD+1,YOFS+cellypos[r-1],
762 CELL_WIDTH,CELL_HEIGHT); 789 CELL_WIDTH,CELL_HEIGHT);
763 } 790 }
764 rb->lcd_hline(XOFSSCRATCHPAD,XOFSSCRATCHPAD+CELL_WIDTH+1, 791 rb->lcd_hline(XOFSSCRATCHPAD,XOFSSCRATCHPAD+CELL_WIDTH+1,
765 YOFS+cellypos[8]+CELL_HEIGHT); 792 YOFS+cellypos[8]+CELL_HEIGHT);
766#if LCD_HEIGHT > 64 793#if LCD_HEIGHT > 64
767 rb->lcd_hline(XOFSSCRATCHPAD,XOFSSCRATCHPAD+CELL_WIDTH+1, 794 rb->lcd_hline(XOFSSCRATCHPAD,XOFSSCRATCHPAD+CELL_WIDTH+1,
768 YOFS+cellypos[8]+CELL_HEIGHT+1); 795 YOFS+cellypos[8]+CELL_HEIGHT+1);
769#endif 796#endif
770 if (state->possiblevals[state->y][state->x]&(1<<(r))) 797 if (state->possiblevals[state->y][state->x]&(1<<(r)))
771 rb->lcd_bitmap_part(sudoku_normal,0,BITMAP_HEIGHT*r,BITMAP_STRIDE, 798 rb->lcd_bitmap_part(sudoku_normal,0,BITMAP_HEIGHT*r,BITMAP_STRIDE,
772 XOFSSCRATCHPAD+1,YOFS+cellypos[8], 799 XOFSSCRATCHPAD+1,YOFS+cellypos[8],
773 CELL_WIDTH,CELL_HEIGHT); 800 CELL_WIDTH,CELL_HEIGHT);
774#endif 801#endif
775 802
776 /* Draw the numbers */ 803 /* Draw the numbers */
777 for (r=0;r<9;r++) { 804 for (r=0;r<9;r++) {
778 for (c=0;c<9;c++) { 805 for (c=0;c<9;c++) {
779 /* We have four types of cell: 806 /* We have four types of cell:
780 1) User-entered number 807 1) User-entered number
781 2) Starting number 808 2) Starting number
782 3) Cursor in cell 809 3) Cursor in cell
783 */ 810 */
784 811
785 if ((r==state->y) && (c==state->x)) { 812 if ((r==state->y) && (c==state->x)) {
786 rb->lcd_bitmap_part(sudoku_inverse,0,BITMAP_HEIGHT*(state->currentboard[r][c]-'0'),BITMAP_STRIDE, 813 rb->lcd_bitmap_part(sudoku_inverse,0,
787 XOFS+cellxpos[c],YOFS+cellypos[r],CELL_WIDTH,CELL_HEIGHT); 814 BITMAP_HEIGHT*(state->currentboard[r][c]-
788 } else { 815 '0'),
789 if (state->startboard[r][c]!='0') { 816 BITMAP_STRIDE,
790 rb->lcd_bitmap_part(sudoku_start,0,BITMAP_HEIGHT*(state->startboard[r][c]-'0'),BITMAP_STRIDE, 817 XOFS+cellxpos[c],YOFS+cellypos[r],
791 XOFS+cellxpos[c],YOFS+cellypos[r],CELL_WIDTH,CELL_HEIGHT); 818 CELL_WIDTH,CELL_HEIGHT);
792 } else { 819 } else {
793 rb->lcd_bitmap_part(sudoku_normal,0,BITMAP_HEIGHT*(state->currentboard[r][c]-'0'),BITMAP_STRIDE, 820 if (state->startboard[r][c]!='0') {
794 XOFS+cellxpos[c],YOFS+cellypos[r],CELL_WIDTH,CELL_HEIGHT); 821 rb->lcd_bitmap_part(sudoku_start,0,
822 BITMAP_HEIGHT*(state->startboard[r][c]-
823 '0'),
824 BITMAP_STRIDE,
825 XOFS+cellxpos[c],YOFS+cellypos[r],
826 CELL_WIDTH,CELL_HEIGHT);
827 } else {
828 rb->lcd_bitmap_part(sudoku_normal,0,
829 BITMAP_HEIGHT*
830 (state->currentboard[r][c]-'0'),
831 BITMAP_STRIDE,
832 XOFS+cellxpos[c],YOFS+cellypos[r],
833 CELL_WIDTH,CELL_HEIGHT);
834 }
835 }
795 } 836 }
796 }
797 } 837 }
798 }
799 838
800 /* update the screen */ 839 /* update the screen */
801 rb->lcd_update(); 840 rb->lcd_update();
802} 841}
803 842
804/* Check the status of the board, assuming a change at the cursor location */ 843/* Check the status of the board, assuming a change at the cursor location */
805bool check_status(struct sudoku_state_t* state) { 844bool check_status(struct sudoku_state_t* state)
806 int check[9]; 845{
807 int r,c; 846 int check[9];
808 int r1,c1; 847 int r,c;
809 int cell; 848 int r1,c1;
810 849 int cell;
811 /* First, check the column */ 850
812 for (cell=0;cell<9;cell++) { check[cell]=0; } 851 /* First, check the column */
813 for (r=0;r<9;r++) { 852 for (cell=0;cell<9;cell++) {
814 cell=state->currentboard[r][state->x]; 853 check[cell]=0;
815 if (cell!='0') {
816 if (check[cell-'1']==1) {
817 return true;
818 }
819 check[cell-'1']=1;
820 } 854 }
821 } 855 for (r=0;r<9;r++) {
822 856 cell=state->currentboard[r][state->x];
823 /* Second, check the row */ 857 if (cell!='0') {
824 for (cell=0;cell<9;cell++) { check[cell]=0; } 858 if (check[cell-'1']==1) {
825 for (c=0;c<9;c++) { 859 return true;
826 cell=state->currentboard[state->y][c]; 860 }
827 if (cell!='0') { 861 check[cell-'1']=1;
828 if (check[cell-'1']==1) { 862 }
829 return true; 863 }
830 } 864
831 check[cell-'1']=1; 865 /* Second, check the row */
866 for (cell=0;cell<9;cell++) {
867 check[cell]=0;
868 }
869 for (c=0;c<9;c++) {
870 cell=state->currentboard[state->y][c];
871 if (cell!='0') {
872 if (check[cell-'1']==1) {
873 return true;
874 }
875 check[cell-'1']=1;
876 }
832 } 877 }
833 } 878
834 879 /* Finally, check the 3x3 sub-grid */
835 /* Finally, check the 3x3 sub-grid */ 880 for (cell=0;cell<9;cell++) {
836 for (cell=0;cell<9;cell++) { check[cell]=0; } 881 check[cell]=0;
837 r1=(state->y/3)*3; 882 }
838 c1=(state->x/3)*3; 883 r1=(state->y/3)*3;
839 for (r=r1;r<r1+3;r++) { 884 c1=(state->x/3)*3;
840 for (c=c1;c<c1+3;c++) { 885 for (r=r1;r<r1+3;r++) {
841 cell=state->currentboard[r][c]; 886 for (c=c1;c<c1+3;c++) {
842 if (cell!='0') { 887 cell=state->currentboard[r][c];
843 if (check[cell-'1']==1) { 888 if (cell!='0') {
844 return true; 889 if (check[cell-'1']==1) {
890 return true;
891 }
892 check[cell-'1']=1;
893 }
845 } 894 }
846 check[cell-'1']=1;
847 }
848 } 895 }
849 }
850 896
851 /* We passed all the checks :) */ 897 /* We passed all the checks :) */
852 898
853 return false; 899 return false;
854} 900}
855 901
856int sudoku_menu_cb(int key, int m) 902int sudoku_menu_cb(int key, int m)
@@ -878,242 +924,243 @@ int sudoku_menu_cb(int key, int m)
878 924
879bool sudoku_menu(struct sudoku_state_t* state) 925bool sudoku_menu(struct sudoku_state_t* state)
880{ 926{
881 int m; 927 int m;
882 int result; 928 int result;
883 929
884 static const struct menu_item items[] = { 930 static const struct menu_item items[] = {
885 { "Save", NULL }, 931 { "Save", NULL },
886 { "Reload", NULL }, 932 { "Reload", NULL },
887 { "Clear", NULL }, 933 { "Clear", NULL },
888 { "Solve", NULL }, 934 { "Solve", NULL },
889 { "New", NULL }, 935 { "New", NULL },
890 }; 936 };
891 937
892 m = rb->menu_init(items, sizeof(items) / sizeof(*items), 938 m = rb->menu_init(items, sizeof(items) / sizeof(*items),
893 sudoku_menu_cb, NULL, NULL, NULL); 939 sudoku_menu_cb, NULL, NULL, NULL);
894 940
895 result=rb->menu_show(m); 941 result=rb->menu_show(m);
896 942
897 switch (result) { 943 switch (result) {
898 case 0: /* Save state */ 944 case 0: /* Save state */
899 save_sudoku(state); 945 save_sudoku(state);
900 break; 946 break;
901 947
902 case 1: /* Restore state */ 948 case 1: /* Restore state */
903 restore_state(state); 949 restore_state(state);
904 break; 950 break;
905 951
906 case 2: /* Clear all */ 952 case 2: /* Clear all */
907 clear_board(state); 953 clear_board(state);
908 break; 954 break;
909 955
910 case 3: /* Solve */ 956 case 3: /* Solve */
911 sudoku_solve(state); 957 sudoku_solve(state);
912 break; 958 break;
913 959
914 case 4: /* Create a new game manually */ 960 case 4: /* Create a new game manually */
915 clear_state(state); 961 clear_state(state);
916 state->editmode=1; 962 state->editmode=1;
917 break; 963 break;
918 964
919 default: 965 default:
920 break; 966 break;
921 } 967 }
922 968
923 rb->menu_exit(m); 969 rb->menu_exit(m);
924 970
925 return (result==MENU_ATTACHED_USB); 971 return (result==MENU_ATTACHED_USB);
926} 972}
927 973
928void move_cursor(struct sudoku_state_t* state, int newx, int newy) { 974void move_cursor(struct sudoku_state_t* state, int newx, int newy)
929 int oldx, oldy; 975{
930 976 int oldx, oldy;
931 /* Check that the character at the cursor position is legal */ 977
932 if (check_status(state)) { 978 /* Check that the character at the cursor position is legal */
933 rb->splash(HZ*2, true, "Illegal move!"); 979 if (check_status(state)) {
934 /* Ignore any button presses during the splash */ 980 rb->splash(HZ*2, true, "Illegal move!");
935 rb->button_clear_queue(); 981 /* Ignore any button presses during the splash */
936 return; 982 rb->button_clear_queue();
937 } 983 return;
984 }
938 985
939 /* Move Cursor */ 986 /* Move Cursor */
940 oldx=state->x; 987 oldx=state->x;
941 oldy=state->y; 988 oldy=state->y;
942 state->x=newx; 989 state->x=newx;
943 state->y=newy; 990 state->y=newy;
944 991
945 /* Redraw current and old cells */ 992 /* Redraw current and old cells */
946 update_cell(state,oldx,oldy); 993 update_cell(state,oldx,oldy);
947 update_cell(state,newx,newy); 994 update_cell(state,newx,newy);
948} 995}
949 996
950/* plugin entry point */ 997/* plugin entry point */
951enum plugin_status plugin_start(struct plugin_api* api, void* parameter) 998enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
952{ 999{
953 bool exit; 1000 bool exit;
954 int button; 1001 int button;
955 int lastbutton = BUTTON_NONE; 1002 int lastbutton = BUTTON_NONE;
956 long ticks; 1003 long ticks;
957 struct sudoku_state_t state; 1004 struct sudoku_state_t state;
958 1005
959 /* plugin init */ 1006 /* plugin init */
960 rb = api; 1007 rb = api;
961 /* end of plugin init */ 1008 /* end of plugin init */
962 1009
963 clear_state(&state); 1010 clear_state(&state);
964 1011
965 if (parameter==NULL) { 1012 if (parameter==NULL) {
966 state.editmode=1; 1013 state.editmode=1;
967 } else { 1014 } else {
968 if (!load_sudoku(&state,(char*)parameter)) { 1015 if (!load_sudoku(&state,(char*)parameter)) {
969 rb->splash(HZ*2, true, "Load error"); 1016 rb->splash(HZ*2, true, "Load error");
970 return(PLUGIN_ERROR); 1017 return(PLUGIN_ERROR);
1018 }
971 } 1019 }
972 }
973 1020
974 display_board(&state); 1021 display_board(&state);
975 1022
976 /* The main game loop */ 1023 /* The main game loop */
977 exit=false; 1024 exit=false;
978 ticks=0; 1025 ticks=0;
979 while(!exit) { 1026 while(!exit) {
980 button = rb->button_get(true); 1027 button = rb->button_get(true);
981 1028
982 switch(button){ 1029 switch(button){
983 /* Exit game */ 1030 /* Exit game */
984 case SUDOKU_BUTTON_QUIT: 1031 case SUDOKU_BUTTON_QUIT:
985 exit=1; 1032 exit=1;
986 break; 1033 break;
987 1034
988 /* Increment digit */ 1035 /* Increment digit */
989#ifdef SUDOKU_BUTTON_ALTTOGGLE 1036#ifdef SUDOKU_BUTTON_ALTTOGGLE
990 case SUDOKU_BUTTON_ALTTOGGLE | BUTTON_REPEAT: 1037 case SUDOKU_BUTTON_ALTTOGGLE | BUTTON_REPEAT:
991#endif 1038#endif
992 case SUDOKU_BUTTON_TOGGLE | BUTTON_REPEAT: 1039 case SUDOKU_BUTTON_TOGGLE | BUTTON_REPEAT:
993 /* Slow down the repeat speed to 1/3 second */ 1040 /* Slow down the repeat speed to 1/3 second */
994 if ((*rb->current_tick-ticks) < (HZ/3)) { 1041 if ((*rb->current_tick-ticks) < (HZ/3)) {
995 break; 1042 break;
996 } 1043 }
997 1044
998#ifdef SUDOKU_BUTTON_ALTTOGGLE 1045#ifdef SUDOKU_BUTTON_ALTTOGGLE
999 case SUDOKU_BUTTON_ALTTOGGLE: 1046 case SUDOKU_BUTTON_ALTTOGGLE:
1000#endif 1047#endif
1001 case SUDOKU_BUTTON_TOGGLE: 1048 case SUDOKU_BUTTON_TOGGLE:
1002#ifdef SUDOKU_BUTTON_TOGGLE_PRE 1049#ifdef SUDOKU_BUTTON_TOGGLE_PRE
1003 if ((button == SUDOKU_BUTTON_TOGGLE) 1050 if ((button == SUDOKU_BUTTON_TOGGLE)
1004 && (lastbutton != SUDOKU_BUTTON_TOGGLE_PRE)) 1051 && (lastbutton != SUDOKU_BUTTON_TOGGLE_PRE))
1005 break; 1052 break;
1006#endif 1053#endif
1007 /* Increment digit */ 1054 /* Increment digit */
1008 ticks=*rb->current_tick; 1055 ticks=*rb->current_tick;
1009 if (state.editmode) { 1056 if (state.editmode) {
1010 if (state.startboard[state.y][state.x]=='9') { 1057 if (state.startboard[state.y][state.x]=='9') {
1011 state.startboard[state.y][state.x]='0'; 1058 state.startboard[state.y][state.x]='0';
1012 state.currentboard[state.y][state.x]='0'; 1059 state.currentboard[state.y][state.x]='0';
1013 } else { 1060 } else {
1014 state.startboard[state.y][state.x]++; 1061 state.startboard[state.y][state.x]++;
1015 state.currentboard[state.y][state.x]++; 1062 state.currentboard[state.y][state.x]++;
1016 } 1063 }
1017 } else { 1064 } else {
1018 if (state.startboard[state.y][state.x]=='0') { 1065 if (state.startboard[state.y][state.x]=='0') {
1019 if (state.currentboard[state.y][state.x]=='9') { 1066 if (state.currentboard[state.y][state.x]=='9') {
1020 state.currentboard[state.y][state.x]='0'; 1067 state.currentboard[state.y][state.x]='0';
1021 } else { 1068 } else {
1022 state.currentboard[state.y][state.x]++; 1069 state.currentboard[state.y][state.x]++;
1023 } 1070 }
1024 } 1071 }
1025 } 1072 }
1026 update_cell(&state,state.y,state.x); 1073 update_cell(&state,state.y,state.x);
1027 break; 1074 break;
1028 1075
1029 /* move cursor left */ 1076 /* move cursor left */
1030 case BUTTON_LEFT: 1077 case BUTTON_LEFT:
1031 case (BUTTON_LEFT | BUTTON_REPEAT): 1078 case (BUTTON_LEFT | BUTTON_REPEAT):
1032 if (state.x==0) { 1079 if (state.x==0) {
1033 move_cursor(&state,8,state.y); 1080 move_cursor(&state,8,state.y);
1034 } else { 1081 } else {
1035 move_cursor(&state,state.x-1,state.y); 1082 move_cursor(&state,state.x-1,state.y);
1036 } 1083 }
1037 break; 1084 break;
1038 1085
1039 /* move cursor right */ 1086 /* move cursor right */
1040 case BUTTON_RIGHT: 1087 case BUTTON_RIGHT:
1041 case (BUTTON_RIGHT | BUTTON_REPEAT): 1088 case (BUTTON_RIGHT | BUTTON_REPEAT):
1042 if (state.x==8) { 1089 if (state.x==8) {
1043 move_cursor(&state,0,state.y); 1090 move_cursor(&state,0,state.y);
1044 } else { 1091 } else {
1045 move_cursor(&state,state.x+1,state.y); 1092 move_cursor(&state,state.x+1,state.y);
1046 } 1093 }
1047 break; 1094 break;
1048 1095
1049 /* move cursor up */ 1096 /* move cursor up */
1050 case SUDOKU_BUTTON_UP: 1097 case SUDOKU_BUTTON_UP:
1051 case (SUDOKU_BUTTON_UP | BUTTON_REPEAT): 1098 case (SUDOKU_BUTTON_UP | BUTTON_REPEAT):
1052 if (state.y==0) { 1099 if (state.y==0) {
1053 move_cursor(&state,state.x,8); 1100 move_cursor(&state,state.x,8);
1054 } else { 1101 } else {
1055 move_cursor(&state,state.x,state.y-1); 1102 move_cursor(&state,state.x,state.y-1);
1056 } 1103 }
1057 break; 1104 break;
1058 1105
1059 /* move cursor down */ 1106 /* move cursor down */
1060 case SUDOKU_BUTTON_DOWN: 1107 case SUDOKU_BUTTON_DOWN:
1061 case (SUDOKU_BUTTON_DOWN | BUTTON_REPEAT): 1108 case (SUDOKU_BUTTON_DOWN | BUTTON_REPEAT):
1062 if (state.y==8) { 1109 if (state.y==8) {
1063 move_cursor(&state,state.x,0); 1110 move_cursor(&state,state.x,0);
1064 } else { 1111 } else {
1065 move_cursor(&state,state.x,state.y+1); 1112 move_cursor(&state,state.x,state.y+1);
1066 } 1113 }
1067 break; 1114 break;
1068 1115
1069 case SUDOKU_BUTTON_MENU: 1116 case SUDOKU_BUTTON_MENU:
1070#ifdef SUDOKU_BUTTON_MENU_PRE 1117#ifdef SUDOKU_BUTTON_MENU_PRE
1071 if (lastbutton != SUDOKU_BUTTON_MENU_PRE) 1118 if (lastbutton != SUDOKU_BUTTON_MENU_PRE)
1072 break; 1119 break;
1073#endif 1120#endif
1074 /* Don't let the user leave a game in a bad state */ 1121 /* Don't let the user leave a game in a bad state */
1075 if (check_status(&state)) { 1122 if (check_status(&state)) {
1076 rb->splash(HZ*2, true, "Illegal move!"); 1123 rb->splash(HZ*2, true, "Illegal move!");
1077 /* Ignore any button presses during the splash */ 1124 /* Ignore any button presses during the splash */
1078 rb->button_clear_queue(); 1125 rb->button_clear_queue();
1079 } else { 1126 } else {
1080 if (state.editmode) { 1127 if (state.editmode) {
1081 rb->kbd_input(state.filename,MAX_PATH); 1128 rb->kbd_input(state.filename,MAX_PATH);
1082 if (save_sudoku(&state)) { 1129 if (save_sudoku(&state)) {
1083 state.editmode=0; 1130 state.editmode=0;
1084 } else { 1131 } else {
1085 rb->splash(HZ*2, true, "Save failed"); 1132 rb->splash(HZ*2, true, "Save failed");
1086 } 1133 }
1087 } else { 1134 } else {
1088 if (sudoku_menu(&state)) { 1135 if (sudoku_menu(&state)) {
1089 return PLUGIN_USB_CONNECTED; 1136 return PLUGIN_USB_CONNECTED;
1090 } 1137 }
1091 } 1138 }
1092 } 1139 }
1093 break; 1140 break;
1094#ifdef SUDOKU_BUTTON_POSSIBLE 1141#ifdef SUDOKU_BUTTON_POSSIBLE
1095 case SUDOKU_BUTTON_POSSIBLE: 1142 case SUDOKU_BUTTON_POSSIBLE:
1096 /* Toggle current number in the possiblevals structure */ 1143 /* Toggle current number in the possiblevals structure */
1097 if (state.currentboard[state.y][state.x]!='0') { 1144 if (state.currentboard[state.y][state.x]!='0') {
1098 state.possiblevals[state.y][state.x]^= 1145 state.possiblevals[state.y][state.x]^=
1099 (1 << (state.currentboard[state.y][state.x] - '0')); 1146 (1 << (state.currentboard[state.y][state.x] - '0'));
1100 } 1147 }
1101 break; 1148 break;
1102#endif 1149#endif
1103 default: 1150 default:
1104 if (rb->default_event_handler(button) == SYS_USB_CONNECTED) { 1151 if (rb->default_event_handler(button) == SYS_USB_CONNECTED) {
1105 /* Quit if USB has been connected */ 1152 /* Quit if USB has been connected */
1106 return PLUGIN_USB_CONNECTED; 1153 return PLUGIN_USB_CONNECTED;
1154 }
1155 break;
1107 } 1156 }
1108 break; 1157 if (button != BUTTON_NONE)
1109 } 1158 lastbutton = button;
1110 if (button != BUTTON_NONE)
1111 lastbutton = button;
1112 1159
1113 display_board(&state); 1160 display_board(&state);
1114 } 1161 }
1115 1162
1116 return PLUGIN_OK; 1163 return PLUGIN_OK;
1117} 1164}
1118 1165
1119#endif 1166#endif
diff --git a/apps/plugins/video.c b/apps/plugins/video.c
index 53535597c9..e82ec1a84f 100644
--- a/apps/plugins/video.c
+++ b/apps/plugins/video.c
@@ -27,10 +27,10 @@
27#include "plugin.h" 27#include "plugin.h"
28#include "sh7034.h" 28#include "sh7034.h"
29#include "system.h" 29#include "system.h"
30#include "../apps/recorder/widgets.h" // not in search path, booh 30#include "../apps/recorder/widgets.h" /* not in search path, booh */
31 31
32#ifndef SIMULATOR // not for simulator by now 32#ifndef SIMULATOR /* not for simulator by now */
33#ifdef HAVE_LCD_BITMAP // and definitely not for the Player, haha 33#ifdef HAVE_LCD_BITMAP /* and definitely not for the Player, haha */
34 34
35PLUGIN_HEADER 35PLUGIN_HEADER
36 36
@@ -52,89 +52,89 @@ PLUGIN_HEADER
52#endif 52#endif
53/****************** constants ******************/ 53/****************** constants ******************/
54 54
55#define SCREENSIZE (LCD_WIDTH*LCD_HEIGHT/8) // in bytes 55#define SCREENSIZE (LCD_WIDTH*LCD_HEIGHT/8) /* in bytes */
56#define FPS 68 // default fps for headerless (old video-only) file 56#define FPS 68 /* default fps for headerless (old video-only) file */
57#define MAX_ACC 20 // maximum FF/FR speedup 57#define MAX_ACC 20 /* maximum FF/FR speedup */
58#define FF_TICKS 3000; // experimentally found nice 58#define FF_TICKS 3000; /* experimentally found nice */
59 59
60// trigger levels, we need about 80 kB/sec 60/* trigger levels, we need about 80 kB/sec */
61#define SPINUP_INIT 5000 // from what level on to refill, in milliseconds 61#define SPINUP_INIT 5000 /* from what level on to refill, in milliseconds */
62#define SPINUP_SAFETY 700 // how much on top of the measured spinup time 62#define SPINUP_SAFETY 700 /* how much on top of the measured spinup time */
63#define CHUNK (1024*32) // read size 63#define CHUNK (1024*32) /* read size */
64 64
65 65
66/****************** prototypes ******************/ 66/****************** prototypes ******************/
67void timer4_isr(void); // IMIA4 ISR 67void timer4_isr(void); /* IMIA4 ISR */
68int check_button(void); // determine next relative frame 68int check_button(void); /* determine next relative frame */
69 69
70 70
71/****************** data types ******************/ 71/****************** data types ******************/
72 72
73// plugins don't introduce headers, so structs are repeated from rvf_format.h 73/* plugins don't introduce headers, so structs are repeated from rvf_format.h */
74 74
75#define HEADER_MAGIC 0x52564668 // "RVFh" at file start 75#define HEADER_MAGIC 0x52564668 /* "RVFh" at file start */
76#define AUDIO_MAGIC 0x41756446 // "AudF" for each audio block 76#define AUDIO_MAGIC 0x41756446 /* "AudF" for each audio block */
77#define FILEVERSION 100 // 1.00 77#define FILEVERSION 100 /* 1.00 */
78 78
79// format type definitions 79/* format type definitions */
80#define VIDEOFORMAT_NO_VIDEO 0 80#define VIDEOFORMAT_NO_VIDEO 0
81#define VIDEOFORMAT_RAW 1 81#define VIDEOFORMAT_RAW 1
82#define AUDIOFORMAT_NO_AUDIO 0 82#define AUDIOFORMAT_NO_AUDIO 0
83#define AUDIOFORMAT_MP3 1 83#define AUDIOFORMAT_MP3 1
84#define AUDIOFORMAT_MP3_BITSWAPPED 2 84#define AUDIOFORMAT_MP3_BITSWAPPED 2
85 85
86// bit flags 86/* bit flags */
87#define FLAG_LOOP 0x00000001 // loop the playback, e.g. for stills 87#define FLAG_LOOP 0x00000001 /* loop the playback, e.g. for stills */
88 88
89typedef struct // contains whatever might be useful to the player 89typedef struct /* contains whatever might be useful to the player */
90{ 90{
91 // general info (16 entries = 64 byte) 91 /* general info (16 entries = 64 byte) */
92 unsigned long magic; // HEADER_MAGIC 92 unsigned long magic; /* HEADER_MAGIC */
93 unsigned long version; // file version 93 unsigned long version; /* file version */
94 unsigned long flags; // combination of FLAG_xx 94 unsigned long flags; /* combination of FLAG_xx */
95 unsigned long blocksize; // how many bytes per block (=video frame) 95 unsigned long blocksize; /* how many bytes per block (=video frame) */
96 unsigned long bps_average; // bits per second of the whole stream 96 unsigned long bps_average; /* bits per second of the whole stream */
97 unsigned long bps_peak; // max. of above (audio may be VBR) 97 unsigned long bps_peak; /* max. of above (audio may be VBR) */
98 unsigned long resume_pos; // file position to resume to 98 unsigned long resume_pos; /* file position to resume to */
99 unsigned long reserved[9]; // reserved, should be zero 99 unsigned long reserved[9]; /* reserved, should be zero */
100 100
101 // video info (16 entries = 64 byte) 101 /* video info (16 entries = 64 byte) */
102 unsigned long video_format; // one of VIDEOFORMAT_xxx 102 unsigned long video_format; /* one of VIDEOFORMAT_xxx */
103 unsigned long video_1st_frame; // byte position of first video frame 103 unsigned long video_1st_frame; /* byte position of first video frame */
104 unsigned long video_duration; // total length of video part, in ms 104 unsigned long video_duration; /* total length of video part, in ms */
105 unsigned long video_payload_size; // total amount of video data, in bytes 105 unsigned long video_payload_size; /* total amount of video data, in bytes */
106 unsigned long video_bitrate; // derived from resolution and frame time, in bps 106 unsigned long video_bitrate; /* derived from resolution and frame time, in bps */
107 unsigned long video_frametime; // frame interval in 11.0592 MHz clocks 107 unsigned long video_frametime; /* frame interval in 11.0592 MHz clocks */
108 long video_preroll; // video is how much ahead, in 11.0592 MHz clocks 108 long video_preroll; /* video is how much ahead, in 11.0592 MHz clocks */
109 unsigned long video_width; // in pixels 109 unsigned long video_width; /* in pixels */
110 unsigned long video_height; // in pixels 110 unsigned long video_height; /* in pixels */
111 unsigned long video_reserved[7]; // reserved, should be zero 111 unsigned long video_reserved[7]; /* reserved, should be zero */
112 112
113 // audio info (16 entries = 64 byte) 113 /* audio info (16 entries = 64 byte) */
114 unsigned long audio_format; // one of AUDIOFORMAT_xxx 114 unsigned long audio_format; /* one of AUDIOFORMAT_xxx */
115 unsigned long audio_1st_frame; // byte position of first video frame 115 unsigned long audio_1st_frame; /* byte position of first video frame */
116 unsigned long audio_duration; // total length of audio part, in ms 116 unsigned long audio_duration; /* total length of audio part, in ms */
117 unsigned long audio_payload_size; // total amount of audio data, in bytes 117 unsigned long audio_payload_size; /* total amount of audio data, in bytes */
118 unsigned long audio_avg_bitrate; // average audio bitrate, in bits per second 118 unsigned long audio_avg_bitrate; /* average audio bitrate, in bits per second */
119 unsigned long audio_peak_bitrate; // maximum bitrate 119 unsigned long audio_peak_bitrate; /* maximum bitrate */
120 unsigned long audio_headersize; // offset to payload in audio frames 120 unsigned long audio_headersize; /* offset to payload in audio frames */
121 long audio_min_associated; // minimum offset to video frame, in bytes 121 long audio_min_associated; /* minimum offset to video frame, in bytes */
122 long audio_max_associated; // maximum offset to video frame, in bytes 122 long audio_max_associated; /* maximum offset to video frame, in bytes */
123 unsigned long audio_reserved[7]; // reserved, should be zero 123 unsigned long audio_reserved[7]; /* reserved, should be zero */
124 124
125 // more to come... ? 125 /* more to come... ? */
126 126
127 // Note: padding up to 'blocksize' with zero following this header 127 /* Note: padding up to 'blocksize' with zero following this header */
128} tFileHeader; 128} tFileHeader;
129 129
130typedef struct // the little header for all audio blocks 130typedef struct /* the little header for all audio blocks */
131{ 131{
132 unsigned long magic; // AUDIO_MAGIC indicates an audio block 132 unsigned long magic; /* AUDIO_MAGIC indicates an audio block */
133 unsigned char previous_block; // previous how many blocks backwards 133 unsigned char previous_block; /* previous how many blocks backwards */
134 unsigned char next_block; // next how many blocks forward 134 unsigned char next_block; /* next how many blocks forward */
135 short associated_video; // offset to block with corresponding video 135 short associated_video; /* offset to block with corresponding video */
136 unsigned short frame_start; // offset to first frame starting in this block 136 unsigned short frame_start; /* offset to first frame starting in this block */
137 unsigned short frame_end; // offset to behind last frame ending in this block 137 unsigned short frame_end; /* offset to behind last frame ending in this block */
138} tAudioFrameHeader; 138} tAudioFrameHeader;
139 139
140 140
@@ -145,7 +145,7 @@ static struct plugin_api* rb; /* here is a global api struct pointer */
145static char gPrint[32]; /* a global printf buffer, saves stack */ 145static char gPrint[32]; /* a global printf buffer, saves stack */
146 146
147 147
148// playstate 148/* playstate */
149static struct 149static struct
150{ 150{
151 enum 151 enum
@@ -157,40 +157,40 @@ static struct
157 bool bVideoUnderrun; 157 bool bVideoUnderrun;
158 bool bHasAudio; 158 bool bHasAudio;
159 bool bHasVideo; 159 bool bHasVideo;
160 int nTimeOSD; // OSD should stay for this many frames 160 int nTimeOSD; /* OSD should stay for this many frames */
161 bool bDirtyOSD; // OSD needs redraw 161 bool bDirtyOSD; /* OSD needs redraw */
162 bool bRefilling; // set if refilling buffer 162 bool bRefilling; /* set if refilling buffer */
163 bool bSeeking; 163 bool bSeeking;
164 int nSeekAcc; // accelleration value for seek 164 int nSeekAcc; /* accelleration value for seek */
165 int nSeekPos; // current file position for seek 165 int nSeekPos; /* current file position for seek */
166 bool bDiskSleep; // disk is suspended 166 bool bDiskSleep; /* disk is suspended */
167#if FREQ == 12000000 /* Ondio speed kludge */ 167#if FREQ == 12000000 /* Ondio speed kludge */
168 int nFrameTimeAdjusted; 168 int nFrameTimeAdjusted;
169#endif 169#endif
170} gPlay; 170} gPlay;
171 171
172// buffer information 172/* buffer information */
173static struct 173static struct
174{ 174{
175 int bufsize; 175 int bufsize;
176 int granularity; // common multiple of block and sector size 176 int granularity; /* common multiple of block and sector size */
177 unsigned char* pBufStart; // start of ring buffer 177 unsigned char* pBufStart; /* start of ring buffer */
178 unsigned char* pBufEnd; // end of ring buffer 178 unsigned char* pBufEnd; /* end of ring buffer */
179 unsigned char* pOSD; // OSD memory (112 bytes for 112*8 pixels) 179 unsigned char* pOSD; /* OSD memory (112 bytes for 112*8 pixels) */
180 180
181 int vidcount; // how many video blocks are known in a row 181 int vidcount; /* how many video blocks are known in a row */
182 unsigned char* pBufFill; // write pointer for disk, owned by main task 182 unsigned char* pBufFill; /* write pointer for disk, owned by main task */
183 unsigned char* pReadVideo; // video readout, maintained by timer ISR 183 unsigned char* pReadVideo; /* video readout, maintained by timer ISR */
184 unsigned char* pReadAudio; // audio readout, maintained by demand ISR 184 unsigned char* pReadAudio; /* audio readout, maintained by demand ISR */
185 bool bEOF; // flag for end of file 185 bool bEOF; /* flag for end of file */
186 int low_water; // reload threshold 186 int low_water; /* reload threshold */
187 int high_water; // end of reload threshold 187 int high_water; /* end of reload threshold */
188 int spinup_safety; // safety margin when recalculating low_water 188 int spinup_safety; /* safety margin when recalculating low_water */
189 int nReadChunk; // how much data for normal buffer fill 189 int nReadChunk; /* how much data for normal buffer fill */
190 int nSeekChunk; // how much data while seeking 190 int nSeekChunk; /* how much data while seeking */
191} gBuf; 191} gBuf;
192 192
193// statistics 193/* statistics */
194static struct 194static struct
195{ 195{
196 int minAudioAvail; 196 int minAudioAvail;
@@ -201,11 +201,11 @@ static struct
201 long maxSpinup; 201 long maxSpinup;
202} gStats; 202} gStats;
203 203
204tFileHeader gFileHdr; // file header 204tFileHeader gFileHdr; /* file header */
205 205
206/****************** implementation ******************/ 206/****************** implementation ******************/
207 207
208// tool function: return how much playable audio/video is left 208/* tool function: return how much playable audio/video is left */
209int Available(unsigned char* pSnapshot) 209int Available(unsigned char* pSnapshot)
210{ 210{
211 if (pSnapshot <= gBuf.pBufFill) 211 if (pSnapshot <= gBuf.pBufFill)
@@ -214,35 +214,35 @@ int Available(unsigned char* pSnapshot)
214 return gBuf.bufsize - (pSnapshot - gBuf.pBufFill); 214 return gBuf.bufsize - (pSnapshot - gBuf.pBufFill);
215} 215}
216 216
217// debug function to draw buffer indicators 217/* debug function to draw buffer indicators */
218void DrawBuf(void) 218void DrawBuf(void)
219{ 219{
220 int fill, video, audio; 220 int fill, video, audio;
221 221
222 rb->memset(gBuf.pOSD, 0x10, LCD_WIDTH); // draw line 222 rb->memset(gBuf.pOSD, 0x10, LCD_WIDTH); /* draw line */
223 gBuf.pOSD[0] = gBuf.pOSD[LCD_WIDTH-1] = 0xFE; // ends 223 gBuf.pOSD[0] = gBuf.pOSD[LCD_WIDTH-1] = 0xFE; /* ends */
224 224
225 // calculate new tick positions 225 /* calculate new tick positions */
226 fill = 1 + ((gBuf.pBufFill - gBuf.pBufStart) * (LCD_WIDTH-2)) / gBuf.bufsize; 226 fill = 1 + ((gBuf.pBufFill - gBuf.pBufStart) * (LCD_WIDTH-2)) / gBuf.bufsize;
227 video = 1 + ((gBuf.pReadVideo - gBuf.pBufStart) * (LCD_WIDTH-2)) / gBuf.bufsize; 227 video = 1 + ((gBuf.pReadVideo - gBuf.pBufStart) * (LCD_WIDTH-2)) / gBuf.bufsize;
228 audio = 1 + ((gBuf.pReadAudio - gBuf.pBufStart) * (LCD_WIDTH-2)) / gBuf.bufsize; 228 audio = 1 + ((gBuf.pReadAudio - gBuf.pBufStart) * (LCD_WIDTH-2)) / gBuf.bufsize;
229 229
230 gBuf.pOSD[fill] |= 0x20; // below the line, two pixels 230 gBuf.pOSD[fill] |= 0x20; /* below the line, two pixels */
231 gBuf.pOSD[video] |= 0x08; // one above 231 gBuf.pOSD[video] |= 0x08; /* one above */
232 gBuf.pOSD[audio] |= 0x04; // two above 232 gBuf.pOSD[audio] |= 0x04; /* two above */
233 233
234 if (gPlay.state == paused) // we have to draw ourselves 234 if (gPlay.state == paused) /* we have to draw ourselves */
235 rb->lcd_update_rect(0, LCD_HEIGHT-8, LCD_WIDTH, 8); 235 rb->lcd_update_rect(0, LCD_HEIGHT-8, LCD_WIDTH, 8);
236 else 236 else
237 gPlay.bDirtyOSD = true; // redraw it with next timer IRQ 237 gPlay.bDirtyOSD = true; /* redraw it with next timer IRQ */
238} 238}
239 239
240 240
241// helper function to draw a position indicator 241/* helper function to draw a position indicator */
242void DrawPosition(int pos, int total) 242void DrawPosition(int pos, int total)
243{ 243{
244 int w,h; 244 int w,h;
245 int sec; // estimated seconds 245 int sec; /* estimated seconds */
246 246
247 247
248 /* print the estimated position */ 248 /* print the estimated position */
@@ -258,17 +258,17 @@ void DrawPosition(int pos, int total)
258 w++; 258 w++;
259 rb->scrollbar(w, LCD_HEIGHT-7, LCD_WIDTH-w, 7, total, 0, pos, HORIZONTAL); 259 rb->scrollbar(w, LCD_HEIGHT-7, LCD_WIDTH-w, 7, total, 0, pos, HORIZONTAL);
260 260
261 if (gPlay.state == paused) // we have to draw ourselves 261 if (gPlay.state == paused) /* we have to draw ourselves */
262 rb->lcd_update_rect(0, LCD_HEIGHT-8, LCD_WIDTH, 8); 262 rb->lcd_update_rect(0, LCD_HEIGHT-8, LCD_WIDTH, 8);
263 else // let the display time do it 263 else /* let the display time do it */
264 { 264 {
265 gPlay.nTimeOSD = 70; 265 gPlay.nTimeOSD = 70;
266 gPlay.bDirtyOSD = true; // redraw it with next timer IRQ 266 gPlay.bDirtyOSD = true; /* redraw it with next timer IRQ */
267 } 267 }
268} 268}
269 269
270 270
271// helper function to change the volume by a certain amount, +/- 271/* helper function to change the volume by a certain amount, +/- */
272void ChangeVolume(int delta) 272void ChangeVolume(int delta)
273{ 273{
274 int minvol = rb->sound_min(SOUND_VOLUME); 274 int minvol = rb->sound_min(SOUND_VOLUME);
@@ -283,18 +283,18 @@ void ChangeVolume(int delta)
283 rb->global_settings->volume = vol; 283 rb->global_settings->volume = vol;
284 rb->snprintf(gPrint, sizeof(gPrint), "Vol: %d dB", vol); 284 rb->snprintf(gPrint, sizeof(gPrint), "Vol: %d dB", vol);
285 rb->lcd_puts(0, 7, gPrint); 285 rb->lcd_puts(0, 7, gPrint);
286 if (gPlay.state == paused) // we have to draw ourselves 286 if (gPlay.state == paused) /* we have to draw ourselves */
287 rb->lcd_update_rect(0, LCD_HEIGHT-8, LCD_WIDTH, 8); 287 rb->lcd_update_rect(0, LCD_HEIGHT-8, LCD_WIDTH, 8);
288 else // let the display time do it 288 else /* let the display time do it */
289 { 289 {
290 gPlay.nTimeOSD = 50; // display it for 50 frames 290 gPlay.nTimeOSD = 50; /* display it for 50 frames */
291 gPlay.bDirtyOSD = true; // let the refresh copy it to LCD 291 gPlay.bDirtyOSD = true; /* let the refresh copy it to LCD */
292 } 292 }
293 } 293 }
294} 294}
295 295
296 296
297// helper function to change the LCD contrast by a certain amount, +/- 297/* helper function to change the LCD contrast by a certain amount, +/- */
298void ChangeContrast(int delta) 298void ChangeContrast(int delta)
299{ 299{
300 static int mycontrast = -1; /* the "permanent" value while running */ 300 static int mycontrast = -1; /* the "permanent" value while running */
@@ -312,18 +312,18 @@ void ChangeContrast(int delta)
312 mycontrast = contrast; 312 mycontrast = contrast;
313 rb->snprintf(gPrint, sizeof(gPrint), "Contrast: %d", contrast); 313 rb->snprintf(gPrint, sizeof(gPrint), "Contrast: %d", contrast);
314 rb->lcd_puts(0, 7, gPrint); 314 rb->lcd_puts(0, 7, gPrint);
315 if (gPlay.state == paused) // we have to draw ourselves 315 if (gPlay.state == paused) /* we have to draw ourselves */
316 rb->lcd_update_rect(0, LCD_HEIGHT-8, LCD_WIDTH, 8); 316 rb->lcd_update_rect(0, LCD_HEIGHT-8, LCD_WIDTH, 8);
317 else // let the display time do it 317 else /* let the display time do it */
318 { 318 {
319 gPlay.nTimeOSD = 50; // display it for 50 frames 319 gPlay.nTimeOSD = 50; /* display it for 50 frames */
320 gPlay.bDirtyOSD = true; // let the refresh copy it to LCD 320 gPlay.bDirtyOSD = true; /* let the refresh copy it to LCD */
321 } 321 }
322 } 322 }
323} 323}
324 324
325 325
326// sync the video to the current audio 326/* sync the video to the current audio */
327void SyncVideo(void) 327void SyncVideo(void)
328{ 328{
329 tAudioFrameHeader* pAudioBuf; 329 tAudioFrameHeader* pAudioBuf;
@@ -331,12 +331,12 @@ void SyncVideo(void)
331 pAudioBuf = (tAudioFrameHeader*)(gBuf.pReadAudio); 331 pAudioBuf = (tAudioFrameHeader*)(gBuf.pReadAudio);
332 if (pAudioBuf->magic == AUDIO_MAGIC) 332 if (pAudioBuf->magic == AUDIO_MAGIC)
333 { 333 {
334 gBuf.vidcount = 0; // nothing known 334 gBuf.vidcount = 0; /* nothing known */
335 // sync the video position 335 /* sync the video position */
336 gBuf.pReadVideo = gBuf.pReadAudio + 336 gBuf.pReadVideo = gBuf.pReadAudio +
337 (long)pAudioBuf->associated_video * (long)gFileHdr.blocksize; 337 (long)pAudioBuf->associated_video * (long)gFileHdr.blocksize;
338 338
339 // handle possible wrap 339 /* handle possible wrap */
340 if (gBuf.pReadVideo >= gBuf.pBufEnd) 340 if (gBuf.pReadVideo >= gBuf.pBufEnd)
341 gBuf.pReadVideo -= gBuf.bufsize; 341 gBuf.pReadVideo -= gBuf.bufsize;
342 else if (gBuf.pReadVideo < gBuf.pBufStart) 342 else if (gBuf.pReadVideo < gBuf.pBufStart)
@@ -345,21 +345,21 @@ void SyncVideo(void)
345} 345}
346 346
347 347
348// timer interrupt handler to display a frame 348/* timer interrupt handler to display a frame */
349void timer4_isr(void) 349void timer4_isr(void)
350{ 350{
351 int available; 351 int available;
352 tAudioFrameHeader* pAudioBuf; 352 tAudioFrameHeader* pAudioBuf;
353 int height; // height to display 353 int height; /* height to display */
354 354
355 // reduce height if we have OSD on 355 /* reduce height if we have OSD on */
356 height = gFileHdr.video_height/8; 356 height = gFileHdr.video_height/8;
357 if (gPlay.nTimeOSD > 0) 357 if (gPlay.nTimeOSD > 0)
358 { 358 {
359 gPlay.nTimeOSD--; 359 gPlay.nTimeOSD--;
360 height = MIN(LCD_HEIGHT/8-1, height); // reserve bottom line 360 height = MIN(LCD_HEIGHT/8-1, height); /* reserve bottom line */
361 if (gPlay.bDirtyOSD) 361 if (gPlay.bDirtyOSD)
362 { // OSD to bottom line 362 { /* OSD to bottom line */
363 rb->lcd_blit(gBuf.pOSD, 0, LCD_HEIGHT/8-1, 363 rb->lcd_blit(gBuf.pOSD, 0, LCD_HEIGHT/8-1,
364 LCD_WIDTH, 1, LCD_WIDTH); 364 LCD_WIDTH, 1, LCD_WIDTH);
365 gPlay.bDirtyOSD = false; 365 gPlay.bDirtyOSD = false;
@@ -371,58 +371,58 @@ void timer4_isr(void)
371 371
372 available = Available(gBuf.pReadVideo); 372 available = Available(gBuf.pReadVideo);
373 373
374 // loop to skip audio frame(s) 374 /* loop to skip audio frame(s) */
375 while(1) 375 while(1)
376 { 376 {
377 // just for the statistics 377 /* just for the statistics */
378 if (!gBuf.bEOF && available < gStats.minVideoAvail) 378 if (!gBuf.bEOF && available < gStats.minVideoAvail)
379 gStats.minVideoAvail = available; 379 gStats.minVideoAvail = available;
380 380
381 if (available <= (int)gFileHdr.blocksize) 381 if (available <= (int)gFileHdr.blocksize)
382 { // no data for next frame 382 { /* no data for next frame */
383 383
384 if (gBuf.bEOF && (gFileHdr.flags & FLAG_LOOP)) 384 if (gBuf.bEOF && (gFileHdr.flags & FLAG_LOOP))
385 { // loop now, assuming the looped clip fits in memory 385 { /* loop now, assuming the looped clip fits in memory */
386 gBuf.pReadVideo = gBuf.pBufStart + gFileHdr.video_1st_frame; 386 gBuf.pReadVideo = gBuf.pBufStart + gFileHdr.video_1st_frame;
387 // FixMe: pReadVideo is incremented below 387 /* FixMe: pReadVideo is incremented below */
388 } 388 }
389 else 389 else
390 { 390 {
391 gPlay.bVideoUnderrun = true; 391 gPlay.bVideoUnderrun = true;
392 rb->timer_unregister(); // disable ourselves 392 rb->timer_unregister(); /* disable ourselves */
393 return; // no data available 393 return; /* no data available */
394 } 394 }
395 } 395 }
396 else // normal advance for next time 396 else /* normal advance for next time */
397 { 397 {
398 gBuf.pReadVideo += gFileHdr.blocksize; 398 gBuf.pReadVideo += gFileHdr.blocksize;
399 if (gBuf.pReadVideo >= gBuf.pBufEnd) 399 if (gBuf.pReadVideo >= gBuf.pBufEnd)
400 gBuf.pReadVideo -= gBuf.bufsize; // wraparound 400 gBuf.pReadVideo -= gBuf.bufsize; /* wraparound */
401 available -= gFileHdr.blocksize; 401 available -= gFileHdr.blocksize;
402 } 402 }
403 403
404 if (!gPlay.bHasAudio) 404 if (!gPlay.bHasAudio)
405 break; // no need to skip any audio 405 break; /* no need to skip any audio */
406 406
407 if (gBuf.vidcount) 407 if (gBuf.vidcount)
408 { 408 {
409 // we know the next is a video frame 409 /* we know the next is a video frame */
410 gBuf.vidcount--; 410 gBuf.vidcount--;
411 break; // exit the loop 411 break; /* exit the loop */
412 } 412 }
413 413
414 pAudioBuf = (tAudioFrameHeader*)(gBuf.pReadVideo); 414 pAudioBuf = (tAudioFrameHeader*)(gBuf.pReadVideo);
415 if (pAudioBuf->magic == AUDIO_MAGIC) 415 if (pAudioBuf->magic == AUDIO_MAGIC)
416 { // we ran into audio, can happen after seek 416 { /* we ran into audio, can happen after seek */
417 gBuf.vidcount = pAudioBuf->next_block; 417 gBuf.vidcount = pAudioBuf->next_block;
418 if (gBuf.vidcount) 418 if (gBuf.vidcount)
419 gBuf.vidcount--; // minus the audio block 419 gBuf.vidcount--; /* minus the audio block */
420 } 420 }
421 } // while 421 } /* while */
422} 422}
423 423
424 424
425// ISR function to get more mp3 data 425/* ISR function to get more mp3 data */
426void GetMoreMp3(unsigned char** start, int* size) 426void GetMoreMp3(unsigned char** start, int* size)
427{ 427{
428 int available; 428 int available;
@@ -434,19 +434,19 @@ void GetMoreMp3(unsigned char** start, int* size)
434 434
435 available = Available(gBuf.pReadAudio); 435 available = Available(gBuf.pReadAudio);
436 436
437 // just for the statistics 437 /* just for the statistics */
438 if (!gBuf.bEOF && available < gStats.minAudioAvail) 438 if (!gBuf.bEOF && available < gStats.minAudioAvail)
439 gStats.minAudioAvail = available; 439 gStats.minAudioAvail = available;
440 440
441 if (available < advance + (int)gFileHdr.blocksize || advance == 0) 441 if (available < advance + (int)gFileHdr.blocksize || advance == 0)
442 { 442 {
443 gPlay.bAudioUnderrun = true; 443 gPlay.bAudioUnderrun = true;
444 return; // no data available 444 return; /* no data available */
445 } 445 }
446 446
447 gBuf.pReadAudio += advance; 447 gBuf.pReadAudio += advance;
448 if (gBuf.pReadAudio >= gBuf.pBufEnd) 448 if (gBuf.pReadAudio >= gBuf.pBufEnd)
449 gBuf.pReadAudio -= gBuf.bufsize; // wraparound 449 gBuf.pReadAudio -= gBuf.bufsize; /* wraparound */
450 450
451 *start = gBuf.pReadAudio + gFileHdr.audio_headersize; 451 *start = gBuf.pReadAudio + gFileHdr.audio_headersize;
452 *size = gFileHdr.blocksize - gFileHdr.audio_headersize; 452 *size = gFileHdr.blocksize - gFileHdr.audio_headersize;
@@ -489,23 +489,23 @@ int SeekTo(int fd, int nPos)
489 int read_now, got_now; 489 int read_now, got_now;
490 490
491 if (gPlay.bHasAudio) 491 if (gPlay.bHasAudio)
492 rb->mp3_play_stop(); // stop audio ISR 492 rb->mp3_play_stop(); /* stop audio ISR */
493 if (gPlay.bHasVideo) 493 if (gPlay.bHasVideo)
494 rb->timer_unregister(); // stop the timer 494 rb->timer_unregister(); /* stop the timer */
495 495
496 rb->lseek(fd, nPos, SEEK_SET); 496 rb->lseek(fd, nPos, SEEK_SET);
497 497
498 gBuf.pBufFill = gBuf.pBufStart; // all empty 498 gBuf.pBufFill = gBuf.pBufStart; /* all empty */
499 gBuf.pReadVideo = gBuf.pReadAudio = gBuf.pBufStart; 499 gBuf.pReadVideo = gBuf.pReadAudio = gBuf.pBufStart;
500 500
501 read_now = gBuf.low_water - 1; // less than low water, so loading will continue 501 read_now = gBuf.low_water - 1; /* less than low water, so loading will continue */
502 read_now -= read_now % gBuf.granularity; // round down to granularity 502 read_now -= read_now % gBuf.granularity; /* round down to granularity */
503 got_now = rb->read(fd, gBuf.pBufFill, read_now); 503 got_now = rb->read(fd, gBuf.pBufFill, read_now);
504 gBuf.bEOF = (read_now != got_now); 504 gBuf.bEOF = (read_now != got_now);
505 gBuf.pBufFill += got_now; 505 gBuf.pBufFill += got_now;
506 506
507 if (nPos == 0) 507 if (nPos == 0)
508 { // we seeked to the start 508 { /* we seeked to the start */
509 if (gPlay.bHasVideo) 509 if (gPlay.bHasVideo)
510 gBuf.pReadVideo += gFileHdr.video_1st_frame; 510 gBuf.pReadVideo += gFileHdr.video_1st_frame;
511 511
@@ -513,31 +513,31 @@ int SeekTo(int fd, int nPos)
513 gBuf.pReadAudio += gFileHdr.audio_1st_frame; 513 gBuf.pReadAudio += gFileHdr.audio_1st_frame;
514 } 514 }
515 else 515 else
516 { // we have to search for the positions 516 { /* we have to search for the positions */
517 if (gPlay.bHasAudio) // prepare audio playback, if contained 517 if (gPlay.bHasAudio) /* prepare audio playback, if contained */
518 { 518 {
519 // search for audio frame 519 /* search for audio frame */
520 while (((tAudioFrameHeader*)(gBuf.pReadAudio))->magic != AUDIO_MAGIC) 520 while (((tAudioFrameHeader*)(gBuf.pReadAudio))->magic != AUDIO_MAGIC)
521 gBuf.pReadAudio += gFileHdr.blocksize; 521 gBuf.pReadAudio += gFileHdr.blocksize;
522 522
523 if (gPlay.bHasVideo) 523 if (gPlay.bHasVideo)
524 SyncVideo(); // pick the right video for that 524 SyncVideo(); /* pick the right video for that */
525 } 525 }
526 } 526 }
527 527
528 // synchronous start 528 /* synchronous start */
529 gPlay.state = playing; 529 gPlay.state = playing;
530 if (gPlay.bHasAudio) 530 if (gPlay.bHasAudio)
531 { 531 {
532 gPlay.bAudioUnderrun = false; 532 gPlay.bAudioUnderrun = false;
533 rb->mp3_play_data(gBuf.pReadAudio + gFileHdr.audio_headersize, 533 rb->mp3_play_data(gBuf.pReadAudio + gFileHdr.audio_headersize,
534 gFileHdr.blocksize - gFileHdr.audio_headersize, GetMoreMp3); 534 gFileHdr.blocksize - gFileHdr.audio_headersize, GetMoreMp3);
535 rb->mp3_play_pause(true); // kickoff audio 535 rb->mp3_play_pause(true); /* kickoff audio */
536 } 536 }
537 if (gPlay.bHasVideo) 537 if (gPlay.bHasVideo)
538 { 538 {
539 gPlay.bVideoUnderrun = false; 539 gPlay.bVideoUnderrun = false;
540 // start display interrupt 540 /* start display interrupt */
541#if FREQ == 12000000 /* Ondio speed kludge */ 541#if FREQ == 12000000 /* Ondio speed kludge */
542 rb->timer_register(1, NULL, gPlay.nFrameTimeAdjusted, 1, timer4_isr); 542 rb->timer_register(1, NULL, gPlay.nFrameTimeAdjusted, 1, timer4_isr);
543#else 543#else
@@ -548,25 +548,25 @@ int SeekTo(int fd, int nPos)
548 return 0; 548 return 0;
549} 549}
550 550
551// called from default_event_handler_ex() or at end of playback 551/* called from default_event_handler_ex() or at end of playback */
552void Cleanup(void *fd) 552void Cleanup(void *fd)
553{ 553{
554 rb->close(*(int*)fd); // close the file 554 rb->close(*(int*)fd); /* close the file */
555 555
556 if (gPlay.bHasVideo) 556 if (gPlay.bHasVideo)
557 rb->timer_unregister(); // stop video ISR, now I can use the display again 557 rb->timer_unregister(); /* stop video ISR, now I can use the display again */
558 558
559 if (gPlay.bHasAudio) 559 if (gPlay.bHasAudio)
560 rb->mp3_play_stop(); // stop audio ISR 560 rb->mp3_play_stop(); /* stop audio ISR */
561 561
562 // restore normal backlight setting 562 /* restore normal backlight setting */
563 rb->backlight_set_timeout(rb->global_settings->backlight_timeout); 563 rb->backlight_set_timeout(rb->global_settings->backlight_timeout);
564 564
565 // restore normal contrast 565 /* restore normal contrast */
566 rb->lcd_set_contrast(rb->global_settings->contrast); 566 rb->lcd_set_contrast(rb->global_settings->contrast);
567} 567}
568 568
569// returns >0 if continue, =0 to stop, <0 to abort (USB) 569/* returns >0 if continue, =0 to stop, <0 to abort (USB) */
570int PlayTick(int fd) 570int PlayTick(int fd)
571{ 571{
572 int button; 572 int button;
@@ -575,7 +575,7 @@ int PlayTick(int fd)
575 int retval = 1; 575 int retval = 1;
576 int filepos; 576 int filepos;
577 577
578 // check buffer level 578 /* check buffer level */
579 579
580 if (gPlay.bHasAudio) 580 if (gPlay.bHasAudio)
581 avail_audio = Available(gBuf.pReadAudio); 581 avail_audio = Available(gBuf.pReadAudio);
@@ -593,41 +593,41 @@ int PlayTick(int fd)
593 && gBuf.bEOF) 593 && gBuf.bEOF)
594 { 594 {
595 if (gFileHdr.resume_pos) 595 if (gFileHdr.resume_pos)
596 { // we played til the end, clear resume position 596 { /* we played til the end, clear resume position */
597 gFileHdr.resume_pos = 0; 597 gFileHdr.resume_pos = 0;
598 rb->lseek(fd, 0, SEEK_SET); // save resume position 598 rb->lseek(fd, 0, SEEK_SET); /* save resume position */
599 rb->write(fd, &gFileHdr, sizeof(gFileHdr)); 599 rb->write(fd, &gFileHdr, sizeof(gFileHdr));
600 } 600 }
601 Cleanup(&fd); 601 Cleanup(&fd);
602 return 0; // all expired 602 return 0; /* all expired */
603 } 603 }
604 604
605 if (!gPlay.bRefilling || gBuf.bEOF) 605 if (!gPlay.bRefilling || gBuf.bEOF)
606 { // nothing to do 606 { /* nothing to do */
607 button = rb->button_get_w_tmo(HZ/10); 607 button = rb->button_get_w_tmo(HZ/10);
608 } 608 }
609 else 609 else
610 { // refill buffer 610 { /* refill buffer */
611 int read_now, got_now; 611 int read_now, got_now;
612 int buf_free; 612 int buf_free;
613 long spinup; // measure the spinup time 613 long spinup; /* measure the spinup time */
614 614
615 // how much can we reload, don't fill completely, would appear empty 615 /* how much can we reload, don't fill completely, would appear empty */
616 buf_free = gBuf.bufsize - MAX(avail_audio, avail_video) - gBuf.high_water; 616 buf_free = gBuf.bufsize - MAX(avail_audio, avail_video) - gBuf.high_water;
617 if (buf_free < 0) 617 if (buf_free < 0)
618 buf_free = 0; // just for safety 618 buf_free = 0; /* just for safety */
619 buf_free -= buf_free % gBuf.granularity; // round down to granularity 619 buf_free -= buf_free % gBuf.granularity; /* round down to granularity */
620 620
621 // in one piece max. up to buffer end (wrap after that) 621 /* in one piece max. up to buffer end (wrap after that) */
622 read_now = MIN(buf_free, gBuf.pBufEnd - gBuf.pBufFill); 622 read_now = MIN(buf_free, gBuf.pBufEnd - gBuf.pBufFill);
623 623
624 // load piecewise, to stay responsive 624 /* load piecewise, to stay responsive */
625 read_now = MIN(read_now, gBuf.nReadChunk); 625 read_now = MIN(read_now, gBuf.nReadChunk);
626 626
627 if (read_now == buf_free) 627 if (read_now == buf_free)
628 gPlay.bRefilling = false; // last piece requested 628 gPlay.bRefilling = false; /* last piece requested */
629 629
630 spinup = *rb->current_tick; // in case this is interesting below 630 spinup = *rb->current_tick; /* in case this is interesting below */
631 631
632 got_now = rb->read(fd, gBuf.pBufFill, read_now); 632 got_now = rb->read(fd, gBuf.pBufFill, read_now);
633 if (got_now != read_now || read_now == 0) 633 if (got_now != read_now || read_now == 0)
@@ -636,7 +636,7 @@ int PlayTick(int fd)
636 gPlay.bRefilling = false; 636 gPlay.bRefilling = false;
637 } 637 }
638 638
639 if (gPlay.bDiskSleep) // statistics about the spinup time 639 if (gPlay.bDiskSleep) /* statistics about the spinup time */
640 { 640 {
641 spinup = *rb->current_tick - spinup; 641 spinup = *rb->current_tick - spinup;
642 gPlay.bDiskSleep = false; 642 gPlay.bDiskSleep = false;
@@ -645,49 +645,48 @@ int PlayTick(int fd)
645 if (spinup < gStats.minSpinup) 645 if (spinup < gStats.minSpinup)
646 gStats.minSpinup = spinup; 646 gStats.minSpinup = spinup;
647 647
648 // recalculate the low water mark from real measurements 648 /* recalculate the low water mark from real measurements */
649 gBuf.low_water = (gStats.maxSpinup + gBuf.spinup_safety) 649 gBuf.low_water = (gStats.maxSpinup + gBuf.spinup_safety)
650 * gFileHdr.bps_peak / 8 / HZ; 650 * gFileHdr.bps_peak / 8 / HZ;
651 } 651 }
652 652
653 if (!gPlay.bRefilling 653 if (!gPlay.bRefilling
654 && rb->global_settings->disk_spindown < 20) // condition for test only 654 && rb->global_settings->disk_spindown < 20) /* condition for test only */
655 { 655 {
656 rb->ata_sleep(); // no point in leaving the disk run til timeout 656 rb->ata_sleep(); /* no point in leaving the disk run til timeout */
657 gPlay.bDiskSleep = true; 657 gPlay.bDiskSleep = true;
658 } 658 }
659 659
660 gBuf.pBufFill += got_now; 660 gBuf.pBufFill += got_now;
661 if (gBuf.pBufFill >= gBuf.pBufEnd) 661 if (gBuf.pBufFill >= gBuf.pBufEnd)
662 gBuf.pBufFill = gBuf.pBufStart; // wrap 662 gBuf.pBufFill = gBuf.pBufStart; /* wrap */
663 663
664 rb->yield(); // have mercy with the other threads 664 rb->yield(); /* have mercy with the other threads */
665 button = rb->button_get(false); 665 button = rb->button_get(false);
666 } 666 }
667 667
668 // check keypresses 668 /* check keypresses */
669 669
670 if (button != BUTTON_NONE) 670 if (button != BUTTON_NONE)
671 { 671 {
672 filepos = rb->lseek(fd, 0, SEEK_CUR); 672 filepos = rb->lseek(fd, 0, SEEK_CUR);
673 673
674 if (gPlay.bHasVideo) // video position is more accurate 674 if (gPlay.bHasVideo) /* video position is more accurate */
675 filepos -= Available(gBuf.pReadVideo); // take video position 675 filepos -= Available(gBuf.pReadVideo); /* take video position */
676 else 676 else
677 filepos -= Available(gBuf.pReadAudio); // else audio 677 filepos -= Available(gBuf.pReadAudio); /* else audio */
678 678
679 switch (button) 679 switch (button) { /* set exit conditions */
680 { // set exit conditions
681 case BUTTON_OFF: 680 case BUTTON_OFF:
682 if (gFileHdr.magic == HEADER_MAGIC // only if file has header 681 if (gFileHdr.magic == HEADER_MAGIC /* only if file has header */
683 && !(gFileHdr.flags & FLAG_LOOP)) // not for stills 682 && !(gFileHdr.flags & FLAG_LOOP)) /* not for stills */
684 { 683 {
685 gFileHdr.resume_pos = filepos; 684 gFileHdr.resume_pos = filepos;
686 rb->lseek(fd, 0, SEEK_SET); // save resume position 685 rb->lseek(fd, 0, SEEK_SET); /* save resume position */
687 rb->write(fd, &gFileHdr, sizeof(gFileHdr)); 686 rb->write(fd, &gFileHdr, sizeof(gFileHdr));
688 } 687 }
689 Cleanup(&fd); 688 Cleanup(&fd);
690 retval = 0; // signal "stopped" to caller 689 retval = 0; /* signal "stopped" to caller */
691 break; 690 break;
692 case VIDEO_STOP_SEEK: 691 case VIDEO_STOP_SEEK:
693#ifdef VIDEO_STOP_SEEK_PRE 692#ifdef VIDEO_STOP_SEEK_PRE
@@ -704,9 +703,9 @@ int PlayTick(int fd)
704 { 703 {
705 gPlay.state = paused; 704 gPlay.state = paused;
706 if (gPlay.bHasAudio) 705 if (gPlay.bHasAudio)
707 rb->mp3_play_pause(false); // pause audio 706 rb->mp3_play_pause(false); /* pause audio */
708 if (gPlay.bHasVideo) 707 if (gPlay.bHasVideo)
709 rb->timer_unregister(); // stop the timer 708 rb->timer_unregister(); /* stop the timer */
710 } 709 }
711 else if (gPlay.state == paused) 710 else if (gPlay.state == paused)
712 { 711 {
@@ -715,10 +714,10 @@ int PlayTick(int fd)
715 { 714 {
716 if (gPlay.bHasVideo) 715 if (gPlay.bHasVideo)
717 SyncVideo(); 716 SyncVideo();
718 rb->mp3_play_pause(true); // play audio 717 rb->mp3_play_pause(true); /* play audio */
719 } 718 }
720 if (gPlay.bHasVideo) 719 if (gPlay.bHasVideo)
721 { // start the video 720 { /* start the video */
722#if FREQ == 12000000 /* Ondio speed kludge */ 721#if FREQ == 12000000 /* Ondio speed kludge */
723 rb->timer_register(1, NULL, 722 rb->timer_register(1, NULL,
724 gPlay.nFrameTimeAdjusted, 1, timer4_isr); 723 gPlay.nFrameTimeAdjusted, 1, timer4_isr);
@@ -741,44 +740,44 @@ int PlayTick(int fd)
741 break; 740 break;
742 case BUTTON_LEFT: 741 case BUTTON_LEFT:
743 case BUTTON_LEFT | BUTTON_REPEAT: 742 case BUTTON_LEFT | BUTTON_REPEAT:
744 if (!gPlay.bSeeking) // prepare seek 743 if (!gPlay.bSeeking) /* prepare seek */
745 { 744 {
746 gPlay.nSeekPos = filepos; 745 gPlay.nSeekPos = filepos;
747 gPlay.bSeeking = true; 746 gPlay.bSeeking = true;
748 gPlay.nSeekAcc = 0; 747 gPlay.nSeekAcc = 0;
749 } 748 }
750 else if (gPlay.nSeekAcc > 0) // other direction, stop sliding 749 else if (gPlay.nSeekAcc > 0) /* other direction, stop sliding */
751 gPlay.nSeekAcc = 0; 750 gPlay.nSeekAcc = 0;
752 else 751 else
753 gPlay.nSeekAcc--; 752 gPlay.nSeekAcc--;
754 break; 753 break;
755 case BUTTON_RIGHT: 754 case BUTTON_RIGHT:
756 case BUTTON_RIGHT | BUTTON_REPEAT: 755 case BUTTON_RIGHT | BUTTON_REPEAT:
757 if (!gPlay.bSeeking) // prepare seek 756 if (!gPlay.bSeeking) /* prepare seek */
758 { 757 {
759 gPlay.nSeekPos = filepos; 758 gPlay.nSeekPos = filepos;
760 gPlay.bSeeking = true; 759 gPlay.bSeeking = true;
761 gPlay.nSeekAcc = 0; 760 gPlay.nSeekAcc = 0;
762 } 761 }
763 else if (gPlay.nSeekAcc < 0) // other direction, stop sliding 762 else if (gPlay.nSeekAcc < 0) /* other direction, stop sliding */
764 gPlay.nSeekAcc = 0; 763 gPlay.nSeekAcc = 0;
765 else 764 else
766 gPlay.nSeekAcc++; 765 gPlay.nSeekAcc++;
767 break; 766 break;
768#ifdef VIDEO_DEBUG 767#ifdef VIDEO_DEBUG
769 case VIDEO_DEBUG: // debug key 768 case VIDEO_DEBUG: /* debug key */
770 case VIDEO_DEBUG | BUTTON_REPEAT: 769 case VIDEO_DEBUG | BUTTON_REPEAT:
771 DrawBuf(); // show buffer status 770 DrawBuf(); /* show buffer status */
772 gPlay.nTimeOSD = 30; 771 gPlay.nTimeOSD = 30;
773 gPlay.bDirtyOSD = true; 772 gPlay.bDirtyOSD = true;
774 break; 773 break;
775#endif 774#endif
776 case VIDEO_CONTRAST_DOWN: // contrast down 775 case VIDEO_CONTRAST_DOWN: /* contrast down */
777 case VIDEO_CONTRAST_DOWN | BUTTON_REPEAT: 776 case VIDEO_CONTRAST_DOWN | BUTTON_REPEAT:
778 if (gPlay.bHasVideo) 777 if (gPlay.bHasVideo)
779 ChangeContrast(-1); 778 ChangeContrast(-1);
780 break; 779 break;
781 case VIDEO_CONTRAST_UP: // contrast up 780 case VIDEO_CONTRAST_UP: /* contrast up */
782 case VIDEO_CONTRAST_UP | BUTTON_REPEAT: 781 case VIDEO_CONTRAST_UP | BUTTON_REPEAT:
783 if (gPlay.bHasVideo) 782 if (gPlay.bHasVideo)
784 ChangeContrast(1); 783 ChangeContrast(1);
@@ -786,7 +785,7 @@ int PlayTick(int fd)
786 default: 785 default:
787 if (rb->default_event_handler_ex(button, Cleanup, &fd) 786 if (rb->default_event_handler_ex(button, Cleanup, &fd)
788 == SYS_USB_CONNECTED) 787 == SYS_USB_CONNECTED)
789 retval = -1; // signal "aborted" to caller 788 retval = -1; /* signal "aborted" to caller */
790 break; 789 break;
791 } 790 }
792 791
@@ -794,9 +793,9 @@ int PlayTick(int fd)
794 } /* if (button != BUTTON_NONE) */ 793 } /* if (button != BUTTON_NONE) */
795 794
796 795
797 // handle seeking 796 /* handle seeking */
798 797
799 if (gPlay.bSeeking) // seeking? 798 if (gPlay.bSeeking) /* seeking? */
800 { 799 {
801 if (gPlay.nSeekAcc < -MAX_ACC) 800 if (gPlay.nSeekAcc < -MAX_ACC)
802 gPlay.nSeekAcc = -MAX_ACC; 801 gPlay.nSeekAcc = -MAX_ACC;
@@ -815,23 +814,23 @@ int PlayTick(int fd)
815 } 814 }
816 815
817 816
818 // check + recover underruns 817 /* check + recover underruns */
819 818
820 if ((gPlay.bAudioUnderrun || gPlay.bVideoUnderrun) && !gBuf.bEOF) 819 if ((gPlay.bAudioUnderrun || gPlay.bVideoUnderrun) && !gBuf.bEOF)
821 { 820 {
822 gBuf.spinup_safety += HZ/2; // add extra spinup time for the future 821 gBuf.spinup_safety += HZ/2; /* add extra spinup time for the future */
823 filepos = rb->lseek(fd, 0, SEEK_CUR); 822 filepos = rb->lseek(fd, 0, SEEK_CUR);
824 823
825 if (gPlay.bHasVideo && gPlay.bVideoUnderrun) 824 if (gPlay.bHasVideo && gPlay.bVideoUnderrun)
826 { 825 {
827 gStats.nVideoUnderruns++; 826 gStats.nVideoUnderruns++;
828 filepos -= Available(gBuf.pReadVideo); // take video position 827 filepos -= Available(gBuf.pReadVideo); /* take video position */
829 SeekTo(fd, filepos); 828 SeekTo(fd, filepos);
830 } 829 }
831 else if (gPlay.bHasAudio && gPlay.bAudioUnderrun) 830 else if (gPlay.bHasAudio && gPlay.bAudioUnderrun)
832 { 831 {
833 gStats.nAudioUnderruns++; 832 gStats.nAudioUnderruns++;
834 filepos -= Available(gBuf.pReadAudio); // else audio 833 filepos -= Available(gBuf.pReadAudio); /* else audio */
835 SeekTo(fd, filepos); 834 SeekTo(fd, filepos);
836 } 835 }
837 } 836 }
@@ -848,46 +847,46 @@ int main(char* filename)
848 int button = 0; 847 int button = 0;
849 int retval; 848 int retval;
850 849
851 // try to open the file 850 /* try to open the file */
852 fd = rb->open(filename, O_RDWR); 851 fd = rb->open(filename, O_RDWR);
853 if (fd < 0) 852 if (fd < 0)
854 return PLUGIN_ERROR; 853 return PLUGIN_ERROR;
855 file_size = rb->filesize(fd); 854 file_size = rb->filesize(fd);
856 855
857 // reset pitch value to ensure synchronous playback 856 /* reset pitch value to ensure synchronous playback */
858 rb->sound_set_pitch(1000); 857 rb->sound_set_pitch(1000);
859 858
860 // init statistics 859 /* init statistics */
861 rb->memset(&gStats, 0, sizeof(gStats)); 860 rb->memset(&gStats, 0, sizeof(gStats));
862 gStats.minAudioAvail = gStats.minVideoAvail = INT_MAX; 861 gStats.minAudioAvail = gStats.minVideoAvail = INT_MAX;
863 gStats.minSpinup = INT_MAX; 862 gStats.minSpinup = INT_MAX;
864 863
865 // init playback state 864 /* init playback state */
866 rb->memset(&gPlay, 0, sizeof(gPlay)); 865 rb->memset(&gPlay, 0, sizeof(gPlay));
867 866
868 // init buffer 867 /* init buffer */
869 rb->memset(&gBuf, 0, sizeof(gBuf)); 868 rb->memset(&gBuf, 0, sizeof(gBuf));
870 gBuf.pOSD = rb->lcd_framebuffer + LCD_WIDTH*7; // last screen line 869 gBuf.pOSD = rb->lcd_framebuffer + LCD_WIDTH*7; /* last screen line */
871 gBuf.pBufStart = rb->plugin_get_audio_buffer(&gBuf.bufsize); 870 gBuf.pBufStart = rb->plugin_get_audio_buffer(&gBuf.bufsize);
872 //gBuf.bufsize = 1700*1024; // test, like 2MB version!!!! 871 /*gBuf.bufsize = 1700*1024; // test, like 2MB version!!!! */
873 gBuf.pBufFill = gBuf.pBufStart; // all empty 872 gBuf.pBufFill = gBuf.pBufStart; /* all empty */
874 873
875 // load file header 874 /* load file header */
876 read_now = sizeof(gFileHdr); 875 read_now = sizeof(gFileHdr);
877 got_now = rb->read(fd, &gFileHdr, read_now); 876 got_now = rb->read(fd, &gFileHdr, read_now);
878 rb->lseek(fd, 0, SEEK_SET); // rewind to restart sector-aligned 877 rb->lseek(fd, 0, SEEK_SET); /* rewind to restart sector-aligned */
879 if (got_now != read_now) 878 if (got_now != read_now)
880 { 879 {
881 rb->close(fd); 880 rb->close(fd);
882 return (PLUGIN_ERROR); 881 return (PLUGIN_ERROR);
883 } 882 }
884 883
885 // check header 884 /* check header */
886 if (gFileHdr.magic != HEADER_MAGIC) 885 if (gFileHdr.magic != HEADER_MAGIC)
887 { // old file, use default info 886 { /* old file, use default info */
888 rb->memset(&gFileHdr, 0, sizeof(gFileHdr)); 887 rb->memset(&gFileHdr, 0, sizeof(gFileHdr));
889 gFileHdr.blocksize = SCREENSIZE; 888 gFileHdr.blocksize = SCREENSIZE;
890 if (file_size < SCREENSIZE * FPS) // less than a second 889 if (file_size < SCREENSIZE * FPS) /* less than a second */
891 gFileHdr.flags |= FLAG_LOOP; 890 gFileHdr.flags |= FLAG_LOOP;
892 gFileHdr.video_format = VIDEOFORMAT_RAW; 891 gFileHdr.video_format = VIDEOFORMAT_RAW;
893 gFileHdr.video_width = LCD_WIDTH; 892 gFileHdr.video_width = LCD_WIDTH;
@@ -900,60 +899,60 @@ int main(char* filename)
900 gPlay.nFrameTimeAdjusted = (gFileHdr.video_frametime * 625) / 576; 899 gPlay.nFrameTimeAdjusted = (gFileHdr.video_frametime * 625) / 576;
901#endif 900#endif
902 901
903 // continue buffer init: align the end, calc low water, read sizes 902 /* continue buffer init: align the end, calc low water, read sizes */
904 gBuf.granularity = gFileHdr.blocksize; 903 gBuf.granularity = gFileHdr.blocksize;
905 while (gBuf.granularity % 512) // common multiple of sector size 904 while (gBuf.granularity % 512) /* common multiple of sector size */
906 gBuf.granularity *= 2; 905 gBuf.granularity *= 2;
907 gBuf.bufsize -= gBuf.bufsize % gBuf.granularity; // round down 906 gBuf.bufsize -= gBuf.bufsize % gBuf.granularity; /* round down */
908 gBuf.pBufEnd = gBuf.pBufStart + gBuf.bufsize; 907 gBuf.pBufEnd = gBuf.pBufStart + gBuf.bufsize;
909 gBuf.low_water = SPINUP_INIT * gFileHdr.bps_peak / 8000; 908 gBuf.low_water = SPINUP_INIT * gFileHdr.bps_peak / 8000;
910 gBuf.spinup_safety = SPINUP_SAFETY * HZ / 1000; // in time ticks 909 gBuf.spinup_safety = SPINUP_SAFETY * HZ / 1000; /* in time ticks */
911 if (gFileHdr.audio_min_associated < 0) 910 if (gFileHdr.audio_min_associated < 0)
912 gBuf.high_water = 0 - gFileHdr.audio_min_associated; 911 gBuf.high_water = 0 - gFileHdr.audio_min_associated;
913 else 912 else
914 gBuf.high_water = 1; // never fill buffer completely, would appear empty 913 gBuf.high_water = 1; /* never fill buffer completely, would appear empty */
915 gBuf.nReadChunk = (CHUNK + gBuf.granularity - 1); // round up 914 gBuf.nReadChunk = (CHUNK + gBuf.granularity - 1); /* round up */
916 gBuf.nReadChunk -= gBuf.nReadChunk % gBuf.granularity;// and align 915 gBuf.nReadChunk -= gBuf.nReadChunk % gBuf.granularity;/* and align */
917 gBuf.nSeekChunk = rb->filesize(fd) / FF_TICKS; 916 gBuf.nSeekChunk = rb->filesize(fd) / FF_TICKS;
918 gBuf.nSeekChunk += gBuf.granularity - 1; // round up 917 gBuf.nSeekChunk += gBuf.granularity - 1; /* round up */
919 gBuf.nSeekChunk -= gBuf.nSeekChunk % gBuf.granularity; // and align 918 gBuf.nSeekChunk -= gBuf.nSeekChunk % gBuf.granularity; /* and align */
920 919
921 // prepare video playback, if contained 920 /* prepare video playback, if contained */
922 if (gFileHdr.video_format == VIDEOFORMAT_RAW) 921 if (gFileHdr.video_format == VIDEOFORMAT_RAW)
923 { 922 {
924 gPlay.bHasVideo = true; 923 gPlay.bHasVideo = true;
925 if (rb->global_settings->backlight_timeout > 0) 924 if (rb->global_settings->backlight_timeout > 0)
926 rb->backlight_set_timeout(1); // keep the light on 925 rb->backlight_set_timeout(1); /* keep the light on */
927 } 926 }
928 927
929 // prepare audio playback, if contained 928 /* prepare audio playback, if contained */
930 if (gFileHdr.audio_format == AUDIOFORMAT_MP3_BITSWAPPED) 929 if (gFileHdr.audio_format == AUDIOFORMAT_MP3_BITSWAPPED)
931 { 930 {
932 gPlay.bHasAudio = true; 931 gPlay.bHasAudio = true;
933 } 932 }
934 933
935 // start playback by seeking to zero or resume position 934 /* start playback by seeking to zero or resume position */
936 if (gFileHdr.resume_pos && WantResume(fd)) // ask the user 935 if (gFileHdr.resume_pos && WantResume(fd)) /* ask the user */
937 SeekTo(fd, gFileHdr.resume_pos); 936 SeekTo(fd, gFileHdr.resume_pos);
938 else 937 else
939 SeekTo(fd, 0); 938 SeekTo(fd, 0);
940 939
941 // all that's left to do is keep the buffer full 940 /* all that's left to do is keep the buffer full */
942 do // the main loop 941 do /* the main loop */
943 { 942 {
944 retval = PlayTick(fd); 943 retval = PlayTick(fd);
945 } while (retval > 0); 944 } while (retval > 0);
946 945
947 if (retval < 0) // aborted? 946 if (retval < 0) /* aborted? */
948 { 947 {
949 return PLUGIN_USB_CONNECTED; 948 return PLUGIN_USB_CONNECTED;
950 } 949 }
951 950
952#ifndef DEBUG // for release compilations, only display the stats in case of error 951#ifndef DEBUG /* for release compilations, only display the stats in case of error */
953 if (gStats.nAudioUnderruns || gStats.nVideoUnderruns) 952 if (gStats.nAudioUnderruns || gStats.nVideoUnderruns)
954#endif 953#endif
955 { 954 {
956 // display statistics 955 /* display statistics */
957 rb->lcd_clear_display(); 956 rb->lcd_clear_display();
958 rb->snprintf(gPrint, sizeof(gPrint), "%d Audio Underruns", gStats.nAudioUnderruns); 957 rb->snprintf(gPrint, sizeof(gPrint), "%d Audio Underruns", gStats.nAudioUnderruns);
959 rb->lcd_puts(0, 0, gPrint); 958 rb->lcd_puts(0, 0, gPrint);
@@ -983,7 +982,7 @@ int main(char* filename)
983 982
984enum plugin_status plugin_start(struct plugin_api* api, void* parameter) 983enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
985{ 984{
986 rb = api; // copy to global api pointer 985 rb = api; /* copy to global api pointer */
987 986
988 if (parameter == NULL) 987 if (parameter == NULL)
989 { 988 {
@@ -991,10 +990,10 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
991 return PLUGIN_ERROR; 990 return PLUGIN_ERROR;
992 } 991 }
993 992
994 // now go ahead and have fun! 993 /* now go ahead and have fun! */
995 return main((char*) parameter); 994 return main((char*) parameter);
996} 995}
997 996
998#endif // #ifdef HAVE_LCD_BITMAP 997#endif /* #ifdef HAVE_LCD_BITMAP */
999#endif // #ifndef SIMULATOR 998#endif /* #ifndef SIMULATOR */
1000 999
diff --git a/apps/plugins/wav2wv.c b/apps/plugins/wav2wv.c
index 812ed176c4..7e85572d78 100644
--- a/apps/plugins/wav2wv.c
+++ b/apps/plugins/wav2wv.c
@@ -161,7 +161,7 @@ static int wav2wv (char *filename)
161 num_chans = config.num_channels = native_header.NumChannels; 161 num_chans = config.num_channels = native_header.NumChannels;
162 total_samples = native_header.data_ckSize / native_header.BlockAlign; 162 total_samples = native_header.data_ckSize / native_header.BlockAlign;
163 163
164// config.flags |= CONFIG_HIGH_FLAG; 164/* config.flags |= CONFIG_HIGH_FLAG; */
165 165
166 if (!WavpackSetConfiguration (wpc, &config, total_samples)) { 166 if (!WavpackSetConfiguration (wpc, &config, total_samples)) {
167 rb->splash(HZ*2, true, "internal error!"); 167 rb->splash(HZ*2, true, "internal error!");