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 app_main (void *); /* mod entry point */
44 extern void new_key(int key
);
45 extern void sim_tick_tasks(void);
46 extern bool sim_io_init(void);
47 extern void sim_io_shutdown(void);
49 void button_event(int key
, bool pressed
);
51 SDL_Surface
*gui_surface
;
52 bool background
= false; /* Don't use backgrounds by default */
54 SDL_TimerID tick_timer_id
;
56 bool lcd_display_redraw
= true; /* Used for player simulator */
57 char having_new_lcd
= true; /* Used for player simulator */
58 bool sim_alarm_wakeup
= false;
60 bool debug_audio
= false;
62 bool debug_wps
= false;
63 int wps_verbose_level
= 3;
67 Uint32
tick_timer(Uint32 interval
, void *param
)
74 new_tick
= (SDL_GetTicks() - start_tick
) / (1000/HZ
);
76 if (new_tick
!= current_tick
) {
78 for (i
= new_tick
- current_tick
; i
> 0; i
--)
80 sim_enter_irq_handler();
82 sim_exit_irq_handler();
84 current_tick
= new_tick
;
90 void gui_message_loop(void)
95 while(!done
&& SDL_WaitEvent(&event
))
100 sim_enter_irq_handler();
101 button_event(event
.key
.keysym
.sym
, true);
102 sim_exit_irq_handler();
105 sim_enter_irq_handler();
106 button_event(event
.key
.keysym
.sym
, false);
107 sim_exit_irq_handler();
113 /*printf("Unhandled event\n"); */
119 bool gui_startup(void)
121 SDL_Surface
*picture_surface
;
124 if (SDL_Init(SDL_INIT_VIDEO
|SDL_INIT_AUDIO
|SDL_INIT_TIMER
)) {
125 fprintf(stderr
, "fatal: %s\n", SDL_GetError());
131 /* Try and load the background image. If it fails go without */
133 picture_surface
= SDL_LoadBMP("UI256.bmp");
134 if (picture_surface
== NULL
) {
136 fprintf(stderr
, "warn: %s\n", SDL_GetError());
146 #ifdef HAVE_REMOTE_LCD
147 width
= UI_LCD_WIDTH
> UI_REMOTE_WIDTH
? UI_LCD_WIDTH
: UI_REMOTE_WIDTH
;
148 height
= UI_LCD_HEIGHT
+ UI_REMOTE_HEIGHT
;
150 width
= UI_LCD_WIDTH
;
151 height
= UI_LCD_HEIGHT
;
156 if ((gui_surface
= SDL_SetVideoMode(width
* display_zoom
, height
* display_zoom
, 24, SDL_HWSURFACE
|SDL_DOUBLEBUF
)) == NULL
) {
157 fprintf(stderr
, "fatal: %s\n", SDL_GetError());
161 SDL_WM_SetCaption(UI_TITLE
, NULL
);
164 #ifdef HAVE_REMOTE_LCD
165 sim_lcd_remote_init();
168 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY
, SDL_DEFAULT_REPEAT_INTERVAL
);
170 if (background
&& picture_surface
!= NULL
) {
171 SDL_BlitSurface(picture_surface
, NULL
, gui_surface
, NULL
);
172 SDL_UpdateRect(gui_surface
, 0, 0, 0, 0);
175 start_tick
= SDL_GetTicks();
180 bool gui_shutdown(void)
182 /* Order here is relevent to prevent deadlocks and use of destroyed
183 sync primitives by kernel threads */
184 thread_sdl_shutdown();
185 SDL_RemoveTimer(tick_timer_id
);
187 sim_kernel_shutdown();
191 #if defined(WIN32) && defined(main)
192 /* Don't use SDL_main on windows -> no more stdio redirection */
196 int main(int argc
, char *argv
[])
200 for (x
= 1; x
< argc
; x
++) {
201 if (!strcmp("--debugaudio", argv
[x
])) {
203 printf("Writing debug audio file.\n");
204 } else if (!strcmp("--debugwps", argv
[x
])) {
206 printf("WPS debug mode enabled.\n");
207 } else if (!strcmp("--background", argv
[x
])) {
209 printf("Using background image.\n");
210 } else if (!strcmp("--old_lcd", argv
[x
])) {
211 having_new_lcd
= false;
212 printf("Using old LCD layout.\n");
213 } else if (!strcmp("--zoom", argv
[x
])) {
216 display_zoom
=atoi(argv
[x
]);
219 printf("Window zoom is %d\n", display_zoom
);
220 } else if (!strcmp("--alarm", argv
[x
])) {
221 sim_alarm_wakeup
= true;
222 printf("Simulating alarm wakeup.\n");
224 printf("rockboxui\n");
225 printf("Arguments:\n");
226 printf(" --debugaudio \t Write raw PCM data to audiodebug.raw\n");
227 printf(" --debugwps \t Print advanced WPS debug info\n");
228 printf(" --background \t Use background image of hardware\n");
229 printf(" --old_lcd \t [Player] simulate old playermodel (ROM version<4.51)\n");
230 printf(" --zoom [VAL]\t window zoom (will disable backgrounds)\n");
231 printf(" --alarm \t Simulate a wakup-up on Alarm\n");
237 if (display_zoom
> 1) {
241 if (!sim_kernel_init()) {
242 fprintf(stderr
, "sim_kernel_init failed\n");
246 if (!sim_io_init()) {
247 fprintf(stderr
, "sim_io_init failed\n");
251 if (!gui_startup()) {
252 fprintf(stderr
, "gui_startup failed\n");
256 /* app_main will be called by the new main thread */
257 if (!thread_sdl_init(NULL
)) {
258 fprintf(stderr
, "thread_sdl_init failed\n");
262 tick_timer_id
= SDL_AddTimer(10, tick_timer
, NULL
);
266 return gui_shutdown();