From 220fafdd72eab05eb49cf6811d15d6618a168910 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 3 Mar 2006 08:14:44 +0000 Subject: [PATCH] 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 --- apps/plugins/fire.c | 2 +- apps/plugins/firmware_flash.c | 4 +- apps/plugins/grayscale.c | 4 +- apps/plugins/jpeg.c | 8 +- apps/plugins/mandelbrot.c | 12 +- apps/plugins/metronome.c | 4 +- apps/plugins/midi2wav.c | 12 +- apps/plugins/minesweeper.c | 6 +- apps/plugins/mp3_encoder.c | 134 ++-- apps/plugins/plasma.c | 2 +- apps/plugins/star.c | 12 +- apps/plugins/starfield.c | 4 +- apps/plugins/sudoku.c | 1367 +++++++++++++++++---------------- apps/plugins/video.c | 485 ++++++------ apps/plugins/wav2wv.c | 2 +- 15 files changed, 1052 insertions(+), 1006 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) return ret; } -#endif // #ifdef HAVE_LCD_BITMAP +#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) } if (fileleft == 256*1024) - { // original dumped firmware file has no CRC nor platform ID + { /* original dumped firmware file has no CRC nor platform ID */ has_crc = false; } else { has_crc = true; - fileleft -= sizeof(unsigned); // exclude the last 4 bytes + fileleft -= sizeof(unsigned); /* exclude the last 4 bytes */ } /* 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) enum plugin_status plugin_start(struct plugin_api* api, void* parameter) { - rb = api; // copy to global api pointer + rb = api; /* copy to global api pointer */ (void)parameter; return main(); } -#endif // #ifdef HAVE_LCD_BITMAP +#endif /* #ifdef HAVE_LCD_BITMAP */ 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) } else { - // error + /* error */ } } @@ -1429,7 +1429,7 @@ int jpeg_decode(struct jpeg* p_jpeg, unsigned char* p_pixel[3], int k_need; /* AC coefficients needed up to here */ int zero_need; /* init the block with this many zeros */ - int last_dc_val[3] = {0, 0, 0}; // or 128 for chroma? + int last_dc_val[3] = {0, 0, 0}; /* or 128 for chroma? */ int store_offs[4]; /* memory offsets: order of Y11 Y12 Y21 Y22 U V */ int restart = p_jpeg->restart_interval; /* MCUs until restart marker */ @@ -1483,7 +1483,7 @@ int jpeg_decode(struct jpeg* p_jpeg, unsigned char* p_pixel[3], for(y=0; yy_mbl && bs.next_input_byte <= bs.input_end; y++) { - for (i=0; i<3; i++) // scan line init + for (i=0; i<3; i++) /* scan line init */ { p_byte[i] = p_line[i]; p_line[i] += skip_strip[i]; @@ -1567,7 +1567,7 @@ int jpeg_decode(struct jpeg* p_jpeg, unsigned char* p_pixel[3], skip_line[ci]); } } /* for blkn */ - p_byte[0] += skip_mcu[0]; // unrolled for (i=0; i<3; i++) loop + p_byte[0] += skip_mcu[0]; /* unrolled for (i=0; i<3; i++) loop */ p_byte[1] += skip_mcu[1]; p_byte[2] += skip_mcu[2]; 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) void init_mandelbrot_set(void) { #if CONFIG_LCD == LCD_SSD1815 /* Recorder, Ondio. */ - x_min = -38L<<22; // -2.375<<26 - x_max = 15L<<22; // 0.9375<<26 + x_min = -38L<<22; /* -2.375<<26 */ + x_max = 15L<<22; /* 0.9375<<26 */ #else /* all others (square pixels) */ - x_min = -36L<<22; // -2.25<<26 - x_max = 12L<<22; // 0.75<<26 + x_min = -36L<<22; /* -2.25<<26 */ + x_max = 12L<<22; /* 0.75<<26 */ #endif - y_min = -19L<<22; // -1.1875<<26 - y_max = 19L<<22; // 1.1875<<26 + y_min = -19L<<22; /* -1.1875<<26 */ + y_max = 19L<<22; /* 1.1875<<26 */ recalc_parameters(); } 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) { void calc_period(void) { - period = 61440/bpm-1; // (60*1024)/bpm; + period = 61440/bpm-1; /* (60*1024)/bpm; */ } @@ -904,7 +904,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter){ rb = api; if (MET_IS_PLAYING) - MET_PLAY_STOP; // stop audio IS + MET_PLAY_STOP; /* stop audio IS */ #if CONFIG_CODEC != SWCODEC 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 @@ /* Only define LOCAL_DSP on Simulator or else we're asking for trouble */ #if defined(SIMULATOR) /*Enable this to write to the soundcard via a /dsv/dsp symlink in */ - //#define LOCAL_DSP + /*#define LOCAL_DSP */ #endif @@ -39,7 +39,7 @@ #include "../../plugin.h" -//#include "../codecs/lib/xxx2wav.h" +/*#include "../codecs/lib/xxx2wav.h" */ PLUGIN_HEADER @@ -200,14 +200,14 @@ int midimain(void * filename) * why this happens. */ - outputBuffer[outputBufferPosition]=outputSampleOne&0XFF; // Low byte first + outputBuffer[outputBufferPosition]=outputSampleOne&0XFF; /* Low byte first */ outputBufferPosition++; - outputBuffer[outputBufferPosition]=outputSampleOne>>8; //High byte second + outputBuffer[outputBufferPosition]=outputSampleOne>>8; /*High byte second */ outputBufferPosition++; - outputBuffer[outputBufferPosition]=outputSampleTwo&0XFF; // Low byte first + outputBuffer[outputBufferPosition]=outputSampleTwo&0XFF; /* Low byte first */ outputBufferPosition++; - outputBuffer[outputBufferPosition]=outputSampleTwo>>8; //High byte second + outputBuffer[outputBufferPosition]=outputSampleTwo>>8; /*High byte second */ outputBufferPosition++; 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) PLUGIN_HEADER -//what the minesweeper() function can return +/*what the minesweeper() function can return */ #define MINESWEEPER_USB 3 #define MINESWEEPER_QUIT 2 #define MINESWEEPER_LOSE 1 @@ -402,10 +402,10 @@ int minesweeper(void) while(true){ - //clear the screen buffer + /*clear the screen buffer */ rb->lcd_clear_display(); - //display the mine field + /*display the mine field */ for(i=0;i 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 @@ -// Shine is an MP3 encoder -// Copyright (C) 1999-2000 Gabriel Bouvigne -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library General Public -// License as published by the Free Software Foundation; either -// version 2 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Library General Public License for more details. +/* Shine is an MP3 encoder + * Copyright (C) 1999-2000 Gabriel Bouvigne + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. */ #define samp_per_frame 1152 #define samp_per_frame2 576 @@ -112,55 +112,55 @@ struct huffcodetab { }; /* !!!!!!!! start of IRAM area: do not insert before x_int1 array !!!!!!!!!!!!! */ -short x_int0 [HAN_SIZE] IBSS_ATTR; // 1024 Bytes -int mdct_freq [2][2][samp_per_frame2] IBSS_ATTR; // 9216 Bytes -short x_int1 [HAN_SIZE] IBSS_ATTR; // 1024 Bytes +short x_int0 [HAN_SIZE] IBSS_ATTR; /* 1024 Bytes */ +int mdct_freq [2][2][samp_per_frame2] IBSS_ATTR; /* 9216 Bytes */ +short x_int1 [HAN_SIZE] IBSS_ATTR; /* 1024 Bytes */ /* !!!!!!!!!!!!!!!!!!!!! here you may insert other data !!!!!!!!!!!!!!!!!!!!!!! */ -uint8 int2idx [4096] IBSS_ATTR; // 4096 Bytes -enct8 enc_data [2][2][samp_per_frame2] IBSS_ATTR; // 4608 Bytes -short y_int [64] IBSS_ATTR; // 256 Bytes -int off [2] IBSS_ATTR; // 16 Bytes -int scalefac_long[23] IBSS_ATTR; // 96 Bytes -int mdct_in [36] IBSS_ATTR; // 144 Bytes -int sb_sample [2][3][18][SBLIMIT] IBSS_ATTR; // 13824 Bytes -BF_Data CodedData IBSS_ATTR; // 1040 Bytes -int ca_int [8] IBSS_ATTR; // 32 Bytes -int cs_int [8] IBSS_ATTR; // 32 Bytes -int win_int [18][36] IBSS_ATTR; // 2592 Bytes -short filter_int [SBLIMIT][64] IBSS_ATTR; // 8192 Bytes -short enwindow_int[512] IBSS_ATTR; // 1024 Bytes -uint8 ht_count1 [2][2][16] IBSS_ATTR; // 64 Bytes -uint16 t1HB [ 4] IBSS_ATTR; // Bytes -uint16 t2HB [ 9] IBSS_ATTR; // Bytes -uint16 t3HB [ 9] IBSS_ATTR; // Bytes -uint16 t5HB [ 16] IBSS_ATTR; // Bytes -uint16 t6HB [ 16] IBSS_ATTR; // Bytes -uint16 t7HB [ 36] IBSS_ATTR; // Bytes -uint16 t8HB [ 36] IBSS_ATTR; // Bytes -uint16 t9HB [ 36] IBSS_ATTR; // Bytes -uint16 t10HB [ 64] IBSS_ATTR; // Bytes -uint16 t11HB [ 64] IBSS_ATTR; // Bytes -uint16 t12HB [ 64] IBSS_ATTR; // Bytes -uint16 t13HB [256] IBSS_ATTR; // Bytes -uint16 t15HB [256] IBSS_ATTR; // Bytes -uint16 t16HB [256] IBSS_ATTR; // Bytes -uint16 t24HB [256] IBSS_ATTR; // Bytes -uint8 t1l [ 4] IBSS_ATTR; // Bytes -uint8 t2l [ 9] IBSS_ATTR; // Bytes -uint8 t3l [ 9] IBSS_ATTR; // Bytes -uint8 t5l [ 16] IBSS_ATTR; // Bytes -uint8 t6l [ 16] IBSS_ATTR; // Bytes -uint8 t7l [ 36] IBSS_ATTR; // Bytes -uint8 t8l [ 36] IBSS_ATTR; // Bytes -uint8 t9l [ 36] IBSS_ATTR; // Bytes -uint8 t10l [ 64] IBSS_ATTR; // Bytes -uint8 t11l [ 64] IBSS_ATTR; // Bytes -uint8 t12l [ 64] IBSS_ATTR; // Bytes -uint8 t13l [256] IBSS_ATTR; // Bytes -uint8 t15l [256] IBSS_ATTR; // Bytes -uint8 t16l [256] IBSS_ATTR; // Bytes -uint8 t24l [256] IBSS_ATTR; // Bytes -struct huffcodetab ht [HTN] IBSS_ATTR; // Bytes +uint8 int2idx [4096] IBSS_ATTR; /* 4096 Bytes */ +enct8 enc_data [2][2][samp_per_frame2] IBSS_ATTR; /* 4608 Bytes */ +short y_int [64] IBSS_ATTR; /* 256 Bytes */ +int off [2] IBSS_ATTR; /* 16 Bytes */ +int scalefac_long[23] IBSS_ATTR; /* 96 Bytes */ +int mdct_in [36] IBSS_ATTR; /* 144 Bytes */ +int sb_sample [2][3][18][SBLIMIT] IBSS_ATTR; /* 13824 Bytes */ +BF_Data CodedData IBSS_ATTR; /* 1040 Bytes */ +int ca_int [8] IBSS_ATTR; /* 32 Bytes */ +int cs_int [8] IBSS_ATTR; /* 32 Bytes */ +int win_int [18][36] IBSS_ATTR; /* 2592 Bytes */ +short filter_int [SBLIMIT][64] IBSS_ATTR; /* 8192 Bytes */ +short enwindow_int[512] IBSS_ATTR; /* 1024 Bytes */ +uint8 ht_count1 [2][2][16] IBSS_ATTR; /* 64 Bytes */ +uint16 t1HB [ 4] IBSS_ATTR; /* Bytes */ +uint16 t2HB [ 9] IBSS_ATTR; /* Bytes */ +uint16 t3HB [ 9] IBSS_ATTR; /* Bytes */ +uint16 t5HB [ 16] IBSS_ATTR; /* Bytes */ +uint16 t6HB [ 16] IBSS_ATTR; /* Bytes */ +uint16 t7HB [ 36] IBSS_ATTR; /* Bytes */ +uint16 t8HB [ 36] IBSS_ATTR; /* Bytes */ +uint16 t9HB [ 36] IBSS_ATTR; /* Bytes */ +uint16 t10HB [ 64] IBSS_ATTR; /* Bytes */ +uint16 t11HB [ 64] IBSS_ATTR; /* Bytes */ +uint16 t12HB [ 64] IBSS_ATTR; /* Bytes */ +uint16 t13HB [256] IBSS_ATTR; /* Bytes */ +uint16 t15HB [256] IBSS_ATTR; /* Bytes */ +uint16 t16HB [256] IBSS_ATTR; /* Bytes */ +uint16 t24HB [256] IBSS_ATTR; /* Bytes */ +uint8 t1l [ 4] IBSS_ATTR; /* Bytes */ +uint8 t2l [ 9] IBSS_ATTR; /* Bytes */ +uint8 t3l [ 9] IBSS_ATTR; /* Bytes */ +uint8 t5l [ 16] IBSS_ATTR; /* Bytes */ +uint8 t6l [ 16] IBSS_ATTR; /* Bytes */ +uint8 t7l [ 36] IBSS_ATTR; /* Bytes */ +uint8 t8l [ 36] IBSS_ATTR; /* Bytes */ +uint8 t9l [ 36] IBSS_ATTR; /* Bytes */ +uint8 t10l [ 64] IBSS_ATTR; /* Bytes */ +uint8 t11l [ 64] IBSS_ATTR; /* Bytes */ +uint8 t12l [ 64] IBSS_ATTR; /* Bytes */ +uint8 t13l [256] IBSS_ATTR; /* Bytes */ +uint8 t15l [256] IBSS_ATTR; /* Bytes */ +uint8 t16l [256] IBSS_ATTR; /* Bytes */ +uint8 t24l [256] IBSS_ATTR; /* Bytes */ +struct huffcodetab ht [HTN] IBSS_ATTR; /* Bytes */ static const uint8 ht_count1_const[2][2][16] = { { { 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] = { 2, 2, 0, 0, t1HB, t1l}, { 3, 3, 0, 0, t2HB, t2l}, { 3, 3, 0, 0, t3HB, t3l}, -{ 0, 0, 0, 0, NULL, NULL},// Apparently not used +{ 0, 0, 0, 0, NULL, NULL},/* Apparently not used */ { 4, 4, 0, 0, t5HB, t5l}, { 4, 4, 0, 0, t6HB, t6l}, { 6, 6, 0, 0, t7HB, t7l}, @@ -250,7 +250,7 @@ const struct huffcodetab ht_const[HTN] = { 8, 8, 0, 0,t11HB, t11l}, { 8, 8, 0, 0,t12HB, t12l}, {16,16, 0, 0,t13HB, t13l}, -{ 0, 0, 0, 0, NULL, NULL},// Apparently not used +{ 0, 0, 0, 0, NULL, NULL},/* Apparently not used */ {16,16, 0, 0,t15HB, t15l}, {16,16, 1, 1,t16HB, t16l}, {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 ylen = h->ylen; if(table > 15) - { // ESC-table is used + { /* ESC-table is used */ linbits = h->linbits; for(i=start; iglobal_settings->backlight_timeout > 0) 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) line[chars_for_line] = '\0'; - // test if we have cutted a word. If it is the case we don't have to - // skip the space + /* test if we have cutted a word. If it is the case we don't have to */ + /* skip the space */ if (i == chars_by_line && chars_for_line == chars_by_line) first_char_index += chars_for_line; else first_char_index += chars_for_line + 1; - // print the line on the screen + /* print the line on the screen */ rb->lcd_putsxy(0, current_line * char_height, line); - // if the number of line showed on the screen is equals to the - // maximum number of line we can show, we wait for a key pressed to - // clear and show the remaining text. + /* if the number of line showed on the screen is equals to the */ + /* maximum number of line we can show, we wait for a key pressed to */ + /* clear and show the remaining text. */ current_line++; if (current_line == lines_by_screen || *ptr_char == '\0') { 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) { int ret; - rb = api; // copy to global api pointer + rb = api; /* copy to global api pointer */ (void)parameter; if (rb->global_settings->backlight_timeout > 0) rb->backlight_set_timeout(1);/* keep the light on */ @@ -277,4 +277,4 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) return ret; } -#endif // #ifdef HAVE_LCD_BITMAP +#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; #define false 0 typedef struct _Sudoku { - Bitset table[SIZE][SIZE]; + Bitset table[SIZE][SIZE]; }Sudoku; typedef struct _Stats { - int numTries; - int backTracks; - int numEmpty; - bool solutionFound; + int numTries; + int backTracks; + int numEmpty; + bool solutionFound; }Stats; typedef struct _Options { - bool allSolutions; - bool uniquenessCheck; + bool allSolutions; + bool uniquenessCheck; }Options; void sudoku_init(Sudoku* sud); @@ -268,589 +268,635 @@ int sudoku_get(Sudoku* sud, int x, int y, bool* original); #define ALL_BITS (BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5) | BIT(6) | BIT(7) | BIT(8) | BIT(9)) /* initialize a sudoku problem, should be called before using set or get */ -void sudoku_init(Sudoku* sud){ - int y, x; - for (y = 0; y < SIZE; y++){ - for (x = 0; x < SIZE; x++){ - sud->table[x][y] = ALL_BITS; +void sudoku_init(Sudoku* sud) +{ + int y, x; + for (y = 0; y < SIZE; y++){ + for (x = 0; x < SIZE; x++){ + sud->table[x][y] = ALL_BITS; + } } - } } /* set the number at a particular x and y column */ -void sudoku_set(Sudoku* sud, int x, int y, int num, bool original){ - int i, j; - int bx, by; - Bitset orig; +void sudoku_set(Sudoku* sud, int x, int y, int num, bool original) +{ + int i, j; + int bx, by; + Bitset orig; - // clear the row and columns - for (i = 0; i < SIZE; i++){ - BIT_CLEAR(sud->table[i][y], num); - BIT_CLEAR(sud->table[x][i], num); - } - // clear the block - bx = x - (x % BLOCK); - by = y - (y % BLOCK); - for (i = 0; i < BLOCK; i++){ - for (j = 0; j < BLOCK; j++){ - BIT_CLEAR(sud->table[bx+j][by+i], num); + /* clear the row and columns */ + for (i = 0; i < SIZE; i++){ + BIT_CLEAR(sud->table[i][y], num); + BIT_CLEAR(sud->table[x][i], num); } - } - // mark the table - orig = original ? ORIGINAL_BIT : 0; - sud->table[x][y] = BIT(num) | MARK_BIT | orig; + /* clear the block */ + bx = x - (x % BLOCK); + by = y - (y % BLOCK); + for (i = 0; i < BLOCK; i++){ + for (j = 0; j < BLOCK; j++){ + BIT_CLEAR(sud->table[bx+j][by+i], num); + } + } + /* mark the table */ + orig = original ? ORIGINAL_BIT : 0; + sud->table[x][y] = BIT(num) | MARK_BIT | orig; } /* get the number at a particular x and y column, if this is not unique return 0 */ -int sudoku_get(Sudoku* sud, int x, int y, bool* original){ - Bitset val = sud->table[x][y]; - int result = 0; - int i; +int sudoku_get(Sudoku* sud, int x, int y, bool* original) +{ + Bitset val = sud->table[x][y]; + int result = 0; + int i; - if (original){ - *original = val & ORIGINAL_BIT; - } - for (i = 1; i <= SIZE; i++){ - if (BIT_TEST(val, i)){ - if (result != 0){ - return 0; - } - result = i; + if (original) { + *original = val & ORIGINAL_BIT; } - } - return result; + for (i = 1; i <= SIZE; i++){ + if (BIT_TEST(val, i)){ + if (result != 0){ + return 0; + } + result = i; + } + } + return result; } /* returns true if this is a valid problem, this is necessary because the input problem might be degenerate which breaks the solver algorithm. */ -static bool is_valid(const Sudoku* sud){ - int x, y; - - for (y = 0; y < SIZE; y++){ - for (x = 0; x < SIZE; x++){ - if ((sud->table[x][y] & ALL_BITS) == 0){ - return false; - } +static bool is_valid(const Sudoku* sud) +{ + int x, y; + + for (y = 0; y < SIZE; y++){ + for (x = 0; x < SIZE; x++){ + if ((sud->table[x][y] & ALL_BITS) == 0){ + return false; + } + } } - } - return true; + return true; } -/* scan the table for the most constrained item, giving all it's options, - sets the best x and y coordinates, the number of options and the options for that coordinate and - returns true if the puzzle is finished */ -static bool scan(const Sudoku* sud, int* rX, int* rY, int *num, int* options){ - int x, y, i, j; - int bestCount = SIZE+1; - Bitset val; - bool allMarked = true; +/* scan the table for the most constrained item, giving all it's options, sets + the best x and y coordinates, the number of options and the options for + that coordinate and returns true if the puzzle is finished */ +static bool scan(const Sudoku* sud, int* rX, int* rY, int *num, int* options) +{ + int x, y, i, j; + int bestCount = SIZE+1; + Bitset val; + bool allMarked = true; - for (y = 0; y < SIZE; y++){ - for (x = 0; x < SIZE; x++){ - Bitset val = sud->table[x][y]; - int i; - int count = 0; + for (y = 0; y < SIZE; y++){ + for (x = 0; x < SIZE; x++){ + Bitset val = sud->table[x][y]; + int i; + int count = 0; - if (val & MARK_BIT){ - // already set - continue; - } - allMarked = false; - for (i = 1; i <= SIZE; i++){ + if (val & MARK_BIT) { + /* already set */ + continue; + } + allMarked = false; + for (i = 1; i <= SIZE; i++){ + if (BIT_TEST(val, i)){ + count++; + } + } + if (count < bestCount){ + bestCount = count; + *rX = x; + *rY = y; + if (count == 0){ + /* can't possibly be beaten */ + *num = 0; + return false; + } + } + } + } + /* now copy into options */ + *num = bestCount; + val = sud->table[*rX][*rY]; + for (i = 1, j = 0; i <= SIZE; i++){ if (BIT_TEST(val, i)){ - count++; + options[j++] = i; } - } - if (count < bestCount){ - bestCount = count; - *rX = x; - *rY = y; - if (count == 0){ - // can't possibly be beaten - *num = 0; - return false; - } - } } - } - // now copy into options - *num = bestCount; - val = sud->table[*rX][*rY]; - for (i = 1, j = 0; i <= SIZE; i++){ - if (BIT_TEST(val, i)){ - options[j++] = i; - } - } - return allMarked; + return allMarked; } static bool solve(Sudoku* sud, Stats* stats, const Options* options); -/* try a particular option and return true if that gives a solution - or false if it doesn't, restores board on backtracking */ -static bool spawn_option(Sudoku* sud, Stats* stats, const Options* options, int x, int y, int num){ - Sudoku copy; +/* try a particular option and return true if that gives a solution or false + if it doesn't, restores board on backtracking */ +static bool spawn_option(Sudoku* sud, Stats* stats, const Options* options, + int x, int y, int num) +{ + Sudoku copy; - rb->memcpy(©,sud,sizeof(Sudoku)); - sudoku_set(©, x, y, num, false); - stats->numTries += 1; - if (solve(©, stats, options)){ - if (!options->allSolutions && stats->solutionFound){ - rb->memcpy(sud,©,sizeof(Sudoku)); + rb->memcpy(©,sud,sizeof(Sudoku)); + sudoku_set(©, x, y, num, false); + stats->numTries += 1; + if (solve(©, stats, options)){ + if (!options->allSolutions && stats->solutionFound){ + rb->memcpy(sud,©,sizeof(Sudoku)); + } + return true; + }else{ + stats->backTracks++; } - return true; - }else{ - stats->backTracks++; - } - return false; + return false; } -/* solve a sudoku problem, returns true if there is a solution and false otherwise. - stats is used to track statisticss */ -static bool solve(Sudoku* sud, Stats* stats, const Options* options){ - while (true){ - int x, y, i, num; - int places[SIZE]; - - if (scan(sud, &x, &y, &num, places)){ - // a solution was found! - if (options->uniquenessCheck && stats->solutionFound){ - //printf("\n\t... But the solution is not unique!\n"); - return true; - } - stats->solutionFound = true; - if (options->allSolutions || options->uniquenessCheck){ - //printf("\n\tSolution after %d iterations\n", stats->numTries); - //sudoku_print(sud); - return false; - }else{ - return true; - } - } - if (num == 0){ - // can't be satisfied - return false; - } - // try all the places (except the last one) - for (i = 0; i < num-1; i++){ - if (spawn_option(sud, stats, options, x, y, places[i])){ - // solution found! - if (!options->allSolutions && stats->solutionFound){ - return true; +/* solve a sudoku problem, returns true if there is a solution and false + otherwise. stats is used to track statisticss */ +static bool solve(Sudoku* sud, Stats* stats, const Options* options) +{ + while (true){ + int x, y, i, num; + int places[SIZE]; + + if (scan(sud, &x, &y, &num, places)){ + /* a solution was found! */ + if (options->uniquenessCheck && stats->solutionFound){ + /*printf("\n\t... But the solution is not unique!\n"); */ + return true; + } + stats->solutionFound = true; + if (options->allSolutions || options->uniquenessCheck){ + /*printf("\n\tSolution after %d iterations\n", stats->numTries); */ + /*sudoku_print(sud); */ + return false; + } + else{ + return true; + } } - } + if (num == 0){ + /* can't be satisfied */ + return false; + } + /* try all the places (except the last one) */ + for (i = 0; i < num-1; i++){ + if (spawn_option(sud, stats, options, x, y, places[i])){ + /* solution found! */ + if (!options->allSolutions && stats->solutionFound){ + return true; + } + } + } + /* take the last place ourself */ + stats->numTries += 1; + sudoku_set(sud, x, y, places[num-1], false); } - // take the last place ourself - stats->numTries += 1; - sudoku_set(sud, x, y, places[num-1], false); - } } /******** END OF IMPORTED CODE */ /* A wrapper function between the Sudoku plugin and the above solver code */ -void sudoku_solve(struct sudoku_state_t* state) { - bool ret; - Stats stats; - Options options; - Sudoku sud; - bool original; - int r,c; +void sudoku_solve(struct sudoku_state_t* state) +{ + bool ret; + Stats stats; + Options options; + Sudoku sud; + bool original; + int r,c; + + /* Initialise the parameters */ + sudoku_init(&sud); + rb->memset(&stats,0,sizeof(stats)); + options.allSolutions=false; + options.uniquenessCheck=false; - /* Initialise the parameters */ - sudoku_init(&sud); - rb->memset(&stats,0,sizeof(stats)); - options.allSolutions=false; - options.uniquenessCheck=false; - - /* Convert Rockbox format into format for solver */ - for (r=0;r<9;r++) { - for (c=0;c<9;c++) { - if (state->startboard[r][c]!='0') { - sudoku_set(&sud, c, r, state->startboard[r][c]-'0', true); - } - } - } - - // need to check for degenerate input problems ... - if (is_valid(&sud)){ - ret = solve(&sud, &stats, &options); - } else { - ret = false; - } - - if (ret) { - /* Populate the board with the solution. */ + /* Convert Rockbox format into format for solver */ for (r=0;r<9;r++) { - for (c=0;c<9;c++) { - state->currentboard[r][c]='0'+sudoku_get(&sud, c, r, &original); - } + for (c=0;c<9;c++) { + if (state->startboard[r][c]!='0') { + sudoku_set(&sud, c, r, state->startboard[r][c]-'0', true); + } + } } - } else { - rb->splash(HZ*2, true, "Solve failed"); - } - return; + /* need to check for degenerate input problems ... */ + if (is_valid(&sud)){ + ret = solve(&sud, &stats, &options); + } else { + ret = false; + } + + if (ret) { + /* Populate the board with the solution. */ + for (r=0;r<9;r++) { + for (c=0;c<9;c++) { + state->currentboard[r][c]='0'+ + sudoku_get(&sud, c, r, &original); + } + } + } else { + rb->splash(HZ*2, true, "Solve failed"); + } + + return; } void clear_state(struct sudoku_state_t* state) { - int r,c; + int r,c; - state->filename[0]=0; - for (r=0;r<9;r++) { - for (c=0;c<9;c++) { - state->startboard[r][c]='0'; - state->currentboard[r][c]='0'; + state->filename[0]=0; + for (r=0;r<9;r++) { + for (c=0;c<9;c++) { + state->startboard[r][c]='0'; + state->currentboard[r][c]='0'; #ifdef SUDOKU_BUTTON_POSSIBLE - state->possiblevals[r][c]=0; + state->possiblevals[r][c]=0; #endif + } } - } - state->x=0; - state->y=0; - state->editmode=0; + state->x=0; + state->y=0; + state->editmode=0; } /* Load game - only ".ss" is officially supported, but any sensible text representation (one line per row) may load. */ -bool load_sudoku(struct sudoku_state_t* state, char* filename) { - int fd; - size_t n; - int r = 0, c = 0; - unsigned int i; - int valid=0; - char buf[300]; /* A buffer to read a sudoku board from */ +bool load_sudoku(struct sudoku_state_t* state, char* filename) +{ + int fd; + size_t n; + int r = 0, c = 0; + unsigned int i; + int valid=0; + char buf[300]; /* A buffer to read a sudoku board from */ - fd=rb->open(filename, O_RDONLY); - if (fd < 0) { - rb->splash(HZ*2, true, "Can not open"); - LOGF("Invalid sudoku file: %s\n",filename); - return(false); - } - - rb->strncpy(state->filename,filename,MAX_PATH); - n=rb->read(fd,buf,300); - if (n <= 0) { - return(false); - } - rb->close(fd); - - r=0; - c=0; - i=0; - while ((i < n) && (r < 9)) { - switch (buf[i]){ - case ' ': case '\t': - if (c > 0) - valid=1; - break; - case '|': - case '*': - case '-': - case '\r': - break; - case '\n': - if (valid) { - r++; - valid=0; - } - c = 0; - break; - case '_': case '.': - valid=1; - if (c >= SIZE || r >= SIZE){ - LOGF("ERROR: sudoku problem is the wrong size (%d,%d)\n", c, r); + fd=rb->open(filename, O_RDONLY); + if (fd < 0) { + rb->splash(HZ*2, true, "Can not open"); + LOGF("Invalid sudoku file: %s\n",filename); return(false); - } - c++; - break; - default: - if (((buf[i]>='A') && (buf[i]<='I')) || ((buf[i]>='0') && (buf[i]<='9'))) { - valid=1; - if (r >= SIZE || c >= SIZE){ - LOGF("ERROR: sudoku problem is the wrong size (%d,%d)\n", c, r); - return(false); - } - if ((buf[i]>='0') && (buf[i]<='9')) { - state->startboard[r][c]=buf[i]; - state->currentboard[r][c]=buf[i]; - } else { - state->currentboard[r][c]='1'+(buf[i]-'A'); - } - c++; - } - /* Ignore any other characters */ - break; } - i++; - } - /* Save a copy of the saved state - so we can reload without - using the disk */ - rb->memcpy(state->savedboard,state->currentboard,81); - return(true); -} + rb->strncpy(state->filename,filename,MAX_PATH); + n=rb->read(fd,buf,300); + if (n <= 0) { + return(false); + } + rb->close(fd); -bool save_sudoku(struct sudoku_state_t* state) { - int fd; - int r,c; - int i; - char line[16]; - char sep[16]; - - rb->memcpy(line,"...|...|...\r\n",13); - rb->memcpy(sep,"-----------\r\n",13); - - if (state->filename[0]==0) { - return false; - } - - fd=rb->open(state->filename, O_WRONLY|O_CREAT); - if (fd >= 0) { - for (r=0;r<9;r++) { - i=0; - for (c=0;c<9;c++) { - if (state->startboard[r][c]!='0') { - line[i]=state->startboard[r][c]; - } else if (state->currentboard[r][c]!='0') { - line[i]='A'+(state->currentboard[r][c]-'1'); - } else { - line[i]='.'; + r=0; + c=0; + i=0; + while ((i < n) && (r < 9)) { + switch (buf[i]){ + case ' ': case '\t': + if (c > 0) + valid=1; + break; + case '|': + case '*': + case '-': + case '\r': + break; + case '\n': + if (valid) { + r++; + valid=0; + } + c = 0; + break; + case '_': case '.': + valid=1; + if (c >= SIZE || r >= SIZE){ + LOGF("ERROR: sudoku problem is the wrong size (%d,%d)\n", + c, r); + return(false); + } + c++; + break; + default: + if (((buf[i]>='A') && (buf[i]<='I')) || + ((buf[i]>='0') && (buf[i]<='9'))) { + valid=1; + if (r >= SIZE || c >= SIZE){ + LOGF("ERROR: sudoku problem is the wrong size " + "(%d,%d)\n", c, r); + return(false); + } + if ((buf[i]>='0') && (buf[i]<='9')) { + state->startboard[r][c]=buf[i]; + state->currentboard[r][c]=buf[i]; + } else { + state->currentboard[r][c]='1'+(buf[i]-'A'); + } + c++; + } + /* Ignore any other characters */ + break; } i++; - if ((c==2) || (c==5)) { i++; } - } - rb->write(fd,line,sizeof(line)-1); - if ((r==2) || (r==5)) { - rb->write(fd,sep,sizeof(sep)-1); - } } - /* Add a blank line at end */ - rb->write(fd,"\r\n",2); - rb->close(fd); - /* Save a copy of the saved state - so we can reload without - using the disk */ + + /* Save a copy of the saved state - so we can reload without using the + disk */ rb->memcpy(state->savedboard,state->currentboard,81); - return true; - } else { - return false; - } + return(true); +} + +bool save_sudoku(struct sudoku_state_t* state) +{ + int fd; + int r,c; + int i; + char line[16]; + char sep[16]; + + rb->memcpy(line,"...|...|...\r\n",13); + rb->memcpy(sep,"-----------\r\n",13); + + if (state->filename[0]==0) { + return false; + } + + fd=rb->open(state->filename, O_WRONLY|O_CREAT); + if (fd >= 0) { + for (r=0;r<9;r++) { + i=0; + for (c=0;c<9;c++) { + if (state->startboard[r][c]!='0') { + line[i]=state->startboard[r][c]; + } else if (state->currentboard[r][c]!='0') { + line[i]='A'+(state->currentboard[r][c]-'1'); + } else { + line[i]='.'; + } + i++; + if ((c==2) || (c==5)) { + i++; + } + } + rb->write(fd,line,sizeof(line)-1); + if ((r==2) || (r==5)) { + rb->write(fd,sep,sizeof(sep)-1); + } + } + /* Add a blank line at end */ + rb->write(fd,"\r\n",2); + rb->close(fd); + /* Save a copy of the saved state - so we can reload without + using the disk */ + rb->memcpy(state->savedboard,state->currentboard,81); + return true; + } else { + return false; + } } void restore_state(struct sudoku_state_t* state) { - rb->memcpy(state->currentboard,state->savedboard,81); + rb->memcpy(state->currentboard,state->savedboard,81); } void clear_board(struct sudoku_state_t* state) { - int r,c; + int r,c; - for (r=0;r<9;r++) { - for (c=0;c<9;c++) { - state->currentboard[r][c]=state->startboard[r][c]; + for (r=0;r<9;r++) { + for (c=0;c<9;c++) { + state->currentboard[r][c]=state->startboard[r][c]; + } } - } - state->x=0; - state->y=0; + state->x=0; + state->y=0; } void update_cell(struct sudoku_state_t* state, int r, int c) { - /* We have four types of cell: - 1) User-entered number - 2) Starting number - 3) Cursor in cell - */ + /* We have four types of cell: + 1) User-entered number + 2) Starting number + 3) Cursor in cell + */ - if ((r==state->y) && (c==state->x)) { - rb->lcd_bitmap_part(sudoku_inverse,0,BITMAP_HEIGHT*(state->currentboard[r][c]-'0'),BITMAP_STRIDE, - XOFS+cellxpos[c],YOFS+cellypos[r],CELL_WIDTH,CELL_HEIGHT); - } else { + if ((r==state->y) && (c==state->x)) { + rb->lcd_bitmap_part(sudoku_inverse,0, + BITMAP_HEIGHT*(state->currentboard[r][c]-'0'), + BITMAP_STRIDE, + XOFS+cellxpos[c],YOFS+cellypos[r],CELL_WIDTH, + CELL_HEIGHT); + } else { if (state->startboard[r][c]!='0') { - rb->lcd_bitmap_part(sudoku_start,0,BITMAP_HEIGHT*(state->startboard[r][c]-'0'),BITMAP_STRIDE, - XOFS+cellxpos[c],YOFS+cellypos[r],CELL_WIDTH,CELL_HEIGHT); + rb->lcd_bitmap_part(sudoku_start,0, + BITMAP_HEIGHT*(state->startboard[r][c]-'0'), + BITMAP_STRIDE, + XOFS+cellxpos[c],YOFS+cellypos[r], + CELL_WIDTH,CELL_HEIGHT); } else { - rb->lcd_bitmap_part(sudoku_normal,0,BITMAP_HEIGHT*(state->currentboard[r][c]-'0'),BITMAP_STRIDE, - XOFS+cellxpos[c],YOFS+cellypos[r],CELL_WIDTH,CELL_HEIGHT); + rb->lcd_bitmap_part(sudoku_normal,0, + BITMAP_HEIGHT*(state->currentboard[r][c]-'0'), + BITMAP_STRIDE, + XOFS+cellxpos[c],YOFS+cellypos[r], + CELL_WIDTH,CELL_HEIGHT); } - } + } - rb->lcd_update_rect(cellxpos[c],cellypos[r],CELL_WIDTH,CELL_HEIGHT); + rb->lcd_update_rect(cellxpos[c],cellypos[r],CELL_WIDTH,CELL_HEIGHT); } void display_board(struct sudoku_state_t* state) { - int r,c; + int r,c; - /* Clear the display buffer */ - rb->lcd_clear_display(); + /* Clear the display buffer */ + rb->lcd_clear_display(); - /* Draw the gridlines - differently for different targets */ + /* Draw the gridlines - differently for different targets */ #if LCD_HEIGHT > 64 - /* Large targets - draw single/double lines */ - for (r=0;r<9;r++) { - rb->lcd_hline(XOFS,XOFS+BOARD_WIDTH-1,YOFS+cellypos[r]-1); - rb->lcd_vline(XOFS+cellxpos[r]-1,YOFS,YOFS+BOARD_HEIGHT-1); - if ((r % 3)==0) { - rb->lcd_hline(XOFS,XOFS+BOARD_WIDTH-1,YOFS+cellypos[r]-2); - rb->lcd_vline(XOFS+cellxpos[r]-2,YOFS,YOFS+BOARD_HEIGHT-1); + /* Large targets - draw single/double lines */ + for (r=0;r<9;r++) { + rb->lcd_hline(XOFS,XOFS+BOARD_WIDTH-1,YOFS+cellypos[r]-1); + rb->lcd_vline(XOFS+cellxpos[r]-1,YOFS,YOFS+BOARD_HEIGHT-1); + if ((r % 3)==0) { + rb->lcd_hline(XOFS,XOFS+BOARD_WIDTH-1,YOFS+cellypos[r]-2); + rb->lcd_vline(XOFS+cellxpos[r]-2,YOFS,YOFS+BOARD_HEIGHT-1); + } } - } - rb->lcd_hline(XOFS,XOFS+BOARD_WIDTH-1,YOFS+cellypos[8]+CELL_HEIGHT); - rb->lcd_hline(XOFS,XOFS+BOARD_WIDTH-1,YOFS+cellypos[8]+CELL_HEIGHT+1); - rb->lcd_vline(XOFS+cellxpos[8]+CELL_WIDTH,YOFS,YOFS+BOARD_HEIGHT-1); - rb->lcd_vline(XOFS+cellxpos[8]+CELL_WIDTH+1,YOFS,YOFS+BOARD_HEIGHT-1); + rb->lcd_hline(XOFS,XOFS+BOARD_WIDTH-1,YOFS+cellypos[8]+CELL_HEIGHT); + rb->lcd_hline(XOFS,XOFS+BOARD_WIDTH-1,YOFS+cellypos[8]+CELL_HEIGHT+1); + rb->lcd_vline(XOFS+cellxpos[8]+CELL_WIDTH,YOFS,YOFS+BOARD_HEIGHT-1); + rb->lcd_vline(XOFS+cellxpos[8]+CELL_WIDTH+1,YOFS,YOFS+BOARD_HEIGHT-1); #elif (LCD_HEIGHT==64) - /* Small targets - draw dotted/single lines */ - for (r=0;r<9;r++) { - if ((r % 3)==0) { - /* Solid Line */ - rb->lcd_hline(XOFS,XOFS+BOARD_WIDTH-1,YOFS+cellypos[r]-1); - rb->lcd_vline(XOFS+cellxpos[r]-1,YOFS,YOFS+BOARD_HEIGHT-1); - } else { - /* Dotted line */ - for (c=XOFS;clcd_drawpixel(c,YOFS+cellypos[r]-1); - } - for (c=YOFS;clcd_drawpixel(XOFS+cellxpos[r]-1,c); - } + /* Small targets - draw dotted/single lines */ + for (r=0;r<9;r++) { + if ((r % 3)==0) { + /* Solid Line */ + rb->lcd_hline(XOFS,XOFS+BOARD_WIDTH-1,YOFS+cellypos[r]-1); + rb->lcd_vline(XOFS+cellxpos[r]-1,YOFS,YOFS+BOARD_HEIGHT-1); + } else { + /* Dotted line */ + for (c=XOFS;clcd_drawpixel(c,YOFS+cellypos[r]-1); + } + for (c=YOFS;clcd_drawpixel(XOFS+cellxpos[r]-1,c); + } + } } - } - rb->lcd_hline(XOFS,XOFS+BOARD_WIDTH-1,YOFS+cellypos[8]+CELL_HEIGHT); - rb->lcd_vline(XOFS+cellxpos[8]+CELL_WIDTH,YOFS,YOFS+BOARD_HEIGHT-1); + rb->lcd_hline(XOFS,XOFS+BOARD_WIDTH-1,YOFS+cellypos[8]+CELL_HEIGHT); + rb->lcd_vline(XOFS+cellxpos[8]+CELL_WIDTH,YOFS,YOFS+BOARD_HEIGHT-1); #else - #error SUDOKU: Unsupported LCD height +#error SUDOKU: Unsupported LCD height #endif #ifdef SUDOKU_BUTTON_POSSIBLE - rb->lcd_vline(XOFSSCRATCHPAD,YOFS,YOFS+BOARD_HEIGHT-1); - rb->lcd_vline(XOFSSCRATCHPAD+CELL_WIDTH+1,YOFS,YOFS+BOARD_HEIGHT-1); - for (r=0;r<9;r++) { + rb->lcd_vline(XOFSSCRATCHPAD,YOFS,YOFS+BOARD_HEIGHT-1); + rb->lcd_vline(XOFSSCRATCHPAD+CELL_WIDTH+1,YOFS,YOFS+BOARD_HEIGHT-1); + for (r=0;r<9;r++) { #if LCD_HEIGHT > 64 - /* Large targets - draw single/double lines */ - rb->lcd_hline(XOFSSCRATCHPAD,XOFSSCRATCHPAD+CELL_WIDTH+1, - YOFS+cellypos[r]-1); - if ((r % 3)==0) - rb->lcd_hline(XOFSSCRATCHPAD,XOFSSCRATCHPAD+CELL_WIDTH+1, - YOFS+cellypos[r]-2); + /* Large targets - draw single/double lines */ + rb->lcd_hline(XOFSSCRATCHPAD,XOFSSCRATCHPAD+CELL_WIDTH+1, + YOFS+cellypos[r]-1); + if ((r % 3)==0) + rb->lcd_hline(XOFSSCRATCHPAD,XOFSSCRATCHPAD+CELL_WIDTH+1, + YOFS+cellypos[r]-2); #elif LCD_HEIGHT == 64 - /* Small targets - draw dotted/single lines */ - if ((r % 3)==0) { - /* Solid Line */ - rb->lcd_hline(XOFSSCRATCHPAD,XOFSSCRATCHPAD+CELL_WIDTH+1, - YOFS+cellypos[r]-1); - } else { - /* Dotted line */ - for (c=XOFSSCRATCHPAD;clcd_drawpixel(c,YOFS+cellypos[r]-1); - } - } -#endif - if ((r>0) && state->possiblevals[state->y][state->x]&(1<<(r))) - rb->lcd_bitmap_part(sudoku_normal,0,BITMAP_HEIGHT*r,BITMAP_STRIDE, - XOFSSCRATCHPAD+1,YOFS+cellypos[r-1], - CELL_WIDTH,CELL_HEIGHT); - } - rb->lcd_hline(XOFSSCRATCHPAD,XOFSSCRATCHPAD+CELL_WIDTH+1, - YOFS+cellypos[8]+CELL_HEIGHT); -#if LCD_HEIGHT > 64 - rb->lcd_hline(XOFSSCRATCHPAD,XOFSSCRATCHPAD+CELL_WIDTH+1, - YOFS+cellypos[8]+CELL_HEIGHT+1); -#endif - if (state->possiblevals[state->y][state->x]&(1<<(r))) - rb->lcd_bitmap_part(sudoku_normal,0,BITMAP_HEIGHT*r,BITMAP_STRIDE, - XOFSSCRATCHPAD+1,YOFS+cellypos[8], - CELL_WIDTH,CELL_HEIGHT); -#endif - - /* Draw the numbers */ - for (r=0;r<9;r++) { - for (c=0;c<9;c++) { - /* We have four types of cell: - 1) User-entered number - 2) Starting number - 3) Cursor in cell - */ - - if ((r==state->y) && (c==state->x)) { - rb->lcd_bitmap_part(sudoku_inverse,0,BITMAP_HEIGHT*(state->currentboard[r][c]-'0'),BITMAP_STRIDE, - XOFS+cellxpos[c],YOFS+cellypos[r],CELL_WIDTH,CELL_HEIGHT); - } else { - if (state->startboard[r][c]!='0') { - rb->lcd_bitmap_part(sudoku_start,0,BITMAP_HEIGHT*(state->startboard[r][c]-'0'),BITMAP_STRIDE, - XOFS+cellxpos[c],YOFS+cellypos[r],CELL_WIDTH,CELL_HEIGHT); + /* Small targets - draw dotted/single lines */ + if ((r % 3)==0) { + /* Solid Line */ + rb->lcd_hline(XOFSSCRATCHPAD,XOFSSCRATCHPAD+CELL_WIDTH+1, + YOFS+cellypos[r]-1); } else { - rb->lcd_bitmap_part(sudoku_normal,0,BITMAP_HEIGHT*(state->currentboard[r][c]-'0'),BITMAP_STRIDE, - XOFS+cellxpos[c],YOFS+cellypos[r],CELL_WIDTH,CELL_HEIGHT); + /* Dotted line */ + for (c=XOFSSCRATCHPAD;clcd_drawpixel(c,YOFS+cellypos[r]-1); + } } - } +#endif + if ((r>0) && state->possiblevals[state->y][state->x]&(1<<(r))) + rb->lcd_bitmap_part(sudoku_normal,0,BITMAP_HEIGHT*r,BITMAP_STRIDE, + XOFSSCRATCHPAD+1,YOFS+cellypos[r-1], + CELL_WIDTH,CELL_HEIGHT); } - } + rb->lcd_hline(XOFSSCRATCHPAD,XOFSSCRATCHPAD+CELL_WIDTH+1, + YOFS+cellypos[8]+CELL_HEIGHT); +#if LCD_HEIGHT > 64 + rb->lcd_hline(XOFSSCRATCHPAD,XOFSSCRATCHPAD+CELL_WIDTH+1, + YOFS+cellypos[8]+CELL_HEIGHT+1); +#endif + if (state->possiblevals[state->y][state->x]&(1<<(r))) + rb->lcd_bitmap_part(sudoku_normal,0,BITMAP_HEIGHT*r,BITMAP_STRIDE, + XOFSSCRATCHPAD+1,YOFS+cellypos[8], + CELL_WIDTH,CELL_HEIGHT); +#endif - /* update the screen */ - rb->lcd_update(); + /* Draw the numbers */ + for (r=0;r<9;r++) { + for (c=0;c<9;c++) { + /* We have four types of cell: + 1) User-entered number + 2) Starting number + 3) Cursor in cell + */ + + if ((r==state->y) && (c==state->x)) { + rb->lcd_bitmap_part(sudoku_inverse,0, + BITMAP_HEIGHT*(state->currentboard[r][c]- + '0'), + BITMAP_STRIDE, + XOFS+cellxpos[c],YOFS+cellypos[r], + CELL_WIDTH,CELL_HEIGHT); + } else { + if (state->startboard[r][c]!='0') { + rb->lcd_bitmap_part(sudoku_start,0, + BITMAP_HEIGHT*(state->startboard[r][c]- + '0'), + BITMAP_STRIDE, + XOFS+cellxpos[c],YOFS+cellypos[r], + CELL_WIDTH,CELL_HEIGHT); + } else { + rb->lcd_bitmap_part(sudoku_normal,0, + BITMAP_HEIGHT* + (state->currentboard[r][c]-'0'), + BITMAP_STRIDE, + XOFS+cellxpos[c],YOFS+cellypos[r], + CELL_WIDTH,CELL_HEIGHT); + } + } + } + } + + /* update the screen */ + rb->lcd_update(); } /* Check the status of the board, assuming a change at the cursor location */ -bool check_status(struct sudoku_state_t* state) { - int check[9]; - int r,c; - int r1,c1; - int cell; +bool check_status(struct sudoku_state_t* state) +{ + int check[9]; + int r,c; + int r1,c1; + int cell; - /* First, check the column */ - for (cell=0;cell<9;cell++) { check[cell]=0; } - for (r=0;r<9;r++) { - cell=state->currentboard[r][state->x]; - if (cell!='0') { - if (check[cell-'1']==1) { - return true; - } - check[cell-'1']=1; + /* First, check the column */ + for (cell=0;cell<9;cell++) { + check[cell]=0; } - } - - /* Second, check the row */ - for (cell=0;cell<9;cell++) { check[cell]=0; } - for (c=0;c<9;c++) { - cell=state->currentboard[state->y][c]; - if (cell!='0') { - if (check[cell-'1']==1) { - return true; - } - check[cell-'1']=1; - } - } - - /* Finally, check the 3x3 sub-grid */ - for (cell=0;cell<9;cell++) { check[cell]=0; } - r1=(state->y/3)*3; - c1=(state->x/3)*3; - for (r=r1;rcurrentboard[r][c]; - if (cell!='0') { - if (check[cell-'1']==1) { - return true; + for (r=0;r<9;r++) { + cell=state->currentboard[r][state->x]; + if (cell!='0') { + if (check[cell-'1']==1) { + return true; + } + check[cell-'1']=1; } - check[cell-'1']=1; - } } - } - /* We passed all the checks :) */ + /* Second, check the row */ + for (cell=0;cell<9;cell++) { + check[cell]=0; + } + for (c=0;c<9;c++) { + cell=state->currentboard[state->y][c]; + if (cell!='0') { + if (check[cell-'1']==1) { + return true; + } + check[cell-'1']=1; + } + } - return false; + /* Finally, check the 3x3 sub-grid */ + for (cell=0;cell<9;cell++) { + check[cell]=0; + } + r1=(state->y/3)*3; + c1=(state->x/3)*3; + for (r=r1;rcurrentboard[r][c]; + if (cell!='0') { + if (check[cell-'1']==1) { + return true; + } + check[cell-'1']=1; + } + } + } + + /* We passed all the checks :) */ + + return false; } int sudoku_menu_cb(int key, int m) @@ -878,242 +924,243 @@ int sudoku_menu_cb(int key, int m) bool sudoku_menu(struct sudoku_state_t* state) { - int m; - int result; + int m; + int result; - static const struct menu_item items[] = { - { "Save", NULL }, - { "Reload", NULL }, - { "Clear", NULL }, - { "Solve", NULL }, - { "New", NULL }, - }; + static const struct menu_item items[] = { + { "Save", NULL }, + { "Reload", NULL }, + { "Clear", NULL }, + { "Solve", NULL }, + { "New", NULL }, + }; + + m = rb->menu_init(items, sizeof(items) / sizeof(*items), + sudoku_menu_cb, NULL, NULL, NULL); - m = rb->menu_init(items, sizeof(items) / sizeof(*items), - sudoku_menu_cb, NULL, NULL, NULL); + result=rb->menu_show(m); - result=rb->menu_show(m); + switch (result) { + case 0: /* Save state */ + save_sudoku(state); + break; - switch (result) { - case 0: /* Save state */ - save_sudoku(state); - break; + case 1: /* Restore state */ + restore_state(state); + break; - case 1: /* Restore state */ - restore_state(state); - break; + case 2: /* Clear all */ + clear_board(state); + break; - case 2: /* Clear all */ - clear_board(state); - break; + case 3: /* Solve */ + sudoku_solve(state); + break; - case 3: /* Solve */ - sudoku_solve(state); - break; + case 4: /* Create a new game manually */ + clear_state(state); + state->editmode=1; + break; - case 4: /* Create a new game manually */ - clear_state(state); - state->editmode=1; - break; + default: + break; + } - default: - break; - } + rb->menu_exit(m); - rb->menu_exit(m); - - return (result==MENU_ATTACHED_USB); + return (result==MENU_ATTACHED_USB); } -void move_cursor(struct sudoku_state_t* state, int newx, int newy) { - int oldx, oldy; +void move_cursor(struct sudoku_state_t* state, int newx, int newy) +{ + int oldx, oldy; - /* Check that the character at the cursor position is legal */ - if (check_status(state)) { - rb->splash(HZ*2, true, "Illegal move!"); - /* Ignore any button presses during the splash */ - rb->button_clear_queue(); - return; - } + /* Check that the character at the cursor position is legal */ + if (check_status(state)) { + rb->splash(HZ*2, true, "Illegal move!"); + /* Ignore any button presses during the splash */ + rb->button_clear_queue(); + return; + } - /* Move Cursor */ - oldx=state->x; - oldy=state->y; - state->x=newx; - state->y=newy; + /* Move Cursor */ + oldx=state->x; + oldy=state->y; + state->x=newx; + state->y=newy; - /* Redraw current and old cells */ - update_cell(state,oldx,oldy); - update_cell(state,newx,newy); + /* Redraw current and old cells */ + update_cell(state,oldx,oldy); + update_cell(state,newx,newy); } /* plugin entry point */ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) { - bool exit; - int button; - int lastbutton = BUTTON_NONE; - long ticks; - struct sudoku_state_t state; + bool exit; + int button; + int lastbutton = BUTTON_NONE; + long ticks; + struct sudoku_state_t state; - /* plugin init */ - rb = api; - /* end of plugin init */ + /* plugin init */ + rb = api; + /* end of plugin init */ - clear_state(&state); + clear_state(&state); - if (parameter==NULL) { - state.editmode=1; - } else { - if (!load_sudoku(&state,(char*)parameter)) { - rb->splash(HZ*2, true, "Load error"); - return(PLUGIN_ERROR); + if (parameter==NULL) { + state.editmode=1; + } else { + if (!load_sudoku(&state,(char*)parameter)) { + rb->splash(HZ*2, true, "Load error"); + return(PLUGIN_ERROR); + } } - } - display_board(&state); + display_board(&state); - /* The main game loop */ - exit=false; - ticks=0; - while(!exit) { - button = rb->button_get(true); + /* The main game loop */ + exit=false; + ticks=0; + while(!exit) { + button = rb->button_get(true); - switch(button){ - /* Exit game */ - case SUDOKU_BUTTON_QUIT: - exit=1; - break; + switch(button){ + /* Exit game */ + case SUDOKU_BUTTON_QUIT: + exit=1; + break; /* Increment digit */ #ifdef SUDOKU_BUTTON_ALTTOGGLE - case SUDOKU_BUTTON_ALTTOGGLE | BUTTON_REPEAT: + case SUDOKU_BUTTON_ALTTOGGLE | BUTTON_REPEAT: #endif - case SUDOKU_BUTTON_TOGGLE | BUTTON_REPEAT: - /* Slow down the repeat speed to 1/3 second */ - if ((*rb->current_tick-ticks) < (HZ/3)) { - break; - } + case SUDOKU_BUTTON_TOGGLE | BUTTON_REPEAT: + /* Slow down the repeat speed to 1/3 second */ + if ((*rb->current_tick-ticks) < (HZ/3)) { + break; + } #ifdef SUDOKU_BUTTON_ALTTOGGLE - case SUDOKU_BUTTON_ALTTOGGLE: + case SUDOKU_BUTTON_ALTTOGGLE: #endif - case SUDOKU_BUTTON_TOGGLE: + case SUDOKU_BUTTON_TOGGLE: #ifdef SUDOKU_BUTTON_TOGGLE_PRE - if ((button == SUDOKU_BUTTON_TOGGLE) - && (lastbutton != SUDOKU_BUTTON_TOGGLE_PRE)) - break; + if ((button == SUDOKU_BUTTON_TOGGLE) + && (lastbutton != SUDOKU_BUTTON_TOGGLE_PRE)) + break; #endif - /* Increment digit */ - ticks=*rb->current_tick; - if (state.editmode) { - if (state.startboard[state.y][state.x]=='9') { - state.startboard[state.y][state.x]='0'; - state.currentboard[state.y][state.x]='0'; - } else { - state.startboard[state.y][state.x]++; - state.currentboard[state.y][state.x]++; - } - } else { - if (state.startboard[state.y][state.x]=='0') { - if (state.currentboard[state.y][state.x]=='9') { - state.currentboard[state.y][state.x]='0'; - } else { + /* Increment digit */ + ticks=*rb->current_tick; + if (state.editmode) { + if (state.startboard[state.y][state.x]=='9') { + state.startboard[state.y][state.x]='0'; + state.currentboard[state.y][state.x]='0'; + } else { + state.startboard[state.y][state.x]++; + state.currentboard[state.y][state.x]++; + } + } else { + if (state.startboard[state.y][state.x]=='0') { + if (state.currentboard[state.y][state.x]=='9') { + state.currentboard[state.y][state.x]='0'; + } else { state.currentboard[state.y][state.x]++; - } - } - } - update_cell(&state,state.y,state.x); - break; + } + } + } + update_cell(&state,state.y,state.x); + break; - /* move cursor left */ - case BUTTON_LEFT: - case (BUTTON_LEFT | BUTTON_REPEAT): - if (state.x==0) { - move_cursor(&state,8,state.y); - } else { - move_cursor(&state,state.x-1,state.y); - } - break; + /* move cursor left */ + case BUTTON_LEFT: + case (BUTTON_LEFT | BUTTON_REPEAT): + if (state.x==0) { + move_cursor(&state,8,state.y); + } else { + move_cursor(&state,state.x-1,state.y); + } + break; + + /* move cursor right */ + case BUTTON_RIGHT: + case (BUTTON_RIGHT | BUTTON_REPEAT): + if (state.x==8) { + move_cursor(&state,0,state.y); + } else { + move_cursor(&state,state.x+1,state.y); + } + break; - /* move cursor right */ - case BUTTON_RIGHT: - case (BUTTON_RIGHT | BUTTON_REPEAT): - if (state.x==8) { - move_cursor(&state,0,state.y); - } else { - move_cursor(&state,state.x+1,state.y); - } - break; + /* move cursor up */ + case SUDOKU_BUTTON_UP: + case (SUDOKU_BUTTON_UP | BUTTON_REPEAT): + if (state.y==0) { + move_cursor(&state,state.x,8); + } else { + move_cursor(&state,state.x,state.y-1); + } + break; - /* move cursor up */ - case SUDOKU_BUTTON_UP: - case (SUDOKU_BUTTON_UP | BUTTON_REPEAT): - if (state.y==0) { - move_cursor(&state,state.x,8); - } else { - move_cursor(&state,state.x,state.y-1); - } - break; + /* move cursor down */ + case SUDOKU_BUTTON_DOWN: + case (SUDOKU_BUTTON_DOWN | BUTTON_REPEAT): + if (state.y==8) { + move_cursor(&state,state.x,0); + } else { + move_cursor(&state,state.x,state.y+1); + } + break; - /* move cursor down */ - case SUDOKU_BUTTON_DOWN: - case (SUDOKU_BUTTON_DOWN | BUTTON_REPEAT): - if (state.y==8) { - move_cursor(&state,state.x,0); - } else { - move_cursor(&state,state.x,state.y+1); - } - break; - - case SUDOKU_BUTTON_MENU: + case SUDOKU_BUTTON_MENU: #ifdef SUDOKU_BUTTON_MENU_PRE - if (lastbutton != SUDOKU_BUTTON_MENU_PRE) - break; + if (lastbutton != SUDOKU_BUTTON_MENU_PRE) + break; #endif - /* Don't let the user leave a game in a bad state */ - if (check_status(&state)) { - rb->splash(HZ*2, true, "Illegal move!"); - /* Ignore any button presses during the splash */ - rb->button_clear_queue(); - } else { - if (state.editmode) { - rb->kbd_input(state.filename,MAX_PATH); - if (save_sudoku(&state)) { - state.editmode=0; - } else { - rb->splash(HZ*2, true, "Save failed"); - } - } else { - if (sudoku_menu(&state)) { - return PLUGIN_USB_CONNECTED; - } - } - } - break; + /* Don't let the user leave a game in a bad state */ + if (check_status(&state)) { + rb->splash(HZ*2, true, "Illegal move!"); + /* Ignore any button presses during the splash */ + rb->button_clear_queue(); + } else { + if (state.editmode) { + rb->kbd_input(state.filename,MAX_PATH); + if (save_sudoku(&state)) { + state.editmode=0; + } else { + rb->splash(HZ*2, true, "Save failed"); + } + } else { + if (sudoku_menu(&state)) { + return PLUGIN_USB_CONNECTED; + } + } + } + break; #ifdef SUDOKU_BUTTON_POSSIBLE - case SUDOKU_BUTTON_POSSIBLE: - /* Toggle current number in the possiblevals structure */ - if (state.currentboard[state.y][state.x]!='0') { - state.possiblevals[state.y][state.x]^= - (1 << (state.currentboard[state.y][state.x] - '0')); - } - break; + case SUDOKU_BUTTON_POSSIBLE: + /* Toggle current number in the possiblevals structure */ + if (state.currentboard[state.y][state.x]!='0') { + state.possiblevals[state.y][state.x]^= + (1 << (state.currentboard[state.y][state.x] - '0')); + } + break; #endif - default: - if (rb->default_event_handler(button) == SYS_USB_CONNECTED) { - /* Quit if USB has been connected */ - return PLUGIN_USB_CONNECTED; + default: + if (rb->default_event_handler(button) == SYS_USB_CONNECTED) { + /* Quit if USB has been connected */ + return PLUGIN_USB_CONNECTED; + } + break; } - break; + if (button != BUTTON_NONE) + lastbutton = button; + + display_board(&state); } - if (button != BUTTON_NONE) - lastbutton = button; - display_board(&state); - } - - return PLUGIN_OK; + return PLUGIN_OK; } #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 @@ #include "plugin.h" #include "sh7034.h" #include "system.h" -#include "../apps/recorder/widgets.h" // not in search path, booh +#include "../apps/recorder/widgets.h" /* not in search path, booh */ -#ifndef SIMULATOR // not for simulator by now -#ifdef HAVE_LCD_BITMAP // and definitely not for the Player, haha +#ifndef SIMULATOR /* not for simulator by now */ +#ifdef HAVE_LCD_BITMAP /* and definitely not for the Player, haha */ PLUGIN_HEADER @@ -52,89 +52,89 @@ PLUGIN_HEADER #endif /****************** constants ******************/ -#define SCREENSIZE (LCD_WIDTH*LCD_HEIGHT/8) // in bytes -#define FPS 68 // default fps for headerless (old video-only) file -#define MAX_ACC 20 // maximum FF/FR speedup -#define FF_TICKS 3000; // experimentally found nice +#define SCREENSIZE (LCD_WIDTH*LCD_HEIGHT/8) /* in bytes */ +#define FPS 68 /* default fps for headerless (old video-only) file */ +#define MAX_ACC 20 /* maximum FF/FR speedup */ +#define FF_TICKS 3000; /* experimentally found nice */ -// trigger levels, we need about 80 kB/sec -#define SPINUP_INIT 5000 // from what level on to refill, in milliseconds -#define SPINUP_SAFETY 700 // how much on top of the measured spinup time -#define CHUNK (1024*32) // read size +/* trigger levels, we need about 80 kB/sec */ +#define SPINUP_INIT 5000 /* from what level on to refill, in milliseconds */ +#define SPINUP_SAFETY 700 /* how much on top of the measured spinup time */ +#define CHUNK (1024*32) /* read size */ /****************** prototypes ******************/ -void timer4_isr(void); // IMIA4 ISR -int check_button(void); // determine next relative frame +void timer4_isr(void); /* IMIA4 ISR */ +int check_button(void); /* determine next relative frame */ /****************** data types ******************/ -// plugins don't introduce headers, so structs are repeated from rvf_format.h +/* plugins don't introduce headers, so structs are repeated from rvf_format.h */ -#define HEADER_MAGIC 0x52564668 // "RVFh" at file start -#define AUDIO_MAGIC 0x41756446 // "AudF" for each audio block -#define FILEVERSION 100 // 1.00 +#define HEADER_MAGIC 0x52564668 /* "RVFh" at file start */ +#define AUDIO_MAGIC 0x41756446 /* "AudF" for each audio block */ +#define FILEVERSION 100 /* 1.00 */ -// format type definitions +/* format type definitions */ #define VIDEOFORMAT_NO_VIDEO 0 #define VIDEOFORMAT_RAW 1 #define AUDIOFORMAT_NO_AUDIO 0 #define AUDIOFORMAT_MP3 1 #define AUDIOFORMAT_MP3_BITSWAPPED 2 -// bit flags -#define FLAG_LOOP 0x00000001 // loop the playback, e.g. for stills +/* bit flags */ +#define FLAG_LOOP 0x00000001 /* loop the playback, e.g. for stills */ -typedef struct // contains whatever might be useful to the player +typedef struct /* contains whatever might be useful to the player */ { - // general info (16 entries = 64 byte) - unsigned long magic; // HEADER_MAGIC - unsigned long version; // file version - unsigned long flags; // combination of FLAG_xx - unsigned long blocksize; // how many bytes per block (=video frame) - unsigned long bps_average; // bits per second of the whole stream - unsigned long bps_peak; // max. of above (audio may be VBR) - unsigned long resume_pos; // file position to resume to - unsigned long reserved[9]; // reserved, should be zero + /* general info (16 entries = 64 byte) */ + unsigned long magic; /* HEADER_MAGIC */ + unsigned long version; /* file version */ + unsigned long flags; /* combination of FLAG_xx */ + unsigned long blocksize; /* how many bytes per block (=video frame) */ + unsigned long bps_average; /* bits per second of the whole stream */ + unsigned long bps_peak; /* max. of above (audio may be VBR) */ + unsigned long resume_pos; /* file position to resume to */ + unsigned long reserved[9]; /* reserved, should be zero */ - // video info (16 entries = 64 byte) - unsigned long video_format; // one of VIDEOFORMAT_xxx - unsigned long video_1st_frame; // byte position of first video frame - unsigned long video_duration; // total length of video part, in ms - unsigned long video_payload_size; // total amount of video data, in bytes - unsigned long video_bitrate; // derived from resolution and frame time, in bps - unsigned long video_frametime; // frame interval in 11.0592 MHz clocks - long video_preroll; // video is how much ahead, in 11.0592 MHz clocks - unsigned long video_width; // in pixels - unsigned long video_height; // in pixels - unsigned long video_reserved[7]; // reserved, should be zero + /* video info (16 entries = 64 byte) */ + unsigned long video_format; /* one of VIDEOFORMAT_xxx */ + unsigned long video_1st_frame; /* byte position of first video frame */ + unsigned long video_duration; /* total length of video part, in ms */ + unsigned long video_payload_size; /* total amount of video data, in bytes */ + unsigned long video_bitrate; /* derived from resolution and frame time, in bps */ + unsigned long video_frametime; /* frame interval in 11.0592 MHz clocks */ + long video_preroll; /* video is how much ahead, in 11.0592 MHz clocks */ + unsigned long video_width; /* in pixels */ + unsigned long video_height; /* in pixels */ + unsigned long video_reserved[7]; /* reserved, should be zero */ - // audio info (16 entries = 64 byte) - unsigned long audio_format; // one of AUDIOFORMAT_xxx - unsigned long audio_1st_frame; // byte position of first video frame - unsigned long audio_duration; // total length of audio part, in ms - unsigned long audio_payload_size; // total amount of audio data, in bytes - unsigned long audio_avg_bitrate; // average audio bitrate, in bits per second - unsigned long audio_peak_bitrate; // maximum bitrate - unsigned long audio_headersize; // offset to payload in audio frames - long audio_min_associated; // minimum offset to video frame, in bytes - long audio_max_associated; // maximum offset to video frame, in bytes - unsigned long audio_reserved[7]; // reserved, should be zero + /* audio info (16 entries = 64 byte) */ + unsigned long audio_format; /* one of AUDIOFORMAT_xxx */ + unsigned long audio_1st_frame; /* byte position of first video frame */ + unsigned long audio_duration; /* total length of audio part, in ms */ + unsigned long audio_payload_size; /* total amount of audio data, in bytes */ + unsigned long audio_avg_bitrate; /* average audio bitrate, in bits per second */ + unsigned long audio_peak_bitrate; /* maximum bitrate */ + unsigned long audio_headersize; /* offset to payload in audio frames */ + long audio_min_associated; /* minimum offset to video frame, in bytes */ + long audio_max_associated; /* maximum offset to video frame, in bytes */ + unsigned long audio_reserved[7]; /* reserved, should be zero */ - // more to come... ? + /* more to come... ? */ - // Note: padding up to 'blocksize' with zero following this header + /* Note: padding up to 'blocksize' with zero following this header */ } tFileHeader; -typedef struct // the little header for all audio blocks +typedef struct /* the little header for all audio blocks */ { - unsigned long magic; // AUDIO_MAGIC indicates an audio block - unsigned char previous_block; // previous how many blocks backwards - unsigned char next_block; // next how many blocks forward - short associated_video; // offset to block with corresponding video - unsigned short frame_start; // offset to first frame starting in this block - unsigned short frame_end; // offset to behind last frame ending in this block + unsigned long magic; /* AUDIO_MAGIC indicates an audio block */ + unsigned char previous_block; /* previous how many blocks backwards */ + unsigned char next_block; /* next how many blocks forward */ + short associated_video; /* offset to block with corresponding video */ + unsigned short frame_start; /* offset to first frame starting in this block */ + unsigned short frame_end; /* offset to behind last frame ending in this block */ } tAudioFrameHeader; @@ -145,7 +145,7 @@ static struct plugin_api* rb; /* here is a global api struct pointer */ static char gPrint[32]; /* a global printf buffer, saves stack */ -// playstate +/* playstate */ static struct { enum @@ -157,40 +157,40 @@ static struct bool bVideoUnderrun; bool bHasAudio; bool bHasVideo; - int nTimeOSD; // OSD should stay for this many frames - bool bDirtyOSD; // OSD needs redraw - bool bRefilling; // set if refilling buffer + int nTimeOSD; /* OSD should stay for this many frames */ + bool bDirtyOSD; /* OSD needs redraw */ + bool bRefilling; /* set if refilling buffer */ bool bSeeking; - int nSeekAcc; // accelleration value for seek - int nSeekPos; // current file position for seek - bool bDiskSleep; // disk is suspended + int nSeekAcc; /* accelleration value for seek */ + int nSeekPos; /* current file position for seek */ + bool bDiskSleep; /* disk is suspended */ #if FREQ == 12000000 /* Ondio speed kludge */ int nFrameTimeAdjusted; #endif } gPlay; -// buffer information +/* buffer information */ static struct { int bufsize; - int granularity; // common multiple of block and sector size - unsigned char* pBufStart; // start of ring buffer - unsigned char* pBufEnd; // end of ring buffer - unsigned char* pOSD; // OSD memory (112 bytes for 112*8 pixels) + int granularity; /* common multiple of block and sector size */ + unsigned char* pBufStart; /* start of ring buffer */ + unsigned char* pBufEnd; /* end of ring buffer */ + unsigned char* pOSD; /* OSD memory (112 bytes for 112*8 pixels) */ - int vidcount; // how many video blocks are known in a row - unsigned char* pBufFill; // write pointer for disk, owned by main task - unsigned char* pReadVideo; // video readout, maintained by timer ISR - unsigned char* pReadAudio; // audio readout, maintained by demand ISR - bool bEOF; // flag for end of file - int low_water; // reload threshold - int high_water; // end of reload threshold - int spinup_safety; // safety margin when recalculating low_water - int nReadChunk; // how much data for normal buffer fill - int nSeekChunk; // how much data while seeking + int vidcount; /* how many video blocks are known in a row */ + unsigned char* pBufFill; /* write pointer for disk, owned by main task */ + unsigned char* pReadVideo; /* video readout, maintained by timer ISR */ + unsigned char* pReadAudio; /* audio readout, maintained by demand ISR */ + bool bEOF; /* flag for end of file */ + int low_water; /* reload threshold */ + int high_water; /* end of reload threshold */ + int spinup_safety; /* safety margin when recalculating low_water */ + int nReadChunk; /* how much data for normal buffer fill */ + int nSeekChunk; /* how much data while seeking */ } gBuf; -// statistics +/* statistics */ static struct { int minAudioAvail; @@ -201,11 +201,11 @@ static struct long maxSpinup; } gStats; -tFileHeader gFileHdr; // file header +tFileHeader gFileHdr; /* file header */ /****************** implementation ******************/ -// tool function: return how much playable audio/video is left +/* tool function: return how much playable audio/video is left */ int Available(unsigned char* pSnapshot) { if (pSnapshot <= gBuf.pBufFill) @@ -214,35 +214,35 @@ int Available(unsigned char* pSnapshot) return gBuf.bufsize - (pSnapshot - gBuf.pBufFill); } -// debug function to draw buffer indicators +/* debug function to draw buffer indicators */ void DrawBuf(void) { int fill, video, audio; - rb->memset(gBuf.pOSD, 0x10, LCD_WIDTH); // draw line - gBuf.pOSD[0] = gBuf.pOSD[LCD_WIDTH-1] = 0xFE; // ends + rb->memset(gBuf.pOSD, 0x10, LCD_WIDTH); /* draw line */ + gBuf.pOSD[0] = gBuf.pOSD[LCD_WIDTH-1] = 0xFE; /* ends */ - // calculate new tick positions + /* calculate new tick positions */ fill = 1 + ((gBuf.pBufFill - gBuf.pBufStart) * (LCD_WIDTH-2)) / gBuf.bufsize; video = 1 + ((gBuf.pReadVideo - gBuf.pBufStart) * (LCD_WIDTH-2)) / gBuf.bufsize; audio = 1 + ((gBuf.pReadAudio - gBuf.pBufStart) * (LCD_WIDTH-2)) / gBuf.bufsize; - gBuf.pOSD[fill] |= 0x20; // below the line, two pixels - gBuf.pOSD[video] |= 0x08; // one above - gBuf.pOSD[audio] |= 0x04; // two above + gBuf.pOSD[fill] |= 0x20; /* below the line, two pixels */ + gBuf.pOSD[video] |= 0x08; /* one above */ + gBuf.pOSD[audio] |= 0x04; /* two above */ - if (gPlay.state == paused) // we have to draw ourselves + if (gPlay.state == paused) /* we have to draw ourselves */ rb->lcd_update_rect(0, LCD_HEIGHT-8, LCD_WIDTH, 8); else - gPlay.bDirtyOSD = true; // redraw it with next timer IRQ + gPlay.bDirtyOSD = true; /* redraw it with next timer IRQ */ } -// helper function to draw a position indicator +/* helper function to draw a position indicator */ void DrawPosition(int pos, int total) { int w,h; - int sec; // estimated seconds + int sec; /* estimated seconds */ /* print the estimated position */ @@ -258,17 +258,17 @@ void DrawPosition(int pos, int total) w++; rb->scrollbar(w, LCD_HEIGHT-7, LCD_WIDTH-w, 7, total, 0, pos, HORIZONTAL); - if (gPlay.state == paused) // we have to draw ourselves + if (gPlay.state == paused) /* we have to draw ourselves */ rb->lcd_update_rect(0, LCD_HEIGHT-8, LCD_WIDTH, 8); - else // let the display time do it + else /* let the display time do it */ { gPlay.nTimeOSD = 70; - gPlay.bDirtyOSD = true; // redraw it with next timer IRQ + gPlay.bDirtyOSD = true; /* redraw it with next timer IRQ */ } } -// helper function to change the volume by a certain amount, +/- +/* helper function to change the volume by a certain amount, +/- */ void ChangeVolume(int delta) { int minvol = rb->sound_min(SOUND_VOLUME); @@ -283,18 +283,18 @@ void ChangeVolume(int delta) rb->global_settings->volume = vol; rb->snprintf(gPrint, sizeof(gPrint), "Vol: %d dB", vol); rb->lcd_puts(0, 7, gPrint); - if (gPlay.state == paused) // we have to draw ourselves + if (gPlay.state == paused) /* we have to draw ourselves */ rb->lcd_update_rect(0, LCD_HEIGHT-8, LCD_WIDTH, 8); - else // let the display time do it + else /* let the display time do it */ { - gPlay.nTimeOSD = 50; // display it for 50 frames - gPlay.bDirtyOSD = true; // let the refresh copy it to LCD + gPlay.nTimeOSD = 50; /* display it for 50 frames */ + gPlay.bDirtyOSD = true; /* let the refresh copy it to LCD */ } } } -// helper function to change the LCD contrast by a certain amount, +/- +/* helper function to change the LCD contrast by a certain amount, +/- */ void ChangeContrast(int delta) { static int mycontrast = -1; /* the "permanent" value while running */ @@ -312,18 +312,18 @@ void ChangeContrast(int delta) mycontrast = contrast; rb->snprintf(gPrint, sizeof(gPrint), "Contrast: %d", contrast); rb->lcd_puts(0, 7, gPrint); - if (gPlay.state == paused) // we have to draw ourselves + if (gPlay.state == paused) /* we have to draw ourselves */ rb->lcd_update_rect(0, LCD_HEIGHT-8, LCD_WIDTH, 8); - else // let the display time do it + else /* let the display time do it */ { - gPlay.nTimeOSD = 50; // display it for 50 frames - gPlay.bDirtyOSD = true; // let the refresh copy it to LCD + gPlay.nTimeOSD = 50; /* display it for 50 frames */ + gPlay.bDirtyOSD = true; /* let the refresh copy it to LCD */ } } } -// sync the video to the current audio +/* sync the video to the current audio */ void SyncVideo(void) { tAudioFrameHeader* pAudioBuf; @@ -331,12 +331,12 @@ void SyncVideo(void) pAudioBuf = (tAudioFrameHeader*)(gBuf.pReadAudio); if (pAudioBuf->magic == AUDIO_MAGIC) { - gBuf.vidcount = 0; // nothing known - // sync the video position + gBuf.vidcount = 0; /* nothing known */ + /* sync the video position */ gBuf.pReadVideo = gBuf.pReadAudio + (long)pAudioBuf->associated_video * (long)gFileHdr.blocksize; - // handle possible wrap + /* handle possible wrap */ if (gBuf.pReadVideo >= gBuf.pBufEnd) gBuf.pReadVideo -= gBuf.bufsize; else if (gBuf.pReadVideo < gBuf.pBufStart) @@ -345,21 +345,21 @@ void SyncVideo(void) } -// timer interrupt handler to display a frame +/* timer interrupt handler to display a frame */ void timer4_isr(void) { int available; tAudioFrameHeader* pAudioBuf; - int height; // height to display + int height; /* height to display */ - // reduce height if we have OSD on + /* reduce height if we have OSD on */ height = gFileHdr.video_height/8; if (gPlay.nTimeOSD > 0) { gPlay.nTimeOSD--; - height = MIN(LCD_HEIGHT/8-1, height); // reserve bottom line + height = MIN(LCD_HEIGHT/8-1, height); /* reserve bottom line */ if (gPlay.bDirtyOSD) - { // OSD to bottom line + { /* OSD to bottom line */ rb->lcd_blit(gBuf.pOSD, 0, LCD_HEIGHT/8-1, LCD_WIDTH, 1, LCD_WIDTH); gPlay.bDirtyOSD = false; @@ -371,58 +371,58 @@ void timer4_isr(void) available = Available(gBuf.pReadVideo); - // loop to skip audio frame(s) + /* loop to skip audio frame(s) */ while(1) { - // just for the statistics + /* just for the statistics */ if (!gBuf.bEOF && available < gStats.minVideoAvail) gStats.minVideoAvail = available; if (available <= (int)gFileHdr.blocksize) - { // no data for next frame + { /* no data for next frame */ if (gBuf.bEOF && (gFileHdr.flags & FLAG_LOOP)) - { // loop now, assuming the looped clip fits in memory + { /* loop now, assuming the looped clip fits in memory */ gBuf.pReadVideo = gBuf.pBufStart + gFileHdr.video_1st_frame; - // FixMe: pReadVideo is incremented below + /* FixMe: pReadVideo is incremented below */ } else { gPlay.bVideoUnderrun = true; - rb->timer_unregister(); // disable ourselves - return; // no data available + rb->timer_unregister(); /* disable ourselves */ + return; /* no data available */ } } - else // normal advance for next time + else /* normal advance for next time */ { gBuf.pReadVideo += gFileHdr.blocksize; if (gBuf.pReadVideo >= gBuf.pBufEnd) - gBuf.pReadVideo -= gBuf.bufsize; // wraparound + gBuf.pReadVideo -= gBuf.bufsize; /* wraparound */ available -= gFileHdr.blocksize; } if (!gPlay.bHasAudio) - break; // no need to skip any audio + break; /* no need to skip any audio */ if (gBuf.vidcount) { - // we know the next is a video frame + /* we know the next is a video frame */ gBuf.vidcount--; - break; // exit the loop + break; /* exit the loop */ } pAudioBuf = (tAudioFrameHeader*)(gBuf.pReadVideo); if (pAudioBuf->magic == AUDIO_MAGIC) - { // we ran into audio, can happen after seek + { /* we ran into audio, can happen after seek */ gBuf.vidcount = pAudioBuf->next_block; if (gBuf.vidcount) - gBuf.vidcount--; // minus the audio block + gBuf.vidcount--; /* minus the audio block */ } - } // while + } /* while */ } -// ISR function to get more mp3 data +/* ISR function to get more mp3 data */ void GetMoreMp3(unsigned char** start, int* size) { int available; @@ -434,19 +434,19 @@ void GetMoreMp3(unsigned char** start, int* size) available = Available(gBuf.pReadAudio); - // just for the statistics + /* just for the statistics */ if (!gBuf.bEOF && available < gStats.minAudioAvail) gStats.minAudioAvail = available; if (available < advance + (int)gFileHdr.blocksize || advance == 0) { gPlay.bAudioUnderrun = true; - return; // no data available + return; /* no data available */ } gBuf.pReadAudio += advance; if (gBuf.pReadAudio >= gBuf.pBufEnd) - gBuf.pReadAudio -= gBuf.bufsize; // wraparound + gBuf.pReadAudio -= gBuf.bufsize; /* wraparound */ *start = gBuf.pReadAudio + gFileHdr.audio_headersize; *size = gFileHdr.blocksize - gFileHdr.audio_headersize; @@ -489,23 +489,23 @@ int SeekTo(int fd, int nPos) int read_now, got_now; if (gPlay.bHasAudio) - rb->mp3_play_stop(); // stop audio ISR + rb->mp3_play_stop(); /* stop audio ISR */ if (gPlay.bHasVideo) - rb->timer_unregister(); // stop the timer + rb->timer_unregister(); /* stop the timer */ rb->lseek(fd, nPos, SEEK_SET); - gBuf.pBufFill = gBuf.pBufStart; // all empty + gBuf.pBufFill = gBuf.pBufStart; /* all empty */ gBuf.pReadVideo = gBuf.pReadAudio = gBuf.pBufStart; - read_now = gBuf.low_water - 1; // less than low water, so loading will continue - read_now -= read_now % gBuf.granularity; // round down to granularity + read_now = gBuf.low_water - 1; /* less than low water, so loading will continue */ + read_now -= read_now % gBuf.granularity; /* round down to granularity */ got_now = rb->read(fd, gBuf.pBufFill, read_now); gBuf.bEOF = (read_now != got_now); gBuf.pBufFill += got_now; if (nPos == 0) - { // we seeked to the start + { /* we seeked to the start */ if (gPlay.bHasVideo) gBuf.pReadVideo += gFileHdr.video_1st_frame; @@ -513,31 +513,31 @@ int SeekTo(int fd, int nPos) gBuf.pReadAudio += gFileHdr.audio_1st_frame; } else - { // we have to search for the positions - if (gPlay.bHasAudio) // prepare audio playback, if contained + { /* we have to search for the positions */ + if (gPlay.bHasAudio) /* prepare audio playback, if contained */ { - // search for audio frame + /* search for audio frame */ while (((tAudioFrameHeader*)(gBuf.pReadAudio))->magic != AUDIO_MAGIC) gBuf.pReadAudio += gFileHdr.blocksize; if (gPlay.bHasVideo) - SyncVideo(); // pick the right video for that + SyncVideo(); /* pick the right video for that */ } } - // synchronous start + /* synchronous start */ gPlay.state = playing; if (gPlay.bHasAudio) { gPlay.bAudioUnderrun = false; rb->mp3_play_data(gBuf.pReadAudio + gFileHdr.audio_headersize, gFileHdr.blocksize - gFileHdr.audio_headersize, GetMoreMp3); - rb->mp3_play_pause(true); // kickoff audio + rb->mp3_play_pause(true); /* kickoff audio */ } if (gPlay.bHasVideo) { gPlay.bVideoUnderrun = false; - // start display interrupt + /* start display interrupt */ #if FREQ == 12000000 /* Ondio speed kludge */ rb->timer_register(1, NULL, gPlay.nFrameTimeAdjusted, 1, timer4_isr); #else @@ -548,25 +548,25 @@ int SeekTo(int fd, int nPos) return 0; } -// called from default_event_handler_ex() or at end of playback +/* called from default_event_handler_ex() or at end of playback */ void Cleanup(void *fd) { - rb->close(*(int*)fd); // close the file + rb->close(*(int*)fd); /* close the file */ if (gPlay.bHasVideo) - rb->timer_unregister(); // stop video ISR, now I can use the display again + rb->timer_unregister(); /* stop video ISR, now I can use the display again */ if (gPlay.bHasAudio) - rb->mp3_play_stop(); // stop audio ISR + rb->mp3_play_stop(); /* stop audio ISR */ - // restore normal backlight setting + /* restore normal backlight setting */ rb->backlight_set_timeout(rb->global_settings->backlight_timeout); - // restore normal contrast + /* restore normal contrast */ rb->lcd_set_contrast(rb->global_settings->contrast); } -// returns >0 if continue, =0 to stop, <0 to abort (USB) +/* returns >0 if continue, =0 to stop, <0 to abort (USB) */ int PlayTick(int fd) { int button; @@ -575,7 +575,7 @@ int PlayTick(int fd) int retval = 1; int filepos; - // check buffer level + /* check buffer level */ if (gPlay.bHasAudio) avail_audio = Available(gBuf.pReadAudio); @@ -593,41 +593,41 @@ int PlayTick(int fd) && gBuf.bEOF) { if (gFileHdr.resume_pos) - { // we played til the end, clear resume position + { /* we played til the end, clear resume position */ gFileHdr.resume_pos = 0; - rb->lseek(fd, 0, SEEK_SET); // save resume position + rb->lseek(fd, 0, SEEK_SET); /* save resume position */ rb->write(fd, &gFileHdr, sizeof(gFileHdr)); } Cleanup(&fd); - return 0; // all expired + return 0; /* all expired */ } if (!gPlay.bRefilling || gBuf.bEOF) - { // nothing to do + { /* nothing to do */ button = rb->button_get_w_tmo(HZ/10); } else - { // refill buffer + { /* refill buffer */ int read_now, got_now; int buf_free; - long spinup; // measure the spinup time + long spinup; /* measure the spinup time */ - // how much can we reload, don't fill completely, would appear empty + /* how much can we reload, don't fill completely, would appear empty */ buf_free = gBuf.bufsize - MAX(avail_audio, avail_video) - gBuf.high_water; if (buf_free < 0) - buf_free = 0; // just for safety - buf_free -= buf_free % gBuf.granularity; // round down to granularity + buf_free = 0; /* just for safety */ + buf_free -= buf_free % gBuf.granularity; /* round down to granularity */ - // in one piece max. up to buffer end (wrap after that) + /* in one piece max. up to buffer end (wrap after that) */ read_now = MIN(buf_free, gBuf.pBufEnd - gBuf.pBufFill); - // load piecewise, to stay responsive + /* load piecewise, to stay responsive */ read_now = MIN(read_now, gBuf.nReadChunk); if (read_now == buf_free) - gPlay.bRefilling = false; // last piece requested + gPlay.bRefilling = false; /* last piece requested */ - spinup = *rb->current_tick; // in case this is interesting below + spinup = *rb->current_tick; /* in case this is interesting below */ got_now = rb->read(fd, gBuf.pBufFill, read_now); if (got_now != read_now || read_now == 0) @@ -636,7 +636,7 @@ int PlayTick(int fd) gPlay.bRefilling = false; } - if (gPlay.bDiskSleep) // statistics about the spinup time + if (gPlay.bDiskSleep) /* statistics about the spinup time */ { spinup = *rb->current_tick - spinup; gPlay.bDiskSleep = false; @@ -645,49 +645,48 @@ int PlayTick(int fd) if (spinup < gStats.minSpinup) gStats.minSpinup = spinup; - // recalculate the low water mark from real measurements + /* recalculate the low water mark from real measurements */ gBuf.low_water = (gStats.maxSpinup + gBuf.spinup_safety) * gFileHdr.bps_peak / 8 / HZ; } if (!gPlay.bRefilling - && rb->global_settings->disk_spindown < 20) // condition for test only + && rb->global_settings->disk_spindown < 20) /* condition for test only */ { - rb->ata_sleep(); // no point in leaving the disk run til timeout + rb->ata_sleep(); /* no point in leaving the disk run til timeout */ gPlay.bDiskSleep = true; } gBuf.pBufFill += got_now; if (gBuf.pBufFill >= gBuf.pBufEnd) - gBuf.pBufFill = gBuf.pBufStart; // wrap + gBuf.pBufFill = gBuf.pBufStart; /* wrap */ - rb->yield(); // have mercy with the other threads + rb->yield(); /* have mercy with the other threads */ button = rb->button_get(false); } - // check keypresses + /* check keypresses */ if (button != BUTTON_NONE) { filepos = rb->lseek(fd, 0, SEEK_CUR); - if (gPlay.bHasVideo) // video position is more accurate - filepos -= Available(gBuf.pReadVideo); // take video position + if (gPlay.bHasVideo) /* video position is more accurate */ + filepos -= Available(gBuf.pReadVideo); /* take video position */ else - filepos -= Available(gBuf.pReadAudio); // else audio + filepos -= Available(gBuf.pReadAudio); /* else audio */ - switch (button) - { // set exit conditions + switch (button) { /* set exit conditions */ case BUTTON_OFF: - if (gFileHdr.magic == HEADER_MAGIC // only if file has header - && !(gFileHdr.flags & FLAG_LOOP)) // not for stills + if (gFileHdr.magic == HEADER_MAGIC /* only if file has header */ + && !(gFileHdr.flags & FLAG_LOOP)) /* not for stills */ { gFileHdr.resume_pos = filepos; - rb->lseek(fd, 0, SEEK_SET); // save resume position + rb->lseek(fd, 0, SEEK_SET); /* save resume position */ rb->write(fd, &gFileHdr, sizeof(gFileHdr)); } Cleanup(&fd); - retval = 0; // signal "stopped" to caller + retval = 0; /* signal "stopped" to caller */ break; case VIDEO_STOP_SEEK: #ifdef VIDEO_STOP_SEEK_PRE @@ -704,9 +703,9 @@ int PlayTick(int fd) { gPlay.state = paused; if (gPlay.bHasAudio) - rb->mp3_play_pause(false); // pause audio + rb->mp3_play_pause(false); /* pause audio */ if (gPlay.bHasVideo) - rb->timer_unregister(); // stop the timer + rb->timer_unregister(); /* stop the timer */ } else if (gPlay.state == paused) { @@ -715,10 +714,10 @@ int PlayTick(int fd) { if (gPlay.bHasVideo) SyncVideo(); - rb->mp3_play_pause(true); // play audio + rb->mp3_play_pause(true); /* play audio */ } if (gPlay.bHasVideo) - { // start the video + { /* start the video */ #if FREQ == 12000000 /* Ondio speed kludge */ rb->timer_register(1, NULL, gPlay.nFrameTimeAdjusted, 1, timer4_isr); @@ -741,44 +740,44 @@ int PlayTick(int fd) break; case BUTTON_LEFT: case BUTTON_LEFT | BUTTON_REPEAT: - if (!gPlay.bSeeking) // prepare seek + if (!gPlay.bSeeking) /* prepare seek */ { gPlay.nSeekPos = filepos; gPlay.bSeeking = true; gPlay.nSeekAcc = 0; } - else if (gPlay.nSeekAcc > 0) // other direction, stop sliding + else if (gPlay.nSeekAcc > 0) /* other direction, stop sliding */ gPlay.nSeekAcc = 0; else gPlay.nSeekAcc--; break; case BUTTON_RIGHT: case BUTTON_RIGHT | BUTTON_REPEAT: - if (!gPlay.bSeeking) // prepare seek + if (!gPlay.bSeeking) /* prepare seek */ { gPlay.nSeekPos = filepos; gPlay.bSeeking = true; gPlay.nSeekAcc = 0; } - else if (gPlay.nSeekAcc < 0) // other direction, stop sliding + else if (gPlay.nSeekAcc < 0) /* other direction, stop sliding */ gPlay.nSeekAcc = 0; else gPlay.nSeekAcc++; break; #ifdef VIDEO_DEBUG - case VIDEO_DEBUG: // debug key + case VIDEO_DEBUG: /* debug key */ case VIDEO_DEBUG | BUTTON_REPEAT: - DrawBuf(); // show buffer status + DrawBuf(); /* show buffer status */ gPlay.nTimeOSD = 30; gPlay.bDirtyOSD = true; break; #endif - case VIDEO_CONTRAST_DOWN: // contrast down + case VIDEO_CONTRAST_DOWN: /* contrast down */ case VIDEO_CONTRAST_DOWN | BUTTON_REPEAT: if (gPlay.bHasVideo) ChangeContrast(-1); break; - case VIDEO_CONTRAST_UP: // contrast up + case VIDEO_CONTRAST_UP: /* contrast up */ case VIDEO_CONTRAST_UP | BUTTON_REPEAT: if (gPlay.bHasVideo) ChangeContrast(1); @@ -786,7 +785,7 @@ int PlayTick(int fd) default: if (rb->default_event_handler_ex(button, Cleanup, &fd) == SYS_USB_CONNECTED) - retval = -1; // signal "aborted" to caller + retval = -1; /* signal "aborted" to caller */ break; } @@ -794,9 +793,9 @@ int PlayTick(int fd) } /* if (button != BUTTON_NONE) */ - // handle seeking + /* handle seeking */ - if (gPlay.bSeeking) // seeking? + if (gPlay.bSeeking) /* seeking? */ { if (gPlay.nSeekAcc < -MAX_ACC) gPlay.nSeekAcc = -MAX_ACC; @@ -815,23 +814,23 @@ int PlayTick(int fd) } - // check + recover underruns + /* check + recover underruns */ if ((gPlay.bAudioUnderrun || gPlay.bVideoUnderrun) && !gBuf.bEOF) { - gBuf.spinup_safety += HZ/2; // add extra spinup time for the future + gBuf.spinup_safety += HZ/2; /* add extra spinup time for the future */ filepos = rb->lseek(fd, 0, SEEK_CUR); if (gPlay.bHasVideo && gPlay.bVideoUnderrun) { gStats.nVideoUnderruns++; - filepos -= Available(gBuf.pReadVideo); // take video position + filepos -= Available(gBuf.pReadVideo); /* take video position */ SeekTo(fd, filepos); } else if (gPlay.bHasAudio && gPlay.bAudioUnderrun) { gStats.nAudioUnderruns++; - filepos -= Available(gBuf.pReadAudio); // else audio + filepos -= Available(gBuf.pReadAudio); /* else audio */ SeekTo(fd, filepos); } } @@ -848,46 +847,46 @@ int main(char* filename) int button = 0; int retval; - // try to open the file + /* try to open the file */ fd = rb->open(filename, O_RDWR); if (fd < 0) return PLUGIN_ERROR; file_size = rb->filesize(fd); - // reset pitch value to ensure synchronous playback + /* reset pitch value to ensure synchronous playback */ rb->sound_set_pitch(1000); - // init statistics + /* init statistics */ rb->memset(&gStats, 0, sizeof(gStats)); gStats.minAudioAvail = gStats.minVideoAvail = INT_MAX; gStats.minSpinup = INT_MAX; - // init playback state + /* init playback state */ rb->memset(&gPlay, 0, sizeof(gPlay)); - // init buffer + /* init buffer */ rb->memset(&gBuf, 0, sizeof(gBuf)); - gBuf.pOSD = rb->lcd_framebuffer + LCD_WIDTH*7; // last screen line + gBuf.pOSD = rb->lcd_framebuffer + LCD_WIDTH*7; /* last screen line */ gBuf.pBufStart = rb->plugin_get_audio_buffer(&gBuf.bufsize); - //gBuf.bufsize = 1700*1024; // test, like 2MB version!!!! - gBuf.pBufFill = gBuf.pBufStart; // all empty + /*gBuf.bufsize = 1700*1024; // test, like 2MB version!!!! */ + gBuf.pBufFill = gBuf.pBufStart; /* all empty */ - // load file header + /* load file header */ read_now = sizeof(gFileHdr); got_now = rb->read(fd, &gFileHdr, read_now); - rb->lseek(fd, 0, SEEK_SET); // rewind to restart sector-aligned + rb->lseek(fd, 0, SEEK_SET); /* rewind to restart sector-aligned */ if (got_now != read_now) { rb->close(fd); return (PLUGIN_ERROR); } - // check header + /* check header */ if (gFileHdr.magic != HEADER_MAGIC) - { // old file, use default info + { /* old file, use default info */ rb->memset(&gFileHdr, 0, sizeof(gFileHdr)); gFileHdr.blocksize = SCREENSIZE; - if (file_size < SCREENSIZE * FPS) // less than a second + if (file_size < SCREENSIZE * FPS) /* less than a second */ gFileHdr.flags |= FLAG_LOOP; gFileHdr.video_format = VIDEOFORMAT_RAW; gFileHdr.video_width = LCD_WIDTH; @@ -900,60 +899,60 @@ int main(char* filename) gPlay.nFrameTimeAdjusted = (gFileHdr.video_frametime * 625) / 576; #endif - // continue buffer init: align the end, calc low water, read sizes + /* continue buffer init: align the end, calc low water, read sizes */ gBuf.granularity = gFileHdr.blocksize; - while (gBuf.granularity % 512) // common multiple of sector size + while (gBuf.granularity % 512) /* common multiple of sector size */ gBuf.granularity *= 2; - gBuf.bufsize -= gBuf.bufsize % gBuf.granularity; // round down + gBuf.bufsize -= gBuf.bufsize % gBuf.granularity; /* round down */ gBuf.pBufEnd = gBuf.pBufStart + gBuf.bufsize; gBuf.low_water = SPINUP_INIT * gFileHdr.bps_peak / 8000; - gBuf.spinup_safety = SPINUP_SAFETY * HZ / 1000; // in time ticks + gBuf.spinup_safety = SPINUP_SAFETY * HZ / 1000; /* in time ticks */ if (gFileHdr.audio_min_associated < 0) gBuf.high_water = 0 - gFileHdr.audio_min_associated; else - gBuf.high_water = 1; // never fill buffer completely, would appear empty - gBuf.nReadChunk = (CHUNK + gBuf.granularity - 1); // round up - gBuf.nReadChunk -= gBuf.nReadChunk % gBuf.granularity;// and align + gBuf.high_water = 1; /* never fill buffer completely, would appear empty */ + gBuf.nReadChunk = (CHUNK + gBuf.granularity - 1); /* round up */ + gBuf.nReadChunk -= gBuf.nReadChunk % gBuf.granularity;/* and align */ gBuf.nSeekChunk = rb->filesize(fd) / FF_TICKS; - gBuf.nSeekChunk += gBuf.granularity - 1; // round up - gBuf.nSeekChunk -= gBuf.nSeekChunk % gBuf.granularity; // and align + gBuf.nSeekChunk += gBuf.granularity - 1; /* round up */ + gBuf.nSeekChunk -= gBuf.nSeekChunk % gBuf.granularity; /* and align */ - // prepare video playback, if contained + /* prepare video playback, if contained */ if (gFileHdr.video_format == VIDEOFORMAT_RAW) { gPlay.bHasVideo = true; if (rb->global_settings->backlight_timeout > 0) - rb->backlight_set_timeout(1); // keep the light on + rb->backlight_set_timeout(1); /* keep the light on */ } - // prepare audio playback, if contained + /* prepare audio playback, if contained */ if (gFileHdr.audio_format == AUDIOFORMAT_MP3_BITSWAPPED) { gPlay.bHasAudio = true; } - // start playback by seeking to zero or resume position - if (gFileHdr.resume_pos && WantResume(fd)) // ask the user + /* start playback by seeking to zero or resume position */ + if (gFileHdr.resume_pos && WantResume(fd)) /* ask the user */ SeekTo(fd, gFileHdr.resume_pos); else SeekTo(fd, 0); - // all that's left to do is keep the buffer full - do // the main loop + /* all that's left to do is keep the buffer full */ + do /* the main loop */ { retval = PlayTick(fd); } while (retval > 0); - if (retval < 0) // aborted? + if (retval < 0) /* aborted? */ { return PLUGIN_USB_CONNECTED; } -#ifndef DEBUG // for release compilations, only display the stats in case of error +#ifndef DEBUG /* for release compilations, only display the stats in case of error */ if (gStats.nAudioUnderruns || gStats.nVideoUnderruns) #endif { - // display statistics + /* display statistics */ rb->lcd_clear_display(); rb->snprintf(gPrint, sizeof(gPrint), "%d Audio Underruns", gStats.nAudioUnderruns); rb->lcd_puts(0, 0, gPrint); @@ -983,7 +982,7 @@ int main(char* filename) enum plugin_status plugin_start(struct plugin_api* api, void* parameter) { - rb = api; // copy to global api pointer + rb = api; /* copy to global api pointer */ if (parameter == NULL) { @@ -991,10 +990,10 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) return PLUGIN_ERROR; } - // now go ahead and have fun! + /* now go ahead and have fun! */ return main((char*) parameter); } -#endif // #ifdef HAVE_LCD_BITMAP -#endif // #ifndef SIMULATOR +#endif /* #ifdef HAVE_LCD_BITMAP */ +#endif /* #ifndef SIMULATOR */ 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) num_chans = config.num_channels = native_header.NumChannels; total_samples = native_header.data_ckSize / native_header.BlockAlign; -// config.flags |= CONFIG_HIGH_FLAG; +/* config.flags |= CONFIG_HIGH_FLAG; */ if (!WavpackSetConfiguration (wpc, &config, total_samples)) { rb->splash(HZ*2, true, "internal error!");