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 ****************************************************************************/
28 #ifdef HAVE_LCD_BITMAP
29 #include "lcd-bitmap.h"
30 #elif defined(HAVE_LCD_CHARCELLS)
31 #include "lcd-charcells.h"
33 #ifdef HAVE_REMOTE_LCD
34 #include "lcd-remote-bitmap.h"
36 #include "thread-sdl.h"
37 #include "SDL_mutex.h"
38 #include "SDL_thread.h"
40 /* extern functions */
41 extern void app_main (void *); /* mod entry point */
42 extern void new_key(int key
);
43 extern void sim_tick_tasks(void);
45 void button_event(int key
, bool pressed
);
47 SDL_Surface
*gui_surface
;
48 bool background
= false; /* Don't use backgrounds by default */
50 SDL_Thread
*gui_thread
;
51 SDL_TimerID tick_timer_id
;
53 bool lcd_display_redraw
= true; /* Used for player simulator */
54 char having_new_lcd
= true; /* Used for player simulator */
56 bool debug_audio
= false;
58 bool debug_wps
= false;
59 int wps_verbose_level
= 3;
63 Uint32
tick_timer(Uint32 interval
, void *param
)
70 new_tick
= (SDL_GetTicks() - start_tick
) * HZ
/ 1000;
72 if (new_tick
!= current_tick
) {
74 for (i
= new_tick
- current_tick
; i
> 0; i
--)
76 current_tick
= new_tick
;
82 void gui_message_loop(void)
87 while(!done
&& SDL_WaitEvent(&event
))
92 button_event(event
.key
.keysym
.sym
, true);
95 button_event(event
.key
.keysym
.sym
, false);
101 /*printf("Unhandled event\n"); */
107 bool gui_startup(void)
109 SDL_Surface
*picture_surface
;
112 if (SDL_Init(SDL_INIT_VIDEO
|SDL_INIT_AUDIO
|SDL_INIT_TIMER
)) {
113 fprintf(stderr
, "fatal: %s", SDL_GetError());
119 /* Try and load the background image. If it fails go without */
121 picture_surface
= SDL_LoadBMP("UI256.bmp");
122 if (picture_surface
== NULL
) {
124 fprintf(stderr
, "warn: %s", SDL_GetError());
134 #ifdef HAVE_REMOTE_LCD
135 width
= UI_LCD_WIDTH
> UI_REMOTE_WIDTH
? UI_LCD_WIDTH
: UI_REMOTE_WIDTH
;
136 height
= UI_LCD_HEIGHT
+ UI_REMOTE_HEIGHT
;
138 width
= UI_LCD_WIDTH
;
139 height
= UI_LCD_HEIGHT
;
144 if ((gui_surface
= SDL_SetVideoMode(width
* display_zoom
, height
* display_zoom
, 24, SDL_HWSURFACE
|SDL_DOUBLEBUF
)) == NULL
) {
145 fprintf(stderr
, "fatal: %s\n", SDL_GetError());
149 SDL_WM_SetCaption(UI_TITLE
, NULL
);
152 #ifdef HAVE_REMOTE_LCD
153 sim_lcd_remote_init();
156 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY
, SDL_DEFAULT_REPEAT_INTERVAL
);
158 if (background
&& picture_surface
!= NULL
) {
159 SDL_BlitSurface(picture_surface
, NULL
, gui_surface
, NULL
);
160 SDL_UpdateRect(gui_surface
, 0, 0, 0, 0);
163 start_tick
= SDL_GetTicks();
168 bool gui_shutdown(void)
172 SDL_KillThread(gui_thread
);
173 SDL_RemoveTimer(tick_timer_id
);
175 for (i
= 0; i
< threadCount
; i
++)
177 SDL_KillThread(threads
[i
]);
184 * Thin wrapper around normal app_main() to stop gcc complaining about types.
186 int sim_app_main(void *param
)
193 #if defined(WIN32) && defined(main)
194 /* Don't use SDL_main on windows -> no more stdio redirection */
198 int main(int argc
, char *argv
[])
202 for (x
= 1; x
< argc
; x
++) {
203 if (!strcmp("--debugaudio", argv
[x
])) {
205 printf("Writing debug audio file.\n");
206 } else if (!strcmp("--debugwps", argv
[x
])) {
208 printf("WPS debug mode enabled.\n");
209 } else if (!strcmp("--background", argv
[x
])) {
211 printf("Using background image.\n");
212 } else if (!strcmp("--old_lcd", argv
[x
])) {
213 having_new_lcd
= false;
214 printf("Using old LCD layout.\n");
215 } else if (!strcmp("--zoom", argv
[x
])) {
218 display_zoom
=atoi(argv
[x
]);
221 printf("Window zoom is %d\n", display_zoom
);
223 printf("rockboxui\n");
224 printf("Arguments:\n");
225 printf(" --debugaudio \t Write raw PCM data to audiodebug.raw\n");
226 printf(" --debugwps \t Print advanced WPS debug info\n");
227 printf(" --background \t Use background image of hardware\n");
228 printf(" --old_lcd \t [Player] simulate old playermodel (ROM version<4.51)\n");
229 printf(" --zoom [VAL]\t window zoom (will disable backgrounds)\n");
235 if (display_zoom
> 1) {
242 gui_thread
= SDL_CreateThread(sim_app_main
, NULL
);
243 if (gui_thread
== NULL
) {
244 printf("Error creating GUI thread!\n");
248 tick_timer_id
= SDL_AddTimer(10, tick_timer
, NULL
);
252 return gui_shutdown();