1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2006 by Daniel Everton <dan@iocaine.org>
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.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
25 #include "system-sdl.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"
38 #include "thread-sdl.h"
39 #include "SDL_mutex.h"
40 #include "SDL_thread.h"
42 /* extern functions */
43 extern void new_key(int key
);
45 void button_event(int key
, bool pressed
);
47 SDL_Surface
*gui_surface
;
48 bool background
= false; /* Don't use backgrounds by default */
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
;
55 bool debug_audio
= false;
57 bool debug_wps
= false;
58 int wps_verbose_level
= 3;
60 void gui_message_loop(void)
65 while(!done
&& SDL_WaitEvent(&event
))
70 sim_enter_irq_handler();
71 button_event(event
.key
.keysym
.sym
, true);
72 sim_exit_irq_handler();
75 sim_enter_irq_handler();
76 button_event(event
.key
.keysym
.sym
, false);
77 sim_exit_irq_handler();
80 case SDL_MOUSEBUTTONDOWN
:
81 if (debug_wps
&& event
.button
.button
== 1)
83 printf("Mouse at: (%d, %d)\n", event
.button
.x
, event
.button
.y
);
91 /*printf("Unhandled event\n"); */
97 bool gui_startup(void)
99 SDL_Surface
*picture_surface
;
102 if (SDL_Init(SDL_INIT_VIDEO
|SDL_INIT_AUDIO
|SDL_INIT_TIMER
)) {
103 fprintf(stderr
, "fatal: %s\n", SDL_GetError());
109 /* Try and load the background image. If it fails go without */
111 picture_surface
= SDL_LoadBMP("UI256.bmp");
112 if (picture_surface
== NULL
) {
114 fprintf(stderr
, "warn: %s\n", SDL_GetError());
124 #ifdef HAVE_REMOTE_LCD
125 width
= UI_LCD_WIDTH
> UI_REMOTE_WIDTH
? UI_LCD_WIDTH
: UI_REMOTE_WIDTH
;
126 height
= UI_LCD_HEIGHT
+ UI_REMOTE_HEIGHT
;
128 width
= UI_LCD_WIDTH
;
129 height
= UI_LCD_HEIGHT
;
134 if ((gui_surface
= SDL_SetVideoMode(width
* display_zoom
, height
* display_zoom
, 24, SDL_HWSURFACE
|SDL_DOUBLEBUF
)) == NULL
) {
135 fprintf(stderr
, "fatal: %s\n", SDL_GetError());
139 SDL_WM_SetCaption(UI_TITLE
, NULL
);
142 #ifdef HAVE_REMOTE_LCD
143 sim_lcd_remote_init();
146 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY
, SDL_DEFAULT_REPEAT_INTERVAL
);
148 if (background
&& picture_surface
!= NULL
) {
149 SDL_BlitSurface(picture_surface
, NULL
, gui_surface
, NULL
);
150 SDL_UpdateRect(gui_surface
, 0, 0, 0, 0);
156 bool gui_shutdown(void)
158 /* Order here is relevent to prevent deadlocks and use of destroyed
159 sync primitives by kernel threads */
160 thread_sdl_shutdown();
161 sim_kernel_shutdown();
165 #if defined(WIN32) && defined(main)
166 /* Don't use SDL_main on windows -> no more stdio redirection */
170 int main(int argc
, char *argv
[])
175 for (x
= 1; x
< argc
; x
++)
177 if (!strcmp("--debugaudio", argv
[x
]))
180 printf("Writing debug audio file.\n");
182 else if (!strcmp("--debugwps", argv
[x
]))
185 printf("WPS debug mode enabled.\n");
187 else if (!strcmp("--background", argv
[x
]))
190 printf("Using background image.\n");
192 else if (!strcmp("--old_lcd", argv
[x
]))
194 having_new_lcd
= false;
195 printf("Using old LCD layout.\n");
197 else if (!strcmp("--zoom", argv
[x
]))
201 display_zoom
=atoi(argv
[x
]);
204 printf("Window zoom is %d\n", display_zoom
);
206 else if (!strcmp("--alarm", argv
[x
]))
208 sim_alarm_wakeup
= true;
209 printf("Simulating alarm wakeup.\n");
211 else if (!strcmp("--root", argv
[x
]))
216 sim_root_dir
= argv
[x
];
217 printf("Root directory: %s\n", sim_root_dir
);
222 printf("rockboxui\n");
223 printf("Arguments:\n");
224 printf(" --debugaudio \t Write raw PCM data to audiodebug.raw\n");
225 printf(" --debugwps \t Print advanced WPS debug info\n");
226 printf(" --background \t Use background image of hardware\n");
227 printf(" --old_lcd \t [Player] simulate old playermodel (ROM version<4.51)\n");
228 printf(" --zoom [VAL]\t Window zoom (will disable backgrounds)\n");
229 printf(" --alarm \t Simulate a wake-up on alarm\n");
230 printf(" --root [DIR]\t Set root directory\n");
236 if (display_zoom
> 1) {
240 if (!sim_kernel_init()) {
241 fprintf(stderr
, "sim_kernel_init failed\n");
245 if (!gui_startup()) {
246 fprintf(stderr
, "gui_startup failed\n");
250 /* app_main will be called by the new main thread */
251 if (!thread_sdl_init(NULL
)) {
252 fprintf(stderr
, "thread_sdl_init failed\n");
258 return gui_shutdown();