Create system-sdl.c in the target tree and move early initialization into a system_in...
[kugel-rb.git] / uisimulator / sdl / uisdl.c
blobb1448e1d36f932e1e02098d395e8baa6659c7edb
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
22 #include <stdlib.h>
23 #include <string.h>
24 #include <setjmp.h>
25 #include "autoconf.h"
26 #include "button.h"
27 #include "system.h"
28 #include "thread.h"
29 #include "kernel.h"
30 #include "uisdl.h"
31 #include "lcd-sdl.h"
32 #ifdef HAVE_LCD_BITMAP
33 #include "lcd-bitmap.h"
34 #elif defined(HAVE_LCD_CHARCELLS)
35 #include "lcd-charcells.h"
36 #endif
37 #ifdef HAVE_REMOTE_LCD
38 #include "lcd-remote-bitmap.h"
39 #endif
40 #include "thread-sdl.h"
41 #include "SDL_mutex.h"
42 #include "SDL_thread.h"
43 #include "math.h"
46 /* extern functions */
47 extern void new_key(int key);
48 extern int xy2button( int x, int y);
49 void button_event(int key, bool pressed);
51 SDL_Surface *gui_surface;
52 bool background = true; /* use backgrounds by default */
53 #ifdef HAVE_REMOTE_LCD
54 bool showremote = true; /* include remote by default */
55 #endif
56 bool mapping = false;
57 bool debug_buttons = false;
59 bool lcd_display_redraw = true; /* Used for player simulator */
60 char having_new_lcd = true; /* Used for player simulator */
61 bool sim_alarm_wakeup = false;
62 const char *sim_root_dir = NULL;
64 #ifdef DEBUG
65 bool debug_audio = false;
66 #endif
68 bool debug_wps = false;
69 int wps_verbose_level = 3;
71 #if defined(WIN32) && defined(main)
72 /* Don't use SDL_main on windows -> no more stdio redirection */
73 #undef main
74 #endif
75 int main(int argc, char *argv[])
77 if (argc >= 1)
79 int x;
80 for (x = 1; x < argc; x++)
82 #ifdef DEBUG
83 if (!strcmp("--debugaudio", argv[x]))
85 debug_audio = true;
86 printf("Writing debug audio file.\n");
88 else
89 #endif
90 if (!strcmp("--debugwps", argv[x]))
92 debug_wps = true;
93 printf("WPS debug mode enabled.\n");
95 else if (!strcmp("--nobackground", argv[x]))
97 background = false;
98 printf("Disabling background image.\n");
100 #ifdef HAVE_REMOTE_LCD
101 else if (!strcmp("--noremote", argv[x]))
103 showremote = false;
104 background = false;
105 printf("Disabling remote image.\n");
107 #endif
108 else if (!strcmp("--old_lcd", argv[x]))
110 having_new_lcd = false;
111 printf("Using old LCD layout.\n");
113 else if (!strcmp("--zoom", argv[x]))
115 x++;
116 if(x < argc)
117 display_zoom=atoi(argv[x]);
118 else
119 display_zoom = 2;
120 printf("Window zoom is %d\n", display_zoom);
122 else if (!strcmp("--alarm", argv[x]))
124 sim_alarm_wakeup = true;
125 printf("Simulating alarm wakeup.\n");
127 else if (!strcmp("--root", argv[x]))
129 x++;
130 if (x < argc)
132 sim_root_dir = argv[x];
133 printf("Root directory: %s\n", sim_root_dir);
136 else if (!strcmp("--mapping", argv[x]))
138 mapping = true;
139 printf("Printing click coords with drag radii.\n");
141 else if (!strcmp("--debugbuttons", argv[x]))
143 debug_buttons = true;
144 printf("Printing background button clicks.\n");
146 else
148 printf("rockboxui\n");
149 printf("Arguments:\n");
150 #ifdef DEBUG
151 printf(" --debugaudio \t Write raw PCM data to audiodebug.raw\n");
152 #endif
153 printf(" --debugwps \t Print advanced WPS debug info\n");
154 printf(" --nobackground \t Disable the background image\n");
155 #ifdef HAVE_REMOTE_LCD
156 printf(" --noremote \t Disable the remote image (will disable backgrounds)\n");
157 #endif
158 printf(" --old_lcd \t [Player] simulate old playermodel (ROM version<4.51)\n");
159 printf(" --zoom [VAL]\t Window zoom (will disable backgrounds)\n");
160 printf(" --alarm \t Simulate a wake-up on alarm\n");
161 printf(" --root [DIR]\t Set root directory\n");
162 printf(" --mapping \t Output coordinates and radius for mapping backgrounds\n");
163 exit(0);
168 if (display_zoom > 1) {
169 background = false;
172 /* need to call it here for the time being, before enabling threads */
173 system_init();
174 struct thread_entry *t = NULL;
175 int status = 0;
176 /* app_main will be called by the new main thread */
177 if (!thread_sdl_init(&t)) {
178 fprintf(stderr, "thread_sdl_init failed\n");
179 return -1;
182 /* HACK!! */
183 if (t)
184 SDL_WaitThread(t->context.t, &status);
186 sys_poweroff();
187 return 0;