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 c7758afbcf..8d8d25fc99 100644
--- a/apps/plugin.c
+++ b/apps/plugin.c
@@ -21,6 +21,7 @@
21#include <stdio.h> 21#include <stdio.h>
22#include <atoi.h> 22#include <atoi.h>
23#include <timefuncs.h> 23#include <timefuncs.h>
24#include "debug.h"
24#include "button.h" 25#include "button.h"
25#include "lcd.h" 26#include "lcd.h"
26#include "dir.h" 27#include "dir.h"
@@ -39,6 +40,7 @@
39#include "backlight.h" 40#include "backlight.h"
40#include "ata.h" 41#include "ata.h"
41#include "talk.h" 42#include "talk.h"
43#include "mp3data.h"
42 44
43#ifdef HAVE_LCD_BITMAP 45#ifdef HAVE_LCD_BITMAP
44#include "widgets.h" 46#include "widgets.h"
@@ -48,11 +50,10 @@
48 #include <debug.h> 50 #include <debug.h>
49 #ifdef WIN32 51 #ifdef WIN32
50 #include "plugin-win32.h" 52 #include "plugin-win32.h"
51 #define PREFIX(_x_) _x_
52 #else 53 #else
53 #include <dlfcn.h> 54 #include <dlfcn.h>
54 #define PREFIX(_x_) x11_ ## _x_
55 #endif 55 #endif
56 #define PREFIX(_x_) sim_ ## _x_
56#else 57#else
57#define PREFIX(_x_) _x_ 58#define PREFIX(_x_) _x_
58#endif 59#endif
@@ -213,6 +214,12 @@ static struct plugin_api rockbox_api = {
213#ifdef HAVE_LCD_BITMAP 214#ifdef HAVE_LCD_BITMAP
214 font_get, 215 font_get,
215#endif 216#endif
217#if defined(DEBUG) || defined(SIMULATOR)
218 debugf,
219#endif
220 mp3info,
221 count_mp3_frames,
222 create_xing_header,
216}; 223};
217 224
218int plugin_load(char* plugin, void* parameter) 225int plugin_load(char* plugin, void* parameter)
@@ -246,11 +253,8 @@ int plugin_load(char* plugin, void* parameter)
246 lcd_clear_display(); 253 lcd_clear_display();
247#endif 254#endif
248#ifdef SIMULATOR 255#ifdef SIMULATOR
249#ifdef WIN32
250 snprintf(path, sizeof path, "%s", plugin);
251#else
252 snprintf(path, sizeof path, "archos%s", plugin); 256 snprintf(path, sizeof path, "archos%s", plugin);
253#endif 257
254 pd = dlopen(path, RTLD_NOW); 258 pd = dlopen(path, RTLD_NOW);
255 if (!pd) { 259 if (!pd) {
256 snprintf(buf, sizeof buf, "Can't open %s", plugin); 260 snprintf(buf, sizeof buf, "Can't open %s", plugin);
diff --git a/apps/plugin.h b/apps/plugin.h
index f539c3ef3a..c67f49ebda 100644
--- a/apps/plugin.h
+++ b/apps/plugin.h
@@ -45,6 +45,16 @@
45#include "settings.h" 45#include "settings.h"
46#include "thread.h" 46#include "thread.h"
47 47
48#ifdef PLUGIN
49#if defined(DEBUG) || defined(SIMULATOR)
50#define DEBUGF rb->debugf
51#define LDEBUGF rb->debugf
52#else
53#define DEBUGF(...)
54#define LDEBUGF(...)
55#endif
56#endif
57
48/* increase this every time the api struct changes */ 58/* increase this every time the api struct changes */
49#define PLUGIN_API_VERSION 14 59#define PLUGIN_API_VERSION 14
50 60
@@ -235,6 +245,16 @@ struct plugin_api {
235#ifdef HAVE_LCD_BITMAP 245#ifdef HAVE_LCD_BITMAP
236 struct font* (*font_get)(int font); 246 struct font* (*font_get)(int font);
237#endif 247#endif
248#if defined(DEBUG) || defined(SIMULATOR)
249 void (*debugf)(char *fmt, ...);
250#endif
251 bool (*mp3info)(struct mp3entry *entry, char *filename) ;
252 int (*count_mp3_frames)(int fd, int startpos, int filesize,
253 void (*progressfunc)(int));
254 int (*create_xing_header)(int fd, int startpos, int filesize,
255 unsigned char *buf, int num_frames,
256 unsigned long header_template,
257 void (*progressfunc)(int), bool generate_toc);
238}; 258};
239 259
240/* defined by the plugin loader (plugin.c) */ 260/* defined by the plugin loader (plugin.c) */
diff --git a/apps/plugins/Makefile b/apps/plugins/Makefile
index 367103be67..1c703f2573 100644
--- a/apps/plugins/Makefile
+++ b/apps/plugins/Makefile
@@ -15,7 +15,7 @@ FIRMWARE = ../../firmware
15INCLUDES = -I$(FIRMWARE)/include -I$(FIRMWARE)/export -I$(FIRMWARE)/common \ 15INCLUDES = -I$(FIRMWARE)/include -I$(FIRMWARE)/export -I$(FIRMWARE)/common \
16-I$(FIRMWARE)/drivers -I.. -Ilib 16-I$(FIRMWARE)/drivers -I.. -Ilib
17CFLAGS = -O -W -Wall -m1 -nostdlib -ffreestanding -Wstrict-prototypes \ 17CFLAGS = -O -W -Wall -m1 -nostdlib -ffreestanding -Wstrict-prototypes \
18$(INCLUDES) $(TARGET) $(EXTRA_DEFINES) -DMEM=${MEM} 18$(INCLUDES) $(TARGET) $(EXTRA_DEFINES) -DMEM=${MEM} -DPLUGIN
19 19
20LDS := plugin.lds 20LDS := plugin.lds
21LINKFILE := $(OBJDIR)/pluginlink.lds 21LINKFILE := $(OBJDIR)/pluginlink.lds
diff --git a/apps/plugins/vbrfix.c b/apps/plugins/vbrfix.c
new file mode 100644
index 0000000000..1beca2669d
--- /dev/null
+++ b/apps/plugins/vbrfix.c
@@ -0,0 +1,280 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2004 Linus Nielsen Feltzing
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include "plugin.h"
20
21static struct plugin_api* rb;
22
23static char *mp3buf;
24static int mp3buflen;
25
26static void xingupdate(int percent)
27{
28 char buf[32];
29
30 rb->snprintf(buf, 32, "%d%%", percent);
31 rb->lcd_puts(0, 1, buf);
32#ifdef HAVE_LCD_BITMAP
33 rb->lcd_update();
34#endif
35}
36
37static int insert_data_in_file(char *fname, int fpos, char *buf, int num_bytes)
38{
39 int readlen;
40 int rc;
41 int orig_fd, fd;
42 char tmpname[MAX_PATH];
43
44 rb->snprintf(tmpname, MAX_PATH, "%s.tmp", fname);
45
46 orig_fd = rb->open(fname, O_RDONLY);
47 if(orig_fd < 0) {
48 return 10*orig_fd - 1;
49 }
50
51 fd = rb->creat(tmpname, O_WRONLY);
52 if(fd < 0) {
53 rb->close(orig_fd);
54 return 10*fd - 2;
55 }
56
57 /* First, copy the initial portion (the ID3 tag) */
58 if(fpos) {
59 readlen = rb->read(orig_fd, mp3buf, fpos);
60 if(readlen < 0) {
61 rb->close(fd);
62 rb->close(orig_fd);
63 return 10*readlen - 3;
64 }
65
66 rc = rb->write(fd, mp3buf, readlen);
67 if(rc < 0) {
68 rb->close(fd);
69 rb->close(orig_fd);
70 return 10*rc - 4;
71 }
72 }
73
74 /* Now insert the data into the file */
75 rc = rb->write(fd, buf, num_bytes);
76 if(rc < 0) {
77 rb->close(orig_fd);
78 rb->close(fd);
79 return 10*rc - 5;
80 }
81
82 /* Copy the file */
83 do {
84 readlen = rb->read(orig_fd, mp3buf, mp3buflen);
85 if(readlen < 0) {
86 rb->close(fd);
87 rb->close(orig_fd);
88 return 10*readlen - 7;
89 }
90
91 rc = rb->write(fd, mp3buf, readlen);
92 if(rc < 0) {
93 rb->close(fd);
94 rb->close(orig_fd);
95 return 10*rc - 8;
96 }
97 } while(readlen > 0);
98
99 rb->close(fd);
100 rb->close(orig_fd);
101
102 /* Remove the old file */
103 rc = rb->remove(fname);
104 if(rc < 0) {
105 return 10*rc - 9;
106 }
107
108 /* Replace the old file with the new */
109 rc = rb->rename(tmpname, fname);
110 if(rc < 0) {
111 return 10*rc - 9;
112 }
113
114 return 0;
115}
116
117static void fileerror(int rc)
118{
119 rb->splash(HZ*2, true, "File error: %d", rc);
120}
121
122static const unsigned char empty_id3_header[] =
123{
124 'I', 'D', '3', 0x04, 0x00, 0x00,
125 0x00, 0x00, 0x1f, 0x76 /* Size is 4096 minus 10 bytes for the header */
126};
127
128static bool vbr_fix(char *selected_file)
129{
130 unsigned char xingbuf[1500];
131 struct mp3entry entry;
132 int fd;
133 int rc;
134 int flen;
135 int num_frames;
136 int numbytes;
137 int framelen;
138 int unused_space;
139
140 rb->lcd_clear_display();
141 rb->lcd_puts_scroll(0, 0, selected_file);
142#ifdef HAVE_LCD_BITMAP
143 rb->lcd_update();
144#endif
145
146 xingupdate(0);
147
148 rc = rb->mp3info(&entry, selected_file);
149 if(rc < 0) {
150 fileerror(rc);
151 return true;
152 }
153
154 fd = rb->open(selected_file, O_RDWR);
155 if(fd < 0) {
156 fileerror(fd);
157 return true;
158 }
159
160 flen = rb->lseek(fd, 0, SEEK_END);
161
162 xingupdate(0);
163
164 num_frames = rb->count_mp3_frames(fd, entry.first_frame_offset,
165 flen, xingupdate);
166
167 if(num_frames) {
168 /* Note: We don't need to pass a template header because it will be
169 taken from the mpeg stream */
170 framelen = rb->create_xing_header(fd, entry.first_frame_offset,
171 flen, xingbuf, num_frames,
172 0, xingupdate, true);
173
174 /* Try to fit the Xing header first in the stream. Replace the existing
175 VBR header if there is one, else see if there is room between the
176 ID3 tag and the first MP3 frame. */
177 if(entry.first_frame_offset - entry.id3v2len >=
178 (unsigned int)framelen) {
179 DEBUGF("Using existing space between ID3 and first frame\n");
180
181 /* Seek to the beginning of the unused space */
182 rc = rb->lseek(fd, entry.id3v2len, SEEK_SET);
183 if(rc < 0) {
184 rb->close(fd);
185 fileerror(rc);
186 return true;
187 }
188
189 unused_space =
190 entry.first_frame_offset - entry.id3v2len - framelen;
191
192 /* Fill the unused space with 0's (using the MP3 buffer)
193 and write it to the file */
194 if(unused_space)
195 {
196 rb->memset(mp3buf, 0, unused_space);
197 rc = rb->write(fd, mp3buf, unused_space);
198 if(rc < 0) {
199 rb->close(fd);
200 fileerror(rc);
201 return true;
202 }
203 }
204
205 /* Then write the Xing header */
206 rc = rb->write(fd, xingbuf, framelen);
207 if(rc < 0) {
208 rb->close(fd);
209 fileerror(rc);
210 return true;
211 }
212
213 rb->close(fd);
214 } else {
215 /* If not, insert some space. If there is an ID3 tag in the
216 file we only insert just enough to squeeze the Xing header
217 in. If not, we insert an additional empty ID3 tag of 4K. */
218
219 rb->close(fd);
220
221 /* Nasty trick alert! The insert_data_in_file() function
222 uses the MP3 buffer when copying the data. We assume
223 that the ID3 tag isn't longer than 1MB so the xing
224 buffer won't be overwritten. */
225
226 if(entry.first_frame_offset) {
227 DEBUGF("Inserting %d bytes\n", framelen);
228 numbytes = framelen;
229 } else {
230 DEBUGF("Inserting 4096+%d bytes\n", framelen);
231 numbytes = 4096 + framelen;
232
233 rb->memset(mp3buf + 0x100000, 0, numbytes);
234
235 /* Insert the ID3 header */
236 rb->memcpy(mp3buf + 0x100000, empty_id3_header,
237 sizeof(empty_id3_header));
238 }
239
240 /* Copy the Xing header */
241 rb->memcpy(mp3buf + 0x100000 + numbytes - framelen,
242 xingbuf, framelen);
243
244 rc = insert_data_in_file(selected_file,
245 entry.first_frame_offset,
246 mp3buf + 0x100000, numbytes);
247
248 if(rc < 0) {
249 fileerror(rc);
250 return true;
251 }
252 }
253
254 xingupdate(100);
255 }
256 else
257 {
258 /* Not a VBR file */
259 DEBUGF("Not a VBR file\n");
260 rb->splash(HZ*2, true, "Not a VBR file");
261 }
262
263 return false;
264}
265
266enum plugin_status plugin_start(struct plugin_api* api, void *parameter)
267{
268 TEST_PLUGIN_API(api);
269
270 rb = api;
271
272 if (!parameter)
273 return PLUGIN_ERROR;
274
275 mp3buf = rb->plugin_get_mp3_buffer(&mp3buflen);
276
277 vbr_fix(parameter);
278
279 return PLUGIN_OK;
280}
diff --git a/apps/plugins/viewers.config b/apps/plugins/viewers.config
index ad1e696957..2acbe17af3 100644
--- a/apps/plugins/viewers.config
+++ b/apps/plugins/viewers.config
@@ -3,3 +3,4 @@ txt,viewer.rock,55 55 55 55 55 55
3jpg,jpeg.rock,18 24 3C 3C 24 18 3jpg,jpeg.rock,18 24 3C 3C 24 18
4ucl,rockbox_flash.rock,2A 7F 41 41 7F 2A 4ucl,rockbox_flash.rock,2A 7F 41 41 7F 2A
5rvf,video.rock,5D 7F 5D 7F 5D 7F 5rvf,video.rock,5D 7F 5D 7F 5D 7F
6mp3,vbrfix.rock,10 08 58 38 04 02
diff --git a/firmware/include/file.h b/firmware/include/file.h
index bb0aad6b73..c58139d9d0 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);
75typedef void (*qsort_func)(void *base, size_t nmemb, size_t size, 75typedef void (*qsort_func)(void *base, size_t nmemb, size_t size,
76 int(*_compar)(const void *, const void *)); 76 int(*_compar)(const void *, const void *));
77 77
78
79#if defined(__MINGW32__) && defined(SIMULATOR)
80extern int open(const char*, int flags, ...);
81extern int close(int fd);
82extern int read(int, void*, unsigned int);
83extern long lseek(int, long, int);
84extern int creat(const char *, int);
85extern int write(int, const void*, unsigned int);
86extern int remove(const char*);
87
88#else
89
90#ifndef SIMULATOR 78#ifndef SIMULATOR
91extern int open(const char* pathname, int flags); 79extern int open(const char* pathname, int flags);
92extern int close(int fd); 80extern int close(int fd);
@@ -100,6 +88,5 @@ extern int rename(const char* path, const char* newname);
100extern int ftruncate(int fd, off_t length); 88extern int ftruncate(int fd, off_t length);
101extern int filesize(int fd); 89extern int filesize(int fd);
102#endif /* SIMULATOR */ 90#endif /* SIMULATOR */
103#endif /* __MINGW32__ */
104 91
105#endif 92#endif
diff --git a/uisimulator/x11/dir.h b/uisimulator/common/dir.h
index 48696c23b8..15332be54e 100644
--- a/uisimulator/x11/dir.h
+++ b/uisimulator/common/dir.h
@@ -16,35 +16,30 @@
16 * KIND, either express or implied. 16 * KIND, either express or implied.
17 * 17 *
18 ****************************************************************************/ 18 ****************************************************************************/
19#ifndef _X11_DIR_H_ 19#ifndef _SIM_DIR_H_
20#define _X11_DIR_H_ 20#define _SIM_DIR_H_
21 21
22#include <sys/types.h> 22#include <sys/types.h>
23typedef void DIR;
24 23
25#define DIRFUNCTIONS_DEFINED /* prevent those prototypes */ 24#define DIRFUNCTIONS_DEFINED /* prevent those prototypes */
26#define dirent x11_dirent 25#define dirent sim_dirent
27#include "../../firmware/include/dir.h" 26#include "../../firmware/include/dir.h"
28#undef dirent 27#undef dirent
29 28
30typedef void * MYDIR; 29typedef void * MYDIR;
31 30
32extern MYDIR *x11_opendir(const char *name); 31extern MYDIR *sim_opendir(const char *name);
33extern struct x11_dirent* x11_readdir(MYDIR* dir); 32extern struct sim_dirent* sim_readdir(MYDIR* dir);
34extern int x11_closedir(MYDIR *dir); 33extern int sim_closedir(MYDIR *dir);
35extern int x11_mkdir(char *name, int mode); 34extern int sim_mkdir(char *name, int mode);
36extern int x11_rmdir(char *name); 35extern int sim_rmdir(char *name);
37
38#ifndef NO_REDEFINES_PLEASE
39 36
40#define DIR MYDIR 37#define DIR MYDIR
41#define dirent x11_dirent 38#define dirent sim_dirent
42#define opendir(x) x11_opendir(x) 39#define opendir(x) sim_opendir(x)
43#define readdir(x) x11_readdir(x) 40#define readdir(x) sim_readdir(x)
44#define closedir(x) x11_closedir(x) 41#define closedir(x) sim_closedir(x)
45#define mkdir(x, y) x11_mkdir(x, y) 42#define mkdir(x, y) sim_mkdir(x, y)
46#define rmdir(x) x11_rmdir(x) 43#define rmdir(x) sim_rmdir(x)
47
48#endif
49 44
50#endif 45#endif
diff --git a/uisimulator/x11/file.h b/uisimulator/common/file.h
index b30167ecbd..8d91b61831 100644
--- a/uisimulator/x11/file.h
+++ b/uisimulator/common/file.h
@@ -17,30 +17,46 @@
17 * 17 *
18 ****************************************************************************/ 18 ****************************************************************************/
19 19
20#ifndef ROCKBOX_FILE_H 20#ifndef _SIM_FILE_H_
21#define ROCKBOX_FILE_H 21#define _SIM_FILE_H_
22 22
23#ifdef WIN32
24#include <io.h>
25#include <fcntl.h>
26#else
23#include <stdio.h> 27#include <stdio.h>
28#endif
29
24#include <sys/types.h> 30#include <sys/types.h>
25 31
26int x11_open(const char *name, int opts); 32#ifdef WIN32
27int x11_close(int fd); 33#ifndef _commit
28int x11_filesize(int fd); 34extern int _commit( int handle );
29int x11_creat(const char *name, mode_t mode); 35#endif
30int x11_remove(char *name); 36#endif
31int x11_rename(char *oldpath, char *newpath); 37
38int sim_open(const char *name, int opts);
39int sim_close(int fd);
40int sim_rename(const char *oldpath, const char *newpath);
41int sim_filesize(int fd);
42int sim_creat(const char *name, mode_t mode);
43int sim_remove(const char *name);
32 44
33#ifndef NO_REDEFINES_PLEASE 45#ifndef NO_REDEFINES_PLEASE
34#define open(x,y) x11_open(x,y) 46#define open(x,y) sim_open(x,y)
35#define close(x) x11_close(x) 47#define close(x) sim_close(x)
36#define filesize(x) x11_filesize(x) 48#define filesize(x) sim_filesize(x)
37#define creat(x,y) x11_creat(x,y) 49#define creat(x,y) sim_creat(x,y)
38#define remove(x) x11_remove(x) 50#define remove(x) sim_remove(x)
39#define rename(x,y) x11_rename(x,y) 51#define rename(x,y) sim_rename(x,y)
52#ifdef WIN32
53#define fsync _commit
54#endif
40#endif 55#endif
41 56
42#include "../../firmware/include/file.h" 57#include "../../firmware/include/file.h"
43 58
59#ifndef WIN32
44int open(const char* pathname, int flags); 60int open(const char* pathname, int flags);
45int close(int fd); 61int close(int fd);
46int printf(const char *format, ...); 62int printf(const char *format, ...);
@@ -50,5 +66,6 @@ int fsync(int fd);
50off_t lseek(int fildes, off_t offset, int whence); 66off_t lseek(int fildes, off_t offset, int whence);
51ssize_t read(int fd, void *buf, size_t count); 67ssize_t read(int fd, void *buf, size_t count);
52ssize_t write(int fd, const void *buf, size_t count); 68ssize_t write(int fd, const void *buf, size_t count);
69#endif
53 70
54#endif 71#endif
diff --git a/uisimulator/x11/io.c b/uisimulator/common/io.c
index d4d2714026..745e417fa6 100644
--- a/uisimulator/x11/io.c
+++ b/uisimulator/common/io.c
@@ -24,7 +24,7 @@
24#ifdef __FreeBSD__ 24#ifdef __FreeBSD__
25#include <sys/param.h> 25#include <sys/param.h>
26#include <sys/mount.h> 26#include <sys/mount.h>
27#else 27#elif !defined(WIN32)
28#include <sys/vfs.h> 28#include <sys/vfs.h>
29#endif 29#endif
30#include <dirent.h> 30#include <dirent.h>
@@ -34,9 +34,11 @@
34#include "debug.h" 34#include "debug.h"
35 35
36#define DIRFUNCTIONS_DEFINED /* prevent those prototypes */ 36#define DIRFUNCTIONS_DEFINED /* prevent those prototypes */
37#define dirent x11_dirent 37#define dirent sim_dirent
38#define DIR SIMDIR
38#include "../../firmware/include/dir.h" 39#include "../../firmware/include/dir.h"
39#undef dirent 40#undef dirent
41#undef DIR
40 42
41#define SIMULATOR_ARCHOS_ROOT "archos" 43#define SIMULATOR_ARCHOS_ROOT "archos"
42 44
@@ -47,7 +49,7 @@ struct mydir {
47 49
48typedef struct mydir MYDIR; 50typedef struct mydir MYDIR;
49 51
50MYDIR *x11_opendir(const char *name) 52MYDIR *sim_opendir(const char *name)
51{ 53{
52 char buffer[256]; /* sufficiently big */ 54 char buffer[256]; /* sufficiently big */
53 DIR *dir; 55 DIR *dir;
@@ -70,15 +72,15 @@ MYDIR *x11_opendir(const char *name)
70 return (MYDIR *)0; 72 return (MYDIR *)0;
71} 73}
72 74
73struct x11_dirent *x11_readdir(MYDIR *dir) 75struct sim_dirent *sim_readdir(MYDIR *dir)
74{ 76{
75 char buffer[512]; /* sufficiently big */ 77 char buffer[512]; /* sufficiently big */
76 static struct x11_dirent secret; 78 static struct sim_dirent secret;
77 struct stat s; 79 struct stat s;
78 struct dirent *x11 = (readdir)(dir->dir); 80 struct dirent *x11 = (readdir)(dir->dir);
79 81
80 if(!x11) 82 if(!x11)
81 return (struct x11_dirent *)0; 83 return (struct sim_dirent *)0;
82 84
83 strcpy(secret.d_name, x11->d_name); 85 strcpy(secret.d_name, x11->d_name);
84 86
@@ -93,7 +95,7 @@ struct x11_dirent *x11_readdir(MYDIR *dir)
93 return &secret; 95 return &secret;
94} 96}
95 97
96void x11_closedir(MYDIR *dir) 98void sim_closedir(MYDIR *dir)
97{ 99{
98 free(dir->name); 100 free(dir->name);
99 (closedir)(dir->dir); 101 (closedir)(dir->dir);
@@ -102,7 +104,7 @@ void x11_closedir(MYDIR *dir)
102} 104}
103 105
104 106
105int x11_open(const char *name, int opts) 107int sim_open(const char *name, int opts)
106{ 108{
107 char buffer[256]; /* sufficiently big */ 109 char buffer[256]; /* sufficiently big */
108 110
@@ -115,12 +117,12 @@ int x11_open(const char *name, int opts)
115 return (open)(name, opts); 117 return (open)(name, opts);
116} 118}
117 119
118int x11_close(int fd) 120int sim_close(int fd)
119{ 121{
120 return (close)(fd); 122 return (close)(fd);
121} 123}
122 124
123int x11_creat(const char *name, mode_t mode) 125int sim_creat(const char *name, mode_t mode)
124{ 126{
125 char buffer[256]; /* sufficiently big */ 127 char buffer[256]; /* sufficiently big */
126 (void)mode; 128 (void)mode;
@@ -133,20 +135,22 @@ int x11_creat(const char *name, mode_t mode)
133 return (creat)(name, 0666); 135 return (creat)(name, 0666);
134} 136}
135 137
136int x11_mkdir(const char *name, mode_t mode) 138int sim_mkdir(const char *name, mode_t mode)
137{ 139{
138 char buffer[256]; /* sufficiently big */ 140 char buffer[256]; /* sufficiently big */
139 (void)mode; 141 (void)mode;
140 if(name[0] == '/') { 142
141 sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name); 143 sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name);
142 144
143 debugf("We create the real directory '%s'\n", buffer); 145 debugf("We create the real directory '%s'\n", buffer);
144 return (mkdir)(buffer, 0666); 146#ifdef WIN32
145 } 147 return (mkdir)(buffer);
146 return (mkdir)(name, 0666); 148#else
149 return (mkdir)(buffer, 0666);
150#endif
147} 151}
148 152
149int x11_rmdir(const char *name) 153int sim_rmdir(const char *name)
150{ 154{
151 char buffer[256]; /* sufficiently big */ 155 char buffer[256]; /* sufficiently big */
152 if(name[0] == '/') { 156 if(name[0] == '/') {
@@ -158,7 +162,7 @@ int x11_rmdir(const char *name)
158 return (rmdir)(name); 162 return (rmdir)(name);
159} 163}
160 164
161int x11_remove(char *name) 165int sim_remove(const char *name)
162{ 166{
163 char buffer[256]; /* sufficiently big */ 167 char buffer[256]; /* sufficiently big */
164 168
@@ -171,7 +175,7 @@ int x11_remove(char *name)
171 return (remove)(name); 175 return (remove)(name);
172} 176}
173 177
174int x11_rename(char *oldpath, char* newpath) 178int sim_rename(const char *oldpath, const char* newpath)
175{ 179{
176 char buffer1[256]; 180 char buffer1[256];
177 char buffer2[256]; 181 char buffer2[256];
@@ -186,7 +190,7 @@ int x11_rename(char *oldpath, char* newpath)
186 return -1; 190 return -1;
187} 191}
188 192
189int x11_filesize(int fd) 193int sim_filesize(int fd)
190{ 194{
191 int old = lseek(fd, 0, SEEK_CUR); 195 int old = lseek(fd, 0, SEEK_CUR);
192 int size = lseek(fd, 0, SEEK_END); 196 int size = lseek(fd, 0, SEEK_END);
@@ -197,6 +201,10 @@ int x11_filesize(int fd)
197 201
198void fat_size(unsigned int* size, unsigned int* free) 202void fat_size(unsigned int* size, unsigned int* free)
199{ 203{
204#ifdef WIN32
205 *size = 2049;
206 *free = 1037;
207#else
200 struct statfs fs; 208 struct statfs fs;
201 209
202 if (!statfs(".", &fs)) { 210 if (!statfs(".", &fs)) {
@@ -213,4 +221,5 @@ void fat_size(unsigned int* size, unsigned int* free)
213 if (free) 221 if (free)
214 *free = 0; 222 *free = 0;
215 } 223 }
224#endif
216} 225}
diff --git a/uisimulator/win32/Makefile b/uisimulator/win32/Makefile
index 59ef7f5206..402b9addd5 100644
--- a/uisimulator/win32/Makefile
+++ b/uisimulator/win32/Makefile
@@ -96,6 +96,8 @@ ifeq ($(DISPLAY),-DHAVE_LCD_BITMAP)
96else 96else
97 LCDSRSC = lcd-playersim.c lcd-player.c lcd-player-charset.c font-player.c 97 LCDSRSC = lcd-playersim.c lcd-player.c lcd-player-charset.c font-player.c
98endif 98endif
99COMMONSRCS = io.c
100
99FIRMSRCS = $(LCDSRSC) id3.c mp3data.c usb.c mpeg.c mp3_playback.c \ 101FIRMSRCS = $(LCDSRSC) id3.c mp3data.c usb.c mpeg.c mp3_playback.c \
100 powermgmt.c power.c sprintf.c buffer.c lcd-common.c strtok.c random.c \ 102 powermgmt.c power.c sprintf.c buffer.c lcd-common.c strtok.c random.c \
101 timefuncs.c 103 timefuncs.c
@@ -111,9 +113,9 @@ ifeq ($(DISPLAY),-DHAVE_LCD_BITMAP)
111 APPS += bmp.c widgets.c 113 APPS += bmp.c widgets.c
112endif 114endif
113 115
114SRCS = button.c dir-win32.c lcd-win32.c panic-win32.c thread-win32.c \ 116SRCS = button.c lcd-win32.c panic-win32.c thread-win32.c \
115 debug-win32.c kernel.c string-win32.c uisw32.c stubs.c \ 117 debug-win32.c kernel.c string-win32.c uisw32.c stubs.c \
116 $(APPS) $(MENUS) $(FIRMSRCS) sim_icons.c io.c 118 $(APPS) $(MENUS) $(FIRMSRCS) $(COMMONSRCS) sim_icons.c
117 119
118OBJS := $(OBJDIR)/lang.o $(SRCS:%.c=$(OBJDIR)/%.o) $(OBJDIR)/uisw32-res.o 120OBJS := $(OBJDIR)/lang.o $(SRCS:%.c=$(OBJDIR)/%.o) $(OBJDIR)/uisw32-res.o
119 121
@@ -303,6 +305,9 @@ $(OBJDIR)/font-player.o: $(SIMCOMMON)/font-player.c
303$(OBJDIR)/sim_icons.o: $(SIMCOMMON)/sim_icons.c 305$(OBJDIR)/sim_icons.o: $(SIMCOMMON)/sim_icons.c
304 $(CC) $(CFLAGS) -c $< -o $@ 306 $(CC) $(CFLAGS) -c $< -o $@
305 307
308$(OBJDIR)/io.o: $(SIMCOMMON)/io.c
309 $(CC) $(CFLAGS) -c $< -o $@
310
306$(OBJDIR)/lcd-playersim.o: $(SIMCOMMON)/lcd-playersim.c 311$(OBJDIR)/lcd-playersim.o: $(SIMCOMMON)/lcd-playersim.c
307 $(CC) $(CFLAGS) -c $< -o $@ 312 $(CC) $(CFLAGS) -c $< -o $@
308 313
@@ -315,7 +320,7 @@ $(OBJDIR)/%.o: %.c
315 $(CC) $(CFLAGS) -c $< -o $@ 320 $(CC) $(CFLAGS) -c $< -o $@
316 321
317$(OBJDIR)/%.po : $(PLUGINDIR)/%.c 322$(OBJDIR)/%.po : $(PLUGINDIR)/%.c
318 $(CC) $(APPCFLAGS) -c $< -o $@ 323 $(CC) $(APPCFLAGS) -DPLUGIN -c $< -o $@
319 324
320$(OBJDIR)/%.rock : $(OBJDIR)/%.po 325$(OBJDIR)/%.rock : $(OBJDIR)/%.po
321 $(DLLTOOL) $(DLLTOOLFLAGS) -z $(OBJDIR)/$*.def $< 326 $(DLLTOOL) $(DLLTOOLFLAGS) -z $(OBJDIR)/$*.def $<
diff --git a/uisimulator/win32/dir-win32.c b/uisimulator/win32/dir-win32.c
deleted file mode 100644
index dfdb6364f1..0000000000
--- a/uisimulator/win32/dir-win32.c
+++ /dev/null
@@ -1,97 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Felix Arends
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#include <io.h>
21#include <windows.h>
22#include <malloc.h>
23#include "dir-win32.h"
24
25// Directory operations
26//
27
28// opendir
29// open directory for scanning
30DIR *opendir (
31 const char *dirname // directory name
32 )
33{
34 DIR *p = (DIR*)malloc(sizeof(DIR));
35 struct _finddata_t fd;
36 unsigned int i;
37 char *s = (char*)malloc(strlen(dirname) + 5);
38 wsprintf (s, "%s", dirname);
39
40 for (i = 0; i < strlen(s); i++)
41 if (s[i] == '/')
42 s[i] = '\\';
43
44 if (s[i - 1] != '\\')
45 {
46 s[i] = '\\';
47 s[++i] = '\0';
48 }
49
50 OutputDebugString (s);
51
52 wsprintf (s, "%s*.*", s);
53
54 if ((p->handle = _findfirst (s, &fd)) == -1)
55 {
56 free (s);
57 free (p);
58 return 0;
59 }
60 free (s);
61 return p;
62}
63
64// closedir
65// close directory
66int closedir (
67 DIR *dir // previously opened dir search
68 )
69{
70 free(dir);
71 return 0;
72}
73
74// read dir
75// read next entry in directory
76struct dirent *readdir (
77 DIR *dir
78 )
79{
80 struct _finddata_t fd;
81 if (_findnext (dir->handle, &fd) == -1)
82 return 0;
83 memcpy (dir->fd.d_name, fd.name, 256);
84
85 dir->fd.attribute = fd.attrib & 0x3f;
86 dir->fd.size = fd.size;
87 dir->fd.startcluster = 0 ;
88
89
90 return &dir->fd;
91}
92
93void fat_size(unsigned int* size, unsigned int* free)
94{
95 *size = 2049;
96 *free = 1037;
97}
diff --git a/uisimulator/win32/dir-win32.h b/uisimulator/win32/dir-win32.h
deleted file mode 100644
index c34a53aa1e..0000000000
--- a/uisimulator/win32/dir-win32.h
+++ /dev/null
@@ -1,26 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Felix Arends
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#ifndef __DIR_WIN32_H__
21#define __DIR_WIN32_H__
22
23#include <io.h>
24#include "../../firmware/include/dir.h"
25
26#endif // #ifndef __DIR_WIN32_H__
diff --git a/uisimulator/win32/dir.h b/uisimulator/win32/dir.h
deleted file mode 100644
index da5064c1fb..0000000000
--- a/uisimulator/win32/dir.h
+++ /dev/null
@@ -1,82 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Björn Stenberg
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#ifndef _DIR_H_
20#define _DIR_H_
21
22#include <stdbool.h>
23#include "file.h"
24
25#ifndef DIRENT_DEFINED
26
27#define ATTR_READ_ONLY 0x01
28#define ATTR_HIDDEN 0x02
29#define ATTR_SYSTEM 0x04
30#define ATTR_VOLUME_ID 0x08
31#define ATTR_DIRECTORY 0x10
32#define ATTR_ARCHIVE 0x20
33
34struct dirent {
35 unsigned char d_name[MAX_PATH];
36 int attribute;
37 int size;
38 int startcluster;
39};
40#endif
41
42
43#ifndef SIMULATOR
44
45#include "fat.h"
46
47typedef struct {
48 bool busy;
49 int startcluster;
50 struct fat_dir fatdir;
51 struct dirent theent;
52} DIR;
53
54#else // SIMULATOR
55
56#ifdef WIN32
57#ifndef __MINGW32__
58#include <io.h>
59#endif /* __MINGW32__ */
60
61typedef struct DIRtag
62{
63 struct dirent fd;
64 int handle;
65} DIR;
66
67#endif /* WIN32 */
68
69#endif // SIMULATOR
70
71#ifndef DIRFUNCTIONS_DEFINED
72
73extern DIR* opendir(const char* name);
74extern int closedir(DIR* dir);
75extern int mkdir(const char* name, int mode);
76extern int rmdir(const char* name);
77
78extern struct dirent* readdir(DIR* dir);
79
80#endif /* DIRFUNCTIONS_DEFINED */
81
82#endif
diff --git a/uisimulator/win32/file.h b/uisimulator/win32/file.h
deleted file mode 100644
index 2c94ba320a..0000000000
--- a/uisimulator/win32/file.h
+++ /dev/null
@@ -1,43 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Daniel Stenberg <daniel@haxx.se>
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#ifndef _FILE_H_
21
22#ifndef __MINGW32__
23#include <io.h>
24#include <fcntl.h>
25#endif
26
27#ifndef _commit
28extern int _commit( int handle );
29#endif
30
31int win32_rename(char *oldpath, char *newpath);
32int win32_filesize(int fd);
33
34#define rename win32_rename
35#define filesize win32_filesize
36#define fsync _commit
37
38#include "../../firmware/include/file.h"
39
40#undef rename
41#define mkdir(x,y) win32_mkdir(x,y)
42
43#endif
diff --git a/uisimulator/win32/io.c b/uisimulator/win32/io.c
deleted file mode 100644
index 023e767b6a..0000000000
--- a/uisimulator/win32/io.c
+++ /dev/null
@@ -1,63 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 Daniel Stenberg
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#include <stdio.h>
21#include "file.h"
22#include "debug.h"
23
24#define SIMULATOR_ARCHOS_ROOT "archos"
25
26int win32_rename(char *oldpath, char* newpath)
27{
28 char buffer1[256];
29 char buffer2[256];
30
31 if(oldpath[0] == '/') {
32 sprintf(buffer1, "%s%s", SIMULATOR_ARCHOS_ROOT, oldpath);
33 sprintf(buffer2, "%s%s", SIMULATOR_ARCHOS_ROOT, newpath);
34
35 debugf("We rename the real file '%s' to '%s'\n", buffer1, buffer2);
36 return rename(buffer1, buffer2);
37 }
38 return -1;
39}
40
41int win32_filesize(int fd)
42{
43 int old = lseek(fd, 0, SEEK_CUR);
44 int size = lseek(fd, 0, SEEK_END);
45 lseek(fd, old, SEEK_SET);
46
47 return(size);
48}
49
50extern int (mkdir)(const char *name);
51
52int win32_mkdir(const char *name, int mode)
53{
54 char buffer[256]; /* sufficiently big */
55 (void)mode;
56 if(name[0] == '/') {
57 sprintf(buffer, "%s%s", SIMULATOR_ARCHOS_ROOT, name);
58
59 debugf("We create the real directory '%s'\n", buffer);
60 return (mkdir)(buffer);
61 }
62 return (mkdir)(name);
63}
diff --git a/uisimulator/win32/kernel.c b/uisimulator/win32/kernel.c
index 44ac88ae7c..77ae6bffb2 100644
--- a/uisimulator/win32/kernel.c
+++ b/uisimulator/win32/kernel.c
@@ -34,7 +34,7 @@ int set_irq_level (int level)
34 return (_lv = level); 34 return (_lv = level);
35} 35}
36 36
37void sleep(int ticks) 37void sim_sleep(int ticks)
38{ 38{
39 Sleep (1000 / HZ * ticks); 39 Sleep (1000 / HZ * ticks);
40} 40}
diff --git a/uisimulator/win32/kernel.h b/uisimulator/win32/kernel.h
index 7cbdd1889e..7633ce68b4 100644
--- a/uisimulator/win32/kernel.h
+++ b/uisimulator/win32/kernel.h
@@ -18,3 +18,9 @@
18 ****************************************************************************/ 18 ****************************************************************************/
19 19
20#include "../../firmware/export/kernel.h" 20#include "../../firmware/export/kernel.h"
21
22#ifndef NO_REDEFINES_PLEASE
23#define sleep(x) sim_sleep(x)
24#endif
25
26void sim_sleep(int);
diff --git a/uisimulator/x11/Makefile b/uisimulator/x11/Makefile
index 65f0b8d5a2..03b23acef3 100644
--- a/uisimulator/x11/Makefile
+++ b/uisimulator/x11/Makefile
@@ -96,6 +96,8 @@ ifeq ($(DISPLAY),-DHAVE_LCD_BITMAP)
96else 96else
97 LCDSRSC = lcd-playersim.c lcd-player.c font-player.c lcd-player-charset.c 97 LCDSRSC = lcd-playersim.c lcd-player.c font-player.c lcd-player-charset.c
98endif 98endif
99COMMONSRCS = io.c
100
99FIRMSRCS = $(LCDSRSC) id3.c debug.c usb.c mpeg.c mp3_playback.c power.c\ 101FIRMSRCS = $(LCDSRSC) id3.c debug.c usb.c mpeg.c mp3_playback.c power.c\
100 powermgmt.c panic.c mp3data.c sprintf.c buffer.c timefuncs.c 102 powermgmt.c panic.c mp3data.c sprintf.c buffer.c timefuncs.c
101 103
@@ -111,8 +113,8 @@ ifeq ($(DISPLAY),-DHAVE_LCD_BITMAP)
111endif 113endif
112 114
113SRCS = screenhack.c uibasic.c resources.c visual.c lcd-x11.c stubs.c \ 115SRCS = screenhack.c uibasic.c resources.c visual.c lcd-x11.c stubs.c \
114 button-x11.c io.c thread.c sim_icons.c $(APPS) $(MENUS) $(FIRMSRCS) \ 116 button-x11.c thread.c sim_icons.c $(APPS) $(MENUS) $(FIRMSRCS) \
115 lcd-common.c 117 $(COMMONSRCS) lcd-common.c
116 118
117ROCKSRC := $(wildcard $(APPDIR)/plugins/*.c) 119ROCKSRC := $(wildcard $(APPDIR)/plugins/*.c)
118ROCKS := $(ROCKSRC:$(APPDIR)/plugins/%.c=$(OBJDIR)/%.rock) 120ROCKS := $(ROCKSRC:$(APPDIR)/plugins/%.c=$(OBJDIR)/%.rock)
@@ -276,6 +278,9 @@ $(OBJDIR)/stubs.o: $(SIMCOMMON)/stubs.c
276$(OBJDIR)/sim_icons.o: $(SIMCOMMON)/sim_icons.c 278$(OBJDIR)/sim_icons.o: $(SIMCOMMON)/sim_icons.c
277 $(CC) $(CFLAGS) -c $< -o $@ 279 $(CC) $(CFLAGS) -c $< -o $@
278 280
281$(OBJDIR)/io.o: $(SIMCOMMON)/io.c
282 $(CC) $(CFLAGS) -c $< -o $@
283
279$(OBJDIR)/usb.o: $(FIRMWAREDIR)/usb.c 284$(OBJDIR)/usb.o: $(FIRMWAREDIR)/usb.c
280 $(CC) $(CFLAGS) -c $< -o $@ 285 $(CC) $(CFLAGS) -c $< -o $@
281 286
diff --git a/uisimulator/x11/button-x11.c b/uisimulator/x11/button-x11.c
index ae16e2e891..eae55318ad 100644
--- a/uisimulator/x11/button-x11.c
+++ b/uisimulator/x11/button-x11.c
@@ -172,7 +172,7 @@ int button_get_w_tmo(int ticks)
172 for(i=0; i< ticks; i++) { 172 for(i=0; i< ticks; i++) {
173 bits = get_raw_button(); 173 bits = get_raw_button();
174 if(!bits) 174 if(!bits)
175 x11_sleep(1); 175 sim_sleep(1);
176 else 176 else
177 break; 177 break;
178 } 178 }
@@ -193,14 +193,14 @@ int button_get(bool block)
193 do { 193 do {
194 bits = get_raw_button(); 194 bits = get_raw_button();
195 if(block && !bits) 195 if(block && !bits)
196 x11_sleep(HZ/10); 196 sim_sleep(HZ/10);
197 else 197 else
198 break; 198 break;
199 } while(1); 199 } while(1);
200 200
201 if(!block) 201 if(!block)
202 /* delay a bit */ 202 /* delay a bit */
203 x11_sleep(1); 203 sim_sleep(1);
204 204
205 return bits; 205 return bits;
206} 206}
diff --git a/uisimulator/x11/kernel.h b/uisimulator/x11/kernel.h
index a045a3f117..f165d92eb3 100644
--- a/uisimulator/x11/kernel.h
+++ b/uisimulator/x11/kernel.h
@@ -21,11 +21,11 @@
21 21
22#ifndef NO_REDEFINES_PLEASE 22#ifndef NO_REDEFINES_PLEASE
23 23
24#define sleep(x) x11_sleep(x) 24#define sleep(x) sim_sleep(x)
25#define mutex_init(x) (void)x 25#define mutex_init(x) (void)x
26#define mutex_lock(x) (void)x 26#define mutex_lock(x) (void)x
27#define mutex_unlock(x) (void)x 27#define mutex_unlock(x) (void)x
28 28
29#endif 29#endif
30 30
31void x11_sleep(int); 31void sim_sleep(int);
diff --git a/uisimulator/x11/thread.c b/uisimulator/x11/thread.c
index 437080acc9..e37373dc54 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)
85} 85}
86 86
87/* ticks is HZ per second */ 87/* ticks is HZ per second */
88void x11_sleep(int ticks) 88void sim_sleep(int ticks)
89{ 89{
90 current_tick+=5; 90 current_tick+=5;
91 pthread_mutex_unlock(&mp); /* return */ 91 pthread_mutex_unlock(&mp); /* return */