summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2006-02-03 15:19:58 +0000
committerLinus Nielsen Feltzing <linus@haxx.se>2006-02-03 15:19:58 +0000
commitfc72c5375813a6bbc0845aca984147a944a7e62a (patch)
tree347a6a9297f9f4d3131c8268f450d6ba227d0246
parent347992e9d93ed0f91cde7e2d580cfdc8d5eb95f4 (diff)
downloadrockbox-fc72c5375813a6bbc0845aca984147a944a7e62a.tar.gz
rockbox-fc72c5375813a6bbc0845aca984147a944a7e62a.zip
Patch #1417462 by Dan Everton - Improved SDL simulator
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8546 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--uisimulator/common/io.c4
-rw-r--r--uisimulator/common/lcd-common.c4
-rw-r--r--uisimulator/sdl/Makefile16
-rw-r--r--uisimulator/sdl/SOURCES9
-rw-r--r--uisimulator/sdl/UI-fmrecorder.bmpbin0 -> 236864 bytes
-rw-r--r--uisimulator/sdl/UI-gmini120.bmpbin0 -> 195416 bytes
-rw-r--r--uisimulator/sdl/UI-h100.bmpbin0 -> 194120 bytes
-rw-r--r--uisimulator/sdl/UI-h120.bmpbin0 -> 194120 bytes
-rw-r--r--uisimulator/sdl/UI-h300.bmpbin0 -> 168408 bytes
-rw-r--r--uisimulator/sdl/UI-ipodcolor.bmpbin0 -> 131232 bytes
-rw-r--r--uisimulator/sdl/UI-ipodnano.bmpbin0 -> 85280 bytes
-rw-r--r--uisimulator/sdl/UI-ondiofm.bmpbin0 -> 104264 bytes
-rw-r--r--uisimulator/sdl/UI-ondiosp.bmpbin0 -> 104264 bytes
-rw-r--r--uisimulator/sdl/UI-player.bmpbin0 -> 238616 bytes
-rw-r--r--uisimulator/sdl/UI-recorder.bmpbin0 -> 219296 bytes
-rw-r--r--uisimulator/sdl/UI-recorderv2.bmpbin0 -> 236864 bytes
-rw-r--r--uisimulator/sdl/button-x11.c317
-rw-r--r--uisimulator/sdl/button.c275
-rw-r--r--uisimulator/sdl/kernel.c13
-rw-r--r--uisimulator/sdl/lcd-sdl.c291
-rw-r--r--uisimulator/sdl/lcd-sdl.h39
-rw-r--r--uisimulator/sdl/lcd-x11.c212
-rw-r--r--uisimulator/sdl/screenhack.c232
-rw-r--r--uisimulator/sdl/screenhack.h33
-rw-r--r--uisimulator/sdl/sound.c30
-rw-r--r--uisimulator/sdl/sprintf.h36
-rw-r--r--uisimulator/sdl/thread-sdl.c78
-rw-r--r--uisimulator/sdl/thread-sdl.h (renamed from uisimulator/sdl/lcd-x11.h)23
-rw-r--r--uisimulator/sdl/uisdl.c287
29 files changed, 887 insertions, 1012 deletions
diff --git a/uisimulator/common/io.c b/uisimulator/common/io.c
index 4943bc04e2..e18d8e6a57 100644
--- a/uisimulator/common/io.c
+++ b/uisimulator/common/io.c
@@ -71,7 +71,11 @@ typedef struct mydir MYDIR;
71#if 1 /* maybe this needs disabling for MSVC... */ 71#if 1 /* maybe this needs disabling for MSVC... */
72static unsigned int rockbox2sim(int opt) 72static unsigned int rockbox2sim(int opt)
73{ 73{
74#ifdef WIN32
75 int newopt = O_BINARY;
76#else
74 int newopt = 0; 77 int newopt = 0;
78#endif
75 if(opt & 1) 79 if(opt & 1)
76 newopt |= O_WRONLY; 80 newopt |= O_WRONLY;
77 if(opt & 2) 81 if(opt & 2)
diff --git a/uisimulator/common/lcd-common.c b/uisimulator/common/lcd-common.c
index 119c440318..a28e619706 100644
--- a/uisimulator/common/lcd-common.c
+++ b/uisimulator/common/lcd-common.c
@@ -24,7 +24,9 @@
24 24
25#include "lcd.h" 25#include "lcd.h"
26 26
27#if defined(WIN32) && !defined(SDL) 27#if defined(SDL)
28#include "lcd-sdl.h"
29#elif defined(WIN32)
28#include "lcd-win32.h" 30#include "lcd-win32.h"
29#else 31#else
30#include "lcd-x11.h" 32#include "lcd-x11.h"
diff --git a/uisimulator/sdl/Makefile b/uisimulator/sdl/Makefile
index 989ac65223..5c5693e98c 100644
--- a/uisimulator/sdl/Makefile
+++ b/uisimulator/sdl/Makefile
@@ -40,7 +40,7 @@ SOURCES = $(SRC)
40 40
41DIRS = . 41DIRS = .
42 42
43CFLAGS = $(DEBUG) $(DEFINES) $(INCLUDES) $(GCCOPTS) 43CFLAGS = $(DEBUG) $(DEFINES) $(INCLUDES) $(GCCOPTS) -W -Wall
44 44
45OUTFILE = $(BUILDDIR)/libsim.a 45OUTFILE = $(BUILDDIR)/libsim.a
46 46
@@ -48,13 +48,19 @@ all: $(OUTFILE)
48 48
49include $(TOOLSDIR)/make.inc 49include $(TOOLSDIR)/make.inc
50 50
51$(OUTFILE): $(OBJS) $(BUILDDIR)/UI256.bmp
52 @echo "AR $@"
53 @$(AR) ruv $@ $(OBJS) >/dev/null 2>&1
54
51clean: 55clean:
52 @echo "cleaning sim" 56 @echo "cleaning sim"
53 @$(RM) $(OBJS) *~ core $(OUTFILE) $(DEPFILE) 57 @$(RM) $(OBJS) *~ core $(OUTFILE) $(DEPFILE) \
58 $(BUILDDIR)/UI256.bmp $(DEPFILE)
54 @$(MAKE) -C $(SIMCOMMON) clean 59 @$(MAKE) -C $(SIMCOMMON) clean
55 60
56$(OUTFILE): $(OBJS) 61################## Specific dependencies ##################
57 @echo "AR $@" 62$(BUILDDIR)/UI256.bmp: UI-$(ARCHOS).bmp
58 @$(AR) ruv $@ $(OBJS) >/dev/null 2>&1 63 @echo UI
64 @cp $< $@
59 65
60-include $(DEPFILE) 66-include $(DEPFILE)
diff --git a/uisimulator/sdl/SOURCES b/uisimulator/sdl/SOURCES
index 32d70b50bf..cbb39a4e6a 100644
--- a/uisimulator/sdl/SOURCES
+++ b/uisimulator/sdl/SOURCES
@@ -1,7 +1,6 @@
1button-x11.c 1button.c
2kernel.c 2kernel.c
3lcd-x11.c 3lcd-sdl.c
4screenhack.c
5thread.c
6uisdl.c
7sound.c 4sound.c
5thread-sdl.c
6uisdl.c
diff --git a/uisimulator/sdl/UI-fmrecorder.bmp b/uisimulator/sdl/UI-fmrecorder.bmp
new file mode 100644
index 0000000000..53f705b9ef
--- /dev/null
+++ b/uisimulator/sdl/UI-fmrecorder.bmp
Binary files differ
diff --git a/uisimulator/sdl/UI-gmini120.bmp b/uisimulator/sdl/UI-gmini120.bmp
new file mode 100644
index 0000000000..afeaf74801
--- /dev/null
+++ b/uisimulator/sdl/UI-gmini120.bmp
Binary files differ
diff --git a/uisimulator/sdl/UI-h100.bmp b/uisimulator/sdl/UI-h100.bmp
new file mode 100644
index 0000000000..caeb81bc4b
--- /dev/null
+++ b/uisimulator/sdl/UI-h100.bmp
Binary files differ
diff --git a/uisimulator/sdl/UI-h120.bmp b/uisimulator/sdl/UI-h120.bmp
new file mode 100644
index 0000000000..caeb81bc4b
--- /dev/null
+++ b/uisimulator/sdl/UI-h120.bmp
Binary files differ
diff --git a/uisimulator/sdl/UI-h300.bmp b/uisimulator/sdl/UI-h300.bmp
new file mode 100644
index 0000000000..5f099b717a
--- /dev/null
+++ b/uisimulator/sdl/UI-h300.bmp
Binary files differ
diff --git a/uisimulator/sdl/UI-ipodcolor.bmp b/uisimulator/sdl/UI-ipodcolor.bmp
new file mode 100644
index 0000000000..de5dad4ffe
--- /dev/null
+++ b/uisimulator/sdl/UI-ipodcolor.bmp
Binary files differ
diff --git a/uisimulator/sdl/UI-ipodnano.bmp b/uisimulator/sdl/UI-ipodnano.bmp
new file mode 100644
index 0000000000..e33f7e81da
--- /dev/null
+++ b/uisimulator/sdl/UI-ipodnano.bmp
Binary files differ
diff --git a/uisimulator/sdl/UI-ondiofm.bmp b/uisimulator/sdl/UI-ondiofm.bmp
new file mode 100644
index 0000000000..e258720d28
--- /dev/null
+++ b/uisimulator/sdl/UI-ondiofm.bmp
Binary files differ
diff --git a/uisimulator/sdl/UI-ondiosp.bmp b/uisimulator/sdl/UI-ondiosp.bmp
new file mode 100644
index 0000000000..c62c2334a3
--- /dev/null
+++ b/uisimulator/sdl/UI-ondiosp.bmp
Binary files differ
diff --git a/uisimulator/sdl/UI-player.bmp b/uisimulator/sdl/UI-player.bmp
new file mode 100644
index 0000000000..db4003b120
--- /dev/null
+++ b/uisimulator/sdl/UI-player.bmp
Binary files differ
diff --git a/uisimulator/sdl/UI-recorder.bmp b/uisimulator/sdl/UI-recorder.bmp
new file mode 100644
index 0000000000..98937fea2d
--- /dev/null
+++ b/uisimulator/sdl/UI-recorder.bmp
Binary files differ
diff --git a/uisimulator/sdl/UI-recorderv2.bmp b/uisimulator/sdl/UI-recorderv2.bmp
new file mode 100644
index 0000000000..53f705b9ef
--- /dev/null
+++ b/uisimulator/sdl/UI-recorderv2.bmp
Binary files differ
diff --git a/uisimulator/sdl/button-x11.c b/uisimulator/sdl/button-x11.c
deleted file mode 100644
index b0ab81a86a..0000000000
--- a/uisimulator/sdl/button-x11.c
+++ /dev/null
@@ -1,317 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Björn Stenberg
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include <stdlib.h>
20#include "config.h"
21#include "button.h"
22#include "kernel.h"
23#include "debug.h"
24#include "backlight.h"
25#include "misc.h"
26#include <SDL.h>
27
28extern int screenhack_handle_events(bool *release);
29
30struct event_queue button_queue;
31
32static int button_state = 0; /* keeps track of pressed keys */
33static long lastbtn; /* Last valid button status */
34
35/* how often we check to see if a button is pressed */
36#define POLL_FREQUENCY HZ/25
37
38/* how long until repeat kicks in */
39#define REPEAT_START 8
40
41/* the speed repeat starts at */
42#define REPEAT_INTERVAL_START 4
43
44/* speed repeat finishes at */
45#define REPEAT_INTERVAL_FINISH 2
46
47/* mostly copied from real button.c */
48void button_read (void);
49
50static void button_tick(void)
51{
52 static int tick = 0;
53 static int count = 0;
54 static int repeat_speed = REPEAT_INTERVAL_START;
55 static int repeat_count = 0;
56 static bool repeat = false;
57 int diff;
58 int btn;
59
60 /* only poll every X ticks */
61 if ( ++tick >= POLL_FREQUENCY )
62 {
63 bool post = false;
64 button_read();
65 btn = button_state;
66
67 /* Find out if a key has been released */
68 diff = btn ^ lastbtn;
69 if(diff && (btn & diff) == 0)
70 {
71 queue_post(&button_queue, BUTTON_REL | diff, NULL);
72 }
73 else
74 {
75 if ( btn )
76 {
77 /* normal keypress */
78 if ( btn != lastbtn )
79 {
80 post = true;
81 repeat = false;
82 repeat_speed = REPEAT_INTERVAL_START;
83
84 }
85 else /* repeat? */
86 {
87 if ( repeat )
88 {
89 count--;
90 if (count == 0) {
91 post = true;
92 /* yes we have repeat */
93 repeat_speed--;
94 if (repeat_speed < REPEAT_INTERVAL_FINISH)
95 repeat_speed = REPEAT_INTERVAL_FINISH;
96 count = repeat_speed;
97
98 repeat_count++;
99
100 }
101 }
102 else
103 {
104 if (count++ > REPEAT_START)
105 {
106 post = true;
107 repeat = true;
108 repeat_count = 0;
109 /* initial repeat */
110 count = REPEAT_INTERVAL_START;
111 }
112 }
113 }
114 if ( post )
115 {
116 if (repeat)
117 queue_post(&button_queue, BUTTON_REPEAT | btn, NULL);
118 else
119 queue_post(&button_queue, btn, NULL);
120#ifdef HAVE_REMOTE_LCD
121 if(btn & BUTTON_REMOTE)
122 remote_backlight_on();
123 else
124#endif
125 backlight_on();
126
127 }
128 }
129 else
130 {
131 repeat = false;
132 count = 0;
133 }
134 }
135 lastbtn = btn & ~(BUTTON_REL | BUTTON_REPEAT);
136 tick = 0;
137 }
138}
139
140/*
141 * Read SDL keys and translate to rockbox buttons
142 */
143
144void button_read (void)
145{
146 int k;
147 bool release = false; /* is this a release event */
148 int ev = screenhack_handle_events(&release);
149
150 switch (ev)
151 {
152 case SDLK_KP4:
153 case SDLK_LEFT:
154 case SDLK_4:
155 k = BUTTON_LEFT;
156 break;
157
158 case SDLK_KP6:
159 case SDLK_RIGHT:
160 case SDLK_6:
161 k = BUTTON_RIGHT;
162 break;
163
164 case SDLK_KP8:
165 case SDLK_UP:
166 case SDLK_8:
167#ifdef BUTTON_UP
168 k = BUTTON_UP;
169#elif defined BUTTON_SCROLL_BACK
170 k = BUTTON_SCROLL_BACK;
171#elif defined BUTTON_PLAY
172 k = BUTTON_PLAY;
173#endif
174 break;
175
176 case SDLK_KP2:
177 case SDLK_DOWN:
178 case SDLK_2:
179#ifdef BUTTON_DOWN
180 k = BUTTON_DOWN;
181#elif defined BUTTON_SCROLL_FWD
182 k = BUTTON_SCROLL_FWD;
183#elif defined BUTTON_STOP
184 k = BUTTON_STOP;
185#endif
186 break;
187
188#ifdef BUTTON_ON
189 case SDLK_KP_PLUS:
190 case SDLK_q:
191 k = BUTTON_ON;
192 break;
193#endif
194
195#ifdef BUTTON_OFF
196 case SDLK_KP_ENTER:
197 case SDLK_a:
198 k = BUTTON_OFF;
199 break;
200#endif
201
202#ifdef BUTTON_POWER
203 case SDLK_KP_MINUS:
204 case SDLK_p:
205 k = BUTTON_POWER;
206#endif
207
208#ifdef BUTTON_F1
209 case SDLK_KP_DIVIDE:
210 case SDLK_F1:
211 k = BUTTON_F1;
212 break;
213
214 case SDLK_KP_MULTIPLY:
215 case SDLK_F2:
216 k = BUTTON_F2;
217 break;
218
219 case SDLK_KP_MINUS:
220 case SDLK_F3:
221 k = BUTTON_F3;
222 break;
223#elif defined(BUTTON_REC)
224 case SDLK_KP_DIVIDE:
225 case SDLK_F1:
226 k = BUTTON_REC;
227 break;
228#endif
229
230 case SDLK_KP5:
231 case SDLK_5:
232 case SDLK_SPACE:
233#ifdef BUTTON_PLAY
234 k = BUTTON_PLAY;
235#elif defined(BUTTON_SELECT)
236 k = BUTTON_SELECT;
237#endif
238 break;
239
240#ifdef HAVE_LCD_BITMAP
241 case SDLK_7:
242 if(!release)
243 screen_dump();
244 break;
245#endif
246
247 case SDLK_KP_PERIOD:
248 case SDLK_INSERT:
249#ifdef BUTTON_MENU
250 k = BUTTON_MENU;
251#elif defined(BUTTON_MODE)
252 k = BUTTON_MODE;
253#endif
254 break;
255
256 default:
257 k = 0;
258 if(ev)
259 DEBUGF("received ev %d\n", ev);
260 break;
261 }
262
263 if (release)
264 button_state &= ~k;
265 else
266 button_state |= k;
267}
268
269/* Again copied from real button.c... */
270
271long button_get(bool block)
272{
273 struct event ev;
274
275 if ( block || !queue_empty(&button_queue) )
276 {
277 queue_wait(&button_queue, &ev);
278 return ev.id;
279 }
280 return BUTTON_NONE;
281}
282
283long button_get_w_tmo(int ticks)
284{
285 struct event ev;
286 queue_wait_w_tmo(&button_queue, &ev, ticks);
287 return (ev.id != SYS_TIMEOUT)? ev.id: BUTTON_NONE;
288}
289
290void button_init(void)
291{
292 tick_add_task(button_tick);
293}
294
295int button_status(void)
296{
297 return lastbtn;
298}
299
300void button_clear_queue(void)
301{
302 queue_clear(&button_queue);
303}
304
305#ifdef HAS_BUTTON_HOLD
306bool button_hold(void) {
307 /* temp fix for hold button on irivers */
308 return false;
309}
310#endif
311
312#ifdef HAS_REMOTE_BUTTON_HOLD
313bool remote_button_hold(void) {
314 /* temp fix for hold button on irivers */
315 return false;
316}
317#endif
diff --git a/uisimulator/sdl/button.c b/uisimulator/sdl/button.c
new file mode 100644
index 0000000000..5def88b9af
--- /dev/null
+++ b/uisimulator/sdl/button.c
@@ -0,0 +1,275 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Felix Arends
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#include "uisdl.h"
21#include "config.h"
22#include "button.h"
23#include "kernel.h"
24#include "backlight.h"
25#include "misc.h"
26
27/* how long until repeat kicks in */
28#define REPEAT_START 6
29
30/* the speed repeat starts at */
31#define REPEAT_INTERVAL_START 4
32
33/* speed repeat finishes at */
34#define REPEAT_INTERVAL_FINISH 2
35
36struct event_queue button_queue;
37
38static int btn = 0; /* Hopefully keeps track of currently pressed keys... */
39
40void button_event(int key, bool pressed)
41{
42 bool post = false;
43 int new_btn = 0;
44 int diff = 0;
45 static int count = 0;
46 static int lastbtn;
47 static int repeat_speed = REPEAT_INTERVAL_START;
48 static int repeat_count = 0;
49 static bool repeat = false;
50
51 switch (key)
52 {
53 case SDLK_KP4:
54 case SDLK_LEFT:
55 new_btn = BUTTON_LEFT;
56 break;
57 case SDLK_KP6:
58 case SDLK_RIGHT:
59 new_btn = BUTTON_RIGHT;
60 break;
61
62 case SDLK_KP8:
63 case SDLK_UP:
64#ifdef BUTTON_UP
65 new_btn = BUTTON_UP;
66#elif defined BUTTON_SCROLL_FWD
67 new_btn = BUTTON_SCROLL_FWD;
68#elif defined BUTTON_PLAY
69 new_btn = BUTTON_PLAY;
70#endif
71 break;
72
73 case SDLK_KP2:
74 case SDLK_DOWN:
75#ifdef BUTTON_DOWN
76 new_btn = BUTTON_DOWN;
77#elif defined BUTTON_SCROLL_BACK
78 new_btn = BUTTON_SCROLL_BACK;
79#elif defined BUTTON_STOP
80 new_btn = BUTTON_STOP;
81#endif
82 break;
83
84 case SDLK_KP_PLUS:
85#ifdef BUTTON_ON
86 new_btn = BUTTON_ON;
87#elif defined(BUTTON_SELECT) && defined(BUTTON_PLAY)
88 new_btn = BUTTON_PLAY;
89#endif
90 break;
91
92#ifdef BUTTON_OFF
93 case SDLK_RETURN:
94 new_btn = BUTTON_OFF;
95 break;
96#endif
97
98#ifdef BUTTON_F1
99 case SDLK_KP_DIVIDE:
100 case SDLK_F1:
101 new_btn = BUTTON_F1;
102 break;
103 case SDLK_KP_MULTIPLY:
104 case SDLK_F2:
105 new_btn = BUTTON_F2;
106 break;
107 case SDLK_KP_MINUS:
108 case SDLK_F3:
109 new_btn = BUTTON_F3;
110 break;
111#elif defined(BUTTON_REC)
112 case SDLK_KP_DIVIDE:
113 case SDLK_F1:
114 new_btn = BUTTON_REC;
115 break;
116#endif
117
118 case SDLK_KP5:
119 case SDLK_SPACE:
120#if defined(BUTTON_PLAY) && !defined(BUTTON_SELECT)
121 new_btn = BUTTON_PLAY;
122#elif defined(BUTTON_SELECT)
123 new_btn = BUTTON_SELECT;
124#endif
125 break;
126
127#ifdef HAVE_LCD_BITMAP
128 case SDLK_KP0:
129 case SDLK_F5:
130 if(pressed)
131 {
132 screen_dump();
133 return;
134 }
135 break;
136#endif
137
138 case SDLK_PERIOD:
139 case SDLK_INSERT:
140#ifdef BUTTON_MENU
141 new_btn = BUTTON_MENU;
142#elif defined(BUTTON_MODE)
143 new_btn = BUTTON_MODE;
144#endif
145 break;
146 }
147
148 if (pressed)
149 btn |= new_btn;
150 else
151 btn &= ~new_btn;
152
153 /* Lots of stuff copied from real button.c. Not good, I think... */
154
155 /* Find out if a key has been released */
156 diff = btn ^ lastbtn;
157
158 if(diff && (btn & diff) == 0)
159 {
160 queue_post(&button_queue, BUTTON_REL | diff, NULL);
161 }
162 else
163 {
164 if ( btn )
165 {
166 /* normal keypress */
167 if ( btn != lastbtn )
168 {
169 post = true;
170 repeat = false;
171 repeat_speed = REPEAT_INTERVAL_START;
172
173 }
174 else /* repeat? */
175 {
176 if ( repeat )
177 {
178 count--;
179 if (count == 0)
180 {
181 post = true;
182 /* yes we have repeat */
183 repeat_speed--;
184 if (repeat_speed < REPEAT_INTERVAL_FINISH)
185 repeat_speed = REPEAT_INTERVAL_FINISH;
186 count = repeat_speed;
187
188 repeat_count++;
189 }
190 }
191 else
192 {
193 if (count++ > REPEAT_START)
194 {
195 post = true;
196 repeat = true;
197 repeat_count = 0;
198 /* initial repeat */
199 count = REPEAT_INTERVAL_START;
200 }
201 }
202 }
203 if ( post )
204 {
205 if(repeat)
206 queue_post(&button_queue, BUTTON_REPEAT | btn, NULL);
207 else
208 queue_post(&button_queue, btn, NULL);
209
210#ifdef HAVE_REMOTE_LCD
211 if(btn & BUTTON_REMOTE)
212 remote_backlight_on();
213 else
214#endif
215 backlight_on();
216
217 }
218 }
219 else
220 {
221 repeat = false;
222 count = 0;
223 }
224 }
225 lastbtn = btn & ~(BUTTON_REL | BUTTON_REPEAT);
226}
227
228/* Again copied from real button.c... */
229
230long button_get(bool block)
231{
232 struct event ev;
233
234 if ( block || !queue_empty(&button_queue) ) {
235 queue_wait(&button_queue, &ev);
236 return ev.id;
237 }
238 return BUTTON_NONE;
239}
240
241long button_get_w_tmo(int ticks)
242{
243 struct event ev;
244 queue_wait_w_tmo(&button_queue, &ev, ticks);
245 return (ev.id != SYS_TIMEOUT)? ev.id: BUTTON_NONE;
246}
247
248void button_init(void)
249{
250}
251
252int button_status(void)
253{
254 return btn;
255}
256
257void button_clear_queue(void)
258{
259 queue_clear(&button_queue);
260}
261
262#ifdef HAS_BUTTON_HOLD
263bool button_hold(void) {
264 /* temp fix for hold button on irivers */
265 return false;
266}
267#endif
268
269#ifdef HAS_REMOTE_BUTTON_HOLD
270bool remote_button_hold(void) {
271 /* temp fix for hold button on irivers */
272 return false;
273}
274#endif
275
diff --git a/uisimulator/sdl/kernel.c b/uisimulator/sdl/kernel.c
index 947d82a550..2621ecebdd 100644
--- a/uisimulator/sdl/kernel.c
+++ b/uisimulator/sdl/kernel.c
@@ -7,7 +7,7 @@
7 * \/ \/ \/ \/ \/ 7 * \/ \/ \/ \/ \/
8 * $Id$ 8 * $Id$
9 * 9 *
10 * Copyright (C) 2005 by Jens Arnold 10 * Copyright (C) 2002 by Felix Arends
11 * 11 *
12 * All files in this archive are subject to the GNU General Public License. 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. 13 * See the file COPYING in the source tree root for full license agreement.
@@ -17,11 +17,18 @@
17 * 17 *
18 ****************************************************************************/ 18 ****************************************************************************/
19 19
20#include <stddef.h> 20#include <stdlib.h>
21#include "uisdl.h"
21#include "kernel.h" 22#include "kernel.h"
23#include "thread-sdl.h"
22#include "thread.h" 24#include "thread.h"
23#include "debug.h" 25#include "debug.h"
24 26
27/* (Daniel 2002-10-31) Mingw32 requires this errno variable to be present.
28 I'm not quite sure why and I don't know if this breaks the MSVC compile.
29 If it does, we should put this within #ifdef __MINGW32__ */
30int errno;
31
25static void (*tick_funcs[MAX_NUM_TICK_TASKS])(void); 32static void (*tick_funcs[MAX_NUM_TICK_TASKS])(void);
26 33
27int set_irq_level (int level) 34int set_irq_level (int level)
@@ -148,6 +155,7 @@ int tick_remove_task(void (*f)(void))
148 return -1; 155 return -1;
149} 156}
150 157
158/* TODO: Implement mutexes for win32 */
151void mutex_init(struct mutex *m) 159void mutex_init(struct mutex *m)
152{ 160{
153 (void)m; 161 (void)m;
@@ -162,4 +170,3 @@ void mutex_unlock(struct mutex *m)
162{ 170{
163 (void)m; 171 (void)m;
164} 172}
165
diff --git a/uisimulator/sdl/lcd-sdl.c b/uisimulator/sdl/lcd-sdl.c
new file mode 100644
index 0000000000..758ab90ef9
--- /dev/null
+++ b/uisimulator/sdl/lcd-sdl.c
@@ -0,0 +1,291 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 Dan Everton
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#include "uisdl.h"
21#include "lcd.h"
22#include "lcd-playersim.h"
23
24SDL_Surface* lcd_surface;
25
26#if LCD_DEPTH == 16
27#else
28SDL_Color lcd_palette[(1<<LCD_DEPTH)];
29SDL_Color lcd_color_zero = {UI_LCD_BGCOLORLIGHT, 0};
30SDL_Color lcd_color_max = {0, 0, 0, 0};
31
32#endif
33
34#ifdef HAVE_LCD_BITMAP
35
36#ifdef HAVE_REMOTE_LCD
37SDL_Surface *remote_surface;
38SDL_Color remote_palette[(1<<LCD_REMOTE_DEPTH)];
39SDL_Color remote_color_zero = {UI_REMOTE_BGCOLORLIGHT, 0};
40SDL_Color remote_color_max = {0, 0, 0, 0};
41
42#endif
43
44void lcd_update (void)
45{
46 /* update a full screen rect */
47 lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT);
48}
49
50void lcd_update_rect(int x_start, int y_start, int width, int height)
51{
52 int x, y;
53 int xmax, ymax;
54
55 ymax = y_start + height;
56 xmax = x_start + width;
57
58 if(xmax > LCD_WIDTH)
59 xmax = LCD_WIDTH;
60 if(ymax >= LCD_HEIGHT)
61 ymax = LCD_HEIGHT;
62
63 SDL_LockSurface(lcd_surface);
64
65 int bpp = lcd_surface->format->BytesPerPixel;
66
67 for (x = x_start; x < xmax; x++)
68 {
69 for (y = y_start; y < ymax; y++)
70 {
71 Uint8 *p = (Uint8 *)lcd_surface->pixels + y * lcd_surface->pitch + x * bpp;
72
73#if LCD_DEPTH == 1
74 *(Uint32 *)p = ((lcd_framebuffer[y/8][x] >> (y & 7)) & 1);
75#elif LCD_DEPTH == 2
76 *(Uint32 *)p = ((lcd_framebuffer[y/4][x] >> (2 * (y & 3))) & 3);
77#elif LCD_DEPTH == 16
78#if LCD_PIXELFORMAT == RGB565SWAPPED
79 unsigned bits = lcd_framebuffer[y][x];
80 *(Uint32 *)p = (bits >> 8) | (bits << 8);
81#else
82 *(Uint32 *)p = lcd_framebuffer[y][x];
83#endif
84#endif
85 }
86 }
87
88 SDL_UnlockSurface(lcd_surface);
89
90 SDL_Rect src = {x_start, y_start, xmax, ymax};
91 SDL_Rect dest = {UI_LCD_POSX + x_start, UI_LCD_POSY + y_start, xmax, ymax};
92
93
94 SDL_BlitSurface(lcd_surface, &src, gui_surface, &dest);
95 SDL_UpdateRect(gui_surface, dest.x, dest.y, dest.w, dest.h);
96 SDL_Flip(gui_surface);
97
98}
99
100#ifdef HAVE_REMOTE_LCD
101
102extern unsigned char lcd_remote_framebuffer[LCD_REMOTE_HEIGHT/8][LCD_REMOTE_WIDTH];
103
104void lcd_remote_update (void)
105{
106 lcd_remote_update_rect(0, 0, LCD_REMOTE_WIDTH, LCD_REMOTE_HEIGHT);
107}
108
109void lcd_remote_update_rect(int x_start, int y_start,
110 int width, int height)
111{
112 int x, y;
113 int xmax, ymax;
114
115 ymax = y_start + height;
116 xmax = x_start + width;
117
118 if(xmax > LCD_REMOTE_WIDTH)
119 xmax = LCD_REMOTE_WIDTH;
120 if(ymax >= LCD_REMOTE_HEIGHT)
121 ymax = LCD_REMOTE_HEIGHT;
122
123 SDL_LockSurface(remote_surface);
124
125 int bpp = remote_surface->format->BytesPerPixel;
126
127 for (x = x_start; x < xmax; x++)
128 for (y = y_start; y < ymax; y++)
129 {
130 Uint8 *p = (Uint8 *)remote_surface->pixels + y * remote_surface->pitch + x * bpp;
131
132 *(Uint32 *)p = ((lcd_remote_framebuffer[y/8][x] >> (y & 7)) & 1);
133 }
134
135 SDL_UnlockSurface(remote_surface);
136
137 SDL_Rect src = {x_start, y_start, xmax, ymax};
138 SDL_Rect dest = {UI_REMOTE_POSX + x_start, UI_REMOTE_POSY + y_start, xmax, ymax};
139
140 SDL_BlitSurface(remote_surface, &src, gui_surface, &dest);
141 SDL_UpdateRect(gui_surface, dest.x, dest.y, dest.w, dest.h);
142 SDL_Flip(gui_surface);
143
144}
145
146#endif /* HAVE_REMOTE_LCD */
147#endif /* HAVE_LCD_BITMAP */
148
149#ifdef HAVE_LCD_CHARCELLS
150/* Defined in lcd-playersim.c */
151extern void lcd_print_char(int x, int y);
152extern bool lcd_display_redraw;
153extern unsigned char hardware_buffer_lcd[11][2];
154static unsigned char lcd_buffer_copy[11][2];
155
156void lcd_update(void)
157{
158 int x, y;
159 bool changed = false;
160 SDL_Rect dest = {UI_LCD_POSX, UI_LCD_POSY, UI_LCD_WIDTH, UI_LCD_HEIGHT};
161
162 for (y = 0; y < 2; y++)
163 {
164 for (x = 0; x < 11; x++)
165 {
166 if (lcd_display_redraw ||
167 lcd_buffer_copy[x][y] != hardware_buffer_lcd[x][y])
168 {
169 lcd_buffer_copy[x][y] = hardware_buffer_lcd[x][y];
170 lcd_print_char(x, y);
171 changed = true;
172 }
173 }
174 }
175 if (changed)
176 {
177 SDL_BlitSurface(lcd_surface, NULL, gui_surface, &dest);
178 SDL_UpdateRect(gui_surface, dest.x, dest.y, dest.w, dest.h);
179 SDL_Flip(gui_surface);
180 }
181 lcd_display_redraw = false;
182}
183
184void drawdots(int color, struct coordinate *points, int count)
185{
186 int bpp = lcd_surface->format->BytesPerPixel;
187
188 SDL_LockSurface(lcd_surface);
189
190 while (count--)
191 {
192 Uint8 *p = (Uint8 *)lcd_surface->pixels + (points[count].y) * lcd_surface->pitch + (points[count].x) * bpp;
193
194 *p = color;
195 }
196
197 SDL_UnlockSurface(lcd_surface);
198}
199
200void drawrectangles(int color, struct rectangle *points, int count)
201{
202 int bpp = lcd_surface->format->BytesPerPixel;
203
204 SDL_LockSurface(lcd_surface);
205
206 while (count--)
207 {
208 int x;
209 int y;
210 int ix;
211 int iy;
212
213 for (x = points[count].x, ix = 0; ix < points[count].width; x++, ix++)
214 {
215 for (y = points[count].y, iy = 0; iy < points[count].height; y++, iy++)
216 {
217 Uint8 *p = (Uint8 *)lcd_surface->pixels + y * lcd_surface->pitch + x * bpp;
218
219 *p = color;
220 }
221 }
222 }
223
224 SDL_UnlockSurface(lcd_surface);
225}
226#endif /* HAVE_LCD_CHARCELLS */
227
228#if LCD_DEPTH <= 8
229/* set a range of bitmap indices to a gradient from startcolour to endcolour */
230void lcdcolors(int index, int count, SDL_Color *start, SDL_Color *end)
231{
232 int i;
233
234 count--;
235 for (i = 0; i <= count; i++)
236 {
237 lcd_palette[i+index].r = start->r
238 + (end->r - start->r) * i / count;
239 lcd_palette[i+index].g = start->g
240 + (end->g - start->g) * i / count;
241 lcd_palette[i+index].b = start->b
242 + (end->b - start->b) * i / count;
243 }
244
245 SDL_SetPalette(lcd_surface, SDL_LOGPAL|SDL_PHYSPAL, lcd_palette, index, count);
246}
247#endif
248
249#ifdef HAVE_REMOTE_LCD
250/* set a range of bitmap indices to a gradient from startcolour to endcolour */
251void lcdremotecolors(int index, int count, SDL_Color *start, SDL_Color *end)
252{
253 int i;
254
255 count--;
256 for (i = 0; i <= count; i++)
257 {
258 remote_palette[i+index].r = start->r
259 + (end->r - start->r) * i / count;
260 remote_palette[i+index].g = start->g
261 + (end->g - start->g) * i / count;
262 remote_palette[i+index].b = start->b
263 + (end->b - start->b) * i / count;
264 }
265
266 SDL_SetPalette(remote_surface, SDL_LOGPAL|SDL_PHYSPAL, remote_palette, index, count);
267}
268#endif
269
270/* initialise simulator lcd driver */
271void simlcdinit(void)
272{
273#if LCD_DEPTH == 16
274 lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, LCD_WIDTH, LCD_HEIGHT, 16,
275 0, 0, 0, 0);
276#else
277 lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, LCD_WIDTH, LCD_HEIGHT, 8,
278 0, 0, 0, 0);
279#endif
280
281#if LCD_DEPTH <= 8
282 lcdcolors(0, (1<<LCD_DEPTH), &lcd_color_zero, &lcd_color_max);
283#endif
284
285#ifdef HAVE_REMOTE_LCD
286 remote_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, LCD_REMOTE_WIDTH, LCD_REMOTE_HEIGHT, 8,
287 0, 0, 0, 0);
288
289 lcdremotecolors(0, (1<<LCD_REMOTE_DEPTH), &remote_color_zero, &remote_color_max);
290#endif
291}
diff --git a/uisimulator/sdl/lcd-sdl.h b/uisimulator/sdl/lcd-sdl.h
new file mode 100644
index 0000000000..312ae0d01f
--- /dev/null
+++ b/uisimulator/sdl/lcd-sdl.h
@@ -0,0 +1,39 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 Dan Everton
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#ifndef __LCDSDL_H__
21#define __LCDSDL_H__
22
23#include "uisdl.h"
24#include "lcd.h"
25
26extern SDL_Surface* lcd_surface;
27#if LCD_DEPTH <= 8
28extern SDL_Color lcd_palette[(1<<LCD_DEPTH)];
29#endif
30
31#ifdef HAVE_REMOTE_LCD
32extern SDL_Surface* remote_surface;
33extern SDL_Color remote_palette[(1<<LCD_REMOTE_DEPTH)];
34#endif
35
36void simlcdinit(void);
37
38#endif // #ifndef __LCDSDL_H__
39
diff --git a/uisimulator/sdl/lcd-x11.c b/uisimulator/sdl/lcd-x11.c
deleted file mode 100644
index c30d857d8c..0000000000
--- a/uisimulator/sdl/lcd-x11.c
+++ /dev/null
@@ -1,212 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Daniel Stenberg <daniel@haxx.se>
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#include <stdio.h>
21#include <string.h>
22#include <stdarg.h>
23#include <stdlib.h>
24#include <ctype.h>
25#include <sys/types.h>
26#include <sys/stat.h>
27#include <fcntl.h>
28
29#include <errno.h>
30#include <ctype.h>
31#include <time.h>
32
33#include "screenhack.h"
34#include "system.h"
35#include "config.h"
36
37/*
38 * Specific implementations for X11, using the generic LCD API and data.
39 */
40
41#include "lcd-x11.h"
42#include "lcd-playersim.h"
43
44#include <SDL.h>
45
46extern SDL_Surface *surface;
47
48extern void screen_resized(int width, int height);
49extern bool lcd_display_redraw;
50
51#ifdef HAVE_LCD_BITMAP
52#if LCD_DEPTH==16
53fb_data lcd_framebuffer_copy[LCD_HEIGHT][LCD_WIDTH*2];
54#else
55fb_data lcd_framebuffer_copy[LCD_HEIGHT][LCD_WIDTH];
56#endif
57
58void lcd_update (void)
59{
60 /* update a full screen rect */
61 lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT);
62}
63
64void lcd_update_rect(int x_start, int y_start,
65 int width, int height)
66{
67 int x;
68 int y;
69 int p=0;
70 int xmax;
71 int ymax;
72 int colors[LCD_WIDTH * LCD_HEIGHT];
73 struct coordinate points[LCD_WIDTH * LCD_HEIGHT];
74
75#if 0
76 fprintf(stderr, "%04d: lcd_update_rect(%d, %d, %d, %d)\n",
77 counter++, x_start, y_start, width, height);
78#endif
79 ymax = y_start + height;
80 xmax = x_start + width;
81
82 if(xmax > LCD_WIDTH)
83 xmax = LCD_WIDTH;
84 if(ymax >= LCD_HEIGHT)
85 ymax = LCD_HEIGHT;
86
87 for (x = x_start; x < xmax; x++)
88 for (y = y_start; y < ymax; y++)
89 {
90#if LCD_DEPTH == 1
91 Uint32 sdl_white = SDL_MapRGB(surface->format, 255, 255, 255);
92 Uint32 sdl_black = SDL_MapRGB(surface->format, 0, 0, 0);
93 points[p].x = x + MARGIN_X;
94 points[p].y = y + MARGIN_Y;
95 colors[p] = ((lcd_framebuffer[y/8][x] >> (y & 7)) & 1) ? sdl_black : sdl_white;
96#elif LCD_DEPTH == 2
97 unsigned gray = ((lcd_framebuffer[y/4][x] >> (2 * (y & 3))) & 3) * 85;
98 points[p].x = x + MARGIN_X;
99 points[p].y = y + MARGIN_Y;
100 colors[p] = SDL_MapRGB(surface->format, 255-gray, 255-gray, 255-gray);
101#elif LCD_DEPTH == 16
102#if LCD_PIXELFORMAT == RGB565SWAPPED
103 unsigned short pixel = swap16(lcd_framebuffer[y][x]);
104 unsigned r = ((pixel >> 11) & 0x1f) << 3;
105 unsigned g = ((pixel >> 5) & 0x3f) << 2;
106 unsigned b = (pixel & 0x1f) << 3;
107 points[p].x = x + MARGIN_X;
108 points[p].y = y + MARGIN_Y;
109 colors[p] = SDL_MapRGB(surface->format, r, g, b);
110#else
111 unsigned r = ((lcd_framebuffer[y][x] >> 11) & 0x1f) << 3;
112 unsigned g = ((lcd_framebuffer[y][x] >> 5) & 0x3f) << 2;
113 unsigned b = ((lcd_framebuffer[y][x]) & 0x1f) << 3;
114 points[p].x = x + MARGIN_X;
115 points[p].y = y + MARGIN_Y;
116 colors[p] = SDL_MapRGB(surface->format, r, g, b);
117#endif
118#endif
119 p++;
120 }
121
122 dots(colors, &points[0], p);
123 /* printf("lcd_update_rect: Draws %d pixels, clears %d pixels\n", p, cp);*/
124 SDL_UpdateRect(surface, 0, 0, 0, 0);
125 lcd_display_redraw=false;
126}
127
128#ifdef LCD_REMOTE_HEIGHT
129extern unsigned char lcd_remote_framebuffer[LCD_REMOTE_HEIGHT/8][LCD_REMOTE_WIDTH];
130unsigned char lcd_remote_framebuffer_copy[LCD_REMOTE_HEIGHT/8][LCD_REMOTE_WIDTH];
131
132#define REMOTE_START_Y (LCD_HEIGHT + 2*MARGIN_Y)
133
134void lcd_remote_update (void)
135{
136 lcd_remote_update_rect(0, 0, LCD_REMOTE_WIDTH, LCD_REMOTE_HEIGHT);
137}
138
139void lcd_remote_update_rect(int x_start, int y_start,
140 int width, int height)
141{
142 int x;
143 int y;
144 int p=0;
145 int xmax;
146 int ymax;
147 struct coordinate points[LCD_REMOTE_WIDTH * LCD_REMOTE_HEIGHT];
148 int colors[LCD_REMOTE_WIDTH * LCD_REMOTE_HEIGHT];
149 Uint32 sdl_white = SDL_MapRGB(surface->format, 255, 255, 255);
150 Uint32 sdl_black = SDL_MapRGB(surface->format, 0, 0, 0);
151
152#if 0
153 fprintf(stderr, "%04d: lcd_update_rect(%d, %d, %d, %d)\n",
154 counter++, x_start, y_start, width, height);
155#endif
156 ymax = y_start + height;
157 xmax = x_start + width;
158
159 if(xmax > LCD_REMOTE_WIDTH)
160 xmax = LCD_REMOTE_WIDTH;
161 if(ymax >= LCD_REMOTE_HEIGHT)
162 ymax = LCD_REMOTE_HEIGHT;
163
164 for (x = x_start; x < xmax; x++)
165 for (y = y_start; y < ymax; y++) {
166 colors[p] = ((lcd_remote_framebuffer[y/8][x] >> (y & 7)) & 1) ? sdl_black : sdl_white;
167 points[p].x = x + MARGIN_X;
168 points[p].y = y + MARGIN_Y + REMOTE_START_Y;
169 p++;
170 }
171
172 dots(colors, &points[0], p);
173 /* printf("lcd_update_rect: Draws %d pixels, clears %d pixels\n", p, cp);*/
174 SDL_UpdateRect(surface, 0, 0, 0, 0);
175 lcd_display_redraw=false;
176}
177
178
179#endif
180
181#endif
182#ifdef HAVE_LCD_CHARCELLS
183
184/* Defined in lcd-playersim.c */
185extern void lcd_print_char(int x, int y);
186extern unsigned char lcd_buffer[2][11];
187
188extern unsigned char hardware_buffer_lcd[11][2];
189static unsigned char lcd_buffer_copy[11][2];
190
191void lcd_update (void)
192{
193 bool changed=false;
194 int x, y;
195 for (y=0; y<2; y++) {
196 for (x=0; x<11; x++) {
197 if (lcd_display_redraw ||
198 lcd_buffer_copy[x][y] != hardware_buffer_lcd[x][y]) {
199 lcd_buffer_copy[x][y] = hardware_buffer_lcd[x][y];
200 lcd_print_char(x, y);
201 changed=true;
202 }
203 }
204 }
205 if (changed)
206 {
207 SDL_UpdateRect(surface, 0, 0, 0, 0);
208 }
209 lcd_display_redraw=false;
210}
211
212#endif
diff --git a/uisimulator/sdl/screenhack.c b/uisimulator/sdl/screenhack.c
deleted file mode 100644
index ad138c282e..0000000000
--- a/uisimulator/sdl/screenhack.c
+++ /dev/null
@@ -1,232 +0,0 @@
1/* xscreensaver, Copyright (c) 1992, 1995, 1997, 1998
2 * Jamie Zawinski <jwz@jwz.org>
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation. No representations are made about the suitability of this
9 * software for any purpose. It is provided "as is" without express or
10 * implied warranty.
11 *
12 * And remember: X Windows is to graphics hacking as roman numerals are to
13 * the square root of pi.
14 */
15
16/* This file contains simple code to open a window or draw on the root.
17 The idea being that, when writing a graphics hack, you can just link
18 with this .o to get all of the uninteresting junk out of the way.
19
20 - create a procedure `screenhack(dpy, window)'
21
22 - create a variable `char *progclass' which names this program's
23 resource class.
24
25 - create a variable `char defaults []' for the default resources, and
26 null-terminate it.
27
28 - create a variable `XrmOptionDescRec options[]' for the command-line,
29 and null-terminate it.
30
31 And that's it...
32 */
33
34#include <stdio.h>
35#include <string.h>
36#include <SDL.h>
37#include "lcd-x11.h"
38#include "screenhack.h"
39#include "version.h"
40
41#include "debug.h"
42#include "config.h"
43
44#ifndef isupper
45# define isupper(c) ((c) >= 'A' && (c) <= 'Z')
46#endif
47#ifndef _tolower
48# define _tolower(c) ((c) - 'A' + 'a')
49#endif
50
51#define KEYBOARD_GENERIC \
52 "Keyboard Rockbox\n" \
53 "-------- ------------\n" \
54 "4, Left LEFT\n" \
55 "6, Right RIGHT\n"
56
57#if CONFIG_KEYPAD == PLAYER_PAD
58#define KEYBOARD_SPECIFIC \
59 "8, Up PLAY\n" \
60 "2, Down STOP\n" \
61 "+, Q ON\n" \
62 "., INS MENU\n"
63
64#elif CONFIG_KEYPAD == RECORDER_PAD
65#define KEYBOARD_SPECIFIC \
66 "8, Up UP\n" \
67 "2, Down DOWN\n" \
68 "5, Space PLAY\n" \
69 "+, Q ON\n" \
70 "Enter, A OFF\n" \
71 "/, (F1) F1\n" \
72 "*, (F2) F2\n" \
73 "-, (F3) F3\n"
74
75#elif CONFIG_KEYPAD == ONDIO_PAD
76#define KEYBOARD_SPECIFIC \
77 "8, Up UP\n" \
78 "2, Down DOWN\n" \
79 "., INS MENU\n" \
80 "Enter, A OFF\n"
81
82#elif CONFIG_KEYPAD == IRIVER_H100_PAD
83#define KEYBOARD_SPECIFIC \
84 "8, Up UP\n" \
85 "2, Down DOWN\n" \
86 "5, Space SELECT\n" \
87 "+, Q ON\n" \
88 "Enter, A OFF\n" \
89 "., INS MODE\n" \
90 "/, (F1) RECORD\n"
91
92#elif CONFIG_KEYPAD == IRIVER_H300_PAD
93#define KEYBOARD_SPECIFIC \
94 "8, Up UP\n" \
95 "2, Down DOWN\n" \
96 "4, Left LEFT\n" \
97 "6, Right RIGHT\n" \
98 "5, Space SELECT\n" \
99 "+, Q ON\n" \
100 "Enter, A OFF\n" \
101 "., INS MODE\n" \
102 "/, (F1) RECORD\n"
103
104#elif CONFIG_KEYPAD == GMINI100_PAD
105#define KEYBOARD_SPECIFIC \
106 "8, Up UP\n" \
107 "2, Down DOWN\n" \
108 "5, Space PLAY\n" \
109 "+, Q ON\n" \
110 "Enter, A OFF\n" \
111 "., INS MENU\n"
112
113#elif (CONFIG_KEYPAD == IPOD_4G_PAD)
114#define KEYBOARD_SPECIFIC \
115 "[not written yet]"
116
117#elif (CONFIG_KEYPAD == IAUDIO_X5_PAD)
118#define KEYBOARD_SPECIFIC \
119 "[not written yet]"
120
121#endif
122
123
124SDL_Surface *surface;
125
126char having_new_lcd = true;
127
128extern int display_zoom;
129
130/* Dead-trivial event handling.
131 */
132int screenhack_handle_event(SDL_Event *event, bool *release)
133{
134 int key = 0;
135
136 *release = false;
137
138 switch (event->type) {
139 case SDL_KEYDOWN:
140 {
141 key = event->key.keysym.sym;
142 *release = false;
143 }
144 break;
145 case SDL_KEYUP:
146 {
147 key = event->key.keysym.sym;
148 *release = true;
149 }
150 break;
151 case SDL_QUIT:
152 {
153 SDL_Quit();
154 exit(0);
155 }
156 break;
157 default:
158 break;
159 }
160
161 return key;
162}
163
164int screenhack_handle_events(bool *release)
165{
166 int key = 0;
167 SDL_Event event;
168
169 if (SDL_PollEvent(&event)) {
170 key = screenhack_handle_event(&event, release);
171 }
172
173 return key;
174}
175
176
177int main (int argc, char **argv)
178{
179 int window_width;
180 int window_height;
181
182 if (argc > 1)
183 {
184 int x;
185 for (x=1; x<argc; x++) {
186 if (!strcmp("--old_lcd", argv[x])) {
187 having_new_lcd=false;
188 printf("Using old LCD layout.\n");
189 } else if (!strcmp("--zoom", argv[x])) {
190 if (++x < argc) {
191 display_zoom=atoi(argv[x]);
192 printf("Window zoom is %d\n", display_zoom);
193 if (display_zoom < 1 || display_zoom > 5) {
194 printf("fatal: --zoom argument must be between 1 and 5\n");
195 exit(0);
196 }
197 } else {
198 printf("fatal: --zoom requires an integer argument\n");
199 exit(0);
200 }
201 } else {
202 printf("rockboxui\n");
203 printf("Arguments:\n");
204 printf(" --old_lcd \t [Player] simulate old playermodel (ROM version<4.51)\n");
205 printf(" --zoom [1-5]\t window zoom\n");
206 printf(KEYBOARD_GENERIC KEYBOARD_SPECIFIC);
207 exit(0);
208 }
209 }
210 }
211
212 window_width = (LCD_WIDTH + 2*MARGIN_X) * display_zoom;
213 window_height = (LCD_HEIGHT + 2*MARGIN_Y) * display_zoom;
214#ifdef LCD_REMOTE_HEIGHT
215 window_height += (LCD_REMOTE_HEIGHT + 2*MARGIN_Y) * display_zoom;
216#endif
217
218 if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO)) {
219 fprintf(stderr, "fatal: %s", SDL_GetError());
220 exit(-1);
221 }
222
223 atexit(SDL_Quit);
224
225 if ((surface = SDL_SetVideoMode(window_width, window_height, 24, 0)) == NULL) {
226 fprintf(stderr, "fatal: %s", SDL_GetError());
227 exit(-1);
228 }
229
230 screenhack(); /* doesn't return */
231 return 0;
232}
diff --git a/uisimulator/sdl/screenhack.h b/uisimulator/sdl/screenhack.h
deleted file mode 100644
index 4c7a8307a4..0000000000
--- a/uisimulator/sdl/screenhack.h
+++ /dev/null
@@ -1,33 +0,0 @@
1/* xscreensaver, Copyright (c) 1992-1997 Jamie Zawinski <jwz@jwz.org>
2 *
3 * Permission to use, copy, modify, distribute, and sell this software and its
4 * documentation for any purpose is hereby granted without fee, provided that
5 * the above copyright notice appear in all copies and that both that
6 * copyright notice and this permission notice appear in supporting
7 * documentation. No representations are made about the suitability of this
8 * software for any purpose. It is provided "as is" without express or
9 * implied warranty.
10 */
11
12#ifndef __SCREENHACK_H__
13#define __SCREENHACK_H__
14
15#include <stdlib.h>
16#include <stdbool.h>
17
18#ifdef __hpux
19 /* Which of the ten billion standards does values.h belong to?
20 What systems always have it? */
21# include <values.h>
22#endif
23
24#include <stdio.h>
25#include <SDL.h>
26
27extern void screenhack();
28extern int screenhack_handle_event(SDL_Event*, bool *);
29extern int screenhack_handle_events(bool *);
30extern void screen_redraw();
31extern void screen_resized();
32
33#endif /* __SCREENHACK_H__ */
diff --git a/uisimulator/sdl/sound.c b/uisimulator/sdl/sound.c
index 388b188448..66df6961b2 100644
--- a/uisimulator/sdl/sound.c
+++ b/uisimulator/sdl/sound.c
@@ -21,24 +21,15 @@
21 21
22#ifdef ROCKBOX_HAS_SIMSOUND /* play sound in sim enabled */ 22#ifdef ROCKBOX_HAS_SIMSOUND /* play sound in sim enabled */
23 23
24#include <stdio.h> 24#include <memory.h>
25#include <stdlib.h> 25#include <stdlib.h>
26#include <unistd.h> 26#include "uisdl.h"
27#include <fcntl.h>
28#include <string.h>
29#include <SDL.h>
30
31#include "sound.h" 27#include "sound.h"
32 28
33//static Uint8 *audio_chunk;
34static int audio_len; 29static int audio_len;
35static char *audio_pos; 30static char *audio_pos;
36SDL_sem* sem; 31SDL_sem* sem;
37 32
38/* The audio function callback takes the following parameters:
39 stream: A pointer to the audio buffer to be filled
40 len: The length (in bytes) of the audio buffer
41*/
42void mixaudio(void *udata, Uint8 *stream, int len) 33void mixaudio(void *udata, Uint8 *stream, int len)
43{ 34{
44 (void)udata; 35 (void)udata;
@@ -59,8 +50,6 @@ void mixaudio(void *udata, Uint8 *stream, int len)
59 } 50 }
60} 51}
61 52
62
63
64int sim_sound_init(void) 53int sim_sound_init(void)
65{ 54{
66 SDL_AudioSpec fmt; 55 SDL_AudioSpec fmt;
@@ -80,15 +69,12 @@ int sim_sound_init(void)
80 fprintf(stderr, "Unable to open audio: %s\n", SDL_GetError()); 69 fprintf(stderr, "Unable to open audio: %s\n", SDL_GetError());
81 return -1; 70 return -1;
82 } 71 }
72
83 SDL_PauseAudio(0); 73 SDL_PauseAudio(0);
84 return 0; 74 return 0;
85
86 //...
87
88 //SDL_CloseAudio();
89} 75}
90 76
91int sound_playback_thread(void* p) 77int sound_playback_thread(void *p)
92{ 78{
93 int sndret = sim_sound_init(); 79 int sndret = sim_sound_init();
94 unsigned char *buf; 80 unsigned char *buf;
@@ -97,12 +83,12 @@ int sound_playback_thread(void* p)
97 (void)p; 83 (void)p;
98 84
99 while(sndret) 85 while(sndret)
100 sleep(100000); /* wait forever, can't play sound! */ 86 SDL_Delay(100000); /* wait forever, can't play sound! */
101 87
102 do { 88 do {
103 while(!sound_get_pcm) 89 while(!sound_get_pcm)
104 /* TODO: fix a fine thread-synch mechanism here */ 90 /* TODO: fix a fine thread-synch mechanism here */
105 usleep(10000); 91 SDL_Delay(100);
106 do { 92 do {
107 sound_get_pcm(&buf, &size); 93 sound_get_pcm(&buf, &size);
108 if(!size) { 94 if(!size) {
@@ -111,11 +97,13 @@ int sound_playback_thread(void* p)
111 } 97 }
112 audio_pos = buf; // TODO: is this safe? 98 audio_pos = buf; // TODO: is this safe?
113 audio_len = size; 99 audio_len = size;
114 //printf("len: %i\n",audio_len); 100
115 if(SDL_SemWait(sem)) 101 if(SDL_SemWait(sem))
116 fprintf(stderr,"Couldn't wait: %s",SDL_GetError()); 102 fprintf(stderr,"Couldn't wait: %s",SDL_GetError());
117 } while(size); 103 } while(size);
118 } while(1); 104 } while(1);
105
119} 106}
120 107
121#endif /* ROCKBOX_HAS_SIMSOUND */ 108#endif /* ROCKBOX_HAS_SIMSOUND */
109
diff --git a/uisimulator/sdl/sprintf.h b/uisimulator/sdl/sprintf.h
index 64a22f3c6e..24e1d4e352 100644
--- a/uisimulator/sdl/sprintf.h
+++ b/uisimulator/sdl/sprintf.h
@@ -1,12 +1,36 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Felix Arends
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#ifndef __SPRINTF_H__
21#define __SPRINTF_H__
22
23#include <stddef.h>
1#include <stdarg.h> 24#include <stdarg.h>
2#include <stdio.h> 25#include <stdio.h>
3 26
4int rockbox_snprintf (char *buf, size_t size, const char *fmt, ...); 27int snprintf (char *buf, size_t size, const char *fmt, ...);
5int rockbox_vsnprintf (char *buf, int size, const char *fmt, va_list ap); 28char *strtok_r (char *, const char *, char **);
29
6int rockbox_fprintf (int fd, const char *fmt, ...); 30int rockbox_fprintf (int fd, const char *fmt, ...);
31#define fprintf rockbox_fprintf
7 32
8#ifndef NO_REDEFINES_PLEASE 33int rockbox_vsnprintf (char *buf, int size, const char *fmt, va_list ap);
9#define snprintf rockbox_snprintf
10#define vsnprintf rockbox_vsnprintf 34#define vsnprintf rockbox_vsnprintf
11#define fprintf rockbox_fprintf 35
12#endif 36#endif /* __SPRINTF_H__ */
diff --git a/uisimulator/sdl/thread-sdl.c b/uisimulator/sdl/thread-sdl.c
new file mode 100644
index 0000000000..41a60c9bc5
--- /dev/null
+++ b/uisimulator/sdl/thread-sdl.c
@@ -0,0 +1,78 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 Dan Everton
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#include <time.h>
21#include <SDL.h>
22#include <SDL_thread.h>
23#include <stdlib.h>
24#include "thread-sdl.h"
25#include "kernel.h"
26#include "debug.h"
27
28SDL_Thread *threads[256];
29int threadCount = 0;
30long current_tick = 0;
31SDL_mutex *m;
32
33void yield(void)
34{
35 SDL_mutexV(m);
36 SDL_Delay(1);
37 SDL_mutexP(m);
38}
39
40void sim_sleep(int ticks)
41{
42 SDL_mutexV(m);
43 SDL_Delay((1000/HZ) * ticks);
44 SDL_mutexP(m);
45}
46
47int runthread(void *data)
48{
49 SDL_mutexV(m);
50 ((void(*)())data) ();
51 SDL_mutexV(m);
52 return 0;
53}
54
55int create_thread(void (*fp)(void), void* sp, int stk_size)
56{
57 /** Avoid compiler warnings */
58 (void)sp;
59 (void)stk_size;
60
61 if (threadCount == 256) {
62 return -1;
63 }
64
65 threads[threadCount++] = SDL_CreateThread(runthread, fp);
66
67 return 0;
68}
69
70void init_threads(void)
71{
72 m = SDL_CreateMutex();
73
74 if (SDL_mutexP(m) == -1) {
75 fprintf(stderr, "Couldn't lock mutex\n");
76 exit(-1);
77 }
78}
diff --git a/uisimulator/sdl/lcd-x11.h b/uisimulator/sdl/thread-sdl.h
index 07911b2530..a661f582a4 100644
--- a/uisimulator/sdl/lcd-x11.h
+++ b/uisimulator/sdl/thread-sdl.h
@@ -1,13 +1,13 @@
1/*************************************************************************** 1/***************************************************************************
2 * __________ __ ___. 2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/ 7 * \/ \/ \/ \/ \/
8 * $Id$ 8 * $Id$
9 * 9 *
10 * Copyright (C) 2002 by Daniel Stenberg <daniel@haxx.se> 10 * Copyright (C) 2006 Dan Everton
11 * 11 *
12 * All files in this archive are subject to the GNU General Public License. 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. 13 * See the file COPYING in the source tree root for full license agreement.
@@ -17,10 +17,7 @@
17 * 17 *
18 ****************************************************************************/ 18 ****************************************************************************/
19 19
20#define MARGIN_X 3 20extern SDL_Thread* threads[256];
21#define MARGIN_Y 3 21extern int threadCount;
22 22extern SDL_mutex* mutex;
23/* include the "real" lcd.h file here */
24#include <lcd.h>
25
26 23
diff --git a/uisimulator/sdl/uisdl.c b/uisimulator/sdl/uisdl.c
index e17a925313..b55e3ee8ff 100644
--- a/uisimulator/sdl/uisdl.c
+++ b/uisimulator/sdl/uisdl.c
@@ -7,7 +7,7 @@
7 * \/ \/ \/ \/ \/ 7 * \/ \/ \/ \/ \/
8 * $Id$ 8 * $Id$
9 * 9 *
10 * Copyright (C) 2002 by Daniel Stenberg <daniel@haxx.se> 10 * Copyright (C) 2006 by Daniel Everton <dan@iocaine.org>
11 * 11 *
12 * All files in this archive are subject to the GNU General Public License. 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. 13 * See the file COPYING in the source tree root for full license agreement.
@@ -16,211 +16,170 @@
16 * KIND, either express or implied. 16 * KIND, either express or implied.
17 * 17 *
18 ****************************************************************************/ 18 ****************************************************************************/
19#include <stdio.h>
20#include <string.h>
21#include <stdarg.h>
22#include <stdlib.h>
23#include <ctype.h>
24#include <sys/types.h>
25#include <sys/stat.h>
26#include <fcntl.h>
27
28#include <errno.h>
29#include <ctype.h>
30#include <time.h>
31
32#include <SDL.h>
33
34#include "config.h"
35#include "screenhack.h"
36
37#include "version.h"
38
39#include "lcd-x11.h"
40#include "lcd-playersim.h"
41
42#define MAX(x,y) ((x)>(y)?(x):(y))
43#define MIN(x,y) ((x)<(y)?(x):(y))
44
45#define PROGNAME "rockboxui"
46
47/* -- -- */
48
49extern SDL_Surface *surface;
50 19
51int display_zoom=2; 20#include <stdlib.h>
21#include "autoconf.h"
22#include "uisdl.h"
23#include "button.h"
24#include "thread.h"
25#include "thread-sdl.h"
26#include "kernel.h"
27#include "sound.h"
28
29// extern functions
30extern void app_main (void *); // mod entry point
31extern void new_key(int key);
32extern void sim_tick_tasks(void);
33
34void button_event(int key, bool pressed);
35
36SDL_Surface *gui_surface;
37
38SDL_Thread *gui_thread;
39SDL_TimerID tick_timer_id;
40#ifdef ROCKBOX_HAS_SIMSOUND
41SDL_Thread *sound_thread;
42#endif
52 43
53bool lcd_display_redraw=true; 44bool lcd_display_redraw=true; // Used for player simulator
45char having_new_lcd=true; // Used for player simulator
54 46
55char *progclass = "rockboxui"; 47long start_tick;
56 48
57void init_window () 49Uint32 tick_timer(Uint32 interval, void *param)
58{ 50{
59 /* stub */ 51 long new_tick;
60}
61 52
62/* used for the player sim */ 53 (void) interval;
63void drawdots(int color, struct coordinate *points, int count) 54 (void) param;
64{
65 SDL_Rect rect;
66 55
67 while (count--) { 56 new_tick = (SDL_GetTicks() - start_tick) * HZ / 1000;
68 rect.x = points[count].x * display_zoom;
69 rect.y = points[count].y * display_zoom;
70 rect.w = display_zoom;
71 rect.h = display_zoom;
72 57
73 SDL_FillRect(surface, &rect, color); 58 if (new_tick != current_tick)
59 {
60 long i;
61 for (i = new_tick - current_tick; i > 0; i--)
62 sim_tick_tasks();
63 current_tick = new_tick;
74 } 64 }
75}
76
77void drawrect(int color, int x1, int y1, int x2, int y2)
78{
79 SDL_Rect rect;
80 65
81 rect.x = x1 * display_zoom; 66 return 1;
82 rect.y = y1 * display_zoom;
83 rect.w = (x2-x1) * display_zoom;
84 rect.h = (y2-y1) * display_zoom;
85
86 SDL_FillRect(surface, &rect, color);
87} 67}
88 68
89#if 0 69void gui_message_loop(void)
90static void help(void)
91{ 70{
92 printf(PROGNAME " " ROCKBOXUI_VERSION " " __DATE__ "\n" 71 SDL_Event event;
93 "usage: " PROGNAME "\n"); 72 bool done = false;
73
74 while(!done && SDL_WaitEvent(&event))
75 {
76 switch(event.type)
77 {
78 case SDL_KEYDOWN:
79 button_event(event.key.keysym.sym, true);
80 break;
81 case SDL_KEYUP:
82 button_event(event.key.keysym.sym, false);
83 break;
84 case SDL_QUIT:
85 done = true;
86 break;
87 default:
88 //printf("Unhandled event\n");
89 break;
90 }
91 }
94} 92}
95#endif
96 93
97void dots(int *colors, struct coordinate *points, int count) 94bool gui_startup()
98{ 95{
99 int bpp = surface->format->BytesPerPixel; 96 SDL_Surface *picture_surface;
100 97
101 if (SDL_MUSTLOCK(surface)) { 98 if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_TIMER)) {
102 if (SDL_LockSurface(surface)) { 99 fprintf(stderr, "fatal: %s", SDL_GetError());
103 fprintf(stderr, "cannot lock surface: %s", SDL_GetError()); 100 return false;
104 exit(-1);
105 }
106 } 101 }
107 102
108 while (count--) { 103 atexit(SDL_Quit);
109 int x_off, y_off;
110 104
111 for (x_off = 0; x_off < display_zoom; x_off++) { 105 if ((gui_surface = SDL_SetVideoMode(UI_WIDTH, UI_HEIGHT, 24, SDL_HWSURFACE|SDL_DOUBLEBUF)) == NULL) {
112 for (y_off = 0; y_off < display_zoom; y_off++) { 106 fprintf(stderr, "fatal: %s", SDL_GetError());
113 int x = points[count].x*display_zoom + x_off; 107 return false;
114 int y = points[count].y*display_zoom + y_off; 108 }
115 109
116 Uint8 *p = (Uint8 *) surface->pixels + y * surface->pitch + x * bpp; 110 SDL_WM_SetCaption(UI_TITLE, NULL);
117 111
118 switch (bpp) { 112 simlcdinit();
119 case 1:
120 *p = colors[count];
121 break;
122 113
123 case 2: 114 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
124 *(Uint16 *)p = colors[count];
125 break;
126 115
127 case 3: 116 picture_surface = SDL_LoadBMP("UI256.bmp");
128 if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { 117 if (picture_surface == NULL) {
129 p[0] = (colors[count] >> 16) & 0xff; 118 fprintf(stderr, "warn: %s", SDL_GetError());
130 p[1] = (colors[count] >> 8) & 0xff;
131 p[2] = (colors[count]) & 0xff;
132 } else { 119 } else {
133 p[2] = (colors[count] >> 16) & 0xff; 120 SDL_BlitSurface(picture_surface, NULL, gui_surface, NULL);
134 p[1] = (colors[count] >> 8) & 0xff; 121 SDL_UpdateRect(gui_surface, 0, 0, 0, 0);
135 p[0] = (colors[count]) & 0xff;
136 } 122 }
137 break;
138 123
139 case 4: 124 start_tick = SDL_GetTicks();
140 *(Uint32 *)p = colors[count];
141 break;
142 }
143 }
144 }
145 }
146
147 if (SDL_MUSTLOCK(surface)) {
148 SDL_UnlockSurface(surface);
149 }
150 125
151 SDL_UpdateRect(surface, 0, 0, 0, 0); 126 return true;
152} 127}
153 128
154/* this is where the applicaton starts */ 129bool gui_shutdown()
155extern void app_main(void);
156
157void screenhack()
158{ 130{
159#if 0 131 int i;
160 Bool helpme;
161 132
162 /* This doesn't work, but I don't know why (Daniel 1999-12-01) */ 133 SDL_KillThread(gui_thread);
163 helpme = get_boolean_resource ("help", "Boolean"); 134 SDL_RemoveTimer(tick_timer_id);
164 if(helpme) 135#ifdef ROCKBOX_HAS_SIMSOUND
165 help(); 136 SDL_KillThread(sound_thread);
166#endif 137#endif
167 138
168 printf(PROGNAME " " ROCKBOXUI_VERSION " (" __DATE__ ")\n"); 139 for (i = 0; i < threadCount; i++)
140 {
141 SDL_KillThread(threads[i]);
142 }
169 143
170 init_window(); 144 return true;
145}
171 146
172 screen_redraw(); 147/**
148 * Thin wrapper around normal app_main() to stop gcc complaining about types.
149 */
150int sim_app_main(void *param)
151{
152 app_main(param);
173 153
174 app_main(); 154 return 0;
175} 155}
176 156
177/* used for the player sim */ 157int main(int argc, char *argv[])
178void drawrectangles(int color, struct rectangle *points, int count)
179{ 158{
180 SDL_Rect rect; 159 (void)argc;
181 Uint32 sdl_white = SDL_MapRGB(surface->format, 255, 255, 255); 160 (void)argv;
182 Uint32 sdl_black = SDL_MapRGB(surface->format, 0, 0, 0); 161
183 162 if (!gui_startup())
184 while (count--) { 163 return -1;
185 rect.x = points[count].x * display_zoom; 164
186 rect.y = points[count].y * display_zoom; 165 gui_thread = SDL_CreateThread(sim_app_main, NULL);
187 rect.w = points[count].width * display_zoom; 166 if (gui_thread == NULL) {
188 rect.h = points[count].height * display_zoom; 167 printf("Error creating GUI thread!\n");
189 168 return -1;
190 SDL_FillRect(surface, &rect, color ? sdl_white : sdl_black);
191 } 169 }
192}
193 170
171 tick_timer_id = SDL_AddTimer(10, tick_timer, NULL);
194 172
195void screen_redraw() 173#ifdef ROCKBOX_HAS_SIMSOUND
196{ 174 sound_thread = SDL_CreateThread(sound_playback_thread, NULL);
197 /* draw a border around the screen */ 175 if (sound_thread == NULL) {
198 int X1 = 0; 176 printf("Error creating sound thread!\n");
199 int Y1 = 0; 177 return -1;
200 int X2 = LCD_WIDTH + 2*MARGIN_X - 1; 178 }
201 int Y2 = LCD_HEIGHT + 2*MARGIN_Y - 1;
202
203 drawrect(SDL_MapRGB(surface->format, 255, 255, 255), X1, Y1, X2, Y1+1);
204 drawrect(SDL_MapRGB(surface->format, 255, 255, 255), X2, Y1, X2+1, Y2);
205 drawrect(SDL_MapRGB(surface->format, 255, 255, 255), X1, Y2, X2, Y2+1);
206 drawrect(SDL_MapRGB(surface->format, 255, 255, 255), X1, Y1, X1+1, Y2);
207
208 lcd_display_redraw = true;
209 lcd_update();
210
211#ifdef LCD_REMOTE_HEIGHT
212 /* draw a border around the remote LCD screen */
213 int RX1 = 0;
214 int RY1 = Y2 + 1;
215 int RX2 = LCD_REMOTE_WIDTH + 2*MARGIN_X - 1;
216 int RY2 = RY1 + LCD_REMOTE_HEIGHT + 2*MARGIN_Y - 1;
217
218 drawrect(SDL_MapRGB(surface->format, 255, 255, 255), RX1, RY1, RX2, RY1+1);
219 drawrect(SDL_MapRGB(surface->format, 255, 255, 255), RX2, RY1, RX2+1, RY2);
220 drawrect(SDL_MapRGB(surface->format, 255, 255, 255), RX1, RY2, RX2, RY2+1);
221 drawrect(SDL_MapRGB(surface->format, 255, 255, 255), RX1, RY1, RX1+1, RY2);
222
223 lcd_display_redraw = true;
224 lcd_remote_update();
225#endif 179#endif
180
181 gui_message_loop();
182
183 return gui_shutdown();
226} 184}
185