summaryrefslogtreecommitdiff
path: root/uisimulator
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2010-05-15 21:02:47 +0000
committerThomas Martitz <kugel@rockbox.org>2010-05-15 21:02:47 +0000
commit3d0cee8abbaf764958743e8a7851eee94e60a913 (patch)
treea96b1ec825003a71643a7da4707c300f64824f82 /uisimulator
parentdcf442e61f21fb2aef5ce7de0547f733557b156e (diff)
downloadrockbox-3d0cee8abbaf764958743e8a7851eee94e60a913.tar.gz
rockbox-3d0cee8abbaf764958743e8a7851eee94e60a913.zip
- Move uisimulator/sdl/*.[ch] into the target tree, under firmware/target/hosted/sdl, uisdl.c is split up across button-sdl.c and system-sdl.c.
- Refactor the program startup. main() is now in main.c like on target, and the implicit application thread will now act as our main thread (previously a separate one was created for this in thread initialization). This is part of Rockbox as an application and is the first step to make an application port from the uisimulator. In a further step the sim bits from the sdl build will be separated out. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26065 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'uisimulator')
-rw-r--r--uisimulator/common/io.c4
-rw-r--r--uisimulator/common/powermgmt-sim.c4
-rw-r--r--uisimulator/common/stubs.c16
-rw-r--r--uisimulator/sdl/Makefile64
-rw-r--r--uisimulator/sdl/README6
-rw-r--r--uisimulator/sdl/SOURCES15
-rw-r--r--uisimulator/sdl/button-sdl.h46
-rw-r--r--uisimulator/sdl/button.c1907
-rw-r--r--uisimulator/sdl/kernel-sdl.c155
-rw-r--r--uisimulator/sdl/lcd-bitmap.c415
-rw-r--r--uisimulator/sdl/lcd-bitmap.h35
-rw-r--r--uisimulator/sdl/lcd-charcells.c197
-rw-r--r--uisimulator/sdl/lcd-charcells.h34
-rw-r--r--uisimulator/sdl/lcd-remote-bitmap.c110
-rw-r--r--uisimulator/sdl/lcd-remote-bitmap.h32
-rw-r--r--uisimulator/sdl/lcd-sdl.c112
-rw-r--r--uisimulator/sdl/lcd-sdl.h42
-rw-r--r--uisimulator/sdl/sound.c426
-rw-r--r--uisimulator/sdl/sound.h24
-rw-r--r--uisimulator/sdl/system-sdl.h49
-rw-r--r--uisimulator/sdl/thread-sdl.c649
-rw-r--r--uisimulator/sdl/thread-sdl.h37
-rw-r--r--uisimulator/sdl/timefuncs.h7
-rw-r--r--uisimulator/sdl/timer.c61
-rw-r--r--uisimulator/sdl/uisdl.c368
-rw-r--r--uisimulator/sdl/uisdl.h408
-rw-r--r--uisimulator/uisimulator.make7
27 files changed, 4 insertions, 5226 deletions
diff --git a/uisimulator/common/io.c b/uisimulator/common/io.c
index cddb19c9a8..bdcc7e6ca1 100644
--- a/uisimulator/common/io.c
+++ b/uisimulator/common/io.c
@@ -233,7 +233,7 @@ static ssize_t io_trigger_and_wait(int cmd)
233 { 233 {
234 /* Allow other rockbox threads to run */ 234 /* Allow other rockbox threads to run */
235 io.accum = 0; 235 io.accum = 0;
236 mythread = thread_sdl_thread_unlock(); 236 mythread = sim_thread_unlock();
237 } 237 }
238 238
239 switch (cmd) 239 switch (cmd)
@@ -249,7 +249,7 @@ static ssize_t io_trigger_and_wait(int cmd)
249 /* Regain our status as current */ 249 /* Regain our status as current */
250 if (mythread != NULL) 250 if (mythread != NULL)
251 { 251 {
252 thread_sdl_thread_lock(mythread); 252 sim_thread_lock(mythread);
253 } 253 }
254 254
255 return result; 255 return result;
diff --git a/uisimulator/common/powermgmt-sim.c b/uisimulator/common/powermgmt-sim.c
index e2ce8c10d2..dbd3149fbb 100644
--- a/uisimulator/common/powermgmt-sim.c
+++ b/uisimulator/common/powermgmt-sim.c
@@ -157,10 +157,6 @@ void shutdown_hw(void)
157{ 157{
158} 158}
159 159
160void sys_poweroff(void)
161{
162}
163
164void cancel_shutdown(void) 160void cancel_shutdown(void)
165{ 161{
166} 162}
diff --git a/uisimulator/common/stubs.c b/uisimulator/common/stubs.c
index d1ec4ec6c2..d4a9af126c 100644
--- a/uisimulator/common/stubs.c
+++ b/uisimulator/common/stubs.c
@@ -314,25 +314,9 @@ void cpu_sleep(bool enabled)
314 (void)enabled; 314 (void)enabled;
315} 315}
316 316
317void button_set_flip(bool yesno)
318{
319 (void)yesno;
320}
321
322#ifdef HAVE_TOUCHPAD_SENSITIVITY_SETTING 317#ifdef HAVE_TOUCHPAD_SENSITIVITY_SETTING
323void touchpad_set_sensitivity(int level) 318void touchpad_set_sensitivity(int level)
324{ 319{
325 (void)level; 320 (void)level;
326} 321}
327#endif 322#endif
328
329void system_exception_wait(void)
330{
331 thread_sdl_exception_wait();
332}
333
334void system_reboot(void)
335{
336 thread_sdl_exception_wait();
337}
338
diff --git a/uisimulator/sdl/Makefile b/uisimulator/sdl/Makefile
deleted file mode 100644
index dc76b35d68..0000000000
--- a/uisimulator/sdl/Makefile
+++ /dev/null
@@ -1,64 +0,0 @@
1############################################################################
2# __________ __ ___.
3# Open \______ \ ____ ____ | | _\_ |__ _______ ___
4# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7# \/ \/ \/ \/ \/
8# $Id$
9#
10# Copyright (C) 2002, 2008 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
20SIMCOMMON = ../common
21
22DEPFILE = $(OBJDIR)/dep-sim
23
24RM = rm -f
25DEBUG = -g
26
27# Use this for simulator-only files
28INCLUDES = -I. -I$(SIMCOMMON) -I$(OBJDIR) $(TARGET_INC) -I$(FIRMDIR)/export \
29-I$(APPSDIR) -I$(BUILDDIR)
30
31# This sets up 'SRC' based on the files mentioned in SOURCES
32include $(TOOLSDIR)/makesrc.inc
33
34OBJS := $(SRC:%.c=$(OBJDIR)/%.o)
35
36DEFINES := -DHAVE_CONFIG_H -DGETTIMEOFDAY_TWO_ARGS -DSIMULATOR \
37$(TARGET) -DAPPSVERSION=\"$(VERSION)\" -DMEM=${MEMORYSIZE} $(EXTRA_DEFINES)
38
39SOURCES = $(SRC)
40
41DIRS = .
42
43CFLAGS = $(DEBUG) $(DEFINES) $(INCLUDES) $(GCCOPTS) -W -Wall
44
45OUTFILE = $(BUILDDIR)/libsim.a
46
47all: $(OUTFILE)
48
49include $(TOOLSDIR)/make.inc
50
51$(OUTFILE): $(OBJS) $(BUILDDIR)/UI256.bmp
52 $(call PRINTS,AR+RANLIB $(@F))$(AR) ruv $@ $(OBJS) >/dev/null 2>&1
53 $(SILENT)$(RANLIB) $@
54
55clean:
56 $(call PRINTS,cleaning sim)$(RM) $(OBJS) *~ core $(OUTFILE) $(DEPFILE) \
57 $(BUILDDIR)/UI256.bmp $(DEPFILE)
58 $(SILENT)$(MAKE) -C $(SIMCOMMON) clean
59
60################## Specific dependencies ##################
61$(BUILDDIR)/UI256.bmp: UI-$(MODELNAME).bmp
62 $(call PRINTS,UI)cp $< $@
63
64-include $(DEPFILE)
diff --git a/uisimulator/sdl/README b/uisimulator/sdl/README
deleted file mode 100644
index 0a293f6ad2..0000000000
--- a/uisimulator/sdl/README
+++ /dev/null
@@ -1,6 +0,0 @@
1To build:
2
3 $ ../tools/configure
4 [answer questions]
5 $ make
6 $ ./rockboxui
diff --git a/uisimulator/sdl/SOURCES b/uisimulator/sdl/SOURCES
deleted file mode 100644
index 1d5b498248..0000000000
--- a/uisimulator/sdl/SOURCES
+++ /dev/null
@@ -1,15 +0,0 @@
1button.c
2kernel-sdl.c
3#ifdef HAVE_LCD_BITMAP
4lcd-bitmap.c
5#elif defined(HAVE_LCD_CHARCELLS)
6lcd-charcells.c
7#endif
8#ifdef HAVE_REMOTE_LCD
9lcd-remote-bitmap.c
10#endif
11lcd-sdl.c
12sound.c
13timer.c
14thread-sdl.c
15uisdl.c
diff --git a/uisimulator/sdl/button-sdl.h b/uisimulator/sdl/button-sdl.h
deleted file mode 100644
index 948af62c5b..0000000000
--- a/uisimulator/sdl/button-sdl.h
+++ /dev/null
@@ -1,46 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2009 by Thomas Martitz
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22
23#ifndef _BUTTON_SDL_H_
24#define _BUTTON_SDL_H_
25
26#include <stdbool.h>
27#include "config.h"
28#include "button-target.h"
29
30#undef HAVE_LCD_FLIP
31
32#undef button_init_device
33#define button_init_device()
34
35struct button_map {
36 int button, x, y, radius;
37 char *description;
38};
39
40int xy2button( int x, int y);
41bool button_hold(void);
42void button_init_sdl(void);
43#undef button_init_device
44#define button_init_device() button_init_sdl()
45
46#endif
diff --git a/uisimulator/sdl/button.c b/uisimulator/sdl/button.c
deleted file mode 100644
index 2bb7764782..0000000000
--- a/uisimulator/sdl/button.c
+++ /dev/null
@@ -1,1907 +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 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "uisdl.h"
23#include "lcd-charcells.h"
24#include "lcd-remote.h"
25#include "config.h"
26#include "button.h"
27#include "kernel.h"
28#include "backlight.h"
29#include "misc.h"
30#include "sim_tasks.h"
31#include "button-sdl.h"
32#include "backlight.h"
33
34#include "debug.h"
35
36#ifdef HAVE_TOUCHSCREEN
37#include "touchscreen.h"
38static int mouse_coords = 0;
39#endif
40/* how long until repeat kicks in */
41#define REPEAT_START 6
42
43/* the speed repeat starts at */
44#define REPEAT_INTERVAL_START 4
45
46/* speed repeat finishes at */
47#define REPEAT_INTERVAL_FINISH 2
48
49#ifdef HAVE_TOUCHSCREEN
50#define USB_KEY SDLK_c /* SDLK_u is taken by BUTTON_MIDLEFT */
51#else
52#define USB_KEY SDLK_u
53#endif
54
55#if defined(IRIVER_H100_SERIES) || defined (IRIVER_H300_SERIES)
56int _remote_type=REMOTETYPE_H100_LCD;
57
58int remote_type(void)
59{
60 return _remote_type;
61}
62#endif
63
64struct event_queue button_queue;
65
66static int btn = 0; /* Hopefully keeps track of currently pressed keys... */
67
68#ifdef HAS_BUTTON_HOLD
69bool hold_button_state = false;
70bool button_hold(void) {
71 return hold_button_state;
72}
73#endif
74
75#ifdef HAS_REMOTE_BUTTON_HOLD
76bool remote_hold_button_state = false;
77bool remote_button_hold(void) {
78 return remote_hold_button_state;
79}
80#endif
81
82void button_event(int key, bool pressed)
83{
84 int new_btn = 0;
85 static bool usb_connected = false;
86 if (usb_connected && key != USB_KEY)
87 return;
88 switch (key)
89 {
90
91#ifdef HAVE_TOUCHSCREEN
92 case BUTTON_TOUCHSCREEN:
93 switch (touchscreen_get_mode())
94 {
95 case TOUCHSCREEN_POINT:
96 new_btn = BUTTON_TOUCHSCREEN;
97 break;
98 case TOUCHSCREEN_BUTTON:
99 {
100 static int touchscreen_buttons[3][3] = {
101 {BUTTON_TOPLEFT, BUTTON_TOPMIDDLE, BUTTON_TOPRIGHT},
102 {BUTTON_MIDLEFT, BUTTON_CENTER, BUTTON_MIDRIGHT},
103 {BUTTON_BOTTOMLEFT, BUTTON_BOTTOMMIDDLE, BUTTON_BOTTOMRIGHT},
104 };
105 int px_x = ((mouse_coords&0xffff0000)>>16);
106 int px_y = ((mouse_coords&0x0000ffff));
107 new_btn = touchscreen_buttons[px_y/(LCD_HEIGHT/3)][px_x/(LCD_WIDTH/3)];
108 break;
109 }
110 }
111 break;
112 case SDLK_KP7:
113 case SDLK_7:
114 new_btn = BUTTON_TOPLEFT;
115 break;
116 case SDLK_KP8:
117 case SDLK_8:
118 case SDLK_UP:
119 new_btn = BUTTON_TOPMIDDLE;
120 break;
121 case SDLK_KP9:
122 case SDLK_9:
123 new_btn = BUTTON_TOPRIGHT;
124 break;
125 case SDLK_KP4:
126 case SDLK_u:
127 case SDLK_LEFT:
128 new_btn = BUTTON_MIDLEFT;
129 break;
130 case SDLK_KP5:
131 case SDLK_i:
132 new_btn = BUTTON_CENTER;
133 break;
134 case SDLK_KP6:
135 case SDLK_o:
136 case SDLK_RIGHT:
137 new_btn = BUTTON_MIDRIGHT;
138 break;
139 case SDLK_KP1:
140 case SDLK_j:
141 new_btn = BUTTON_BOTTOMLEFT;
142 break;
143 case SDLK_KP2:
144 case SDLK_k:
145 case SDLK_DOWN:
146 new_btn = BUTTON_BOTTOMMIDDLE;
147 break;
148 case SDLK_KP3:
149 case SDLK_l:
150 new_btn = BUTTON_BOTTOMRIGHT;
151 break;
152 case SDLK_F4:
153 if(pressed)
154 {
155 touchscreen_set_mode(touchscreen_get_mode() == TOUCHSCREEN_POINT ? TOUCHSCREEN_BUTTON : TOUCHSCREEN_POINT);
156 printf("Touchscreen mode: %s\n", touchscreen_get_mode() == TOUCHSCREEN_POINT ? "TOUCHSCREEN_POINT" : "TOUCHSCREEN_BUTTON");
157 }
158 break;
159
160#endif
161 case USB_KEY:
162 if (!pressed)
163 {
164 usb_connected = !usb_connected;
165 if (usb_connected)
166 queue_post(&button_queue, SYS_USB_CONNECTED, 0);
167 else
168 queue_post(&button_queue, SYS_USB_DISCONNECTED, 0);
169 }
170 return;
171
172#ifdef HAS_BUTTON_HOLD
173 case SDLK_h:
174 if(pressed)
175 {
176 hold_button_state = !hold_button_state;
177 DEBUGF("Hold button is %s\n", hold_button_state?"ON":"OFF");
178 }
179 return;
180#endif
181
182#ifdef HAS_REMOTE_BUTTON_HOLD
183 case SDLK_j:
184 if(pressed)
185 {
186 remote_hold_button_state = !remote_hold_button_state;
187 DEBUGF("Remote hold button is %s\n",
188 remote_hold_button_state?"ON":"OFF");
189 }
190 return;
191#endif
192
193#if CONFIG_KEYPAD == GIGABEAT_PAD
194 case SDLK_KP4:
195 case SDLK_LEFT:
196 new_btn = BUTTON_LEFT;
197 break;
198 case SDLK_KP6:
199 case SDLK_RIGHT:
200 new_btn = BUTTON_RIGHT;
201 break;
202 case SDLK_KP8:
203 case SDLK_UP:
204 new_btn = BUTTON_UP;
205 break;
206 case SDLK_KP2:
207 case SDLK_DOWN:
208 new_btn = BUTTON_DOWN;
209 break;
210 case SDLK_KP_PLUS:
211 case SDLK_F8:
212 new_btn = BUTTON_POWER;
213 break;
214 case SDLK_ESCAPE:
215 new_btn = BUTTON_POWER;
216 break;
217 case SDLK_KP_ENTER:
218 case SDLK_RETURN:
219 case SDLK_a:
220 new_btn = BUTTON_A;
221 break;
222 case SDLK_KP5:
223 case SDLK_SPACE:
224 new_btn = BUTTON_SELECT;
225 break;
226 case SDLK_KP_PERIOD:
227 case SDLK_INSERT:
228 new_btn = BUTTON_MENU;
229 break;
230 case SDLK_KP9:
231 new_btn = BUTTON_VOL_UP;
232 break;
233 case SDLK_KP3:
234 new_btn = BUTTON_VOL_DOWN;
235 break;
236
237#elif CONFIG_KEYPAD == GIGABEAT_S_PAD
238 case SDLK_KP4:
239 case SDLK_LEFT:
240 new_btn = BUTTON_LEFT;
241 break;
242 case SDLK_KP6:
243 case SDLK_RIGHT:
244 new_btn = BUTTON_RIGHT;
245 break;
246 case SDLK_KP8:
247 case SDLK_UP:
248 new_btn = BUTTON_UP;
249 break;
250 case SDLK_KP2:
251 case SDLK_DOWN:
252 new_btn = BUTTON_DOWN;
253 break;
254 case SDLK_F8:
255 case SDLK_ESCAPE:
256 new_btn = BUTTON_POWER;
257 break;
258 case SDLK_KP_PLUS:
259 case SDLK_KP_ENTER:
260 case SDLK_RETURN:
261 new_btn = BUTTON_PLAY;
262 break;
263 case SDLK_KP7:
264 new_btn = BUTTON_BACK;
265 break;
266 case SDLK_KP5:
267 case SDLK_SPACE:
268 new_btn = BUTTON_SELECT;
269 break;
270 case SDLK_KP9:
271 case SDLK_KP_PERIOD:
272 case SDLK_INSERT:
273 new_btn = BUTTON_MENU;
274 break;
275
276#elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
277 case SDLK_KP4:
278 case SDLK_LEFT:
279 new_btn = BUTTON_LEFT;
280 break;
281 case SDLK_KP6:
282 case SDLK_RIGHT:
283 new_btn = BUTTON_RIGHT;
284 break;
285 case SDLK_KP8:
286 case SDLK_UP:
287 new_btn = BUTTON_UP;
288 break;
289 case SDLK_KP2:
290 case SDLK_DOWN:
291 new_btn = BUTTON_DOWN;
292 break;
293 case SDLK_KP_PLUS:
294 case SDLK_F8:
295 new_btn = BUTTON_PLAY;
296 break;
297 case SDLK_ESCAPE:
298 new_btn = BUTTON_POWER;
299 break;
300 case SDLK_KP_ENTER:
301 case SDLK_RETURN:
302 case SDLK_a:
303 new_btn = BUTTON_POWER;
304 break;
305 case SDLK_KP_DIVIDE:
306 case SDLK_F1:
307 new_btn = BUTTON_REC;
308 break;
309 case SDLK_KP5:
310 case SDLK_SPACE:
311 new_btn = BUTTON_SELECT;
312 break;
313
314#elif CONFIG_KEYPAD == IAUDIO_M3_PAD
315 case SDLK_KP4:
316 new_btn = BUTTON_LEFT;
317 break;
318 case SDLK_LEFT:
319 new_btn = BUTTON_RC_REW;
320 break;
321 case SDLK_KP6:
322 new_btn = BUTTON_RIGHT;
323 break;
324 case SDLK_RIGHT:
325 new_btn = BUTTON_RC_FF;
326 break;
327 case SDLK_KP8:
328 new_btn = BUTTON_VOL_UP;
329 break;
330 case SDLK_UP:
331 new_btn = BUTTON_RC_VOL_UP;
332 break;
333 case SDLK_KP2:
334 new_btn = BUTTON_VOL_DOWN;
335 break;
336 case SDLK_DOWN:
337 new_btn = BUTTON_RC_VOL_DOWN;
338 break;
339 case SDLK_KP_PERIOD:
340 new_btn = BUTTON_MODE;
341 break;
342 case SDLK_INSERT:
343 new_btn = BUTTON_RC_MODE;
344 break;
345 case SDLK_KP_DIVIDE:
346 new_btn = BUTTON_REC;
347 break;
348 case SDLK_F1:
349 new_btn = BUTTON_RC_REC;
350 break;
351 case SDLK_KP5:
352 new_btn = BUTTON_PLAY;
353 break;
354 case SDLK_SPACE:
355 new_btn = BUTTON_RC_PLAY;
356 break;
357 case SDLK_KP_ENTER:
358 case SDLK_RETURN:
359 new_btn = BUTTON_RC_MENU;
360 break;
361
362#elif (CONFIG_KEYPAD == IPOD_1G2G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) \
363 || (CONFIG_KEYPAD == IPOD_4G_PAD)
364 case SDLK_KP4:
365 case SDLK_LEFT:
366 new_btn = BUTTON_LEFT;
367 break;
368 case SDLK_KP6:
369 case SDLK_RIGHT:
370 new_btn = BUTTON_RIGHT;
371 break;
372 case SDLK_KP8:
373 case SDLK_UP:
374 new_btn = BUTTON_SCROLL_BACK;
375 break;
376 case SDLK_KP2:
377 case SDLK_DOWN:
378 new_btn = BUTTON_SCROLL_FWD;
379 break;
380 case SDLK_KP_PLUS:
381 case SDLK_F8:
382 new_btn = BUTTON_PLAY;
383 break;
384 case SDLK_KP5:
385 case SDLK_SPACE:
386 new_btn = BUTTON_SELECT;
387 break;
388 case SDLK_KP_PERIOD:
389 case SDLK_INSERT:
390 new_btn = BUTTON_MENU;
391 break;
392
393#elif CONFIG_KEYPAD == IRIVER_H10_PAD
394 case SDLK_KP4:
395 case SDLK_LEFT:
396 new_btn = BUTTON_LEFT;
397 break;
398 case SDLK_KP6:
399 case SDLK_RIGHT:
400 new_btn = BUTTON_RIGHT;
401 break;
402 case SDLK_KP8:
403 case SDLK_UP:
404 new_btn = BUTTON_SCROLL_UP;
405 break;
406 case SDLK_KP2:
407 case SDLK_DOWN:
408 new_btn = BUTTON_SCROLL_DOWN;
409 break;
410 case SDLK_KP_PLUS:
411 case SDLK_F8:
412 new_btn = BUTTON_POWER;
413 break;
414 case SDLK_ESCAPE:
415 new_btn = BUTTON_POWER;
416 break;
417 case SDLK_KP_DIVIDE:
418 case SDLK_F1:
419 new_btn = BUTTON_REW;
420 break;
421 case SDLK_KP_MULTIPLY:
422 case SDLK_F2:
423 new_btn = BUTTON_FF;
424 break;
425 case SDLK_KP5:
426 case SDLK_SPACE:
427 new_btn = BUTTON_PLAY;
428 break;
429
430#elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
431 case SDLK_t:
432 if(pressed)
433 switch(_remote_type)
434 {
435 case REMOTETYPE_UNPLUGGED:
436 _remote_type=REMOTETYPE_H100_LCD;
437 DEBUGF("Changed remote type to H100\n");
438 break;
439 case REMOTETYPE_H100_LCD:
440 _remote_type=REMOTETYPE_H300_LCD;
441 DEBUGF("Changed remote type to H300\n");
442 break;
443 case REMOTETYPE_H300_LCD:
444 _remote_type=REMOTETYPE_H300_NONLCD;
445 DEBUGF("Changed remote type to H300 NON-LCD\n");
446 break;
447 case REMOTETYPE_H300_NONLCD:
448 _remote_type=REMOTETYPE_UNPLUGGED;
449 DEBUGF("Changed remote type to none\n");
450 break;
451 }
452 break;
453 case SDLK_KP4:
454 case SDLK_LEFT:
455 new_btn = BUTTON_LEFT;
456 break;
457 case SDLK_KP6:
458 case SDLK_RIGHT:
459 new_btn = BUTTON_RIGHT;
460 break;
461 case SDLK_KP8:
462 case SDLK_UP:
463 new_btn = BUTTON_UP;
464 break;
465 case SDLK_KP2:
466 case SDLK_DOWN:
467 new_btn = BUTTON_DOWN;
468 break;
469 case SDLK_KP_PLUS:
470 case SDLK_F8:
471 new_btn = BUTTON_ON;
472 break;
473 case SDLK_KP_ENTER:
474 case SDLK_RETURN:
475 case SDLK_a:
476 new_btn = BUTTON_OFF;
477 break;
478 case SDLK_KP_DIVIDE:
479 case SDLK_F1:
480 new_btn = BUTTON_REC;
481 break;
482 case SDLK_KP5:
483 case SDLK_SPACE:
484 new_btn = BUTTON_SELECT;
485 break;
486 case SDLK_KP_PERIOD:
487 case SDLK_INSERT:
488 new_btn = BUTTON_MODE;
489 break;
490
491#elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
492 case SDLK_KP4:
493 case SDLK_LEFT:
494 new_btn = BUTTON_LEFT;
495 break;
496 case SDLK_KP6:
497 case SDLK_RIGHT:
498 new_btn = BUTTON_RIGHT;
499 break;
500 case SDLK_KP8:
501 case SDLK_UP:
502 new_btn = BUTTON_UP;
503 break;
504 case SDLK_KP2:
505 case SDLK_DOWN:
506 new_btn = BUTTON_DOWN;
507 break;
508 case SDLK_KP_PLUS:
509 case SDLK_F8:
510 new_btn = BUTTON_PLAY;
511 break;
512 case SDLK_KP_ENTER:
513 case SDLK_RETURN:
514 case SDLK_a:
515 new_btn = BUTTON_EQ;
516 break;
517 case SDLK_KP5:
518 case SDLK_SPACE:
519 new_btn = BUTTON_SELECT;
520 break;
521 case SDLK_KP_PERIOD:
522 case SDLK_INSERT:
523 new_btn = BUTTON_MODE;
524 break;
525
526#elif CONFIG_KEYPAD == ONDIO_PAD
527 case SDLK_KP4:
528 case SDLK_LEFT:
529 new_btn = BUTTON_LEFT;
530 break;
531 case SDLK_KP6:
532 case SDLK_RIGHT:
533 new_btn = BUTTON_RIGHT;
534 break;
535 case SDLK_KP8:
536 case SDLK_UP:
537 new_btn = BUTTON_UP;
538 break;
539 case SDLK_KP2:
540 case SDLK_DOWN:
541 new_btn = BUTTON_DOWN;
542 break;
543 case SDLK_KP_ENTER:
544 case SDLK_RETURN:
545 case SDLK_a:
546 new_btn = BUTTON_OFF;
547 break;
548 case SDLK_KP_PERIOD:
549 case SDLK_INSERT:
550 new_btn = BUTTON_MENU;
551 break;
552
553#elif CONFIG_KEYPAD == PLAYER_PAD
554 case SDLK_KP4:
555 case SDLK_LEFT:
556 new_btn = BUTTON_LEFT;
557 break;
558 case SDLK_KP6:
559 case SDLK_RIGHT:
560 new_btn = BUTTON_RIGHT;
561 break;
562 case SDLK_KP8:
563 case SDLK_UP:
564 new_btn = BUTTON_PLAY;
565 break;
566 case SDLK_KP2:
567 case SDLK_DOWN:
568 new_btn = BUTTON_STOP;
569 break;
570 case SDLK_KP_PLUS:
571 case SDLK_F8:
572 new_btn = BUTTON_ON;
573 break;
574 case SDLK_KP_PERIOD:
575 case SDLK_INSERT:
576 new_btn = BUTTON_MENU;
577 break;
578
579#elif CONFIG_KEYPAD == RECORDER_PAD
580 case SDLK_KP4:
581 case SDLK_LEFT:
582 new_btn = BUTTON_LEFT;
583 break;
584 case SDLK_KP6:
585 case SDLK_RIGHT:
586 new_btn = BUTTON_RIGHT;
587 break;
588 case SDLK_KP8:
589 case SDLK_UP:
590 new_btn = BUTTON_UP;
591 break;
592 case SDLK_KP2:
593 case SDLK_DOWN:
594 new_btn = BUTTON_DOWN;
595 break;
596 case SDLK_KP_PLUS:
597 case SDLK_F8:
598 new_btn = BUTTON_ON;
599 break;
600 case SDLK_KP_ENTER:
601 case SDLK_RETURN:
602 case SDLK_a:
603 new_btn = BUTTON_OFF;
604 break;
605 case SDLK_KP_DIVIDE:
606 case SDLK_F1:
607 new_btn = BUTTON_F1;
608 break;
609 case SDLK_KP_MULTIPLY:
610 case SDLK_F2:
611 new_btn = BUTTON_F2;
612 break;
613 case SDLK_KP_MINUS:
614 case SDLK_F3:
615 new_btn = BUTTON_F3;
616 break;
617 case SDLK_KP5:
618 case SDLK_SPACE:
619 new_btn = BUTTON_PLAY;
620 break;
621
622#elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
623 case SDLK_KP4:
624 case SDLK_LEFT:
625 new_btn = BUTTON_LEFT;
626 break;
627 case SDLK_KP6:
628 case SDLK_RIGHT:
629 new_btn = BUTTON_RIGHT;
630 break;
631 case SDLK_KP8:
632 case SDLK_UP:
633 new_btn = BUTTON_UP;
634 break;
635 case SDLK_KP2:
636 case SDLK_DOWN:
637 new_btn = BUTTON_DOWN;
638 break;
639 case SDLK_KP_PLUS:
640 case SDLK_F8:
641 new_btn = BUTTON_ON;
642 break;
643 case SDLK_KP_ENTER:
644 case SDLK_RETURN:
645 case SDLK_a:
646 new_btn = BUTTON_OFF;
647 break;
648 case SDLK_KP_DIVIDE:
649 case SDLK_F1:
650 new_btn = BUTTON_F1;
651 break;
652 case SDLK_KP_MULTIPLY:
653 case SDLK_F2:
654 new_btn = BUTTON_F2;
655 break;
656 case SDLK_KP_MINUS:
657 case SDLK_F3:
658 new_btn = BUTTON_F3;
659 break;
660 case SDLK_KP5:
661 case SDLK_SPACE:
662 new_btn = BUTTON_SELECT;
663 break;
664
665#elif CONFIG_KEYPAD == SANSA_E200_PAD
666 case SDLK_KP4:
667 case SDLK_LEFT:
668 new_btn = BUTTON_LEFT;
669 break;
670 case SDLK_KP6:
671 case SDLK_RIGHT:
672 new_btn = BUTTON_RIGHT;
673 break;
674 case SDLK_KP8:
675 case SDLK_UP:
676 new_btn = BUTTON_SCROLL_BACK;
677 break;
678 case SDLK_KP2:
679 case SDLK_DOWN:
680 new_btn = BUTTON_SCROLL_FWD;
681 break;
682 case SDLK_KP9:
683 case SDLK_PAGEUP:
684 new_btn = BUTTON_UP;
685 break;
686 case SDLK_KP3:
687 case SDLK_PAGEDOWN:
688 new_btn = BUTTON_DOWN;
689 break;
690 case SDLK_KP1:
691 case SDLK_HOME:
692 new_btn = BUTTON_POWER;
693 break;
694 case SDLK_KP7:
695 case SDLK_END:
696 new_btn = BUTTON_REC;
697 break;
698 case SDLK_KP5:
699 case SDLK_SPACE:
700 new_btn = BUTTON_SELECT;
701 break;
702
703#elif CONFIG_KEYPAD == SANSA_C200_PAD
704 case SDLK_KP4:
705 case SDLK_LEFT:
706 new_btn = BUTTON_LEFT;
707 break;
708 case SDLK_KP6:
709 case SDLK_RIGHT:
710 new_btn = BUTTON_RIGHT;
711 break;
712 case SDLK_KP8:
713 case SDLK_UP:
714 new_btn = BUTTON_UP;
715 break;
716 case SDLK_KP2:
717 case SDLK_DOWN:
718 new_btn = BUTTON_DOWN;
719 break;
720 case SDLK_KP3:
721 new_btn = BUTTON_POWER;
722 break;
723 case SDLK_KP1:
724 new_btn = BUTTON_REC;
725 break;
726 case SDLK_KP5:
727 case SDLK_KP_ENTER:
728 case SDLK_RETURN:
729 new_btn = BUTTON_SELECT;
730 break;
731 case SDLK_KP7:
732 new_btn = BUTTON_VOL_DOWN;
733 break;
734 case SDLK_KP9:
735 new_btn = BUTTON_VOL_UP;
736 break;
737
738#elif CONFIG_KEYPAD == MROBE500_PAD
739 case SDLK_F9:
740 new_btn = BUTTON_RC_HEART;
741 break;
742 case SDLK_F10:
743 new_btn = BUTTON_RC_MODE;
744 break;
745 case SDLK_F11:
746 new_btn = BUTTON_RC_VOL_DOWN;
747 break;
748 case SDLK_F12:
749 new_btn = BUTTON_RC_VOL_UP;
750 break;
751 case SDLK_MINUS:
752 case SDLK_LESS:
753 case SDLK_LEFTBRACKET:
754 case SDLK_KP_DIVIDE:
755 new_btn = BUTTON_LEFT;
756 break;
757 case SDLK_PLUS:
758 case SDLK_GREATER:
759 case SDLK_RIGHTBRACKET:
760 case SDLK_KP_MULTIPLY:
761 new_btn = BUTTON_RIGHT;
762 break;
763 case SDLK_PAGEUP:
764 new_btn = BUTTON_RC_PLAY;
765 break;
766 case SDLK_PAGEDOWN:
767 new_btn = BUTTON_RC_DOWN;
768 break;
769 case SDLK_F8:
770 case SDLK_ESCAPE:
771 new_btn = BUTTON_POWER;
772 break;
773#elif CONFIG_KEYPAD == MROBE100_PAD
774 case SDLK_F9:
775 new_btn = BUTTON_RC_HEART;
776 break;
777 case SDLK_F10:
778 new_btn = BUTTON_RC_MODE;
779 break;
780 case SDLK_F11:
781 new_btn = BUTTON_RC_VOL_DOWN;
782 break;
783 case SDLK_F12:
784 new_btn = BUTTON_RC_VOL_UP;
785 break;
786 case SDLK_LEFT:
787 new_btn = BUTTON_RC_FF;
788 break;
789 case SDLK_RIGHT:
790 new_btn = BUTTON_RC_REW;
791 break;
792 case SDLK_UP:
793 new_btn = BUTTON_RC_PLAY;
794 break;
795 case SDLK_DOWN:
796 new_btn = BUTTON_RC_DOWN;
797 break;
798 case SDLK_KP1:
799 new_btn = BUTTON_DISPLAY;
800 break;
801 case SDLK_KP7:
802 new_btn = BUTTON_MENU;
803 break;
804 case SDLK_KP9:
805 new_btn = BUTTON_PLAY;
806 break;
807 case SDLK_KP4:
808 new_btn = BUTTON_LEFT;
809 break;
810 case SDLK_KP6:
811 new_btn = BUTTON_RIGHT;
812 break;
813 case SDLK_KP8:
814 new_btn = BUTTON_UP;
815 break;
816 case SDLK_KP2:
817 new_btn = BUTTON_DOWN;
818 break;
819 case SDLK_KP5:
820 case SDLK_SPACE:
821 new_btn = BUTTON_SELECT;
822 break;
823 case SDLK_KP_MULTIPLY:
824 case SDLK_F8:
825 case SDLK_ESCAPE:
826 new_btn = BUTTON_POWER;
827 break;
828
829#elif CONFIG_KEYPAD == COWON_D2_PAD
830 case SDLK_KP_MULTIPLY:
831 case SDLK_F8:
832 case SDLK_ESCAPE:
833 case SDLK_BACKSPACE:
834 case SDLK_DELETE:
835 new_btn = BUTTON_POWER;
836 break;
837 case SDLK_KP_PLUS:
838 case SDLK_EQUALS:
839 new_btn = BUTTON_PLUS;
840 break;
841 case SDLK_KP_MINUS:
842 case SDLK_MINUS:
843 new_btn = BUTTON_MINUS;
844 break;
845 case SDLK_KP_ENTER:
846 case SDLK_RETURN:
847 case SDLK_SPACE:
848 case SDLK_INSERT:
849 new_btn = BUTTON_MENU;
850 break;
851#elif CONFIG_KEYPAD == IAUDIO67_PAD
852 case SDLK_UP:
853 new_btn = BUTTON_RIGHT;
854 break;
855 case SDLK_DOWN:
856 new_btn = BUTTON_LEFT;
857 break;
858 case SDLK_LEFT:
859 new_btn = BUTTON_STOP;
860 break;
861 case SDLK_RETURN:
862 case SDLK_KP_ENTER:
863 case SDLK_RIGHT:
864 new_btn = BUTTON_PLAY;
865 break;
866 case SDLK_PLUS:
867 new_btn = BUTTON_VOLUP;
868 break;
869 case SDLK_MINUS:
870 new_btn = BUTTON_VOLDOWN;
871 break;
872 case SDLK_SPACE:
873 new_btn = BUTTON_MENU;
874 break;
875 case SDLK_BACKSPACE:
876 new_btn = BUTTON_POWER;
877 break;
878#elif CONFIG_KEYPAD == CREATIVEZVM_PAD
879 case SDLK_KP1:
880 new_btn = BUTTON_BACK;
881 break;
882 case SDLK_KP3:
883 new_btn = BUTTON_MENU;
884 break;
885 case SDLK_KP7:
886 new_btn = BUTTON_CUSTOM;
887 break;
888 case SDLK_KP9:
889 new_btn = BUTTON_PLAY;
890 break;
891 case SDLK_KP4:
892 case SDLK_LEFT:
893 new_btn = BUTTON_LEFT;
894 break;
895 case SDLK_KP6:
896 case SDLK_RIGHT:
897 new_btn = BUTTON_RIGHT;
898 break;
899 case SDLK_KP8:
900 case SDLK_UP:
901 new_btn = BUTTON_UP;
902 break;
903 case SDLK_KP2:
904 case SDLK_DOWN:
905 new_btn = BUTTON_DOWN;
906 break;
907 case SDLK_KP5:
908 case SDLK_SPACE:
909 new_btn = BUTTON_SELECT;
910 break;
911 case SDLK_KP_MULTIPLY:
912 case SDLK_F8:
913 case SDLK_ESCAPE:
914 new_btn = BUTTON_POWER;
915 break;
916#elif CONFIG_KEYPAD == CREATIVEZV_PAD
917 case SDLK_KP1:
918 new_btn = BUTTON_PREV;
919 break;
920 case SDLK_KP3:
921 new_btn = BUTTON_NEXT;
922 break;
923 case SDLK_KP7:
924 new_btn = BUTTON_BACK;
925 break;
926 case SDLK_p:
927 new_btn = BUTTON_PLAY;
928 break;
929 case SDLK_KP9:
930 new_btn = BUTTON_MENU;
931 break;
932 case SDLK_KP4:
933 case SDLK_LEFT:
934 new_btn = BUTTON_LEFT;
935 break;
936 case SDLK_KP6:
937 case SDLK_RIGHT:
938 new_btn = BUTTON_RIGHT;
939 break;
940 case SDLK_KP8:
941 case SDLK_UP:
942 new_btn = BUTTON_UP;
943 break;
944 case SDLK_KP2:
945 case SDLK_DOWN:
946 new_btn = BUTTON_DOWN;
947 break;
948 case SDLK_KP5:
949 case SDLK_SPACE:
950 new_btn = BUTTON_SELECT;
951 break;
952 case SDLK_KP_MULTIPLY:
953 case SDLK_F8:
954 case SDLK_ESCAPE:
955 new_btn = BUTTON_POWER;
956 break;
957 case SDLK_z:
958 new_btn = BUTTON_VOL_DOWN;
959 break;
960 case SDLK_s:
961 new_btn = BUTTON_VOL_UP;
962
963#elif CONFIG_KEYPAD == MEIZU_M6SL_PAD
964 case SDLK_KP1:
965 new_btn = BUTTON_PREV;
966 break;
967 case SDLK_KP3:
968 new_btn = BUTTON_NEXT;
969 break;
970 case SDLK_KP_ENTER:
971 case SDLK_RETURN:
972 case SDLK_a:
973 new_btn = BUTTON_PLAY;
974 break;
975 case SDLK_KP_PERIOD:
976 case SDLK_INSERT:
977 new_btn = BUTTON_MENU;
978 break;
979 case SDLK_KP8:
980 case SDLK_UP:
981 new_btn = BUTTON_UP;
982 break;
983 case SDLK_KP2:
984 case SDLK_DOWN:
985 new_btn = BUTTON_DOWN;
986 break;
987 case SDLK_KP5:
988 case SDLK_SPACE:
989 new_btn = BUTTON_SELECT;
990 break;
991#elif CONFIG_KEYPAD == SANSA_FUZE_PAD
992 case SDLK_KP4:
993 case SDLK_LEFT:
994 new_btn = BUTTON_LEFT;
995 break;
996 case SDLK_KP6:
997 case SDLK_RIGHT:
998 new_btn = BUTTON_RIGHT;
999 break;
1000 case SDLK_KP8:
1001 case SDLK_UP:
1002 new_btn = BUTTON_SCROLL_BACK;
1003 break;
1004 case SDLK_KP2:
1005 case SDLK_DOWN:
1006 new_btn = BUTTON_SCROLL_FWD;
1007 break;
1008 case SDLK_PAGEUP:
1009 case SDLK_KP9:
1010 new_btn = BUTTON_UP;
1011 break;
1012 case SDLK_PAGEDOWN:
1013 case SDLK_KP3:
1014 new_btn = BUTTON_DOWN;
1015 break;
1016 case SDLK_KP_MINUS:
1017 case SDLK_KP1:
1018 new_btn = BUTTON_POWER;
1019 break;
1020 case SDLK_KP_MULTIPLY:
1021 new_btn = BUTTON_HOME;
1022 break;
1023 case SDLK_KP5:
1024 case SDLK_SPACE:
1025 case SDLK_KP_ENTER:
1026 case SDLK_RETURN:
1027 new_btn = BUTTON_SELECT;
1028 break;
1029#elif CONFIG_KEYPAD == SANSA_CLIP_PAD
1030 case SDLK_KP4:
1031 case SDLK_LEFT:
1032 new_btn = BUTTON_LEFT;
1033 break;
1034 case SDLK_KP6:
1035 case SDLK_RIGHT:
1036 new_btn = BUTTON_RIGHT;
1037 break;
1038 case SDLK_KP8:
1039 case SDLK_UP:
1040 new_btn = BUTTON_UP;
1041 break;
1042 case SDLK_KP2:
1043 case SDLK_DOWN:
1044 new_btn = BUTTON_DOWN;
1045 break;
1046
1047 case SDLK_INSERT:
1048 case SDLK_KP_MULTIPLY:
1049 new_btn = BUTTON_HOME;
1050 break;
1051 case SDLK_SPACE:
1052 case SDLK_KP5:
1053 new_btn = BUTTON_SELECT;
1054 break;
1055 case SDLK_PAGEDOWN:
1056 case SDLK_KP3:
1057 new_btn = BUTTON_VOL_DOWN;
1058 break;
1059 case SDLK_PAGEUP:
1060 case SDLK_KP9:
1061 new_btn = BUTTON_VOL_UP;
1062 break;
1063 case SDLK_ESCAPE:
1064 case SDLK_KP1:
1065 new_btn = BUTTON_POWER;
1066 break;
1067#elif CONFIG_KEYPAD == SANSA_M200_PAD
1068 case SDLK_KP4:
1069 case SDLK_LEFT:
1070 new_btn = BUTTON_LEFT;
1071 break;
1072 case SDLK_KP6:
1073 case SDLK_RIGHT:
1074 new_btn = BUTTON_RIGHT;
1075 break;
1076 case SDLK_KP8:
1077 case SDLK_UP:
1078 new_btn = BUTTON_UP;
1079 break;
1080 case SDLK_KP2:
1081 case SDLK_DOWN:
1082 new_btn = BUTTON_DOWN;
1083 break;
1084 case SDLK_PLUS:
1085 new_btn = BUTTON_POWER;
1086 break;
1087 case SDLK_KP5:
1088 new_btn = BUTTON_SELECT;
1089 break;
1090 case SDLK_KP7:
1091 new_btn = BUTTON_VOL_DOWN;
1092 break;
1093 case SDLK_KP9:
1094 new_btn = BUTTON_VOL_UP;
1095 break;
1096#elif CONFIG_KEYPAD == PHILIPS_SA9200_PAD
1097 case SDLK_KP4:
1098 case SDLK_LEFT:
1099 new_btn = BUTTON_LEFT;
1100 break;
1101 case SDLK_KP6:
1102 case SDLK_RIGHT:
1103 new_btn = BUTTON_RIGHT;
1104 break;
1105 case SDLK_KP8:
1106 case SDLK_UP:
1107 new_btn = BUTTON_UP;
1108 break;
1109 case SDLK_KP2:
1110 case SDLK_DOWN:
1111 new_btn = BUTTON_DOWN;
1112 break;
1113 case SDLK_KP1:
1114 new_btn = BUTTON_MENU;
1115 break;
1116 case SDLK_KP5:
1117 case SDLK_SPACE:
1118 new_btn = BUTTON_PLAY;
1119 break;
1120 case SDLK_KP7:
1121 new_btn = BUTTON_PREV;
1122 break;
1123 case SDLK_KP9:
1124 new_btn = BUTTON_NEXT;
1125 break;
1126 case SDLK_KP_ENTER:
1127 case SDLK_RETURN:
1128 new_btn = BUTTON_POWER;
1129 break;
1130 case SDLK_PAGEUP:
1131 new_btn = BUTTON_VOL_UP;
1132 break;
1133 case SDLK_PAGEDOWN:
1134 new_btn = BUTTON_VOL_DOWN;
1135 break;
1136#elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
1137 case SDLK_KP4:
1138 case SDLK_LEFT:
1139 new_btn = BUTTON_LEFT;
1140 break;
1141 case SDLK_KP6:
1142 case SDLK_RIGHT:
1143 new_btn = BUTTON_RIGHT;
1144 break;
1145 case SDLK_KP8:
1146 case SDLK_UP:
1147 new_btn = BUTTON_UP;
1148 break;
1149 case SDLK_KP2:
1150 case SDLK_DOWN:
1151 new_btn = BUTTON_DOWN;
1152 break;
1153 case SDLK_KP5:
1154 case SDLK_SPACE:
1155 new_btn = BUTTON_SELECT;
1156 break;
1157 case SDLK_KP7:
1158 case SDLK_ESCAPE:
1159 new_btn = BUTTON_POWER;
1160 break;
1161 case SDLK_KP1:
1162 new_btn = BUTTON_PLAYLIST;
1163 break;
1164 case SDLK_KP9:
1165 new_btn = BUTTON_VOL_UP;
1166 break;
1167 case SDLK_KP3:
1168 new_btn = BUTTON_VOL_DOWN;
1169 break;
1170 case SDLK_KP_MINUS:
1171 new_btn = BUTTON_MENU;
1172 break;
1173 case SDLK_KP_PLUS:
1174 new_btn = BUTTON_VIEW;
1175 break;
1176#elif CONFIG_KEYPAD == ONDAVX747_PAD
1177 case SDLK_ESCAPE:
1178 new_btn = BUTTON_POWER;
1179 break;
1180 case SDLK_KP_PLUS:
1181 case SDLK_PLUS:
1182 case SDLK_GREATER:
1183 case SDLK_RIGHTBRACKET:
1184 case SDLK_KP_MULTIPLY:
1185 new_btn = BUTTON_VOL_UP;
1186 break;
1187 case SDLK_KP_MINUS:
1188 case SDLK_MINUS:
1189 case SDLK_LESS:
1190 case SDLK_LEFTBRACKET:
1191 case SDLK_KP_DIVIDE:
1192 new_btn = BUTTON_VOL_DOWN;
1193 break;
1194 case SDLK_KP_ENTER:
1195 case SDLK_RETURN:
1196 new_btn = BUTTON_MENU;
1197 break;
1198#elif CONFIG_KEYPAD == ONDAVX777_PAD
1199 case SDLK_ESCAPE:
1200 new_btn = BUTTON_POWER;
1201 break;
1202#elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
1203 case SDLK_KP4:
1204 case SDLK_LEFT:
1205 new_btn = BUTTON_LEFT;
1206 break;
1207 case SDLK_KP6:
1208 case SDLK_RIGHT:
1209 new_btn = BUTTON_RIGHT;
1210 break;
1211 case SDLK_KP8:
1212 case SDLK_UP:
1213 new_btn = BUTTON_UP;
1214 break;
1215 case SDLK_KP2:
1216 case SDLK_DOWN:
1217 new_btn = BUTTON_DOWN;
1218 break;
1219 case SDLK_KP5:
1220 case SDLK_KP_ENTER:
1221 new_btn = BUTTON_PLAY;
1222 break;
1223 case SDLK_KP9:
1224 case SDLK_PAGEUP:
1225 new_btn = BUTTON_FFWD;
1226 break;
1227#ifdef SAMSUNG_YH820
1228 case SDLK_KP7:
1229#else
1230 case SDLK_KP3:
1231#endif
1232 case SDLK_PAGEDOWN:
1233 new_btn = BUTTON_REW;
1234 break;
1235 case SDLK_KP_PLUS:
1236 new_btn = BUTTON_REC;
1237 break;
1238#elif CONFIG_KEYPAD == MINI2440_PAD
1239 case SDLK_LEFT:
1240 new_btn = BUTTON_LEFT;
1241 break;
1242 case SDLK_RIGHT:
1243 new_btn = BUTTON_RIGHT;
1244 break;
1245 case SDLK_UP:
1246 new_btn = BUTTON_UP;
1247 break;
1248 case SDLK_DOWN:
1249 new_btn = BUTTON_DOWN;
1250 break;
1251 case SDLK_F8:
1252 case SDLK_ESCAPE:
1253 new_btn = BUTTON_POWER;
1254 break;
1255 case SDLK_KP_ENTER:
1256 case SDLK_RETURN:
1257 case SDLK_a:
1258 new_btn = BUTTON_A;
1259 break;
1260 case SDLK_SPACE:
1261 new_btn = BUTTON_SELECT;
1262 break;
1263 case SDLK_KP_PERIOD:
1264 case SDLK_INSERT:
1265 new_btn = BUTTON_MENU;
1266 break;
1267 case SDLK_KP_PLUS:
1268 new_btn = BUTTON_VOL_UP;
1269 break;
1270 case SDLK_KP_MINUS:
1271 new_btn = BUTTON_VOL_DOWN;
1272 break;
1273#elif CONFIG_KEYPAD == PBELL_VIBE500_PAD
1274 case SDLK_KP4:
1275 case SDLK_LEFT:
1276 new_btn = BUTTON_PREV;
1277 break;
1278 case SDLK_KP6:
1279 case SDLK_RIGHT:
1280 new_btn = BUTTON_NEXT;
1281 break;
1282 case SDLK_KP8:
1283 case SDLK_UP:
1284 new_btn = BUTTON_UP;
1285 break;
1286 case SDLK_KP2:
1287 case SDLK_DOWN:
1288 new_btn = BUTTON_DOWN;
1289 break;
1290 case SDLK_KP7:
1291 new_btn = BUTTON_MENU;
1292 break;
1293 case SDLK_KP9:
1294 new_btn = BUTTON_PLAY;
1295 break;
1296 case SDLK_KP5:
1297 new_btn = BUTTON_OK;
1298 break;
1299 case SDLK_KP_DIVIDE:
1300 new_btn = BUTTON_CANCEL;
1301 break;
1302 case SDLK_KP_PLUS:
1303 new_btn = BUTTON_POWER;
1304 break;
1305 case SDLK_KP_MULTIPLY:
1306 new_btn = BUTTON_REC;
1307 break;
1308
1309#elif CONFIG_KEYPAD == MPIO_HD200_PAD
1310 case SDLK_UP:
1311 new_btn = BUTTON_PREV;
1312 break;
1313 case SDLK_DOWN:
1314 new_btn = BUTTON_NEXT;
1315 break;
1316 case SDLK_SPACE:
1317 new_btn = BUTTON_SELECT;
1318 break;
1319 case SDLK_RETURN:
1320 new_btn = BUTTON_PLAY;
1321 break;
1322 case SDLK_LEFT:
1323 new_btn = BUTTON_VOL_DOWN;
1324 break;
1325 case SDLK_RIGHT:
1326 new_btn = BUTTON_VOL_UP;
1327 break;
1328 case SDLK_ESCAPE:
1329 new_btn = BUTTON_REC;
1330 break;
1331
1332#else
1333#error No keymap defined!
1334#endif /* CONFIG_KEYPAD */
1335 case SDLK_KP0:
1336 case SDLK_F5:
1337 if(pressed)
1338 {
1339 sim_trigger_screendump();
1340 return;
1341 }
1342 break;
1343 }
1344
1345 /* Call to make up for scrollwheel target implementation. This is
1346 * not handled in the main button.c driver, but on the target
1347 * implementation (look at button-e200.c for example if you are trying to
1348 * figure out why using button_get_data needed a hack before).
1349 */
1350#if defined(BUTTON_SCROLL_FWD) && defined(BUTTON_SCROLL_BACK)
1351 if((new_btn == BUTTON_SCROLL_FWD || new_btn == BUTTON_SCROLL_BACK) &&
1352 pressed)
1353 {
1354 /* Clear these buttons from the data - adding them to the queue is
1355 * handled in the scrollwheel drivers for the targets. They do not
1356 * store the scroll forward/back buttons in their button data for
1357 * the button_read call.
1358 */
1359#ifdef HAVE_BACKLIGHT
1360 backlight_on();
1361#endif
1362#ifdef HAVE_BUTTON_LIGHT
1363 buttonlight_on();
1364#endif
1365 queue_post(&button_queue, new_btn, 1<<24);
1366 new_btn &= ~(BUTTON_SCROLL_FWD | BUTTON_SCROLL_BACK);
1367 }
1368#endif
1369
1370 if (pressed)
1371 btn |= new_btn;
1372 else
1373 btn &= ~new_btn;
1374}
1375#if defined(HAVE_BUTTON_DATA) && defined(HAVE_TOUCHSCREEN)
1376int button_read_device(int* data)
1377{
1378 *data = mouse_coords;
1379#else
1380int button_read_device(void)
1381{
1382#endif
1383
1384#ifdef HAS_BUTTON_HOLD
1385 int hold_button = button_hold();
1386
1387#ifdef HAVE_BACKLIGHT
1388 /* light handling */
1389 static int hold_button_old = false;
1390 if (hold_button != hold_button_old)
1391 {
1392 hold_button_old = hold_button;
1393 backlight_hold_changed(hold_button);
1394 }
1395#endif
1396
1397 if (hold_button)
1398 return BUTTON_NONE;
1399#endif
1400
1401 return btn;
1402}
1403
1404
1405#ifdef HAVE_TOUCHSCREEN
1406extern bool debug_wps;
1407void mouse_tick_task(void)
1408{
1409 static int last_check = 0;
1410 int x,y;
1411 if (TIME_BEFORE(current_tick, last_check+(HZ/10)))
1412 return;
1413 last_check = current_tick;
1414 if (SDL_GetMouseState(&x, &y) & SDL_BUTTON(SDL_BUTTON_LEFT))
1415 {
1416 if(background)
1417 {
1418 x -= UI_LCD_POSX;
1419 y -= UI_LCD_POSY;
1420
1421 if(x<0 || y<0 || x>SIM_LCD_WIDTH || y>SIM_LCD_HEIGHT)
1422 return;
1423 }
1424
1425 mouse_coords = (x<<16)|y;
1426 button_event(BUTTON_TOUCHSCREEN, true);
1427 if (debug_wps)
1428 printf("Mouse at: (%d, %d)\n", x, y);
1429 }
1430}
1431#endif
1432
1433void button_init_sdl(void)
1434{
1435#ifdef HAVE_TOUCHSCREEN
1436 tick_add_task(mouse_tick_task);
1437#endif
1438}
1439
1440/* Button maps: simulated key, x, y, radius, name */
1441/* Run sim with --mapping to get coordinates */
1442/* or --debugbuttons to check */
1443/* The First matching button is returned */
1444
1445#ifdef SANSA_FUZE
1446struct button_map bm[] = {
1447 { SDLK_KP8, 70, 265, 35, "Scroll Back" },
1448 { SDLK_KP9, 141, 255, 31, "Play" },
1449 { SDLK_KP_MULTIPLY, 228, 267, 18, "Home" },
1450 { SDLK_LEFT, 69, 329, 31, "Left" },
1451 { SDLK_SPACE, 141, 330, 20, "Select" },
1452 { SDLK_RIGHT, 214, 331, 23, "Right" },
1453 { SDLK_KP3, 142, 406, 30, "Menu" },
1454 { SDLK_DOWN, 221, 384, 24, "Scroll Fwd" },
1455 { SDLK_KP_MINUS, 270, 299, 25, "Power" },
1456 { SDLK_h, 269, 358, 26, "Hold" },
1457 { 0, 0, 0, 0, "None" }
1458};
1459#elif defined (SANSA_CLIP)
1460struct button_map bm[] = {
1461 { SDLK_KP_MULTIPLY, 165, 158, 17, "Home" },
1462 { SDLK_KP5, 102, 230, 29, "Select" },
1463 { SDLK_KP8, 100, 179, 25, "Play" },
1464 { SDLK_KP4, 53, 231, 21, "Left" },
1465 { SDLK_KP6, 147, 232, 19, "Right" },
1466 { SDLK_KP2, 105, 275, 22, "Menu" },
1467 { 0, 0, 0, 0, "None" }
1468};
1469#elif defined (SANSA_C200) || defined(SANSA_C200V2)
1470struct button_map bm[] = {
1471
1472 { SDLK_KP7, 84, 7, 21, "Vol Down" },
1473 { SDLK_KP9, 158, 7, 20, "Vol Up" },
1474 { SDLK_KP1, 173, 130, 27, "Record" },
1475 { SDLK_KP5, 277, 75, 21, "Select" },
1476 { SDLK_KP4, 233, 75, 24, "Left" },
1477 { SDLK_KP6, 313, 74, 18, "Right" },
1478 { SDLK_KP8, 276, 34, 15, "Play" },
1479 { SDLK_KP2, 277, 119, 17, "Down" },
1480 { SDLK_KP3, 314, 113, 19, "Menu" },
1481 { 0, 0, 0, 0, "None" }
1482};
1483#elif defined (SANSA_E200V2) || defined(SANSA_E200)
1484struct button_map bm[] = {
1485 { SDLK_KP7, 5, 92, 18, "Record" },
1486 { SDLK_KP9, 128, 295, 43, "Play" },
1487 { SDLK_KP4, 42, 380, 33, "Left" },
1488 { SDLK_KP5, 129, 378, 36, "Select" },
1489 { SDLK_KP6, 218, 383, 30, "Right" },
1490 { SDLK_KP3, 129, 461, 29, "Down" },
1491 { SDLK_KP1, 55, 464, 20, "Menu" },
1492 { SDLK_KP8, 92, 338, 17, "Scroll Back" },
1493 { SDLK_KP2, 167, 342, 17, "Scroll Fwd" },
1494 { 0, 0, 0, 0, "None" }
1495};
1496#elif defined (SANSA_M200V4)
1497struct button_map bm[] = {
1498 { SDLK_KP_PLUS, 54, 14, 16, "Power" },
1499 { SDLK_KP7, 96, 13, 12, "Vol Down" },
1500 { SDLK_KP9, 139, 14, 14, "Vol Up" },
1501 { SDLK_KP5, 260, 82, 20, "Select" },
1502 { SDLK_KP8, 258, 35, 30, "Play" },
1503 { SDLK_KP4, 214, 84, 25, "Left" },
1504 { SDLK_KP6, 300, 83, 24, "Right" },
1505 { SDLK_KP2, 262, 125, 28, "Repeat" },
1506 { SDLK_h, 113, 151, 21, "Hold" },
1507 { 0, 0, 0, 0, "None" }
1508};
1509#elif defined (IPOD_VIDEO)
1510struct button_map bm[] = {
1511 { SDLK_KP_PERIOD, 174, 350, 35, "Menu" },
1512 { SDLK_KP8, 110, 380, 33, "Scroll Back" },
1513 { SDLK_KP2, 234, 377, 34, "Scroll Fwd" },
1514 { SDLK_KP4, 78, 438, 47, "Left" },
1515 { SDLK_KP5, 172, 435, 43, "Select" },
1516 { SDLK_KP6, 262, 438, 52, "Right" },
1517 { SDLK_KP_PLUS, 172, 519, 43, "Play" },
1518 { 0, 0, 0 , 0, "None" }
1519};
1520#elif defined (IPOD_MINI) || defined(IPOD_MINI2G)
1521struct button_map bm[] = {
1522 { SDLK_KP5, 92, 267, 29, "Select" },
1523 { SDLK_KP4, 31, 263, 37, "Left" },
1524 { SDLK_KP6, 150, 268, 33, "Right" },
1525 { SDLK_KP_PERIOD, 93, 209, 30, "Menu" },
1526 { SDLK_KP_PLUS, 93, 324, 25, "Play" },
1527 { SDLK_KP8, 53, 220, 29, "Scroll Back" },
1528 { SDLK_KP2, 134, 219, 31, "Scroll Fwd" },
1529 { 0, 0, 0 , 0, "None" }
1530};
1531#elif defined (IPOD_3G)
1532struct button_map bm[] = {
1533 { SDLK_KP5, 108, 296, 26, "Select" },
1534 { SDLK_KP8, 70, 255, 26, "Scroll Back" },
1535 { SDLK_KP2, 149, 256, 28, "Scroll Fwd" },
1536 { SDLK_KP4, 27, 186, 22, "Left" },
1537 { SDLK_KP_PERIOD, 82, 185, 22, "Menu" },
1538 { SDLK_KP_PERIOD, 133, 185, 21, "Play" },
1539 { SDLK_KP6, 189, 188, 21, "Right" },
1540 { 0, 0, 0 , 0, "None" }
1541};
1542#elif defined (IPOD_4G)
1543struct button_map bm[] = {
1544 { SDLK_KP5, 96, 269, 27, "Select" },
1545 { SDLK_KP4, 39, 267, 30, "Left" },
1546 { SDLK_KP6, 153, 270, 27, "Right" },
1547 { SDLK_KP_PERIOD, 96, 219, 30, "Menu" },
1548 { SDLK_KP_PLUS, 95, 326, 27, "Play" },
1549 { SDLK_KP8, 57, 233, 29, "Scroll Back" },
1550 { SDLK_KP2, 132, 226, 29, "Scroll Fwd" },
1551 { 0, 0, 0 , 0, "None" }
1552};
1553#elif defined (IPOD_COLOR)
1554struct button_map bm[] = {
1555 { SDLK_KP5, 128, 362, 35, "Select" },
1556 { SDLK_KP4, 55, 358, 38, "Left" },
1557 { SDLK_KP6, 203, 359, 39, "Right" },
1558 { SDLK_KP_PERIOD, 128, 282, 34, "Menu" },
1559 { SDLK_KP_PLUS, 129, 439, 41, "Play" },
1560 { SDLK_KP8, 76, 309, 34, "Scroll Back" },
1561 { SDLK_KP2, 182, 311, 45, "Scroll Fwd" },
1562 { 0, 0, 0 , 0, "None" }
1563};
1564#elif defined (IPOD_1G2G)
1565struct button_map bm[] = {
1566 { SDLK_KP5, 112, 265, 31, "Select" },
1567 { SDLK_KP8, 74, 224, 28, "Scroll Back" },
1568 { SDLK_KP2, 146, 228, 28, "Scroll Fwd" },
1569 /* Dummy button to make crescent shape */
1570 { SDLK_y, 112, 265, 76, "None" },
1571 { SDLK_KP8, 74, 224, 28, "Scroll Back" },
1572 { SDLK_KP2, 146, 228, 28, "Scroll Fwd" },
1573 { SDLK_KP6, 159, 268, 64, "Right" },
1574 { SDLK_KP4, 62, 266, 62, "Left" },
1575 { SDLK_KP_PERIOD, 111, 216, 64, "Menu" },
1576 { SDLK_KP_PLUS, 111, 326, 55, "Down" },
1577 { 0, 0, 0 , 0, "None" }
1578};
1579#elif defined (IPOD_NANO)
1580struct button_map bm[] = {
1581 { SDLK_KP5, 98, 316, 37, "Select" },
1582 { SDLK_KP4, 37, 312, 28, "Left" },
1583 { SDLK_KP6, 160, 313, 25, "Right" },
1584 { SDLK_KP_PERIOD,102, 256, 23, "Menu" },
1585 { SDLK_KP_PLUS, 99, 378, 28, "Play" },
1586 { SDLK_KP8, 58, 272, 24, "Scroll Back" },
1587 { SDLK_KP2, 141, 274, 22, "Scroll Fwd" },
1588 { 0, 0, 0 , 0, "None" }
1589};
1590#elif defined (IPOD_NANO2G)
1591struct button_map bm[] = {
1592 { SDLK_KP5, 118, 346, 37, "Select" },
1593 { SDLK_KP4, 51, 345, 28, "Left" },
1594 { SDLK_KP6, 180, 346, 26, "Right" },
1595 { SDLK_KP_PERIOD, 114, 286, 23, "Menu" },
1596 { SDLK_KP_PLUS, 115, 412, 27, "Down" },
1597 { SDLK_KP8, 67, 303, 28, "Scroll Back" },
1598 { SDLK_KP2, 163, 303, 27, "Scroll Fwd" },
1599 { 0, 0, 0 , 0, "None" }
1600};
1601#elif defined (COWON_D2)
1602struct button_map bm[] = {
1603 { SDLK_DELETE, 51, 14, 17, "Power" },
1604 { SDLK_h, 138, 14, 16, "Hold" },
1605 { SDLK_MINUS, 320, 14, 10, "Minus" },
1606 { SDLK_INSERT, 347, 13, 13, "Menu" },
1607 { SDLK_KP_PLUS, 374, 14, 12, "Plus" },
1608 { 0, 0, 0, 0, "None" }
1609};
1610#elif defined (IAUDIO_M3)
1611struct button_map bm[] = {
1612 { SDLK_KP5, 256, 72, 29, "Play" },
1613 { SDLK_KP6, 255, 137, 28, "Right" },
1614 { SDLK_KP4, 257, 201, 26, "Left" },
1615 { SDLK_KP8, 338, 31, 27, "Up" },
1616 { SDLK_KP2, 339, 92, 23, "Down" },
1617 { SDLK_KP_PERIOD, 336, 50, 23, "Mode" },
1618 { SDLK_KP_DIVIDE, 336, 147, 23, "Rec" },
1619 { SDLK_h, 336, 212, 30, "Hold" },
1620 /* remote */
1621 { SDLK_SPACE, 115, 308, 20, "RC Play" },
1622 { SDLK_RIGHT, 85, 308, 20, "RC Rew" },
1623 { SDLK_LEFT, 143, 308, 20, "RC FF" },
1624 { SDLK_UP, 143, 498, 20, "RC Up" },
1625 { SDLK_DOWN, 85, 498, 20, "RC Down" },
1626 { SDLK_INSERT, 212, 308, 30, "RC Mode" },
1627 { SDLK_F1, 275, 308, 25, "RC Rec" },
1628 { SDLK_KP_ENTER, 115, 498, 20, "RC Menu" },
1629 { 0, 0, 0, 0, "None" }
1630};
1631#elif defined (IAUDIO_M5)
1632struct button_map bm[] = {
1633 { SDLK_KP_ENTER, 333, 41, 17, "Enter" },
1634 { SDLK_h, 334, 74, 21, "Hold" },
1635 { SDLK_KP_DIVIDE, 333, 142, 24, "Record" },
1636 { SDLK_KP_PLUS, 332, 213, 20, "Play" },
1637 { SDLK_KP5, 250, 291, 19, "Select" },
1638 { SDLK_KP8, 249, 236, 32, "Up" },
1639 { SDLK_KP4, 194, 292, 29, "Left" },
1640 { SDLK_KP6, 297, 290, 27, "Right" },
1641 { SDLK_KP2, 252, 335, 28, "Down" },
1642 { 0, 0, 0, 0, "None" }
1643};
1644#elif defined (IAUDIO_7)
1645struct button_map bm[] = {
1646 { 0, 0, 0, 0, "None" }
1647};
1648#elif defined (IAUDIO_X5)
1649struct button_map bm[] = {
1650 { SDLK_KP_ENTER, 275, 38, 17, "Power" },
1651 { SDLK_h, 274, 83, 16, "Hold" },
1652 { SDLK_KP_DIVIDE, 276, 128, 22, "Record" },
1653 { SDLK_KP_PLUS, 274, 186, 22, "Play" },
1654 { SDLK_KP5, 200, 247, 16, "Select" },
1655 { SDLK_KP8, 200, 206, 16, "Up" },
1656 { SDLK_KP4, 163, 248, 19, "Left" },
1657 { SDLK_KP6, 225, 247, 24, "Right" },
1658 { SDLK_KP2, 199, 279, 20, "Down" },
1659 { 0, 0, 0, 0, "None" }
1660};
1661#elif defined (ARCHOS_PLAYER)
1662struct button_map bm[] = {
1663 { SDLK_KP_PLUS, 79, 252, 23, "On" },
1664 { SDLK_KP_PERIOD, 81, 310, 20, "Menu" },
1665 { SDLK_KP8, 154, 237, 28, "Play" },
1666 { SDLK_KP4, 121, 282, 23, "Left" },
1667 { SDLK_KP6, 187, 282, 22, "Right" },
1668 { SDLK_KP2, 157, 312, 20, "Down" },
1669 { 0, 0, 0, 0, "None" }
1670};
1671#elif defined (ARCHOS_RECORDER)
1672struct button_map bm[] = {
1673 { SDLK_F1, 94, 205, 22, "F1" },
1674 { SDLK_F2, 136, 204, 21, "F2" },
1675 { SDLK_F3, 174, 204, 24, "F3" },
1676 { SDLK_KP_PLUS, 75, 258, 19, "On" },
1677 { SDLK_KP_ENTER, 76, 307, 15, "Off" },
1678 { SDLK_KP5, 151, 290, 20, "Select" },
1679 { SDLK_KP8, 152, 251, 23, "Up" },
1680 { SDLK_KP4, 113, 288, 26, "Left" },
1681 { SDLK_KP6, 189, 291, 23, "Right" },
1682 { SDLK_KP2, 150, 327, 27, "Down" },
1683 { 0, 0, 0, 0, "None" }
1684};
1685#elif defined (ARCHOS_FMRECORDER) || defined (ARCHOS_RECORDERV2)
1686struct button_map bm[] = {
1687 { SDLK_F1, 88, 210, 28, "F1" },
1688 { SDLK_F2, 144, 212, 28, "F2" },
1689 { SDLK_F3, 197, 212, 28, "F3" },
1690 { SDLK_KP5, 144, 287, 21, "Select" },
1691 { SDLK_KP_PLUS, 86, 320, 13, "Menu" },
1692 { SDLK_KP_ENTER, 114, 347, 13, "Stop" },
1693 { SDLK_y, 144, 288, 31, "None" },
1694 { SDLK_KP8, 144, 259, 25, "Up" },
1695 { SDLK_KP2, 144, 316, 31, "Down" },
1696 { SDLK_KP6, 171, 287, 32, "Right" },
1697 { SDLK_KP4, 117, 287, 31, "Left" },
1698 { 0, 0, 0, 0, "None" }
1699};
1700#elif defined (ARCHOS_ONDIOSP) || defined (ARCHOS_ONDIOFM)
1701struct button_map bm[] = {
1702 { SDLK_KP_ENTER, 75, 23, 30, "Enter" },
1703 { SDLK_KP8, 75, 174, 33, "KP8" },
1704 { SDLK_KP4, 26, 186, 48, "KP4" },
1705 { SDLK_KP6, 118, 196, 32, "KP6" },
1706 { SDLK_KP2, 75, 234, 16, "KP2" },
1707 { SDLK_KP_PERIOD, 54, 250, 24, "Period" },
1708 { 0, 0, 0, 0, "None" }
1709};
1710#elif defined (IRIVER_H10)
1711struct button_map bm[] = {
1712 { SDLK_KP_PLUS, 38, 70, 37, "Power" },
1713 { SDLK_KP4, 123, 194, 26, "Cancel" },
1714 { SDLK_KP6, 257, 195, 34, "Select" },
1715 { SDLK_KP8, 190, 221, 28, "Up" },
1716 { SDLK_KP2, 192, 320, 27, "Down" },
1717 { SDLK_KP_DIVIDE, 349, 49, 20, "Rew" },
1718 { SDLK_KP5, 349, 96, 20, "Play" },
1719 { SDLK_KP_MULTIPLY, 350, 141, 23, "FF" },
1720 { 0, 0, 0, 0, "None" }
1721};
1722#elif defined (IRIVER_H10_5GB)
1723struct button_map bm[] = {
1724 { SDLK_KP_PLUS, 34, 76, 23, "Power" },
1725 { SDLK_KP4, 106, 222, 28, "Cancel" },
1726 { SDLK_KP6, 243, 220, 31, "Select" },
1727 { SDLK_KP8, 176, 254, 34, "Up" },
1728 { SDLK_KP2, 175, 371, 35, "Down" },
1729 { SDLK_KP_DIVIDE, 319, 63, 26, "Rew" },
1730 { SDLK_KP5, 320, 124, 26, "Play" },
1731 { SDLK_KP_MULTIPLY, 320, 181, 32, "FF" },
1732 { 0, 0, 0, 0, "None" }
1733};
1734#elif defined (IRIVER_H120) || defined (IRIVER_H100)
1735struct button_map bm[] = {
1736 { SDLK_KP_DIVIDE, 46, 162, 13, "Record" },
1737 { SDLK_KP_PLUS, 327, 36, 16, "Play" },
1738 { SDLK_KP_ENTER, 330, 99, 18, "Stop" },
1739 { SDLK_KP_PERIOD, 330, 163, 18, "AB" },
1740 { SDLK_KP5, 186, 227, 27, "5" },
1741 { SDLK_KP8, 187, 185, 19, "8" },
1742 { SDLK_KP4, 142, 229, 23, "4" },
1743 { SDLK_KP6, 231, 229, 22, "6" },
1744 { SDLK_KP2, 189, 272, 28, "2" },
1745/* Remote Buttons */
1746 { SDLK_KP_ENTER, 250, 404, 20, "Stop" },
1747 { SDLK_SPACE, 285, 439, 29, "Space" },
1748 { SDLK_h, 336, 291, 24, "Hold" },
1749 { 0, 0, 0, 0, "None" }
1750};
1751#elif defined (IRIVER_H300)
1752struct button_map bm[] = {
1753 { SDLK_KP_PLUS, 56, 335, 20, "Play" },
1754 { SDLK_KP8, 140, 304, 29, "Up" },
1755 { SDLK_KP_DIVIDE, 233, 331, 23, "Record" },
1756 { SDLK_KP_ENTER, 54, 381, 24, "Stop" },
1757 { SDLK_KP4, 100, 353, 17, "Left" },
1758 { SDLK_KP5, 140, 351, 19, "Navi" },
1759 { SDLK_KP6, 185, 356, 19, "Right" },
1760 { SDLK_KP_PERIOD, 230, 380, 20, "AB" },
1761 { SDLK_KP2, 142, 402, 24, "Down" },
1762 { SDLK_KP_ENTER, 211, 479, 21, "Stop" },
1763 { SDLK_KP_PLUS, 248, 513, 29, "Play" },
1764 { 0, 0, 0, 0, "None" }
1765};
1766#elif defined (MROBE_500)
1767struct button_map bm[] = {
1768 { SDLK_KP9, 171, 609, 9, "Play" },
1769 { SDLK_KP4, 158, 623, 9, "Left" },
1770 { SDLK_KP6, 184, 622, 9, "Right" },
1771 { SDLK_KP7, 171, 638, 11, "Menu" },
1772 { 0, 0, 0, 0, "None" }
1773};
1774#elif defined (MROBE_100)
1775struct button_map bm[] = {
1776 { SDLK_KP7, 80, 233, 30, "Menu" },
1777 { SDLK_KP8, 138, 250, 19, "Up" },
1778 { SDLK_KP9, 201, 230, 27, "Play" },
1779 { SDLK_KP4, 63, 305, 25, "Left" },
1780 { SDLK_KP5, 125, 309, 28, "Select" },
1781 { SDLK_KP6, 200, 307, 35, "Right" },
1782 { SDLK_KP1, 52, 380, 32, "Display" },
1783 { SDLK_KP2, 125, 363, 30, "Down" },
1784 { SDLK_KP9, 168, 425, 10, "Play" },
1785 { SDLK_KP4, 156, 440, 11, "Left" },
1786 { SDLK_KP6, 180, 440, 13, "Right" },
1787 { SDLK_KP7, 169, 452, 10, "Menu" },
1788 { SDLK_KP_MULTIPLY, 222, 15, 16, "Power" },
1789 { 0, 0, 0, 0, "None" }
1790};
1791#elif defined (GIGABEAT_F)
1792struct button_map bm[] = {
1793 { SDLK_KP_PLUS, 361, 187, 22, "Power" },
1794 { SDLK_KP_PERIOD, 361, 270, 17, "Menu" },
1795 { SDLK_KP9, 365, 345, 26, "Vol Up" },
1796 { SDLK_KP3, 363, 433, 25, "Vol Down" },
1797 { SDLK_KP_ENTER, 365, 520, 19, "A" },
1798 { SDLK_KP8, 167, 458, 35, "Up" },
1799 { SDLK_KP4, 86, 537, 29, "Left" },
1800 { SDLK_KP5, 166, 536, 30, "Select" },
1801 { SDLK_KP6, 248, 536, 30, "Right" },
1802 { SDLK_KP2, 169, 617, 28, "Down" },
1803 { 0, 0, 0, 0, "None" }
1804};
1805#elif defined (GIGABEAT_S)
1806struct button_map bm[] = {
1807 { SDLK_KP_PLUS, 416, 383, 23, "Play" },
1808 { SDLK_KP7, 135, 442, 46, "Back" },
1809 { SDLK_KP9, 288, 447, 35, "Menu" },
1810 { SDLK_KP8, 214, 480, 32, "Up" },
1811 { SDLK_KP4, 128, 558, 33, "Left" },
1812 { SDLK_KP5, 214, 556, 34, "Select" },
1813 { SDLK_KP6, 293, 558, 35, "Right" },
1814 { SDLK_KP2, 214, 637, 38, "Down" },
1815 { 0, 0, 0, 0, "None" }
1816};
1817#elif defined (SAMSUNG_YH820)
1818struct button_map bm[] = {
1819 { SDLK_KP_PLUS, 330, 53, 23, "Record" },
1820 { SDLK_KP7, 132, 208, 21, "Left" },
1821 { SDLK_KP5, 182, 210, 18, "Play" },
1822 { SDLK_KP9, 234, 211, 22, "Right" },
1823 { SDLK_KP8, 182, 260, 15, "Up" },
1824 { SDLK_KP4, 122, 277, 29, "Menu" },
1825 { SDLK_KP6, 238, 276, 25, "Select" },
1826 { SDLK_KP2, 183, 321, 24, "Down" },
1827 { 0, 0, 0, 0, "None" }
1828};
1829#elif defined (SAMSUNG_YH920) || defined (SAMSUNG_YH925)
1830struct button_map bm[] = {
1831 { SDLK_KP9, 370, 32, 15, "FF" },
1832 { SDLK_KP5, 369, 84, 25, "Play" },
1833 { SDLK_KP5, 367, 125, 27, "Play" },
1834 { SDLK_KP3, 369, 188, 17, "Rew" },
1835 { SDLK_KP_PLUS, 370, 330, 30, "Record" },
1836 { SDLK_KP4, 146, 252, 32, "Menu" },
1837 { SDLK_KP8, 204, 226, 27, "Up" },
1838 { SDLK_KP6, 257, 250, 34, "Select" },
1839 { SDLK_KP2, 205, 294, 35, "Down" },
1840 { 0, 0, 0, 0, "None" }
1841};
1842#elif defined (ONDA_VX747) || defined (ONDA_VX747P)
1843struct button_map bm[] = {
1844 { SDLK_MINUS, 113, 583, 28, "Minus" },
1845 { SDLK_PLUS, 227, 580, 28, "Plus" },
1846 { SDLK_RETURN, 171, 583, 34, "Menu" },
1847 { 0, 0, 0, 0, "None" }
1848};
1849#elif defined (PHILIPS_SA9200)
1850struct button_map bm[] = {
1851 { SDLK_KP_ENTER, 25, 155, 33, "Power" },
1852 { SDLK_PAGEUP, 210, 98, 31, "Vol Up" },
1853 { SDLK_PAGEDOWN, 210, 168, 34, "Vol Down" },
1854 { SDLK_KP7, 40, 249, 26, "Prev" },
1855 { SDLK_KP8, 110, 247, 22, "Up" },
1856 { SDLK_KP9, 183, 249, 31, "Next" },
1857 { SDLK_KP4, 45, 305, 25, "Left" },
1858 { SDLK_KP5, 111, 304, 24, "Play" },
1859 { SDLK_KP6, 183, 304, 21, "Right" },
1860 { SDLK_KP1, 43, 377, 21, "Menu" },
1861 { SDLK_KP2, 112, 371, 24, "Down" },
1862 { 0, 0, 0, 0, "None" }
1863};
1864#elif defined (CREATIVE_ZVM) || defined (CREATIVE_ZVM60GB) || \
1865 defined (CREATIVE_ZV)
1866struct button_map bm[] = {
1867 { SDLK_KP7, 52, 414, 35, "Custom" },
1868 { SDLK_KP8, 185, 406, 55, "Up" },
1869 { SDLK_KP9, 315, 421, 46, "Play" },
1870 { SDLK_KP4, 122, 500, 41, "Left" },
1871 { SDLK_KP6, 247, 493, 49, "Right" },
1872 { SDLK_KP1, 58, 577, 49, "Back" },
1873 { SDLK_KP2, 186, 585, 46, "Down" },
1874 { SDLK_KP3, 311, 569, 47, "Menu" },
1875 { 0, 0, 0, 0, "None" }
1876};
1877#elif defined (MPIO_HD200)
1878struct button_map bm[] = {
1879 { SDLK_ESCAPE, 369, 257, 20, "Rec" },
1880 { SDLK_RETURN, 369, 305, 20, "Play/Stop" },
1881 { SDLK_UP, 353, 168, 10, "Rew" },
1882 { SDLK_DOWN, 353, 198, 10, "FF" },
1883 { SDLK_SPACE, 353, 186, 10, "Select" },
1884 { SDLK_LEFT, 123, 67, 20, "Vol Down" },
1885 { SDLK_RIGHT, 206, 67, 20, "Vol Up" },
1886 { SDLK_h, 369, 402, 30, "Hold" },
1887 { 0, 0, 0, 0, "None" }
1888};
1889#else
1890struct button_map bm[] = {
1891 { 0, 0, 0, 0, ""}
1892};
1893#endif
1894
1895int xy2button( int x, int y) {
1896 int i;
1897 extern bool debug_buttons;
1898
1899 for ( i = 0; bm[i].button; i++ )
1900 /* check distance from center of button < radius */
1901 if ( ( (x-bm[i].x)*(x-bm[i].x) ) + ( ( y-bm[i].y)*(y-bm[i].y) ) < bm[i].radius*bm[i].radius ) {
1902 if (debug_buttons)
1903 printf("Button: %s\n", bm[i].description );
1904 return bm[i].button;
1905 }
1906 return 0;
1907}
diff --git a/uisimulator/sdl/kernel-sdl.c b/uisimulator/sdl/kernel-sdl.c
deleted file mode 100644
index 3288a6f97a..0000000000
--- a/uisimulator/sdl/kernel-sdl.c
+++ /dev/null
@@ -1,155 +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 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include <stdlib.h>
23#include <SDL.h>
24#include <SDL_thread.h>
25#include "memory.h"
26#include "system-sdl.h"
27#include "uisdl.h"
28#include "kernel.h"
29#include "thread-sdl.h"
30#include "thread.h"
31#include "debug.h"
32
33static SDL_TimerID tick_timer_id;
34long start_tick;
35
36/* Condition to signal that "interrupts" may proceed */
37static SDL_cond *sim_thread_cond;
38/* Mutex to serialize changing levels and exclude other threads while
39 * inside a handler */
40static SDL_mutex *sim_irq_mtx;
41static int interrupt_level = HIGHEST_IRQ_LEVEL;
42static int handlers_pending = 0;
43static int status_reg = 0;
44
45/* Nescessary logic:
46 * 1) All threads must pass unblocked
47 * 2) Current handler must always pass unblocked
48 * 3) Threads must be excluded when irq routine is running
49 * 4) No more than one handler routine should execute at a time
50 */
51int set_irq_level(int level)
52{
53 SDL_LockMutex(sim_irq_mtx);
54
55 int oldlevel = interrupt_level;
56
57 if (status_reg == 0 && level == 0 && oldlevel != 0)
58 {
59 /* Not in a handler and "interrupts" are being reenabled */
60 if (handlers_pending > 0)
61 SDL_CondSignal(sim_thread_cond);
62 }
63
64 interrupt_level = level; /* save new level */
65
66 SDL_UnlockMutex(sim_irq_mtx);
67 return oldlevel;
68}
69
70void sim_enter_irq_handler(void)
71{
72 SDL_LockMutex(sim_irq_mtx);
73 handlers_pending++;
74
75 if(interrupt_level != 0)
76 {
77 /* "Interrupts" are disabled. Wait for reenable */
78 SDL_CondWait(sim_thread_cond, sim_irq_mtx);
79 }
80
81 status_reg = 1;
82}
83
84void sim_exit_irq_handler(void)
85{
86 if (--handlers_pending > 0)
87 SDL_CondSignal(sim_thread_cond);
88
89 status_reg = 0;
90 SDL_UnlockMutex(sim_irq_mtx);
91}
92
93bool sim_kernel_init(void)
94{
95 sim_irq_mtx = SDL_CreateMutex();
96 if (sim_irq_mtx == NULL)
97 {
98 fprintf(stderr, "Cannot create sim_handler_mtx\n");
99 return false;
100 }
101
102 sim_thread_cond = SDL_CreateCond();
103 if (sim_thread_cond == NULL)
104 {
105 fprintf(stderr, "Cannot create sim_thread_cond\n");
106 return false;
107 }
108
109 return true;
110}
111
112void sim_kernel_shutdown(void)
113{
114 SDL_RemoveTimer(tick_timer_id);
115 SDL_DestroyMutex(sim_irq_mtx);
116 SDL_DestroyCond(sim_thread_cond);
117}
118
119Uint32 tick_timer(Uint32 interval, void *param)
120{
121 long new_tick;
122
123 (void) interval;
124 (void) param;
125
126 new_tick = (SDL_GetTicks() - start_tick) / (1000/HZ);
127
128 while(new_tick != current_tick)
129 {
130 sim_enter_irq_handler();
131
132 /* Run through the list of tick tasks - increments tick
133 * on each iteration. */
134 call_tick_tasks();
135
136 sim_exit_irq_handler();
137 }
138
139 return 1;
140}
141
142void tick_start(unsigned int interval_in_ms)
143{
144 if (tick_timer_id != NULL)
145 {
146 SDL_RemoveTimer(tick_timer_id);
147 tick_timer_id = NULL;
148 }
149 else
150 {
151 start_tick = SDL_GetTicks();
152 }
153
154 tick_timer_id = SDL_AddTimer(interval_in_ms, tick_timer, NULL);
155}
diff --git a/uisimulator/sdl/lcd-bitmap.c b/uisimulator/sdl/lcd-bitmap.c
deleted file mode 100644
index 0bd90196e4..0000000000
--- a/uisimulator/sdl/lcd-bitmap.c
+++ /dev/null
@@ -1,415 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 Dan Everton
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "debug.h"
23#include "uisdl.h"
24#include "lcd-sdl.h"
25#include "screendump.h"
26
27SDL_Surface* lcd_surface;
28
29#if LCD_DEPTH <= 8
30#ifdef HAVE_BACKLIGHT
31SDL_Color lcd_bl_color_dark = {RED_CMP(LCD_BL_DARKCOLOR),
32 GREEN_CMP(LCD_BL_DARKCOLOR),
33 BLUE_CMP(LCD_BL_DARKCOLOR), 0};
34SDL_Color lcd_bl_color_bright = {RED_CMP(LCD_BL_BRIGHTCOLOR),
35 GREEN_CMP(LCD_BL_BRIGHTCOLOR),
36 BLUE_CMP(LCD_BL_BRIGHTCOLOR), 0};
37#ifdef HAVE_LCD_SPLIT
38SDL_Color lcd_bl_color2_dark = {RED_CMP(LCD_BL_DARKCOLOR_2),
39 GREEN_CMP(LCD_BL_DARKCOLOR_2),
40 BLUE_CMP(LCD_BL_DARKCOLOR_2), 0};
41SDL_Color lcd_bl_color2_bright = {RED_CMP(LCD_BL_BRIGHTCOLOR_2),
42 GREEN_CMP(LCD_BL_BRIGHTCOLOR_2),
43 BLUE_CMP(LCD_BL_BRIGHTCOLOR_2), 0};
44#endif
45#endif /* HAVE_BACKLIGHT */
46SDL_Color lcd_color_dark = {RED_CMP(LCD_DARKCOLOR),
47 GREEN_CMP(LCD_DARKCOLOR),
48 BLUE_CMP(LCD_DARKCOLOR), 0};
49SDL_Color lcd_color_bright = {RED_CMP(LCD_BRIGHTCOLOR),
50 GREEN_CMP(LCD_BRIGHTCOLOR),
51 BLUE_CMP(LCD_BRIGHTCOLOR), 0};
52#ifdef HAVE_LCD_SPLIT
53SDL_Color lcd_color2_dark = {RED_CMP(LCD_DARKCOLOR_2),
54 GREEN_CMP(LCD_DARKCOLOR_2),
55 BLUE_CMP(LCD_DARKCOLOR_2), 0};
56SDL_Color lcd_color2_bright = {RED_CMP(LCD_BRIGHTCOLOR_2),
57 GREEN_CMP(LCD_BRIGHTCOLOR_2),
58 BLUE_CMP(LCD_BRIGHTCOLOR_2), 0};
59#endif
60
61#ifdef HAVE_LCD_SPLIT
62#define NUM_SHADES 128
63#else
64#define NUM_SHADES 129
65#endif
66
67#else /* LCD_DEPTH > 8 */
68
69#ifdef HAVE_TRANSFLECTIVE_LCD
70#define BACKLIGHT_OFF_ALPHA 85 /* 1/3 brightness */
71#else
72#define BACKLIGHT_OFF_ALPHA 0 /* pitch black */
73#endif
74
75#endif /* LCD_DEPTH */
76
77#if LCD_DEPTH < 8
78unsigned long (*lcd_ex_getpixel)(int, int) = NULL;
79#endif /* LCD_DEPTH < 8 */
80
81#if LCD_DEPTH == 2
82/* Only defined for positive, non-split LCD for now */
83static const unsigned char colorindex[4] = {128, 85, 43, 0};
84#endif
85
86static unsigned long get_lcd_pixel(int x, int y)
87{
88#if LCD_DEPTH == 1
89#ifdef HAVE_NEGATIVE_LCD
90 return (lcd_framebuffer[y/8][x] & (1 << (y & 7))) ? (NUM_SHADES-1) : 0;
91#else
92 return (lcd_framebuffer[y/8][x] & (1 << (y & 7))) ? 0 : (NUM_SHADES-1);
93#endif
94#elif LCD_DEPTH == 2
95#if LCD_PIXELFORMAT == HORIZONTAL_PACKING
96 return colorindex[(lcd_framebuffer[y][x/4] >> (2 * (~x & 3))) & 3];
97#elif LCD_PIXELFORMAT == VERTICAL_PACKING
98 return colorindex[(lcd_framebuffer[y/4][x] >> (2 * (y & 3))) & 3];
99#elif LCD_PIXELFORMAT == VERTICAL_INTERLEAVED
100 unsigned bits = (lcd_framebuffer[y/8][x] >> (y & 7)) & 0x0101;
101 return colorindex[(bits | (bits >> 7)) & 3];
102#endif
103#elif LCD_DEPTH == 16
104#if LCD_PIXELFORMAT == RGB565SWAPPED
105 unsigned bits = lcd_framebuffer[y][x];
106 return (bits >> 8) | (bits << 8);
107#else
108#if defined(LCD_STRIDEFORMAT) && LCD_STRIDEFORMAT == VERTICAL_STRIDE
109 return *(&lcd_framebuffer[0][0]+LCD_HEIGHT*x+y);
110#else
111 return lcd_framebuffer[y][x];
112#endif
113#endif
114#endif
115}
116
117void lcd_update(void)
118{
119 /* update a full screen rect */
120 lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT);
121}
122
123void lcd_update_rect(int x_start, int y_start, int width, int height)
124{
125 sdl_update_rect(lcd_surface, x_start, y_start, width, height,
126 LCD_WIDTH, LCD_HEIGHT, get_lcd_pixel);
127 sdl_gui_update(lcd_surface, x_start, y_start, width,
128 height + LCD_SPLIT_LINES, SIM_LCD_WIDTH, SIM_LCD_HEIGHT,
129 background ? UI_LCD_POSX : 0, background? UI_LCD_POSY : 0);
130}
131
132#ifdef HAVE_BACKLIGHT
133void sim_backlight(int value)
134{
135#if LCD_DEPTH <= 8
136 if (value > 0) {
137 sdl_set_gradient(lcd_surface, &lcd_bl_color_dark,
138 &lcd_bl_color_bright, 0, NUM_SHADES);
139#ifdef HAVE_LCD_SPLIT
140 sdl_set_gradient(lcd_surface, &lcd_bl_color2_dark,
141 &lcd_bl_color2_bright, NUM_SHADES, NUM_SHADES);
142#endif
143 } else {
144 sdl_set_gradient(lcd_surface, &lcd_color_dark,
145 &lcd_color_bright, 0, NUM_SHADES);
146#ifdef HAVE_LCD_SPLIT
147 sdl_set_gradient(lcd_surface, &lcd_color2_dark,
148 &lcd_color2_bright, NUM_SHADES, NUM_SHADES);
149#endif
150 }
151#else /* LCD_DEPTH > 8 */
152 SDL_SetAlpha(lcd_surface, SDL_SRCALPHA, (value * 255) / 100);
153#endif /* LCD_DEPTH */
154
155 sdl_gui_update(lcd_surface, 0, 0, SIM_LCD_WIDTH, SIM_LCD_HEIGHT,
156 SIM_LCD_WIDTH, SIM_LCD_HEIGHT,
157 background ? UI_LCD_POSX : 0, background? UI_LCD_POSY : 0);
158}
159#endif /* HAVE_BACKLIGHT */
160
161/* initialise simulator lcd driver */
162void sim_lcd_init(void)
163{
164#if LCD_DEPTH == 16
165 lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
166 SIM_LCD_WIDTH * display_zoom,
167 SIM_LCD_HEIGHT * display_zoom,
168 LCD_DEPTH, 0, 0, 0, 0);
169#elif LCD_DEPTH <= 8
170 lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
171 SIM_LCD_WIDTH * display_zoom,
172 SIM_LCD_HEIGHT * display_zoom,
173 8, 0, 0, 0, 0);
174
175#ifdef HAVE_BACKLIGHT
176 sdl_set_gradient(lcd_surface, &lcd_bl_color_dark,
177 &lcd_bl_color_bright, 0, NUM_SHADES);
178#ifdef HAVE_LCD_SPLIT
179 sdl_set_gradient(lcd_surface, &lcd_bl_color2_dark,
180 &lcd_bl_color2_bright, NUM_SHADES, NUM_SHADES);
181#endif
182#else /* !HAVE_BACKLIGHT */
183 sdl_set_gradient(lcd_surface, &lcd_color_dark,
184 &lcd_color_bright, 0, NUM_SHADES);
185#ifdef HAVE_LCD_SPLIT
186 sdl_set_gradient(lcd_surface, &lcd_color2_dark,
187 &lcd_color2_bright, NUM_SHADES, NUM_SHADES);
188#endif
189#endif /* !HAVE_BACKLIGHT */
190#endif /* LCD_DEPTH */
191}
192
193#if LCD_DEPTH < 8
194void sim_lcd_ex_init(unsigned long (*getpixel)(int, int))
195{
196 lcd_ex_getpixel = getpixel;
197}
198
199void sim_lcd_ex_update_rect(int x_start, int y_start, int width, int height)
200{
201 if (lcd_ex_getpixel) {
202 sdl_update_rect(lcd_surface, x_start, y_start, width, height,
203 LCD_WIDTH, LCD_HEIGHT, lcd_ex_getpixel);
204 sdl_gui_update(lcd_surface, x_start, y_start, width,
205 height + LCD_SPLIT_LINES, SIM_LCD_WIDTH, SIM_LCD_HEIGHT,
206 background ? UI_LCD_POSX : 0,
207 background ? UI_LCD_POSY : 0);
208 }
209}
210#endif
211
212#ifdef HAVE_LCD_COLOR
213/**
214 * |R| |1.000000 -0.000001 1.402000| |Y'|
215 * |G| = |1.000000 -0.334136 -0.714136| |Pb|
216 * |B| |1.000000 1.772000 0.000000| |Pr|
217 * Scaled, normalized, rounded and tweaked to yield RGB 565:
218 * |R| |74 0 101| |Y' - 16| >> 9
219 * |G| = |74 -24 -51| |Cb - 128| >> 8
220 * |B| |74 128 0| |Cr - 128| >> 9
221 */
222#define YFAC (74)
223#define RVFAC (101)
224#define GUFAC (-24)
225#define GVFAC (-51)
226#define BUFAC (128)
227
228static inline int clamp(int val, int min, int max)
229{
230 if (val < min)
231 val = min;
232 else if (val > max)
233 val = max;
234 return val;
235}
236
237void lcd_yuv_set_options(unsigned options)
238{
239 (void)options;
240}
241
242/* Draw a partial YUV colour bitmap - similiar behavior to lcd_blit_yuv
243 in the core */
244void lcd_blit_yuv(unsigned char * const src[3],
245 int src_x, int src_y, int stride,
246 int x, int y, int width, int height)
247{
248 const unsigned char *ysrc, *usrc, *vsrc;
249 int linecounter;
250 fb_data *dst, *row_end;
251 long z;
252
253 /* width and height must be >= 2 and an even number */
254 width &= ~1;
255 linecounter = height >> 1;
256
257#if LCD_WIDTH >= LCD_HEIGHT
258 dst = &lcd_framebuffer[y][x];
259 row_end = dst + width;
260#else
261 dst = &lcd_framebuffer[x][LCD_WIDTH - y - 1];
262 row_end = dst + LCD_WIDTH * width;
263#endif
264
265 z = stride * src_y;
266 ysrc = src[0] + z + src_x;
267 usrc = src[1] + (z >> 2) + (src_x >> 1);
268 vsrc = src[2] + (usrc - src[1]);
269
270 /* stride => amount to jump from end of last row to start of next */
271 stride -= width;
272
273 /* upsampling, YUV->RGB conversion and reduction to RGB565 in one go */
274
275 do
276 {
277 do
278 {
279 int y, cb, cr, rv, guv, bu, r, g, b;
280
281 y = YFAC*(*ysrc++ - 16);
282 cb = *usrc++ - 128;
283 cr = *vsrc++ - 128;
284
285 rv = RVFAC*cr;
286 guv = GUFAC*cb + GVFAC*cr;
287 bu = BUFAC*cb;
288
289 r = y + rv;
290 g = y + guv;
291 b = y + bu;
292
293 if ((unsigned)(r | g | b) > 64*256-1)
294 {
295 r = clamp(r, 0, 64*256-1);
296 g = clamp(g, 0, 64*256-1);
297 b = clamp(b, 0, 64*256-1);
298 }
299
300 *dst = LCD_RGBPACK_LCD(r >> 9, g >> 8, b >> 9);
301
302#if LCD_WIDTH >= LCD_HEIGHT
303 dst++;
304#else
305 dst += LCD_WIDTH;
306#endif
307
308 y = YFAC*(*ysrc++ - 16);
309 r = y + rv;
310 g = y + guv;
311 b = y + bu;
312
313 if ((unsigned)(r | g | b) > 64*256-1)
314 {
315 r = clamp(r, 0, 64*256-1);
316 g = clamp(g, 0, 64*256-1);
317 b = clamp(b, 0, 64*256-1);
318 }
319
320 *dst = LCD_RGBPACK_LCD(r >> 9, g >> 8, b >> 9);
321
322#if LCD_WIDTH >= LCD_HEIGHT
323 dst++;
324#else
325 dst += LCD_WIDTH;
326#endif
327 }
328 while (dst < row_end);
329
330 ysrc += stride;
331 usrc -= width >> 1;
332 vsrc -= width >> 1;
333
334#if LCD_WIDTH >= LCD_HEIGHT
335 row_end += LCD_WIDTH;
336 dst += LCD_WIDTH - width;
337#else
338 row_end -= 1;
339 dst -= LCD_WIDTH*width + 1;
340#endif
341
342 do
343 {
344 int y, cb, cr, rv, guv, bu, r, g, b;
345
346 y = YFAC*(*ysrc++ - 16);
347 cb = *usrc++ - 128;
348 cr = *vsrc++ - 128;
349
350 rv = RVFAC*cr;
351 guv = GUFAC*cb + GVFAC*cr;
352 bu = BUFAC*cb;
353
354 r = y + rv;
355 g = y + guv;
356 b = y + bu;
357
358 if ((unsigned)(r | g | b) > 64*256-1)
359 {
360 r = clamp(r, 0, 64*256-1);
361 g = clamp(g, 0, 64*256-1);
362 b = clamp(b, 0, 64*256-1);
363 }
364
365 *dst = LCD_RGBPACK_LCD(r >> 9, g >> 8, b >> 9);
366
367#if LCD_WIDTH >= LCD_HEIGHT
368 dst++;
369#else
370 dst += LCD_WIDTH;
371#endif
372
373 y = YFAC*(*ysrc++ - 16);
374 r = y + rv;
375 g = y + guv;
376 b = y + bu;
377
378 if ((unsigned)(r | g | b) > 64*256-1)
379 {
380 r = clamp(r, 0, 64*256-1);
381 g = clamp(g, 0, 64*256-1);
382 b = clamp(b, 0, 64*256-1);
383 }
384
385 *dst = LCD_RGBPACK_LCD(r >> 9, g >> 8, b >> 9);
386
387#if LCD_WIDTH >= LCD_HEIGHT
388 dst++;
389#else
390 dst += LCD_WIDTH;
391#endif
392 }
393 while (dst < row_end);
394
395 ysrc += stride;
396 usrc += stride >> 1;
397 vsrc += stride >> 1;
398
399#if LCD_WIDTH >= LCD_HEIGHT
400 row_end += LCD_WIDTH;
401 dst += LCD_WIDTH - width;
402#else
403 row_end -= 1;
404 dst -= LCD_WIDTH*width + 1;
405#endif
406 }
407 while (--linecounter > 0);
408
409#if LCD_WIDTH >= LCD_HEIGHT
410 lcd_update_rect(x, y, width, height);
411#else
412 lcd_update_rect(LCD_WIDTH - y - height, x, height, width);
413#endif
414}
415#endif /* HAVE_LCD_COLOR */
diff --git a/uisimulator/sdl/lcd-bitmap.h b/uisimulator/sdl/lcd-bitmap.h
deleted file mode 100644
index a898744b41..0000000000
--- a/uisimulator/sdl/lcd-bitmap.h
+++ /dev/null
@@ -1,35 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 Dan Everton
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef __LCDBITMAP_H__
23#define __LCDBITMAP_H__
24
25#include "lcd.h"
26#include "SDL.h"
27
28void sim_lcd_init(void);
29#if LCD_DEPTH < 8
30void sim_lcd_ex_init(unsigned long (*getpixel)(int, int));
31void sim_lcd_ex_update_rect(int x, int y, int width, int height);
32#endif
33
34#endif /* #ifndef __LCDBITMAP_H__ */
35
diff --git a/uisimulator/sdl/lcd-charcells.c b/uisimulator/sdl/lcd-charcells.c
deleted file mode 100644
index 05513ab266..0000000000
--- a/uisimulator/sdl/lcd-charcells.c
+++ /dev/null
@@ -1,197 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 Dan Everton
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "debug.h"
23#include "lcd.h"
24#include "lcd-charcell.h"
25#include "screendump.h"
26#include "general.h"
27#include <string.h>
28#include <unistd.h>
29#include <fcntl.h>
30
31#include "lcd-playersim.h"
32#include "uisdl.h"
33#include "lcd-sdl.h"
34
35/* can't include file.h here */
36#ifndef MAX_PATH
37#define MAX_PATH 260
38#endif
39
40/* extern functions, needed for screendump() */
41extern int sim_creat(const char *name, mode_t mode);
42
43SDL_Surface* lcd_surface;
44
45SDL_Color lcd_bl_color_dark = {RED_CMP(LCD_BL_DARKCOLOR),
46 GREEN_CMP(LCD_BL_DARKCOLOR),
47 BLUE_CMP(LCD_BL_DARKCOLOR), 0};
48SDL_Color lcd_bl_color_bright = {RED_CMP(LCD_BL_BRIGHTCOLOR),
49 GREEN_CMP(LCD_BL_BRIGHTCOLOR),
50 BLUE_CMP(LCD_BL_BRIGHTCOLOR), 0};
51SDL_Color lcd_color_dark = {RED_CMP(LCD_DARKCOLOR),
52 GREEN_CMP(LCD_DARKCOLOR),
53 BLUE_CMP(LCD_DARKCOLOR), 0};
54SDL_Color lcd_color_bright = {RED_CMP(LCD_BRIGHTCOLOR),
55 GREEN_CMP(LCD_BRIGHTCOLOR),
56 BLUE_CMP(LCD_BRIGHTCOLOR), 0};
57
58
59static unsigned long get_lcd_pixel(int x, int y)
60{
61 return sim_lcd_framebuffer[y][x];
62}
63
64void sim_lcd_update_rect(int x_start, int y_start, int width, int height)
65{
66 sdl_update_rect(lcd_surface, x_start, y_start, width, height,
67 SIM_LCD_WIDTH, SIM_LCD_HEIGHT, get_lcd_pixel);
68 sdl_gui_update(lcd_surface, x_start, y_start, width, height,
69 SIM_LCD_WIDTH, SIM_LCD_HEIGHT,
70 background ? UI_LCD_POSX : 0, background ? UI_LCD_POSY : 0);
71}
72
73void lcd_update(void)
74{
75 int x, y;
76
77 for (y = 0; y < lcd_pattern_count; y++)
78 if (lcd_patterns[y].count > 0)
79 sim_lcd_define_pattern(y, lcd_patterns[y].pattern);
80
81 for (y = 0; y < LCD_HEIGHT; y++)
82 for (x = 0; x < LCD_WIDTH; x++)
83 lcd_print_char(x, y, lcd_charbuffer[y][x]);
84
85 if (lcd_cursor.visible)
86 lcd_print_char(lcd_cursor.x, lcd_cursor.y, lcd_cursor.hw_char);
87
88 sim_lcd_update_rect(0, ICON_HEIGHT, SIM_LCD_WIDTH,
89 LCD_HEIGHT*CHAR_HEIGHT*CHAR_PIXEL);
90}
91
92#ifdef HAVE_BACKLIGHT
93void sim_backlight(int value)
94{
95 if (value > 0) {
96 sdl_set_gradient(lcd_surface, &lcd_bl_color_bright,
97 &lcd_bl_color_dark, 0, (1<<LCD_DEPTH));
98 } else {
99 sdl_set_gradient(lcd_surface, &lcd_color_bright,
100 &lcd_color_dark, 0, (1<<LCD_DEPTH));
101 }
102
103 sim_lcd_update_rect(0, 0, SIM_LCD_WIDTH, SIM_LCD_HEIGHT);
104}
105#endif
106
107/* initialise simulator lcd driver */
108void sim_lcd_init(void)
109{
110 lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
111 SIM_LCD_WIDTH * display_zoom,
112 SIM_LCD_HEIGHT * display_zoom,
113 8, 0, 0, 0, 0);
114
115 sdl_set_gradient(lcd_surface, &lcd_bl_color_bright,
116 &lcd_bl_color_dark, 0, (1<<LCD_DEPTH));
117}
118
119#define BMP_COMPRESSION 0 /* BI_RGB */
120#define BMP_NUMCOLORS (1 << LCD_DEPTH)
121#define BMP_BPP 1
122#define BMP_LINESIZE (((SIM_LCD_WIDTH + 31) / 32) * 4)
123
124#define BMP_HEADERSIZE (54 + 4 * BMP_NUMCOLORS)
125#define BMP_DATASIZE (BMP_LINESIZE * SIM_LCD_HEIGHT)
126#define BMP_TOTALSIZE (BMP_HEADERSIZE + BMP_DATASIZE)
127
128#define LE16_CONST(x) (x)&0xff, ((x)>>8)&0xff
129#define LE32_CONST(x) (x)&0xff, ((x)>>8)&0xff, ((x)>>16)&0xff, ((x)>>24)&0xff
130
131static const unsigned char bmpheader[] =
132{
133 0x42, 0x4d, /* 'BM' */
134 LE32_CONST(BMP_TOTALSIZE), /* Total file size */
135 0x00, 0x00, 0x00, 0x00, /* Reserved */
136 LE32_CONST(BMP_HEADERSIZE), /* Offset to start of pixel data */
137
138 0x28, 0x00, 0x00, 0x00, /* Size of (2nd) header */
139 LE32_CONST(SIM_LCD_WIDTH), /* Width in pixels */
140 LE32_CONST(SIM_LCD_HEIGHT), /* Height in pixels */
141 0x01, 0x00, /* Number of planes (always 1) */
142 LE16_CONST(BMP_BPP), /* Bits per pixel 1/4/8/16/24 */
143 LE32_CONST(BMP_COMPRESSION),/* Compression mode */
144 LE32_CONST(BMP_DATASIZE), /* Size of bitmap data */
145 0xc4, 0x0e, 0x00, 0x00, /* Horizontal resolution (pixels/meter) */
146 0xc4, 0x0e, 0x00, 0x00, /* Vertical resolution (pixels/meter) */
147 LE32_CONST(BMP_NUMCOLORS), /* Number of used colours */
148 LE32_CONST(BMP_NUMCOLORS), /* Number of important colours */
149
150 BMP_COLOR(LCD_BL_BRIGHTCOLOR),
151 BMP_COLOR(LCD_BL_DARKCOLOR)
152};
153
154void screen_dump(void)
155{
156 int fd;
157 char filename[MAX_PATH];
158 int x, y;
159 static unsigned char line[BMP_LINESIZE];
160
161 create_numbered_filename(filename, "", "dump_", ".bmp", 4
162 IF_CNFN_NUM_(, NULL));
163 DEBUGF("screen_dump\n");
164
165 fd = sim_creat(filename, 0666);
166 if (fd < 0)
167 return;
168
169 write(fd, bmpheader, sizeof(bmpheader));
170 SDL_LockSurface(lcd_surface);
171
172 /* BMP image goes bottom up */
173 for (y = SIM_LCD_HEIGHT - 1; y >= 0; y--)
174 {
175 Uint8 *src = (Uint8 *)lcd_surface->pixels
176 + y * SIM_LCD_WIDTH * display_zoom * display_zoom;
177 unsigned char *dst = line;
178 unsigned dst_mask = 0x80;
179
180 memset(line, 0, sizeof(line));
181 for (x = SIM_LCD_WIDTH; x > 0; x--)
182 {
183 if (*src)
184 *dst |= dst_mask;
185 src += display_zoom;
186 dst_mask >>= 1;
187 if (dst_mask == 0)
188 {
189 dst++;
190 dst_mask = 0x80;
191 }
192 }
193 write(fd, line, sizeof(line));
194 }
195 SDL_UnlockSurface(lcd_surface);
196 close(fd);
197}
diff --git a/uisimulator/sdl/lcd-charcells.h b/uisimulator/sdl/lcd-charcells.h
deleted file mode 100644
index 890594f766..0000000000
--- a/uisimulator/sdl/lcd-charcells.h
+++ /dev/null
@@ -1,34 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 Dan Everton
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef __LCDCHARCELL_H__
23#define __LCDCHARCELL_H__
24
25#include "lcd.h"
26#include "SDL.h"
27
28#ifdef HAVE_LCD_CHARCELLS
29void sim_lcd_init(void);
30void screen_dump(void);
31#endif
32
33#endif /* #ifndef __LCDCHARCELL_H__ */
34
diff --git a/uisimulator/sdl/lcd-remote-bitmap.c b/uisimulator/sdl/lcd-remote-bitmap.c
deleted file mode 100644
index c44e476288..0000000000
--- a/uisimulator/sdl/lcd-remote-bitmap.c
+++ /dev/null
@@ -1,110 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 Dan Everton
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "uisdl.h"
23#include "lcd-sdl.h"
24#include "lcd-remote-bitmap.h"
25#include "screendump.h"
26
27SDL_Surface *remote_surface = 0;
28
29SDL_Color remote_bl_color_dark = {RED_CMP(LCD_REMOTE_BL_DARKCOLOR),
30 GREEN_CMP(LCD_REMOTE_BL_DARKCOLOR),
31 BLUE_CMP(LCD_REMOTE_BL_DARKCOLOR), 0};
32SDL_Color remote_bl_color_bright = {RED_CMP(LCD_REMOTE_BL_BRIGHTCOLOR),
33 GREEN_CMP(LCD_REMOTE_BL_BRIGHTCOLOR),
34 BLUE_CMP(LCD_REMOTE_BL_BRIGHTCOLOR), 0};
35SDL_Color remote_color_dark = {RED_CMP(LCD_REMOTE_DARKCOLOR),
36 GREEN_CMP(LCD_REMOTE_DARKCOLOR),
37 BLUE_CMP(LCD_REMOTE_DARKCOLOR), 0};
38SDL_Color remote_color_bright = {RED_CMP(LCD_REMOTE_BRIGHTCOLOR),
39 GREEN_CMP(LCD_REMOTE_BRIGHTCOLOR),
40 BLUE_CMP(LCD_REMOTE_BRIGHTCOLOR), 0};
41
42#define NUM_SHADES 129
43
44#if LCD_REMOTE_DEPTH == 2
45/* Only defined for positive, non-split LCD for now */
46static const unsigned char colorindex[4] = {128, 85, 43, 0};
47#endif
48
49static unsigned long get_lcd_remote_pixel(int x, int y)
50{
51#if LCD_REMOTE_DEPTH == 1
52 return lcd_remote_framebuffer[y/8][x] & (1 << (y & 7)) ? 0 : (NUM_SHADES-1);
53#elif LCD_REMOTE_DEPTH == 2
54#if LCD_REMOTE_PIXELFORMAT == VERTICAL_INTERLEAVED
55 unsigned bits = (lcd_remote_framebuffer[y/8][x] >> (y & 7)) & 0x0101;
56 return colorindex[(bits | (bits >> 7)) & 3];
57#endif
58#endif
59}
60
61void lcd_remote_update (void)
62{
63 lcd_remote_update_rect(0, 0, LCD_REMOTE_WIDTH, LCD_REMOTE_HEIGHT);
64}
65
66void lcd_remote_update_rect(int x_start, int y_start, int width, int height)
67{
68 if (remote_surface)
69 {
70 sdl_update_rect(remote_surface, x_start, y_start, width, height,
71 LCD_REMOTE_WIDTH, LCD_REMOTE_HEIGHT, get_lcd_remote_pixel);
72 sdl_gui_update(remote_surface, x_start, y_start, width, height,
73 LCD_REMOTE_WIDTH, LCD_REMOTE_HEIGHT, background ? UI_REMOTE_POSX : 0,
74 background ? UI_REMOTE_POSY : LCD_HEIGHT);
75 }
76}
77
78void sim_remote_backlight(int value)
79{
80 if (remote_surface)
81 {
82 if (value > 0)
83 {
84 sdl_set_gradient(remote_surface, &remote_bl_color_dark,
85 &remote_bl_color_bright, 0, NUM_SHADES);
86 }
87 else
88 {
89 sdl_set_gradient(remote_surface, &remote_color_dark,
90 &remote_color_bright, 0, NUM_SHADES);
91 }
92 sdl_gui_update(remote_surface, 0, 0, LCD_REMOTE_WIDTH, LCD_REMOTE_HEIGHT,
93 LCD_REMOTE_WIDTH, LCD_REMOTE_HEIGHT,
94 background ? UI_REMOTE_POSX : 0,
95 background? UI_REMOTE_POSY : LCD_HEIGHT);
96 }
97}
98
99/* initialise simulator lcd remote driver */
100void sim_lcd_remote_init(void)
101{
102 remote_surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
103 LCD_REMOTE_WIDTH * display_zoom,
104 LCD_REMOTE_HEIGHT * display_zoom,
105 8, 0, 0, 0, 0);
106
107 sdl_set_gradient(remote_surface, &remote_bl_color_dark,
108 &remote_bl_color_bright, 0, NUM_SHADES);
109}
110
diff --git a/uisimulator/sdl/lcd-remote-bitmap.h b/uisimulator/sdl/lcd-remote-bitmap.h
deleted file mode 100644
index 0a92ee6b79..0000000000
--- a/uisimulator/sdl/lcd-remote-bitmap.h
+++ /dev/null
@@ -1,32 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 Dan Everton
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef __LCDREMOTE_H__
23#define __LCDREMOTE_H__
24
25#include "lcd.h"
26#include "lcd-remote.h"
27#include "SDL.h"
28
29void sim_lcd_remote_init(void);
30
31#endif /* #ifndef __LCDREMOTE_H__ */
32
diff --git a/uisimulator/sdl/lcd-sdl.c b/uisimulator/sdl/lcd-sdl.c
deleted file mode 100644
index f1ffe8a76a..0000000000
--- a/uisimulator/sdl/lcd-sdl.c
+++ /dev/null
@@ -1,112 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 Dan Everton
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "lcd-sdl.h"
23#include "uisdl.h"
24#include "system.h" /* for MIN() and MAX() */
25
26int display_zoom = 1;
27
28void sdl_update_rect(SDL_Surface *surface, int x_start, int y_start, int width,
29 int height, int max_x, int max_y,
30 unsigned long (*getpixel)(int, int))
31{
32 int x, y;
33 int xmax, ymax;
34 SDL_Rect dest;
35
36 ymax = y_start + height;
37 xmax = x_start + width;
38
39 if(xmax > max_x)
40 xmax = max_x;
41 if(ymax >= max_y)
42 ymax = max_y;
43
44 SDL_LockSurface(surface);
45
46 dest.w = display_zoom;
47 dest.h = display_zoom;
48
49 for (x = x_start; x < xmax; x++) {
50 dest.x = x * display_zoom;
51
52#ifdef HAVE_LCD_SPLIT
53 for (y = y_start; y < MIN(ymax, LCD_SPLIT_POS); y++) {
54 dest.y = y * display_zoom;
55
56 SDL_FillRect(surface, &dest, (Uint32)(getpixel(x, y) | 0x80));
57 }
58 for (y = MAX(y_start, LCD_SPLIT_POS); y < ymax; y++) {
59 dest.y = (y + LCD_SPLIT_LINES) * display_zoom ;
60
61 SDL_FillRect(surface, &dest, (Uint32)getpixel(x, y));
62 }
63#else
64 for (y = y_start; y < ymax; y++) {
65 dest.y = y * display_zoom;
66
67 SDL_FillRect(surface, &dest, (Uint32)getpixel(x, y));
68 }
69#endif
70 }
71
72 SDL_UnlockSurface(surface);
73}
74
75void sdl_gui_update(SDL_Surface *surface, int x_start, int y_start, int width,
76 int height, int max_x, int max_y, int ui_x, int ui_y)
77{
78 if (x_start + width > max_x)
79 width = max_x - x_start;
80 if (y_start + height > max_y)
81 height = max_y - y_start;
82
83 SDL_Rect src = {x_start * display_zoom, y_start * display_zoom,
84 width * display_zoom, height * display_zoom};
85 SDL_Rect dest= {(ui_x + x_start) * display_zoom,
86 (ui_y + y_start) * display_zoom,
87 width * display_zoom, height * display_zoom};
88
89 if (surface->flags & SDL_SRCALPHA) /* alpha needs a black background */
90 SDL_FillRect(gui_surface, &dest, 0);
91
92 SDL_BlitSurface(surface, &src, gui_surface, &dest);
93
94 SDL_Flip(gui_surface);
95}
96
97/* set a range of bitmap indices to a gradient from startcolour to endcolour */
98void sdl_set_gradient(SDL_Surface *surface, SDL_Color *start, SDL_Color *end,
99 int first, int steps)
100{
101 int i;
102 SDL_Color palette[steps];
103
104 for (i = 0; i < steps; i++) {
105 palette[i].r = start->r + (end->r - start->r) * i / (steps - 1);
106 palette[i].g = start->g + (end->g - start->g) * i / (steps - 1);
107 palette[i].b = start->b + (end->b - start->b) * i / (steps - 1);
108 }
109
110 SDL_SetPalette(surface, SDL_LOGPAL|SDL_PHYSPAL, palette, first, steps);
111}
112
diff --git a/uisimulator/sdl/lcd-sdl.h b/uisimulator/sdl/lcd-sdl.h
deleted file mode 100644
index 9ffa5246cf..0000000000
--- a/uisimulator/sdl/lcd-sdl.h
+++ /dev/null
@@ -1,42 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 Dan Everton
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef __LCDSDL_H__
23#define __LCDSDL_H__
24
25#include "lcd.h"
26#include "SDL.h"
27
28/* Default display zoom level */
29extern int display_zoom;
30
31void sdl_update_rect(SDL_Surface *surface, int x_start, int y_start, int width,
32 int height, int max_x, int max_y,
33 unsigned long (*getpixel)(int, int));
34
35void sdl_gui_update(SDL_Surface *surface, int x_start, int y_start, int width,
36 int height, int max_x, int max_y, int ui_x, int ui_y);
37
38void sdl_set_gradient(SDL_Surface *surface, SDL_Color *start, SDL_Color *end,
39 int first, int steps);
40
41#endif /* #ifndef __LCDSDL_H__ */
42
diff --git a/uisimulator/sdl/sound.c b/uisimulator/sdl/sound.c
deleted file mode 100644
index 0f8d5d4934..0000000000
--- a/uisimulator/sdl/sound.c
+++ /dev/null
@@ -1,426 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2005 by Nick Lanham
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "autoconf.h"
23
24#include <stdlib.h>
25#include <stdbool.h>
26#include <memory.h>
27#include "kernel.h"
28#include "sound.h"
29#include "audiohw.h"
30
31#include "pcm.h"
32#include "pcm_sampr.h"
33#include "SDL.h"
34
35/*#define LOGF_ENABLE*/
36#include "logf.h"
37
38static int sim_volume = 0;
39
40#if CONFIG_CODEC == SWCODEC
41static int cvt_status = -1;
42
43static Uint8* pcm_data;
44static size_t pcm_data_size;
45static size_t pcm_sample_bytes;
46static size_t pcm_channel_bytes;
47
48static struct pcm_udata
49{
50 Uint8 *stream;
51 Uint32 num_in;
52 Uint32 num_out;
53 FILE *debug;
54} udata;
55
56static SDL_AudioSpec obtained;
57static SDL_AudioCVT cvt;
58
59extern bool debug_audio;
60
61#ifndef MIN
62#define MIN(a, b) (((a) < (b)) ? (a) : (b))
63#endif
64
65void pcm_play_lock(void)
66{
67 SDL_LockAudio();
68}
69
70void pcm_play_unlock(void)
71{
72 SDL_UnlockAudio();
73}
74
75static void pcm_dma_apply_settings_nolock(void)
76{
77 cvt_status = SDL_BuildAudioCVT(&cvt, AUDIO_S16SYS, 2, pcm_sampr,
78 obtained.format, obtained.channels, obtained.freq);
79
80 if (cvt_status < 0) {
81 cvt.len_ratio = (double)obtained.freq / (double)pcm_sampr;
82 }
83}
84
85void pcm_dma_apply_settings(void)
86{
87 pcm_play_lock();
88 pcm_dma_apply_settings_nolock();
89 pcm_play_unlock();
90}
91
92void pcm_play_dma_start(const void *addr, size_t size)
93{
94 pcm_dma_apply_settings_nolock();
95
96 pcm_data = (Uint8 *) addr;
97 pcm_data_size = size;
98
99 SDL_PauseAudio(0);
100}
101
102void pcm_play_dma_stop(void)
103{
104 SDL_PauseAudio(1);
105 if (udata.debug != NULL) {
106 fclose(udata.debug);
107 udata.debug = NULL;
108 DEBUGF("Audio debug file closed\n");
109 }
110}
111
112void pcm_play_dma_pause(bool pause)
113{
114 if (pause)
115 SDL_PauseAudio(1);
116 else
117 SDL_PauseAudio(0);
118}
119
120size_t pcm_get_bytes_waiting(void)
121{
122 return pcm_data_size;
123}
124
125extern int sim_volume; /* in firmware/sound.c */
126static void write_to_soundcard(struct pcm_udata *udata) {
127 if (debug_audio && (udata->debug == NULL)) {
128 udata->debug = fopen("audiodebug.raw", "ab");
129 DEBUGF("Audio debug file open\n");
130 }
131
132 if (cvt.needed) {
133 Uint32 rd = udata->num_in;
134 Uint32 wr = (double)rd * cvt.len_ratio;
135
136 if (wr > udata->num_out) {
137 wr = udata->num_out;
138 rd = (double)wr / cvt.len_ratio;
139
140 if (rd > udata->num_in)
141 {
142 rd = udata->num_in;
143 wr = (double)rd * cvt.len_ratio;
144 }
145 }
146
147 if (wr == 0 || rd == 0)
148 {
149 udata->num_out = udata->num_in = 0;
150 return;
151 }
152
153 if (cvt_status > 0) {
154 cvt.len = rd * pcm_sample_bytes;
155 cvt.buf = (Uint8 *) malloc(cvt.len * cvt.len_mult);
156
157 memcpy(cvt.buf, pcm_data, cvt.len);
158
159 SDL_ConvertAudio(&cvt);
160 SDL_MixAudio(udata->stream, cvt.buf, cvt.len_cvt, sim_volume);
161
162 udata->num_in = cvt.len / pcm_sample_bytes;
163 udata->num_out = cvt.len_cvt / pcm_sample_bytes;
164
165 if (udata->debug != NULL) {
166 fwrite(cvt.buf, sizeof(Uint8), cvt.len_cvt, udata->debug);
167 }
168
169 free(cvt.buf);
170 }
171 else {
172 /* Convert is bad, so do silence */
173 Uint32 num = wr*obtained.channels;
174 udata->num_in = rd;
175 udata->num_out = wr;
176
177 switch (pcm_channel_bytes)
178 {
179 case 1:
180 {
181 Uint8 *stream = udata->stream;
182 while (num-- > 0)
183 *stream++ = obtained.silence;
184 break;
185 }
186 case 2:
187 {
188 Uint16 *stream = (Uint16 *)udata->stream;
189 while (num-- > 0)
190 *stream++ = obtained.silence;
191 break;
192 }
193 }
194
195 if (udata->debug != NULL) {
196 fwrite(udata->stream, sizeof(Uint8), wr, udata->debug);
197 }
198 }
199 } else {
200 udata->num_in = udata->num_out = MIN(udata->num_in, udata->num_out);
201 SDL_MixAudio(udata->stream, pcm_data,
202 udata->num_out * pcm_sample_bytes, sim_volume);
203
204 if (udata->debug != NULL) {
205 fwrite(pcm_data, sizeof(Uint8), udata->num_out * pcm_sample_bytes,
206 udata->debug);
207 }
208 }
209}
210
211static void sdl_audio_callback(struct pcm_udata *udata, Uint8 *stream, int len)
212{
213 logf("sdl_audio_callback: len %d, pcm %d\n", len, pcm_data_size);
214 udata->stream = stream;
215
216 /* Write what we have in the PCM buffer */
217 if (pcm_data_size > 0)
218 goto start;
219
220 /* Audio card wants more? Get some more then. */
221 while (len > 0) {
222 if ((ssize_t)pcm_data_size <= 0) {
223 pcm_data_size = 0;
224 if (pcm_callback_for_more)
225 pcm_callback_for_more(&pcm_data, &pcm_data_size);
226 }
227
228 if (pcm_data_size > 0) {
229 start:
230 udata->num_in = pcm_data_size / pcm_sample_bytes;
231 udata->num_out = len / pcm_sample_bytes;
232
233 write_to_soundcard(udata);
234
235 udata->num_in *= pcm_sample_bytes;
236 udata->num_out *= pcm_sample_bytes;
237
238 pcm_data += udata->num_in;
239 pcm_data_size -= udata->num_in;
240 udata->stream += udata->num_out;
241 len -= udata->num_out;
242 } else {
243 DEBUGF("sdl_audio_callback: No Data.\n");
244 pcm_play_dma_stop();
245 pcm_play_dma_stopped_callback();
246 break;
247 }
248 }
249}
250
251const void * pcm_play_dma_get_peak_buffer(int *count)
252{
253 uintptr_t addr = (uintptr_t)pcm_data;
254 *count = pcm_data_size / 4;
255 return (void *)((addr + 2) & ~3);
256}
257
258#ifdef HAVE_RECORDING
259void pcm_rec_lock(void)
260{
261}
262
263void pcm_rec_unlock(void)
264{
265}
266
267void pcm_rec_dma_init(void)
268{
269}
270
271void pcm_rec_dma_close(void)
272{
273}
274
275void pcm_rec_dma_start(void *start, size_t size)
276{
277 (void)start;
278 (void)size;
279}
280
281void pcm_rec_dma_stop(void)
282{
283}
284
285void pcm_rec_dma_record_more(void *start, size_t size)
286{
287 (void)start;
288 (void)size;
289}
290
291unsigned long pcm_rec_status(void)
292{
293 return 0;
294}
295
296const void * pcm_rec_dma_get_peak_buffer(void)
297{
298 return NULL;
299}
300
301#endif /* HAVE_RECORDING */
302
303void pcm_play_dma_init(void)
304{
305 SDL_AudioSpec wanted_spec;
306 udata.debug = NULL;
307
308 if (debug_audio) {
309 udata.debug = fopen("audiodebug.raw", "wb");
310 DEBUGF("Audio debug file open\n");
311 }
312
313 /* Set 16-bit stereo audio at 44Khz */
314 wanted_spec.freq = 44100;
315 wanted_spec.format = AUDIO_S16SYS;
316 wanted_spec.channels = 2;
317 wanted_spec.samples = 2048;
318 wanted_spec.callback =
319 (void (SDLCALL *)(void *userdata,
320 Uint8 *stream, int len))sdl_audio_callback;
321 wanted_spec.userdata = &udata;
322
323 /* Open the audio device and start playing sound! */
324 if(SDL_OpenAudio(&wanted_spec, &obtained) < 0) {
325 fprintf(stderr, "Unable to open audio: %s\n", SDL_GetError());
326 return;
327 }
328
329 switch (obtained.format)
330 {
331 case AUDIO_U8:
332 case AUDIO_S8:
333 pcm_channel_bytes = 1;
334 break;
335 case AUDIO_U16LSB:
336 case AUDIO_S16LSB:
337 case AUDIO_U16MSB:
338 case AUDIO_S16MSB:
339 pcm_channel_bytes = 2;
340 break;
341 default:
342 fprintf(stderr, "Unknown sample format obtained: %u\n",
343 (unsigned)obtained.format);
344 return;
345 }
346
347 pcm_sample_bytes = obtained.channels * pcm_channel_bytes;
348
349 pcm_dma_apply_settings_nolock();
350}
351
352void pcm_postinit(void)
353{
354}
355
356#endif /* CONFIG_CODEC == SWCODEC */
357
358/**
359 * Audio Hardware api. Make them do nothing as we cannot properly simulate with
360 * SDL. if we used DSP we would run code that doesn't actually run on the target
361 **/
362void audiohw_set_volume(int volume)
363{
364 sim_volume = SDL_MIX_MAXVOLUME * ((volume - VOLUME_MIN) / 10) / (VOLUME_RANGE / 10);
365}
366#if defined(AUDIOHW_HAVE_PRESCALER)
367void audiohw_set_prescaler(int value) { (void)value; }
368#endif
369#if defined(AUDIOHW_HAVE_BALANCE)
370void audiohw_set_balance(int value) { (void)value; }
371#endif
372#if defined(AUDIOHW_HAVE_BASS)
373void audiohw_set_bass(int value) { (void)value; }
374#endif
375#if defined(AUDIOHW_HAVE_TREBLE)
376void audiohw_set_treble(int value) { (void)value; }
377#endif
378#if CONFIG_CODEC != SWCODEC
379void audiohw_set_channel(int value) { (void)value; }
380void audiohw_set_stereo_width(int value){ (void)value; }
381#endif
382#if defined(AUDIOHW_HAVE_BASS_CUTOFF)
383void audiohw_set_bass_cutoff(int value) { (void)value; }
384#endif
385#if defined(AUDIOHW_HAVE_TREBLE_CUTOFF)
386void audiohw_set_treble_cutoff(int value){ (void)value; }
387#endif
388/* EQ-based tone controls */
389#if defined(AUDIOHW_HAVE_EQ)
390void audiohw_set_eq_band_gain(unsigned int band, int value)
391 { (void)band; (void)value; }
392#endif
393#if defined(AUDIOHW_HAVE_EQ_FREQUENCY)
394void audiohw_set_eq_band_frequency(unsigned int band, int value)
395 { (void)band; (void)value; }
396#endif
397#if defined(AUDIOHW_HAVE_EQ_WIDTH)
398void audiohw_set_eq_band_width(unsigned int band, int value)
399 { (void)band; (void)value; }
400#endif
401#if defined(AUDIOHW_HAVE_DEPTH_3D)
402void audiohw_set_depth_3d(int value)
403 { (void)value; }
404#endif
405#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
406int mas_codec_readreg(int reg)
407{
408 (void)reg;
409 return 0;
410}
411
412int mas_codec_writereg(int reg, unsigned int val)
413{
414 (void)reg;
415 (void)val;
416 return 0;
417}
418int mas_writemem(int bank, int addr, const unsigned long* src, int len)
419{
420 (void)bank;
421 (void)addr;
422 (void)src;
423 (void)len;
424 return 0;
425}
426#endif
diff --git a/uisimulator/sdl/sound.h b/uisimulator/sdl/sound.h
deleted file mode 100644
index 5f4cc6eaf0..0000000000
--- a/uisimulator/sdl/sound.h
+++ /dev/null
@@ -1,24 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2005 by Daniel Stenberg <daniel@haxx.se>
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22int sound_playback_thread(void* p);
23
24extern void (*sound_get_pcm)(unsigned char** start, long* size);
diff --git a/uisimulator/sdl/system-sdl.h b/uisimulator/sdl/system-sdl.h
deleted file mode 100644
index 04e033e330..0000000000
--- a/uisimulator/sdl/system-sdl.h
+++ /dev/null
@@ -1,49 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2007 by Michael Sevakis
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#ifndef _SYSTEM_SDL_H_
22#define _SYSTEM_SDL_H_
23
24#include <stdbool.h>
25
26#define HIGHEST_IRQ_LEVEL 1
27
28int set_irq_level(int level);
29
30#define disable_irq() \
31 ((void)set_irq_level(HIGHEST_IRQ_LEVEL))
32
33#define enable_irq() \
34 ((void)set_irq_level(0))
35
36#define disable_irq_save() \
37 set_irq_level(HIGHEST_IRQ_LEVEL)
38
39#define restore_irq(level) \
40 ((void)set_irq_level(level))
41
42void sim_enter_irq_handler(void);
43void sim_exit_irq_handler(void);
44bool sim_kernel_init(void);
45void sim_kernel_shutdown(void);
46
47extern long start_tick;
48
49#endif /* _SYSTEM_SDL_H_ */
diff --git a/uisimulator/sdl/thread-sdl.c b/uisimulator/sdl/thread-sdl.c
deleted file mode 100644
index e9b5fc205d..0000000000
--- a/uisimulator/sdl/thread-sdl.c
+++ /dev/null
@@ -1,649 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 Dan Everton
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include <stdbool.h>
23#include <time.h>
24#include <SDL.h>
25#include <SDL_thread.h>
26#include <stdlib.h>
27#include <memory.h>
28#include <setjmp.h>
29#include "system-sdl.h"
30#include "thread-sdl.h"
31#include "system.h"
32#include "kernel.h"
33#include "thread.h"
34#include "debug.h"
35
36/* Define this as 1 to show informational messages that are not errors. */
37#define THREAD_SDL_DEBUGF_ENABLED 0
38
39#if THREAD_SDL_DEBUGF_ENABLED
40#define THREAD_SDL_DEBUGF(...) DEBUGF(__VA_ARGS__)
41static char __name[32];
42#define THREAD_SDL_GET_NAME(thread) \
43 ({ thread_get_name(__name, ARRAYLEN(__name), thread); __name; })
44#else
45#define THREAD_SDL_DEBUGF(...)
46#define THREAD_SDL_GET_NAME(thread)
47#endif
48
49#define THREAD_PANICF(str...) \
50 ({ fprintf(stderr, str); exit(-1); })
51
52/* Thread/core entries as in rockbox core */
53static struct core_entry cores[NUM_CORES];
54struct thread_entry threads[MAXTHREADS];
55/* Jump buffers for graceful exit - kernel threads don't stay neatly
56 * in their start routines responding to messages so this is the only
57 * way to get them back in there so they may exit */
58static jmp_buf thread_jmpbufs[MAXTHREADS];
59static SDL_mutex *m;
60static volatile bool threads_exit = false;
61
62extern long start_tick;
63
64void thread_sdl_shutdown(void)
65{
66 int i;
67
68 /* Tell all threads jump back to their start routines, unlock and exit
69 gracefully - we'll check each one in turn for it's status. Threads
70 _could_ terminate via remove_thread or multiple threads could exit
71 on each unlock but that is safe. */
72
73 /* Do this before trying to acquire lock */
74 threads_exit = true;
75
76 /* Take control */
77 SDL_LockMutex(m);
78
79 for (i = 0; i < MAXTHREADS; i++)
80 {
81 struct thread_entry *thread = &threads[i];
82 if (thread->context.t != NULL)
83 {
84 /* Signal thread on delay or block */
85 SDL_Thread *t = thread->context.t;
86 SDL_SemPost(thread->context.s);
87 SDL_UnlockMutex(m);
88 /* Wait for it to finish */
89 SDL_WaitThread(t, NULL);
90 /* Relock for next thread signal */
91 SDL_LockMutex(m);
92 }
93 }
94
95 SDL_UnlockMutex(m);
96 SDL_DestroyMutex(m);
97}
98
99static void new_thread_id(unsigned int slot_num,
100 struct thread_entry *thread)
101{
102 unsigned int version =
103 (thread->id + (1u << THREAD_ID_VERSION_SHIFT))
104 & THREAD_ID_VERSION_MASK;
105
106 if (version == 0)
107 version = 1u << THREAD_ID_VERSION_SHIFT;
108
109 thread->id = version | (slot_num & THREAD_ID_SLOT_MASK);
110}
111
112static struct thread_entry * find_empty_thread_slot(void)
113{
114 struct thread_entry *thread = NULL;
115 int n;
116
117 for (n = 0; n < MAXTHREADS; n++)
118 {
119 int state = threads[n].state;
120
121 if (state == STATE_KILLED)
122 {
123 thread = &threads[n];
124 break;
125 }
126 }
127
128 return thread;
129}
130
131/* Do main thread creation in this file scope to avoid the need to double-
132 return to a prior call-level which would be unaware of the fact setjmp
133 was used */
134extern void app_main(void *param);
135static int thread_sdl_app_main(void *param)
136{
137 SDL_LockMutex(m);
138 cores[CURRENT_CORE].running = &threads[0];
139
140 /* Set the jump address for return */
141 if (setjmp(thread_jmpbufs[0]) == 0)
142 {
143 app_main(param);
144 /* should not ever be reached but... */
145 THREAD_PANICF("app_main returned!\n");
146 }
147
148 /* Unlock and exit */
149 SDL_UnlockMutex(m);
150 return 0;
151}
152
153/* Initialize SDL threading */
154bool thread_sdl_init(void *param)
155{
156 struct thread_entry *thread;
157 int n;
158
159 memset(cores, 0, sizeof(cores));
160 memset(threads, 0, sizeof(threads));
161
162 m = SDL_CreateMutex();
163
164 if (SDL_LockMutex(m) == -1)
165 {
166 fprintf(stderr, "Couldn't lock mutex\n");
167 return false;
168 }
169
170 /* Initialize all IDs */
171 for (n = 0; n < MAXTHREADS; n++)
172 threads[n].id = THREAD_ID_INIT(n);
173
174 /* Slot 0 is reserved for the main thread - initialize it here and
175 then create the SDL thread - it is possible to have a quick, early
176 shutdown try to access the structure. */
177 thread = &threads[0];
178 thread->stack = (uintptr_t *)" ";
179 thread->stack_size = 8;
180 thread->name = "main";
181 thread->state = STATE_RUNNING;
182 thread->context.s = SDL_CreateSemaphore(0);
183 cores[CURRENT_CORE].running = thread;
184
185 if (thread->context.s == NULL)
186 {
187 fprintf(stderr, "Failed to create main semaphore\n");
188 return false;
189 }
190
191 thread->context.t = SDL_CreateThread(thread_sdl_app_main, param);
192
193 if (thread->context.t == NULL)
194 {
195 SDL_DestroySemaphore(thread->context.s);
196 fprintf(stderr, "Failed to create main thread\n");
197 return false;
198 }
199
200 THREAD_SDL_DEBUGF("Main thread: %p\n", thread);
201
202 SDL_UnlockMutex(m);
203 return true;
204}
205
206void thread_sdl_exception_wait(void)
207{
208 while (1)
209 {
210 SDL_Delay(HZ/10);
211 if (threads_exit)
212 thread_exit();
213 }
214}
215
216/* A way to yield and leave the threading system for extended periods */
217void thread_sdl_thread_lock(void *me)
218{
219 SDL_LockMutex(m);
220 cores[CURRENT_CORE].running = (struct thread_entry *)me;
221
222 if (threads_exit)
223 thread_exit();
224}
225
226void * thread_sdl_thread_unlock(void)
227{
228 struct thread_entry *current = cores[CURRENT_CORE].running;
229 SDL_UnlockMutex(m);
230 return current;
231}
232
233struct thread_entry * thread_id_entry(unsigned int thread_id)
234{
235 return (thread_id == THREAD_ID_CURRENT) ?
236 cores[CURRENT_CORE].running :
237 &threads[thread_id & THREAD_ID_SLOT_MASK];
238}
239
240static void add_to_list_l(struct thread_entry **list,
241 struct thread_entry *thread)
242{
243 if (*list == NULL)
244 {
245 /* Insert into unoccupied list */
246 thread->l.next = thread;
247 thread->l.prev = thread;
248 *list = thread;
249 }
250 else
251 {
252 /* Insert last */
253 thread->l.next = *list;
254 thread->l.prev = (*list)->l.prev;
255 thread->l.prev->l.next = thread;
256 (*list)->l.prev = thread;
257 }
258}
259
260static void remove_from_list_l(struct thread_entry **list,
261 struct thread_entry *thread)
262{
263 if (thread == thread->l.next)
264 {
265 /* The only item */
266 *list = NULL;
267 return;
268 }
269
270 if (thread == *list)
271 {
272 /* List becomes next item */
273 *list = thread->l.next;
274 }
275
276 /* Fix links to jump over the removed entry. */
277 thread->l.prev->l.next = thread->l.next;
278 thread->l.next->l.prev = thread->l.prev;
279}
280
281unsigned int thread_get_current(void)
282{
283 return cores[CURRENT_CORE].running->id;
284}
285
286void switch_thread(void)
287{
288 struct thread_entry *current = cores[CURRENT_CORE].running;
289
290 enable_irq();
291
292 switch (current->state)
293 {
294 case STATE_RUNNING:
295 {
296 SDL_UnlockMutex(m);
297 /* Any other thread waiting already will get it first */
298 SDL_LockMutex(m);
299 break;
300 } /* STATE_RUNNING: */
301
302 case STATE_BLOCKED:
303 {
304 int oldlevel;
305
306 SDL_UnlockMutex(m);
307 SDL_SemWait(current->context.s);
308 SDL_LockMutex(m);
309
310 oldlevel = disable_irq_save();
311 current->state = STATE_RUNNING;
312 restore_irq(oldlevel);
313 break;
314 } /* STATE_BLOCKED: */
315
316 case STATE_BLOCKED_W_TMO:
317 {
318 int result, oldlevel;
319
320 SDL_UnlockMutex(m);
321 result = SDL_SemWaitTimeout(current->context.s, current->tmo_tick);
322 SDL_LockMutex(m);
323
324 oldlevel = disable_irq_save();
325
326 if (current->state == STATE_BLOCKED_W_TMO)
327 {
328 /* Timed out */
329 remove_from_list_l(current->bqp, current);
330
331#ifdef HAVE_WAKEUP_EXT_CB
332 if (current->wakeup_ext_cb != NULL)
333 current->wakeup_ext_cb(current);
334#endif
335 current->state = STATE_RUNNING;
336 }
337
338 if (result == SDL_MUTEX_TIMEDOUT)
339 {
340 /* Other signals from an explicit wake could have been made before
341 * arriving here if we timed out waiting for the semaphore. Make
342 * sure the count is reset. */
343 while (SDL_SemValue(current->context.s) > 0)
344 SDL_SemTryWait(current->context.s);
345 }
346
347 restore_irq(oldlevel);
348 break;
349 } /* STATE_BLOCKED_W_TMO: */
350
351 case STATE_SLEEPING:
352 {
353 SDL_UnlockMutex(m);
354 SDL_SemWaitTimeout(current->context.s, current->tmo_tick);
355 SDL_LockMutex(m);
356 current->state = STATE_RUNNING;
357 break;
358 } /* STATE_SLEEPING: */
359 }
360
361 cores[CURRENT_CORE].running = current;
362
363 if (threads_exit)
364 thread_exit();
365}
366
367void sleep_thread(int ticks)
368{
369 struct thread_entry *current = cores[CURRENT_CORE].running;
370 int rem;
371
372 current->state = STATE_SLEEPING;
373
374 rem = (SDL_GetTicks() - start_tick) % (1000/HZ);
375 if (rem < 0)
376 rem = 0;
377
378 current->tmo_tick = (1000/HZ) * ticks + ((1000/HZ)-1) - rem;
379}
380
381void block_thread(struct thread_entry *current)
382{
383 current->state = STATE_BLOCKED;
384 add_to_list_l(current->bqp, current);
385}
386
387void block_thread_w_tmo(struct thread_entry *current, int ticks)
388{
389 current->state = STATE_BLOCKED_W_TMO;
390 current->tmo_tick = (1000/HZ)*ticks;
391 add_to_list_l(current->bqp, current);
392}
393
394unsigned int wakeup_thread(struct thread_entry **list)
395{
396 struct thread_entry *thread = *list;
397
398 if (thread != NULL)
399 {
400 switch (thread->state)
401 {
402 case STATE_BLOCKED:
403 case STATE_BLOCKED_W_TMO:
404 remove_from_list_l(list, thread);
405 thread->state = STATE_RUNNING;
406 SDL_SemPost(thread->context.s);
407 return THREAD_OK;
408 }
409 }
410
411 return THREAD_NONE;
412}
413
414unsigned int thread_queue_wake(struct thread_entry **list)
415{
416 unsigned int result = THREAD_NONE;
417
418 for (;;)
419 {
420 unsigned int rc = wakeup_thread(list);
421
422 if (rc == THREAD_NONE)
423 break;
424
425 result |= rc;
426 }
427
428 return result;
429}
430
431void thread_thaw(unsigned int thread_id)
432{
433 struct thread_entry *thread = thread_id_entry(thread_id);
434
435 if (thread->id == thread_id && thread->state == STATE_FROZEN)
436 {
437 thread->state = STATE_RUNNING;
438 SDL_SemPost(thread->context.s);
439 }
440}
441
442int runthread(void *data)
443{
444 struct thread_entry *current;
445 jmp_buf *current_jmpbuf;
446
447 /* Cannot access thread variables before locking the mutex as the
448 data structures may not be filled-in yet. */
449 SDL_LockMutex(m);
450 cores[CURRENT_CORE].running = (struct thread_entry *)data;
451 current = cores[CURRENT_CORE].running;
452 current_jmpbuf = &thread_jmpbufs[current - threads];
453
454 /* Setup jump for exit */
455 if (setjmp(*current_jmpbuf) == 0)
456 {
457 /* Run the thread routine */
458 if (current->state == STATE_FROZEN)
459 {
460 SDL_UnlockMutex(m);
461 SDL_SemWait(current->context.s);
462 SDL_LockMutex(m);
463 cores[CURRENT_CORE].running = current;
464 }
465
466 if (!threads_exit)
467 {
468 current->context.start();
469 THREAD_SDL_DEBUGF("Thread Done: %d (%s)\n",
470 current - threads, THREAD_SDL_GET_NAME(current));
471 /* Thread routine returned - suicide */
472 }
473
474 thread_exit();
475 }
476 else
477 {
478 /* Unlock and exit */
479 SDL_UnlockMutex(m);
480 }
481
482 return 0;
483}
484
485unsigned int create_thread(void (*function)(void),
486 void* stack, size_t stack_size,
487 unsigned flags, const char *name)
488{
489 struct thread_entry *thread;
490 SDL_Thread* t;
491 SDL_sem *s;
492
493 THREAD_SDL_DEBUGF("Creating thread: (%s)\n", name ? name : "");
494
495 thread = find_empty_thread_slot();
496 if (thread == NULL)
497 {
498 DEBUGF("Failed to find thread slot\n");
499 return 0;
500 }
501
502 s = SDL_CreateSemaphore(0);
503 if (s == NULL)
504 {
505 DEBUGF("Failed to create semaphore\n");
506 return 0;
507 }
508
509 t = SDL_CreateThread(runthread, thread);
510 if (t == NULL)
511 {
512 DEBUGF("Failed to create SDL thread\n");
513 SDL_DestroySemaphore(s);
514 return 0;
515 }
516
517 thread->stack = stack;
518 thread->stack_size = stack_size;
519 thread->name = name;
520 thread->state = (flags & CREATE_THREAD_FROZEN) ?
521 STATE_FROZEN : STATE_RUNNING;
522 thread->context.start = function;
523 thread->context.t = t;
524 thread->context.s = s;
525
526 THREAD_SDL_DEBUGF("New Thread: %d (%s)\n",
527 thread - threads, THREAD_SDL_GET_NAME(thread));
528
529 return thread->id;
530}
531
532void init_threads(void)
533{
534 /* Main thread is already initialized */
535 if (cores[CURRENT_CORE].running != &threads[0])
536 {
537 THREAD_PANICF("Wrong main thread in init_threads: %p\n",
538 cores[CURRENT_CORE].running);
539 }
540
541 THREAD_SDL_DEBUGF("First Thread: %d (%s)\n",
542 0, THREAD_SDL_GET_NAME(&threads[0]));
543}
544
545#ifndef ALLOW_REMOVE_THREAD
546static void remove_thread(unsigned int thread_id)
547#else
548void remove_thread(unsigned int thread_id)
549#endif
550{
551 struct thread_entry *current = cores[CURRENT_CORE].running;
552 struct thread_entry *thread = thread_id_entry(thread_id);
553
554 SDL_Thread *t;
555 SDL_sem *s;
556
557 if (thread_id != THREAD_ID_CURRENT && thread->id != thread_id)
558 return;
559
560 int oldlevel = disable_irq_save();
561
562 t = thread->context.t;
563 s = thread->context.s;
564 thread->context.t = NULL;
565
566 if (thread != current)
567 {
568 switch (thread->state)
569 {
570 case STATE_BLOCKED:
571 case STATE_BLOCKED_W_TMO:
572 /* Remove thread from object it's waiting on */
573 remove_from_list_l(thread->bqp, thread);
574
575#ifdef HAVE_WAKEUP_EXT_CB
576 if (thread->wakeup_ext_cb != NULL)
577 thread->wakeup_ext_cb(thread);
578#endif
579 break;
580 }
581
582 SDL_SemPost(s);
583 }
584
585 THREAD_SDL_DEBUGF("Removing thread: %d (%s)\n",
586 thread - threads, THREAD_SDL_GET_NAME(thread));
587
588 new_thread_id(thread->id, thread);
589 thread->state = STATE_KILLED;
590 thread_queue_wake(&thread->queue);
591
592 SDL_DestroySemaphore(s);
593
594 if (thread == current)
595 {
596 /* Do a graceful exit - perform the longjmp back into the thread
597 function to return */
598 restore_irq(oldlevel);
599 longjmp(thread_jmpbufs[current - threads], 1);
600 }
601
602 SDL_KillThread(t);
603 restore_irq(oldlevel);
604}
605
606void thread_exit(void)
607{
608 remove_thread(THREAD_ID_CURRENT);
609}
610
611void thread_wait(unsigned int thread_id)
612{
613 struct thread_entry *current = cores[CURRENT_CORE].running;
614 struct thread_entry *thread = thread_id_entry(thread_id);
615
616 if (thread_id == THREAD_ID_CURRENT ||
617 (thread->id == thread_id && thread->state != STATE_KILLED))
618 {
619 current->bqp = &thread->queue;
620 block_thread(current);
621 switch_thread();
622 }
623}
624
625int thread_stack_usage(const struct thread_entry *thread)
626{
627 return 50;
628 (void)thread;
629}
630
631/* Return name if one or ID if none */
632void thread_get_name(char *buffer, int size,
633 struct thread_entry *thread)
634{
635 if (size <= 0)
636 return;
637
638 *buffer = '\0';
639
640 if (thread)
641 {
642 /* Display thread name if one or ID if none */
643 bool named = thread->name && *thread->name;
644 const char *fmt = named ? "%s" : "%08lX";
645 intptr_t name = named ?
646 (intptr_t)thread->name : (intptr_t)thread;
647 snprintf(buffer, size, fmt, name);
648 }
649}
diff --git a/uisimulator/sdl/thread-sdl.h b/uisimulator/sdl/thread-sdl.h
deleted file mode 100644
index f221aa5a72..0000000000
--- a/uisimulator/sdl/thread-sdl.h
+++ /dev/null
@@ -1,37 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 Dan Everton
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef __THREADSDL_H__
23#define __THREADSDL_H__
24
25#include "SDL_thread.h"
26
27extern SDL_Thread *gui_thread; /* The "main" thread */
28void thread_sdl_thread_lock(void *me);
29void * thread_sdl_thread_unlock(void);
30void thread_sdl_exception_wait(void);
31bool thread_sdl_init(void *param); /* Init the sim threading API - thread created calls app_main */
32void thread_sdl_shutdown(void); /* Shut down all kernel threads gracefully */
33void thread_sdl_lock(void); /* Sync with SDL threads */
34void thread_sdl_unlock(void); /* Sync with SDL threads */
35
36#endif /* #ifndef __THREADSDL_H__ */
37
diff --git a/uisimulator/sdl/timefuncs.h b/uisimulator/sdl/timefuncs.h
deleted file mode 100644
index de17fcdc73..0000000000
--- a/uisimulator/sdl/timefuncs.h
+++ /dev/null
@@ -1,7 +0,0 @@
1#include <time.h>
2#include <stdbool.h>
3
4/* struct tm defined */
5struct tm *get_time(void);
6int set_time(const struct tm *tm);
7bool valid_time(const struct tm *tm);
diff --git a/uisimulator/sdl/timer.c b/uisimulator/sdl/timer.c
deleted file mode 100644
index 369aeab929..0000000000
--- a/uisimulator/sdl/timer.c
+++ /dev/null
@@ -1,61 +0,0 @@
1/***************************************************************************
2* __________ __ ___.
3* Open \______ \ ____ ____ | | _\_ |__ _______ ___
4* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7* \/ \/ \/ \/ \/
8* $Id: timer.h 13806 2007-07-06 21:36:32Z jethead71 $
9*
10* Copyright (C) 2005 Kévin Ferrare
11*
12* This program is free software; you can redistribute it and/or
13* modify it under the terms of the GNU General Public License
14* as published by the Free Software Foundation; either version 2
15* of the License, or (at your option) any later version.
16*
17* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18* KIND, either express or implied.
19*
20****************************************************************************/
21
22#include "timer.h"
23#include <SDL_timer.h>
24
25static int timer_prio = -1;
26void (*global_timer_callback)(void);
27SDL_TimerID timerId;
28
29Uint32 SDL_timer_callback(Uint32 interval, void *param){
30 (void)param;
31 global_timer_callback();
32 return(interval);
33}
34
35#define cycles_to_miliseconds(cycles) \
36 ((int)((1000*cycles)/TIMER_FREQ))
37
38bool timer_register(int reg_prio, void (*unregister_callback)(void),
39 long cycles, void (*timer_callback)(void))
40{
41 (void)unregister_callback;
42 if (reg_prio <= timer_prio || cycles == 0)
43 return false;
44 timer_prio=reg_prio;
45 global_timer_callback=timer_callback;
46 timerId=SDL_AddTimer(cycles_to_miliseconds(cycles), SDL_timer_callback, 0);
47 return true;
48}
49
50bool timer_set_period(long cycles)
51{
52 SDL_RemoveTimer (timerId);
53 timerId=SDL_AddTimer(cycles_to_miliseconds(cycles), SDL_timer_callback, 0);
54 return true;
55}
56
57void timer_unregister(void)
58{
59 SDL_RemoveTimer (timerId);
60 timer_prio = -1;
61}
diff --git a/uisimulator/sdl/uisdl.c b/uisimulator/sdl/uisdl.c
deleted file mode 100644
index 8cf4b42ba0..0000000000
--- a/uisimulator/sdl/uisdl.c
+++ /dev/null
@@ -1,368 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 by Daniel Everton <dan@iocaine.org>
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include <stdlib.h>
23#include <string.h>
24#include <setjmp.h>
25#include "autoconf.h"
26#include "button.h"
27#include "system-sdl.h"
28#include "thread.h"
29#include "kernel.h"
30#include "uisdl.h"
31#include "lcd-sdl.h"
32#ifdef HAVE_LCD_BITMAP
33#include "lcd-bitmap.h"
34#elif defined(HAVE_LCD_CHARCELLS)
35#include "lcd-charcells.h"
36#endif
37#ifdef HAVE_REMOTE_LCD
38#include "lcd-remote-bitmap.h"
39#endif
40#include "thread-sdl.h"
41#include "SDL_mutex.h"
42#include "SDL_thread.h"
43#include "math.h"
44
45
46/* extern functions */
47extern void new_key(int key);
48extern int xy2button( int x, int y);
49void button_event(int key, bool pressed);
50
51SDL_Surface *gui_surface;
52bool background = true; /* use backgrounds by default */
53#ifdef HAVE_REMOTE_LCD
54static bool showremote = true; /* include remote by default */
55#endif
56bool mapping = false;
57bool debug_buttons = false;
58
59bool lcd_display_redraw = true; /* Used for player simulator */
60char having_new_lcd = true; /* Used for player simulator */
61bool sim_alarm_wakeup = false;
62const char *sim_root_dir = NULL;
63
64bool debug_audio = false;
65
66bool debug_wps = false;
67int wps_verbose_level = 3;
68
69
70void irq_button_event(int key, bool pressed) {
71 sim_enter_irq_handler();
72 button_event( key, pressed );
73 sim_exit_irq_handler();
74}
75
76int sqr( int a ) {
77 return a*a;
78}
79
80void gui_message_loop(void)
81{
82 SDL_Event event;
83 bool done = false;
84 static int x,y,xybutton = 0;
85
86 while(!done && SDL_WaitEvent(&event))
87 {
88 switch(event.type)
89 {
90 case SDL_KEYDOWN:
91 irq_button_event(event.key.keysym.sym, true);
92 break;
93 case SDL_KEYUP:
94 irq_button_event(event.key.keysym.sym, false);
95 case SDL_MOUSEBUTTONDOWN:
96 switch ( event.button.button ) {
97#ifdef HAVE_SCROLLWHEEL
98 case SDL_BUTTON_WHEELUP:
99 irq_button_event( SDLK_UP, true );
100 break;
101 case SDL_BUTTON_WHEELDOWN:
102 irq_button_event( SDLK_DOWN, true );
103 break;
104#endif
105 case SDL_BUTTON_LEFT:
106 case SDL_BUTTON_MIDDLE:
107 if ( mapping && background ) {
108 x = event.button.x;
109 y = event.button.y;
110 }
111 if ( background ) {
112 xybutton = xy2button( event.button.x, event.button.y );
113 if( xybutton )
114 irq_button_event( xybutton, true );
115 }
116 break;
117 default:
118 break;
119 }
120
121 if (debug_wps && event.button.button == 1)
122 {
123 if ( background )
124#ifdef HAVE_REMOTE
125 if ( event.button.y < UI_REMOTE_POSY ) /* Main Screen */
126 printf("Mouse at: (%d, %d)\n", event.button.x - UI_LCD_POSX -1 , event.button.y - UI_LCD_POSY - 1 );
127 else
128 printf("Mouse at: (%d, %d)\n", event.button.x - UI_REMOTE_POSX -1 , event.button.y - UI_REMOTE_POSY - 1 );
129#else
130 printf("Mouse at: (%d, %d)\n", event.button.x - UI_LCD_POSX -1 , event.button.y - UI_LCD_POSY - 1 );
131#endif
132 else
133 if ( event.button.y/display_zoom < LCD_HEIGHT ) /* Main Screen */
134 printf("Mouse at: (%d, %d)\n", event.button.x/display_zoom, event.button.y/display_zoom );
135#ifdef HAVE_REMOTE
136 else
137 printf("Mouse at: (%d, %d)\n", event.button.x/display_zoom, event.button.y/display_zoom - LCD_HEIGHT );
138#endif
139 }
140 break;
141 case SDL_MOUSEBUTTONUP:
142 switch ( event.button.button ) {
143 /* The scrollwheel button up events are ignored as they are queued immediately */
144 case SDL_BUTTON_LEFT:
145 case SDL_BUTTON_MIDDLE:
146 if ( mapping && background ) {
147 printf(" { SDLK_, %d, %d, %d, \"\" },\n", x, y, (int)sqrt( sqr(x-(int)event.button.x) + sqr(y-(int)event.button.y)) );
148 }
149 if ( background && xybutton ) {
150 irq_button_event( xybutton, false );
151 xybutton = 0;
152 }
153#ifdef HAVE_TOUCHSCREEN
154 else {
155 irq_button_event(BUTTON_TOUCHSCREEN, false);
156 }
157#endif
158 break;
159 default:
160 break;
161 }
162 break;
163
164
165 case SDL_QUIT:
166 done = true;
167 break;
168 default:
169 /*printf("Unhandled event\n"); */
170 break;
171 }
172 }
173}
174
175bool gui_startup(void)
176{
177 SDL_Surface *picture_surface;
178 int width, height;
179
180 if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_TIMER)) {
181 fprintf(stderr, "fatal: %s\n", SDL_GetError());
182 return false;
183 }
184
185 atexit(SDL_Quit);
186
187 /* Try and load the background image. If it fails go without */
188 if (background) {
189 picture_surface = SDL_LoadBMP("UI256.bmp");
190 if (picture_surface == NULL) {
191 background = false;
192 fprintf(stderr, "warn: %s\n", SDL_GetError());
193 }
194 }
195
196 /* Set things up */
197 if (background)
198 {
199 width = UI_WIDTH;
200 height = UI_HEIGHT;
201 }
202 else
203 {
204#ifdef HAVE_REMOTE_LCD
205 if (showremote)
206 {
207 width = SIM_LCD_WIDTH > SIM_REMOTE_WIDTH ? SIM_LCD_WIDTH : SIM_REMOTE_WIDTH;
208 height = SIM_LCD_HEIGHT + SIM_REMOTE_HEIGHT;
209 }
210 else
211#endif
212 {
213 width = SIM_LCD_WIDTH;
214 height = SIM_LCD_HEIGHT;
215 }
216 }
217
218
219 if ((gui_surface = SDL_SetVideoMode(width * display_zoom, height * display_zoom, 24, SDL_HWSURFACE|SDL_DOUBLEBUF)) == NULL) {
220 fprintf(stderr, "fatal: %s\n", SDL_GetError());
221 return false;
222 }
223
224 SDL_WM_SetCaption(UI_TITLE, NULL);
225
226 sim_lcd_init();
227#ifdef HAVE_REMOTE_LCD
228 if (showremote)
229 sim_lcd_remote_init();
230#endif
231
232 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
233
234 if (background && picture_surface != NULL) {
235 SDL_BlitSurface(picture_surface, NULL, gui_surface, NULL);
236 SDL_UpdateRect(gui_surface, 0, 0, 0, 0);
237 }
238
239 return true;
240}
241
242bool gui_shutdown(void)
243{
244 /* Order here is relevent to prevent deadlocks and use of destroyed
245 sync primitives by kernel threads */
246 thread_sdl_shutdown();
247 sim_kernel_shutdown();
248 return true;
249}
250
251#if defined(WIN32) && defined(main)
252/* Don't use SDL_main on windows -> no more stdio redirection */
253#undef main
254#endif
255
256int main(int argc, char *argv[])
257{
258 if (argc >= 1)
259 {
260 int x;
261 for (x = 1; x < argc; x++)
262 {
263 if (!strcmp("--debugaudio", argv[x]))
264 {
265 debug_audio = true;
266 printf("Writing debug audio file.\n");
267 }
268 else if (!strcmp("--debugwps", argv[x]))
269 {
270 debug_wps = true;
271 printf("WPS debug mode enabled.\n");
272 }
273 else if (!strcmp("--nobackground", argv[x]))
274 {
275 background = false;
276 printf("Disabling background image.\n");
277 }
278#ifdef HAVE_REMOTE_LCD
279 else if (!strcmp("--noremote", argv[x]))
280 {
281 showremote = false;
282 background = false;
283 printf("Disabling remote image.\n");
284 }
285#endif
286 else if (!strcmp("--old_lcd", argv[x]))
287 {
288 having_new_lcd = false;
289 printf("Using old LCD layout.\n");
290 }
291 else if (!strcmp("--zoom", argv[x]))
292 {
293 x++;
294 if(x < argc)
295 display_zoom=atoi(argv[x]);
296 else
297 display_zoom = 2;
298 printf("Window zoom is %d\n", display_zoom);
299 }
300 else if (!strcmp("--alarm", argv[x]))
301 {
302 sim_alarm_wakeup = true;
303 printf("Simulating alarm wakeup.\n");
304 }
305 else if (!strcmp("--root", argv[x]))
306 {
307 x++;
308 if (x < argc)
309 {
310 sim_root_dir = argv[x];
311 printf("Root directory: %s\n", sim_root_dir);
312 }
313 }
314 else if (!strcmp("--mapping", argv[x]))
315 {
316 mapping = true;
317 printf("Printing click coords with drag radii.\n");
318 }
319 else if (!strcmp("--debugbuttons", argv[x]))
320 {
321 debug_buttons = true;
322 printf("Printing background button clicks.\n");
323 }
324 else
325 {
326 printf("rockboxui\n");
327 printf("Arguments:\n");
328 printf(" --debugaudio \t Write raw PCM data to audiodebug.raw\n");
329 printf(" --debugwps \t Print advanced WPS debug info\n");
330 printf(" --nobackground \t Disable the background image\n");
331#ifdef HAVE_REMOTE_LCD
332 printf(" --noremote \t Disable the remote image (will disable backgrounds)\n");
333#endif
334 printf(" --old_lcd \t [Player] simulate old playermodel (ROM version<4.51)\n");
335 printf(" --zoom [VAL]\t Window zoom (will disable backgrounds)\n");
336 printf(" --alarm \t Simulate a wake-up on alarm\n");
337 printf(" --root [DIR]\t Set root directory\n");
338 printf(" --mapping \t Output coordinates and radius for mapping backgrounds\n");
339 exit(0);
340 }
341 }
342 }
343
344 if (display_zoom > 1) {
345 background = false;
346 }
347
348 if (!sim_kernel_init()) {
349 fprintf(stderr, "sim_kernel_init failed\n");
350 return -1;
351 }
352
353 if (!gui_startup()) {
354 fprintf(stderr, "gui_startup failed\n");
355 return -1;
356 }
357
358 /* app_main will be called by the new main thread */
359 if (!thread_sdl_init(NULL)) {
360 fprintf(stderr, "thread_sdl_init failed\n");
361 return -1;
362 }
363
364 gui_message_loop();
365
366 return gui_shutdown();
367}
368
diff --git a/uisimulator/sdl/uisdl.h b/uisimulator/sdl/uisdl.h
deleted file mode 100644
index dac84ffb74..0000000000
--- a/uisimulator/sdl/uisdl.h
+++ /dev/null
@@ -1,408 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 Dan Everton
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef __UISDL_H__
23#define __UISDL_H__
24
25#include <stdbool.h>
26#include "SDL.h"
27#include "config.h"
28
29/* colour definitions are R, G, B */
30
31#if defined(ARCHOS_RECORDER)
32#define UI_TITLE "Jukebox Recorder"
33#define UI_WIDTH 270 /* width of GUI window */
34#define UI_HEIGHT 406 /* height of GUI window */
35#define UI_LCD_POSX 80 /* x position of lcd */
36#define UI_LCD_POSY 104 /* y position of lcd */
37
38#elif defined(ARCHOS_PLAYER)
39#define UI_TITLE "Jukebox Player"
40#define UI_WIDTH 284 /* width of GUI window */
41#define UI_HEIGHT 420 /* height of GUI window */
42#define UI_LCD_POSX 75 /* x position of lcd */
43#define UI_LCD_POSY 116 /* y position of lcd */
44
45#elif defined(ARCHOS_FMRECORDER) || defined(ARCHOS_RECORDERV2)
46#define UI_TITLE "Jukebox FM Recorder"
47#define UI_WIDTH 285 /* width of GUI window */
48#define UI_HEIGHT 414 /* height of GUI window */
49#define UI_LCD_POSX 87 /* x position of lcd */
50#define UI_LCD_POSY 77 /* y position of lcd */
51
52#elif defined(ARCHOS_ONDIOSP) || defined(ARCHOS_ONDIOFM)
53#define UI_TITLE "Ondio"
54#define UI_WIDTH 155 /* width of GUI window */
55#define UI_HEIGHT 334 /* height of GUI window */
56#define UI_LCD_POSX 21 /* x position of lcd */
57#define UI_LCD_POSY 82 /* y position of lcd */
58
59#elif defined(IRIVER_H120) || defined(IRIVER_H100)
60#define UI_TITLE "iriver H1x0"
61#define UI_WIDTH 379 /* width of GUI window */
62#define UI_HEIGHT 508 /* height of GUI window */
63#define UI_LCD_POSX 109 /* x position of lcd */
64#define UI_LCD_POSY 23 /* y position of lcd */
65#define UI_REMOTE_POSX 50 /* x position of remote lcd */
66#define UI_REMOTE_POSY 403 /* y position of remote lcd */
67
68#elif defined(IRIVER_H300)
69#define UI_TITLE "iriver H300"
70#define UI_WIDTH 288 /* width of GUI window */
71#define UI_HEIGHT 581 /* height of GUI window */
72#define UI_LCD_POSX 26 /* x position of lcd */
73#define UI_LCD_POSY 36 /* y position of lcd */
74#define UI_REMOTE_POSX 12 /* x position of remote lcd */
75#define UI_REMOTE_POSY 478 /* y position of remote lcd */
76
77#elif defined(IPOD_1G2G)
78#define UI_TITLE "iPod 1G/2G"
79#define UI_WIDTH 224 /* width of GUI window */
80#define UI_HEIGHT 382 /* height of GUI window */
81#define UI_LCD_POSX 32 /* x position of lcd */
82#define UI_LCD_POSY 12 /* y position of lcd */
83
84#elif defined(IPOD_3G)
85#define UI_TITLE "iPod 3G"
86#define UI_WIDTH 218 /* width of GUI window */
87#define UI_HEIGHT 389 /* height of GUI window */
88#define UI_LCD_POSX 29 /* x position of lcd */
89#define UI_LCD_POSY 16 /* y position of lcd */
90
91#elif defined(IPOD_4G)
92#define UI_TITLE "iPod 4G"
93#define UI_WIDTH 196 /* width of GUI window */
94#define UI_HEIGHT 370 /* height of GUI window */
95#define UI_LCD_POSX 19 /* x position of lcd */
96#define UI_LCD_POSY 14 /* y position of lcd */
97
98#elif defined(IPOD_MINI) || defined(IPOD_MINI2G)
99#define UI_TITLE "iPod mini"
100#define UI_WIDTH 191 /* width of GUI window */
101#define UI_HEIGHT 365 /* height of GUI window */
102#define UI_LCD_POSX 24 /* x position of lcd */
103#define UI_LCD_POSY 17 /* y position of lcd */
104
105#elif defined(IPOD_COLOR)
106#define UI_TITLE "iPod Color"
107#define UI_WIDTH 261 /* width of GUI window */
108#define UI_HEIGHT 493 /* height of GUI window */
109#define UI_LCD_POSX 21 /* x position of lcd */
110#define UI_LCD_POSY 16 /* y position of lcd */
111
112#elif defined(IPOD_NANO)
113#define UI_TITLE "iPod Nano"
114#define UI_WIDTH 199 /* width of GUI window */
115#define UI_HEIGHT 421 /* height of GUI window */
116#define UI_LCD_POSX 13 /* x position of lcd */
117#define UI_LCD_POSY 14 /* y position of lcd */
118
119#elif defined(IPOD_NANO2G)
120#define UI_TITLE "iPod Nano 2G"
121#define UI_WIDTH 235 /* width of GUI window */
122#define UI_HEIGHT 537 /* height of GUI window */
123#define UI_LCD_POSX 29 /* x position of lcd */
124#define UI_LCD_POSY 33 /* y position of lcd */
125
126#elif defined(IPOD_VIDEO)
127#define UI_TITLE "iPod Video"
128#define UI_WIDTH 350 /* width of GUI window */
129#define UI_HEIGHT 591 /* height of GUI window */
130#define UI_LCD_POSX 14 /* x position of lcd */
131#define UI_LCD_POSY 12 /* y position of lcd */
132
133#elif defined(IAUDIO_X5)
134#define UI_TITLE "iAudio X5"
135#define UI_WIDTH 300 /* width of GUI window */
136#define UI_HEIGHT 558 /* height of GUI window */
137#define UI_LCD_POSX 55 /* x position of lcd */
138#define UI_LCD_POSY 61 /* y position of lcd */
139#define UI_REMOTE_POSX 12 /* x position of remote lcd */
140#define UI_REMOTE_POSY 462 /* y position of remote lcd */
141
142#elif defined(IAUDIO_M5)
143#define UI_TITLE "iAudio M5"
144#define UI_WIDTH 374 /* width of GUI window */
145#define UI_HEIGHT 650 /* height of GUI window */
146#define UI_LCD_POSX 82 /* x position of lcd */
147#define UI_LCD_POSY 74 /* y position of lcd */
148#define UI_REMOTE_POSX 59 /* x position of remote lcd */
149#define UI_REMOTE_POSY 509 /* y position of remote lcd */
150
151#elif defined(IAUDIO_M3)
152#define UI_TITLE "iAudio M3"
153#define UI_WIDTH 397 /* width of GUI window */
154#define UI_HEIGHT 501 /* height of GUI window */
155#define UI_LCD_POSX 92 /* x position of lcd */
156#define UI_LCD_POSY 348 /* y position of lcd */
157
158#elif defined(GIGABEAT_F)
159#define UI_TITLE "Toshiba Gigabeat"
160#define UI_WIDTH 401 /* width of GUI window */
161#define UI_HEIGHT 655 /* height of GUI window */
162#define UI_LCD_POSX 48 /* x position of lcd */
163#define UI_LCD_POSY 60 /* y position of lcd */
164
165#elif defined(GIGABEAT_S)
166#define UI_TITLE "Toshiba Gigabeat"
167#define UI_WIDTH 450 /* width of GUI window */
168#define UI_HEIGHT 688 /* height of GUI window */
169#define UI_LCD_POSX 96 /* x position of lcd */
170#define UI_LCD_POSY 90 /* y position of lcd */
171
172#elif defined(MROBE_500)
173#if LCD_WIDTH==320
174#define UI_TITLE "Olympus M:Robe 500"
175#define UI_WIDTH 450 /* width of GUI window */
176#define UI_HEIGHT 350 /* height of GUI window */
177#define UI_LCD_POSX 65 /* x position of lcd */
178#define UI_LCD_POSY 30 /* y position of lcd */
179#define UI_REMOTE_POSX 36 /* x position of remote lcd */
180#define UI_REMOTE_POSY 318 /* y position of remote lcd */
181#else
182#define UI_TITLE "Olympus M:Robe 500"
183#define UI_WIDTH 895 /* width of GUI window */
184#define UI_HEIGHT 646 /* height of GUI window */
185#define UI_LCD_POSX 129 /* x position of lcd */
186#define UI_LCD_POSY 60 /* y position of lcd */
187#define UI_REMOTE_POSX 37 /* x position of remote lcd */
188#define UI_REMOTE_POSY 615 /* y position of remote lcd */
189#endif
190
191#elif defined(IRIVER_H10)
192#define UI_TITLE "iriver H10 20Gb"
193#define UI_WIDTH 392 /* width of GUI window */
194#define UI_HEIGHT 391 /* height of GUI window */
195#define UI_LCD_POSX 111 /* x position of lcd */
196#define UI_LCD_POSY 30 /* y position of lcd */
197
198#elif defined(IRIVER_H10_5GB)
199#define UI_TITLE "iriver H10 5/6Gb"
200#define UI_WIDTH 353 /* width of GUI window */
201#define UI_HEIGHT 460 /* height of GUI window */
202#define UI_LCD_POSX 112 /* x position of lcd */
203#define UI_LCD_POSY 45 /* y position of lcd */
204
205#elif defined(SANSA_E200) || defined(SANSA_E200V2)
206#ifdef SANSA_E200
207#define UI_TITLE "Sansa e200"
208#else
209#define UI_TITLE "Sansa e200v2"
210#endif
211#define UI_WIDTH 260 /* width of GUI window */
212#define UI_HEIGHT 502 /* height of GUI window */
213#define UI_LCD_POSX 42 /* x position of lcd */
214#define UI_LCD_POSY 37 /* y position of lcd */
215
216#elif defined(SANSA_C200) || defined(SANSA_C200V2)
217#ifdef SANSA_C200
218#define UI_TITLE "Sansa c200"
219#else
220#define UI_TITLE "Sansa c200v2"
221#endif
222#define UI_WIDTH 350 /* width of GUI window */
223#define UI_HEIGHT 152 /* height of GUI window */
224#define UI_LCD_POSX 42 /* x position of lcd */
225#define UI_LCD_POSY 35 /* y position of lcd */
226
227#elif defined(IRIVER_IFP7XX)
228#define UI_TITLE "iriver iFP7xx"
229#define UI_WIDTH 425 /* width of GUI window */
230#define UI_HEIGHT 183 /* height of GUI window */
231#define UI_LCD_POSX 115 /* x position of lcd */
232#define UI_LCD_POSY 54 /* y position of lcd */
233
234#elif defined(ARCHOS_AV300)
235#define UI_TITLE "Archos AV300"
236/* We are temporarily using a 2bpp LCD driver and dummy bitmap */
237#define UI_WIDTH 420 /* width of GUI window */
238#define UI_HEIGHT 340 /* height of GUI window */
239#define UI_LCD_POSX 50 /* x position of lcd */
240#define UI_LCD_POSY 50 /* y position of lcd */
241
242#elif defined(MROBE_100)
243#define UI_TITLE "Olympus M:Robe 100"
244#define UI_WIDTH 247 /* width of GUI window */
245#define UI_HEIGHT 462 /* height of GUI window */
246#define UI_LCD_POSX 43 /* x position of lcd */
247#define UI_LCD_POSY 25 /* y position of lcd */
248#define UI_REMOTE_POSX 34 /* x position of remote lcd */
249#define UI_REMOTE_POSY 432 /* y position of remote lcd */
250
251#elif defined(COWON_D2)
252#define UI_TITLE "Cowon D2"
253#define UI_WIDTH 472 /* width of GUI window */
254#define UI_HEIGHT 368 /* height of GUI window */
255#define UI_LCD_POSX 58 /* x position of lcd */
256#define UI_LCD_POSY 67 /* y position of lcd */
257
258#elif defined(IAUDIO_7)
259#define UI_TITLE "iAudio7"
260#define UI_WIDTH 494 /* width of GUI window */
261#define UI_HEIGHT 214 /* height of GUI window */
262#define UI_LCD_POSX 131 /* x position of lcd */
263#define UI_LCD_POSY 38 /* y position of lcd */
264
265#elif defined(CREATIVE_ZVM) || defined(CREATIVE_ZVM60GB)
266#ifdef CREATIVE_ZVM
267 #define UI_TITLE "Creative Zen Vision:M 30GB"
268#else
269 #define UI_TITLE "Creative Zen Vision:M 60GB"
270#endif
271#define UI_WIDTH 383 /* width of GUI window */
272#define UI_HEIGHT 643 /* height of GUI window */
273#define UI_LCD_POSX 31 /* x position of lcd */
274#define UI_LCD_POSY 62 /* y position of lcd */
275
276#elif defined(CREATIVE_ZV)
277#define UI_TITLE "Creative Zen Vision"
278#define UI_WIDTH 1054 /* width of GUI window */
279#define UI_HEIGHT 643 /* height of GUI window */
280#define UI_LCD_POSX 129 /* x position of lcd */
281#define UI_LCD_POSY 85 /* y position of lcd */
282
283#elif defined(MEIZU_M6SL)
284#define UI_TITLE "Meizu M6"
285#define UI_WIDTH 512 /* width of GUI window */
286#define UI_HEIGHT 322 /* height of GUI window */
287#define UI_LCD_POSX 39 /* x position of lcd */
288#define UI_LCD_POSY 38 /* y position of lcd */
289
290#elif defined(SANSA_FUZE) || defined(SANSA_FUZEV2)
291#ifdef SANSA_FUZE
292#define UI_TITLE "Sansa Fuze"
293#else
294#define UI_TITLE "Sansa Fuzev2"
295#endif
296#define UI_WIDTH 279 /* width of GUI window */
297#define UI_HEIGHT 449 /* height of GUI window */
298#define UI_LCD_POSX 30 /* x position of lcd */
299#define UI_LCD_POSY 31 /* y position of lcd */
300
301#elif defined(SANSA_CLIP) || defined(SANSA_CLIPV2)
302#if defined(SANSA_CLIP)
303#define CLIP_VERSION ""
304#elif defined(SANSA_CLIPV2)
305#define CLIP_VERSION "v2"
306#endif
307#define UI_TITLE "Sansa Clip"CLIP_VERSION
308#define UI_WIDTH 205 /* width of GUI window */
309#define UI_HEIGHT 325 /* height of GUI window */
310#define UI_LCD_POSX 38 /* x position of lcd */
311#define UI_LCD_POSY 38 /* y position of lcd */
312
313#elif defined(SANSA_CLIPPLUS)
314#define UI_TITLE "Sansa Clip+"
315#define UI_WIDTH 205 /* width of GUI window */
316#define UI_HEIGHT 325 /* height of GUI window */
317#define UI_LCD_POSX 42 /* x position of lcd */
318#define UI_LCD_POSY 42 /* y position of lcd */
319
320
321
322#elif defined(PHILIPS_SA9200)
323#define UI_TITLE "Philips GoGear SA9200"
324#define UI_WIDTH 233 /* width of GUI window */
325#define UI_HEIGHT 435 /* height of GUI window */
326#define UI_LCD_POSX 50 /* x position of lcd */
327#define UI_LCD_POSY 50 /* y position of lcd */
328
329#elif defined(PHILIPS_HDD1630)
330#define UI_TITLE "Philips GoGear HDD1630"
331#define UI_WIDTH 407 /* width of GUI window */
332#define UI_HEIGHT 391 /* height of GUI window */
333#define UI_LCD_POSX 143 /* x position of lcd */
334#define UI_LCD_POSY 27 /* y position of lcd */
335
336#elif defined(SANSA_M200V4)
337#define UI_TITLE "sansa m200v4"
338#define UI_WIDTH 350 /* width of GUI window */
339#define UI_HEIGHT 168 /* height of GUI window */
340#define UI_LCD_POSX 42 /* x position of lcd */
341#define UI_LCD_POSY 55 /* y position of lcd */
342
343#elif defined(ONDA_VX747) || defined(ONDA_VX747P)
344#ifdef ONDA_VX747
345#define UI_TITLE "Onda VX747"
346#else
347#define UI_TITLE "Onda VX747+"
348#endif
349#define UI_WIDTH 340 /* width of GUI window */
350#define UI_HEIGHT 601 /* height of GUI window */
351#define UI_LCD_POSX 45 /* x position of lcd */
352#define UI_LCD_POSY 90 /* y position of lcd */
353
354#elif defined(ONDA_VX777)
355#define UI_TITLE "Onda VX777"
356#define UI_WIDTH 306 /* width of GUI window */
357#define UI_HEIGHT 558 /* height of GUI window */
358#define UI_LCD_POSX 32 /* x position of lcd */
359#define UI_LCD_POSY 81 /* y position of lcd */
360
361#elif defined(SAMSUNG_YH820)
362#define UI_TITLE "Samsung YH-820"
363#define UI_WIDTH 368 /* width of GUI window */
364#define UI_HEIGHT 428 /* height of GUI window */
365#define UI_LCD_POSX 120 /* x position of lcd */
366#define UI_LCD_POSY 75 /* y position of lcd */
367
368#elif defined(SAMSUNG_YH920) || defined(SAMSUNG_YH925)
369#ifdef SAMSUNG_YH920
370#define UI_TITLE "Samsung YH-920"
371#else
372#define UI_TITLE "Samsung YH-925"
373#endif
374#define UI_WIDTH 408 /* width of GUI window */
375#define UI_HEIGHT 454 /* height of GUI window */
376#define UI_LCD_POSX 124 /* x position of lcd */
377#define UI_LCD_POSY 42 /* y position of lcd */
378
379#elif defined(MINI2440)
380#define UI_TITLE "Mini2440"
381#define UI_WIDTH 441 /* width of GUI window */
382#define UI_HEIGHT 436 /* height of GUI window */
383#define UI_LCD_POSX 148 /* x position of lcd */
384#define UI_LCD_POSY 50 /* y position of lcd */
385
386#elif defined(PBELL_VIBE500)
387#define UI_TITLE "Packard Bell Vibe 500"
388#define UI_WIDTH 287 /* width of GUI window */
389#define UI_HEIGHT 488 /* height of GUI window */
390#define UI_LCD_POSX 64 /* x position of lcd */
391#define UI_LCD_POSY 61 /* y position of lcd */
392
393#elif defined(MPIO_HD200)
394#define UI_TITLE "MPIO HD200"
395#define UI_WIDTH 430 /* width of GUI window */
396#define UI_HEIGHT 479 /* height of GUI window */
397#define UI_LCD_POSX 101
398#define UI_LCD_POSY 195
399
400#else
401#error no UI defines
402#endif
403extern SDL_Surface *gui_surface;
404extern bool background; /* True if the background image is enabled */
405extern int display_zoom;
406
407#endif /* #ifndef __UISDL_H__ */
408
diff --git a/uisimulator/uisimulator.make b/uisimulator/uisimulator.make
index 121f31e0f6..86fcb2a3d2 100644
--- a/uisimulator/uisimulator.make
+++ b/uisimulator/uisimulator.make
@@ -8,13 +8,10 @@
8# 8#
9 9
10INCLUDES += -I$(ROOTDIR)/uisimulator/sdl -I$(ROOTDIR)/uisimulator/common \ 10INCLUDES += -I$(ROOTDIR)/uisimulator/sdl -I$(ROOTDIR)/uisimulator/common \
11 -I$(FIRMDIR)/include -I$(FIRMDIR)/export $(TARGET_INC) -I$(BUILDDIR) -I$(APPSDIR)
11 12
12SIMINCLUDES += -I$(ROOTDIR)/uisimulator/sdl -I$(ROOTDIR)/uisimulator/common \ 13SIMFLAGS += $(INCLUDES) $(DEFINES) -DHAVE_CONFIG_H $(GCCOPTS)
13 -I$(FIRMDIR)/export $(TARGET_INC) -I$(BUILDDIR) -I$(APPSDIR)
14 14
15SIMFLAGS += $(SIMINCLUDES) $(DEFINES) -DHAVE_CONFIG_H $(GCCOPTS)
16
17SIMSRC += $(call preprocess, $(ROOTDIR)/uisimulator/sdl/SOURCES)
18SIMSRC += $(call preprocess, $(ROOTDIR)/uisimulator/common/SOURCES) 15SIMSRC += $(call preprocess, $(ROOTDIR)/uisimulator/common/SOURCES)
19SIMOBJ = $(call c2obj,$(SIMSRC)) 16SIMOBJ = $(call c2obj,$(SIMSRC))
20OTHER_SRC += $(SIMSRC) 17OTHER_SRC += $(SIMSRC)