New makefile solution: A single invocation of 'make' to build the entire tree. Fully...
[kugel-rb.git] / apps / plugins / snow.c
blob28315cc34f3650dd1c9c7df1ce0cdd2a1e84d195
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
41 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
42 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
43 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
44 #define SNOW_QUIT BUTTON_MENU
45 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
46 #define SNOW_QUIT BUTTON_PLAY
47 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
48 #define SNOW_QUIT BUTTON_POWER
49 #elif CONFIG_KEYPAD == GIGABEAT_PAD
50 #define SNOW_QUIT BUTTON_POWER
51 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
52 (CONFIG_KEYPAD == SANSA_C200_PAD)
53 #define SNOW_QUIT BUTTON_POWER
54 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
55 #define SNOW_QUIT BUTTON_POWER
56 #elif CONFIG_KEYPAD == MROBE500_PAD
57 #define SNOW_QUIT BUTTON_POWER
58 #elif CONFIG_KEYPAD == MROBE100_PAD
59 #define SNOW_QUIT BUTTON_POWER
60 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
61 #define SNOW_QUIT BUTTON_BACK
62 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
63 #define SNOW_QUIT BUTTON_REC
64 #define SNOW_RC_QUIT BUTTON_RC_REC
65 #elif CONFIG_KEYPAD == COWOND2_PAD
66 #define SNOW_QUIT BUTTON_POWER
67 #elif CONFIG_KEYPAD == IAUDIO67_PAD
68 #define SNOW_QUIT BUTTON_POWER
69 #else
70 #define SNOW_QUIT BUTTON_OFF
71 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
72 #define SNOW_RC_QUIT BUTTON_RC_STOP
73 #endif
74 #endif
76 static short particles[NUM_PARTICLES][2];
77 static const struct plugin_api* rb;
79 #ifdef HAVE_LCD_BITMAP
80 #if LCD_WIDTH >= 160
81 #define FLAKE_WIDTH 5
82 static const unsigned char flake[] = {0x0a,0x04,0x1f,0x04,0x0a};
83 #else
84 #define FLAKE_WIDTH 3
85 static const unsigned char flake[] = {0x02,0x07,0x02};
86 #endif
87 #endif
89 static bool particle_exists(int particle)
91 if (particles[particle][0]>=0 && particles[particle][1]>=0 &&
92 particles[particle][0]<SNOW_WIDTH && particles[particle][1]<SNOW_HEIGHT)
93 return true;
94 else
95 return false;
98 static int create_particle(void)
100 int i;
102 for (i=0; i<NUM_PARTICLES; i++) {
103 if (!particle_exists(i)) {
104 particles[i][0]=(rb->rand()%SNOW_WIDTH);
105 particles[i][1]=0;
106 return i;
109 return -1;
112 static void snow_move(void)
114 int i;
116 if (!(rb->rand()%2))
117 create_particle();
119 for (i=0; i<NUM_PARTICLES; i++) {
120 if (particle_exists(i)) {
121 MYLCD(set_drawmode)(DRMODE_SOLID|DRMODE_INVERSEVID);
122 #ifdef HAVE_LCD_BITMAP
123 rb->lcd_fillrect(particles[i][0],particles[i][1],
124 FLAKE_WIDTH,FLAKE_WIDTH);
125 #else
126 pgfx_drawpixel(particles[i][0],particles[i][1]);
127 #endif
128 MYLCD(set_drawmode)(DRMODE_SOLID);
129 #ifdef HAVE_REMOTE_LCD
130 if (particles[i][0] <= LCD_REMOTE_WIDTH
131 && particles[i][1] <= LCD_REMOTE_HEIGHT) {
132 rb->lcd_remote_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
133 rb->lcd_remote_fillrect(particles[i][0],particles[i][1],
134 FLAKE_WIDTH,FLAKE_WIDTH);
135 rb->lcd_remote_set_drawmode(DRMODE_SOLID);
137 #endif
138 switch ((rb->rand()%7)) {
139 case 0:
140 particles[i][0]++;
141 break;
143 case 1:
144 particles[i][0]--;
145 break;
147 case 2:
148 break;
150 default:
151 particles[i][1]++;
152 break;
154 if (particle_exists(i))
155 #ifdef HAVE_LCD_BITMAP
156 rb->lcd_mono_bitmap(flake,particles[i][0],particles[i][1],
157 FLAKE_WIDTH,FLAKE_WIDTH);
158 #else
159 pgfx_drawpixel(particles[i][0],particles[i][1]);
160 #endif
161 #ifdef HAVE_REMOTE_LCD
162 if (particles[i][0] <= LCD_REMOTE_WIDTH
163 && particles[i][1] <= LCD_REMOTE_HEIGHT) {
164 rb->lcd_remote_mono_bitmap(flake,particles[i][0],particles[i][1],
165 FLAKE_WIDTH,FLAKE_WIDTH);
167 #endif
173 static void snow_init(void)
175 int i;
177 for (i=0; i<NUM_PARTICLES; i++) {
178 particles[i][0]=-1;
179 particles[i][1]=-1;
181 #ifdef HAVE_LCD_CHARCELLS
182 pgfx_display(0, 0); /* display three times */
183 pgfx_display(4, 0);
184 pgfx_display(8, 0);
185 #endif
186 MYLCD(clear_display)();
187 #ifdef HAVE_REMOTE_LCD
188 rb->lcd_remote_clear_display();
189 #endif
192 enum plugin_status plugin_start(const struct plugin_api* api, const void* parameter)
194 int button;
195 (void)(parameter);
196 rb = api;
198 #ifdef HAVE_LCD_CHARCELLS
199 if (!pgfx_init(rb, 4, 2))
201 rb->splash(HZ*2, "Old LCD :(");
202 return PLUGIN_OK;
204 #endif
205 #ifdef HAVE_LCD_COLOR
206 rb->lcd_clear_display();
207 rb->lcd_set_foreground(LCD_WHITE);
208 rb->lcd_set_background(LCD_DEFAULT_BG);
209 #endif
210 snow_init();
211 while (1) {
212 snow_move();
213 MYLCD(update)();
214 #ifdef HAVE_REMOTE_LCD
215 rb->lcd_remote_update();
216 #endif
217 rb->sleep(HZ/20);
219 button = rb->button_get(false);
221 if (button == SNOW_QUIT
222 #ifdef SNOW_RC_QUIT
223 || button == SNOW_RC_QUIT
224 #endif
227 #ifdef HAVE_LCD_CHARCELLS
228 pgfx_release();
229 #endif
230 return PLUGIN_OK;
232 else
233 if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
235 #ifdef HAVE_LCD_CHARCELLS
236 pgfx_release();
237 #endif
238 return PLUGIN_USB_CONNECTED;