Hopefully fix FS#8506 (OF cant be loaded on some PP targets). also hopefully fixes...
[Rockbox.git] / apps / plugins / snow.c
blob6550050646861621888d62b3d27815152b796462
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Itai Shaked
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 **************************************************************************/
19 #include "plugin.h"
20 #include "playergfx.h"
22 PLUGIN_HEADER
24 #ifdef HAVE_LCD_BITMAP
25 #define NUM_PARTICLES (LCD_WIDTH * LCD_HEIGHT / 72)
26 #define SNOW_HEIGHT LCD_HEIGHT
27 #define SNOW_WIDTH LCD_WIDTH
28 #define MYLCD(fn) rb->lcd_ ## fn
29 #else
30 #define NUM_PARTICLES 10
31 #define SNOW_HEIGHT 14
32 #define SNOW_WIDTH 20
33 #define MYLCD(fn) pgfx_ ## fn
34 #endif
36 /* variable button definitions */
37 #if CONFIG_KEYPAD == PLAYER_PAD
38 #define SNOW_QUIT BUTTON_STOP
39 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
40 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
41 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
42 #define SNOW_QUIT BUTTON_MENU
43 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
44 #define SNOW_QUIT BUTTON_PLAY
45 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
46 #define SNOW_QUIT BUTTON_POWER
47 #elif CONFIG_KEYPAD == GIGABEAT_PAD
48 #define SNOW_QUIT BUTTON_POWER
49 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
50 (CONFIG_KEYPAD == SANSA_C200_PAD)
51 #define SNOW_QUIT BUTTON_POWER
52 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
53 #define SNOW_QUIT BUTTON_POWER
54 #elif CONFIG_KEYPAD == MROBE500_PAD
55 #define SNOW_QUIT BUTTON_POWER
56 #elif CONFIG_KEYPAD == MROBE100_PAD
57 #define SNOW_QUIT BUTTON_POWER
58 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
59 #define SNOW_QUIT BUTTON_BACK
60 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
61 #define SNOW_QUIT BUTTON_REC
62 #define SNOW_RC_QUIT BUTTON_RC_REC
63 #elif CONFIG_KEYPAD == COWOND2_PAD
64 #define SNOW_QUIT BUTTON_POWER
65 #else
66 #define SNOW_QUIT BUTTON_OFF
67 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
68 #define SNOW_RC_QUIT BUTTON_RC_STOP
69 #endif
70 #endif
72 static short particles[NUM_PARTICLES][2];
73 static struct plugin_api* rb;
75 #ifdef HAVE_LCD_BITMAP
76 #if LCD_WIDTH >= 160
77 #define FLAKE_WIDTH 5
78 static const unsigned char flake[] = {0x0a,0x04,0x1f,0x04,0x0a};
79 #else
80 #define FLAKE_WIDTH 3
81 static const unsigned char flake[] = {0x02,0x07,0x02};
82 #endif
83 #endif
85 static bool particle_exists(int particle)
87 if (particles[particle][0]>=0 && particles[particle][1]>=0 &&
88 particles[particle][0]<SNOW_WIDTH && particles[particle][1]<SNOW_HEIGHT)
89 return true;
90 else
91 return false;
94 static int create_particle(void)
96 int i;
98 for (i=0; i<NUM_PARTICLES; i++) {
99 if (!particle_exists(i)) {
100 particles[i][0]=(rb->rand()%SNOW_WIDTH);
101 particles[i][1]=0;
102 return i;
105 return -1;
108 static void snow_move(void)
110 int i;
112 if (!(rb->rand()%2))
113 create_particle();
115 for (i=0; i<NUM_PARTICLES; i++) {
116 if (particle_exists(i)) {
117 MYLCD(set_drawmode)(DRMODE_SOLID|DRMODE_INVERSEVID);
118 #ifdef HAVE_LCD_BITMAP
119 rb->lcd_fillrect(particles[i][0],particles[i][1],
120 FLAKE_WIDTH,FLAKE_WIDTH);
121 #else
122 pgfx_drawpixel(particles[i][0],particles[i][1]);
123 #endif
124 MYLCD(set_drawmode)(DRMODE_SOLID);
125 #ifdef HAVE_REMOTE_LCD
126 if (particles[i][0] <= LCD_REMOTE_WIDTH
127 && particles[i][1] <= LCD_REMOTE_HEIGHT) {
128 rb->lcd_remote_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
129 rb->lcd_remote_fillrect(particles[i][0],particles[i][1],
130 FLAKE_WIDTH,FLAKE_WIDTH);
131 rb->lcd_remote_set_drawmode(DRMODE_SOLID);
133 #endif
134 switch ((rb->rand()%7)) {
135 case 0:
136 particles[i][0]++;
137 break;
139 case 1:
140 particles[i][0]--;
141 break;
143 case 2:
144 break;
146 default:
147 particles[i][1]++;
148 break;
150 if (particle_exists(i))
151 #ifdef HAVE_LCD_BITMAP
152 rb->lcd_mono_bitmap(flake,particles[i][0],particles[i][1],
153 FLAKE_WIDTH,FLAKE_WIDTH);
154 #else
155 pgfx_drawpixel(particles[i][0],particles[i][1]);
156 #endif
157 #ifdef HAVE_REMOTE_LCD
158 if (particles[i][0] <= LCD_REMOTE_WIDTH
159 && particles[i][1] <= LCD_REMOTE_HEIGHT) {
160 rb->lcd_remote_mono_bitmap(flake,particles[i][0],particles[i][1],
161 FLAKE_WIDTH,FLAKE_WIDTH);
163 #endif
169 static void snow_init(void)
171 int i;
173 for (i=0; i<NUM_PARTICLES; i++) {
174 particles[i][0]=-1;
175 particles[i][1]=-1;
177 #ifdef HAVE_LCD_CHARCELLS
178 pgfx_display(0, 0); /* display three times */
179 pgfx_display(4, 0);
180 pgfx_display(8, 0);
181 #endif
182 MYLCD(clear_display)();
183 #ifdef HAVE_REMOTE_LCD
184 rb->lcd_remote_clear_display();
185 #endif
188 enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
190 int button;
191 (void)(parameter);
192 rb = api;
194 #ifdef HAVE_LCD_CHARCELLS
195 if (!pgfx_init(rb, 4, 2))
197 rb->splash(HZ*2, "Old LCD :(");
198 return PLUGIN_OK;
200 #endif
201 #ifdef HAVE_LCD_COLOR
202 rb->lcd_clear_display();
203 rb->lcd_set_foreground(LCD_WHITE);
204 rb->lcd_set_background(LCD_DEFAULT_BG);
205 #endif
206 snow_init();
207 while (1) {
208 snow_move();
209 MYLCD(update)();
210 #ifdef HAVE_REMOTE_LCD
211 rb->lcd_remote_update();
212 #endif
213 rb->sleep(HZ/20);
215 button = rb->button_get(false);
217 if (button == SNOW_QUIT
218 #ifdef SNOW_RC_QUIT
219 || button == SNOW_RC_QUIT
220 #endif
223 #ifdef HAVE_LCD_CHARCELLS
224 pgfx_release();
225 #endif
226 return PLUGIN_OK;
228 else
229 if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
231 #ifdef HAVE_LCD_CHARCELLS
232 pgfx_release();
233 #endif
234 return PLUGIN_USB_CONNECTED;