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 ****************************************************************************/
27 #include "system-sdl.h"
32 #ifdef HAVE_LCD_BITMAP
33 #include "lcd-bitmap.h"
34 #elif defined(HAVE_LCD_CHARCELLS)
35 #include "lcd-charcells.h"
37 #ifdef HAVE_REMOTE_LCD
38 #include "lcd-remote-bitmap.h"
40 #include "thread-sdl.h"
41 #include "SDL_mutex.h"
42 #include "SDL_thread.h"
44 /* extern functions */
45 extern void new_key(int key
);
47 void button_event(int key
, bool pressed
);
49 SDL_Surface
*gui_surface
;
50 bool background
= true; /* use backgrounds by default */
51 #ifdef HAVE_REMOTE_LCD
52 static bool showremote
= true; /* include remote by default */
55 bool lcd_display_redraw
= true; /* Used for player simulator */
56 char having_new_lcd
= true; /* Used for player simulator */
57 bool sim_alarm_wakeup
= false;
58 const char *sim_root_dir
= NULL
;
60 bool debug_audio
= false;
62 bool debug_wps
= false;
63 int wps_verbose_level
= 3;
65 void gui_message_loop(void)
70 while(!done
&& SDL_WaitEvent(&event
))
75 sim_enter_irq_handler();
76 button_event(event
.key
.keysym
.sym
, true);
77 sim_exit_irq_handler();
80 sim_enter_irq_handler();
81 button_event(event
.key
.keysym
.sym
, false);
82 sim_exit_irq_handler();
84 #ifndef HAVE_TOUCHSCREEN
85 case SDL_MOUSEBUTTONDOWN
:
86 if (debug_wps
&& event
.button
.button
== 1)
88 printf("Mouse at: (%d, %d)\n", event
.button
.x
, event
.button
.y
);
92 case SDL_MOUSEBUTTONUP
:
93 sim_enter_irq_handler();
94 button_event(BUTTON_TOUCHSCREEN
, false);
95 sim_exit_irq_handler();
102 /*printf("Unhandled event\n"); */
108 bool gui_startup(void)
110 SDL_Surface
*picture_surface
;
113 if (SDL_Init(SDL_INIT_VIDEO
|SDL_INIT_AUDIO
|SDL_INIT_TIMER
)) {
114 fprintf(stderr
, "fatal: %s\n", SDL_GetError());
120 /* Try and load the background image. If it fails go without */
122 picture_surface
= SDL_LoadBMP("UI256.bmp");
123 if (picture_surface
== NULL
) {
125 fprintf(stderr
, "warn: %s\n", SDL_GetError());
137 #ifdef HAVE_REMOTE_LCD
140 width
= SIM_LCD_WIDTH
> SIM_REMOTE_WIDTH
? SIM_LCD_WIDTH
: SIM_REMOTE_WIDTH
;
141 height
= SIM_LCD_HEIGHT
+ SIM_REMOTE_HEIGHT
;
146 width
= SIM_LCD_WIDTH
;
147 height
= SIM_LCD_HEIGHT
;
152 if ((gui_surface
= SDL_SetVideoMode(width
* display_zoom
, height
* display_zoom
, 24, SDL_HWSURFACE
|SDL_DOUBLEBUF
)) == NULL
) {
153 fprintf(stderr
, "fatal: %s\n", SDL_GetError());
157 SDL_WM_SetCaption(UI_TITLE
, NULL
);
160 #ifdef HAVE_REMOTE_LCD
162 sim_lcd_remote_init();
165 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY
, SDL_DEFAULT_REPEAT_INTERVAL
);
167 if (background
&& picture_surface
!= NULL
) {
168 SDL_BlitSurface(picture_surface
, NULL
, gui_surface
, NULL
);
169 SDL_UpdateRect(gui_surface
, 0, 0, 0, 0);
175 bool gui_shutdown(void)
177 /* Order here is relevent to prevent deadlocks and use of destroyed
178 sync primitives by kernel threads */
179 thread_sdl_shutdown();
180 sim_kernel_shutdown();
184 #if defined(WIN32) && defined(main)
185 /* Don't use SDL_main on windows -> no more stdio redirection */
189 int main(int argc
, char *argv
[])
194 for (x
= 1; x
< argc
; x
++)
196 if (!strcmp("--debugaudio", argv
[x
]))
199 printf("Writing debug audio file.\n");
201 else if (!strcmp("--debugwps", argv
[x
]))
204 printf("WPS debug mode enabled.\n");
206 else if (!strcmp("--nobackground", argv
[x
]))
209 printf("Disabling background image.\n");
211 #ifdef HAVE_REMOTE_LCD
212 else if (!strcmp("--noremote", argv
[x
]))
216 printf("Disabling remote image.\n");
219 else if (!strcmp("--old_lcd", argv
[x
]))
221 having_new_lcd
= false;
222 printf("Using old LCD layout.\n");
224 else if (!strcmp("--zoom", argv
[x
]))
228 display_zoom
=atoi(argv
[x
]);
231 printf("Window zoom is %d\n", display_zoom
);
233 else if (!strcmp("--alarm", argv
[x
]))
235 sim_alarm_wakeup
= true;
236 printf("Simulating alarm wakeup.\n");
238 else if (!strcmp("--root", argv
[x
]))
243 sim_root_dir
= argv
[x
];
244 printf("Root directory: %s\n", sim_root_dir
);
249 printf("rockboxui\n");
250 printf("Arguments:\n");
251 printf(" --debugaudio \t Write raw PCM data to audiodebug.raw\n");
252 printf(" --debugwps \t Print advanced WPS debug info\n");
253 printf(" --nobackground \t Disable the background image\n");
254 #ifdef HAVE_REMOTE_LCD
255 printf(" --noremote \t Disable the remote image (will disable backgrounds)\n");
257 printf(" --old_lcd \t [Player] simulate old playermodel (ROM version<4.51)\n");
258 printf(" --zoom [VAL]\t Window zoom (will disable backgrounds)\n");
259 printf(" --alarm \t Simulate a wake-up on alarm\n");
260 printf(" --root [DIR]\t Set root directory\n");
266 if (display_zoom
> 1) {
270 if (!sim_kernel_init()) {
271 fprintf(stderr
, "sim_kernel_init failed\n");
275 if (!gui_startup()) {
276 fprintf(stderr
, "gui_startup failed\n");
280 /* app_main will be called by the new main thread */
281 if (!thread_sdl_init(NULL
)) {
282 fprintf(stderr
, "thread_sdl_init failed\n");
288 return gui_shutdown();