summaryrefslogtreecommitdiff
path: root/firmware/target/hosted/sdl/system-sdl.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/hosted/sdl/system-sdl.c')
-rw-r--r--firmware/target/hosted/sdl/system-sdl.c236
1 files changed, 236 insertions, 0 deletions
diff --git a/firmware/target/hosted/sdl/system-sdl.c b/firmware/target/hosted/sdl/system-sdl.c
new file mode 100644
index 0000000000..693e8d1b57
--- /dev/null
+++ b/firmware/target/hosted/sdl/system-sdl.c
@@ -0,0 +1,236 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 by Daniel Everton <dan@iocaine.org>
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include <SDL.h>
23#include <stdlib.h>
24#include <string.h>
25#include <setjmp.h>
26#include "system-sdl.h"
27#include "thread-sdl.h"
28#include "sim-ui-defines.h"
29#include "lcd-sdl.h"
30#ifdef HAVE_LCD_BITMAP
31#include "lcd-bitmap.h"
32#elif defined(HAVE_LCD_CHARCELLS)
33#include "lcd-charcells.h"
34#endif
35#ifdef HAVE_REMOTE_LCD
36#include "lcd-remote-bitmap.h"
37#endif
38#include "panic.h"
39#include "debug.h"
40
41SDL_Surface *gui_surface;
42
43bool background = true; /* use backgrounds by default */
44#ifdef HAVE_REMOTE_LCD
45bool showremote = true; /* include remote by default */
46#endif
47bool mapping = false;
48bool debug_buttons = false;
49
50bool lcd_display_redraw = true; /* Used for player simulator */
51char having_new_lcd = true; /* Used for player simulator */
52bool sim_alarm_wakeup = false;
53const char *sim_root_dir = NULL;
54extern int display_zoom;
55
56#ifdef DEBUG
57bool debug_audio = false;
58#endif
59
60bool debug_wps = false;
61int wps_verbose_level = 3;
62
63
64void sys_poweroff(void)
65{
66 /* Order here is relevent to prevent deadlocks and use of destroyed
67 sync primitives by kernel threads */
68 sim_thread_shutdown();
69 sim_kernel_shutdown();
70 SDL_Quit();
71}
72
73void system_init(void)
74{
75 SDL_Surface *picture_surface;
76 int width, height;
77
78 if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER))
79 panicf("%s", SDL_GetError());
80
81 /* Try and load the background image. If it fails go without */
82 if (background) {
83 picture_surface = SDL_LoadBMP("UI256.bmp");
84 if (picture_surface == NULL) {
85 background = false;
86 DEBUGF("warn: %s\n", SDL_GetError());
87 }
88 }
89
90 /* Set things up */
91 if (background)
92 {
93 width = UI_WIDTH;
94 height = UI_HEIGHT;
95 }
96 else
97 {
98#ifdef HAVE_REMOTE_LCD
99 if (showremote)
100 {
101 width = SIM_LCD_WIDTH > SIM_REMOTE_WIDTH ? SIM_LCD_WIDTH : SIM_REMOTE_WIDTH;
102 height = SIM_LCD_HEIGHT + SIM_REMOTE_HEIGHT;
103 }
104 else
105#endif
106 {
107 width = SIM_LCD_WIDTH;
108 height = SIM_LCD_HEIGHT;
109 }
110 }
111
112
113 if ((gui_surface = SDL_SetVideoMode(width * display_zoom, height * display_zoom, 24, SDL_HWSURFACE|SDL_DOUBLEBUF)) == NULL) {
114 panicf("%s", SDL_GetError());
115 }
116
117 SDL_WM_SetCaption(UI_TITLE, NULL);
118
119 sim_lcd_init();
120#ifdef HAVE_REMOTE_LCD
121 if (showremote)
122 sim_lcd_remote_init();
123#endif
124
125 if (background && picture_surface != NULL) {
126 SDL_BlitSurface(picture_surface, NULL, gui_surface, NULL);
127 SDL_UpdateRect(gui_surface, 0, 0, 0, 0);
128 }
129}
130
131void system_exception_wait(void)
132{
133 sim_thread_exception_wait();
134}
135
136void system_reboot(void)
137{
138 sim_thread_exception_wait();
139}
140
141void sys_handle_argv(int argc, char *argv[])
142{
143 if (argc >= 1)
144 {
145 int x;
146 for (x = 1; x < argc; x++)
147 {
148#ifdef DEBUG
149 if (!strcmp("--debugaudio", argv[x]))
150 {
151 debug_audio = true;
152 printf("Writing debug audio file.\n");
153 }
154 else
155#endif
156 if (!strcmp("--debugwps", argv[x]))
157 {
158 debug_wps = true;
159 printf("WPS debug mode enabled.\n");
160 }
161 else if (!strcmp("--nobackground", argv[x]))
162 {
163 background = false;
164 printf("Disabling background image.\n");
165 }
166#ifdef HAVE_REMOTE_LCD
167 else if (!strcmp("--noremote", argv[x]))
168 {
169 showremote = false;
170 background = false;
171 printf("Disabling remote image.\n");
172 }
173#endif
174 else if (!strcmp("--old_lcd", argv[x]))
175 {
176 having_new_lcd = false;
177 printf("Using old LCD layout.\n");
178 }
179 else if (!strcmp("--zoom", argv[x]))
180 {
181 x++;
182 if(x < argc)
183 display_zoom=atoi(argv[x]);
184 else
185 display_zoom = 2;
186 printf("Window zoom is %d\n", display_zoom);
187 }
188 else if (!strcmp("--alarm", argv[x]))
189 {
190 sim_alarm_wakeup = true;
191 printf("Simulating alarm wakeup.\n");
192 }
193 else if (!strcmp("--root", argv[x]))
194 {
195 x++;
196 if (x < argc)
197 {
198 sim_root_dir = argv[x];
199 printf("Root directory: %s\n", sim_root_dir);
200 }
201 }
202 else if (!strcmp("--mapping", argv[x]))
203 {
204 mapping = true;
205 printf("Printing click coords with drag radii.\n");
206 }
207 else if (!strcmp("--debugbuttons", argv[x]))
208 {
209 debug_buttons = true;
210 printf("Printing background button clicks.\n");
211 }
212 else
213 {
214 printf("rockboxui\n");
215 printf("Arguments:\n");
216#ifdef DEBUG
217 printf(" --debugaudio \t Write raw PCM data to audiodebug.raw\n");
218#endif
219 printf(" --debugwps \t Print advanced WPS debug info\n");
220 printf(" --nobackground \t Disable the background image\n");
221#ifdef HAVE_REMOTE_LCD
222 printf(" --noremote \t Disable the remote image (will disable backgrounds)\n");
223#endif
224 printf(" --old_lcd \t [Player] simulate old playermodel (ROM version<4.51)\n");
225 printf(" --zoom [VAL]\t Window zoom (will disable backgrounds)\n");
226 printf(" --alarm \t Simulate a wake-up on alarm\n");
227 printf(" --root [DIR]\t Set root directory\n");
228 printf(" --mapping \t Output coordinates and radius for mapping backgrounds\n");
229 exit(0);
230 }
231 }
232 }
233 if (display_zoom > 1) {
234 background = false;
235 }
236}