2003-06-29 16:33:04 +00:00
|
|
|
|
/***************************************************************************
|
|
|
|
|
* __________ __ ___.
|
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
|
* $Id$
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2002 Bj<EFBFBD>rn 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 <stdbool.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdio.h>
|
2003-07-24 10:02:45 +00:00
|
|
|
|
#include <atoi.h>
|
|
|
|
|
#include <timefuncs.h>
|
2003-06-29 16:33:04 +00:00
|
|
|
|
#include "button.h"
|
|
|
|
|
#include "lcd.h"
|
|
|
|
|
#include "dir.h"
|
|
|
|
|
#include "file.h"
|
|
|
|
|
#include "kernel.h"
|
|
|
|
|
#include "sprintf.h"
|
|
|
|
|
#include "screens.h"
|
|
|
|
|
#include "misc.h"
|
|
|
|
|
#include "mas.h"
|
|
|
|
|
#include "plugin.h"
|
|
|
|
|
#include "lang.h"
|
2003-07-09 22:36:23 +00:00
|
|
|
|
#include "keyboard.h"
|
2003-07-20 21:29:16 +00:00
|
|
|
|
#include "mpeg.h"
|
2004-01-30 22:30:40 +00:00
|
|
|
|
#include "buffer.h"
|
|
|
|
|
#include "mp3_playback.h"
|
|
|
|
|
#include "backlight.h"
|
2004-02-03 23:56:25 +00:00
|
|
|
|
#include "ata.h"
|
2004-03-14 21:33:53 +00:00
|
|
|
|
#include "talk.h"
|
2003-07-09 22:36:23 +00:00
|
|
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
|
#include "widgets.h"
|
|
|
|
|
#endif
|
2003-06-29 16:33:04 +00:00
|
|
|
|
|
|
|
|
|
#ifdef SIMULATOR
|
2003-06-29 23:38:03 +00:00
|
|
|
|
#include <debug.h>
|
|
|
|
|
#ifdef WIN32
|
|
|
|
|
#include "plugin-win32.h"
|
|
|
|
|
#define PREFIX(_x_) _x_
|
|
|
|
|
#else
|
|
|
|
|
#include <dlfcn.h>
|
|
|
|
|
#define PREFIX(_x_) x11_ ## _x_
|
|
|
|
|
#endif
|
2003-06-29 16:33:04 +00:00
|
|
|
|
#else
|
|
|
|
|
#define PREFIX(_x_) _x_
|
|
|
|
|
#endif
|
|
|
|
|
|
2003-07-25 23:04:59 +00:00
|
|
|
|
#define PLUGIN_BUFFER_SIZE 0x8000
|
|
|
|
|
|
|
|
|
|
#ifdef SIMULATOR
|
|
|
|
|
static unsigned char pluginbuf[PLUGIN_BUFFER_SIZE];
|
|
|
|
|
#else
|
|
|
|
|
extern unsigned char pluginbuf[];
|
2004-01-30 22:30:40 +00:00
|
|
|
|
extern void bitswap(unsigned char *data, int length);
|
2003-07-25 23:04:59 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
static bool plugin_loaded = false;
|
|
|
|
|
static int plugin_size = 0;
|
|
|
|
|
|
2003-07-13 22:15:19 +00:00
|
|
|
|
static int plugin_test(int api_version, int model, int memsize);
|
2003-06-29 16:33:04 +00:00
|
|
|
|
|
|
|
|
|
static struct plugin_api rockbox_api = {
|
|
|
|
|
PLUGIN_API_VERSION,
|
|
|
|
|
|
|
|
|
|
plugin_test,
|
|
|
|
|
|
|
|
|
|
/* lcd */
|
|
|
|
|
lcd_clear_display,
|
|
|
|
|
lcd_puts,
|
|
|
|
|
lcd_puts_scroll,
|
|
|
|
|
lcd_stop_scroll,
|
|
|
|
|
#ifdef HAVE_LCD_CHARCELLS
|
|
|
|
|
lcd_define_pattern,
|
2003-07-24 09:35:32 +00:00
|
|
|
|
lcd_get_locked_pattern,
|
|
|
|
|
lcd_unlock_pattern,
|
|
|
|
|
lcd_putc,
|
2003-06-29 16:33:04 +00:00
|
|
|
|
#else
|
|
|
|
|
lcd_putsxy,
|
|
|
|
|
lcd_bitmap,
|
|
|
|
|
lcd_drawline,
|
|
|
|
|
lcd_clearline,
|
|
|
|
|
lcd_drawpixel,
|
|
|
|
|
lcd_clearpixel,
|
|
|
|
|
lcd_setfont,
|
|
|
|
|
lcd_clearrect,
|
|
|
|
|
lcd_fillrect,
|
|
|
|
|
lcd_drawrect,
|
|
|
|
|
lcd_invertrect,
|
|
|
|
|
lcd_getstringsize,
|
|
|
|
|
lcd_update,
|
|
|
|
|
lcd_update_rect,
|
2003-07-09 22:36:23 +00:00
|
|
|
|
progressbar,
|
|
|
|
|
slidebar,
|
|
|
|
|
scrollbar,
|
2003-06-29 16:33:04 +00:00
|
|
|
|
#ifndef SIMULATOR
|
|
|
|
|
lcd_roll,
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* button */
|
|
|
|
|
button_get,
|
|
|
|
|
button_get_w_tmo,
|
|
|
|
|
|
|
|
|
|
/* file */
|
2003-12-09 06:48:55 +00:00
|
|
|
|
(open_func)PREFIX(open),
|
2003-06-29 16:33:04 +00:00
|
|
|
|
PREFIX(close),
|
2003-12-09 06:48:55 +00:00
|
|
|
|
(read_func)read,
|
2003-06-29 16:33:04 +00:00
|
|
|
|
lseek,
|
2003-12-09 06:48:55 +00:00
|
|
|
|
(creat_func)PREFIX(creat),
|
|
|
|
|
(write_func)write,
|
2003-06-29 16:33:04 +00:00
|
|
|
|
remove,
|
|
|
|
|
rename,
|
|
|
|
|
ftruncate,
|
|
|
|
|
PREFIX(filesize),
|
|
|
|
|
fprintf,
|
|
|
|
|
read_line,
|
|
|
|
|
|
|
|
|
|
/* dir */
|
|
|
|
|
PREFIX(opendir),
|
|
|
|
|
PREFIX(closedir),
|
|
|
|
|
PREFIX(readdir),
|
|
|
|
|
|
|
|
|
|
/* kernel */
|
|
|
|
|
PREFIX(sleep),
|
|
|
|
|
usb_screen,
|
|
|
|
|
¤t_tick,
|
|
|
|
|
|
|
|
|
|
/* strings and memory */
|
|
|
|
|
snprintf,
|
|
|
|
|
strcpy,
|
|
|
|
|
strlen,
|
|
|
|
|
memset,
|
|
|
|
|
memcpy,
|
|
|
|
|
|
|
|
|
|
/* sound */
|
|
|
|
|
#ifndef SIMULATOR
|
|
|
|
|
#ifdef HAVE_MAS3587F
|
|
|
|
|
mas_codec_readreg,
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* misc */
|
|
|
|
|
srand,
|
|
|
|
|
rand,
|
|
|
|
|
splash,
|
2003-12-09 06:48:55 +00:00
|
|
|
|
(qsort_func)qsort,
|
2003-07-09 22:36:23 +00:00
|
|
|
|
kbd_input,
|
2003-07-24 10:02:45 +00:00
|
|
|
|
mpeg_current_track,
|
|
|
|
|
atoi,
|
2003-07-25 23:04:59 +00:00
|
|
|
|
get_time,
|
|
|
|
|
plugin_get_buffer,
|
2003-12-15 07:44:43 +00:00
|
|
|
|
|
|
|
|
|
/* new stuff at the end, sort into place next time the API gets incompatible */
|
|
|
|
|
|
|
|
|
|
#ifndef HAVE_LCD_CHARCELLS
|
|
|
|
|
&lcd_framebuffer[0][0],
|
|
|
|
|
lcd_blit,
|
|
|
|
|
#endif
|
|
|
|
|
yield,
|
2004-01-30 22:30:40 +00:00
|
|
|
|
|
|
|
|
|
plugin_get_mp3_buffer,
|
|
|
|
|
mpeg_sound_set,
|
|
|
|
|
#ifndef SIMULATOR
|
|
|
|
|
mp3_play_init,
|
|
|
|
|
mp3_play_data,
|
|
|
|
|
mp3_play_pause,
|
|
|
|
|
mp3_play_stop,
|
|
|
|
|
mp3_is_playing,
|
|
|
|
|
bitswap,
|
|
|
|
|
#endif
|
|
|
|
|
&global_settings,
|
|
|
|
|
backlight_set_timeout,
|
2004-02-03 23:56:25 +00:00
|
|
|
|
#ifndef SIMULATOR
|
|
|
|
|
ata_sleep,
|
|
|
|
|
#endif
|
2004-04-28 22:20:27 +00:00
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
|
checkbox,
|
|
|
|
|
#endif
|
2003-06-29 16:33:04 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int plugin_load(char* plugin, void* parameter)
|
|
|
|
|
{
|
|
|
|
|
enum plugin_status (*plugin_start)(struct plugin_api* api, void* param);
|
|
|
|
|
int rc;
|
|
|
|
|
char buf[64];
|
|
|
|
|
#ifdef SIMULATOR
|
|
|
|
|
void* pd;
|
|
|
|
|
char path[256];
|
|
|
|
|
#else
|
|
|
|
|
int fd;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2004-01-12 13:19:13 +00:00
|
|
|
|
int xm,ym;
|
|
|
|
|
lcd_clear_display();
|
|
|
|
|
xm = lcd_getxmargin();
|
|
|
|
|
ym = lcd_getymargin();
|
2003-06-29 16:33:04 +00:00
|
|
|
|
lcd_setmargins(0,0);
|
|
|
|
|
lcd_update();
|
2004-01-12 13:19:13 +00:00
|
|
|
|
#else
|
|
|
|
|
lcd_clear_display();
|
2003-06-29 16:33:04 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef SIMULATOR
|
2003-06-29 23:38:03 +00:00
|
|
|
|
#ifdef WIN32
|
|
|
|
|
snprintf(path, sizeof path, "%s", plugin);
|
|
|
|
|
#else
|
2003-06-29 16:33:04 +00:00
|
|
|
|
snprintf(path, sizeof path, "archos%s", plugin);
|
2003-06-29 23:38:03 +00:00
|
|
|
|
#endif
|
2003-06-29 16:33:04 +00:00
|
|
|
|
pd = dlopen(path, RTLD_NOW);
|
|
|
|
|
if (!pd) {
|
|
|
|
|
snprintf(buf, sizeof buf, "Can't open %s", plugin);
|
2004-01-08 09:58:58 +00:00
|
|
|
|
splash(HZ*2, true, buf);
|
2003-06-29 21:42:15 +00:00
|
|
|
|
DEBUGF("dlopen(%s): %s\n",path,dlerror());
|
2003-06-29 16:33:04 +00:00
|
|
|
|
dlclose(pd);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
plugin_start = dlsym(pd, "plugin_start");
|
|
|
|
|
if (!plugin_start) {
|
|
|
|
|
plugin_start = dlsym(pd, "_plugin_start");
|
|
|
|
|
if (!plugin_start) {
|
2004-01-08 09:58:58 +00:00
|
|
|
|
splash(HZ*2, true, "Can't find entry point");
|
2003-06-29 16:33:04 +00:00
|
|
|
|
dlclose(pd);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
fd = open(plugin, O_RDONLY);
|
|
|
|
|
if (fd < 0) {
|
|
|
|
|
snprintf(buf, sizeof buf, str(LANG_PLUGIN_CANT_OPEN), plugin);
|
2004-01-08 09:58:58 +00:00
|
|
|
|
splash(HZ*2, true, buf);
|
2003-06-29 16:33:04 +00:00
|
|
|
|
return fd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
plugin_start = (void*)&pluginbuf;
|
2003-07-25 23:04:59 +00:00
|
|
|
|
plugin_size = read(fd, plugin_start, PLUGIN_BUFFER_SIZE);
|
2003-06-29 16:33:04 +00:00
|
|
|
|
close(fd);
|
2003-07-25 23:04:59 +00:00
|
|
|
|
if (plugin_size < 0) {
|
2003-06-29 16:33:04 +00:00
|
|
|
|
/* read error */
|
|
|
|
|
snprintf(buf, sizeof buf, str(LANG_READ_FAILED), plugin);
|
2004-01-08 09:58:58 +00:00
|
|
|
|
splash(HZ*2, true, buf);
|
2003-06-29 16:33:04 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
2003-07-25 23:04:59 +00:00
|
|
|
|
if (plugin_size == 0) {
|
2003-06-29 16:33:04 +00:00
|
|
|
|
/* loaded a 0-byte plugin, implying it's not for this model */
|
2004-01-08 09:58:58 +00:00
|
|
|
|
splash(HZ*2, true, str(LANG_PLUGIN_WRONG_MODEL));
|
2003-06-29 16:33:04 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2003-07-25 23:04:59 +00:00
|
|
|
|
plugin_loaded = true;
|
2003-06-29 16:33:04 +00:00
|
|
|
|
rc = plugin_start(&rockbox_api, parameter);
|
2003-07-25 23:04:59 +00:00
|
|
|
|
plugin_loaded = false;
|
|
|
|
|
|
2003-06-29 16:33:04 +00:00
|
|
|
|
switch (rc) {
|
|
|
|
|
case PLUGIN_OK:
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PLUGIN_USB_CONNECTED:
|
|
|
|
|
return PLUGIN_USB_CONNECTED;
|
|
|
|
|
|
|
|
|
|
case PLUGIN_WRONG_API_VERSION:
|
2004-01-08 09:58:58 +00:00
|
|
|
|
splash(HZ*2, true, str(LANG_PLUGIN_WRONG_VERSION));
|
2003-06-29 16:33:04 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PLUGIN_WRONG_MODEL:
|
2004-01-08 09:58:58 +00:00
|
|
|
|
splash(HZ*2, true, str(LANG_PLUGIN_WRONG_MODEL));
|
2003-06-29 16:33:04 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
2004-01-08 09:58:58 +00:00
|
|
|
|
splash(HZ*2, true, str(LANG_PLUGIN_ERROR));
|
2003-06-29 16:33:04 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef SIMULATOR
|
|
|
|
|
dlclose(pd);
|
|
|
|
|
#endif
|
2004-01-12 13:19:13 +00:00
|
|
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
|
/* restore margins */
|
|
|
|
|
lcd_setmargins(xm,ym);
|
|
|
|
|
#endif
|
|
|
|
|
|
2003-06-29 16:33:04 +00:00
|
|
|
|
return PLUGIN_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-25 23:04:59 +00:00
|
|
|
|
/* Returns a pointer to the portion of the plugin buffer that is not already
|
|
|
|
|
being used. If no plugin is loaded, returns the entire plugin buffer */
|
|
|
|
|
void* plugin_get_buffer(int* buffer_size)
|
|
|
|
|
{
|
|
|
|
|
int buffer_pos;
|
|
|
|
|
|
|
|
|
|
if (plugin_loaded)
|
|
|
|
|
{
|
|
|
|
|
if (plugin_size >= PLUGIN_BUFFER_SIZE)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
*buffer_size = PLUGIN_BUFFER_SIZE-plugin_size;
|
|
|
|
|
buffer_pos = plugin_size;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
*buffer_size = PLUGIN_BUFFER_SIZE;
|
|
|
|
|
buffer_pos = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &pluginbuf[buffer_pos];
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-30 22:30:40 +00:00
|
|
|
|
/* Returns a pointer to the mp3 buffer.
|
|
|
|
|
Playback gets stopped, to avoid conflicts. */
|
|
|
|
|
void* plugin_get_mp3_buffer(int* buffer_size)
|
|
|
|
|
{
|
|
|
|
|
#ifdef SIMULATOR
|
|
|
|
|
static unsigned char buf[1700*1024];
|
|
|
|
|
*buffer_size = sizeof(buf);
|
|
|
|
|
return buf;
|
|
|
|
|
#else
|
|
|
|
|
mpeg_stop();
|
2004-03-14 21:33:53 +00:00
|
|
|
|
talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
|
2004-01-30 22:30:40 +00:00
|
|
|
|
*buffer_size = mp3end - mp3buf;
|
|
|
|
|
return mp3buf;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-25 23:04:59 +00:00
|
|
|
|
static int plugin_test(int api_version, int model, int memsize)
|
2003-06-29 16:33:04 +00:00
|
|
|
|
{
|
2003-07-25 23:04:59 +00:00
|
|
|
|
if (api_version < PLUGIN_MIN_API_VERSION ||
|
|
|
|
|
api_version > PLUGIN_API_VERSION)
|
2003-06-29 16:33:04 +00:00
|
|
|
|
return PLUGIN_WRONG_API_VERSION;
|
|
|
|
|
|
|
|
|
|
if (model != MODEL)
|
|
|
|
|
return PLUGIN_WRONG_MODEL;
|
|
|
|
|
|
2003-07-13 22:15:19 +00:00
|
|
|
|
if (memsize != MEM)
|
|
|
|
|
return PLUGIN_WRONG_MODEL;
|
|
|
|
|
|
2003-06-29 16:33:04 +00:00
|
|
|
|
return PLUGIN_OK;
|
|
|
|
|
}
|