A bit of adapting.
[Rockbox.git] / apps / plugins / snow.c
blob47b182299c7c52377c8df75a2acff39cbcd4e834
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 #else
57 #define SNOW_QUIT BUTTON_OFF
58 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
59 #define SNOW_RC_QUIT BUTTON_RC_STOP
60 #endif
61 #endif
63 static short particles[NUM_PARTICLES][2];
64 static struct plugin_api* rb;
66 #ifdef HAVE_LCD_BITMAP
67 #if LCD_WIDTH >= 160
68 #define FLAKE_WIDTH 5
69 static const unsigned char flake[] = {0x0a,0x04,0x1f,0x04,0x0a};
70 #else
71 #define FLAKE_WIDTH 3
72 static const unsigned char flake[] = {0x02,0x07,0x02};
73 #endif
74 #endif
76 static bool particle_exists(int particle)
78 if (particles[particle][0]>=0 && particles[particle][1]>=0 &&
79 particles[particle][0]<SNOW_WIDTH && particles[particle][1]<SNOW_HEIGHT)
80 return true;
81 else
82 return false;
85 static int create_particle(void)
87 int i;
89 for (i=0; i<NUM_PARTICLES; i++) {
90 if (!particle_exists(i)) {
91 particles[i][0]=(rb->rand()%SNOW_WIDTH);
92 particles[i][1]=0;
93 return i;
96 return -1;
99 static void snow_move(void)
101 int i;
103 if (!(rb->rand()%2))
104 create_particle();
106 for (i=0; i<NUM_PARTICLES; i++) {
107 if (particle_exists(i)) {
108 MYLCD(set_drawmode)(DRMODE_SOLID|DRMODE_INVERSEVID);
109 #ifdef HAVE_LCD_BITMAP
110 rb->lcd_fillrect(particles[i][0],particles[i][1],
111 FLAKE_WIDTH,FLAKE_WIDTH);
112 #else
113 pgfx_drawpixel(particles[i][0],particles[i][1]);
114 #endif
115 MYLCD(set_drawmode)(DRMODE_SOLID);
116 #ifdef HAVE_REMOTE_LCD
117 if (particles[i][0] <= LCD_REMOTE_WIDTH
118 && particles[i][1] <= LCD_REMOTE_HEIGHT) {
119 rb->lcd_remote_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
120 rb->lcd_remote_fillrect(particles[i][0],particles[i][1],
121 FLAKE_WIDTH,FLAKE_WIDTH);
122 rb->lcd_remote_set_drawmode(DRMODE_SOLID);
124 #endif
125 switch ((rb->rand()%7)) {
126 case 0:
127 particles[i][0]++;
128 break;
130 case 1:
131 particles[i][0]--;
132 break;
134 case 2:
135 break;
137 default:
138 particles[i][1]++;
139 break;
141 if (particle_exists(i))
142 #ifdef HAVE_LCD_BITMAP
143 rb->lcd_mono_bitmap(flake,particles[i][0],particles[i][1],
144 FLAKE_WIDTH,FLAKE_WIDTH);
145 #else
146 pgfx_drawpixel(particles[i][0],particles[i][1]);
147 #endif
148 #ifdef HAVE_REMOTE_LCD
149 if (particles[i][0] <= LCD_REMOTE_WIDTH
150 && particles[i][1] <= LCD_REMOTE_HEIGHT) {
151 rb->lcd_remote_mono_bitmap(flake,particles[i][0],particles[i][1],
152 FLAKE_WIDTH,FLAKE_WIDTH);
154 #endif
160 static void snow_init(void)
162 int i;
164 for (i=0; i<NUM_PARTICLES; i++) {
165 particles[i][0]=-1;
166 particles[i][1]=-1;
168 #ifdef HAVE_LCD_CHARCELLS
169 pgfx_display(0, 0); /* display three times */
170 pgfx_display(4, 0);
171 pgfx_display(8, 0);
172 #endif
173 MYLCD(clear_display)();
174 #ifdef HAVE_REMOTE_LCD
175 rb->lcd_remote_clear_display();
176 #endif
179 enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
181 int button;
182 (void)(parameter);
183 rb = api;
185 #ifdef HAVE_LCD_CHARCELLS
186 if (!pgfx_init(rb, 4, 2))
188 rb->splash(HZ*2, "Old LCD :(");
189 return PLUGIN_OK;
191 #endif
192 #ifdef HAVE_LCD_COLOR
193 rb->lcd_clear_display();
194 rb->lcd_set_foreground(LCD_WHITE);
195 rb->lcd_set_background(LCD_DEFAULT_BG);
196 #endif
197 snow_init();
198 while (1) {
199 snow_move();
200 MYLCD(update)();
201 #ifdef HAVE_REMOTE_LCD
202 rb->lcd_remote_update();
203 #endif
204 rb->sleep(HZ/20);
206 button = rb->button_get(false);
208 if (button == SNOW_QUIT
209 #ifdef SNOW_RC_QUIT
210 || button == SNOW_RC_QUIT
211 #endif
214 #ifdef HAVE_LCD_CHARCELLS
215 pgfx_release();
216 #endif
217 return PLUGIN_OK;
219 else
220 if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
222 #ifdef HAVE_LCD_CHARCELLS
223 pgfx_release();
224 #endif
225 return PLUGIN_USB_CONNECTED;