Pong: small improvement in the c200 buttonmap; the left paddle is now controlled...
[Rockbox.git] / apps / plugins / snow.c
blob6078f87708a7ed63fe062f69fde0ed71b16b4fa6
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 #else
55 #define SNOW_QUIT BUTTON_OFF
56 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
57 #define SNOW_RC_QUIT BUTTON_RC_STOP
58 #endif
59 #endif
61 static short particles[NUM_PARTICLES][2];
62 static struct plugin_api* rb;
64 #ifdef HAVE_LCD_BITMAP
65 #if LCD_WIDTH >= 160
66 #define FLAKE_WIDTH 5
67 static const unsigned char flake[] = {0x0a,0x04,0x1f,0x04,0x0a};
68 #else
69 #define FLAKE_WIDTH 3
70 static const unsigned char flake[] = {0x02,0x07,0x02};
71 #endif
72 #endif
74 static bool particle_exists(int particle)
76 if (particles[particle][0]>=0 && particles[particle][1]>=0 &&
77 particles[particle][0]<SNOW_WIDTH && particles[particle][1]<SNOW_HEIGHT)
78 return true;
79 else
80 return false;
83 static int create_particle(void)
85 int i;
87 for (i=0; i<NUM_PARTICLES; i++) {
88 if (!particle_exists(i)) {
89 particles[i][0]=(rb->rand()%SNOW_WIDTH);
90 particles[i][1]=0;
91 return i;
94 return -1;
97 static void snow_move(void)
99 int i;
101 if (!(rb->rand()%2))
102 create_particle();
104 for (i=0; i<NUM_PARTICLES; i++) {
105 if (particle_exists(i)) {
106 MYLCD(set_drawmode)(DRMODE_SOLID|DRMODE_INVERSEVID);
107 #ifdef HAVE_LCD_BITMAP
108 rb->lcd_fillrect(particles[i][0],particles[i][1],
109 FLAKE_WIDTH,FLAKE_WIDTH);
110 #else
111 pgfx_drawpixel(particles[i][0],particles[i][1]);
112 #endif
113 MYLCD(set_drawmode)(DRMODE_SOLID);
114 #ifdef HAVE_REMOTE_LCD
115 if (particles[i][0] <= LCD_REMOTE_WIDTH
116 && particles[i][1] <= LCD_REMOTE_HEIGHT) {
117 rb->lcd_remote_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
118 rb->lcd_remote_fillrect(particles[i][0],particles[i][1],
119 FLAKE_WIDTH,FLAKE_WIDTH);
120 rb->lcd_remote_set_drawmode(DRMODE_SOLID);
122 #endif
123 switch ((rb->rand()%7)) {
124 case 0:
125 particles[i][0]++;
126 break;
128 case 1:
129 particles[i][0]--;
130 break;
132 case 2:
133 break;
135 default:
136 particles[i][1]++;
137 break;
139 if (particle_exists(i))
140 #ifdef HAVE_LCD_BITMAP
141 rb->lcd_mono_bitmap(flake,particles[i][0],particles[i][1],
142 FLAKE_WIDTH,FLAKE_WIDTH);
143 #else
144 pgfx_drawpixel(particles[i][0],particles[i][1]);
145 #endif
146 #ifdef HAVE_REMOTE_LCD
147 if (particles[i][0] <= LCD_REMOTE_WIDTH
148 && particles[i][1] <= LCD_REMOTE_HEIGHT) {
149 rb->lcd_remote_mono_bitmap(flake,particles[i][0],particles[i][1],
150 FLAKE_WIDTH,FLAKE_WIDTH);
152 #endif
158 static void snow_init(void)
160 int i;
162 for (i=0; i<NUM_PARTICLES; i++) {
163 particles[i][0]=-1;
164 particles[i][1]=-1;
166 #ifdef HAVE_LCD_CHARCELLS
167 pgfx_display(0, 0); /* display three times */
168 pgfx_display(4, 0);
169 pgfx_display(8, 0);
170 #endif
171 MYLCD(clear_display)();
172 #ifdef HAVE_REMOTE_LCD
173 rb->lcd_remote_clear_display();
174 #endif
177 enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
179 int button;
180 (void)(parameter);
181 rb = api;
183 #ifdef HAVE_LCD_CHARCELLS
184 if (!pgfx_init(rb, 4, 2))
186 rb->splash(HZ*2, "Old LCD :(");
187 return PLUGIN_OK;
189 #endif
190 #ifdef HAVE_LCD_COLOR
191 rb->lcd_clear_display();
192 rb->lcd_set_foreground(LCD_WHITE);
193 rb->lcd_set_background(LCD_DEFAULT_BG);
194 #endif
195 snow_init();
196 while (1) {
197 snow_move();
198 MYLCD(update)();
199 #ifdef HAVE_REMOTE_LCD
200 rb->lcd_remote_update();
201 #endif
202 rb->sleep(HZ/20);
204 button = rb->button_get(false);
206 if (button == SNOW_QUIT
207 #ifdef SNOW_RC_QUIT
208 || button == SNOW_RC_QUIT
209 #endif
212 #ifdef HAVE_LCD_CHARCELLS
213 pgfx_release();
214 #endif
215 return PLUGIN_OK;
217 else
218 if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
220 #ifdef HAVE_LCD_CHARCELLS
221 pgfx_release();
222 #endif
223 return PLUGIN_USB_CONNECTED;