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 */
52 bool lcd_display_redraw
= true; /* Used for player simulator */
53 char having_new_lcd
= true; /* Used for player simulator */
54 bool sim_alarm_wakeup
= false;
55 const char *sim_root_dir
= NULL
;
57 bool debug_audio
= false;
59 bool debug_wps
= false;
60 int wps_verbose_level
= 3;
62 void gui_message_loop(void)
67 while(!done
&& SDL_WaitEvent(&event
))
72 sim_enter_irq_handler();
73 button_event(event
.key
.keysym
.sym
, true);
74 sim_exit_irq_handler();
77 sim_enter_irq_handler();
78 button_event(event
.key
.keysym
.sym
, false);
79 sim_exit_irq_handler();
81 #ifndef HAVE_TOUCHSCREEN
82 case SDL_MOUSEBUTTONDOWN
:
83 if (debug_wps
&& event
.button
.button
== 1)
85 printf("Mouse at: (%d, %d)\n", event
.button
.x
, event
.button
.y
);
89 case SDL_MOUSEBUTTONUP
:
90 sim_enter_irq_handler();
91 button_event(BUTTON_TOUCHSCREEN
, false);
92 sim_exit_irq_handler();
99 /*printf("Unhandled event\n"); */
105 bool gui_startup(void)
107 SDL_Surface
*picture_surface
;
110 if (SDL_Init(SDL_INIT_VIDEO
|SDL_INIT_AUDIO
|SDL_INIT_TIMER
)) {
111 fprintf(stderr
, "fatal: %s\n", SDL_GetError());
117 /* Try and load the background image. If it fails go without */
119 picture_surface
= SDL_LoadBMP("UI256.bmp");
120 if (picture_surface
== NULL
) {
122 fprintf(stderr
, "warn: %s\n", SDL_GetError());
132 #ifdef HAVE_REMOTE_LCD
133 width
= SIM_LCD_WIDTH
> SIM_REMOTE_WIDTH
? SIM_LCD_WIDTH
: SIM_REMOTE_WIDTH
;
134 height
= SIM_LCD_HEIGHT
+ SIM_REMOTE_HEIGHT
;
136 width
= SIM_LCD_WIDTH
;
137 height
= SIM_LCD_HEIGHT
;
142 if ((gui_surface
= SDL_SetVideoMode(width
* display_zoom
, height
* display_zoom
, 24, SDL_HWSURFACE
|SDL_DOUBLEBUF
)) == NULL
) {
143 fprintf(stderr
, "fatal: %s\n", SDL_GetError());
147 SDL_WM_SetCaption(UI_TITLE
, NULL
);
150 #ifdef HAVE_REMOTE_LCD
151 sim_lcd_remote_init();
154 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY
, SDL_DEFAULT_REPEAT_INTERVAL
);
156 if (background
&& picture_surface
!= NULL
) {
157 SDL_BlitSurface(picture_surface
, NULL
, gui_surface
, NULL
);
158 SDL_UpdateRect(gui_surface
, 0, 0, 0, 0);
164 bool gui_shutdown(void)
166 /* Order here is relevent to prevent deadlocks and use of destroyed
167 sync primitives by kernel threads */
168 thread_sdl_shutdown();
169 sim_kernel_shutdown();
173 #if defined(WIN32) && defined(main)
174 /* Don't use SDL_main on windows -> no more stdio redirection */
178 int main(int argc
, char *argv
[])
183 for (x
= 1; x
< argc
; x
++)
185 if (!strcmp("--debugaudio", argv
[x
]))
188 printf("Writing debug audio file.\n");
190 else if (!strcmp("--debugwps", argv
[x
]))
193 printf("WPS debug mode enabled.\n");
195 else if (!strcmp("--nobackground", argv
[x
]))
198 printf("Disabling background image.\n");
200 else if (!strcmp("--old_lcd", argv
[x
]))
202 having_new_lcd
= false;
203 printf("Using old LCD layout.\n");
205 else if (!strcmp("--zoom", argv
[x
]))
209 display_zoom
=atoi(argv
[x
]);
212 printf("Window zoom is %d\n", display_zoom
);
214 else if (!strcmp("--alarm", argv
[x
]))
216 sim_alarm_wakeup
= true;
217 printf("Simulating alarm wakeup.\n");
219 else if (!strcmp("--root", argv
[x
]))
224 sim_root_dir
= argv
[x
];
225 printf("Root directory: %s\n", sim_root_dir
);
230 printf("rockboxui\n");
231 printf("Arguments:\n");
232 printf(" --debugaudio \t Write raw PCM data to audiodebug.raw\n");
233 printf(" --debugwps \t Print advanced WPS debug info\n");
234 printf(" --nobackground \t Disable the background image\n");
235 printf(" --old_lcd \t [Player] simulate old playermodel (ROM version<4.51)\n");
236 printf(" --zoom [VAL]\t Window zoom (will disable backgrounds)\n");
237 printf(" --alarm \t Simulate a wake-up on alarm\n");
238 printf(" --root [DIR]\t Set root directory\n");
244 if (display_zoom
> 1) {
248 if (!sim_kernel_init()) {
249 fprintf(stderr
, "sim_kernel_init failed\n");
253 if (!gui_startup()) {
254 fprintf(stderr
, "gui_startup failed\n");
258 /* app_main will be called by the new main thread */
259 if (!thread_sdl_init(NULL
)) {
260 fprintf(stderr
, "thread_sdl_init failed\n");
266 return gui_shutdown();