1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2006 by Daniel Everton <dan@iocaine.org>
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
26 #include "system-sdl.h"
27 #include "thread-sdl.h"
28 #include "sim-ui-defines.h"
30 #ifdef HAVE_LCD_BITMAP
31 #include "lcd-bitmap.h"
32 #elif defined(HAVE_LCD_CHARCELLS)
33 #include "lcd-charcells.h"
35 #ifdef HAVE_REMOTE_LCD
36 #include "lcd-remote-bitmap.h"
41 SDL_Surface
*gui_surface
;
43 bool background
= true; /* use backgrounds by default */
44 #ifdef HAVE_REMOTE_LCD
45 bool showremote
= true; /* include remote by default */
48 bool debug_buttons
= false;
50 bool lcd_display_redraw
= true; /* Used for player simulator */
51 char having_new_lcd
= true; /* Used for player simulator */
52 bool sim_alarm_wakeup
= false;
53 const char *sim_root_dir
= NULL
;
54 extern int display_zoom
;
57 bool debug_audio
= false;
60 bool debug_wps
= false;
61 int wps_verbose_level
= 3;
64 void sys_poweroff(void)
66 /* Order here is relevent to prevent deadlocks and use of destroyed
67 sync primitives by kernel threads */
68 sim_thread_shutdown();
69 sim_kernel_shutdown();
75 void gui_message_loop(void);
78 * This callback let's the main thread run again after SDL has been initialized
80 static uint32_t cond_signal(uint32_t interval
, void *param
)
83 SDL_cond
*c
= (SDL_cond
*)param
;
84 /* remove timer, CondSignal returns 0 on success */
85 return SDL_CondSignal(c
);
89 * This thread will read the buttons in an interrupt like fashion, and
90 * also initializes SDL_INIT_VIDEO and the surfaces
92 * it must be done in the same thread (at least on windows) because events only
93 * work in the thread which called SDL_Init(SubSystem) with SDL_INIT_VIDEO
95 * This is an SDL thread and relies on preemptive behavoir of the host
97 static int sdl_event_thread(void * param
)
99 SDL_InitSubSystem(SDL_INIT_VIDEO
);
101 SDL_Surface
*picture_surface
;
104 /* Try and load the background image. If it fails go without */
106 picture_surface
= SDL_LoadBMP("UI256.bmp");
107 if (picture_surface
== NULL
) {
109 DEBUGF("warn: %s\n", SDL_GetError());
121 #ifdef HAVE_REMOTE_LCD
124 width
= SIM_LCD_WIDTH
> SIM_REMOTE_WIDTH
? SIM_LCD_WIDTH
: SIM_REMOTE_WIDTH
;
125 height
= SIM_LCD_HEIGHT
+ SIM_REMOTE_HEIGHT
;
130 width
= SIM_LCD_WIDTH
;
131 height
= SIM_LCD_HEIGHT
;
136 if ((gui_surface
= SDL_SetVideoMode(width
* display_zoom
, height
* display_zoom
, 24, SDL_HWSURFACE
|SDL_DOUBLEBUF
)) == NULL
) {
137 panicf("%s", SDL_GetError());
140 SDL_WM_SetCaption(UI_TITLE
, NULL
);
143 #ifdef HAVE_REMOTE_LCD
145 sim_lcd_remote_init();
148 if (background
&& picture_surface
!= NULL
)
149 SDL_BlitSurface(picture_surface
, NULL
, gui_surface
, NULL
);
151 /* calling SDL_CondSignal() right away here doesn't work reliably so
152 * post-pone it a bit */
153 SDL_AddTimer(100, cond_signal
, param
);
155 * finally enter the button loop */
163 void system_init(void)
167 if (SDL_Init(SDL_INIT_TIMER
))
168 panicf("%s", SDL_GetError());
171 c
= SDL_CreateCond();
172 m
= SDL_CreateMutex();
174 SDL_CreateThread(sdl_event_thread
, c
);
176 /* Lock mutex and wait for sdl_event_thread to run so that it can
177 * initialize the surfaces and video subsystem needed for SDL events */
187 void system_exception_wait(void)
189 sim_thread_exception_wait();
192 void system_reboot(void)
194 sim_thread_exception_wait();
198 void sys_handle_argv(int argc
, char *argv
[])
203 for (x
= 1; x
< argc
; x
++)
206 if (!strcmp("--debugaudio", argv
[x
]))
209 printf("Writing debug audio file.\n");
213 if (!strcmp("--debugwps", argv
[x
]))
216 printf("WPS debug mode enabled.\n");
218 else if (!strcmp("--nobackground", argv
[x
]))
221 printf("Disabling background image.\n");
223 #ifdef HAVE_REMOTE_LCD
224 else if (!strcmp("--noremote", argv
[x
]))
228 printf("Disabling remote image.\n");
231 else if (!strcmp("--old_lcd", argv
[x
]))
233 having_new_lcd
= false;
234 printf("Using old LCD layout.\n");
236 else if (!strcmp("--zoom", argv
[x
]))
240 display_zoom
=atoi(argv
[x
]);
243 printf("Window zoom is %d\n", display_zoom
);
245 else if (!strcmp("--alarm", argv
[x
]))
247 sim_alarm_wakeup
= true;
248 printf("Simulating alarm wakeup.\n");
250 else if (!strcmp("--root", argv
[x
]))
255 sim_root_dir
= argv
[x
];
256 printf("Root directory: %s\n", sim_root_dir
);
259 else if (!strcmp("--mapping", argv
[x
]))
262 printf("Printing click coords with drag radii.\n");
264 else if (!strcmp("--debugbuttons", argv
[x
]))
266 debug_buttons
= true;
267 printf("Printing background button clicks.\n");
271 printf("rockboxui\n");
272 printf("Arguments:\n");
274 printf(" --debugaudio \t Write raw PCM data to audiodebug.raw\n");
276 printf(" --debugwps \t Print advanced WPS debug info\n");
277 printf(" --nobackground \t Disable the background image\n");
278 #ifdef HAVE_REMOTE_LCD
279 printf(" --noremote \t Disable the remote image (will disable backgrounds)\n");
281 printf(" --old_lcd \t [Player] simulate old playermodel (ROM version<4.51)\n");
282 printf(" --zoom [VAL]\t Window zoom (will disable backgrounds)\n");
283 printf(" --alarm \t Simulate a wake-up on alarm\n");
284 printf(" --root [DIR]\t Set root directory\n");
285 printf(" --mapping \t Output coordinates and radius for mapping backgrounds\n");
290 if (display_zoom
> 1) {