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 ****************************************************************************/
29 #ifdef HAVE_LCD_BITMAP
30 #include "lcd-bitmap.h"
31 #elif defined(HAVE_LCD_CHARCELLS)
32 #include "lcd-charcells.h"
34 #ifdef HAVE_REMOTE_LCD
35 #include "lcd-remote-bitmap.h"
37 #include "thread-sdl.h"
38 #include "SDL_mutex.h"
39 #include "SDL_thread.h"
41 /* extern functions */
42 extern void app_main (void *); /* mod entry point */
43 extern void new_key(int key
);
44 extern void sim_tick_tasks(void);
45 extern bool sim_io_init(void);
46 extern void sim_io_shutdown(void);
48 void button_event(int key
, bool pressed
);
50 SDL_Surface
*gui_surface
;
51 bool background
= false; /* Don't use backgrounds by default */
53 SDL_TimerID tick_timer_id
;
55 bool lcd_display_redraw
= true; /* Used for player simulator */
56 char having_new_lcd
= true; /* Used for player simulator */
58 bool debug_audio
= false;
60 bool debug_wps
= false;
61 int wps_verbose_level
= 3;
65 Uint32
tick_timer(Uint32 interval
, void *param
)
72 new_tick
= (SDL_GetTicks() - start_tick
) / (1000/HZ
);
74 if (new_tick
!= current_tick
) {
76 for (i
= new_tick
- current_tick
; i
> 0; i
--)
78 current_tick
= new_tick
;
84 void gui_message_loop(void)
89 while(!done
&& SDL_WaitEvent(&event
))
94 button_event(event
.key
.keysym
.sym
, true);
97 button_event(event
.key
.keysym
.sym
, false);
103 /*printf("Unhandled event\n"); */
109 bool gui_startup(void)
111 SDL_Surface
*picture_surface
;
114 if (SDL_Init(SDL_INIT_VIDEO
|SDL_INIT_AUDIO
|SDL_INIT_TIMER
)) {
115 fprintf(stderr
, "fatal: %s\n", SDL_GetError());
121 /* Try and load the background image. If it fails go without */
123 picture_surface
= SDL_LoadBMP("UI256.bmp");
124 if (picture_surface
== NULL
) {
126 fprintf(stderr
, "warn: %s\n", SDL_GetError());
136 #ifdef HAVE_REMOTE_LCD
137 width
= UI_LCD_WIDTH
> UI_REMOTE_WIDTH
? UI_LCD_WIDTH
: UI_REMOTE_WIDTH
;
138 height
= UI_LCD_HEIGHT
+ UI_REMOTE_HEIGHT
;
140 width
= UI_LCD_WIDTH
;
141 height
= UI_LCD_HEIGHT
;
146 if ((gui_surface
= SDL_SetVideoMode(width
* display_zoom
, height
* display_zoom
, 24, SDL_HWSURFACE
|SDL_DOUBLEBUF
)) == NULL
) {
147 fprintf(stderr
, "fatal: %s\n", SDL_GetError());
151 SDL_WM_SetCaption(UI_TITLE
, NULL
);
154 #ifdef HAVE_REMOTE_LCD
155 sim_lcd_remote_init();
158 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY
, SDL_DEFAULT_REPEAT_INTERVAL
);
160 if (background
&& picture_surface
!= NULL
) {
161 SDL_BlitSurface(picture_surface
, NULL
, gui_surface
, NULL
);
162 SDL_UpdateRect(gui_surface
, 0, 0, 0, 0);
165 start_tick
= SDL_GetTicks();
170 bool gui_shutdown(void)
172 SDL_RemoveTimer(tick_timer_id
);
173 /* Order here is relevent to prevent deadlocks and use of destroyed
174 sync primitives by kernel threads */
175 thread_sdl_shutdown();
180 #if defined(WIN32) && defined(main)
181 /* Don't use SDL_main on windows -> no more stdio redirection */
185 int main(int argc
, char *argv
[])
189 for (x
= 1; x
< argc
; x
++) {
190 if (!strcmp("--debugaudio", argv
[x
])) {
192 printf("Writing debug audio file.\n");
193 } else if (!strcmp("--debugwps", argv
[x
])) {
195 printf("WPS debug mode enabled.\n");
196 } else if (!strcmp("--background", argv
[x
])) {
198 printf("Using background image.\n");
199 } else if (!strcmp("--old_lcd", argv
[x
])) {
200 having_new_lcd
= false;
201 printf("Using old LCD layout.\n");
202 } else if (!strcmp("--zoom", argv
[x
])) {
205 display_zoom
=atoi(argv
[x
]);
208 printf("Window zoom is %d\n", display_zoom
);
210 printf("rockboxui\n");
211 printf("Arguments:\n");
212 printf(" --debugaudio \t Write raw PCM data to audiodebug.raw\n");
213 printf(" --debugwps \t Print advanced WPS debug info\n");
214 printf(" --background \t Use background image of hardware\n");
215 printf(" --old_lcd \t [Player] simulate old playermodel (ROM version<4.51)\n");
216 printf(" --zoom [VAL]\t window zoom (will disable backgrounds)\n");
222 if (display_zoom
> 1) {
226 if (!sim_io_init()) {
227 fprintf(stderr
, "sim_io_init failed\n");
231 if (!gui_startup()) {
232 fprintf(stderr
, "gui_startup failed\n");
236 /* app_main will be called by the new main thread */
237 if (!thread_sdl_init(NULL
)) {
238 fprintf(stderr
, "thread_sdl_init failed\n");
242 tick_timer_id
= SDL_AddTimer(10, tick_timer
, NULL
);
246 return gui_shutdown();