summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/plugin.c16
-rw-r--r--apps/plugin.h20
-rw-r--r--apps/plugins/Makefile2
-rw-r--r--apps/plugins/vbrfix.c280
-rw-r--r--apps/plugins/viewers.config1
-rw-r--r--firmware/include/file.h13
-rw-r--r--uisimulator/common/dir.h (renamed from uisimulator/x11/dir.h)33
-rw-r--r--uisimulator/common/file.h (renamed from uisimulator/x11/file.h)45
-rw-r--r--uisimulator/common/io.c (renamed from uisimulator/x11/io.c)51
-rw-r--r--uisimulator/win32/Makefile11
-rw-r--r--uisimulator/win32/dir-win32.c97
-rw-r--r--uisimulator/win32/dir-win32.h26
-rw-r--r--uisimulator/win32/dir.h82
-rw-r--r--uisimulator/win32/file.h43
-rw-r--r--uisimulator/win32/io.c63
-rw-r--r--uisimulator/win32/kernel.c2
-rw-r--r--uisimulator/win32/kernel.h6
-rw-r--r--uisimulator/x11/Makefile9
-rw-r--r--uisimulator/x11/button-x11.c6
-rw-r--r--uisimulator/x11/kernel.h4
-rw-r--r--uisimulator/x11/thread.c2
21 files changed, 415 insertions, 397 deletions
diff --git a/apps/plugin.c b/apps/plugin.c
index c7758af..8d8d25f 100644
--- a/apps/plugin.c
+++ b/apps/plugin.c
@@ -21,6 +21,7 @@
#include <stdio.h>
#include <atoi.h>
#include <timefuncs.h>
+#include "debug.h"
#include "button.h"
#include "lcd.h"
#include "dir.h"
@@ -39,6 +40,7 @@
#include "backlight.h"
#include "ata.h"
#include "talk.h"
+#include "mp3data.h"
#ifdef HAVE_LCD_BITMAP
#include "widgets.h"
@@ -48,11 +50,10 @@
#include <debug.h>
#ifdef WIN32
#include "plugin-win32.h"
- #define PREFIX(_x_) _x_
#else
#include <dlfcn.h>
- #define PREFIX(_x_) x11_ ## _x_
#endif
+ #define PREFIX(_x_) sim_ ## _x_
#else
#define PREFIX(_x_) _x_
#endif
@@ -213,6 +214,12 @@ static struct plugin_api rockbox_api = {
#ifdef HAVE_LCD_BITMAP
font_get,
#endif
+#if defined(DEBUG) || defined(SIMULATOR)
+ debugf,
+#endif
+ mp3info,
+ count_mp3_frames,
+ create_xing_header,
};
int plugin_load(char* plugin, void* parameter)
@@ -246,11 +253,8 @@ int plugin_load(char* plugin, void* parameter)
lcd_clear_display();
#endif
#ifdef SIMULATOR
-#ifdef WIN32
- snprintf(path, sizeof path, "%s", plugin);
-#else
snprintf(path, sizeof path, "archos%s", plugin);
-#endif
+
pd = dlopen(path, RTLD_NOW);
if (!pd) {
snprintf(buf, sizeof buf, "Can't open %s", plugin);
diff --git a/apps/plugin.h b/apps/plugin.h
index f539c3e..c67f49e 100644
--- a/apps/plugin.h
+++ b/apps/plugin.h
@@ -45,6 +45,16 @@
#include "settings.h"
#include "thread.h"
+#ifdef PLUGIN
+#if defined(DEBUG) || defined(SIMULATOR)
+#define DEBUGF rb->debugf
+#define LDEBUGF rb->debugf
+#else
+#define DEBUGF(...)
+#define LDEBUGF(...)
+#endif
+#endif
+
/* increase this every time the api struct changes */
#define PLUGIN_API_VERSION 14
@@ -235,6 +245,16 @@ struct plugin_api {
#ifdef HAVE_LCD_BITMAP
struct font* (*font_get)(int font);
#endif
+#if defined(DEBUG) || defined(SIMULATOR)
+ void (*debugf)(char *fmt, ...);
+#endif
+ bool (*mp3info)(struct mp3entry *entry, char *filename) ;
+ int (*count_mp3_frames)(int fd, int startpos, int filesize,
+ void (*progressfunc)(int));
+ int (*create_xing_header)(int fd, int startpos, int filesize,
+ unsigned char *buf, int num_frames,
+ unsigned long header_template,
+ void (*progressfunc)(int), bool generate_toc);
};
/* defined by the plugin loader (plugin.c) */
diff --git a/apps/plugins/Makefile b/apps/plugins/Makefile
index 367103b..1c703f2 100644
--- a/apps/plugins/Makefile
+++ b/apps/plugins/Makefile
@@ -15,7 +15,7 @@ FIRMWARE = ../../firmware
INCLUDES = -I$(FIRMWARE)/include -I$(FIRMWARE)/export -I$(FIRMWARE)/common \
-I$(FIRMWARE)/drivers -I.. -Ilib
CFLAGS = -O -W -Wall -m1 -nostdlib -ffreestanding -Wstrict-prototypes \
-$(INCLUDES) $(TARGET) $(EXTRA_DEFINES) -DMEM=${MEM}
+$(INCLUDES) $(TARGET) $(EXTRA_DEFINES) -DMEM=${MEM} -DPLUGIN
LDS := plugin.lds
LINKFILE := $(OBJDIR)/pluginlink.lds
diff --git a/apps/plugins/vbrfix.c b/apps/plugins/vbrfix.c
new file mode 100644
index 0000000..1beca26
--- /dev/null
+++ b/apps/plugins/vbrfix.c
@@ -0,0 +1,280 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2004 Linus Nielsen Feltzing
+ *
+ * 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"
+
+static struct plugin_api* rb;
+
+static char *mp3buf;
+static int mp3buflen;
+
+static void xingupdate(int percent)
+{
+ char buf[32];
+
+ rb->snprintf(buf, 32, "%d%%", percent);
+ rb->lcd_puts(0, 1, buf);
+#ifdef HAVE_LCD_BITMAP
+ rb->lcd_update();
+#endif
+}
+
+static int insert_data_in_file(char *fname, int fpos, char *buf, int num_bytes)
+{
+ int readlen;
+ int rc;
+ int orig_fd, fd;
+ char tmpname[MAX_PATH];
+
+ rb->snprintf(tmpname, MAX_PATH, "%s.tmp", fname);
+
+ orig_fd = rb->open(fname, O_RDONLY);
+ if(orig_fd < 0) {
+ return 10*orig_fd - 1;
+ }
+
+ fd = rb->creat(tmpname, O_WRONLY);
+ if(fd < 0) {
+ rb->close(orig_fd);
+ return 10*fd - 2;
+ }
+
+ /* First, copy the initial portion (the ID3 tag) */
+ if(fpos) {
+ readlen = rb->read(orig_fd, mp3buf, fpos);
+ if(readlen < 0) {
+ rb->close(fd);
+ rb->close(orig_fd);
+ return 10*readlen - 3;
+ }
+
+ rc = rb->write(fd, mp3buf, readlen);
+ if(rc < 0) {
+ rb->close(fd);
+ rb->close(orig_fd);
+ return 10*rc - 4;
+ }
+ }
+
+ /* Now insert the data into the file */
+ rc = rb->write(fd, buf, num_bytes);
+ if(rc < 0) {
+ rb->close(orig_fd);
+ rb->close(fd);
+ return 10*rc - 5;
+ }
+
+ /* Copy the file */
+ do {
+ readlen = rb->read(orig_fd, mp3buf, mp3buflen);
+ if(readlen < 0) {
+ rb->close(fd);
+ rb->close(orig_fd);
+ return 10*readlen - 7;
+ }
+
+ rc = rb->write(fd, mp3buf, readlen);
+ if(rc < 0) {
+ rb->close(fd);
+ rb->close(orig_fd);
+ return 10*rc - 8;
+ }
+ } while(readlen > 0);
+
+ rb->close(fd);
+ rb->close(orig_fd);
+
+ /* Remove the old file */
+ rc = rb->remove(fname);
+ if(rc < 0) {
+ return 10*rc - 9;
+ }
+
+ /* Replace the old file with the new */
+ rc = rb->rename(tmpname, fname);
+ if(rc < 0) {
+ return 10*rc - 9;
+ }
+
+ return 0;
+}
+
+static void fileerror(int rc)
+{
+ rb->splash(HZ*2, true, "File error: %d", rc);
+}
+
+static const unsigned char empty_id3_header[] =
+{
+ 'I', 'D', '3', 0x04, 0x00, 0x00,
+ 0x00, 0x00, 0x1f, 0x76 /* Size is 4096 minus 10 bytes for the header */
+};
+
+static bool vbr_fix(char *selected_file)
+{
+ unsigned char xingbuf[1500];
+ struct mp3entry entry;
+ int fd;
+ int rc;
+ int flen;
+ int num_frames;
+ int numbytes;
+ int framelen;
+ int unused_space;
+
+ rb->lcd_clear_display();
+ rb->lcd_puts_scroll(0, 0, selected_file);
+#ifdef HAVE_LCD_BITMAP
+ rb->lcd_update();
+#endif
+
+ xingupdate(0);
+
+ rc = rb->mp3info(&entry, selected_file);
+ if(rc < 0) {
+ fileerror(rc);
+ return true;
+ }
+
+ fd = rb->open(selected_file, O_RDWR);
+ if(fd < 0) {
+ fileerror(fd);
+ return true;
+ }
+
+ flen = rb->lseek(fd, 0, SEEK_END);
+
+ xingupdate(0);
+
+ num_frames = rb->count_mp3_frames(fd, entry.first_frame_offset,
+ flen, xingupdate);
+
+ if(num_frames) {
+ /* Note: We don't need to pass a template header because it will be
+ taken from the mpeg stream */
+ framelen = rb->create_xing_header(fd, entry.first_frame_offset,
+ flen, xingbuf, num_frames,
+ 0, xingupdate, true);
+
+ /* Try to fit the Xing header first in the stream. Replace the existing
+ VBR header if there is one, else see if there is room between the
+ ID3 tag and the first MP3 frame. */
+ if(entry.first_frame_offset - entry.id3v2len >=
+ (unsigned int)framelen) {
+ DEBUGF("Using existing space between ID3 and first frame\n");
+
+ /* Seek to the beginning of the unused space */
+ rc = rb->lseek(fd, entry.id3v2len, SEEK_SET);
+ if(rc < 0) {
+ rb->close(fd);
+ fileerror(rc);
+ return true;
+ }
+
+ unused_space =
+ entry.first_frame_offset - entry.id3v2len - framelen;
+
+ /* Fill the unused space with 0's (using the MP3 buffer)
+ and write it to the file */
+ if(unused_space)
+ {
+ rb->memset(mp3buf, 0, unused_space);
+ rc = rb->write(fd, mp3buf, unused_space);
+ if(rc < 0) {
+ rb->close(fd);
+ fileerror(rc);
+ return true;
+ }
+ }
+
+ /* Then write the Xing header */
+ rc = rb->write(fd, xingbuf, framelen);
+ if(rc < 0) {
+ rb->close(fd);
+ fileerror(rc);
+ return true;
+ }
+
+ rb->close(fd);
+ } else {
+ /* If not, insert some space. If there is an ID3 tag in the
+ file we only insert just enough to squeeze the Xing header
+ in. If not, we insert an additional empty ID3 tag of 4K. */
+
+ rb->close(fd);
+
+ /* Nasty trick alert! The insert_data_in_file() function
+ uses the MP3 buffer when copying the data. We assume
+ that the ID3 tag isn't longer than 1MB so the xing
+ buffer won't be overwritten. */
+
+ if(entry.first_frame_offset) {
+ DEBUGF("Inserting %d bytes\n", framelen);
+ numbytes = framelen;
+ } else {
+ DEBUGF("Inserting 4096+%d bytes\n", framelen);
+ numbytes = 4096 + framelen;
+
+ rb->memset(mp3buf + 0x100000, 0, numbytes);
+
+ /* Insert the ID3 header */
+ rb->memcpy(mp3buf + 0x100000, empty_id3_header,
+ sizeof(empty_id3_header));
+ }
+
+ /* Copy the Xing header */
+ rb->memcpy(mp3buf + 0x100000 + numbytes - framelen,
+ xingbuf, framelen);
+
+ rc = insert_data_in_file(selected_file,
+ entry.first_frame_offset,
+ mp3buf + 0x100000, numbytes);
+
+ if(rc < 0) {
+ fileerror(rc);
+ return true;
+ }
+ }
+
+ xingupdate(100);
+ }
+ else
+ {
+ /* Not a VBR file */
+ DEBUGF("Not a VBR file\n");
+ rb->splash(HZ*2, true, "Not a VBR file");
+ }
+
+ return false;
+}
+
+enum plugin_status plugin_start(struct plugin_api* api, void *parameter)
+{
+ TEST_PLUGIN_API(api);
+
+ rb = api;
+
+ if (!parameter)
+ return PLUGIN_ERROR;
+
+ mp3buf = rb->plugin_get_mp3_buffer(&mp3buflen);
+
+ vbr_fix(parameter);
+
+ return PLUGIN_OK;
+}
diff --git a/apps/plugins/viewers.config b/apps/plugins/viewers.config
index ad1e696..2acbe17 100644
--- a/apps/plugins/viewers.config
+++ b/apps/plugins/viewers.config
@@ -3,3 +3,4 @@ txt,viewer.rock,55 55 55 55 55 55
jpg,jpeg.rock,18 24 3C 3C 24 18
ucl,rockbox_flash.rock,2A 7F 41 41 7F 2A
rvf,video.rock,5D 7F 5D 7F 5D 7F
+mp3,vbrfix.rock,10 08 58 38 04 02
diff --git a/firmware/include/file.h b/firmware/include/file.h
index bb0aad6..c58139d 100644
--- a/firmware/include/file.h
+++ b/firmware/include/file.h
@@ -75,18 +75,6 @@ typedef ssize_t (*write_func)(int fd, const void *buf, size_t count);
typedef void (*qsort_func)(void *base, size_t nmemb, size_t size,
int(*_compar)(const void *, const void *));
-
-#if defined(__MINGW32__) && defined(SIMULATOR)
-extern int open(const char*, int flags, ...);
-extern int close(int fd);
-extern int read(int, void*, unsigned int);
-extern long lseek(int, long, int);
-extern int creat(const char *, int);
-extern int write(int, const void*, unsigned int);
-extern int remove(const char*);
-
-#else
-
#ifndef SIMULATOR
extern int open(const char* pathname, int flags);
extern int close(int fd);
@@ -100,6 +88,5 @@ extern int rename(const char* path, const char* newname);
extern int ftruncate(int fd, off_t length);
extern int filesize(int fd);
#endif /* SIMULATOR */
-#endif /* __MINGW32__ */
#endif
diff --git a/uisimulator/x11/dir.h b/uisimulator/common/dir.h
index 48696c2..15332be 100644
--- a/uisimulator/x11/dir.h
+++ b/uisimulator/common/dir.h
@@ -16,35 +16,30 @@
* KIND, either express or implied.
*
****************************************************************************/
-#ifndef _X11_DIR_H_
-#define _X11_DIR_H_
+#ifndef _SIM_DIR_H_
+#define _SIM_DIR_H_
#include <sys/types.h>
-typedef void DIR;
#define DIRFUNCTIONS_DEFINED /* prevent those prototypes */
-#define dirent x11_dirent
+#define dirent sim_dirent
#include "../../firmware/include/dir.h"
#undef dirent
typedef void * MYDIR;
-extern MYDIR *x11_opendir(const char *name);
-extern struct x11_dirent* x11_readdir(MYDIR* dir);
-extern int x11_closedir(MYDIR *dir);
-extern int x11_mkdir(char *name, int mode);
-extern int x11_rmdir(char *name);
-
-#ifndef NO_REDEFINES_PLEASE
+extern MYDIR *sim_opendir(const char *name);
+extern struct sim_dirent* sim_readdir(MYDIR* dir);
+extern int sim_closedir(MYDIR *dir);
+extern int sim_mkdir(char *name, int mode);
+extern int sim_rmdir(char *name);
#define DIR MYDIR
-#define dirent x11_dirent
-#define opendir(x) x11_opendir(x)
-#define readdir(x) x11_readdir(x)
-#define closedir(x) x11_closedir(x)
-#define mkdir(x, y) x11_mkdir(x, y)
-#define rmdir(x) x11_rmdir(x)
-
-#endif
+#define dirent sim_dirent
+#define opendir(x) sim_opendir(x)
+#define readdir(x) sim_readdir(x)
+#define closedir(x) sim_closedir(x)
+#define mkdir(x, y) sim_mkdir(x, y)
+#define rmdir(x) sim_rmdir(x)
#endif
diff --git a/uisimulator/x11/file.h b/uisimulator/common/file.h
index b30167e..8d91b61 100644
--- a/uisimulator/x11/file.h
+++ b/uisimulator/common/file.h
@@ -17,30 +17,46 @@
*
****************************************************************************/
-#ifndef ROCKBOX_FILE_H
-#define ROCKBOX_FILE_H
+#ifndef _SIM_FILE_H_
+#define _SIM_FILE_H_
+#ifdef WIN32
+#include <io.h>
+#include <fcntl.h>
+#else
#include <stdio.h>
+#endif
+
#include <sys/types.h>
-int x11_open(const char *name, int opts);
-int x11_close(int fd);
-int x11_filesize(int fd);
-int x11_creat(const char *name, mode_t mode);
-int x11_remove(char *name);
-int x11_rename(char *oldpath, char *newpath);
+#ifdef WIN32
+#ifndef _commit
+extern int _commit( int handle );
+#endif
+#endif
+
+int sim_open(const char *name, int opts);
+int sim_close(int fd);
+int sim_rename(const char *oldpath, const char *newpath);
+int sim_filesize(int fd);
+int sim_creat(const char *name, mode_t mode);
+int sim_remove(const char *name);
#ifndef NO_REDEFINES_PLEASE
-#define open(x,y) x11_open(x,y)
-#define close(x) x11_close(x)
-#define filesize(x) x11_filesize(x)
-#define creat(x,y) x11_creat(x,y)
-#define remove(x) x11_remove(x)
-#define rename(x,y) x11_rename(x,y)
+#define open(x,y) sim_open(x,y)
+#define close(x) sim_close(x)
+#define filesize(x) sim_filesize(x)
+#define creat(x,y) sim_creat(x,y)
+#define remove(x) sim_remove(x)
+#define rename(x,y) sim_rename(x,y)
+#ifdef WIN32
+#define fsync _commit
+#endif
#endif
#include "../../firmware/include/file.h"
+#ifndef WIN32
int open(const char* pathname, int flags);
int close(int fd);
int printf(const char *format, ...);
@@ -50,5 +66,6 @@ int fsync(int fd);
off_t lseek(int fildes, off_t offset, int whence);
ssize_t read(int fd, void *buf, size_t count);
ssize_t write(int fd, const void *buf, size_t count);
+#endif
#endif
diff --git a/uisimulator/x11/io.c b/uisimulator/common/io.c
index d4d2714..745e417 100644
--- a/uisimulator/x11/io.c
+++ b/uisimulator/common/io.c
@@ -24,7 +24,7 @@
#ifdef __FreeBSD__
#include <sys/param.h>
#include <sys/mount.h>
-#else
+#elif !defined(WIN32)
#include <sys/vfs.h>
#endif
#include <dirent.h>
@@ -34,9 +34,11 @@
#include "debug.h"
#define DIRFUNCTIONS_DEFINED /* prevent those prototypes */
-#define dirent x11_dirent
+#define dirent sim_dirent
+#define DIR SIMDIR
#include "../../firmware/include/dir.h"
#undef dirent
+#undef DIR
#define SIMULATOR_ARCHOS_ROOT "archos"
@@ -47,7 +49,7 @@ struct mydir {
typedef struct mydir MYDIR;
-MYDIR *x11_opendir(const char *name)
+MYDIR *sim_opendir(const char *name)
{
char buffer[256]; /* sufficiently big */
DIR *dir;
@@ -70,15 +72,15 @@ MYDIR *x11_opendir(const char *name)
return (MYDIR *)0;
}
-struct x11_dirent *x11_readdir(MYDIR *dir)
+struct sim_dirent *sim_readdir(MYDIR *dir)
{
char buffer[512]; /* sufficiently big */
- static struct x11_dirent secret;
+ static struct sim_dirent secret;
struct stat s;
struct dirent *x11 = (readdir)(dir->dir);
if(!x11)
- return (struct x11_dirent *)0;
+ return (struct sim_dirent *)0;
strcpy(secret.d_name, x11->d_name);
@@ -93,7 +95,7 @@ struct x11_dirent *x11_readdir(MYDIR *dir)
return &secret;
}
-void x11_closedir(MYDIR *dir)
+void sim_closedir(MYDIR *dir)
{
free(dir->name);
(closedir)(dir->dir);
@@ -102,7 +104,7 @@ void x11_closedir(MYDIR *dir)
}
-int x11_open(const char *name, int opts)
+int sim_open(const char *name, int opts)
{
char buffer[256]; /* sufficiently big */
@@ -115,12 +117,12 @@ int x11_open(const char *name, int opts)
return (open)(name, opts);
}
-int x11_close(int fd)
+int sim_close(int fd)
{
return (close)(fd);
}
-int x11_creat(const char *name, mode_t mode)
+int sim_creat(const char *name, mode_t mode)
{
char buffer[256]; /* sufficiently big */
(void)mode;
@@ -133,20 +135,22 @@ int x11_creat(const char *name, mode_t mode)
return (creat)(name, 0666);
}
-int x11_mkdir(const char *name, mode_t mode)
+int sim_mkdir(const char *name, mode_t mode)
{
char buffer[256]; /* sufficiently big */
(void)mode;
- if(name[0] == '/') {
- sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name);
+
+ sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name);
- debugf("We create the real directory '%s'\n", buffer);
- return (mkdir)(buffer, 0666);
- }
- return (mkdir)(name, 0666);
+ debugf("We create the real directory '%s'\n", buffer);
+#ifdef WIN32
+ return (mkdir)(buffer);
+#else
+ return (mkdir)(buffer, 0666);
+#endif
}
-int x11_rmdir(const char *name)
+int sim_rmdir(const char *name)
{
char buffer[256]; /* sufficiently big */
if(name[0] == '/') {
@@ -158,7 +162,7 @@ int x11_rmdir(const char *name)
return (rmdir)(name);
}
-int x11_remove(char *name)
+int sim_remove(const char *name)
{
char buffer[256]; /* sufficiently big */
@@ -171,7 +175,7 @@ int x11_remove(char *name)
return (remove)(name);
}
-int x11_rename(char *oldpath, char* newpath)
+int sim_rename(const char *oldpath, const char* newpath)
{
char buffer1[256];
char buffer2[256];
@@ -186,7 +190,7 @@ int x11_rename(char *oldpath, char* newpath)
return -1;
}
-int x11_filesize(int fd)
+int sim_filesize(int fd)
{
int old = lseek(fd, 0, SEEK_CUR);
int size = lseek(fd, 0, SEEK_END);
@@ -197,6 +201,10 @@ int x11_filesize(int fd)
void fat_size(unsigned int* size, unsigned int* free)
{
+#ifdef WIN32
+ *size = 2049;
+ *free = 1037;
+#else
struct statfs fs;
if (!statfs(".", &fs)) {
@@ -213,4 +221,5 @@ void fat_size(unsigned int* size, unsigned int* free)
if (free)
*free = 0;
}
+#endif
}
diff --git a/uisimulator/win32/Makefile b/uisimulator/win32/Makefile
index 59ef7f5..402b9ad 100644
--- a/uisimulator/win32/Makefile
+++ b/uisimulator/win32/Makefile
@@ -96,6 +96,8 @@ ifeq ($(DISPLAY),-DHAVE_LCD_BITMAP)
else
LCDSRSC = lcd-playersim.c lcd-player.c lcd-player-charset.c font-player.c
endif
+COMMONSRCS = io.c
+
FIRMSRCS = $(LCDSRSC) id3.c mp3data.c usb.c mpeg.c mp3_playback.c \
powermgmt.c power.c sprintf.c buffer.c lcd-common.c strtok.c random.c \
timefuncs.c
@@ -111,9 +113,9 @@ ifeq ($(DISPLAY),-DHAVE_LCD_BITMAP)
APPS += bmp.c widgets.c
endif
-SRCS = button.c dir-win32.c lcd-win32.c panic-win32.c thread-win32.c \
+SRCS = button.c lcd-win32.c panic-win32.c thread-win32.c \
debug-win32.c kernel.c string-win32.c uisw32.c stubs.c \
- $(APPS) $(MENUS) $(FIRMSRCS) sim_icons.c io.c
+ $(APPS) $(MENUS) $(FIRMSRCS) $(COMMONSRCS) sim_icons.c
OBJS := $(OBJDIR)/lang.o $(SRCS:%.c=$(OBJDIR)/%.o) $(OBJDIR)/uisw32-res.o
@@ -303,6 +305,9 @@ $(OBJDIR)/font-player.o: $(SIMCOMMON)/font-player.c
$(OBJDIR)/sim_icons.o: $(SIMCOMMON)/sim_icons.c
$(CC) $(CFLAGS) -c $< -o $@
+$(OBJDIR)/io.o: $(SIMCOMMON)/io.c
+ $(CC) $(CFLAGS) -c $< -o $@
+
$(OBJDIR)/lcd-playersim.o: $(SIMCOMMON)/lcd-playersim.c
$(CC) $(CFLAGS) -c $< -o $@
@@ -315,7 +320,7 @@ $(OBJDIR)/%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
$(OBJDIR)/%.po : $(PLUGINDIR)/%.c
- $(CC) $(APPCFLAGS) -c $< -o $@
+ $(CC) $(APPCFLAGS) -DPLUGIN -c $< -o $@
$(OBJDIR)/%.rock : $(OBJDIR)/%.po
$(DLLTOOL) $(DLLTOOLFLAGS) -z $(OBJDIR)/$*.def $<
diff --git a/uisimulator/win32/dir-win32.c b/uisimulator/win32/dir-win32.c
deleted file mode 100644
index dfdb636..0000000
--- a/uisimulator/win32/dir-win32.c
+++ /dev/null
@@ -1,97 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2002 by Felix Arends
- *
- * 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 <io.h>
-#include <windows.h>
-#include <malloc.h>
-#include "dir-win32.h"
-
-// Directory operations
-//
-
-// opendir
-// open directory for scanning
-DIR *opendir (
- const char *dirname // directory name
- )
-{
- DIR *p = (DIR*)malloc(sizeof(DIR));
- struct _finddata_t fd;
- unsigned int i;
- char *s = (char*)malloc(strlen(dirname) + 5);
- wsprintf (s, "%s", dirname);
-
- for (i = 0; i < strlen(s); i++)
- if (s[i] == '/')
- s[i] = '\\';
-
- if (s[i - 1] != '\\')
- {
- s[i] = '\\';
- s[++i] = '\0';
- }
-
- OutputDebugString (s);
-
- wsprintf (s, "%s*.*", s);
-
- if ((p->handle = _findfirst (s, &fd)) == -1)
- {
- free (s);
- free (p);
- return 0;
- }
- free (s);
- return p;
-}
-
-// closedir
-// close directory
-int closedir (
- DIR *dir // previously opened dir search
- )
-{
- free(dir);
- return 0;
-}
-
-// read dir
-// read next entry in directory
-struct dirent *readdir (
- DIR *dir
- )
-{
- struct _finddata_t fd;
- if (_findnext (dir->handle, &fd) == -1)
- return 0;
- memcpy (dir->fd.d_name, fd.name, 256);
-
- dir->fd.attribute = fd.attrib & 0x3f;
- dir->fd.size = fd.size;
- dir->fd.startcluster = 0 ;
-
-
- return &dir->fd;
-}
-
-void fat_size(unsigned int* size, unsigned int* free)
-{
- *size = 2049;
- *free = 1037;
-}
diff --git a/uisimulator/win32/dir-win32.h b/uisimulator/win32/dir-win32.h
deleted file mode 100644
index c34a53a..0000000
--- a/uisimulator/win32/dir-win32.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2002 by Felix Arends
- *
- * 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 __DIR_WIN32_H__
-#define __DIR_WIN32_H__
-
-#include <io.h>
-#include "../../firmware/include/dir.h"
-
-#endif // #ifndef __DIR_WIN32_H__
diff --git a/uisimulator/win32/dir.h b/uisimulator/win32/dir.h
deleted file mode 100644
index da5064c..0000000
--- a/uisimulator/win32/dir.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2002 by Bjö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.
- *
- ****************************************************************************/
-#ifndef _DIR_H_
-#define _DIR_H_
-
-#include <stdbool.h>
-#include "file.h"
-
-#ifndef DIRENT_DEFINED
-
-#define ATTR_READ_ONLY 0x01
-#define ATTR_HIDDEN 0x02
-#define ATTR_SYSTEM 0x04
-#define ATTR_VOLUME_ID 0x08
-#define ATTR_DIRECTORY 0x10
-#define ATTR_ARCHIVE 0x20
-
-struct dirent {
- unsigned char d_name[MAX_PATH];
- int attribute;
- int size;
- int startcluster;
-};
-#endif
-
-
-#ifndef SIMULATOR
-
-#include "fat.h"
-
-typedef struct {
- bool busy;
- int startcluster;
- struct fat_dir fatdir;
- struct dirent theent;
-} DIR;
-
-#else // SIMULATOR
-
-#ifdef WIN32
-#ifndef __MINGW32__
-#include <io.h>
-#endif /* __MINGW32__ */
-
-typedef struct DIRtag
-{
- struct dirent fd;
- int handle;
-} DIR;
-
-#endif /* WIN32 */
-
-#endif // SIMULATOR
-
-#ifndef DIRFUNCTIONS_DEFINED
-
-extern DIR* opendir(const char* name);
-extern int closedir(DIR* dir);
-extern int mkdir(const char* name, int mode);
-extern int rmdir(const char* name);
-
-extern struct dirent* readdir(DIR* dir);
-
-#endif /* DIRFUNCTIONS_DEFINED */
-
-#endif
diff --git a/uisimulator/win32/file.h b/uisimulator/win32/file.h
deleted file mode 100644
index 2c94ba3..0000000
--- a/uisimulator/win32/file.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2002 by Daniel Stenberg <daniel@haxx.se>
- *
- * 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 _FILE_H_
-
-#ifndef __MINGW32__
-#include <io.h>
-#include <fcntl.h>
-#endif
-
-#ifndef _commit
-extern int _commit( int handle );
-#endif
-
-int win32_rename(char *oldpath, char *newpath);
-int win32_filesize(int fd);
-
-#define rename win32_rename
-#define filesize win32_filesize
-#define fsync _commit
-
-#include "../../firmware/include/file.h"
-
-#undef rename
-#define mkdir(x,y) win32_mkdir(x,y)
-
-#endif
diff --git a/uisimulator/win32/io.c b/uisimulator/win32/io.c
deleted file mode 100644
index 023e767..0000000
--- a/uisimulator/win32/io.c
+++ /dev/null
@@ -1,63 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2002 Daniel 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 <stdio.h>
-#include "file.h"
-#include "debug.h"
-
-#define SIMULATOR_ARCHOS_ROOT "archos"
-
-int win32_rename(char *oldpath, char* newpath)
-{
- char buffer1[256];
- char buffer2[256];
-
- if(oldpath[0] == '/') {
- sprintf(buffer1, "%s%s", SIMULATOR_ARCHOS_ROOT, oldpath);
- sprintf(buffer2, "%s%s", SIMULATOR_ARCHOS_ROOT, newpath);
-
- debugf("We rename the real file '%s' to '%s'\n", buffer1, buffer2);
- return rename(buffer1, buffer2);
- }
- return -1;
-}
-
-int win32_filesize(int fd)
-{
- int old = lseek(fd, 0, SEEK_CUR);
- int size = lseek(fd, 0, SEEK_END);
- lseek(fd, old, SEEK_SET);
-
- return(size);
-}
-
-extern int (mkdir)(const char *name);
-
-int win32_mkdir(const char *name, int mode)
-{
- char buffer[256]; /* sufficiently big */
- (void)mode;
- if(name[0] == '/') {
- sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name);
-
- debugf("We create the real directory '%s'\n", buffer);
- return (mkdir)(buffer);
- }
- return (mkdir)(name);
-}
diff --git a/uisimulator/win32/kernel.c b/uisimulator/win32/kernel.c
index 44ac88a..77ae6bf 100644
--- a/uisimulator/win32/kernel.c
+++ b/uisimulator/win32/kernel.c
@@ -34,7 +34,7 @@ int set_irq_level (int level)
return (_lv = level);
}
-void sleep(int ticks)
+void sim_sleep(int ticks)
{
Sleep (1000 / HZ * ticks);
}
diff --git a/uisimulator/win32/kernel.h b/uisimulator/win32/kernel.h
index 7cbdd18..7633ce6 100644
--- a/uisimulator/win32/kernel.h
+++ b/uisimulator/win32/kernel.h
@@ -18,3 +18,9 @@
****************************************************************************/
#include "../../firmware/export/kernel.h"
+
+#ifndef NO_REDEFINES_PLEASE
+#define sleep(x) sim_sleep(x)
+#endif
+
+void sim_sleep(int);
diff --git a/uisimulator/x11/Makefile b/uisimulator/x11/Makefile
index 65f0b8d..03b23ac 100644
--- a/uisimulator/x11/Makefile
+++ b/uisimulator/x11/Makefile
@@ -96,6 +96,8 @@ ifeq ($(DISPLAY),-DHAVE_LCD_BITMAP)
else
LCDSRSC = lcd-playersim.c lcd-player.c font-player.c lcd-player-charset.c
endif
+COMMONSRCS = io.c
+
FIRMSRCS = $(LCDSRSC) id3.c debug.c usb.c mpeg.c mp3_playback.c power.c\
powermgmt.c panic.c mp3data.c sprintf.c buffer.c timefuncs.c
@@ -111,8 +113,8 @@ ifeq ($(DISPLAY),-DHAVE_LCD_BITMAP)
endif
SRCS = screenhack.c uibasic.c resources.c visual.c lcd-x11.c stubs.c \
- button-x11.c io.c thread.c sim_icons.c $(APPS) $(MENUS) $(FIRMSRCS) \
- lcd-common.c
+ button-x11.c thread.c sim_icons.c $(APPS) $(MENUS) $(FIRMSRCS) \
+ $(COMMONSRCS) lcd-common.c
ROCKSRC := $(wildcard $(APPDIR)/plugins/*.c)
ROCKS := $(ROCKSRC:$(APPDIR)/plugins/%.c=$(OBJDIR)/%.rock)
@@ -276,6 +278,9 @@ $(OBJDIR)/stubs.o: $(SIMCOMMON)/stubs.c
$(OBJDIR)/sim_icons.o: $(SIMCOMMON)/sim_icons.c
$(CC) $(CFLAGS) -c $< -o $@
+$(OBJDIR)/io.o: $(SIMCOMMON)/io.c
+ $(CC) $(CFLAGS) -c $< -o $@
+
$(OBJDIR)/usb.o: $(FIRMWAREDIR)/usb.c
$(CC) $(CFLAGS) -c $< -o $@
diff --git a/uisimulator/x11/button-x11.c b/uisimulator/x11/button-x11.c
index ae16e2e..eae5531 100644
--- a/uisimulator/x11/button-x11.c
+++ b/uisimulator/x11/button-x11.c
@@ -172,7 +172,7 @@ int button_get_w_tmo(int ticks)
for(i=0; i< ticks; i++) {
bits = get_raw_button();
if(!bits)
- x11_sleep(1);
+ sim_sleep(1);
else
break;
}
@@ -193,14 +193,14 @@ int button_get(bool block)
do {
bits = get_raw_button();
if(block && !bits)
- x11_sleep(HZ/10);
+ sim_sleep(HZ/10);
else
break;
} while(1);
if(!block)
/* delay a bit */
- x11_sleep(1);
+ sim_sleep(1);
return bits;
}
diff --git a/uisimulator/x11/kernel.h b/uisimulator/x11/kernel.h
index a045a3f..f165d92 100644
--- a/uisimulator/x11/kernel.h
+++ b/uisimulator/x11/kernel.h
@@ -21,11 +21,11 @@
#ifndef NO_REDEFINES_PLEASE
-#define sleep(x) x11_sleep(x)
+#define sleep(x) sim_sleep(x)
#define mutex_init(x) (void)x
#define mutex_lock(x) (void)x
#define mutex_unlock(x) (void)x
#endif
-void x11_sleep(int);
+void sim_sleep(int);
diff --git a/uisimulator/x11/thread.c b/uisimulator/x11/thread.c
index 437080a..e37373d 100644
--- a/uisimulator/x11/thread.c
+++ b/uisimulator/x11/thread.c
@@ -85,7 +85,7 @@ int create_thread(void* fp, void* sp, int stk_size)
}
/* ticks is HZ per second */
-void x11_sleep(int ticks)
+void sim_sleep(int ticks)
{
current_tick+=5;
pthread_mutex_unlock(&mp); /* return */