core_alloc: Provide a tiny test allocation, which can be freed for debug purposes.
[maemo-rb.git] / apps / plugins / logo.c
blobdc0db8e95a3a7289eee9ddb26c4b376538b7dfac
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2005 Jonas H�gqvist
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 **************************************************************************/
21 #include "plugin.h"
22 #include "lib/playergfx.h"
26 #ifdef HAVE_LCD_BITMAP
27 #define DISPLAY_WIDTH LCD_WIDTH
28 #define DISPLAY_HEIGHT LCD_HEIGHT
29 #define RAND_SCALE 5
31 #ifdef HAVE_REMOTE_LCD
32 #define REMOTE_WIDTH LCD_REMOTE_WIDTH
33 #define REMOTE_HEIGHT LCD_REMOTE_HEIGHT
34 #include "pluginbitmaps/remote_rockboxlogo.h"
35 #define REMOTE_LOGO_WIDTH BMPWIDTH_remote_rockboxlogo
36 #define REMOTE_LOGO_HEIGHT BMPHEIGHT_remote_rockboxlogo
37 #define REMOTE_LOGO remote_rockboxlogo
38 extern const fb_remote_data remote_rockboxlogo[];
39 #endif /* HAVE_REMOTE_LCD */
41 #define LOGO rockboxlogo
42 #include "pluginbitmaps/rockboxlogo.h"
43 #define LOGO_WIDTH BMPWIDTH_rockboxlogo
44 #define LOGO_HEIGHT BMPHEIGHT_rockboxlogo
45 extern const fb_data rockboxlogo[];
47 #else /* !LCD_BITMAP */
48 #define DISPLAY_WIDTH 55
49 #define DISPLAY_HEIGHT 14
50 #define RAND_SCALE 2
51 #define LOGO_WIDTH 16
52 #define LOGO_HEIGHT 7
53 #define LOGO rockbox16x7
54 const unsigned char rockbox16x7[] = {
55 0x47, 0x18, 0xa6, 0xd8, 0x66, 0xde, 0xb7, 0x9b,
56 0x76, 0xdb, 0x26, 0xdb, 0x66, 0xde,
58 #endif /* !LCD_BITMAP */
60 /* variable button definitions */
61 #if CONFIG_KEYPAD == PLAYER_PAD
62 #define LP_QUIT BUTTON_STOP
63 #define LP_DEC_X BUTTON_LEFT
64 #define LP_INC_X BUTTON_RIGHT
65 #define LP_DEC_Y (BUTTON_ON | BUTTON_LEFT)
66 #define LP_INC_Y (BUTTON_ON | BUTTON_RIGHT)
68 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
69 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
70 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
71 #define LP_QUIT BUTTON_MENU
72 #define LP_DEC_X BUTTON_LEFT
73 #define LP_INC_X BUTTON_RIGHT
74 #define LP_DEC_Y BUTTON_SCROLL_BACK
75 #define LP_INC_Y BUTTON_SCROLL_FWD
77 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
78 #define LP_QUIT BUTTON_PLAY
79 #define LP_DEC_X BUTTON_LEFT
80 #define LP_INC_X BUTTON_RIGHT
81 #define LP_DEC_Y BUTTON_DOWN
82 #define LP_INC_Y BUTTON_UP
84 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
85 #define LP_QUIT BUTTON_POWER
86 #define LP_DEC_X BUTTON_LEFT
87 #define LP_INC_X BUTTON_RIGHT
88 #define LP_DEC_Y BUTTON_DOWN
89 #define LP_INC_Y BUTTON_UP
91 #elif CONFIG_KEYPAD == GIGABEAT_PAD
92 #define LP_QUIT BUTTON_POWER
93 #define LP_DEC_X BUTTON_LEFT
94 #define LP_INC_X BUTTON_RIGHT
95 #define LP_DEC_Y BUTTON_DOWN
96 #define LP_INC_Y BUTTON_UP
98 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
99 (CONFIG_KEYPAD == SANSA_C200_PAD) || \
100 (CONFIG_KEYPAD == SANSA_CLIP_PAD) || \
101 (CONFIG_KEYPAD == SANSA_M200_PAD)
102 #define LP_QUIT BUTTON_POWER
103 #define LP_DEC_X BUTTON_LEFT
104 #define LP_INC_X BUTTON_RIGHT
105 #define LP_DEC_Y BUTTON_DOWN
106 #define LP_INC_Y BUTTON_UP
108 #elif (CONFIG_KEYPAD == SANSA_FUZE_PAD)
109 #define LP_QUIT (BUTTON_HOME|BUTTON_REPEAT)
110 #define LP_DEC_X BUTTON_LEFT
111 #define LP_INC_X BUTTON_RIGHT
112 #define LP_DEC_Y BUTTON_DOWN
113 #define LP_INC_Y BUTTON_UP
115 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
116 #define LP_QUIT BUTTON_POWER
117 #define LP_DEC_X BUTTON_LEFT
118 #define LP_INC_X BUTTON_RIGHT
119 #define LP_DEC_Y BUTTON_SCROLL_DOWN
120 #define LP_INC_Y BUTTON_SCROLL_UP
122 #elif CONFIG_KEYPAD == MROBE500_PAD
123 #define LP_QUIT BUTTON_POWER
125 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
126 #define LP_QUIT BUTTON_BACK
127 #define LP_DEC_X BUTTON_LEFT
128 #define LP_INC_X BUTTON_RIGHT
129 #define LP_DEC_Y BUTTON_DOWN
130 #define LP_INC_Y BUTTON_UP
132 #elif CONFIG_KEYPAD == MROBE100_PAD
133 #define LP_QUIT BUTTON_POWER
134 #define LP_DEC_X BUTTON_LEFT
135 #define LP_INC_X BUTTON_RIGHT
136 #define LP_DEC_Y BUTTON_DOWN
137 #define LP_INC_Y BUTTON_UP
139 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
140 #define LP_QUIT BUTTON_RC_REC
141 #define LP_DEC_X BUTTON_RC_REW
142 #define LP_INC_X BUTTON_RC_FF
143 #define LP_DEC_Y BUTTON_RC_VOL_DOWN
144 #define LP_INC_Y BUTTON_RC_VOL_UP
146 #elif CONFIG_KEYPAD == COWON_D2_PAD
147 #define LP_QUIT BUTTON_POWER
149 #elif CONFIG_KEYPAD == IAUDIO67_PAD
150 #define LP_QUIT BUTTON_POWER
151 #define LP_DEC_X BUTTON_LEFT
152 #define LP_INC_X BUTTON_RIGHT
153 #define LP_DEC_Y BUTTON_PLAY
154 #define LP_INC_Y BUTTON_STOP
156 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
157 #define LP_QUIT BUTTON_BACK
158 #define LP_DEC_X BUTTON_LEFT
159 #define LP_INC_X BUTTON_RIGHT
160 #define LP_DEC_Y BUTTON_DOWN
161 #define LP_INC_Y BUTTON_UP
163 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
164 #define LP_QUIT BUTTON_POWER
165 #define LP_DEC_X BUTTON_LEFT
166 #define LP_INC_X BUTTON_RIGHT
167 #define LP_DEC_Y BUTTON_DOWN
168 #define LP_INC_Y BUTTON_UP
170 #elif CONFIG_KEYPAD == PHILIPS_HDD6330_PAD
171 #define LP_QUIT BUTTON_POWER
172 #define LP_DEC_X BUTTON_LEFT
173 #define LP_INC_X BUTTON_RIGHT
174 #define LP_DEC_Y BUTTON_DOWN
175 #define LP_INC_Y BUTTON_UP
177 #elif CONFIG_KEYPAD == PHILIPS_SA9200_PAD
178 #define LP_QUIT BUTTON_POWER
179 #define LP_DEC_X BUTTON_PREV
180 #define LP_INC_X BUTTON_NEXT
181 #define LP_DEC_Y BUTTON_DOWN
182 #define LP_INC_Y BUTTON_UP
184 #elif CONFIG_KEYPAD == ONDAVX747_PAD
185 #define LP_QUIT BUTTON_POWER
186 #elif CONFIG_KEYPAD == ONDAVX777_PAD
187 #define LP_QUIT BUTTON_POWER
189 #elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
190 #define LP_QUIT BUTTON_PLAY
191 #define LP_DEC_X BUTTON_LEFT
192 #define LP_INC_X BUTTON_RIGHT
193 #define LP_DEC_Y BUTTON_DOWN
194 #define LP_INC_Y BUTTON_UP
196 #elif CONFIG_KEYPAD == PBELL_VIBE500_PAD
197 #define LP_QUIT BUTTON_REC
198 #define LP_DEC_X BUTTON_PREV
199 #define LP_INC_X BUTTON_NEXT
200 #define LP_DEC_Y BUTTON_DOWN
201 #define LP_INC_Y BUTTON_UP
203 #elif CONFIG_KEYPAD == MPIO_HD200_PAD
204 #define LP_QUIT (BUTTON_REC|BUTTON_PLAY)
205 #define LP_DEC_X BUTTON_VOL_DOWN
206 #define LP_INC_X BUTTON_VOL_UP
207 #define LP_DEC_Y BUTTON_REW
208 #define LP_INC_Y BUTTON_FF
210 #elif CONFIG_KEYPAD == MPIO_HD300_PAD
211 #define LP_QUIT (BUTTON_REC|BUTTON_REPEAT)
212 #define LP_DEC_X BUTTON_REW
213 #define LP_INC_X BUTTON_FF
214 #define LP_DEC_Y BUTTON_DOWN
215 #define LP_INC_Y BUTTON_UP
217 #elif CONFIG_KEYPAD == SANSA_FUZEPLUS_PAD
218 #define LP_QUIT BUTTON_POWER
219 #define LP_DEC_X BUTTON_LEFT
220 #define LP_INC_X BUTTON_RIGHT
221 #define LP_DEC_Y BUTTON_DOWN
222 #define LP_INC_Y BUTTON_UP
224 #else
225 #define LP_QUIT BUTTON_OFF
226 #define LP_DEC_X BUTTON_LEFT
227 #define LP_INC_X BUTTON_RIGHT
228 #define LP_DEC_Y BUTTON_DOWN
229 #define LP_INC_Y BUTTON_UP
230 #endif
232 #ifdef CONFIG_REMOTE_KEYPAD
233 #if (CONFIG_REMOTE_KEYPAD == H100_REMOTE) || \
234 (CONFIG_REMOTE_KEYPAD == H300_REMOTE)
235 #define LP_R_QUIT BUTTON_RC_STOP
236 #define LP_R_DEC_X BUTTON_RC_REW
237 #define LP_R_INC_X BUTTON_RC_FF
238 #define LP_R_DEC_Y BUTTON_RC_SOURCE
239 #define LP_R_INC_Y BUTTON_RC_BITRATE
241 #elif CONFIG_REMOTE_KEYPAD == IAUDIO_REMOTE
242 #define LP_R_QUIT BUTTON_RC_REC
243 #define LP_R_DEC_X BUTTON_RC_REW
244 #define LP_R_INC_X BUTTON_RC_FF
245 #define LP_R_DEC_Y BUTTON_RC_VOL_DOWN
246 #define LP_R_INC_Y BUTTON_RC_VOL_UP
248 #elif (CONFIG_REMOTE_KEYPAD == MROBE_REMOTE)
249 #define LP_R_QUIT BUTTON_RC_HEART
250 #define LP_R_DEC_X BUTTON_RC_REW
251 #define LP_R_INC_X BUTTON_RC_FF
252 #define LP_R_DEC_Y BUTTON_RC_DOWN
253 #define LP_R_INC_Y BUTTON_RC_PLAY
254 #endif
256 #endif /* CONFIG_REMOTE_KEYPAD */
258 #ifdef HAVE_TOUCHSCREEN
259 #ifndef LP_QUIT
260 #define LP_QUIT BUTTON_TOPLEFT
261 #endif
262 #ifndef LP_DEC_X
263 #define LP_DEC_X BUTTON_MIDLEFT
264 #endif
265 #ifndef LP_INC_X
266 #define LP_INC_X BUTTON_MIDRIGHT
267 #endif
268 #ifndef LP_DEC_Y
269 #define LP_DEC_Y BUTTON_TOPMIDDLE
270 #endif
271 #ifndef LP_INC_Y
272 #define LP_INC_Y BUTTON_BOTTOMMIDDLE
273 #endif
274 #endif
276 enum plugin_status plugin_start(const void* parameter) {
277 int button;
278 int timer = 10;
279 int x = (DISPLAY_WIDTH / 2) - (LOGO_WIDTH / 2);
280 int y = (DISPLAY_HEIGHT / 2) - (LOGO_HEIGHT / 2);
281 int dx;
282 int dy;
283 #ifdef HAVE_LCD_CHARCELLS
284 int cpos = -1;
285 int old_cpos = -1;
286 #endif
288 (void)parameter;
290 #ifdef HAVE_LCD_CHARCELLS
291 if (!pgfx_init(4, 2)) {
292 rb->splash(HZ*2, "Old LCD :(");
293 return PLUGIN_OK;
295 #endif
296 rb->srand(*rb->current_tick);
297 dx = rb->rand()%(2*RAND_SCALE+1) - RAND_SCALE;
298 dy = rb->rand()%(2*RAND_SCALE+1) - RAND_SCALE;
300 while (1) {
301 #ifdef HAVE_LCD_BITMAP
302 rb->lcd_clear_display();
303 rb->lcd_bitmap(LOGO, x, y, LOGO_WIDTH, LOGO_HEIGHT);
304 #ifdef REMOTE_LOGO
305 rb->lcd_remote_clear_display();
306 rb->lcd_remote_bitmap(REMOTE_LOGO,
307 (x * (REMOTE_WIDTH - REMOTE_LOGO_WIDTH)) / (DISPLAY_WIDTH - LOGO_WIDTH),
308 (y * (REMOTE_HEIGHT - REMOTE_LOGO_HEIGHT)) / (DISPLAY_HEIGHT - LOGO_HEIGHT),
309 REMOTE_LOGO_WIDTH, REMOTE_LOGO_HEIGHT);
310 #endif
311 #else
312 pgfx_clear_display();
313 pgfx_mono_bitmap(LOGO, x % 5, y, LOGO_WIDTH, LOGO_HEIGHT);
314 cpos = x / 5;
315 #endif
317 x += dx;
318 if (x < 0) {
319 dx = -dx;
320 x = 0;
322 if (x > DISPLAY_WIDTH - LOGO_WIDTH) {
323 dx = -dx;
324 x = DISPLAY_WIDTH - LOGO_WIDTH;
327 y += dy;
328 if (y < 0) {
329 dy = -dy;
330 y = 0;
332 if (y > DISPLAY_HEIGHT - LOGO_HEIGHT) {
333 dy = -dy;
334 y = DISPLAY_HEIGHT - LOGO_HEIGHT;
337 #ifdef HAVE_LCD_BITMAP
338 rb->lcd_update();
339 #ifdef REMOTE_LOGO
340 rb->lcd_remote_update();
341 #endif
342 #else
343 if (cpos != old_cpos) {
344 rb->lcd_clear_display();
345 pgfx_display(cpos, 0);
346 old_cpos = cpos;
348 pgfx_update();
349 #endif
350 rb->sleep(HZ/timer);
352 button = rb->button_get(false);
353 switch (button) {
354 case LP_QUIT:
355 #ifdef CONFIG_REMOTE_KEYPAD
356 case LP_R_QUIT:
357 #endif
358 #ifdef HAVE_LCD_CHARCELLS
359 pgfx_release();
360 #endif
361 return PLUGIN_OK;
362 case LP_DEC_X:
363 #ifdef CONFIG_REMOTE_KEYPAD
364 case LP_R_DEC_X:
365 #endif
366 if (dx)
367 dx += (dx < 0) ? 1 : -1;
368 break;
369 case LP_INC_X:
370 #ifdef CONFIG_REMOTE_KEYPAD
371 case LP_R_INC_X:
372 #endif
373 dx += (dx < 0) ? -1 : 1;
374 break;
375 case LP_DEC_Y:
376 #ifdef CONFIG_REMOTE_KEYPAD
377 case LP_R_DEC_Y:
378 #endif
379 if (dy)
380 dy += (dy < 0) ? 1 : -1;
381 break;
382 case LP_INC_Y:
383 #ifdef CONFIG_REMOTE_KEYPAD
384 case LP_R_INC_Y:
385 #endif
386 dy += (dy < 0) ? -1 : 1;
387 break;
389 default:
390 if (rb->default_event_handler(button) == SYS_USB_CONNECTED) {
391 #ifdef HAVE_LCD_CHARCELLS
392 pgfx_release();
393 #endif
394 return PLUGIN_USB_CONNECTED;
396 break;