Fix red in bootloaders
[maemo-rb.git] / apps / plugins / snow.c
blobfe10e3995ba1a1ad23b3a32700cdb5e3113e1364
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Itai Shaked
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"
24 PLUGIN_HEADER
26 #ifdef HAVE_LCD_BITMAP
27 #define NUM_PARTICLES (LCD_WIDTH * LCD_HEIGHT / 72)
28 #define SNOW_HEIGHT LCD_HEIGHT
29 #define SNOW_WIDTH LCD_WIDTH
30 #define MYLCD(fn) rb->lcd_ ## fn
31 #else
32 #define NUM_PARTICLES 10
33 #define SNOW_HEIGHT 14
34 #define SNOW_WIDTH 20
35 #define MYLCD(fn) pgfx_ ## fn
36 #endif
38 /* variable button definitions */
39 #if CONFIG_KEYPAD == PLAYER_PAD
40 #define SNOW_QUIT BUTTON_STOP
42 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
43 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
44 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
45 #define SNOW_QUIT BUTTON_MENU
47 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
48 #define SNOW_QUIT BUTTON_PLAY
50 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
51 (CONFIG_KEYPAD == SANSA_C200_PAD) || \
52 (CONFIG_KEYPAD == SANSA_CLIP_PAD) || \
53 (CONFIG_KEYPAD == SANSA_M200_PAD) || \
54 (CONFIG_KEYPAD == MROBE500_PAD) || \
55 (CONFIG_KEYPAD == IRIVER_H10_PAD) || \
56 (CONFIG_KEYPAD == MROBE100_PAD) || \
57 (CONFIG_KEYPAD == COWOND2_PAD) || \
58 (CONFIG_KEYPAD == IAUDIO67_PAD) || \
59 (CONFIG_KEYPAD == PHILIPS_HDD1630_PAD) || \
60 (CONFIG_KEYPAD == ONDAVX747_PAD) || \
61 (CONFIG_KEYPAD == GIGABEAT_PAD) || \
62 (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
63 #define SNOW_QUIT BUTTON_POWER
65 #elif (CONFIG_KEYPAD == SANSA_FUZE_PAD)
66 #define SNOW_QUIT (BUTTON_HOME|BUTTON_REPEAT)
68 #elif (CONFIG_KEYPAD == GIGABEAT_S_PAD) || \
69 (CONFIG_KEYPAD == CREATIVEZVM_PAD)
70 #define SNOW_QUIT BUTTON_BACK
72 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
73 #define SNOW_QUIT BUTTON_REC
74 #define SNOW_RC_QUIT BUTTON_RC_REC
76 #else
77 #define SNOW_QUIT BUTTON_OFF
78 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
79 #define SNOW_RC_QUIT BUTTON_RC_STOP
80 #endif
81 #endif
83 static short particles[NUM_PARTICLES][2];
85 #ifdef HAVE_LCD_BITMAP
86 #if LCD_WIDTH >= 160
87 #define FLAKE_WIDTH 5
88 static const unsigned char flake[] = {0x0a,0x04,0x1f,0x04,0x0a};
89 #else
90 #define FLAKE_WIDTH 3
91 static const unsigned char flake[] = {0x02,0x07,0x02};
92 #endif
93 #endif
95 static bool particle_exists(int particle)
97 if (particles[particle][0]>=0 && particles[particle][1]>=0 &&
98 particles[particle][0]<SNOW_WIDTH && particles[particle][1]<SNOW_HEIGHT)
99 return true;
100 else
101 return false;
104 static int create_particle(void)
106 int i;
108 for (i=0; i<NUM_PARTICLES; i++) {
109 if (!particle_exists(i)) {
110 particles[i][0]=(rb->rand()%SNOW_WIDTH);
111 particles[i][1]=0;
112 return i;
115 return -1;
118 static void snow_move(void)
120 int i;
122 if (!(rb->rand()%2))
123 create_particle();
125 for (i=0; i<NUM_PARTICLES; i++) {
126 if (particle_exists(i)) {
127 MYLCD(set_drawmode)(DRMODE_SOLID|DRMODE_INVERSEVID);
128 #ifdef HAVE_LCD_BITMAP
129 rb->lcd_fillrect(particles[i][0],particles[i][1],
130 FLAKE_WIDTH,FLAKE_WIDTH);
131 #else
132 pgfx_drawpixel(particles[i][0],particles[i][1]);
133 #endif
134 MYLCD(set_drawmode)(DRMODE_SOLID);
135 #ifdef HAVE_REMOTE_LCD
136 if (particles[i][0] <= LCD_REMOTE_WIDTH
137 && particles[i][1] <= LCD_REMOTE_HEIGHT) {
138 rb->lcd_remote_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
139 rb->lcd_remote_fillrect(particles[i][0],particles[i][1],
140 FLAKE_WIDTH,FLAKE_WIDTH);
141 rb->lcd_remote_set_drawmode(DRMODE_SOLID);
143 #endif
144 switch ((rb->rand()%7)) {
145 case 0:
146 particles[i][0]++;
147 break;
149 case 1:
150 particles[i][0]--;
151 break;
153 case 2:
154 break;
156 default:
157 particles[i][1]++;
158 break;
160 if (particle_exists(i))
161 #ifdef HAVE_LCD_BITMAP
162 rb->lcd_mono_bitmap(flake,particles[i][0],particles[i][1],
163 FLAKE_WIDTH,FLAKE_WIDTH);
164 #else
165 pgfx_drawpixel(particles[i][0],particles[i][1]);
166 #endif
167 #ifdef HAVE_REMOTE_LCD
168 if (particles[i][0] <= LCD_REMOTE_WIDTH
169 && particles[i][1] <= LCD_REMOTE_HEIGHT) {
170 rb->lcd_remote_mono_bitmap(flake,particles[i][0],particles[i][1],
171 FLAKE_WIDTH,FLAKE_WIDTH);
173 #endif
179 static void snow_init(void)
181 int i;
183 for (i=0; i<NUM_PARTICLES; i++) {
184 particles[i][0]=-1;
185 particles[i][1]=-1;
187 #ifdef HAVE_LCD_CHARCELLS
188 pgfx_display(0, 0); /* display three times */
189 pgfx_display(4, 0);
190 pgfx_display(8, 0);
191 #endif
192 MYLCD(clear_display)();
193 #ifdef HAVE_REMOTE_LCD
194 rb->lcd_remote_clear_display();
195 #endif
198 enum plugin_status plugin_start(const void* parameter)
200 int button;
201 (void)(parameter);
203 #ifdef HAVE_LCD_CHARCELLS
204 if (!pgfx_init(4, 2))
206 rb->splash(HZ*2, "Old LCD :(");
207 return PLUGIN_OK;
209 #endif
210 #ifdef HAVE_LCD_COLOR
211 rb->lcd_clear_display();
212 rb->lcd_set_foreground(LCD_WHITE);
213 rb->lcd_set_background(LCD_DEFAULT_BG);
214 #endif
215 snow_init();
216 while (1) {
217 snow_move();
218 MYLCD(update)();
219 #ifdef HAVE_REMOTE_LCD
220 rb->lcd_remote_update();
221 #endif
222 rb->sleep(HZ/20);
224 button = rb->button_get(false);
226 if (button == SNOW_QUIT
227 #ifdef SNOW_RC_QUIT
228 || button == SNOW_RC_QUIT
229 #endif
232 #ifdef HAVE_LCD_CHARCELLS
233 pgfx_release();
234 #endif
235 return PLUGIN_OK;
237 else
238 if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
240 #ifdef HAVE_LCD_CHARCELLS
241 pgfx_release();
242 #endif
243 return PLUGIN_USB_CONNECTED;