summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorBjörn Stenberg <bjorn@haxx.se>2005-09-21 23:09:19 +0000
committerBjörn Stenberg <bjorn@haxx.se>2005-09-21 23:09:19 +0000
commitaf348637a52147cf3a45cee3d82d6459af74d900 (patch)
treec3cbf92a4e99d1f64d2bd93c32bc12a3424aaefb /apps
parent1b79209ea7d02956cf27ce719516dcf495e26f98 (diff)
downloadrockbox-2.5-final.tar.gz
rockbox-2.5-final.zip
This commit was manufactured by cvs2svn to create tag 'v2_5'.v2.5-final
git-svn-id: svn://svn.rockbox.org/rockbox/tags/v2_5@7531 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r--apps/codecs/libmusepack/config.h105
-rw-r--r--apps/credits.c131
-rw-r--r--apps/credits.h28
-rw-r--r--apps/credits.pl13
-rw-r--r--apps/plugins/a52towav.c208
-rw-r--r--apps/plugins/codecmpa.c404
-rw-r--r--apps/plugins/codecvorbis.c161
-rw-r--r--apps/plugins/flac2wav.c237
-rw-r--r--apps/plugins/lib/codeclib.c37
-rw-r--r--apps/plugins/lib/codeclib.h46
-rw-r--r--apps/plugins/lib/gray_black_display.c44
-rw-r--r--apps/plugins/lib/gray_blockfuncs.c262
-rw-r--r--apps/plugins/lib/gray_clear_display.c44
-rw-r--r--apps/plugins/lib/gray_deferred_update.c50
-rw-r--r--apps/plugins/lib/gray_drawbitmap.c116
-rw-r--r--apps/plugins/lib/gray_drawgraymap.c275
-rw-r--r--apps/plugins/lib/gray_drawline.c119
-rw-r--r--apps/plugins/lib/gray_drawpixel.c55
-rw-r--r--apps/plugins/lib/gray_drawrect.c62
-rw-r--r--apps/plugins/lib/gray_fillrect.c92
-rw-r--r--apps/plugins/lib/gray_getstringsize.c64
-rw-r--r--apps/plugins/lib/gray_horline.c65
-rw-r--r--apps/plugins/lib/gray_pixelfuncs.c245
-rw-r--r--apps/plugins/lib/gray_position_display.c57
-rw-r--r--apps/plugins/lib/gray_putsxy.c67
-rw-r--r--apps/plugins/lib/gray_screendump.c141
-rw-r--r--apps/plugins/lib/gray_scroll_down.c134
-rw-r--r--apps/plugins/lib/gray_scroll_down8.c69
-rw-r--r--apps/plugins/lib/gray_scroll_left.c100
-rw-r--r--apps/plugins/lib/gray_scroll_right.c100
-rw-r--r--apps/plugins/lib/gray_scroll_up.c135
-rw-r--r--apps/plugins/lib/gray_scroll_up8.c69
-rw-r--r--apps/plugins/lib/gray_set_background.c48
-rw-r--r--apps/plugins/lib/gray_set_drawinfo.c49
-rw-r--r--apps/plugins/lib/gray_set_drawmode.c52
-rw-r--r--apps/plugins/lib/gray_set_foreground.c48
-rw-r--r--apps/plugins/lib/gray_setfont.c47
-rw-r--r--apps/plugins/lib/gray_verline.c88
-rw-r--r--apps/plugins/lib/xxx2wav.c259
-rw-r--r--apps/plugins/lib/xxx2wav.h67
-rw-r--r--apps/plugins/mpa2wav.c269
-rw-r--r--apps/plugins/mpc2wav.c208
-rw-r--r--apps/plugins/rockboy/cpu.h59
-rw-r--r--apps/plugins/rockboy/lcd.h78
-rw-r--r--apps/plugins/rockboy/rtc.h25
-rw-r--r--apps/plugins/vorbis2wav.c180
-rw-r--r--apps/plugins/wv2wav.c217
47 files changed, 5429 insertions, 0 deletions
diff --git a/apps/codecs/libmusepack/config.h b/apps/codecs/libmusepack/config.h
new file mode 100644
index 0000000000..8d764c4031
--- /dev/null
+++ b/apps/codecs/libmusepack/config.h
@@ -0,0 +1,105 @@
+/* include/config.h. Generated by configure. */
+/* include/config.h.in. Generated from configure.in by autoheader. */
+
+/* Define to 1 if you have the <dlfcn.h> header file. */
+#define HAVE_DLFCN_H 1
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#define HAVE_INTTYPES_H 1
+
+/* Define to 1 if you have the `memmove' function. */
+#define HAVE_MEMMOVE 1
+
+/* Define to 1 if you have the <memory.h> header file. */
+#define HAVE_MEMORY_H 1
+
+/* Define to 1 if you have the `memset' function. */
+#define HAVE_MEMSET 1
+
+/* Define to 1 if the system has the type `ptrdiff_t'. */
+#define HAVE_PTRDIFF_T 1
+
+/* Define to 1 if you have the `sqrt' function. */
+/* #undef HAVE_SQRT */
+
+/* Define to 1 if stdbool.h conforms to C99. */
+#define HAVE_STDBOOL_H 1
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#define HAVE_STDINT_H 1
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#define HAVE_STDLIB_H 1
+
+/* Define to 1 if you have the <strings.h> header file. */
+#define HAVE_STRINGS_H 1
+
+/* Define to 1 if you have the <string.h> header file. */
+#define HAVE_STRING_H 1
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#define HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#define HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#define HAVE_UNISTD_H 1
+
+/* Define to 1 if the system has the type `_Bool'. */
+#define HAVE__BOOL 1
+
+/* Name of package */
+#define PACKAGE "libmusepack"
+
+/* Define to the address where bug reports for this package should be sent. */
+#define PACKAGE_BUGREPORT ""
+
+/* Define to the full name of this package. */
+#define PACKAGE_NAME ""
+
+/* Define to the full name and version of this package. */
+#define PACKAGE_STRING ""
+
+/* Define to the one symbol short name of this package. */
+#define PACKAGE_TARNAME ""
+
+/* Define to the version of this package. */
+#define PACKAGE_VERSION ""
+
+/* The size of a `int', as computed by sizeof. */
+#define SIZEOF_INT 4
+
+/* The size of a `long', as computed by sizeof. */
+#define SIZEOF_LONG 4
+
+/* The size of a `long long', as computed by sizeof. */
+#define SIZEOF_LONG_LONG 8
+
+/* The size of a `short', as computed by sizeof. */
+#define SIZEOF_SHORT 2
+
+/* Define to 1 if you have the ANSI C header files. */
+#define STDC_HEADERS 1
+
+/* Version number of package */
+#define VERSION "1.1"
+
+/* Define to 1 if your processor stores words with the most significant byte
+ first (like Motorola and SPARC, unlike Intel and VAX). */
+/* #undef WORDS_BIGENDIAN */
+
+/* Define to empty if `const' does not conform to ANSI C. */
+/* #undef const */
+
+/* Define to `__inline__' or `__inline' if that's what the C compiler
+ calls it, or to nothing if 'inline' is not supported under any name. */
+#ifndef __cplusplus
+/* #undef inline */
+#endif
+
+/* Define to `long' if <sys/types.h> does not define. */
+/* #undef off_t */
+
+/* Define to `unsigned' if <sys/types.h> does not define. */
+/* #undef size_t */
diff --git a/apps/credits.c b/apps/credits.c
new file mode 100644
index 0000000000..72a33cf3c5
--- /dev/null
+++ b/apps/credits.c
@@ -0,0 +1,131 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2002 by Robert Hak <rhak at ramapo.edu>
+ *
+ * All files in this archive are subject to the GNU General Public License.
+ * See the file COPYING in the source tree root for full license agreement.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#include "credits.h"
+#include "lcd.h"
+#include "font.h"
+#include "kernel.h"
+#include "button.h"
+#include "sprintf.h"
+#include "string.h"
+
+const char* const credits[] = {
+#include "credits.raw" /* generated list of names from docs/CREDITS */
+};
+
+#ifdef HAVE_LCD_CHARCELLS
+#define MAX(x, y) ((x) > (y) ? (x) : (y))
+void roll_credits(void)
+{
+ int numnames = sizeof(credits)/sizeof(char*);
+ int curr_name = 0;
+ int curr_len = strlen(credits[0]);
+ int curr_index = 0;
+ int curr_line = 0;
+ int name, len, new_len, line, x;
+
+ while (1)
+ {
+ lcd_clear_display();
+
+ name = curr_name;
+ x = -curr_index;
+ len = curr_len;
+ line = curr_line;
+
+ while (x < 11)
+ {
+ int x2;
+
+ if (x < 0)
+ lcd_puts(0, line, credits[name] - x);
+ else
+ lcd_puts(x, line, credits[name]);
+
+ if (++name >= numnames)
+ break;
+ line ^= 1;
+
+ x2 = x + len/2;
+ if ((unsigned)x2 < 11)
+ lcd_putc(x2, line, '*');
+
+ new_len = strlen(credits[name]);
+ x += MAX(len/2 + 2, len - new_len/2 + 1);
+ len = new_len;
+ }
+ /* abort on keypress */
+ if (button_get_w_tmo(HZ/8) & BUTTON_REL)
+ return;
+
+ if (++curr_index >= curr_len)
+ {
+ if (++curr_name >= numnames)
+ break;
+ new_len = strlen(credits[curr_name]);
+ curr_index -= MAX(curr_len/2 + 2, curr_len - new_len/2 + 1);
+ curr_len = new_len;
+ curr_line ^= 1;
+ }
+ }
+}
+#else
+
+void roll_credits(void)
+{
+ int i;
+ int line = 0;
+ int numnames = sizeof(credits)/sizeof(char*);
+ char buffer[40];
+
+ int y=LCD_HEIGHT;
+
+ int height;
+ int width;
+
+ lcd_setfont(FONT_UI);
+
+ lcd_getstringsize("A", &width, &height);
+
+ while(1) {
+ lcd_clear_display();
+ for ( i=0; i <= (LCD_HEIGHT-y)/height; i++ )
+ lcd_putsxy(0, i*height+y, line+i<numnames?credits[line+i]:"");
+ snprintf(buffer, sizeof(buffer), " [Credits] %2d/%2d ",
+ line+1, numnames);
+ lcd_clearrect(0, 0, LCD_WIDTH, height);
+ lcd_putsxy(0, 0, buffer);
+ lcd_update();
+
+ if (button_get_w_tmo(HZ/20) & BUTTON_REL)
+ return;
+
+ y--;
+
+ if(y<0) {
+ line++;
+ if(line >= numnames)
+ break;
+ y+=height;
+ }
+
+ }
+ return;
+}
+#endif
diff --git a/apps/credits.h b/apps/credits.h
new file mode 100644
index 0000000000..dd4b459326
--- /dev/null
+++ b/apps/credits.h
@@ -0,0 +1,28 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2002 by Robert Hak <rhak at ramapo.edu>
+ *
+ * All files in this archive are subject to the GNU General Public License.
+ * See the file COPYING in the source tree root for full license agreement.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#ifndef __ROCKBOX_CREDITS_H__
+#define __ROCKBOX_CREDITS_H__
+
+/* Show who worked on the project */
+void roll_credits(void);
+
+#endif
+
+
diff --git a/apps/credits.pl b/apps/credits.pl
new file mode 100644
index 0000000000..942a96b99f
--- /dev/null
+++ b/apps/credits.pl
@@ -0,0 +1,13 @@
+# __________ __ ___.
+# Open \______ \ ____ ____ | | _\_ |__ _______ ___
+# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+# \/ \/ \/ \/ \/
+# $Id$
+#
+while (<STDIN>) {
+ if(($_ =~ /^([A-Z]+[\S ]+)/) && ($_ !~ /^People/)) {
+ print "\"$1\",\n";
+ }
+}
diff --git a/apps/plugins/a52towav.c b/apps/plugins/a52towav.c
new file mode 100644
index 0000000000..32353d823f
--- /dev/null
+++ b/apps/plugins/a52towav.c
@@ -0,0 +1,208 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2005 Dave Chapman
+ *
+ * All files in this archive are subject to the GNU General Public License.
+ * See the file COPYING in the source tree root for full license agreement.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#include "plugin.h"
+
+#if (CONFIG_HWCODEC == MASNONE)
+/* software codec platforms */
+
+#include <inttypes.h> /* Needed by a52.h */
+
+#include <codecs/liba52/config-a52.h>
+#include <codecs/liba52/a52.h>
+
+#include "lib/xxx2wav.h" /* Helper functions common to test decoders */
+
+static struct plugin_api* rb;
+
+#ifdef WORDS_BIGENDIAN
+#define LE_S16(x) ( (uint16_t) ( ((uint16_t)(x) >> 8) | ((uint16_t)(x) << 8) ) )
+#else
+#define LE_S16(x) (x)
+#endif
+
+
+static float gain = 1;
+static a52_state_t * state;
+
+static inline int16_t convert (int32_t i)
+{
+ i >>= 15;
+ return (i > 32767) ? 32767 : ((i < -32768) ? -32768 : i);
+}
+
+void ao_play(file_info_struct* file_info,sample_t* samples,int flags) {
+ int i;
+ static int16_t int16_samples[256*2];
+
+ flags &= A52_CHANNEL_MASK | A52_LFE;
+
+ if (flags==A52_STEREO) {
+ for (i = 0; i < 256; i++) {
+ int16_samples[2*i] = LE_S16(convert (samples[i]));
+ int16_samples[2*i+1] = LE_S16(convert (samples[i+256]));
+ }
+ } else {
+ DEBUGF("ERROR: unsupported format: %d\n",flags);
+ }
+
+ /* FIX: Buffer the disk write to write larger amounts at one */
+ i=rb->write(file_info->outfile,int16_samples,256*2*2);
+}
+
+
+void a52_decode_data (file_info_struct* file_info, uint8_t * start, uint8_t * end)
+{
+ static uint8_t buf[3840];
+ static uint8_t * bufptr = buf;
+ static uint8_t * bufpos = buf + 7;
+
+ /*
+ * sample_rate and flags are static because this routine could
+ * exit between the a52_syncinfo() and the ao_setup(), and we want
+ * to have the same values when we get back !
+ */
+
+ static int sample_rate;
+ static int flags;
+ int bit_rate;
+ int len;
+
+ while (1) {
+ len = end - start;
+ if (!len)
+ break;
+ if (len > bufpos - bufptr)
+ len = bufpos - bufptr;
+ memcpy (bufptr, start, len);
+ bufptr += len;
+ start += len;
+ if (bufptr == bufpos) {
+ if (bufpos == buf + 7) {
+ int length;
+
+ length = a52_syncinfo (buf, &flags, &sample_rate, &bit_rate);
+ if (!length) {
+ DEBUGF("skip\n");
+ for (bufptr = buf; bufptr < buf + 6; bufptr++)
+ bufptr[0] = bufptr[1];
+ continue;
+ }
+ bufpos = buf + length;
+ } else {
+ // The following two defaults are taken from audio_out_oss.c:
+ level_t level;
+ sample_t bias;
+ int i;
+
+ /* This is the configuration for the downmixing: */
+ flags=A52_STEREO|A52_ADJUST_LEVEL|A52_LFE;
+ level=(1 << 26);
+ bias=0;
+
+ level = (level_t) (level * gain);
+
+ if (a52_frame (state, buf, &flags, &level, bias))
+ goto error;
+ file_info->frames_decoded++;
+
+ /* We assume this never changes */
+ file_info->samplerate=sample_rate;
+
+ // An A52 frame consists of 6 blocks of 256 samples
+ // So we decode and output them one block at a time
+ for (i = 0; i < 6; i++) {
+ if (a52_block (state)) {
+ goto error;
+ }
+ ao_play (file_info, a52_samples (state),flags);
+ file_info->current_sample+=256;
+ }
+ bufptr = buf;
+ bufpos = buf + 7;
+ continue;
+ error:
+ DEBUGF("error\n");
+ bufptr = buf;
+ bufpos = buf + 7;
+ }
+ }
+ }
+}
+
+
+#define BUFFER_SIZE 4096
+
+/* this is the plugin entry point */
+enum plugin_status plugin_start(struct plugin_api* api, void* file)
+{
+ file_info_struct file_info;
+
+ /* Generic plugin initialisation */
+
+ TEST_PLUGIN_API(api);
+ rb = api;
+
+
+ /* This function sets up the buffers and reads the file into RAM */
+
+ if (local_init(file,"/ac3test.wav",&file_info,api)) {
+ return PLUGIN_ERROR;
+ }
+
+ /* Intialise the A52 decoder and check for success */
+ state = a52_init (0); // Parameter is "accel"
+
+ if (state == NULL) {
+ rb->splash(HZ*2, true, "a52_init failed");
+ return PLUGIN_ERROR;
+ }
+
+ /* The main decoding loop */
+
+ file_info.start_tick=*(rb->current_tick);
+ rb->button_clear_queue();
+
+ while (file_info.curpos < file_info.filesize) {
+
+ if ((file_info.curpos+BUFFER_SIZE) < file_info.filesize) {
+ a52_decode_data(&file_info,&filebuf[file_info.curpos],&filebuf[file_info.curpos+BUFFER_SIZE]);
+ file_info.curpos+=BUFFER_SIZE;
+ } else {
+ a52_decode_data(&file_info,&filebuf[file_info.curpos],&filebuf[file_info.filesize-1]);
+ file_info.curpos=file_info.filesize;
+ }
+
+ display_status(&file_info);
+
+ if (rb->button_get(false)!=BUTTON_NONE) {
+ close_wav(&file_info);
+ return PLUGIN_OK;
+ }
+ }
+ close_wav(&file_info);
+
+ /* Cleanly close and exit */
+
+//NOT NEEDED: a52_free (state);
+
+ rb->splash(HZ*2, true, "FINISHED!");
+ return PLUGIN_OK;
+}
+#endif /* CONFIG_HWCODEC == MASNONE */
diff --git a/apps/plugins/codecmpa.c b/apps/plugins/codecmpa.c
new file mode 100644
index 0000000000..1125b4bf18
--- /dev/null
+++ b/apps/plugins/codecmpa.c
@@ -0,0 +1,404 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2005 Dave Chapman
+ *
+ * All files in this archive are subject to the GNU General Public License.
+ * See the file COPYING in the source tree root for full license agreement.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#include "plugin.h"
+
+#include <codecs/libmad/mad.h>
+
+#include "playback.h"
+#include "mp3data.h"
+#include "lib/codeclib.h"
+
+static struct plugin_api* rb;
+
+struct mad_stream Stream IDATA_ATTR;
+struct mad_frame Frame IDATA_ATTR;
+struct mad_synth Synth IDATA_ATTR;
+mad_timer_t Timer;
+struct dither d0, d1;
+
+/* The following function is used inside libmad - let's hope it's never
+ called.
+*/
+
+void abort(void) {
+}
+
+/* The "dither" code to convert the 24-bit samples produced by libmad was
+ taken from the coolplayer project - coolplayer.sourceforge.net */
+
+struct dither {
+ mad_fixed_t error[3];
+ mad_fixed_t random;
+};
+
+# define SAMPLE_DEPTH 16
+# define scale(x, y) dither((x), (y))
+
+/*
+ * NAME: prng()
+ * DESCRIPTION: 32-bit pseudo-random number generator
+ */
+static __inline
+unsigned long prng(unsigned long state)
+{
+ return (state * 0x0019660dL + 0x3c6ef35fL) & 0xffffffffL;
+}
+
+/*
+ * NAME: dither()
+ * DESCRIPTION: dither and scale sample
+ */
+static __inline
+signed int dither(mad_fixed_t sample, struct dither *dither)
+{
+ unsigned int scalebits;
+ mad_fixed_t output, mask, random;
+
+ enum {
+ MIN = -MAD_F_ONE,
+ MAX = MAD_F_ONE - 1
+ };
+
+ /* noise shape */
+ sample += dither->error[0] - dither->error[1] + dither->error[2];
+
+ dither->error[2] = dither->error[1];
+ dither->error[1] = dither->error[0] / 2;
+
+ /* bias */
+ output = sample + (1L << (MAD_F_FRACBITS + 1 - SAMPLE_DEPTH - 1));
+
+ scalebits = MAD_F_FRACBITS + 1 - SAMPLE_DEPTH;
+ mask = (1L << scalebits) - 1;
+
+ /* dither */
+ random = prng(dither->random);
+ output += (random & mask) - (dither->random & mask);
+
+ //dither->random = random;
+
+ /* clip */
+ if (output > MAX) {
+ output = MAX;
+
+ if (sample > MAX)
+ sample = MAX;
+ }
+ else if (output < MIN) {
+ output = MIN;
+
+ if (sample < MIN)
+ sample = MIN;
+ }
+
+ /* quantize */
+ output &= ~mask;
+
+ /* error feedback */
+ dither->error[0] = sample - output;
+
+ /* scale */
+ return output >> scalebits;
+}
+
+static __inline
+signed int detect_silence(mad_fixed_t sample)
+{
+ unsigned int scalebits;
+ mad_fixed_t output, mask;
+
+ enum {
+ MIN = -MAD_F_ONE,
+ MAX = MAD_F_ONE - 1
+ };
+
+ /* bias */
+ output = sample + (1L << (MAD_F_FRACBITS + 1 - SAMPLE_DEPTH - 1));
+
+ scalebits = MAD_F_FRACBITS + 1 - SAMPLE_DEPTH;
+ mask = (1L << scalebits) - 1;
+
+ /* clip */
+ if (output > MAX) {
+ output = MAX;
+
+ if (sample > MAX)
+ sample = MAX;
+ }
+ else if (output < MIN) {
+ output = MIN;
+
+ if (sample < MIN)
+ sample = MIN;
+ }
+
+ /* quantize */
+ output &= ~mask;
+
+ /* scale */
+ output >>= scalebits + 4;
+
+ if (output == 0x00 || output == 0xff)
+ return 1;
+
+ return 0;
+}
+#define SHRT_MAX 32767
+
+#define INPUT_CHUNK_SIZE 8192
+#define OUTPUT_BUFFER_SIZE 65536 /* Must be an integer multiple of 4. */
+
+unsigned char OutputBuffer[OUTPUT_BUFFER_SIZE];
+unsigned char *OutputPtr;
+unsigned char *GuardPtr=NULL;
+const unsigned char *OutputBufferEnd=OutputBuffer+OUTPUT_BUFFER_SIZE;
+
+mad_fixed_t mad_frame_overlap[2][32][18] IDATA_ATTR;
+unsigned char mad_main_data[MAD_BUFFER_MDLEN] IDATA_ATTR;
+
+#ifdef USE_IRAM
+extern char iramcopy[];
+extern char iramstart[];
+extern char iramend[];
+#endif
+
+#undef DEBUG_GAPLESS
+
+/* this is the plugin entry point */
+enum plugin_status plugin_start(struct plugin_api* api, void* parm)
+{
+ struct codec_api *ci = (struct codec_api *)parm;
+ int Status=0;
+ size_t size;
+ int file_end;
+ unsigned short Sample;
+ char *InputBuffer;
+ unsigned int samplecount;
+ unsigned int samplesdone;
+ bool first_frame;
+#ifdef DEBUG_GAPLESS
+ bool first = true;
+ int fd;
+#endif
+ int i;
+
+ /* Generic plugin inititialisation */
+
+ TEST_PLUGIN_API(api);
+ rb = api;
+
+#ifdef USE_IRAM
+ rb->memcpy(iramstart, iramcopy, iramend-iramstart);
+#endif
+
+ /* This function sets up the buffers and reads the file into RAM */
+
+ if (codec_init(api, ci)) {
+ return PLUGIN_ERROR;
+ }
+
+ /* Create a decoder instance */
+
+ next_track:
+
+ memset(&Stream, 0, sizeof(struct mad_stream));
+ memset(&Frame, 0, sizeof(struct mad_frame));
+ memset(&Synth, 0, sizeof(struct mad_synth));
+ memset(&Timer, 0, sizeof(mad_timer_t));
+
+ mad_stream_init(&Stream);
+ mad_frame_init(&Frame);
+ mad_synth_init(&Synth);
+ mad_timer_reset(&Timer);
+
+ /* We do this so libmad doesn't try to call codec_calloc() */
+ memset(mad_frame_overlap, 0, sizeof(mad_frame_overlap));
+ Frame.overlap = &mad_frame_overlap;
+ Stream.main_data = &mad_main_data;
+
+#ifdef DEBUG_GAPLESS
+ if (first)
+ fd = rb->open("/first.pcm", O_WRONLY | O_CREAT);
+ else
+ fd = rb->open("/second.pcm", O_WRONLY | O_CREAT);
+ first = false;
+#endif
+
+ samplesdone = 0;
+ first_frame = false;
+ file_end = 0;
+ OutputPtr = OutputBuffer;
+
+ while (!*ci->taginfo_ready)
+ rb->yield();
+
+
+ ci->request_buffer(&size, ci->id3->first_frame_offset);
+ ci->advance_buffer(size);
+
+ samplecount = ci->id3->length * (ci->id3->frequency / 100) / 10;
+ /* rb->snprintf(buf2, sizeof(buf2), "sc: %d", samplecount);
+ rb->splash(0, true, buf2);
+ rb->snprintf(buf2, sizeof(buf2), "length: %d", ci->id3->length);
+ rb->splash(HZ*5, true, buf2);
+ rb->snprintf(buf2, sizeof(buf2), "frequency: %d", ci->id3->frequency);
+ rb->splash(HZ*5, true, buf2); */
+
+ /* This is the decoding loop. */
+ while (1) {
+ rb->yield();
+ if (ci->stop_codec || ci->reload_codec) {
+ break ;
+ }
+
+ if (ci->seek_time) {
+ unsigned int sample_loc;
+ int newpos;
+
+ sample_loc = ci->seek_time/1000 * ci->id3->frequency;
+ newpos = ci->mp3_get_filepos(ci->seek_time-1);
+ if (ci->seek_buffer(newpos)) {
+ ci->seek_time = 0;
+ if (sample_loc >= samplecount + samplesdone)
+ break ;
+ samplecount += samplesdone - sample_loc;
+ samplesdone = sample_loc;
+ }
+ }
+
+ /* Lock buffers */
+ if (Stream.error == 0) {
+ InputBuffer = ci->request_buffer(&size, INPUT_CHUNK_SIZE);
+ if (size == 0 || InputBuffer == NULL)
+ break ;
+ mad_stream_buffer(&Stream, InputBuffer, size);
+ }
+
+ //if ((int)ci->curpos >= ci->id3->first_frame_offset)
+ //first_frame = true;
+
+ if(mad_frame_decode(&Frame,&Stream))
+ {
+ if (Stream.error == MAD_FLAG_INCOMPLETE || Stream.error == MAD_ERROR_BUFLEN) {
+ // rb->splash(HZ*1, true, "Incomplete");
+ /* This makes the codec to support partially corrupted files too. */
+ if (file_end == 30)
+ break ;
+
+ /* Fill the buffer */
+ Stream.error = 0;
+ file_end++;
+ continue ;
+ }
+ else if(MAD_RECOVERABLE(Stream.error))
+ {
+ if(Stream.error!=MAD_ERROR_LOSTSYNC || Stream.this_frame!=GuardPtr)
+ {
+ // rb->splash(HZ*1, true, "Recoverable...!");
+ }
+ continue;
+ }
+ else if(Stream.error==MAD_ERROR_BUFLEN) {
+ //rb->splash(HZ*1, true, "Buflen error");
+ break ;
+ } else {
+ //rb->splash(HZ*1, true, "Unrecoverable error");
+ Status=1;
+ break;
+ }
+ }
+ if (Stream.next_frame)
+ ci->advance_buffer_loc((void *)Stream.next_frame);
+ file_end = false;
+ /* ?? Do we need the timer module? */
+ // mad_timer_add(&Timer,Frame.header.duration);
+
+/* DAVE: This can be used to attenuate the audio */
+// if(DoFilter)
+// ApplyFilter(&Frame);
+
+ mad_synth_frame(&Synth,&Frame);
+
+ //if (!first_frame) {
+ //samplecount -= Synth.pcm.length;
+ //continue ;
+ //}
+
+ /* Convert MAD's numbers to an array of 16-bit LE signed integers */
+ for(i=0;i<Synth.pcm.length;i++)
+ {
+ samplesdone++;
+ //if (ci->mp3data->padding > 0) {
+ // ci->mp3data->padding--;
+ // continue ;
+ //}
+ if (!first_frame) {
+ if (detect_silence(Synth.pcm.samples[0][i]))
+ continue ;
+ first_frame = true;
+ }
+
+ /* Left channel */
+ Sample=scale(Synth.pcm.samples[0][i],&d0);
+ *(OutputPtr++)=Sample>>8;
+ *(OutputPtr++)=Sample&0xff;
+
+ /* Right channel. If the decoded stream is monophonic then
+ * the right output channel is the same as the left one.
+ */
+ if(MAD_NCHANNELS(&Frame.header)==2)
+ Sample=scale(Synth.pcm.samples[1][i],&d1);
+ *(OutputPtr++)=Sample>>8;
+ *(OutputPtr++)=Sample&0xff;
+
+ samplecount--;
+ if (samplecount == 0) {
+#ifdef DEBUG_GAPLESS
+ rb->write(fd, OutputBuffer, (int)OutputPtr-(int)OutputBuffer);
+#endif
+ while (!ci->audiobuffer_insert(OutputBuffer, (int)OutputPtr-(int)OutputBuffer))
+ rb->yield();
+ goto song_end;
+ }
+
+ /* Flush the buffer if it is full. */
+ if(OutputPtr==OutputBufferEnd)
+ {
+#ifdef DEBUG_GAPLESS
+ rb->write(fd, OutputBuffer, OUTPUT_BUFFER_SIZE);
+#endif
+ while (!ci->audiobuffer_insert(OutputBuffer, OUTPUT_BUFFER_SIZE))
+ rb->yield();
+ OutputPtr=OutputBuffer;
+ }
+ }
+ ci->set_elapsed(samplesdone / (ci->id3->frequency/1000));
+ }
+
+ song_end:
+#ifdef DEBUG_GAPLESS
+ rb->close(fd);
+#endif
+ Stream.error = 0;
+
+ if (ci->request_next_track())
+ goto next_track;
+ return PLUGIN_OK;
+}
diff --git a/apps/plugins/codecvorbis.c b/apps/plugins/codecvorbis.c
new file mode 100644
index 0000000000..2fcc031ce5
--- /dev/null
+++ b/apps/plugins/codecvorbis.c
@@ -0,0 +1,161 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2002 Bjrn Stenberg
+ *
+ * All files in this archive are subject to the GNU General Public License.
+ * See the file COPYING in the source tree root for full license agreement.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+#include "kernel.h"
+#include "plugin.h"
+
+#include <codecs/Tremor/ivorbisfile.h>
+
+#include "playback.h"
+#include "lib/codeclib.h"
+
+static struct plugin_api* rb;
+
+/* Some standard functions and variables needed by Tremor */
+
+
+int errno;
+
+size_t strlen(const char *s) {
+ return(rb->strlen(s));
+}
+
+char *strcpy(char *dest, const char *src) {
+ return(rb->strcpy(dest,src));
+}
+
+char *strcat(char *dest, const char *src) {
+ return(rb->strcat(dest,src));
+}
+
+size_t read_handler(void *ptr, size_t size, size_t nmemb, void *datasource) {
+ struct codec_api *p = (struct codec_api *) datasource;
+
+ return p->read_filebuf(ptr, nmemb*size);
+}
+
+int seek_handler(void *datasource, ogg_int64_t offset, int whence) {
+ /* We are not seekable at the moment */
+ (void)datasource;
+ (void)offset;
+ (void)whence;
+ return -1;
+}
+
+int close_handler(void *datasource) {
+ (void)datasource;
+ return 0;
+}
+
+long tell_handler(void *datasource) {
+ struct codec_api *p = (struct codec_api *) datasource;
+ return p->curpos;
+}
+
+#ifdef USE_IRAM
+extern char iramcopy[];
+extern char iramstart[];
+extern char iramend[];
+#endif
+
+
+/* reserve the PCM buffer in the IRAM area */
+static char pcmbuf[4096] IDATA_ATTR;
+
+/* this is the plugin entry point */
+enum plugin_status plugin_start(struct plugin_api* api, void* parm)
+{
+ struct codec_api *ci = (struct codec_api *)parm;
+ ov_callbacks callbacks;
+ OggVorbis_File vf;
+ vorbis_info* vi;
+
+ int error;
+ long n;
+ int current_section;
+ int eof;
+#if BYTE_ORDER == BIG_ENDIAN
+ int i;
+ char x;
+#endif
+
+ TEST_PLUGIN_API(api);
+
+ /* if you are using a global api pointer, don't forget to copy it!
+ otherwise you will get lovely "I04: IllInstr" errors... :-) */
+ rb = api;
+
+ #ifdef USE_IRAM
+ rb->memcpy(iramstart, iramcopy, iramend-iramstart);
+ #endif
+
+ /* This function sets up the buffers and reads the file into RAM */
+
+ /* We need to flush reserver memory every track load. */
+ next_track:
+ if (codec_init(api, ci)) {
+ return PLUGIN_ERROR;
+ }
+
+
+ /* Create a decoder instance */
+
+ callbacks.read_func=read_handler;
+ callbacks.seek_func=seek_handler;
+ callbacks.tell_func=tell_handler;
+ callbacks.close_func=close_handler;
+
+ error=ov_open_callbacks(ci,&vf,NULL,0,callbacks);
+
+ vi=ov_info(&vf,-1);
+
+ if (vi==NULL) {
+ // rb->splash(HZ*2, true, "Vorbis Error");
+ return PLUGIN_ERROR;
+ }
+
+ eof=0;
+ while (!eof) {
+ /* Read host-endian signed 16 bit PCM samples */
+ n=ov_read(&vf,pcmbuf,sizeof(pcmbuf),&current_section);
+
+ if (n==0) {
+ eof=1;
+ } else if (n < 0) {
+ DEBUGF("Error decoding frame\n");
+ } else {
+ rb->yield();
+ if (ci->stop_codec || ci->reload_codec)
+ break ;
+ while (!ci->audiobuffer_insert(pcmbuf, n))
+ rb->yield();
+
+#if BYTE_ORDER == BIG_ENDIAN
+ for (i=0;i<n;i+=2) {
+ x=pcmbuf[i]; pcmbuf[i]=pcmbuf[i+1]; pcmbuf[i+1]=x;
+ }
+#endif
+ }
+ }
+
+ if (ci->request_next_track())
+ goto next_track;
+
+ return PLUGIN_OK;
+}
+
diff --git a/apps/plugins/flac2wav.c b/apps/plugins/flac2wav.c
new file mode 100644
index 0000000000..84b5ed15b2
--- /dev/null
+++ b/apps/plugins/flac2wav.c
@@ -0,0 +1,237 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2002 Bjrn Stenberg
+ *
+ * All files in this archive are subject to the GNU General Public License.
+ * See the file COPYING in the source tree root for full license agreement.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#include "plugin.h"
+
+#if (CONFIG_HWCODEC == MASNONE)
+/* software codec platforms */
+
+#include <codecs/libFLAC/include/FLAC/seekable_stream_decoder.h>
+
+#include "lib/xxx2wav.h" /* Helper functions common to test decoders */
+
+#define FLAC_MAX_SUPPORTED_BLOCKSIZE 4608
+#define FLAC_MAX_SUPPORTED_CHANNELS 2
+
+static struct plugin_api* rb;
+
+/* Called when the FLAC decoder needs some FLAC data to decode */
+FLAC__SeekableStreamDecoderReadStatus flac_read_handler(const FLAC__SeekableStreamDecoder *dec,
+ FLAC__byte buffer[], unsigned *bytes, void *data)
+{ (void)dec;
+
+ file_info_struct *p = (file_info_struct *) data;
+
+ if (p->curpos >= p->filesize) {
+ return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
+ }
+
+ rb->memcpy(buffer,&filebuf[p->curpos],*bytes);
+ p->curpos+=*bytes;
+
+ return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
+}
+
+/* Called when the FLAC decoder has some decoded PCM data to write */
+FLAC__StreamDecoderWriteStatus flac_write_handler(const FLAC__SeekableStreamDecoder *dec,
+ const FLAC__Frame *frame,
+ const FLAC__int32 * const buf[],
+ void *data)
+{
+ unsigned int c_samp, c_chan, d_samp;
+ file_info_struct *p = (file_info_struct *) data;
+ uint32_t data_size = frame->header.blocksize * frame->header.channels * (p->bitspersample / 8);
+ uint32_t samples = frame->header.blocksize;
+
+ // FIXME: This should not be on the stack!
+ static unsigned char ldb[FLAC_MAX_SUPPORTED_BLOCKSIZE*FLAC_MAX_SUPPORTED_CHANNELS*2];
+
+ if (samples*frame->header.channels > (FLAC_MAX_SUPPORTED_BLOCKSIZE*FLAC_MAX_SUPPORTED_CHANNELS)) {
+ // ERROR!!!
+ DEBUGF("ERROR: samples*frame->header.channels=%d\n",samples*frame->header.channels);
+ return(FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE);
+ }
+
+ (void)dec;
+ (void)data_size;
+ for(c_samp = d_samp = 0; c_samp < samples; c_samp++) {
+ for(c_chan = 0; c_chan < frame->header.channels; c_chan++, d_samp++) {
+ ldb[d_samp*2] = buf[c_chan][c_samp]&0xff;
+ ldb[(d_samp*2)+1] = (buf[c_chan][c_samp]&0xff00)>>8;
+ }
+ }
+
+ rb->write(p->outfile,ldb,data_size);
+
+ p->current_sample += samples;
+
+ return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
+}
+
+void flac_metadata_handler(const FLAC__SeekableStreamDecoder *dec,
+ const FLAC__StreamMetadata *meta, void *data)
+{
+ file_info_struct *p = (file_info_struct *) data;
+ (void)dec;
+
+ if(meta->type == FLAC__METADATA_TYPE_STREAMINFO) {
+ p->bitspersample = meta->data.stream_info.bits_per_sample;
+ p->samplerate = meta->data.stream_info.sample_rate;
+ p->channels = meta->data.stream_info.channels;
+// FLAC__ASSERT(meta->data.stream_info.total_samples < 0x100000000); /* we can handle < 4 gigasamples */
+ p->total_samples = (unsigned)
+ (meta->data.stream_info.total_samples & 0xffffffff);
+ p->current_sample = 0;
+ }
+}
+
+
+void flac_error_handler(const FLAC__SeekableStreamDecoder *dec,
+ FLAC__StreamDecoderErrorStatus status, void *data)
+{
+ (void)dec;
+ (void)status;
+ (void)data;
+}
+
+FLAC__SeekableStreamDecoderSeekStatus flac_seek_handler (const FLAC__SeekableStreamDecoder *decoder,
+ FLAC__uint64 absolute_byte_offset,
+ void *client_data)
+{
+ (void)decoder;
+ file_info_struct *p = (file_info_struct *) client_data;
+ rb->lseek(p->infile,SEEK_SET,absolute_byte_offset);
+ return(FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK);
+}
+
+FLAC__SeekableStreamDecoderTellStatus flac_tell_handler (const FLAC__SeekableStreamDecoder *decoder,
+ FLAC__uint64 *absolute_byte_offset, void *client_data)
+{
+ file_info_struct *p = (file_info_struct *) client_data;
+
+ (void)decoder;
+ *absolute_byte_offset=rb->lseek(p->infile,SEEK_CUR,0);
+ return(FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_OK);
+}
+
+FLAC__SeekableStreamDecoderLengthStatus flac_length_handler (const FLAC__SeekableStreamDecoder *decoder,
+ FLAC__uint64 *stream_length, void *client_data)
+{
+ file_info_struct *p = (file_info_struct *) client_data;
+
+ (void)decoder;
+ *stream_length=p->filesize;
+ return(FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_OK);
+}
+
+FLAC__bool flac_eof_handler (const FLAC__SeekableStreamDecoder *decoder,
+ void *client_data)
+{
+ file_info_struct *p = (file_info_struct *) client_data;
+
+ (void)decoder;
+ if (p->curpos >= p->filesize) {
+ return(true);
+ } else {
+ return(false);
+ }
+}
+
+#ifndef SIMULATOR
+extern char iramcopy[];
+extern char iramstart[];
+extern char iramend[];
+#endif
+
+/* this is the plugin entry point */
+enum plugin_status plugin_start(struct plugin_api* api, void* file)
+{
+ FLAC__SeekableStreamDecoder* flacDecoder;
+ file_info_struct file_info;
+
+ TEST_PLUGIN_API(api);
+
+ /* if you are using a global api pointer, don't forget to copy it!
+ otherwise you will get lovely "I04: IllInstr" errors... :-) */
+ rb = api;
+
+#ifndef SIMULATOR
+ rb->memcpy(iramstart, iramcopy, iramend-iramstart);
+#endif
+
+ /* This function sets up the buffers and reads the file into RAM */
+
+ if (local_init(file,"/flactest.wav",&file_info,api)) {
+ return PLUGIN_ERROR;
+ }
+
+ /* Create a decoder instance */
+
+ flacDecoder=FLAC__seekable_stream_decoder_new();
+
+ /* Set up the decoder and the callback functions - this must be done before init */
+
+ /* The following are required for stream_decoder and higher */
+ FLAC__seekable_stream_decoder_set_client_data(flacDecoder,&file_info);
+ FLAC__seekable_stream_decoder_set_write_callback(flacDecoder, flac_write_handler);
+ FLAC__seekable_stream_decoder_set_read_callback(flacDecoder, flac_read_handler);
+ FLAC__seekable_stream_decoder_set_metadata_callback(flacDecoder, flac_metadata_handler);
+ FLAC__seekable_stream_decoder_set_error_callback(flacDecoder, flac_error_handler);
+ FLAC__seekable_stream_decoder_set_metadata_respond(flacDecoder, FLAC__METADATA_TYPE_STREAMINFO);
+
+ /* The following are only for the seekable_stream_decoder */
+ FLAC__seekable_stream_decoder_set_seek_callback(flacDecoder, flac_seek_handler);
+ FLAC__seekable_stream_decoder_set_tell_callback(flacDecoder, flac_tell_handler);
+ FLAC__seekable_stream_decoder_set_length_callback(flacDecoder, flac_length_handler);
+ FLAC__seekable_stream_decoder_set_eof_callback(flacDecoder, flac_eof_handler);
+
+ if (FLAC__seekable_stream_decoder_init(flacDecoder)) {
+ return PLUGIN_ERROR;
+ }
+
+ /* The first thing to do is to parse the metadata */
+ FLAC__seekable_stream_decoder_process_until_end_of_metadata(flacDecoder);
+
+ file_info.frames_decoded=0;
+ file_info.start_tick=*(rb->current_tick);
+ rb->button_clear_queue();
+
+ while (FLAC__seekable_stream_decoder_get_state(flacDecoder)!=2) {
+ FLAC__seekable_stream_decoder_process_single(flacDecoder);
+ file_info.frames_decoded++;
+
+ display_status(&file_info);
+
+ if (rb->button_get(false)!=BUTTON_NONE) {
+ close_wav(&file_info);
+ return PLUGIN_OK;
+ }
+ }
+
+ close_wav(&file_info);
+ rb->splash(HZ*2, true, "FINISHED!");
+
+ /* Flush internal buffers etc */
+//No need for this. flacResult=FLAC__seekable_stream_decoder_reset(flacDecoder);
+
+ // audio_close();
+
+ return PLUGIN_OK;
+}
+#endif /* CONFIG_HWCODEC == MASNONE */
diff --git a/apps/plugins/lib/codeclib.c b/apps/plugins/lib/codeclib.c
new file mode 100644
index 0000000000..9d9cc0b91b
--- /dev/null
+++ b/apps/plugins/lib/codeclib.c
@@ -0,0 +1,37 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2005 Dave Chapman
+ *
+ * All files in this archive are subject to the GNU General Public License.
+ * See the file COPYING in the source tree root for full license agreement.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+/* Various "helper functions" common to all the xxx2wav decoder plugins */
+
+#include "plugin.h"
+#include "playback.h"
+#include "codeclib.h"
+#include "xxx2wav.h"
+
+struct plugin_api* local_rb;
+
+int codec_init(struct plugin_api* rb, struct codec_api* ci) {
+ local_rb = rb;
+
+ xxx2wav_set_api(rb);
+ mem_ptr = 0;
+ mallocbuf = (unsigned char *)ci->get_codec_memory((size_t *)&bufsize);
+
+ return 0;
+}
diff --git a/apps/plugins/lib/codeclib.h b/apps/plugins/lib/codeclib.h
new file mode 100644
index 0000000000..876e69b57e
--- /dev/null
+++ b/apps/plugins/lib/codeclib.h
@@ -0,0 +1,46 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2005 Dave Chapman
+ *
+ * All files in this archive are subject to the GNU General Public License.
+ * See the file COPYING in the source tree root for full license agreement.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+/* Various "helper functions" common to all the xxx2wav decoder plugins */
+
+#if CONFIG_CPU == MCF5249 && !defined(SIMULATOR)
+#define ICODE_ATTR __attribute__ ((section(".icode")))
+#define IDATA_ATTR __attribute__ ((section(".idata")))
+#define USE_IRAM 1
+#else
+#define ICODE_ATTR
+#define IDATA_ATTR
+#endif
+
+extern int mem_ptr;
+extern int bufsize;
+extern unsigned char* mallocbuf; // 512K from the start of MP3 buffer
+
+void* codec_malloc(size_t size);
+void* codec_calloc(size_t nmemb, size_t size);
+void* codec_alloca(size_t size);
+void* codec_realloc(void* ptr, size_t size);
+void codec_free(void* ptr);
+void *memcpy(void *dest, const void *src, size_t n);
+void *memset(void *s, int c, size_t n);
+int memcmp(const void *s1, const void *s2, size_t n);
+void* memmove(const void *s1, const void *s2, size_t n);
+
+int codec_init(struct plugin_api* rb, struct codec_api* ci);
+
diff --git a/apps/plugins/lib/gray_black_display.c b/apps/plugins/lib/gray_black_display.c
new file mode 100644
index 0000000000..573060eb62
--- /dev/null
+++ b/apps/plugins/lib/gray_black_display.c
@@ -0,0 +1,44 @@
+/***************************************************************************
+* __________ __ ___.
+* Open \______ \ ____ ____ | | _\_ |__ _______ ___
+* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+* \/ \/ \/ \/ \/
+* $Id$
+*
+* Grayscale framework
+* gray_black_display() function
+*
+* This is a generic framework to use grayscale display within Rockbox
+* plugins. It obviously does not work for the player.
+*
+* Copyright (C) 2004 Jens Arnold
+*
+* All files in this archive are subject to the GNU General Public License.
+* See the file COPYING in the source tree root for full license agreement.
+*
+* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+* KIND, either express or implied.
+*
+****************************************************************************/
+
+#ifndef SIMULATOR /* not for simulator by now */
+#include "plugin.h"
+
+#ifdef HAVE_LCD_BITMAP /* and also not for the Player */
+#include "gray.h"
+
+/*---------------------------------------------------------------------------
+ Set the grayscale display to all black
+ ----------------------------------------------------------------------------
+ */
+void gray_black_display(void)
+{
+ _gray_rb->memset(_graybuf->data, 0xFF, MULU16(_graybuf->depth,
+ _graybuf->plane_size));
+}
+
+#endif // #ifdef HAVE_LCD_BITMAP
+#endif // #ifndef SIMULATOR
+
diff --git a/apps/plugins/lib/gray_blockfuncs.c b/apps/plugins/lib/gray_blockfuncs.c
new file mode 100644
index 0000000000..85af0014e1
--- /dev/null
+++ b/apps/plugins/lib/gray_blockfuncs.c
@@ -0,0 +1,262 @@
+/***************************************************************************
+* __________ __ ___.
+* Open \______ \ ____ ____ | | _\_ |__ _______ ___
+* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+* \/ \/ \/ \/ \/
+* $Id$
+*
+* Grayscale framework
+* Low level block drawing functions
+*
+* This is a generic framework to use grayscale display within Rockbox
+* plugins. It obviously does not work for the player.
+*
+* Copyright (C) 2004 Jens Arnold
+*
+* All files in this archive are subject to the GNU General Public License.
+* See the file COPYING in the source tree root for full license agreement.
+*
+* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+* KIND, either express or implied.
+*
+****************************************************************************/
+
+#ifndef SIMULATOR /* not for simulator by now */
+#include "plugin.h"
+
+#if CONFIG_LCD == LCD_SSD1815 /* only for Recorder/Ondio */
+#include "gray.h"
+
+/* Prototypes */
+static void _writeblock(unsigned char *address, unsigned mask, unsigned bits);
+static void _invertblock(unsigned char *address, unsigned mask, unsigned bits);
+static void _writeblockfg(unsigned char *address, unsigned mask, unsigned bits);
+static void _writeblockbg(unsigned char *address, unsigned mask, unsigned bits);
+
+/* Block function pointer array */
+void (* const _gray_blockfuncs[4])(unsigned char *address, unsigned mask,
+ unsigned bits) = {
+ _invertblock, _writeblockfg, _writeblockbg, _writeblock
+};
+
+/* Write an 8-pixel block, defined by foreground and background pattern.
+ * Address is the byte in the first bitplane, mask determines which pixels to
+ * set, and bits determines if the pixel is foreground or background */
+static void _writeblock(unsigned char *address, unsigned mask, unsigned bits)
+{
+ unsigned long pat_stack[8];
+ register unsigned char *end_addr;
+ register unsigned long *pat_ptr = &pat_stack[8];
+
+ /* precalculate the bit patterns with random shifts (same RNG as _writepixel,
+ * see there for an explanation) for all 8 pixels and put them on an
+ * extra stack */
+ asm (
+ "mov #8,r3 \n" /* loop count in r3: 8 pixels */
+ "mov %6,r2 \n" /* copy mask */
+
+ ".wb_loop: \n" /** load pattern for pixel **/
+ "shlr r2 \n" /* shift out lsb of mask */
+ "bf .wb_skip \n" /* skip this pixel */
+
+ "mov %2,r4 \n" /* load foreground pattern */
+ "shlr %7 \n" /* shift out lsb of bits */
+ "bt .wb_fg \n" /* foreground? -> skip next insn */
+ "mov %3,r4 \n" /* load background pattern */
+ ".wb_fg: \n"
+
+ "mov #75,r0 \n"
+ "mulu r0,%0 \n" /* multiply by 75 */
+ "sts macl,%0 \n"
+ "add #74,%0 \n" /* add another 74 */
+ /* Since the lower bits are not very random: */
+ "swap.b %0,r1 \n" /* get bits 8..15 (need max. 5) */
+ "and %5,r1 \n" /* mask out unneeded bits */
+
+ "cmp/hs %4,r1 \n" /* random >= depth ? */
+ "bf .wb_ntrim \n"
+ "sub %4,r1 \n" /* yes: random -= depth; */
+ ".wb_ntrim: \n"
+
+ "mov.l .ashlsi3,r0 \n" /** rotate pattern **/
+ "jsr @r0 \n" /* r4 -> r0, shift left by r5 */
+ "mov r1,r5 \n"
+
+ "mov %4,r5 \n"
+ "sub r1,r5 \n" /* r5 = depth - r1 */
+ "mov.l .lshrsi3,r1 \n"
+ "jsr @r1 \n" /* r4 -> r0, shift right by r5 */
+ "mov r0,r1 \n" /* store previous result in r1 */
+
+ "bra .wb_store \n"
+ "or r1,r0 \n" /* rotated_pattern = r0 | r1 */
+
+ ".wb_skip: \n"
+ "shlr %7 \n" /* shift out lsb of bits to keep in sync */
+ "mov #0,r0 \n" /* pattern for skipped pixel must be 0 */
+
+ ".wb_store: \n"
+ "mov.l r0,@-%1 \n" /* push on pattern stack */
+
+ "add #-1,r3 \n" /* decrease loop count */
+ "cmp/pl r3 \n" /* loop count > 0? */
+ "bt .wb_loop \n" /* yes: loop */
+ : /* outputs */
+ /* %0, in & out */ "+r"(_gray_random_buffer),
+ /* %1, in & out */ "+r"(pat_ptr)
+ : /* inputs */
+ /* %2 */ "r"(_graybuf->fg_pattern),
+ /* %3 */ "r"(_graybuf->bg_pattern),
+ /* %4 */ "r"(_graybuf->depth),
+ /* %5 */ "r"(_graybuf->randmask),
+ /* %6 */ "r"(mask),
+ /* %7 */ "r"(bits)
+ : /* clobbers */
+ "r0", "r1", "r2", "r3", "r4", "r5", "macl", "pr"
+ );
+
+ end_addr = address + MULU16(_graybuf->depth, _graybuf->plane_size);
+
+ /* set the bits for all 8 pixels in all bytes according to the
+ * precalculated patterns on the pattern stack */
+ asm volatile (
+ "mov.l @%3+,r1 \n" /* pop all 8 patterns */
+ "mov.l @%3+,r2 \n"
+ "mov.l @%3+,r3 \n"
+ "mov.l @%3+,r8 \n"
+ "mov.l @%3+,r9 \n"
+ "mov.l @%3+,r10 \n"
+ "mov.l @%3+,r11 \n"
+ "mov.l @%3+,r12 \n"
+
+ "not %4,%4 \n" /* "set" mask -> "keep" mask */
+ "extu.b %4,%4 \n" /* mask out high bits */
+ "tst %4,%4 \n" /* nothing to keep? */
+ "bt .wb_sloop \n" /* yes: jump to short loop */
+
+ ".wb_floop: \n" /** full loop (there are bits to keep)**/
+ "shlr r1 \n" /* rotate lsb of pattern 1 to t bit */
+ "rotcl r0 \n" /* rotate t bit into r0 */
+ "shlr r2 \n"
+ "rotcl r0 \n"
+ "shlr r3 \n"
+ "rotcl r0 \n"
+ "shlr r8 \n"
+ "rotcl r0 \n"
+ "shlr r9 \n"
+ "rotcl r0 \n"
+ "shlr r10 \n"
+ "rotcl r0 \n"
+ "shlr r11 \n"
+ "rotcl r0 \n"
+ "shlr r12 \n"
+ "mov.b @%0,%3 \n" /* read old value */
+ "rotcl r0 \n"
+ "and %4,%3 \n" /* mask out unneeded bits */
+ "or r0,%3 \n" /* set new bits */
+ "mov.b %3,@%0 \n" /* store value to bitplane */
+ "add %2,%0 \n" /* advance to next bitplane */
+ "cmp/hi %0,%1 \n" /* last bitplane done? */
+ "bt .wb_floop \n" /* no: loop */
+
+ "bra .wb_end \n"
+ "nop \n"
+
+ ".wb_sloop: \n" /** short loop (nothing to keep) **/
+ "shlr r1 \n" /* rotate lsb of pattern 1 to t bit */
+ "rotcl r0 \n" /* rotate t bit into r0 */
+ "shlr r2 \n"
+ "rotcl r0 \n"
+ "shlr r3 \n"
+ "rotcl r0 \n"
+ "shlr r8 \n"
+ "rotcl r0 \n"
+ "shlr r9 \n"
+ "rotcl r0 \n"
+ "shlr r10 \n"
+ "rotcl r0 \n"
+ "shlr r11 \n"
+ "rotcl r0 \n"
+ "shlr r12 \n"
+ "rotcl r0 \n"
+ "mov.b r0,@%0 \n" /* store byte to bitplane */
+ "add %2,%0 \n" /* advance to next bitplane */
+ "cmp/hi %0,%1 \n" /* last bitplane done? */
+ "bt .wb_sloop \n" /* no: loop */
+
+ ".wb_end: \n"
+ : /* outputs */
+ : /* inputs */
+ /* %0 */ "r"(address),
+ /* %1 */ "r"(end_addr),
+ /* %2 */ "r"(_graybuf->plane_size),
+ /* %3 */ "r"(pat_ptr),
+ /* %4 */ "r"(mask)
+ : /* clobbers */
+ "r0", "r1", "r2", "r3", "r8", "r9", "r10", "r11", "r12"
+ );
+}
+
+/* References to C library routines used in _writeblock */
+asm (
+ ".align 2 \n"
+".ashlsi3: \n" /* C library routine: */
+ ".long ___ashlsi3 \n" /* shift r4 left by r5, return in r0 */
+".lshrsi3: \n" /* C library routine: */
+ ".long ___lshrsi3 \n" /* shift r4 right by r5, return in r0 */
+ /* both routines preserve r4, destroy r5 and take ~16 cycles */
+);
+
+/* Invert pixels within an 8-pixel block.
+ * Address is the byte in the first bitplane, mask and bits determine which
+ * pixels to invert ('And'ed together, for matching the parameters with
+ * _writeblock) */
+static void _invertblock(unsigned char *address, unsigned mask, unsigned bits)
+{
+ bits &= mask;
+ if (!bits)
+ return;
+
+ asm volatile (
+ "mov #0,r1 \n" /* current_plane = 0 */
+
+ ".im_loop: \n"
+ "mov.b @%1,r2 \n" /* get data byte */
+ "add #1,r1 \n" /* current_plane++; */
+ "xor %2,r2 \n" /* invert bits */
+ "mov.b r2,@%1 \n" /* store data byte */
+ "add %3,%1 \n" /* advance address to next bitplane */
+ "cmp/hi r1,%0 \n" /* current_plane < depth ? */
+ "bt .im_loop \n"
+ : /* outputs */
+ : /* inputs */
+ /* %0 */ "r"(_graybuf->depth),
+ /* %1 */ "r"(address),
+ /* %2 */ "r"(bits),
+ /* %3 */ "r"(_graybuf->plane_size)
+ : /* clobbers */
+ "r1", "r2", "macl"
+ );
+}
+
+/* Call _writeblock with the mask modified to draw foreground pixels only */
+static void _writeblockfg(unsigned char *address, unsigned mask, unsigned bits)
+{
+ mask &= bits;
+ if (mask)
+ _writeblock(address, mask, bits);
+}
+
+/* Call _writeblock with the mask modified to draw background pixels only */
+static void _writeblockbg(unsigned char *address, unsigned mask, unsigned bits)
+{
+ mask &= ~bits;
+ if (mask)
+ _writeblock(address, mask, bits);
+}
+
+#endif // #ifdef HAVE_LCD_BITMAP
+#endif // #ifndef SIMULATOR
+
diff --git a/apps/plugins/lib/gray_clear_display.c b/apps/plugins/lib/gray_clear_display.c
new file mode 100644
index 0000000000..835107a7fe
--- /dev/null
+++ b/apps/plugins/lib/gray_clear_display.c
@@ -0,0 +1,44 @@
+/***************************************************************************
+* __________ __ ___.
+* Open \______ \ ____ ____ | | _\_ |__ _______ ___
+* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+* \/ \/ \/ \/ \/
+* $Id$
+*
+* Grayscale framework
+* gray_clear_display() function
+*
+* This is a generic framework to use grayscale display within Rockbox
+* plugins. It obviously does not work for the player.
+*
+* Copyright (C) 2004 Jens Arnold
+*
+* All files in this archive are subject to the GNU General Public License.
+* See the file COPYING in the source tree root for full license agreement.
+*
+* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+* KIND, either express or implied.
+*
+****************************************************************************/
+
+#ifndef SIMULATOR /* not for simulator by now */
+#include "plugin.h"
+
+#ifdef HAVE_LCD_BITMAP /* and also not for the Player */
+#include "gray.h"
+
+/*---------------------------------------------------------------------------
+ Clear the grayscale display (sets all pixels to white)
+ ----------------------------------------------------------------------------
+ */
+void gray_clear_display(void)
+{
+ _gray_rb->memset(_graybuf->data, 0, MULU16(_graybuf->depth,
+ _graybuf->plane_size));
+}
+
+#endif // #ifdef HAVE_LCD_BITMAP
+#endif // #ifndef SIMULATOR
+
diff --git a/apps/plugins/lib/gray_deferred_update.c b/apps/plugins/lib/gray_deferred_update.c
new file mode 100644
index 0000000000..3b6edd869e
--- /dev/null
+++ b/apps/plugins/lib/gray_deferred_update.c
@@ -0,0 +1,50 @@
+/***************************************************************************
+* __________ __ ___.
+* Open \______ \ ____ ____ | | _\_ |__ _______ ___
+* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+* \/ \/ \/ \/ \/
+* $Id$
+*
+* Grayscale framework
+* gray_deferred_update() function
+*
+* This is a generic framework to use grayscale display within Rockbox
+* plugins. It obviously does not work for the player.
+*
+* Copyright (C) 2004 Jens Arnold
+*
+* All files in this archive are subject to the GNU General Public License.
+* See the file COPYING in the source tree root for full license agreement.
+*
+* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+* KIND, either express or implied.
+*
+****************************************************************************/
+
+#ifndef SIMULATOR /* not for simulator by now */
+#include "plugin.h"
+
+#ifdef HAVE_LCD_BITMAP /* and also not for the Player */
+#include "gray.h"
+
+/*---------------------------------------------------------------------------
+ Do an lcd_update() to show changes done by rb->lcd_xxx() functions (in areas
+ of the screen not covered by the grayscale overlay).
+ ----------------------------------------------------------------------------
+ If the grayscale overlay is running, the update will be done in the next
+ call of the interrupt routine, otherwise it will be performed right away.
+ See also comment for the gray_show_display() function.
+ */
+void gray_deferred_update(void)
+{
+ if (_graybuf->flags & _GRAY_RUNNING)
+ _graybuf->flags |= _GRAY_DEFERRED_UPDATE;
+ else
+ _gray_rb->lcd_update();
+}
+
+#endif // #ifdef HAVE_LCD_BITMAP
+#endif // #ifndef SIMULATOR
+
diff --git a/apps/plugins/lib/gray_drawbitmap.c b/apps/plugins/lib/gray_drawbitmap.c
new file mode 100644
index 0000000000..376f76d45e
--- /dev/null
+++ b/apps/plugins/lib/gray_drawbitmap.c
@@ -0,0 +1,116 @@
+/***************************************************************************
+* __________ __ ___.
+* Open \______ \ ____ ____ | | _\_ |__ _______ ___
+* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+* \/ \/ \/ \/ \/
+* $Id$
+*
+* Grayscale framework
+* gray_drawbitmap() function
+*
+* This is a generic framework to use grayscale display within Rockbox
+* plugins. It obviously does not work for the player.
+*
+* Copyright (C) 2004 Jens Arnold
+*
+* All files in this archive are subject to the GNU General Public License.
+* See the file COPYING in the source tree root for full license agreement.
+*
+* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+* KIND, either express or implied.
+*
+****************************************************************************/
+
+#ifndef SIMULATOR /* not for simulator by now */
+#include "plugin.h"
+
+#ifdef HAVE_LCD_BITMAP /* and also not for the Player */
+#include "gray.h"
+
+/*---------------------------------------------------------------------------
+ Display a bitmap with the current drawinfo
+ ----------------------------------------------------------------------------
+ The drawmode is used as described for gray_set_drawmode()
+
+ This (now) uses the same bitmap format as the core b&w graphics routines,
+ so you can use bmp2rb to generate bitmaps for use with this function as
+ well.
+
+ A bitmap contains one bit for every pixel that defines if that pixel is
+ foreground (1) or background (0). Bits within a byte are arranged
+ vertically, LSB at top.
+ The bytes are stored in row-major order, with byte 0 being top left,
+ byte 1 2nd from left etc. The first row of bytes defines pixel rows
+ 0..7, the second row defines pixel row 8..15 etc.
+
+ The <stride> parameter is useful if you want to show only a part of a
+ bitmap. It should always be set to the "row length" of the bitmap.
+ */
+void gray_drawbitmap(const unsigned char *src, int x, int y, int nx, int ny,
+ int stride)
+{
+ int shift;
+ unsigned bits, mask_top, mask_bottom;
+ const unsigned char *src_col;
+ unsigned char *dst, *dst_col;
+ void (*blockfunc)(unsigned char *address, unsigned mask, unsigned bits);
+
+ if ((unsigned) x >= (unsigned) _graybuf->width
+ || (unsigned) y >= (unsigned) _graybuf->height)
+ return;
+
+ if ((unsigned) (y + ny) >= (unsigned) _graybuf->height) /* clip bottom */
+ ny = _graybuf->height - y;
+
+ if ((unsigned) (x + nx) >= (unsigned) _graybuf->width) /* clip right */
+ nx = _graybuf->width - x;
+
+ dst = _graybuf->data + x + MULU16(_graybuf->width, y >> 3);
+ shift = y & 7;
+ ny += shift;
+
+ mask_top = 0xFFu << (y & 7);
+ mask_bottom = ~(0xFEu << ((ny - 1) & 7));
+ if (ny <= 8)
+ mask_bottom &= mask_top;
+
+ blockfunc = _gray_blockfuncs[_graybuf->drawmode];
+
+ for(x = 0; x < nx; x++)
+ {
+ src_col = src++;
+ dst_col = dst++;
+ bits = 0;
+ y = 0;
+
+ if (ny > 8)
+ {
+ bits = *src_col << shift;
+ src_col += stride;
+
+ blockfunc(dst_col, mask_top, bits);
+ dst_col += _graybuf->width;
+ bits >>= 8;
+
+ for (y = 8; y < ny - 8; y += 8)
+ {
+ bits |= *src_col << shift;
+ src_col += stride;
+
+ blockfunc(dst_col, 0xFFu, bits);
+ dst_col += _graybuf->width;
+ bits >>= 8;
+ }
+ }
+ if (y + shift < ny)
+ bits |= *src_col << shift;
+
+ blockfunc(dst_col, mask_bottom, bits);
+ }
+}
+
+#endif // #ifdef HAVE_LCD_BITMAP
+#endif // #ifndef SIMULATOR
+
diff --git a/apps/plugins/lib/gray_drawgraymap.c b/apps/plugins/lib/gray_drawgraymap.c
new file mode 100644
index 0000000000..2760d5a96c
--- /dev/null
+++ b/apps/plugins/lib/gray_drawgraymap.c
@@ -0,0 +1,275 @@
+/***************************************************************************
+* __________ __ ___.
+* Open \______ \ ____ ____ | | _\_ |__ _______ ___
+* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+* \/ \/ \/ \/ \/
+* $Id$
+*
+* Grayscale framework
+* gray_drawgraymap() function
+*
+* This is a generic framework to use grayscale display within Rockbox
+* plugins. It obviously does not work for the player.
+*
+* Copyright (C) 2004 Jens Arnold
+*
+* All files in this archive are subject to the GNU General Public License.
+* See the file COPYING in the source tree root for full license agreement.
+*
+* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+* KIND, either express or implied.
+*
+****************************************************************************/
+
+#ifndef SIMULATOR /* not for simulator by now */
+#include "plugin.h"
+
+#if CONFIG_LCD == LCD_SSD1815 /* only for Recorder/Ondio */
+#include "gray.h"
+
+/* Prototypes */
+static void _writearray(unsigned char *address, const unsigned char *src,
+ int stride, unsigned mask);
+
+/* Write an 8-pixel block, defined by their brightnesses in a graymap.
+ * Address is the byte in the first bitplane, src is the graymap start address,
+ * stride is the increment for the graymap to get to the next pixel, mask
+ * determines which pixels of the destination block are changed. For "0" bits,
+ * the src address is not incremented! */
+static void _writearray(unsigned char *address, const unsigned char *src,
+ int stride, unsigned mask)
+{
+ unsigned long pat_stack[8];
+ register unsigned char *end_addr;
+ register unsigned long *pat_ptr = &pat_stack[8];
+
+ /* precalculate the bit patterns with random shifts (same RNG as
+ * _writepixel, see there for an explanation) for all 8 pixels and put them
+ * on an extra "stack" */
+ asm (
+ "mov #8,r3 \n" /* loop count in r3: 8 pixels */
+ "mov %7,r2 \n" /* copy mask */
+
+ ".wa_loop: \n" /** load pattern for pixel **/
+ "mov #0,r0 \n" /* pattern for skipped pixel must be 0 */
+ "shlr r2 \n" /* shift out lsb of mask */
+ "bf .wa_skip \n" /* skip this pixel */
+
+ "mov.b @%2,r0 \n" /* load src byte */
+ "extu.b r0,r0 \n" /* extend unsigned */
+ "mulu %4,r0 \n" /* macl = byte * depth; */
+ "add %3,%2 \n" /* src += stride; */
+ "sts macl,r4 \n" /* r4 = macl; */
+ "add r4,r0 \n" /* byte += r4; */
+ "shlr8 r0 \n" /* byte >>= 8; */
+ "shll2 r0 \n"
+ "mov.l @(r0,%5),r4 \n" /* r4 = bitpattern[byte]; */
+
+ "mov #75,r0 \n"
+ "mulu r0,%0 \n" /* multiply by 75 */
+ "sts macl,%0 \n"
+ "add #74,%0 \n" /* add another 74 */
+ /* Since the lower bits are not very random: */
+ "swap.b %0,r1 \n" /* get bits 8..15 (need max. 5) */
+ "and %6,r1 \n" /* mask out unneeded bits */
+
+ "cmp/hs %4,r1 \n" /* random >= depth ? */
+ "bf .wa_ntrim \n"
+ "sub %4,r1 \n" /* yes: random -= depth; */
+ ".wa_ntrim: \n"
+
+ "mov.l .ashlsi3,r0 \n" /** rotate pattern **/
+ "jsr @r0 \n" /* r4 -> r0, shift left by r5 */
+ "mov r1,r5 \n"
+
+ "mov %4,r5 \n"
+ "sub r1,r5 \n" /* r5 = depth - r1 */
+ "mov.l .lshrsi3,r1 \n"
+ "jsr @r1 \n" /* r4 -> r0, shift right by r5 */
+ "mov r0,r1 \n" /* store previous result in r1 */
+
+ "or r1,r0 \n" /* rotated_pattern = r0 | r1 */
+
+ ".wa_skip: \n"
+ "mov.l r0,@-%1 \n" /* push on pattern stack */
+
+ "add #-1,r3 \n" /* decrease loop count */
+ "cmp/pl r3 \n" /* loop count > 0? */
+ "bt .wa_loop \n" /* yes: loop */
+ : /* outputs */
+ /* %0, in & out */ "+r"(_gray_random_buffer),
+ /* %1, in & out */ "+r"(pat_ptr)
+ : /* inputs */
+ /* %2 */ "r"(src),
+ /* %3 */ "r"(stride),
+ /* %4 */ "r"(_graybuf->depth),
+ /* %5 */ "r"(_graybuf->bitpattern),
+ /* %6 */ "r"(_graybuf->randmask),
+ /* %7 */ "r"(mask)
+ : /* clobbers */
+ "r0", "r1", "r2", "r3", "r4", "r5", "macl", "pr"
+ );
+
+ end_addr = address + MULU16(_graybuf->depth, _graybuf->plane_size);
+
+ /* set the bits for all 8 pixels in all bytes according to the
+ * precalculated patterns on the pattern stack */
+ asm volatile (
+ "mov.l @%3+,r1 \n" /* pop all 8 patterns */
+ "mov.l @%3+,r2 \n"
+ "mov.l @%3+,r3 \n"
+ "mov.l @%3+,r8 \n"
+ "mov.l @%3+,r9 \n"
+ "mov.l @%3+,r10 \n"
+ "mov.l @%3+,r11 \n"
+ "mov.l @%3+,r12 \n"
+
+ "not %4,%4 \n" /* "set" mask -> "keep" mask */
+ "extu.b %4,%4 \n" /* mask out high bits */
+ "tst %4,%4 \n" /* nothing to keep? */
+ "bt .wa_sloop \n" /* yes: jump to short loop */
+
+ ".wa_floop: \n" /** full loop (there are bits to keep)**/
+ "shlr r1 \n" /* rotate lsb of pattern 1 to t bit */
+ "rotcl r0 \n" /* rotate t bit into r0 */
+ "shlr r2 \n"
+ "rotcl r0 \n"
+ "shlr r3 \n"
+ "rotcl r0 \n"
+ "shlr r8 \n"
+ "rotcl r0 \n"
+ "shlr r9 \n"
+ "rotcl r0 \n"
+ "shlr r10 \n"
+ "rotcl r0 \n"
+ "shlr r11 \n"
+ "rotcl r0 \n"
+ "shlr r12 \n"
+ "mov.b @%0,%3 \n" /* read old value */
+ "rotcl r0 \n"
+ "and %4,%3 \n" /* mask out unneeded bits */
+ "or r0,%3 \n" /* set new bits */
+ "mov.b %3,@%0 \n" /* store value to bitplane */
+ "add %2,%0 \n" /* advance to next bitplane */
+ "cmp/hi %0,%1 \n" /* last bitplane done? */
+ "bt .wa_floop \n" /* no: loop */
+
+ "bra .wa_end \n"
+ "nop \n"
+
+ ".wa_sloop: \n" /** short loop (nothing to keep) **/
+ "shlr r1 \n" /* rotate lsb of pattern 1 to t bit */
+ "rotcl r0 \n" /* rotate t bit into r0 */
+ "shlr r2 \n"
+ "rotcl r0 \n"
+ "shlr r3 \n"
+ "rotcl r0 \n"
+ "shlr r8 \n"
+ "rotcl r0 \n"
+ "shlr r9 \n"
+ "rotcl r0 \n"
+ "shlr r10 \n"
+ "rotcl r0 \n"
+ "shlr r11 \n"
+ "rotcl r0 \n"
+ "shlr r12 \n"
+ "rotcl r0 \n"
+ "mov.b r0,@%0 \n" /* store byte to bitplane */
+ "add %2,%0 \n" /* advance to next bitplane */
+ "cmp/hi %0,%1 \n" /* last bitplane done? */
+ "bt .wa_sloop \n" /* no: loop */
+
+ ".wa_end: \n"
+ : /* outputs */
+ : /* inputs */
+ /* %0 */ "r"(address),
+ /* %1 */ "r"(end_addr),
+ /* %2 */ "r"(_graybuf->plane_size),
+ /* %3 */ "r"(pat_ptr),
+ /* %4 */ "r"(mask)
+ : /* clobbers */
+ "r0", "r1", "r2", "r3", "r8", "r9", "r10", "r11", "r12"
+ );
+}
+
+/* References to C library routines used in _writearray */
+asm (
+ ".align 2 \n"
+".ashlsi3: \n" /* C library routine: */
+ ".long ___ashlsi3 \n" /* shift r4 left by r5, return in r0 */
+".lshrsi3: \n" /* C library routine: */
+ ".long ___lshrsi3 \n" /* shift r4 right by r5, return in r0 */
+ /* both routines preserve r4, destroy r5 and take ~16 cycles */
+);
+
+/*---------------------------------------------------------------------------
+ Copy a grayscale bitmap into the display
+ ----------------------------------------------------------------------------
+ A grayscale bitmap contains one byte for every pixel that defines the
+ brightness of the pixel (0..255). Bytes are read in row-major order.
+ The <stride> parameter is useful if you want to show only a part of a
+ bitmap. It should always be set to the "row length" of the bitmap, so
+ for displaying the whole bitmap, nx == stride.
+
+ This is the only drawing function NOT using the drawinfo.
+ */
+void gray_drawgraymap(const unsigned char *src, int x, int y, int nx, int ny,
+ int stride)
+{
+ int shift;
+ unsigned mask_top, mask_bottom;
+ const unsigned char *src_row;
+ unsigned char *dst, *dst_row;
+
+ if ((unsigned) x >= (unsigned) _graybuf->width
+ || (unsigned) y >= (unsigned) _graybuf->height)
+ return;
+
+ if ((unsigned) (y + ny) >= (unsigned) _graybuf->height) /* clip bottom */
+ ny = _graybuf->height - y;
+
+ if ((unsigned) (x + nx) >= (unsigned) _graybuf->width) /* clip right */
+ nx = _graybuf->width - x;
+
+ dst = _graybuf->data + x + MULU16(_graybuf->width, y >> 3);
+ shift = y & 7;
+ ny += shift;
+
+ mask_top = 0xFFu << (y & 7);
+ mask_bottom = ~(0xFEu << ((ny - 1) & 7));
+ if (ny <= 8)
+ mask_bottom &= mask_top;
+
+ if (ny > 8)
+ {
+ src_row = src;
+ dst_row = dst;
+
+ for (x = 0; x < nx; x++)
+ _writearray(dst_row++, src_row++, stride, mask_top);
+
+ src += MULU16(stride, 8 - shift);
+ dst += _graybuf->width;
+
+ for (y = 8; y < ny - 8; y += 8)
+ {
+ src_row = src;
+ dst_row = dst;
+
+ for (x = 0; x < nx; x++)
+ _writearray(dst_row++, src_row++, stride, 0xFFu);
+
+ src += stride << 3;
+ dst += _graybuf->width;
+ }
+ }
+
+ for (x = 0; x < nx; x++)
+ _writearray(dst++, src++, stride, mask_bottom);
+}
+
+#endif // #ifdef HAVE_LCD_BITMAP
+#endif // #ifndef SIMULATOR
+
diff --git a/apps/plugins/lib/gray_drawline.c b/apps/plugins/lib/gray_drawline.c
new file mode 100644
index 0000000000..5ec4967c14
--- /dev/null
+++ b/apps/plugins/lib/gray_drawline.c
@@ -0,0 +1,119 @@
+/***************************************************************************
+* __________ __ ___.
+* Open \______ \ ____ ____ | | _\_ |__ _______ ___
+* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+* \/ \/ \/ \/ \/
+* $Id$
+*
+* Grayscale framework
+* gray_drawline() function
+*
+* This is a generic framework to use grayscale display within Rockbox
+* plugins. It obviously does not work for the player.
+*
+* Copyright (C) 2004 Jens Arnold
+*
+* All files in this archive are subject to the GNU General Public License.
+* See the file COPYING in the source tree root for full license agreement.
+*
+* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+* KIND, either express or implied.
+*
+****************************************************************************/
+
+#ifndef SIMULATOR /* not for simulator by now */
+#include "plugin.h"
+
+#ifdef HAVE_LCD_BITMAP /* and also not for the Player */
+#include "gray.h"
+
+/*---------------------------------------------------------------------------
+ Draw a line from (x1, y1) to (x2, y2) with the current drawinfo
+ ----------------------------------------------------------------------------
+ See gray_drawpixel() for details
+ */
+void gray_drawline(int x1, int y1, int x2, int y2)
+{
+ int numpixels;
+ int i;
+ int deltax, deltay;
+ int d, dinc1, dinc2;
+ int x, xinc1, xinc2;
+ int y, yinc1, yinc2;
+ unsigned long pattern;
+ void (*pixelfunc)(int x, int y, unsigned long pattern);
+
+ if ((unsigned) x1 >= (unsigned) _graybuf->width
+ || (unsigned) y1 >= (unsigned) _graybuf->height
+ || (unsigned) x2 >= (unsigned) _graybuf->width
+ || (unsigned) y2 >= (unsigned) _graybuf->height)
+ return;
+
+ deltax = abs(x2 - x1);
+ deltay = abs(y2 - y1);
+ xinc2 = 1;
+ yinc2 = 1;
+
+ if (deltax >= deltay)
+ {
+ numpixels = deltax;
+ d = 2 * deltay - deltax;
+ dinc1 = deltay * 2;
+ dinc2 = (deltay - deltax) * 2;
+ xinc1 = 1;
+ yinc1 = 0;
+ }
+ else
+ {
+ numpixels = deltay;
+ d = 2 * deltax - deltay;
+ dinc1 = deltax * 2;
+ dinc2 = (deltax - deltay) * 2;
+ xinc1 = 0;
+ yinc1 = 1;
+ }
+ numpixels++; /* include endpoints */
+
+ if (x1 > x2)
+ {
+ xinc1 = -xinc1;
+ xinc2 = -xinc2;
+ }
+
+ if (y1 > y2)
+ {
+ yinc1 = -yinc1;
+ yinc2 = -yinc2;
+ }
+
+ x = x1;
+ y = y1;
+
+ pixelfunc = _gray_pixelfuncs[_graybuf->drawmode];
+ pattern = (_graybuf->drawmode == GRAY_DRAW_BG) ?
+ _graybuf->bg_pattern : _graybuf->fg_pattern;
+
+ for (i = 0; i < numpixels; i++)
+ {
+ pixelfunc(x, y, pattern);
+
+ if (d < 0)
+ {
+ d += dinc1;
+ x += xinc1;
+ y += yinc1;
+ }
+ else
+ {
+ d += dinc2;
+ x += xinc2;
+ y += yinc2;
+ }
+ }
+}
+
+#endif // #ifdef HAVE_LCD_BITMAP
+#endif // #ifndef SIMULATOR
+
diff --git a/apps/plugins/lib/gray_drawpixel.c b/apps/plugins/lib/gray_drawpixel.c
new file mode 100644
index 0000000000..f7601f4360
--- /dev/null
+++ b/apps/plugins/lib/gray_drawpixel.c
@@ -0,0 +1,55 @@
+/***************************************************************************
+* __________ __ ___.
+* Open \______ \ ____ ____ | | _\_ |__ _______ ___
+* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+* \/ \/ \/ \/ \/
+* $Id$
+*
+* Grayscale framework
+* gray_drawpixel() function
+*
+* This is a generic framework to use grayscale display within Rockbox
+* plugins. It obviously does not work for the player.
+*
+* Copyright (C) 2004 Jens Arnold
+*
+* All files in this archive are subject to the GNU General Public License.
+* See the file COPYING in the source tree root for full license agreement.
+*
+* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+* KIND, either express or implied.
+*
+****************************************************************************/
+
+#ifndef SIMULATOR /* not for simulator by now */
+#include "plugin.h"
+
+#ifdef HAVE_LCD_BITMAP /* and also not for the Player */
+#include "gray.h"
+
+/*---------------------------------------------------------------------------
+ Set a pixel with the current drawinfo
+ ----------------------------------------------------------------------------
+ If the drawmode is GRAY_DRAW_INVERSE, the pixel is inverted
+ GRAY_DRAW_FG and GRAY_DRAW_SOLID draw the pixel in the foreground shade
+ GRAY_DRAW_BG draws the pixel in the background shade
+ */
+void gray_drawpixel(int x, int y)
+{
+ unsigned long pattern;
+
+ if ((unsigned) x >= (unsigned) _graybuf->width
+ || (unsigned) y >= (unsigned) _graybuf->height)
+ return;
+
+ pattern = (_graybuf->drawmode == GRAY_DRAW_BG) ?
+ _graybuf->bg_pattern : _graybuf->fg_pattern;
+
+ _gray_pixelfuncs[_graybuf->drawmode](x, y, pattern);
+}
+
+#endif // #ifdef HAVE_LCD_BITMAP
+#endif // #ifndef SIMULATOR
+
diff --git a/apps/plugins/lib/gray_drawrect.c b/apps/plugins/lib/gray_drawrect.c
new file mode 100644
index 0000000000..bd0bb71852
--- /dev/null
+++ b/apps/plugins/lib/gray_drawrect.c
@@ -0,0 +1,62 @@
+/***************************************************************************
+* __________ __ ___.
+* Open \______ \ ____ ____ | | _\_ |__ _______ ___
+* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+* \/ \/ \/ \/ \/
+* $Id$
+*
+* Grayscale framework
+* gray_drawrect() function
+*
+* This is a generic framework to use grayscale display within Rockbox
+* plugins. It obviously does not work for the player.
+*
+* Copyright (C) 2004 Jens Arnold
+*
+* All files in this archive are subject to the GNU General Public License.
+* See the file COPYING in the source tree root for full license agreement.
+*
+* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+* KIND, either express or implied.
+*
+****************************************************************************/
+
+#ifndef SIMULATOR /* not for simulator by now */
+#include "plugin.h"
+
+#ifdef HAVE_LCD_BITMAP /* and also not for the Player */
+#include "gray.h"
+
+/*---------------------------------------------------------------------------
+ Draw a (hollow) rectangle with the current drawinfo
+ ----------------------------------------------------------------------------
+ See gray_drawpixel() for details
+ */
+void gray_drawrect(int x, int y, int nx, int ny)
+{
+ int x2, y2;
+
+ if ((unsigned) x >= (unsigned) _graybuf->width
+ || (unsigned) y >= (unsigned) _graybuf->height)
+ return;
+
+ if ((unsigned) (y + ny) >= (unsigned) _graybuf->height) /* clip bottom */
+ ny = _graybuf->height - y;
+
+ if ((unsigned) (x + nx) >= (unsigned) _graybuf->width) /* clip right */
+ nx = _graybuf->width - x;
+
+ x2 = x + nx - 1;
+ y2 = y + ny - 1;
+
+ gray_horline(x, x2, y);
+ gray_horline(x, x2, y2);
+ gray_verline(x, y, y2);
+ gray_verline(x2, y, y2);
+}
+
+#endif // #ifdef HAVE_LCD_BITMAP
+#endif // #ifndef SIMULATOR
+
diff --git a/apps/plugins/lib/gray_fillrect.c b/apps/plugins/lib/gray_fillrect.c
new file mode 100644
index 0000000000..ac6d4818b9
--- /dev/null
+++ b/apps/plugins/lib/gray_fillrect.c
@@ -0,0 +1,92 @@
+/***************************************************************************
+* __________ __ ___.
+* Open \______ \ ____ ____ | | _\_ |__ _______ ___
+* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+* \/ \/ \/ \/ \/
+* $Id$
+*
+* Grayscale framework
+* gray_fillrect() function
+*
+* This is a generic framework to use grayscale display within Rockbox
+* plugins. It obviously does not work for the player.
+*
+* Copyright (C) 2004 Jens Arnold
+*
+* All files in this archive are subject to the GNU General Public License.
+* See the file COPYING in the source tree root for full license agreement.
+*
+* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+* KIND, either express or implied.
+*
+****************************************************************************/
+
+#ifndef SIMULATOR /* not for simulator by now */
+#include "plugin.h"
+
+#ifdef HAVE_LCD_BITMAP /* and also not for the Player */
+#include "gray.h"
+
+/*---------------------------------------------------------------------------
+ Draw a filled rectangle with the current drawinfo
+ ----------------------------------------------------------------------------
+ See gray_drawpixel() for details
+
+ This one uses the block drawing optimization, so it is rather fast.
+ */
+void gray_fillrect(int x, int y, int nx, int ny)
+{
+ int shift;
+ unsigned bits, mask_top, mask_bottom;
+ unsigned char *dst, *dst_row;
+ void (*blockfunc)(unsigned char *address, unsigned mask, unsigned bits);
+
+ if ((unsigned) x >= (unsigned) _graybuf->width
+ || (unsigned) y >= (unsigned) _graybuf->height)
+ return;
+
+ if ((unsigned) (y + ny) >= (unsigned) _graybuf->height) /* clip bottom */
+ ny = _graybuf->height - y;
+
+ if ((unsigned) (x + nx) >= (unsigned) _graybuf->width) /* clip right */
+ nx = _graybuf->width - x;
+
+ dst = _graybuf->data + x + MULU16(_graybuf->width, y >> 3);
+ shift = y & 7;
+ ny += shift;
+
+ mask_top = 0xFFu << (y & 7);
+ mask_bottom = ~(0xFEu << ((ny - 1) & 7));
+ if (ny <= 8)
+ mask_bottom &= mask_top;
+
+ blockfunc = _gray_blockfuncs[_graybuf->drawmode];
+ bits = (_graybuf->drawmode == GRAY_DRAW_BG) ? 0u : 0xFFu;
+
+ if (ny > 8)
+ {
+ dst_row = dst;
+ for (x = 0; x < nx; x++)
+ blockfunc(dst_row++, mask_top, bits);
+
+ dst += _graybuf->width;
+
+ for (y = 8; y < ny - 8; y += 8)
+ {
+ dst_row = dst;
+ for (x = 0; x < nx; x++)
+ blockfunc(dst_row++, 0xFFu, bits);
+
+ dst += _graybuf->width;
+ }
+ }
+
+ for (x = 0; x < nx; x++)
+ blockfunc(dst++, mask_bottom, bits);
+}
+
+#endif // #ifdef HAVE_LCD_BITMAP
+#endif // #ifndef SIMULATOR
+
diff --git a/apps/plugins/lib/gray_getstringsize.c b/apps/plugins/lib/gray_getstringsize.c
new file mode 100644
index 0000000000..5b6d3e7c49
--- /dev/null
+++ b/apps/plugins/lib/gray_getstringsize.c
@@ -0,0 +1,64 @@
+/***************************************************************************
+* __________ __ ___.
+* Open \______ \ ____ ____ | | _\_ |__ _______ ___
+* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+* \/ \/ \/ \/ \/
+* $Id$
+*
+* Grayscale framework
+* gray_getstringsize() function
+*
+* This is a generic framework to use grayscale display within Rockbox
+* plugins. It obviously does not work for the player.
+*
+* Copyright (C) 2004 Jens Arnold
+*
+* All files in this archive are subject to the GNU General Public License.
+* See the file COPYING in the source tree root for full license agreement.
+*
+* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+* KIND, either express or implied.
+*
+****************************************************************************/
+
+#ifndef SIMULATOR /* not for simulator by now */
+#include "plugin.h"
+
+#ifdef HAVE_LCD_BITMAP /* and also not for the Player */
+#include "gray.h"
+
+/*---------------------------------------------------------------------------
+ Calculate width and height of the given text in pixels when rendered with
+ the currently selected font.
+ ----------------------------------------------------------------------------
+ This works exactly the same way as the core lcd_getstringsize(), only that
+ it uses the selected font for grayscale.
+ */
+int gray_getstringsize(const unsigned char *str, int *w, int *h)
+{
+ int ch;
+ int width = 0;
+ struct font *pf = _graybuf->curfont;
+
+ while ((ch = *str++))
+ {
+ /* check input range */
+ if (ch < pf->firstchar || ch >= pf->firstchar + pf->size)
+ ch = pf->defaultchar;
+ ch -= pf->firstchar;
+
+ /* get proportional width */
+ width += pf->width ? pf->width[ch] : pf->maxwidth;
+ }
+ if (w)
+ *w = width;
+ if (h)
+ *h = pf->height;
+ return width;
+}
+
+#endif // #ifdef HAVE_LCD_BITMAP
+#endif // #ifndef SIMULATOR
+
diff --git a/apps/plugins/lib/gray_horline.c b/apps/plugins/lib/gray_horline.c
new file mode 100644
index 0000000000..c5ad0046de
--- /dev/null
+++ b/apps/plugins/lib/gray_horline.c
@@ -0,0 +1,65 @@
+/***************************************************************************
+* __________ __ ___.
+* Open \______ \ ____ ____ | | _\_ |__ _______ ___
+* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+* \/ \/ \/ \/ \/
+* $Id$
+*
+* Grayscale framework
+* gray_horline() function
+*
+* This is a generic framework to use grayscale display within Rockbox
+* plugins. It obviously does not work for the player.
+*
+* Copyright (C) 2004 Jens Arnold
+*
+* All files in this archive are subject to the GNU General Public License.
+* See the file COPYING in the source tree root for full license agreement.
+*
+* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+* KIND, either express or implied.
+*
+****************************************************************************/
+
+#ifndef SIMULATOR /* not for simulator by now */
+#include "plugin.h"
+
+#ifdef HAVE_LCD_BITMAP /* and also not for the Player */
+#include "gray.h"
+
+/*---------------------------------------------------------------------------
+ Draw a horizontal line from (x1, y) to (x2, y) with the current drawinfo
+ ----------------------------------------------------------------------------
+ See gray_drawpixel() for details
+ */
+void gray_horline(int x1, int x2, int y)
+{
+ int x;
+ unsigned long pattern;
+ void (*pixelfunc)(int x, int y, unsigned long pattern);
+
+ if ((unsigned) x1 >= (unsigned) _graybuf->width
+ || (unsigned) x2 >= (unsigned) _graybuf->width
+ || (unsigned) y >= (unsigned) _graybuf->height)
+ return;
+
+ if (x1 > x2)
+ {
+ x = x1;
+ x1 = x2;
+ x2 = x;
+ }
+ pixelfunc = _gray_pixelfuncs[_graybuf->drawmode];
+ pattern = (_graybuf->drawmode == GRAY_DRAW_BG) ?
+ _graybuf->bg_pattern : _graybuf->fg_pattern;
+
+ for (x = x1; x <= x2; x++)
+ pixelfunc(x, y, pattern);
+
+}
+
+#endif // #ifdef HAVE_LCD_BITMAP
+#endif // #ifndef SIMULATOR
+
diff --git a/apps/plugins/lib/gray_pixelfuncs.c b/apps/plugins/lib/gray_pixelfuncs.c
new file mode 100644
index 0000000000..31ce8deb3c
--- /dev/null
+++ b/apps/plugins/lib/gray_pixelfuncs.c
@@ -0,0 +1,245 @@
+/***************************************************************************
+* __________ __ ___.
+* Open \______ \ ____ ____ | | _\_ |__ _______ ___
+* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+* \/ \/ \/ \/ \/
+* $Id$
+*
+* Grayscale framework
+* Low level pixel drawing functions
+*
+* This is a generic framework to use grayscale display within Rockbox
+* plugins. It obviously does not work for the player.
+*
+* Copyright (C) 2004 Jens Arnold
+*
+* All files in this archive are subject to the GNU General Public License.
+* See the file COPYING in the source tree root for full license agreement.
+*
+* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+* KIND, either express or implied.
+*
+****************************************************************************/
+
+#ifndef SIMULATOR /* not for simulator by now */
+#include "plugin.h"
+
+#if CONFIG_LCD == LCD_SSD1815 /* only for Recorder/Ondio */
+#include "gray.h"
+
+/* Prototypes */
+static void _writepixel(int x, int y, unsigned long pattern);
+static void _invertpixel(int x, int y, unsigned long pattern);
+
+/* function pointer array */
+void (* const _gray_pixelfuncs[4])(int x, int y, unsigned long pattern) = {
+ _invertpixel, _writepixel, _writepixel, _writepixel
+};
+
+/* Set a pixel to a specific bit pattern (low level routine) */
+static void _writepixel(int x, int y, unsigned long pattern)
+{
+ register unsigned mask, random;
+ register unsigned char *address;
+
+ /* Some (pseudo-)random function must be used here to shift the bit
+ * pattern randomly, otherwise you would get flicker and/or moire.
+ * Since rand() is relatively slow, I've implemented a simple, but very
+ * fast pseudo-random generator based on linear congruency in assembler.
+ * It delivers max. 16 pseudo-random bits in each iteration. */
+
+ /* simple but fast pseudo-random generator */
+ asm (
+ "mov #75,r1 \n"
+ "mulu %1,r1 \n" /* multiply by 75 */
+ "sts macl,%1 \n" /* get result */
+ "add #74,%1 \n" /* add another 74 */
+ /* Since the lower bits are not very random: */
+ "swap.b %1,%0 \n" /* get bits 8..15 (need max. 5) */
+ "and %2,%0 \n" /* mask out unneeded bits */
+ : /* outputs */
+ /* %0 */ "=&r"(random),
+ /* %1, in & out */ "+r"(_gray_random_buffer)
+ : /* inputs */
+ /* %2 */ "r"(_graybuf->randmask)
+ : /* clobbers */
+ "r1", "macl"
+ );
+
+ /* precalculate mask and byte address in first bitplane */
+ asm (
+ "mov %3,%0 \n" /* take y as base for address offset */
+ "shlr2 %0 \n" /* shift right by 3 (= divide by 8) */
+ "shlr %0 \n"
+ "mulu %0,%2 \n" /* multiply with width */
+ "and #7,%3 \n" /* get lower 3 bits of y */
+ "sts macl,%0 \n" /* get mulu result */
+ "add %4,%0 \n" /* add base + x to get final address */
+
+ "mov %3,%1 \n" /* move lower 3 bits of y out of r0 */
+ "mova .wp_masktable,%3\n" /* get address of mask table in r0 */
+ "bra .wp_predone \n" /* skip the table */
+ "mov.b @(%3,%1),%1 \n" /* get entry from mask table */
+
+ ".align 2 \n"
+ ".wp_masktable: \n" /* mask table */
+ ".byte 0x01 \n"
+ ".byte 0x02 \n"
+ ".byte 0x04 \n"
+ ".byte 0x08 \n"
+ ".byte 0x10 \n"
+ ".byte 0x20 \n"
+ ".byte 0x40 \n"
+ ".byte 0x80 \n"
+
+ ".wp_predone: \n"
+ : /* outputs */
+ /* %0 */ "=&r"(address),
+ /* %1 */ "=&r"(mask)
+ : /* inputs */
+ /* %2 */ "r"(_graybuf->width),
+ /* %3 = r0 */ "z"(y),
+ /* %4 */ "r"(_graybuf->data + x)
+ : /* clobbers */
+ "macl"
+ );
+
+ /* the hard part: set bits in all bitplanes according to pattern */
+ asm volatile (
+ "cmp/hs %1,%5 \n" /* random >= depth ? */
+ "bf .wp_ntrim \n"
+ "sub %1,%5 \n" /* yes: random -= depth */
+ /* it's sufficient to do this once, since the mask guarantees
+ * random < 2 * depth */
+ ".wp_ntrim: \n"
+
+ /* calculate some addresses */
+ "mulu %4,%1 \n" /* end address offset */
+ "not %3,r1 \n" /* get inverse mask (for "and") */
+ "sts macl,%1 \n" /* result of mulu */
+ "mulu %4,%5 \n" /* address offset of <random>'th plane */
+ "add %2,%1 \n" /* end offset -> end address */
+ "sts macl,%5 \n" /* result of mulu */
+ "add %2,%5 \n" /* address of <random>'th plane */
+ "bra .wp_start1 \n"
+ "mov %5,r2 \n" /* copy address */
+
+ /* first loop: set bits from <random>'th bitplane to last */
+ ".wp_loop1: \n"
+ "mov.b @r2,r3 \n" /* get data byte */
+ "shlr %0 \n" /* shift bit mask, sets t bit */
+ "and r1,r3 \n" /* reset bit (-> "white") */
+ "bf .wp_white1 \n" /* t=0? -> "white" bit */
+ "or %3,r3 \n" /* set bit ("black" bit) */
+ ".wp_white1: \n"
+ "mov.b r3,@r2 \n" /* store data byte */
+ "add %4,r2 \n" /* advance address to next bitplane */
+ ".wp_start1: \n"
+ "cmp/hi r2,%1 \n" /* address < end address ? */
+ "bt .wp_loop1 \n"
+
+ "bra .wp_start2 \n"
+ "nop \n"
+
+ /* second loop: set bits from first to <random-1>'th bitplane
+ * Bit setting works the other way round here to equalize average
+ * execution times for bright and dark pixels */
+ ".wp_loop2: \n"
+ "mov.b @%2,r3 \n" /* get data byte */
+ "shlr %0 \n" /* shift bit mask, sets t bit */
+ "or %3,r3 \n" /* set bit (-> "black") */
+ "bt .wp_black2 \n" /* t=1? -> "black" bit */
+ "and r1,r3 \n" /* reset bit ("white" bit) */
+ ".wp_black2: \n"
+ "mov.b r3,@%2 \n" /* store data byte */
+ "add %4,%2 \n" /* advance address to next bitplane */
+ ".wp_start2: \n"
+ "cmp/hi %2,%5 \n" /* address < <random>'th address ? */
+ "bt .wp_loop2 \n"
+ : /* outputs */
+ : /* inputs */
+ /* %0 */ "r"(pattern),
+ /* %1 */ "r"(_graybuf->depth),
+ /* %2 */ "r"(address),
+ /* %3 */ "r"(mask),
+ /* %4 */ "r"(_graybuf->plane_size),
+ /* %5 */ "r"(random)
+ : /* clobbers */
+ "r1", "r2", "r3", "macl"
+ );
+}
+
+/* invert all bits for one pixel (low level routine) */
+static void _invertpixel(int x, int y, unsigned long pattern)
+{
+ register unsigned mask;
+ register unsigned char *address;
+
+ (void) pattern; /* not used for invert */
+
+ /* precalculate mask and byte address in first bitplane */
+ asm (
+ "mov %3,%0 \n" /* take y as base for address offset */
+ "shlr2 %0 \n" /* shift right by 3 (= divide by 8) */
+ "shlr %0 \n"
+ "mulu %0,%2 \n" /* multiply with width */
+ "and #7,%3 \n" /* get lower 3 bits of y */
+ "sts macl,%0 \n" /* get mulu result */
+ "add %4,%0 \n" /* add base + x to get final address */
+
+ "mov %3,%1 \n" /* move lower 3 bits of y out of r0 */
+ "mova .ip_masktable,%3\n" /* get address of mask table in r0 */
+ "bra .ip_predone \n" /* skip the table */
+ "mov.b @(%3,%1),%1 \n" /* get entry from mask table */
+
+ ".align 2 \n"
+ ".ip_masktable: \n" /* mask table */
+ ".byte 0x01 \n"
+ ".byte 0x02 \n"
+ ".byte 0x04 \n"
+ ".byte 0x08 \n"
+ ".byte 0x10 \n"
+ ".byte 0x20 \n"
+ ".byte 0x40 \n"
+ ".byte 0x80 \n"
+
+ ".ip_predone: \n"
+ : /* outputs */
+ /* %0 */ "=&r"(address),
+ /* %1 */ "=&r"(mask)
+ : /* inputs */
+ /* %2 */ "r"(_graybuf->width),
+ /* %3 = r0 */ "z"(y),
+ /* %4 */ "r"(_graybuf->data + x)
+ : /* clobbers */
+ "macl"
+ );
+
+ /* invert bits in all bitplanes */
+ asm volatile (
+ "mov #0,r1 \n" /* current_plane = 0 */
+
+ ".ip_loop: \n"
+ "mov.b @%1,r2 \n" /* get data byte */
+ "add #1,r1 \n" /* current_plane++; */
+ "xor %2,r2 \n" /* invert bits */
+ "mov.b r2,@%1 \n" /* store data byte */
+ "add %3,%1 \n" /* advance address to next bitplane */
+ "cmp/hi r1,%0 \n" /* current_plane < depth ? */
+ "bt .ip_loop \n"
+ : /* outputs */
+ : /* inputs */
+ /* %0 */ "r"(_graybuf->depth),
+ /* %1 */ "r"(address),
+ /* %2 */ "r"(mask),
+ /* %3 */ "r"(_graybuf->plane_size)
+ : /* clobbers */
+ "r1", "r2"
+ );
+}
+
+#endif // #ifdef HAVE_LCD_BITMAP
+#endif // #ifndef SIMULATOR
+
diff --git a/apps/plugins/lib/gray_position_display.c b/apps/plugins/lib/gray_position_display.c
new file mode 100644
index 0000000000..4ec13ee730
--- /dev/null
+++ b/apps/plugins/lib/gray_position_display.c
@@ -0,0 +1,57 @@
+/***************************************************************************
+* __________ __ ___.
+* Open \______ \ ____ ____ | | _\_ |__ _______ ___
+* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+* \/ \/ \/ \/ \/
+* $Id$
+*
+* Grayscale framework
+* gray_position_display() function
+*
+* This is a generic framework to use grayscale display within Rockbox
+* plugins. It obviously does not work for the player.
+*
+* Copyright (C) 2004 Jens Arnold
+*
+* All files in this archive are subject to the GNU General Public License.
+* See the file COPYING in the source tree root for full license agreement.
+*
+* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+* KIND, either express or implied.
+*
+****************************************************************************/
+
+#ifndef SIMULATOR /* not for simulator by now */
+#include "plugin.h"
+
+#ifdef HAVE_LCD_BITMAP /* and also not for the Player */
+#include "gray.h"
+
+/*---------------------------------------------------------------------------
+ Set position of the top left corner of the grayscale overlay
+ ----------------------------------------------------------------------------
+ x = left margin in pixels
+ by = top margin in 8-pixel units
+
+ You may set this in a way that the overlay spills across the right or
+ bottom display border. In this case it will simply be clipped by the
+ LCD controller. You can even set negative values, this will clip at the
+ left or top border. I did not test it, but the limits may be +127 / -128
+
+ If you use this while the grayscale overlay is running, the now-freed area
+ will be restored.
+ */
+void gray_position_display(int x, int by)
+{
+ _graybuf->x = x;
+ _graybuf->by = by;
+
+ if (_graybuf->flags & _GRAY_RUNNING)
+ _graybuf->flags |= _GRAY_DEFERRED_UPDATE;
+}
+
+#endif // #ifdef HAVE_LCD_BITMAP
+#endif // #ifndef SIMULATOR
+
diff --git a/apps/plugins/lib/gray_putsxy.c b/apps/plugins/lib/gray_putsxy.c
new file mode 100644
index 0000000000..9b34ad7a65
--- /dev/null
+++ b/apps/plugins/lib/gray_putsxy.c
@@ -0,0 +1,67 @@
+/***************************************************************************
+* __________ __ ___.
+* Open \______ \ ____ ____ | | _\_ |__ _______ ___
+* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+* \/ \/ \/ \/ \/
+* $Id$
+*
+* Grayscale framework
+* gray_putsxy() function
+*
+* This is a generic framework to use grayscale display within Rockbox
+* plugins. It obviously does not work for the player.
+*
+* Copyright (C) 2004 Jens Arnold
+*
+* All files in this archive are subject to the GNU General Public License.
+* See the file COPYING in the source tree root for full license agreement.
+*
+* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+* KIND, either express or implied.
+*
+****************************************************************************/
+
+#ifndef SIMULATOR /* not for simulator by now */
+#include "plugin.h"
+
+#ifdef HAVE_LCD_BITMAP /* and also not for the Player */
+#include "gray.h"
+
+/*---------------------------------------------------------------------------
+ Display text starting at (x, y) with the current font and drawinfo
+ ----------------------------------------------------------------------------
+ The drawmode is used as described for gray_set_drawmode()
+ */
+void gray_putsxy(int x, int y, const unsigned char *str)
+{
+ int ch, width;
+ const unsigned char *bits;
+ struct font *pf = _graybuf->curfont;
+
+ if ((unsigned) x >= (unsigned) _graybuf->width
+ || (unsigned) y >= (unsigned) _graybuf->height)
+ return;
+
+ while ((ch = *str++) != '\0' && x < _graybuf->width)
+ {
+ /* check input range */
+ if (ch < pf->firstchar || ch >= pf->firstchar + pf->size)
+ ch = pf->defaultchar;
+ ch -= pf->firstchar;
+
+ /* get proportional width and glyph bits */
+ width = pf->width ? pf->width[ch] : pf->maxwidth;
+ bits = pf->bits + (pf->offset ? pf->offset[ch] :
+ MULU16((pf->height + 7) / 8, MULU16(pf->maxwidth, ch)));
+
+ gray_drawbitmap((const unsigned char*) bits, x, y, width, pf->height,
+ width);
+ x += width;
+ }
+}
+
+#endif // #ifdef HAVE_LCD_BITMAP
+#endif // #ifndef SIMULATOR
+
diff --git a/apps/plugins/lib/gray_screendump.c b/apps/plugins/lib/gray_screendump.c
new file mode 100644
index 0000000000..fdc88b8547
--- /dev/null
+++ b/apps/plugins/lib/gray_screendump.c
@@ -0,0 +1,141 @@
+/***************************************************************************
+* __________ __ ___.
+* Open \______ \ ____ ____ | | _\_ |__ _______ ___
+* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+* \/ \/ \/ \/ \/
+* $Id$
+*
+* Grayscale framework
+* gray_screendump() function
+*
+* This is a generic framework to use grayscale display within Rockbox
+* plugins. It obviously does not work for the player.
+*
+* Copyright (C) 2004 Jens Arnold
+*
+* All files in this archive are subject to the GNU General Public License.
+* See the file COPYING in the source tree root for full license agreement.
+*
+* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+* KIND, either express or implied.
+*
+****************************************************************************/
+
+#ifndef SIMULATOR /* not for simulator by now */
+#include "plugin.h"
+
+#ifdef HAVE_LCD_BITMAP /* and also not for the Player */
+#include "gray.h"
+
+static const unsigned char bmpheader[] =
+{
+ 0x42, 0x4d, 0xba, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xba, 0x00,
+ 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x40, 0x00,
+ 0x00, 0x00, 0x01, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c,
+ 0x00, 0x00, 0xc4, 0x0e, 0x00, 0x00, 0xc4, 0x0e, 0x00, 0x00, 0x21, 0x00,
+ 0x00, 0x00, 0x21, 0x00, 0x00, 0x00
+};
+
+static unsigned char linebuf[LCD_WIDTH];
+
+/*---------------------------------------------------------------------------
+ Save the current display content (b&w and grayscale overlay) to an 8-bit
+ BMP file in the root directory
+ ----------------------------------------------------------------------------
+ *
+ * This one is rather slow if used with larger bit depths, but it's intended
+ * primary use is for documenting the grayscale plugins. A much faster version
+ * would be possible, but would take more than twice the RAM
+ */
+void gray_screendump(void)
+{
+ int fh, i, bright;
+ int x, y, by, mask;
+ int gx, gby;
+
+ char filename[MAX_PATH];
+ struct tm *tm = _gray_rb->get_time();
+
+ unsigned char *lcdptr, *grayptr, *grayptr2;
+
+ _gray_rb->snprintf(filename, MAX_PATH,
+ "/graydump %04d-%02d-%02d %02d-%02d-%02d.bmp",
+ tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
+ tm->tm_hour, tm->tm_min, tm->tm_sec);
+ fh = _gray_rb->creat(filename, O_WRONLY);
+
+ if (fh < 0)
+ return;
+
+ _gray_rb->write(fh, bmpheader, sizeof(bmpheader)); /* write header */
+
+ /* build clut, always 33 entries */
+
+ linebuf[3] = 0;
+
+ for (i = 0; i < 33; i++)
+ {
+ bright = MIN(i, _graybuf->depth);
+ linebuf[0] = linebuf[2] = MULU16(0x90, bright) / _graybuf->depth;
+ linebuf[1] = MULU16(0xee, bright) / _graybuf->depth;
+ _gray_rb->write(fh, linebuf, 4);
+ }
+
+ /* 8-bit BMP image goes bottom -> top */
+
+ for (y = LCD_HEIGHT - 1; y >= 0; y--)
+ {
+ _gray_rb->memset(linebuf, 32, sizeof(linebuf)); /* max. brightness */
+
+ mask = 1 << (y & 7);
+ by = y / 8;
+ lcdptr = _gray_rb->lcd_framebuffer + MULU16(LCD_WIDTH, by);
+ gby = by - _graybuf->by;
+
+ if ((_graybuf->flags & _GRAY_RUNNING)
+ && (unsigned) gby < (unsigned) _graybuf->bheight)
+ {
+ /* line contains grayscale (and maybe b&w) graphics */
+ grayptr = _graybuf->data + MULU16(_graybuf->width, gby);
+
+ for (x = 0; x < LCD_WIDTH; x++)
+ {
+ if (*lcdptr++ & mask)
+ linebuf[x] = 0;
+
+ gx = x - _graybuf->x;
+
+ if ((unsigned) gx < (unsigned) _graybuf->width)
+ {
+ bright = 0;
+ grayptr2 = grayptr + gx;
+
+ for (i = 0; i < _graybuf->depth; i++)
+ {
+ if (!(*grayptr2 & mask))
+ bright++;
+ grayptr2 += _graybuf->plane_size;
+ }
+ linebuf[x] = bright;
+ }
+ }
+ }
+ else
+ {
+ /* line contains only b&w graphics */
+ for (x = 0; x < LCD_WIDTH; x++)
+ if (*lcdptr++ & mask)
+ linebuf[x] = 0;
+ }
+
+ _gray_rb->write(fh, linebuf, sizeof(linebuf));
+ }
+
+ _gray_rb->close(fh);
+}
+
+#endif // #ifdef HAVE_LCD_BITMAP
+#endif // #ifndef SIMULATOR
+
diff --git a/apps/plugins/lib/gray_scroll_down.c b/apps/plugins/lib/gray_scroll_down.c
new file mode 100644
index 0000000000..1fb1de8335
--- /dev/null
+++ b/apps/plugins/lib/gray_scroll_down.c
@@ -0,0 +1,134 @@
+/***************************************************************************
+* __________ __ ___.
+* Open \______ \ ____ ____ | | _\_ |__ _______ ___
+* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+* \/ \/ \/ \/ \/
+* $Id$
+*
+* Grayscale framework
+* gray_scroll_down() function
+*
+* This is a generic framework to use grayscale display within Rockbox
+* plugins. It obviously does not work for the player.
+*
+* Copyright (C) 2004 Jens Arnold
+*
+* All files in this archive are subject to the GNU General Public License.
+* See the file COPYING in the source tree root for full license agreement.
+*
+* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+* KIND, either express or implied.
+*
+****************************************************************************/
+
+#ifndef SIMULATOR /* not for simulator by now */
+#include "plugin.h"
+
+#if CONFIG_LCD == LCD_SSD1815 /* only for Recorder/Ondio */
+#include "gray.h"
+
+/*---------------------------------------------------------------------------
+ Scroll the whole grayscale buffer down by <count> pixels (<= 7)
+ ----------------------------------------------------------------------------
+ black_border determines if the pixels scrolled in at the top are black
+ or white
+
+ Scrolling up/down pixel-wise is significantly slower than scrolling
+ left/right or scrolling up/down byte-wise because it involves bit
+ shifting. That's why it is asm optimized.
+ */
+void gray_scroll_down(int count, bool black_border)
+{
+ unsigned filler;
+
+ if ((unsigned) count > 7)
+ return;
+
+ filler = black_border ? (0xFFu << count) : 0;
+
+ /* scroll column by column to minimize flicker */
+ asm volatile (
+ "mov #0,r6 \n" /* x = 0 */
+ "mova .sd_shifttbl,r0 \n" /* calculate jump destination for */
+ "mov.b @(r0,%6),%6 \n" /* shift amount from table */
+ "bra .sd_cloop \n" /* skip table */
+ "add r0,%6 \n"
+
+ ".align 2 \n"
+ ".sd_shifttbl: \n" /* shift jump offset table */
+ ".byte .sd_shift0 - .sd_shifttbl \n"
+ ".byte .sd_shift1 - .sd_shifttbl \n"
+ ".byte .sd_shift2 - .sd_shifttbl \n"
+ ".byte .sd_shift3 - .sd_shifttbl \n"
+ ".byte .sd_shift4 - .sd_shifttbl \n"
+ ".byte .sd_shift5 - .sd_shifttbl \n"
+ ".byte .sd_shift6 - .sd_shifttbl \n"
+ ".byte .sd_shift7 - .sd_shifttbl \n"
+
+ ".sd_cloop: \n" /* repeat for every column */
+ "mov %1,r2 \n" /* get start address */
+ "mov #0,r3 \n" /* current_plane = 0 */
+
+ ".sd_oloop: \n" /* repeat for every bitplane */
+ "mov r2,r4 \n" /* get start address */
+ "mov #0,r5 \n" /* current_row = 0 */
+ "mov %5,r1 \n" /* get filler bits */
+
+ ".sd_iloop: \n" /* repeat for all rows */
+ "shlr8 r1 \n" /* shift right to get residue */
+ "mov.b @r4,r0 \n" /* get data byte */
+ "jmp @%6 \n" /* jump into shift "path" */
+ "extu.b r0,r0 \n" /* extend unsigned */
+
+ ".sd_shift6: \n" /* shift left by 0..7 bits */
+ "shll2 r0 \n"
+ ".sd_shift4: \n"
+ "shll2 r0 \n"
+ ".sd_shift2: \n"
+ "bra .sd_shift0 \n"
+ "shll2 r0 \n"
+ ".sd_shift7: \n"
+ "shll2 r0 \n"
+ ".sd_shift5: \n"
+ "shll2 r0 \n"
+ ".sd_shift3: \n"
+ "shll2 r0 \n"
+ ".sd_shift1: \n"
+ "shll r0 \n"
+ ".sd_shift0: \n"
+
+ "or r0,r1 \n" /* combine with last residue */
+ "mov.b r1,@r4 \n" /* store data */
+ "add %2,r4 \n" /* address += width */
+ "add #1,r5 \n" /* current_row++ */
+ "cmp/hi r5,%3 \n" /* current_row < bheight ? */
+ "bt .sd_iloop \n"
+
+ "add %4,r2 \n" /* start_address += plane_size */
+ "add #1,r3 \n" /* current_plane++ */
+ "cmp/hi r3,%0 \n" /* current_plane < depth ? */
+ "bt .sd_oloop \n"
+
+ "add #1,%1 \n" /* start_address++ */
+ "add #1,r6 \n" /* x++ */
+ "cmp/hi r6,%2 \n" /* x < width ? */
+ "bt .sd_cloop \n"
+ : /* outputs */
+ : /* inputs */
+ /* %0 */ "r"(_graybuf->depth),
+ /* %1 */ "r"(_graybuf->data),
+ /* %2 */ "r"(_graybuf->width),
+ /* %3 */ "r"(_graybuf->bheight),
+ /* %4 */ "r"(_graybuf->plane_size),
+ /* %5 */ "r"(filler),
+ /* %6 */ "r"(count)
+ : /* clobbers */
+ "r0", "r1", "r2", "r3", "r4", "r5", "r6"
+ );
+}
+
+#endif // #ifdef HAVE_LCD_BITMAP
+#endif // #ifndef SIMULATOR
+
diff --git a/apps/plugins/lib/gray_scroll_down8.c b/apps/plugins/lib/gray_scroll_down8.c
new file mode 100644
index 0000000000..db716baee7
--- /dev/null
+++ b/apps/plugins/lib/gray_scroll_down8.c
@@ -0,0 +1,69 @@
+/***************************************************************************
+* __________ __ ___.
+* Open \______ \ ____ ____ | | _\_ |__ _______ ___
+* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+* \/ \/ \/ \/ \/
+* $Id$
+*
+* Grayscale framework
+* gray_scroll_down8() function
+*
+* This is a generic framework to use grayscale display within Rockbox
+* plugins. It obviously does not work for the player.
+*
+* Copyright (C) 2004 Jens Arnold
+*
+* All files in this archive are subject to the GNU General Public License.
+* See the file COPYING in the source tree root for full license agreement.
+*
+* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+* KIND, either express or implied.
+*
+****************************************************************************/
+
+#ifndef SIMULATOR /* not for simulator by now */
+#include "plugin.h"
+
+#ifdef HAVE_LCD_BITMAP /* and also not for the Player */
+#include "gray.h"
+
+/*---------------------------------------------------------------------------
+ Scroll the whole grayscale buffer down by 8 pixels
+ ----------------------------------------------------------------------------
+ black_border determines if the pixels scrolled in at the top are black
+ or white
+
+ Scrolling up/down by 8 pixels is very fast.
+ */
+void gray_scroll_down8(bool black_border)
+{
+ int by, d;
+ unsigned filler;
+ unsigned char *ptr;
+
+ filler = black_border ? 0xFF : 0;
+
+ /* Scroll row by row to minimize flicker (byte rows = 8 pixels each) */
+ for (by = _graybuf->bheight - 1; by > 0; by--)
+ {
+ ptr = _graybuf->data + MULU16(_graybuf->width, by);
+ for (d = 0; d < _graybuf->depth; d++)
+ {
+ _gray_rb->memcpy(ptr, ptr - _graybuf->width, _graybuf->width);
+ ptr += _graybuf->plane_size;
+ }
+ }
+ /* fill first row */
+ ptr = _graybuf->data;
+ for (d = 0; d < _graybuf->depth; d++)
+ {
+ _gray_rb->memset(ptr, filler, _graybuf->width);
+ ptr += _graybuf->plane_size;
+ }
+}
+
+#endif // #ifdef HAVE_LCD_BITMAP
+#endif // #ifndef SIMULATOR
+
diff --git a/apps/plugins/lib/gray_scroll_left.c b/apps/plugins/lib/gray_scroll_left.c
new file mode 100644
index 0000000000..5fb9a441c1
--- /dev/null
+++ b/apps/plugins/lib/gray_scroll_left.c
@@ -0,0 +1,100 @@
+/***************************************************************************
+* __________ __ ___.
+* Open \______ \ ____ ____ | | _\_ |__ _______ ___
+* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+* \/ \/ \/ \/ \/
+* $Id$
+*
+* Grayscale framework
+* gray_scroll_left() function
+*
+* This is a generic framework to use grayscale display within Rockbox
+* plugins. It obviously does not work for the player.
+*
+* Copyright (C) 2004 Jens Arnold
+*
+* All files in this archive are subject to the GNU General Public License.
+* See the file COPYING in the source tree root for full license agreement.
+*
+* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+* KIND, either express or implied.
+*
+****************************************************************************/
+
+#ifndef SIMULATOR /* not for simulator by now */
+#include "plugin.h"
+
+#if CONFIG_LCD == LCD_SSD1815 /* only for Recorder/Ondio */
+#include "gray.h"
+
+/*---------------------------------------------------------------------------
+ Scroll the whole grayscale buffer left by <count> pixels
+ ----------------------------------------------------------------------------
+ black_border determines if the pixels scrolled in at the right are black
+ or white
+
+ Scrolling left/right by an even pixel count is almost twice as fast as
+ scrolling by an odd pixel count.
+ */
+void gray_scroll_left(int count, bool black_border)
+{
+ int by, d;
+ unsigned filler;
+ unsigned char *ptr;
+
+ if ((unsigned) count >= (unsigned) _graybuf->width)
+ return;
+
+ filler = black_border ? 0xFF : 0;
+
+ /* Scroll row by row to minimize flicker (byte rows = 8 pixels each) */
+ for (by = 0; by < _graybuf->bheight; by++)
+ {
+ ptr = _graybuf->data + MULU16(_graybuf->width, by);
+ for (d = 0; d < _graybuf->depth; d++)
+ {
+ asm volatile (
+ "mov %0,r1 \n" /* check if both source... */
+ "or %2,r1 \n" /* ...and offset are even */
+ "shlr r1 \n" /* -> lsb = 0 */
+ "bf .sl_start2 \n" /* -> copy word-wise */
+
+ "add #-1,%2 \n" /* copy byte-wise */
+ ".sl_loop1: \n"
+ "mov.b @%0+,r1 \n"
+ "mov.b r1,@(%2,%0) \n"
+ "cmp/hi %0,%1 \n"
+ "bt .sl_loop1 \n"
+
+ "bra .sl_end \n"
+ "nop \n"
+
+ ".sl_start2: \n" /* copy word-wise */
+ "add #-2,%2 \n"
+ ".sl_loop2: \n"
+ "mov.w @%0+,r1 \n"
+ "mov.w r1,@(%2,%0) \n"
+ "cmp/hi %0,%1 \n"
+ "bt .sl_loop2 \n"
+
+ ".sl_end: \n"
+ : /* outputs */
+ : /* inputs */
+ /* %0 */ "r"(ptr + count),
+ /* %1 */ "r"(ptr + _graybuf->width),
+ /* %2 */ "z"(-count)
+ : /* clobbers */
+ "r1"
+ );
+
+ _gray_rb->memset(ptr + _graybuf->width - count, filler, count);
+ ptr += _graybuf->plane_size;
+ }
+ }
+}
+
+#endif // #ifdef HAVE_LCD_BITMAP
+#endif // #ifndef SIMULATOR
+
diff --git a/apps/plugins/lib/gray_scroll_right.c b/apps/plugins/lib/gray_scroll_right.c
new file mode 100644
index 0000000000..f944319d91
--- /dev/null
+++ b/apps/plugins/lib/gray_scroll_right.c
@@ -0,0 +1,100 @@
+/***************************************************************************
+* __________ __ ___.
+* Open \______ \ ____ ____ | | _\_ |__ _______ ___
+* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+* \/ \/ \/ \/ \/
+* $Id$
+*
+* Grayscale framework
+* gray_scroll_right() function
+*
+* This is a generic framework to use grayscale display within Rockbox
+* plugins. It obviously does not work for the player.
+*
+* Copyright (C) 2004 Jens Arnold
+*
+* All files in this archive are subject to the GNU General Public License.
+* See the file COPYING in the source tree root for full license agreement.
+*
+* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+* KIND, either express or implied.
+*
+****************************************************************************/
+
+#ifndef SIMULATOR /* not for simulator by now */
+#include "plugin.h"
+
+#if CONFIG_LCD == LCD_SSD1815 /* only for Recorder/Ondio */
+#include "gray.h"
+
+/*---------------------------------------------------------------------------
+ Scroll the whole grayscale buffer right by <count> pixels
+ ----------------------------------------------------------------------------
+ black_border determines if the pixels scrolled in at the left are black
+ or white
+
+ Scrolling left/right by an even pixel count is almost twice as fast as
+ scrolling by an odd pixel count.
+ */
+void gray_scroll_right(int count, bool black_border)
+{
+ int by, d;
+ unsigned filler;
+ unsigned char *ptr;
+
+ if ((unsigned) count >= (unsigned) _graybuf->width)
+ return;
+
+ filler = black_border ? 0xFF : 0;
+
+ /* Scroll row by row to minimize flicker (byte rows = 8 pixels each) */
+ for (by = 0; by < _graybuf->bheight; by++)
+ {
+ ptr = _graybuf->data + MULU16(_graybuf->width, by);
+ for (d = 0; d < _graybuf->depth; d++)
+ {
+ asm volatile (
+ "mov %0,r1 \n" /* check if both source... */
+ "or %2,r1 \n" /* ...and offset are even */
+ "shlr r1 \n" /* -> lsb = 0 */
+ "bf .sr_start2 \n" /* -> copy word-wise */
+
+ "add #-1,%2 \n" /* copy byte-wise */
+ ".sr_loop1: \n"
+ "mov.b @(%2,%0),r1 \n"
+ "mov.b r1,@-%0 \n"
+ "cmp/hi %1,%0 \n"
+ "bt .sr_loop1 \n"
+
+ "bra .sr_end \n"
+ "nop \n"
+
+ ".sr_start2: \n" /* copy word-wise */
+ "add #-2,%2 \n"
+ ".sr_loop2: \n"
+ "mov.w @(%2,%0),r1 \n"
+ "mov.w r1,@-%0 \n"
+ "cmp/hi %1,%0 \n"
+ "bt .sr_loop2 \n"
+
+ ".sr_end: \n"
+ : /* outputs */
+ : /* inputs */
+ /* %0 */ "r"(ptr + _graybuf->width),
+ /* %1 */ "r"(ptr + count),
+ /* %2 */ "z"(-count)
+ : /* clobbers */
+ "r1"
+ );
+
+ _gray_rb->memset(ptr, filler, count);
+ ptr += _graybuf->plane_size;
+ }
+ }
+}
+
+#endif // #ifdef HAVE_LCD_BITMAP
+#endif // #ifndef SIMULATOR
+
diff --git a/apps/plugins/lib/gray_scroll_up.c b/apps/plugins/lib/gray_scroll_up.c
new file mode 100644
index 0000000000..4c493071af
--- /dev/null
+++ b/apps/plugins/lib/gray_scroll_up.c
@@ -0,0 +1,135 @@
+/***************************************************************************
+* __________ __ ___.
+* Open \______ \ ____ ____ | | _\_ |__ _______ ___
+* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+* \/ \/ \/ \/ \/
+* $Id$
+*
+* Grayscale framework
+* gray_scroll_up() function
+*
+* This is a generic framework to use grayscale display within Rockbox
+* plugins. It obviously does not work for the player.
+*
+* Copyright (C) 2004 Jens Arnold
+*
+* All files in this archive are subject to the GNU General Public License.
+* See the file COPYING in the source tree root for full license agreement.
+*
+* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+* KIND, either express or implied.
+*
+****************************************************************************/
+
+#ifndef SIMULATOR /* not for simulator by now */
+#include "plugin.h"
+
+#if CONFIG_LCD == LCD_SSD1815 /* only for Recorder/Ondio */
+#include "gray.h"
+
+/*---------------------------------------------------------------------------
+ Scroll the whole grayscale buffer up by <count> pixels (<= 7)
+ ----------------------------------------------------------------------------
+ black_border determines if the pixels scrolled in at the bottom are black
+ or white
+
+ Scrolling up/down pixel-wise is significantly slower than scrolling
+ left/right or scrolling up/down byte-wise because it involves bit
+ shifting. That's why it is asm optimized.
+ */
+void gray_scroll_up(int count, bool black_border)
+{
+ unsigned filler;
+
+ if ((unsigned) count > 7)
+ return;
+
+ filler = black_border ? 0xFFu : 0;
+
+ /* scroll column by column to minimize flicker */
+ asm volatile (
+ "mov #0,r6 \n" /* x = 0 */
+ "mova .su_shifttbl,r0 \n" /* calculate jump destination for */
+ "mov.b @(r0,%6),%6 \n" /* shift amount from table */
+ "bra .su_cloop \n" /* skip table */
+ "add r0,%6 \n"
+
+ ".align 2 \n"
+ ".su_shifttbl: \n" /* shift jump offset table */
+ ".byte .su_shift0 - .su_shifttbl \n"
+ ".byte .su_shift1 - .su_shifttbl \n"
+ ".byte .su_shift2 - .su_shifttbl \n"
+ ".byte .su_shift3 - .su_shifttbl \n"
+ ".byte .su_shift4 - .su_shifttbl \n"
+ ".byte .su_shift5 - .su_shifttbl \n"
+ ".byte .su_shift6 - .su_shifttbl \n"
+ ".byte .su_shift7 - .su_shifttbl \n"
+
+ ".su_cloop: \n" /* repeat for every column */
+ "mov %1,r2 \n" /* get start address */
+ "mov #0,r3 \n" /* current_plane = 0 */
+
+ ".su_oloop: \n" /* repeat for every bitplane */
+ "mov r2,r4 \n" /* get start address */
+ "mov #0,r5 \n" /* current_row = 0 */
+ "mov %5,r1 \n" /* get filler bits */
+
+ ".su_iloop: \n" /* repeat for all rows */
+ "sub %2,r4 \n" /* address -= width */
+ "mov.b @r4,r0 \n" /* get data byte */
+ "shll8 r1 \n" /* old data to 2nd byte */
+ "extu.b r0,r0 \n" /* extend unsigned */
+ "or r1,r0 \n" /* combine old data */
+ "jmp @%6 \n" /* jump into shift "path" */
+ "extu.b r0,r1 \n" /* store data for next round */
+
+ ".su_shift6: \n" /* shift right by 0..7 bits */
+ "shlr2 r0 \n"
+ ".su_shift4: \n"
+ "shlr2 r0 \n"
+ ".su_shift2: \n"
+ "bra .su_shift0 \n"
+ "shlr2 r0 \n"
+ ".su_shift7: \n"
+ "shlr2 r0 \n"
+ ".su_shift5: \n"
+ "shlr2 r0 \n"
+ ".su_shift3: \n"
+ "shlr2 r0 \n"
+ ".su_shift1: \n"
+ "shlr r0 \n"
+ ".su_shift0: \n"
+
+ "mov.b r0,@r4 \n" /* store data */
+ "add #1,r5 \n" /* current_row++ */
+ "cmp/hi r5,%3 \n" /* current_row < bheight ? */
+ "bt .su_iloop \n"
+
+ "add %4,r2 \n" /* start_address += plane_size */
+ "add #1,r3 \n" /* current_plane++ */
+ "cmp/hi r3,%0 \n" /* current_plane < depth ? */
+ "bt .su_oloop \n"
+
+ "add #1,%1 \n" /* start_address++ */
+ "add #1,r6 \n" /* x++ */
+ "cmp/hi r6,%2 \n" /* x < width ? */
+ "bt .su_cloop \n"
+ : /* outputs */
+ : /* inputs */
+ /* %0 */ "r"(_graybuf->depth),
+ /* %1 */ "r"(_graybuf->data + _graybuf->plane_size),
+ /* %2 */ "r"(_graybuf->width),
+ /* %3 */ "r"(_graybuf->bheight),
+ /* %4 */ "r"(_graybuf->plane_size),
+ /* %5 */ "r"(filler),
+ /* %6 */ "r"(count)
+ : /* clobbers */
+ "r0", "r1", "r2", "r3", "r4", "r5", "r6"
+ );
+}
+
+#endif // #ifdef HAVE_LCD_BITMAP
+#endif // #ifndef SIMULATOR
+
diff --git a/apps/plugins/lib/gray_scroll_up8.c b/apps/plugins/lib/gray_scroll_up8.c
new file mode 100644
index 0000000000..b181673f22
--- /dev/null
+++ b/apps/plugins/lib/gray_scroll_up8.c
@@ -0,0 +1,69 @@
+/***************************************************************************
+* __________ __ ___.
+* Open \______ \ ____ ____ | | _\_ |__ _______ ___
+* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+* \/ \/ \/ \/ \/
+* $Id$
+*
+* Grayscale framework
+* gray_scroll_up8() function
+*
+* This is a generic framework to use grayscale display within Rockbox
+* plugins. It obviously does not work for the player.
+*
+* Copyright (C) 2004 Jens Arnold
+*
+* All files in this archive are subject to the GNU General Public License.
+* See the file COPYING in the source tree root for full license agreement.
+*
+* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+* KIND, either express or implied.
+*
+****************************************************************************/
+
+#ifndef SIMULATOR /* not for simulator by now */
+#include "plugin.h"
+
+#ifdef HAVE_LCD_BITMAP /* and also not for the Player */
+#include "gray.h"
+
+/*---------------------------------------------------------------------------
+ Scroll the whole grayscale buffer up by 8 pixels
+ ----------------------------------------------------------------------------
+ black_border determines if the pixels scrolled in at the bottom are black
+ or white
+
+ Scrolling up/down by 8 pixels is very fast.
+ */
+void gray_scroll_up8(bool black_border)
+{
+ int by, d;
+ unsigned filler;
+ unsigned char *ptr;
+
+ filler = black_border ? 0xFF : 0;
+
+ /* Scroll row by row to minimize flicker (byte rows = 8 pixels each) */
+ for (by = 1; by < _graybuf->bheight; by++)
+ {
+ ptr = _graybuf->data + MULU16(_graybuf->width, by);
+ for (d = 0; d < _graybuf->depth; d++)
+ {
+ _gray_rb->memcpy(ptr - _graybuf->width, ptr, _graybuf->width);
+ ptr += _graybuf->plane_size;
+ }
+ }
+ /* fill last row */
+ ptr = _graybuf->data + _graybuf->plane_size - _graybuf->width;
+ for (d = 0; d < _graybuf->depth; d++)
+ {
+ _gray_rb->memset(ptr, filler, _graybuf->width);
+ ptr += _graybuf->plane_size;
+ }
+}
+
+#endif // #ifdef HAVE_LCD_BITMAP
+#endif // #ifndef SIMULATOR
+
diff --git a/apps/plugins/lib/gray_set_background.c b/apps/plugins/lib/gray_set_background.c
new file mode 100644
index 0000000000..c78e9ff112
--- /dev/null
+++ b/apps/plugins/lib/gray_set_background.c
@@ -0,0 +1,48 @@
+/***************************************************************************
+* __________ __ ___.
+* Open \______ \ ____ ____ | | _\_ |__ _______ ___
+* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+* \/ \/ \/ \/ \/
+* $Id$
+*
+* Grayscale framework
+* gray_set_background() function
+*
+* This is a generic framework to use grayscale display within Rockbox
+* plugins. It obviously does not work for the player.
+*
+* Copyright (C) 2004 Jens Arnold
+*
+* All files in this archive are subject to the GNU General Public License.
+* See the file COPYING in the source tree root for full license agreement.
+*
+* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+* KIND, either express or implied.
+*
+****************************************************************************/
+
+#ifndef SIMULATOR /* not for simulator by now */
+#include "plugin.h"
+
+#ifdef HAVE_LCD_BITMAP /* and also not for the Player */
+#include "gray.h"
+
+/*---------------------------------------------------------------------------
+ Set the background shade for subsequent drawing operations
+ ----------------------------------------------------------------------------
+ brightness = 0 (black) .. 255 (white)
+
+ Default after initialization: 255
+ */
+void gray_set_background(int brightness)
+{
+ if ((unsigned) brightness <= 255)
+ _graybuf->bg_pattern = _graybuf->bitpattern[MULU16(brightness,
+ _graybuf->depth + 1) >> 8];
+}
+
+#endif // #ifdef HAVE_LCD_BITMAP
+#endif // #ifndef SIMULATOR
+
diff --git a/apps/plugins/lib/gray_set_drawinfo.c b/apps/plugins/lib/gray_set_drawinfo.c
new file mode 100644
index 0000000000..59928882d7
--- /dev/null
+++ b/apps/plugins/lib/gray_set_drawinfo.c
@@ -0,0 +1,49 @@
+/***************************************************************************
+* __________ __ ___.
+* Open \______ \ ____ ____ | | _\_ |__ _______ ___
+* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+* \/ \/ \/ \/ \/
+* $Id$
+*
+* Grayscale framework
+* gray_set_drawinfo() function
+*
+* This is a generic framework to use grayscale display within Rockbox
+* plugins. It obviously does not work for the player.
+*
+* Copyright (C) 2004 Jens Arnold
+*
+* All files in this archive are subject to the GNU General Public License.
+* See the file COPYING in the source tree root for full license agreement.
+*
+* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+* KIND, either express or implied.
+*
+****************************************************************************/
+
+#ifndef SIMULATOR /* not for simulator by now */
+#include "plugin.h"
+
+#ifdef HAVE_LCD_BITMAP /* and also not for the Player */
+#include "gray.h"
+
+/*---------------------------------------------------------------------------
+ Set draw mode, foreground and background shades at once
+ ----------------------------------------------------------------------------
+ If you hand it -1 (or in fact any other out-of-bounds value) for a
+ parameter, that particular setting won't be changed
+
+ Default after initialization: GRAY_DRAW_SOLID, 0, 255
+ */
+void gray_set_drawinfo(int drawmode, int fg_brightness, int bg_brightness)
+{
+ gray_set_drawmode(drawmode);
+ gray_set_foreground(fg_brightness);
+ gray_set_background(bg_brightness);
+}
+
+#endif // #ifdef HAVE_LCD_BITMAP
+#endif // #ifndef SIMULATOR
+
diff --git a/apps/plugins/lib/gray_set_drawmode.c b/apps/plugins/lib/gray_set_drawmode.c
new file mode 100644
index 0000000000..969b99894f
--- /dev/null
+++ b/apps/plugins/lib/gray_set_drawmode.c
@@ -0,0 +1,52 @@
+/***************************************************************************
+* __________ __ ___.
+* Open \______ \ ____ ____ | | _\_ |__ _______ ___
+* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+* \/ \/ \/ \/ \/
+* $Id$
+*
+* Grayscale framework
+* gray_set_drawmode() function
+*
+* This is a generic framework to use grayscale display within Rockbox
+* plugins. It obviously does not work for the player.
+*
+* Copyright (C) 2004 Jens Arnold
+*
+* All files in this archive are subject to the GNU General Public License.
+* See the file COPYING in the source tree root for full license agreement.
+*
+* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+* KIND, either express or implied.
+*
+****************************************************************************/
+
+#ifndef SIMULATOR /* not for simulator by now */
+#include "plugin.h"
+
+#ifdef HAVE_LCD_BITMAP /* and also not for the Player */
+#include "gray.h"
+
+/*---------------------------------------------------------------------------
+ Set the draw mode for subsequent drawing operations
+ ----------------------------------------------------------------------------
+ drawmode =
+ GRAY_DRAW_INVERSE: Foreground pixels are inverted, background pixels are
+ left untouched
+ GRAY_DRAW_FG: Only foreground pixels are drawn
+ GRAY_DRAW_BG: Only background pixels are drawn
+ GRAY_DRAW_SOLID: Foreground and background pixels are drawn
+
+ Default after initialization: GRAY_DRAW_SOLID
+ */
+void gray_set_drawmode(int drawmode)
+{
+ if ((unsigned) drawmode <= GRAY_DRAW_SOLID)
+ _graybuf->drawmode = drawmode;
+}
+
+#endif // #ifdef HAVE_LCD_BITMAP
+#endif // #ifndef SIMULATOR
+
diff --git a/apps/plugins/lib/gray_set_foreground.c b/apps/plugins/lib/gray_set_foreground.c
new file mode 100644
index 0000000000..afde64f645
--- /dev/null
+++ b/apps/plugins/lib/gray_set_foreground.c
@@ -0,0 +1,48 @@
+/***************************************************************************
+* __________ __ ___.
+* Open \______ \ ____ ____ | | _\_ |__ _______ ___
+* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+* \/ \/ \/ \/ \/
+* $Id$
+*
+* Grayscale framework
+* gray_set_foreground() function
+*
+* This is a generic framework to use grayscale display within Rockbox
+* plugins. It obviously does not work for the player.
+*
+* Copyright (C) 2004 Jens Arnold
+*
+* All files in this archive are subject to the GNU General Public License.
+* See the file COPYING in the source tree root for full license agreement.
+*
+* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+* KIND, either express or implied.
+*
+****************************************************************************/
+
+#ifndef SIMULATOR /* not for simulator by now */
+#include "plugin.h"
+
+#ifdef HAVE_LCD_BITMAP /* and also not for the Player */
+#include "gray.h"
+
+/*---------------------------------------------------------------------------
+ Set the foreground shade for subsequent drawing operations
+ ----------------------------------------------------------------------------
+ brightness = 0 (black) .. 255 (white)
+
+ Default after initialization: 0
+ */
+void gray_set_foreground(int brightness)
+{
+ if ((unsigned) brightness <= 255)
+ _graybuf->fg_pattern = _graybuf->bitpattern[MULU16(brightness,
+ _graybuf->depth + 1) >> 8];
+}
+
+#endif // #ifdef HAVE_LCD_BITMAP
+#endif // #ifndef SIMULATOR
+
diff --git a/apps/plugins/lib/gray_setfont.c b/apps/plugins/lib/gray_setfont.c
new file mode 100644
index 0000000000..714a1f5b17
--- /dev/null
+++ b/apps/plugins/lib/gray_setfont.c
@@ -0,0 +1,47 @@
+/***************************************************************************
+* __________ __ ___.
+* Open \______ \ ____ ____ | | _\_ |__ _______ ___
+* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+* \/ \/ \/ \/ \/
+* $Id$
+*
+* Grayscale framework
+*
+* This is a generic framework to use grayscale display within Rockbox
+* plugins. It obviously does not work for the player.
+*
+* Copyright (C) 2004 Jens Arnold
+* gray_setfont() function
+*
+* All files in this archive are subject to the GNU General Public License.
+* See the file COPYING in the source tree root for full license agreement.
+*
+* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+* KIND, either express or implied.
+*
+****************************************************************************/
+
+#ifndef SIMULATOR /* not for simulator by now */
+#include "plugin.h"
+
+#ifdef HAVE_LCD_BITMAP /* and also not for the Player */
+#include "gray.h"
+
+/*---------------------------------------------------------------------------
+ Set font for the font routines
+ ----------------------------------------------------------------------------
+ newfont can be FONT_SYSFIXED or FONT_UI the same way as with the Rockbox
+ core routines
+
+ Default after initialization: FONT_SYSFIXED
+ */
+void gray_setfont(int newfont)
+{
+ _graybuf->curfont = _gray_rb->font_get(newfont);
+}
+
+#endif // #ifdef HAVE_LCD_BITMAP
+#endif // #ifndef SIMULATOR
+
diff --git a/apps/plugins/lib/gray_verline.c b/apps/plugins/lib/gray_verline.c
new file mode 100644
index 0000000000..15910b41cf
--- /dev/null
+++ b/apps/plugins/lib/gray_verline.c
@@ -0,0 +1,88 @@
+/***************************************************************************
+* __________ __ ___.
+* Open \______ \ ____ ____ | | _\_ |__ _______ ___
+* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+* \/ \/ \/ \/ \/
+* $Id$
+*
+* Grayscale framework
+* gray_verline() function
+*
+* This is a generic framework to use grayscale display within Rockbox
+* plugins. It obviously does not work for the player.
+*
+* Copyright (C) 2004 Jens Arnold
+*
+* All files in this archive are subject to the GNU General Public License.
+* See the file COPYING in the source tree root for full license agreement.
+*
+* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+* KIND, either express or implied.
+*
+****************************************************************************/
+
+#ifndef SIMULATOR /* not for simulator by now */
+#include "plugin.h"
+
+#ifdef HAVE_LCD_BITMAP /* and also not for the Player */
+#include "gray.h"
+
+/*---------------------------------------------------------------------------
+ Draw a vertical line from (x, y1) to (x, y2) with the current drawinfo
+ ----------------------------------------------------------------------------
+ See gray_drawpixel() for details
+ This one uses the block drawing optimization, so it is rather fast.
+ */
+void gray_verline(int x, int y1, int y2)
+{
+ int shift, y, ny;
+ unsigned bits, mask_top, mask_bottom;
+ unsigned char *dst;
+ void (*blockfunc)(unsigned char *address, unsigned mask, unsigned bits);
+
+ if ((unsigned) x >= (unsigned) _graybuf->width
+ || (unsigned) y1 >= (unsigned) _graybuf->height
+ || (unsigned) y2 >= (unsigned) _graybuf->height)
+ return;
+
+ if (y1 > y2)
+ {
+ y = y1;
+ y1 = y2;
+ y2 = y;
+ }
+ y = y1;
+ ny = y2 - y1 + 1;
+
+ dst = _graybuf->data + x + MULU16(_graybuf->width, y >> 3);
+ shift = y & 7;
+ ny += shift;
+
+ mask_top = 0xFFu << (y & 7);
+ mask_bottom = ~(0xFEu << ((ny - 1) & 7));
+ if (ny <= 8)
+ mask_bottom &= mask_top;
+
+ blockfunc = _gray_blockfuncs[_graybuf->drawmode];
+ bits = (_graybuf->drawmode == GRAY_DRAW_BG) ? 0u : 0xFFu;
+
+ if (ny > 8)
+ {
+ blockfunc(dst, mask_top, bits);
+ dst += _graybuf->width;
+
+ for (y = 8; y < ny - 8; y += 8)
+ {
+ blockfunc(dst, 0xFFu, bits);
+ dst += _graybuf->width;
+ }
+ }
+
+ blockfunc(dst, mask_bottom, bits);
+}
+
+#endif // #ifdef HAVE_LCD_BITMAP
+#endif // #ifndef SIMULATOR
+
diff --git a/apps/plugins/lib/xxx2wav.c b/apps/plugins/lib/xxx2wav.c
new file mode 100644
index 0000000000..8eadfb815e
--- /dev/null
+++ b/apps/plugins/lib/xxx2wav.c
@@ -0,0 +1,259 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2005 Dave Chapman
+ *
+ * All files in this archive are subject to the GNU General Public License.
+ * See the file COPYING in the source tree root for full license agreement.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+/* Various "helper functions" common to all the xxx2wav decoder plugins */
+
+#if (CONFIG_HWCODEC == MASNONE)
+/* software codec platforms, not for simulator */
+
+#include "plugin.h"
+#include "xxx2wav.h"
+
+static struct plugin_api* local_rb;
+
+int mem_ptr;
+int bufsize;
+unsigned char* audiobuf; // The actual audio buffer from Rockbox
+unsigned char* mallocbuf; // 512K from the start of audio buffer
+unsigned char* filebuf; // The rest of the audio buffer
+
+void* codec_malloc(size_t size) {
+ void* x;
+
+ x=&mallocbuf[mem_ptr];
+ mem_ptr+=(size+3)&~3; // Keep memory 32-bit aligned (if it was already?)
+/*
+ if(TIME_AFTER(*(local_rb->current_tick), last_tick + HZ)) {
+ char s[32];
+ static long last_tick = 0;
+ local_rb->snprintf(s,30,"Memory used: %d",mem_ptr);
+ local_rb->lcd_putsxy(0,80,s);
+
+ last_tick = *(local_rb->current_tick);
+ local_rb->lcd_update();
+ }*/
+ return(x);
+}
+
+void* codec_calloc(size_t nmemb, size_t size) {
+ void* x;
+ x = codec_malloc(nmemb*size);
+ local_rb->memset(x,0,nmemb*size);
+ return(x);
+}
+
+void* codec_alloca(size_t size) {
+ void* x;
+ x = codec_malloc(size);
+ return(x);
+}
+
+void codec_free(void* ptr) {
+ (void)ptr;
+}
+
+void* codec_realloc(void* ptr, size_t size) {
+ void* x;
+ (void)ptr;
+ x = codec_malloc(size);
+ return(x);
+}
+
+void *memcpy(void *dest, const void *src, size_t n) {
+ return(local_rb->memcpy(dest,src,n));
+}
+
+void *memset(void *s, int c, size_t n) {
+ return(local_rb->memset(s,c,n));
+}
+
+int memcmp(const void *s1, const void *s2, size_t n) {
+ return(local_rb->memcmp(s1,s2,n));
+}
+
+void* memchr(const void *s, int c, size_t n) {
+ /* TO DO: Implement for Tremor */
+ (void)s;
+ (void)c;
+ (void)n;
+ return(NULL);
+}
+
+void* memmove(const void *s1, const void *s2, size_t n) {
+ char* dest=(char*)s1;
+ char* src=(char*)s2;
+ size_t i;
+
+ for (i=0;i<n;i++) { dest[i]=src[i]; }
+ // while(n>0) { *(dest++)=*(src++); n--; }
+ return(dest);
+}
+
+void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *)) {
+ local_rb->qsort(base,nmemb,size,compar);
+}
+
+void display_status(file_info_struct* file_info) {
+ char s[32];
+ unsigned long ticks_taken;
+ unsigned long long speed;
+ unsigned long xspeed;
+ static long last_tick = 0;
+
+ if(TIME_AFTER(*(local_rb->current_tick), last_tick + HZ)) {
+ local_rb->snprintf(s,32,"Bytes read: %d",file_info->curpos);
+ local_rb->lcd_putsxy(0,0,s);
+ local_rb->snprintf(s,32,"Samples Decoded: %d",file_info->current_sample);
+ local_rb->lcd_putsxy(0,20,s);
+ local_rb->snprintf(s,32,"Frames Decoded: %d",file_info->frames_decoded);
+ local_rb->lcd_putsxy(0,40,s);
+
+ ticks_taken=*(local_rb->current_tick)-file_info->start_tick;
+
+ /* e.g.:
+ ticks_taken=500
+ sam_fmt.rate=44,100
+ samples_decoded=172,400
+ (samples_decoded/sam_fmt.rate)*100=400 (time it should have taken)
+ % Speed=(400/500)*100=80%
+ */
+
+ if (ticks_taken==0) { ticks_taken=1; } // Avoid fp exception.
+
+ speed=(100*file_info->current_sample)/file_info->samplerate;
+ xspeed=(speed*10000)/ticks_taken;
+ local_rb->snprintf(s,32,"Speed %ld.%02ld %% Secs: %d",(xspeed/100),(xspeed%100),ticks_taken/100);
+ local_rb->lcd_putsxy(0,60,s);
+
+ last_tick = *(local_rb->current_tick);
+ local_rb->lcd_update();
+ }
+}
+
+static unsigned char wav_header[44]={'R','I','F','F', // 0 - ChunkID
+ 0,0,0,0, // 4 - ChunkSize (filesize-8)
+ 'W','A','V','E', // 8 - Format
+ 'f','m','t',' ', // 12 - SubChunkID
+ 16,0,0,0, // 16 - SubChunk1ID // 16 for PCM
+ 1,0, // 20 - AudioFormat (1=16-bit)
+ 2,0, // 22 - NumChannels
+ 0,0,0,0, // 24 - SampleRate in Hz
+ 0,0,0,0, // 28 - Byte Rate (SampleRate*NumChannels*(BitsPerSample/8)
+ 4,0, // 32 - BlockAlign (== NumChannels * BitsPerSample/8)
+ 16,0, // 34 - BitsPerSample
+ 'd','a','t','a', // 36 - Subchunk2ID
+ 0,0,0,0 // 40 - Subchunk2Size
+ };
+
+
+void xxx2wav_set_api(struct plugin_api* rb)
+{
+ local_rb = rb;
+}
+
+int local_init(char* infilename, char* outfilename, file_info_struct* file_info, struct plugin_api* rb) {
+ char s[32];
+ int i,n,bytesleft;
+
+ local_rb=rb;
+
+ mem_ptr=0;
+ audiobuf=local_rb->plugin_get_audio_buffer(&bufsize);
+ mallocbuf=audiobuf;
+ filebuf=&audiobuf[MALLOC_BUFSIZE];
+
+ local_rb->snprintf(s,32,"audio bufsize: %d",bufsize);
+ local_rb->lcd_putsxy(0,100,s);
+ local_rb->lcd_update();
+
+ file_info->infile=local_rb->open(infilename,O_RDONLY);
+ file_info->outfile=local_rb->creat(outfilename,O_WRONLY);
+ local_rb->write(file_info->outfile,wav_header,sizeof(wav_header));
+ file_info->curpos=0;
+ file_info->current_sample=0;
+ file_info->frames_decoded=0;
+ file_info->filesize=local_rb->filesize(file_info->infile);
+
+ local_rb->splash(HZ, true, "in: %d, size: %d", file_info->infile, file_info->filesize);
+
+ if (file_info->filesize > (bufsize-MALLOC_BUFSIZE)) {
+ local_rb->close(file_info->infile);
+ local_rb->splash(HZ*2, true, "File too large");
+ return(1);
+ }
+
+ local_rb->snprintf(s,32,"Loading file...");
+ local_rb->lcd_putsxy(0,0,s);
+ local_rb->lcd_update();
+
+ bytesleft=file_info->filesize;
+ i=0;
+ while (bytesleft > 0) {
+ n=local_rb->read(file_info->infile,&filebuf[i],bytesleft);
+ if (n < 0) {
+ local_rb->close(file_info->infile);
+ local_rb->splash(HZ*2, true, "ERROR READING FILE");
+ return(1);
+ }
+ i+=n; bytesleft-=n;
+ }
+ local_rb->close(file_info->infile);
+ local_rb->lcd_clear_display();
+ return(0);
+}
+
+void close_wav(file_info_struct* file_info) {
+ int x;
+ int filesize=local_rb->filesize(file_info->outfile);
+
+ /* We assume 16-bit, Stereo */
+
+ local_rb->lseek(file_info->outfile,0,SEEK_SET);
+
+ // ChunkSize
+ x=filesize-8;
+ wav_header[4]=(x&0xff);
+ wav_header[5]=(x&0xff00)>>8;
+ wav_header[6]=(x&0xff0000)>>16;
+ wav_header[7]=(x&0xff000000)>>24;
+
+ // Samplerate
+ wav_header[24]=file_info->samplerate&0xff;
+ wav_header[25]=(file_info->samplerate&0xff00)>>8;
+ wav_header[26]=(file_info->samplerate&0xff0000)>>16;
+ wav_header[27]=(file_info->samplerate&0xff000000)>>24;
+
+ // ByteRate
+ x=file_info->samplerate*4;
+ wav_header[28]=(x&0xff);
+ wav_header[29]=(x&0xff00)>>8;
+ wav_header[30]=(x&0xff0000)>>16;
+ wav_header[31]=(x&0xff000000)>>24;
+
+ // Subchunk2Size
+ x=filesize-44;
+ wav_header[40]=(x&0xff);
+ wav_header[41]=(x&0xff00)>>8;
+ wav_header[42]=(x&0xff0000)>>16;
+ wav_header[43]=(x&0xff000000)>>24;
+
+ local_rb->write(file_info->outfile,wav_header,sizeof(wav_header));
+ local_rb->close(file_info->outfile);
+}
+#endif /* CONFIG_HWCODEC == MASNONE */
diff --git a/apps/plugins/lib/xxx2wav.h b/apps/plugins/lib/xxx2wav.h
new file mode 100644
index 0000000000..7e1b942820
--- /dev/null
+++ b/apps/plugins/lib/xxx2wav.h
@@ -0,0 +1,67 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2005 Dave Chapman
+ *
+ * All files in this archive are subject to the GNU General Public License.
+ * See the file COPYING in the source tree root for full license agreement.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+/* Various "helper functions" common to all the xxx2wav decoder plugins */
+
+#if CONFIG_CPU == MCF5249 && !defined(SIMULATOR)
+#define ICODE_ATTR __attribute__ ((section(".icode")))
+#define IDATA_ATTR __attribute__ ((section(".idata")))
+#define USE_IRAM 1
+#else
+#define ICODE_ATTR
+#define IDATA_ATTR
+#endif
+
+/* the main data structure of the program */
+typedef struct {
+ int infile;
+ int outfile;
+ off_t curpos;
+ off_t filesize;
+ int samplerate;
+ int bitspersample;
+ int channels;
+ int frames_decoded;
+ unsigned long total_samples;
+ unsigned long current_sample;
+ unsigned long start_tick;
+} file_info_struct;
+
+#define MALLOC_BUFSIZE (512*1024)
+
+extern int mem_ptr;
+extern int bufsize;
+extern unsigned char* mp3buf; // The actual MP3 buffer from Rockbox
+extern unsigned char* mallocbuf; // 512K from the start of MP3 buffer
+extern unsigned char* filebuf; // The rest of the MP3 buffer
+
+void* codec_malloc(size_t size);
+void* codec_calloc(size_t nmemb, size_t size);
+void* codec_alloca(size_t size);
+void* codec_realloc(void* ptr, size_t size);
+void codec_free(void* ptr);
+void *memcpy(void *dest, const void *src, size_t n);
+void *memset(void *s, int c, size_t n);
+int memcmp(const void *s1, const void *s2, size_t n);
+void* memmove(const void *s1, const void *s2, size_t n);
+
+void display_status(file_info_struct* file_info);
+int local_init(char* infilename, char* outfilename, file_info_struct* file_info, struct plugin_api* rb);
+void close_wav(file_info_struct* file_info);
+void xxx2wav_set_api(struct plugin_api* rb);
diff --git a/apps/plugins/mpa2wav.c b/apps/plugins/mpa2wav.c
new file mode 100644
index 0000000000..bf40fa3b81
--- /dev/null
+++ b/apps/plugins/mpa2wav.c
@@ -0,0 +1,269 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2005 Dave Chapman
+ *
+ * All files in this archive are subject to the GNU General Public License.
+ * See the file COPYING in the source tree root for full license agreement.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#include "plugin.h"
+
+#if (CONFIG_HWCODEC == MASNONE)
+/* software codec platforms */
+
+#include <codecs/libmad/mad.h>
+
+#include "lib/xxx2wav.h" /* Helper functions common to test decoders */
+
+static struct plugin_api* rb;
+
+struct mad_stream Stream IDATA_ATTR;
+struct mad_frame Frame IDATA_ATTR;
+struct mad_synth Synth IDATA_ATTR;
+mad_timer_t Timer;
+struct dither d0, d1;
+
+/* The following function is used inside libmad - let's hope it's never
+ called.
+*/
+
+void abort(void) {
+}
+
+/* The "dither" code to convert the 24-bit samples produced by libmad was
+ taken from the coolplayer project - coolplayer.sourceforge.net */
+
+struct dither {
+ mad_fixed_t error[3];
+ mad_fixed_t random;
+};
+
+# define SAMPLE_DEPTH 16
+# define scale(x, y) dither((x), (y))
+
+/*
+ * NAME: prng()
+ * DESCRIPTION: 32-bit pseudo-random number generator
+ */
+static __inline
+unsigned long prng(unsigned long state)
+{
+ return (state * 0x0019660dL + 0x3c6ef35fL) & 0xffffffffL;
+}
+
+/*
+ * NAME: dither()
+ * DESCRIPTION: dither and scale sample
+ */
+static __inline
+signed int dither(mad_fixed_t sample, struct dither *dither)
+{
+ unsigned int scalebits;
+ mad_fixed_t output, mask, random;
+
+ enum {
+ MIN = -MAD_F_ONE,
+ MAX = MAD_F_ONE - 1
+ };
+
+ /* noise shape */
+ sample += dither->error[0] - dither->error[1] + dither->error[2];
+
+ dither->error[2] = dither->error[1];
+ dither->error[1] = dither->error[0] / 2;
+
+ /* bias */
+ output = sample + (1L << (MAD_F_FRACBITS + 1 - SAMPLE_DEPTH - 1));
+
+ scalebits = MAD_F_FRACBITS + 1 - SAMPLE_DEPTH;
+ mask = (1L << scalebits) - 1;
+
+ /* dither */
+ random = prng(dither->random);
+ output += (random & mask) - (dither->random & mask);
+
+ dither->random = random;
+
+ /* clip */
+ if (output > MAX) {
+ output = MAX;
+
+ if (sample > MAX)
+ sample = MAX;
+ }
+ else if (output < MIN) {
+ output = MIN;
+
+ if (sample < MIN)
+ sample = MIN;
+ }
+
+ /* quantize */
+ output &= ~mask;
+
+ /* error feedback */
+ dither->error[0] = sample - output;
+
+ /* scale */
+ return output >> scalebits;
+}
+
+#define SHRT_MAX 32767
+
+#define INPUT_BUFFER_SIZE (10*8192)
+#define OUTPUT_BUFFER_SIZE 65536 /* Must be an integer multiple of 4. */
+
+unsigned char InputBuffer[INPUT_BUFFER_SIZE+MAD_BUFFER_GUARD];
+unsigned char OutputBuffer[OUTPUT_BUFFER_SIZE];
+unsigned char *OutputPtr=OutputBuffer;
+unsigned char *GuardPtr=NULL;
+const unsigned char *OutputBufferEnd=OutputBuffer+OUTPUT_BUFFER_SIZE;
+
+mad_fixed_t mad_frame_overlap[2][32][18] IDATA_ATTR;
+unsigned char mad_main_data[MAD_BUFFER_MDLEN] IDATA_ATTR;
+
+#ifdef USE_IRAM
+extern char iramcopy[];
+extern char iramstart[];
+extern char iramend[];
+#endif
+
+/* this is the plugin entry point */
+enum plugin_status plugin_start(struct plugin_api* api, void* file)
+{
+ file_info_struct file_info;
+ int Status=0;
+ unsigned short Sample;
+ int i;
+
+ /* Generic plugin inititialisation */
+
+ TEST_PLUGIN_API(api);
+ rb = api;
+
+#ifdef USE_IRAM
+ rb->memcpy(iramstart, iramcopy, iramend-iramstart);
+#endif
+
+ /* This function sets up the buffers and reads the file into RAM */
+
+ if (local_init(file,"/libmadtest.wav",&file_info,api)) {
+ return PLUGIN_ERROR;
+ }
+
+ /* Create a decoder instance */
+
+ mad_stream_init(&Stream);
+ mad_frame_init(&Frame);
+ mad_synth_init(&Synth);
+ mad_timer_reset(&Timer);
+
+ /* We do this so libmad doesn't try to call codec_calloc() */
+ memset(mad_frame_overlap, 0, sizeof(mad_frame_overlap));
+ Frame.overlap = &mad_frame_overlap;
+ Stream.main_data = &mad_main_data;
+
+ GuardPtr = &filebuf[file_info.filesize];
+ memset(GuardPtr,0,MAD_BUFFER_GUARD);
+ mad_stream_buffer(&Stream, filebuf,file_info.filesize);
+
+ file_info.curpos=0;
+ file_info.start_tick=*(rb->current_tick);
+
+ rb->button_clear_queue();
+
+ /* This is the decoding loop. */
+ while (file_info.curpos < file_info.filesize &&
+ Stream.this_frame != GuardPtr &&
+ Stream.error != MAD_ERROR_BUFLEN) {
+ file_info.curpos += (int)Stream.next_frame - (int)Stream.this_frame;
+
+ if(mad_frame_decode(&Frame,&Stream))
+ {
+ if(MAD_RECOVERABLE(Stream.error))
+ {
+ if(Stream.error!=MAD_ERROR_LOSTSYNC || Stream.this_frame!=GuardPtr)
+ {
+ rb->splash(HZ*1, true, "Recoverable...!");
+ }
+ continue;
+ }
+ else
+ if(Stream.error==MAD_ERROR_BUFLEN)
+ continue;
+ else
+ {
+ rb->splash(HZ*1, true, "Recoverable...!");
+ //fprintf(stderr,"%s: unrecoverable frame level error.\n",ProgName);
+ Status=1;
+ break;
+ }
+ }
+
+ /* We assume all frames have same samplerate as the first */
+ if(file_info.frames_decoded==0) {
+ file_info.samplerate=Frame.header.samplerate;
+ }
+
+ file_info.frames_decoded++;
+
+ /* ?? Do we need the timer module? */
+ mad_timer_add(&Timer,Frame.header.duration);
+
+/* DAVE: This can be used to attenuate the audio */
+// if(DoFilter)
+// ApplyFilter(&Frame);
+
+ mad_synth_frame(&Synth,&Frame);
+
+ /* Convert MAD's numbers to an array of 16-bit LE signed integers */
+ for(i=0;i<Synth.pcm.length;i++)
+ {
+ /* Left channel */
+ Sample=scale(Synth.pcm.samples[0][i],&d0);
+ *(OutputPtr++)=Sample&0xff;
+ *(OutputPtr++)=Sample>>8;
+
+ /* Right channel. If the decoded stream is monophonic then
+ * the right output channel is the same as the left one.
+ */
+ if(MAD_NCHANNELS(&Frame.header)==2)
+ Sample=scale(Synth.pcm.samples[1][i],&d1);
+ *(OutputPtr++)=Sample&0xff;
+ *(OutputPtr++)=Sample>>8;
+
+ /* Flush the buffer if it is full. */
+ if(OutputPtr==OutputBufferEnd)
+ {
+ rb->write(file_info.outfile,OutputBuffer,OUTPUT_BUFFER_SIZE);
+ OutputPtr=OutputBuffer;
+ }
+ }
+
+ file_info.current_sample+=Synth.pcm.length;
+
+ display_status(&file_info);
+
+ if (rb->button_get(false)!=BUTTON_NONE) {
+ close_wav(&file_info);
+ return PLUGIN_OK;
+ }
+ }
+
+ close_wav(&file_info);
+ rb->splash(HZ*2, true, "FINISHED!");
+
+ return PLUGIN_OK;
+}
+#endif /* CONFIG_HWCODEC == MASNONE */
diff --git a/apps/plugins/mpc2wav.c b/apps/plugins/mpc2wav.c
new file mode 100644
index 0000000000..b1478bac31
--- /dev/null
+++ b/apps/plugins/mpc2wav.c
@@ -0,0 +1,208 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2005 Thom Johansen
+ *
+ * All files in this archive are subject to the GNU General Public License.
+ * See the file COPYING in the source tree root for full license agreement.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+/* This is a lovely mishmash of sample.c from libmusepack and mpa2wav.c,
+ * but happens to work, so no whining!
+ */
+
+#include "plugin.h"
+
+#if (CONFIG_HWCODEC == MASNONE)
+/* software codec platforms */
+
+#include <codecs/libmusepack/musepack.h>
+
+#include "lib/xxx2wav.h" /* Helper functions common to test decoders */
+
+static struct plugin_api* rb;
+mpc_decoder decoder;
+
+/*
+ Our implementations of the mpc_reader callback functions.
+*/
+mpc_int32_t
+read_impl(void *data, void *ptr, mpc_int32_t size)
+{
+ file_info_struct *f = (file_info_struct *)data;
+ mpc_int32_t num = f->filesize - f->curpos;
+ if (num > size)
+ num = size;
+ rb->memcpy(ptr, filebuf + f->curpos, num);
+ f->curpos += num;
+ return num;
+}
+
+bool
+seek_impl(void *data, mpc_int32_t offset)
+{
+ file_info_struct *f = (file_info_struct *)data;
+ if (offset > f->filesize) {
+ return 0;
+ } else {
+ f->curpos = offset;
+ return 1;
+ }
+}
+
+mpc_int32_t
+tell_impl(void *data)
+{
+ file_info_struct *f = (file_info_struct *)data;
+ return f->curpos;
+}
+
+mpc_int32_t
+get_size_impl(void *data)
+{
+ file_info_struct *f = (file_info_struct *)data;
+ return f->filesize;
+}
+
+bool
+canseek_impl(void *data)
+{
+ (void)data;
+ return true;
+}
+
+static int
+shift_signed(MPC_SAMPLE_FORMAT val, int shift)
+{
+ if (shift > 0)
+ val <<= shift;
+ else if (shift < 0)
+ val >>= -shift;
+ return (int)val;
+}
+
+#define OUTPUT_BUFFER_SIZE 65536 /* Must be an integer multiple of 4. */
+
+unsigned char OutputBuffer[OUTPUT_BUFFER_SIZE];
+MPC_SAMPLE_FORMAT sample_buffer[MPC_DECODER_BUFFER_LENGTH];
+unsigned char *OutputPtr=OutputBuffer;
+const unsigned char *OutputBufferEnd=OutputBuffer+OUTPUT_BUFFER_SIZE;
+
+#ifdef USE_IRAM
+extern char iramcopy[];
+extern char iramstart[];
+extern char iramend[];
+#endif
+
+/* this is the plugin entry point */
+enum plugin_status plugin_start(struct plugin_api* api, void* file)
+{
+ file_info_struct file_info;
+ unsigned short Sample;
+ unsigned status = 1;
+ unsigned int i;
+ mpc_reader reader;
+
+ /* Generic plugin inititialisation */
+
+ TEST_PLUGIN_API(api);
+ rb = api;
+
+#ifdef USE_IRAM
+ rb->memcpy(iramstart, iramcopy, iramend-iramstart);
+#endif
+
+ reader.read = read_impl;
+ reader.seek = seek_impl;
+ reader.tell = tell_impl;
+ reader.get_size = get_size_impl;
+ reader.canseek = canseek_impl;
+ reader.data = &file_info;
+
+ /* This function sets up the buffers and reads the file into RAM */
+
+ if (local_init(file, "/libmusepacktest.wav", &file_info, api)) {
+ return PLUGIN_ERROR;
+ }
+
+ /* read file's streaminfo data */
+ mpc_streaminfo info;
+ mpc_streaminfo_init(&info);
+ if (mpc_streaminfo_read(&info, &reader) != ERROR_CODE_OK) {
+ rb->splash(HZ, true, "Not an MPC file.");
+ return PLUGIN_ERROR;
+ }
+ file_info.samplerate=info.sample_freq;
+ /* instantiate a decoder with our file reader */
+ mpc_decoder_setup(&decoder, &reader);
+ if (!mpc_decoder_initialize(&decoder, &info)) {
+ rb->splash(HZ, true, "Error in init.");
+ return PLUGIN_ERROR;
+ }
+ file_info.frames_decoded = 0;
+ file_info.start_tick = *(rb->current_tick);
+
+ rb->button_clear_queue();
+
+ /* This is the decoding loop. */
+ while (status != 0) {
+ status = mpc_decoder_decode(&decoder, sample_buffer, 0, 0);
+ if (status == (unsigned)(-1)) {
+ //decode error
+ rb->splash(HZ, true, "Error decoding file.");
+ break;
+ }
+ else //status>0
+ {
+ file_info.current_sample += status;
+ file_info.frames_decoded++;
+ /* Convert musepack's numbers to an array of 16-bit LE signed integers */
+#if 1 /* uncomment to time without byte swapping and disk writing */
+ for(i = 0; i < status*info.channels; i += info.channels)
+ {
+ /* Left channel */
+ Sample=shift_signed(sample_buffer[i], 16 - MPC_FIXED_POINT_SCALE_SHIFT);
+ *(OutputPtr++)=Sample&0xff;
+ *(OutputPtr++)=Sample>>8;
+
+ /* Right channel. If the decoded stream is monophonic then
+ * the right output channel is the same as the left one.
+ */
+ if(info.channels==2)
+ Sample=shift_signed(sample_buffer[i + 1], 16 - MPC_FIXED_POINT_SCALE_SHIFT);
+ *(OutputPtr++)=Sample&0xff;
+ *(OutputPtr++)=Sample>>8;
+
+ /* Flush the buffer if it is full. */
+ if(OutputPtr==OutputBufferEnd)
+ {
+ rb->write(file_info.outfile,OutputBuffer,OUTPUT_BUFFER_SIZE);
+ OutputPtr=OutputBuffer;
+ }
+ }
+#endif
+
+ }
+ display_status(&file_info);
+
+ if (rb->button_get(false)!=BUTTON_NONE) {
+ close_wav(&file_info);
+ return PLUGIN_OK;
+ }
+ }
+ close_wav(&file_info);
+ rb->splash(HZ*2, true, "FINISHED!");
+
+ return PLUGIN_OK;
+}
+#endif /* CONFIG_HWCODEC == MASNONE */
diff --git a/apps/plugins/rockboy/cpu.h b/apps/plugins/rockboy/cpu.h
new file mode 100644
index 0000000000..c7ec36ccf8
--- /dev/null
+++ b/apps/plugins/rockboy/cpu.h
@@ -0,0 +1,59 @@
+
+
+#ifndef __CPU_H__
+#define __CPU_H__
+
+
+
+#include "defs.h"
+
+
+union reg
+{
+ byte b[2][2];
+ word w[2];
+ un32 d; /* padding for alignment, carry */
+};
+
+struct cpu
+{
+#ifdef DYNAREC
+ union reg a,b,c,d,e,hl,f,sp,pc;
+#else
+ union reg pc, sp, bc, de, hl, af;
+#endif
+ int ime, ima;
+ int speed;
+ int halt;
+ int div, tim;
+ int lcdc;
+ int snd;
+};
+
+extern struct cpu cpu;
+
+#ifdef DYNAREC
+struct dynarec_block {
+ union reg address;
+ void *block;
+ int length;
+ struct dynarec_block *next;
+};
+
+#define HASH_SIGNIFICANT_LOWER_BITS 8
+#define HASH_BITMASK ((1<<HASH_SIGNIFICANT_LOWER_BITS)-1)
+
+extern struct dynarec_block *address_map[1<<HASH_SIGNIFICANT_LOWER_BITS];
+extern int blockclen;
+#endif
+
+void cpu_reset(void);
+void div_advance(int cnt);
+void timer_advance(int cnt);
+void lcdc_advance(int cnt);
+void sound_advance(int cnt);
+void cpu_timers(int cnt);
+int cpu_emulate(int cycles) ICODE_ATTR;
+int cpu_step(int max) ICODE_ATTR;
+
+#endif
diff --git a/apps/plugins/rockboy/lcd.h b/apps/plugins/rockboy/lcd.h
new file mode 100644
index 0000000000..776c8592f4
--- /dev/null
+++ b/apps/plugins/rockboy/lcd.h
@@ -0,0 +1,78 @@
+
+
+#ifndef __LCD_H__
+#define __LCD_H__
+
+#include "defs.h"
+
+struct vissprite
+{
+ byte *buf;
+ int x;
+ byte pal, pri, pad[6];
+};
+
+struct scan
+{
+ int bg[64];
+ int wnd[64];
+#ifdef GRAYSCALE
+ byte buf[4][256];
+#else
+ byte buf[8][256];
+#endif
+ byte pal1[128];
+ un16 pal2[64];
+ un32 pal4[64];
+ byte pri[256];
+ struct vissprite vs[16];
+ int ns, l, x, y, s, t, u, v, wx, wy, wt, wv;
+};
+
+struct obj
+{
+ byte y;
+ byte x;
+ byte pat;
+ byte flags;
+};
+
+struct lcd
+{
+ byte vbank[2][8192];
+ union
+ {
+ byte mem[256];
+ struct obj obj[40];
+ } oam;
+ byte pal[128];
+};
+
+extern struct lcd lcd;
+extern struct scan scan;
+
+
+
+
+
+#endif
+
+
+
+void updatepatpix(void) ICODE_ATTR;
+void tilebuf(void);
+void bg_scan(void);
+void wnd_scan(void);
+void bg_scan_pri(void);
+void wnd_scan_pri(void);
+void spr_count(void);
+void spr_enum(void);
+void spr_scan(void);
+void lcd_begin(void);
+void lcd_refreshline(void);
+void pal_write(int i, byte b);
+void pal_write_dmg(int i, int mapnum, byte d);
+void vram_write(int a, byte b);
+void vram_dirty(void);
+void pal_dirty(void);
+void lcd_reset(void);
diff --git a/apps/plugins/rockboy/rtc.h b/apps/plugins/rockboy/rtc.h
new file mode 100644
index 0000000000..2665cd81c3
--- /dev/null
+++ b/apps/plugins/rockboy/rtc.h
@@ -0,0 +1,25 @@
+
+
+#ifndef __RTC_H__
+#define __RTC_H__
+
+
+struct rtc
+{
+ int batt;
+ int sel;
+ int latch;
+ int d, h, m, s, t;
+ int stop, carry;
+ byte regs[8];
+};
+
+extern struct rtc rtc;
+
+void rtc_latch(byte b);
+void rtc_write(byte b);
+void rtc_tick(void);
+void rtc_save_internal(int fd);
+void rtc_load_internal(int fd);
+
+#endif
diff --git a/apps/plugins/vorbis2wav.c b/apps/plugins/vorbis2wav.c
new file mode 100644
index 0000000000..01815ab1ca
--- /dev/null
+++ b/apps/plugins/vorbis2wav.c
@@ -0,0 +1,180 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2002 Bjrn Stenberg
+ *
+ * All files in this archive are subject to the GNU General Public License.
+ * See the file COPYING in the source tree root for full license agreement.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+#include "kernel.h"
+#include "plugin.h"
+
+#if (CONFIG_HWCODEC == MASNONE)
+/* software codec platforms */
+
+#include <codecs/Tremor/ivorbisfile.h>
+
+#include "lib/xxx2wav.h" /* Helper functions common to test decoders */
+
+static struct plugin_api* rb;
+
+/* Some standard functions and variables needed by Tremor */
+
+
+int errno;
+
+size_t strlen(const char *s) {
+ return(rb->strlen(s));
+}
+
+char *strcpy(char *dest, const char *src) {
+ return(rb->strcpy(dest,src));
+}
+
+char *strcat(char *dest, const char *src) {
+ return(rb->strcat(dest,src));
+}
+
+size_t read_handler(void *ptr, size_t size, size_t nmemb, void *datasource) {
+ size_t len;
+ file_info_struct *p = (file_info_struct *) datasource;
+
+ if (p->curpos >= p->filesize) {
+ return 0; /* EOF */
+ }
+
+ len=nmemb*size;
+ if ((long)(p->curpos+len) > (long)p->filesize) { len=p->filesize-p->curpos; }
+
+ rb->memcpy(ptr,&filebuf[p->curpos],len);
+ p->curpos+=len;
+
+ return(len);
+}
+
+int seek_handler(void *datasource, ogg_int64_t offset, int whence) {
+ /* We are not seekable at the moment */
+ (void)datasource;
+ (void)offset;
+ (void)whence;
+ return -1;
+}
+
+int close_handler(void *datasource) {
+ (void)datasource;
+ return 0;
+}
+
+long tell_handler(void *datasource) {
+ file_info_struct *p = (file_info_struct *) datasource;
+ return p->curpos;
+}
+
+#ifdef USE_IRAM
+extern char iramcopy[];
+extern char iramstart[];
+extern char iramend[];
+#endif
+
+
+/* reserve the PCM buffer in the IRAM area */
+static char pcmbuf[4096] IDATA_ATTR;
+
+/* this is the plugin entry point */
+enum plugin_status plugin_start(struct plugin_api* api, void* file)
+{
+ ov_callbacks callbacks;
+ OggVorbis_File vf;
+ vorbis_info* vi;
+
+ int error;
+ long n;
+ int current_section;
+ int eof;
+#if BYTE_ORDER == BIG_ENDIAN
+ int i;
+ char x;
+#endif
+
+ file_info_struct file_info;
+
+ TEST_PLUGIN_API(api);
+
+ /* if you are using a global api pointer, don't forget to copy it!
+ otherwise you will get lovely "I04: IllInstr" errors... :-) */
+ rb = api;
+
+ #ifdef USE_IRAM
+ rb->memcpy(iramstart, iramcopy, iramend-iramstart);
+ #endif
+
+ /* This function sets up the buffers and reads the file into RAM */
+
+ if (local_init(file,"/vorbistest.wav",&file_info,api)) {
+ return PLUGIN_ERROR;
+ }
+
+
+ /* Create a decoder instance */
+
+ callbacks.read_func=read_handler;
+ callbacks.seek_func=seek_handler;
+ callbacks.tell_func=tell_handler;
+ callbacks.close_func=close_handler;
+
+ file_info.frames_decoded=0;
+ file_info.start_tick=*(rb->current_tick);
+ rb->button_clear_queue();
+
+ error=ov_open_callbacks(&file_info,&vf,NULL,0,callbacks);
+
+ vi=ov_info(&vf,-1);
+
+ if (vi==NULL) {
+ rb->splash(HZ*2, true, "Error");
+ }
+ file_info.samplerate=vi->rate;
+
+ eof=0;
+ while (!eof) {
+ /* Read host-endian signed 16 bit PCM samples */
+ n=ov_read(&vf,pcmbuf,sizeof(pcmbuf),&current_section);
+
+ if (n==0) {
+ eof=1;
+ } else if (n < 0) {
+ DEBUGF("Error decoding frame\n");
+ } else {
+ file_info.frames_decoded++;
+#if BYTE_ORDER == BIG_ENDIAN
+ for (i=0;i<n;i+=2) {
+ x=pcmbuf[i]; pcmbuf[i]=pcmbuf[i+1]; pcmbuf[i+1]=x;
+ }
+#endif
+ rb->write(file_info.outfile,pcmbuf,n);
+ file_info.current_sample+=(n/4);
+ }
+
+ display_status(&file_info);
+
+ if (rb->button_get(false)!=BUTTON_NONE) {
+ close_wav(&file_info);
+ return PLUGIN_OK;
+ }
+ }
+
+ close_wav(&file_info);
+ rb->splash(HZ*2, true, "FINISHED!");
+ return PLUGIN_OK;
+}
+#endif /* CONFIG_HWCODEC == MASNONE */
diff --git a/apps/plugins/wv2wav.c b/apps/plugins/wv2wav.c
new file mode 100644
index 0000000000..909a0c3c63
--- /dev/null
+++ b/apps/plugins/wv2wav.c
@@ -0,0 +1,217 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2005 Christian Gmeiner
+ *
+ * All files in this archive are subject to the GNU General Public License.
+ * See the file COPYING in the source tree root for full license agreement.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#include "plugin.h"
+
+#if (CONFIG_HWCODEC == MASNONE)
+/* software codec platforms */
+
+#include "lib/xxx2wav.h" /* Helper functions common to test decoders */
+#include <codecs/libwavpack/wavpack.h>
+
+#define BUFFER_SIZE 4096
+
+static struct plugin_api* rb;
+static file_info_struct file_info;
+static long temp_buffer [BUFFER_SIZE] IDATA_ATTR;
+
+/* Reformat samples from longs in processor's native endian mode to
+ little-endian data with 2 bytes / sample. */
+uchar* format_samples (int bps, uchar *dst, long *src, ulong samcnt)
+{
+ long temp;
+
+ switch (bps)
+ {
+ case 1:
+ while (samcnt--)
+ {
+ *dst++ = (uchar)(temp = (*src++ << 8));
+ *dst++ = (uchar)(temp >> 8);
+ }
+
+ break;
+
+ case 2:
+ while (samcnt--)
+ {
+ *dst++ = (uchar)(temp = *src++);
+ *dst++ = (uchar)(temp >> 8);
+ }
+
+ break;
+
+ case 3:
+ while (samcnt--)
+ {
+ *dst++ = (uchar)(temp = (*src++ >> 8));
+ *dst++ = (uchar)(temp >> 8);
+ }
+
+ break;
+
+ case 4:
+ while (samcnt--)
+ {
+ *dst++ = (uchar)(temp = (*src++ >> 16));
+ *dst++ = (uchar)(temp >> 8);
+ }
+
+ break;
+ }
+
+ return dst;
+}
+
+/* this is our function to decode a memory block from a file */
+void wvpack_decode_data(file_info_struct* file_info, int samples_to_decode, WavpackContext **wpc)
+{
+ int bps = WavpackGetBytesPerSample(*wpc);
+ /* nothing to decode */
+ if (!samples_to_decode)
+ {
+ return;
+ }
+
+ /* decode now */
+ ulong samples_unpacked = WavpackUnpackSamples(*wpc, temp_buffer, samples_to_decode);
+
+ if (samples_unpacked)
+ {
+ /* update some infos */
+ file_info->current_sample += samples_unpacked;
+
+ /* for now, convert mono to stereo here, in place */
+ if (WavpackGetReducedChannels (*wpc) == 1) {
+ long *dst = temp_buffer + (samples_unpacked * 2);
+ long *src = temp_buffer + samples_unpacked;
+ long count = samples_unpacked;
+
+ while (count--) {
+ *--dst = *--src;
+ *--dst = *src;
+ }
+ }
+
+ format_samples (bps, (uchar *) temp_buffer, temp_buffer, samples_unpacked * file_info->channels);
+ rb->write(file_info->outfile, temp_buffer, samples_unpacked * 4);
+ }
+}
+
+/* callback function for wavpack
+Maybe we do this at a lower level, but the
+first thing is to get all working */
+long Read(void* buffer, long size)
+{
+ long oldpos = file_info.curpos;
+
+ if ((file_info.curpos + size) < file_info.filesize)
+ {
+ memcpy(buffer, &filebuf[file_info.curpos], size);
+ file_info.curpos += size;
+ }
+ else
+ {
+ memcpy(buffer, &filebuf[file_info.curpos], file_info.filesize-file_info.curpos);
+ file_info.curpos = file_info.filesize;
+ }
+
+ return (file_info.curpos - oldpos);
+}
+
+#ifdef USE_IRAM
+extern char iramcopy[];
+extern char iramstart[];
+extern char iramend[];
+#endif
+
+/* this is the plugin entry point */
+enum plugin_status plugin_start(struct plugin_api* api, void* file)
+{
+ WavpackContext *wpc;
+ char error[80];
+
+ /* generic plugin initialisation */
+ TEST_PLUGIN_API(api);
+ rb = api;
+
+ #ifdef USE_IRAM
+ rb->memcpy(iramstart, iramcopy, iramend-iramstart);
+ #endif
+
+ /* this function sets up the buffers and reads the file into RAM */
+ if (local_init(file,"/wvtest.wav",&file_info,api))
+ {
+ return PLUGIN_ERROR;
+ }
+
+ /* setup wavpack */
+ wpc = WavpackOpenFileInput(Read, error);
+
+ /* was there an error? */
+ if (!wpc)
+ {
+ rb->splash(HZ*2, true, error);
+ return PLUGIN_ERROR;
+ }
+
+ /* grap/set some infos (forcing some to temp values) */
+ file_info.channels = 2;
+ file_info.total_samples = WavpackGetNumSamples(wpc);
+ file_info.bitspersample = 16;
+ file_info.samplerate = WavpackGetSampleRate(wpc);
+ file_info.current_sample = 0;
+
+ /* deciding loop */
+ file_info.start_tick=*(rb->current_tick);
+ rb->button_clear_queue();
+
+ while (file_info.current_sample < file_info.total_samples)
+ {
+ wvpack_decode_data(&file_info, BUFFER_SIZE / file_info.channels, &wpc);
+
+ display_status(&file_info);
+
+ if (rb->button_get(false)!=BUTTON_NONE)
+ {
+ close_wav(&file_info);
+ return PLUGIN_OK;
+ }
+ }
+
+ close_wav(&file_info);
+
+ /* do some last checks */
+ if ((WavpackGetNumSamples (wpc) != (ulong) -1) && (file_info.current_sample != WavpackGetNumSamples (wpc)))
+ {
+ rb->splash(HZ*2, true, "incorrect number of samples!");
+ return PLUGIN_ERROR;
+ }
+
+ if (WavpackGetNumErrors (wpc)) {
+ rb->splash(HZ*2, true, "crc errors detected!");
+ return PLUGIN_ERROR;
+ }
+
+ rb->splash(HZ*2, true, "FINISHED!");
+
+ return PLUGIN_OK;
+}
+
+#endif /* CONFIG_HWCODEC == MASNONE */