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>
|
2004-07-13 14:01:41 +00:00
|
|
|
|
#include <ctype.h>
|
2004-06-10 13:29:52 +00:00
|
|
|
|
#include "debug.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"
|
2004-06-10 13:29:52 +00:00
|
|
|
|
#include "mp3data.h"
|
2004-06-15 22:54:37 +00:00
|
|
|
|
#include "powermgmt.h"
|
2003-07-09 22:36:23 +00:00
|
|
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2004-07-29 13:59:04 +00:00
|
|
|
|
#include "peakmeter.h"
|
2003-07-09 22:36:23 +00:00
|
|
|
|
#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"
|
|
|
|
|
#else
|
|
|
|
|
#include <dlfcn.h>
|
|
|
|
|
#endif
|
2004-06-10 13:29:52 +00:00
|
|
|
|
#define PREFIX(_x_) sim_ ## _x_
|
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-09-26 09:25:59 +00:00
|
|
|
|
#include "bitswap.h"
|
2003-07-25 23:04:59 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
static bool plugin_loaded = false;
|
|
|
|
|
static int plugin_size = 0;
|
2004-05-01 15:45:01 +00:00
|
|
|
|
#ifndef SIMULATOR
|
2004-04-30 20:37:11 +00:00
|
|
|
|
static void (*pfn_timer)(void) = NULL; /* user timer handler */
|
2004-05-01 15:45:01 +00:00
|
|
|
|
#endif
|
2004-04-30 20:37:11 +00:00
|
|
|
|
static void (*pfn_tsr_exit)(void) = NULL; /* TSR exit callback */
|
2003-07-25 23:04:59 +00:00
|
|
|
|
|
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
|
|
|
|
|
2004-07-20 21:37:36 +00:00
|
|
|
|
static const struct plugin_api rockbox_api = {
|
2003-06-29 16:33:04 +00:00
|
|
|
|
PLUGIN_API_VERSION,
|
|
|
|
|
|
|
|
|
|
plugin_test,
|
|
|
|
|
|
|
|
|
|
/* lcd */
|
|
|
|
|
lcd_clear_display,
|
|
|
|
|
lcd_puts,
|
|
|
|
|
lcd_puts_scroll,
|
|
|
|
|
lcd_stop_scroll,
|
2004-07-27 14:10:48 +00:00
|
|
|
|
lcd_set_contrast,
|
2003-06-29 16:33:04 +00:00
|
|
|
|
#ifdef HAVE_LCD_CHARCELLS
|
|
|
|
|
lcd_define_pattern,
|
2003-07-24 09:35:32 +00:00
|
|
|
|
lcd_get_locked_pattern,
|
|
|
|
|
lcd_unlock_pattern,
|
|
|
|
|
lcd_putc,
|
2004-07-27 14:10:48 +00:00
|
|
|
|
lcd_put_cursor,
|
|
|
|
|
lcd_remove_cursor,
|
|
|
|
|
lcd_icon,
|
2003-06-29 16:33:04 +00:00
|
|
|
|
#else
|
|
|
|
|
lcd_putsxy,
|
2004-07-27 14:10:48 +00:00
|
|
|
|
lcd_puts_style,
|
2004-10-23 09:59:53 +00:00
|
|
|
|
lcd_puts_scroll_style,
|
2003-06-29 16:33:04 +00:00
|
|
|
|
lcd_bitmap,
|
|
|
|
|
lcd_drawline,
|
|
|
|
|
lcd_clearline,
|
|
|
|
|
lcd_drawpixel,
|
|
|
|
|
lcd_clearpixel,
|
|
|
|
|
lcd_setfont,
|
2004-07-27 14:10:48 +00:00
|
|
|
|
font_get,
|
2003-06-29 16:33:04 +00:00
|
|
|
|
lcd_clearrect,
|
|
|
|
|
lcd_fillrect,
|
|
|
|
|
lcd_drawrect,
|
|
|
|
|
lcd_invertrect,
|
|
|
|
|
lcd_getstringsize,
|
|
|
|
|
lcd_update,
|
|
|
|
|
lcd_update_rect,
|
2003-07-09 22:36:23 +00:00
|
|
|
|
scrollbar,
|
2004-07-27 14:10:48 +00:00
|
|
|
|
checkbox,
|
|
|
|
|
&lcd_framebuffer[0][0],
|
|
|
|
|
lcd_blit,
|
2003-06-29 16:33:04 +00:00
|
|
|
|
#ifndef SIMULATOR
|
|
|
|
|
lcd_roll,
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
2004-07-27 14:10:48 +00:00
|
|
|
|
backlight_on,
|
|
|
|
|
backlight_off,
|
2004-10-23 09:59:53 +00:00
|
|
|
|
backlight_set_timeout,
|
2004-07-27 19:16:58 +00:00
|
|
|
|
splash,
|
2003-06-29 16:33:04 +00:00
|
|
|
|
|
|
|
|
|
/* button */
|
|
|
|
|
button_get,
|
|
|
|
|
button_get_w_tmo,
|
2004-07-27 14:10:48 +00:00
|
|
|
|
button_status,
|
|
|
|
|
button_clear_queue,
|
2003-06-29 16:33:04 +00:00
|
|
|
|
|
|
|
|
|
/* 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,
|
2004-07-23 14:51:49 +00:00
|
|
|
|
PREFIX(remove),
|
|
|
|
|
PREFIX(rename),
|
2003-06-29 16:33:04 +00:00
|
|
|
|
ftruncate,
|
|
|
|
|
PREFIX(filesize),
|
|
|
|
|
fprintf,
|
|
|
|
|
read_line,
|
2004-07-27 14:10:48 +00:00
|
|
|
|
settings_parseline,
|
2004-07-27 19:16:58 +00:00
|
|
|
|
#ifndef SIMULATOR
|
|
|
|
|
ata_sleep,
|
|
|
|
|
#endif
|
2003-06-29 16:33:04 +00:00
|
|
|
|
|
|
|
|
|
/* dir */
|
|
|
|
|
PREFIX(opendir),
|
|
|
|
|
PREFIX(closedir),
|
|
|
|
|
PREFIX(readdir),
|
|
|
|
|
|
2004-10-23 09:59:53 +00:00
|
|
|
|
/* kernel/ system */
|
2003-06-29 16:33:04 +00:00
|
|
|
|
PREFIX(sleep),
|
2004-07-27 14:10:48 +00:00
|
|
|
|
yield,
|
2003-06-29 16:33:04 +00:00
|
|
|
|
¤t_tick,
|
2004-07-27 14:10:48 +00:00
|
|
|
|
default_event_handler,
|
2004-10-23 09:59:53 +00:00
|
|
|
|
default_event_handler_ex,
|
2004-07-27 14:10:48 +00:00
|
|
|
|
create_thread,
|
|
|
|
|
remove_thread,
|
2004-07-27 19:16:58 +00:00
|
|
|
|
reset_poweroff_timer,
|
2004-10-23 09:59:53 +00:00
|
|
|
|
#ifndef SIMULATOR
|
|
|
|
|
system_memory_guard,
|
|
|
|
|
#endif
|
2003-06-29 16:33:04 +00:00
|
|
|
|
|
|
|
|
|
/* strings and memory */
|
|
|
|
|
snprintf,
|
|
|
|
|
strcpy,
|
2004-07-27 14:10:48 +00:00
|
|
|
|
strncpy,
|
2003-06-29 16:33:04 +00:00
|
|
|
|
strlen,
|
2004-07-13 14:14:30 +00:00
|
|
|
|
strrchr,
|
2004-07-27 14:10:48 +00:00
|
|
|
|
strcmp,
|
|
|
|
|
strcasecmp,
|
2004-10-23 09:59:53 +00:00
|
|
|
|
strncasecmp,
|
2003-06-29 16:33:04 +00:00
|
|
|
|
memset,
|
|
|
|
|
memcpy,
|
2004-07-13 14:01:41 +00:00
|
|
|
|
#ifndef SIMULATOR
|
|
|
|
|
_ctype_,
|
|
|
|
|
#endif
|
2004-07-27 19:16:58 +00:00
|
|
|
|
atoi,
|
2003-06-29 16:33:04 +00:00
|
|
|
|
|
|
|
|
|
/* sound */
|
2004-07-27 14:10:48 +00:00
|
|
|
|
mpeg_sound_set,
|
2003-06-29 16:33:04 +00:00
|
|
|
|
#ifndef SIMULATOR
|
2004-07-27 14:10:48 +00:00
|
|
|
|
mp3_play_data,
|
|
|
|
|
mp3_play_pause,
|
|
|
|
|
mp3_play_stop,
|
|
|
|
|
mp3_is_playing,
|
|
|
|
|
bitswap,
|
2003-06-29 16:33:04 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2004-07-27 14:10:48 +00:00
|
|
|
|
/* playback control */
|
|
|
|
|
mpeg_play,
|
|
|
|
|
mpeg_stop,
|
|
|
|
|
mpeg_pause,
|
|
|
|
|
mpeg_resume,
|
|
|
|
|
mpeg_next,
|
|
|
|
|
mpeg_prev,
|
|
|
|
|
mpeg_ff_rewind,
|
|
|
|
|
mpeg_next_track,
|
|
|
|
|
playlist_amount,
|
|
|
|
|
mpeg_status,
|
|
|
|
|
mpeg_has_changed_track,
|
2004-07-27 19:16:58 +00:00
|
|
|
|
mpeg_current_track,
|
2004-10-23 09:59:53 +00:00
|
|
|
|
mpeg_flush_and_reload_tracks,
|
|
|
|
|
mpeg_get_file_pos,
|
|
|
|
|
mpeg_get_last_header,
|
|
|
|
|
#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
|
|
|
|
|
mpeg_set_pitch,
|
|
|
|
|
#endif
|
2004-07-27 19:16:58 +00:00
|
|
|
|
|
|
|
|
|
/* MAS communication */
|
|
|
|
|
#ifndef SIMULATOR
|
|
|
|
|
mas_readmem,
|
|
|
|
|
mas_writemem,
|
|
|
|
|
mas_readreg,
|
|
|
|
|
mas_writereg,
|
2004-09-29 19:51:41 +00:00
|
|
|
|
#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
|
2004-07-27 19:16:58 +00:00
|
|
|
|
mas_codec_writereg,
|
|
|
|
|
mas_codec_readreg,
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
2004-07-27 14:10:48 +00:00
|
|
|
|
|
2003-06-29 16:33:04 +00:00
|
|
|
|
/* misc */
|
|
|
|
|
srand,
|
|
|
|
|
rand,
|
2003-12-09 06:48:55 +00:00
|
|
|
|
(qsort_func)qsort,
|
2003-07-09 22:36:23 +00:00
|
|
|
|
kbd_input,
|
2003-07-25 23:04:59 +00:00
|
|
|
|
get_time,
|
2004-07-27 19:16:58 +00:00
|
|
|
|
set_time,
|
2003-07-25 23:04:59 +00:00
|
|
|
|
plugin_get_buffer,
|
2004-07-27 14:10:48 +00:00
|
|
|
|
plugin_get_mp3_buffer,
|
|
|
|
|
#ifndef SIMULATOR
|
|
|
|
|
plugin_register_timer,
|
|
|
|
|
plugin_unregister_timer,
|
|
|
|
|
#endif
|
|
|
|
|
plugin_tsr,
|
2004-06-10 13:29:52 +00:00
|
|
|
|
#if defined(DEBUG) || defined(SIMULATOR)
|
|
|
|
|
debugf,
|
|
|
|
|
#endif
|
2004-07-27 19:16:58 +00:00
|
|
|
|
&global_settings,
|
2004-06-10 13:29:52 +00:00
|
|
|
|
mp3info,
|
|
|
|
|
count_mp3_frames,
|
|
|
|
|
create_xing_header,
|
2004-10-23 09:59:53 +00:00
|
|
|
|
find_next_frame,
|
2004-06-15 23:16:43 +00:00
|
|
|
|
battery_level,
|
2004-10-23 09:59:53 +00:00
|
|
|
|
battery_level_safe,
|
2004-09-29 19:51:41 +00:00
|
|
|
|
#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
|
2004-07-29 13:59:04 +00:00
|
|
|
|
peak_meter_scale_value,
|
2004-10-23 09:59:53 +00:00
|
|
|
|
peak_meter_set_use_dbfs,
|
2004-07-29 13:59:04 +00:00
|
|
|
|
peak_meter_get_use_dbfs,
|
|
|
|
|
#endif
|
2004-10-23 09:59:53 +00:00
|
|
|
|
|
|
|
|
|
/* new stuff at the end, sort into place next time
|
|
|
|
|
the API gets incompatible */
|
|
|
|
|
|
2003-06-29 16:33:04 +00:00
|
|
|
|
};
|
|
|
|
|
|
2004-08-18 01:09:31 +00:00
|
|
|
|
int plugin_load(const char* plugin, void* parameter)
|
2003-06-29 16:33:04 +00:00
|
|
|
|
{
|
|
|
|
|
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
|
2004-05-01 15:14:09 +00:00
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
|
int xm,ym;
|
|
|
|
|
#endif
|
2003-06-29 16:33:04 +00:00
|
|
|
|
|
2004-04-30 20:37:11 +00:00
|
|
|
|
if (pfn_tsr_exit != NULL) /* if we have a resident old plugin: */
|
|
|
|
|
{
|
|
|
|
|
pfn_tsr_exit(); /* force it to exit now */
|
|
|
|
|
pfn_tsr_exit = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2003-06-29 16:33:04 +00:00
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2004-01-12 13:19:13 +00:00
|
|
|
|
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
|
|
|
|
|
snprintf(path, sizeof path, "archos%s", plugin);
|
2004-06-10 13:29:52 +00:00
|
|
|
|
|
2003-06-29 16:33:04 +00:00
|
|
|
|
pd = dlopen(path, RTLD_NOW);
|
|
|
|
|
if (!pd) {
|
2004-10-07 06:11:01 +00:00
|
|
|
|
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 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;
|
|
|
|
|
}
|
2004-11-10 22:20:20 +00:00
|
|
|
|
|
|
|
|
|
/* zero out plugin buffer to ensure a properly zeroed bss area */
|
|
|
|
|
memset(pluginbuf, 0, PLUGIN_BUFFER_SIZE);
|
2003-06-29 16:33:04 +00:00
|
|
|
|
|
|
|
|
|
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;
|
2004-07-20 21:37:36 +00:00
|
|
|
|
rc = plugin_start((struct plugin_api*) &rockbox_api, parameter);
|
2004-07-21 08:02:23 +00:00
|
|
|
|
/* explicitly casting the pointer here to avoid touching every plugin. */
|
|
|
|
|
|
|
|
|
|
button_clear_queue();
|
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2004-04-30 20:37:11 +00:00
|
|
|
|
#ifndef SIMULATOR
|
|
|
|
|
/* Register a periodic time callback, called every "cycles" CPU clocks.
|
|
|
|
|
Note that this function will be called in interrupt context! */
|
|
|
|
|
int plugin_register_timer(int cycles, int prio, void (*timer_callback)(void))
|
|
|
|
|
{
|
|
|
|
|
int phi = 0; /* bits for the prescaler */
|
|
|
|
|
int prescale = 1;
|
|
|
|
|
|
|
|
|
|
while (cycles > 0x10000)
|
|
|
|
|
{ /* work out the smallest prescaler that makes it fit */
|
|
|
|
|
phi++;
|
|
|
|
|
prescale *= 2;
|
|
|
|
|
cycles /= 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (prescale > 8 || cycles == 0 || prio < 1 || prio > 15)
|
|
|
|
|
return 0; /* error, we can't do such period, bad argument */
|
|
|
|
|
|
|
|
|
|
and_b(~0x10, &TSTR); /* Stop the timer 4 */
|
|
|
|
|
and_b(~0x10, &TSNC); /* No synchronization */
|
|
|
|
|
and_b(~0x10, &TMDR); /* Operate normally */
|
|
|
|
|
|
|
|
|
|
pfn_timer = timer_callback; /* install 2nd level ISR */
|
|
|
|
|
|
2004-05-02 19:07:55 +00:00
|
|
|
|
and_b(~0x01, &TSR4);
|
2004-04-30 20:37:11 +00:00
|
|
|
|
TIER4 = 0xF9; /* Enable GRA match interrupt */
|
|
|
|
|
|
|
|
|
|
GRA4 = (unsigned short)(cycles - 1);
|
|
|
|
|
TCR4 = 0x20 | phi; /* clear at GRA match, set prescaler */
|
|
|
|
|
IPRD = (IPRD & 0xFF0F) | prio << 4; /* interrupt priority */
|
|
|
|
|
or_b(0x10, &TSTR); /* start timer 4 */
|
|
|
|
|
|
|
|
|
|
return cycles * prescale; /* return the actual period, in CPU clocks */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* disable the user timer */
|
|
|
|
|
void plugin_unregister_timer(void)
|
|
|
|
|
{
|
|
|
|
|
and_b(~0x10, &TSTR); /* stop the timer 4 */
|
|
|
|
|
IPRD = (IPRD & 0xFF0F); /* disable interrupt */
|
|
|
|
|
pfn_timer = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* interrupt handler for user timer */
|
|
|
|
|
#pragma interrupt
|
|
|
|
|
void IMIA4(void)
|
|
|
|
|
{
|
|
|
|
|
if (pfn_timer != NULL)
|
|
|
|
|
pfn_timer(); /* call the user timer function */
|
2004-04-30 21:50:13 +00:00
|
|
|
|
and_b(~0x01, &TSR4); /* clear the interrupt */
|
2004-04-30 20:37:11 +00:00
|
|
|
|
}
|
|
|
|
|
#endif /* #ifndef SIMULATOR */
|
|
|
|
|
|
|
|
|
|
/* The plugin wants to stay resident after leaving its main function, e.g.
|
|
|
|
|
runs from timer or own thread. The callback is registered to later
|
|
|
|
|
instruct it to free its resources before a new plugin gets loaded. */
|
|
|
|
|
void plugin_tsr(void (*exit_callback)(void))
|
|
|
|
|
{
|
|
|
|
|
pfn_tsr_exit = exit_callback; /* remember the callback for later */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|