Add platform file for Ipod 1G / 2G. Now only the front image is missing for building...
[Rockbox.git] / apps / plugins / snow.c
blobc7ebb1864c16559214124233fde4cfe8546ae83d
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 #define SNOW_QUIT BUTTON_POWER
51 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
52 #define SNOW_QUIT BUTTON_POWER
53 #else
54 #define SNOW_QUIT BUTTON_OFF
55 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
56 #define SNOW_RC_QUIT BUTTON_RC_STOP
57 #endif
58 #endif
60 static short particles[NUM_PARTICLES][2];
61 static struct plugin_api* rb;
63 #ifdef HAVE_LCD_BITMAP
64 #if LCD_WIDTH >= 160
65 #define FLAKE_WIDTH 5
66 static const unsigned char flake[] = {0x0a,0x04,0x1f,0x04,0x0a};
67 #else
68 #define FLAKE_WIDTH 3
69 static const unsigned char flake[] = {0x02,0x07,0x02};
70 #endif
71 #endif
73 static bool particle_exists(int particle)
75 if (particles[particle][0]>=0 && particles[particle][1]>=0 &&
76 particles[particle][0]<SNOW_WIDTH && particles[particle][1]<SNOW_HEIGHT)
77 return true;
78 else
79 return false;
82 static int create_particle(void)
84 int i;
86 for (i=0; i<NUM_PARTICLES; i++) {
87 if (!particle_exists(i)) {
88 particles[i][0]=(rb->rand()%SNOW_WIDTH);
89 particles[i][1]=0;
90 return i;
93 return -1;
96 static void snow_move(void)
98 int i;
100 if (!(rb->rand()%2))
101 create_particle();
103 for (i=0; i<NUM_PARTICLES; i++) {
104 if (particle_exists(i)) {
105 MYLCD(set_drawmode)(DRMODE_SOLID|DRMODE_INVERSEVID);
106 #ifdef HAVE_LCD_BITMAP
107 rb->lcd_fillrect(particles[i][0],particles[i][1],
108 FLAKE_WIDTH,FLAKE_WIDTH);
109 #else
110 pgfx_drawpixel(particles[i][0],particles[i][1]);
111 #endif
112 MYLCD(set_drawmode)(DRMODE_SOLID);
113 #ifdef HAVE_REMOTE_LCD
114 if (particles[i][0] <= LCD_REMOTE_WIDTH
115 && particles[i][1] <= LCD_REMOTE_HEIGHT) {
116 rb->lcd_remote_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
117 rb->lcd_remote_fillrect(particles[i][0],particles[i][1],
118 FLAKE_WIDTH,FLAKE_WIDTH);
119 rb->lcd_remote_set_drawmode(DRMODE_SOLID);
121 #endif
122 switch ((rb->rand()%7)) {
123 case 0:
124 particles[i][0]++;
125 break;
127 case 1:
128 particles[i][0]--;
129 break;
131 case 2:
132 break;
134 default:
135 particles[i][1]++;
136 break;
138 if (particle_exists(i))
139 #ifdef HAVE_LCD_BITMAP
140 rb->lcd_mono_bitmap(flake,particles[i][0],particles[i][1],
141 FLAKE_WIDTH,FLAKE_WIDTH);
142 #else
143 pgfx_drawpixel(particles[i][0],particles[i][1]);
144 #endif
145 #ifdef HAVE_REMOTE_LCD
146 if (particles[i][0] <= LCD_REMOTE_WIDTH
147 && particles[i][1] <= LCD_REMOTE_HEIGHT) {
148 rb->lcd_remote_mono_bitmap(flake,particles[i][0],particles[i][1],
149 FLAKE_WIDTH,FLAKE_WIDTH);
151 #endif
157 static void snow_init(void)
159 int i;
161 for (i=0; i<NUM_PARTICLES; i++) {
162 particles[i][0]=-1;
163 particles[i][1]=-1;
165 #ifdef HAVE_LCD_CHARCELLS
166 pgfx_display(0, 0); /* display three times */
167 pgfx_display(4, 0);
168 pgfx_display(8, 0);
169 #endif
170 MYLCD(clear_display)();
171 #ifdef HAVE_REMOTE_LCD
172 rb->lcd_remote_clear_display();
173 #endif
176 enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
178 int button;
179 (void)(parameter);
180 rb = api;
182 #ifdef HAVE_LCD_CHARCELLS
183 if (!pgfx_init(rb, 4, 2))
185 rb->splash(HZ*2, "Old LCD :(");
186 return PLUGIN_OK;
188 #endif
189 snow_init();
190 while (1) {
191 snow_move();
192 MYLCD(update)();
193 #ifdef HAVE_REMOTE_LCD
194 rb->lcd_remote_update();
195 #endif
196 rb->sleep(HZ/20);
198 button = rb->button_get(false);
200 if (button == SNOW_QUIT
201 #ifdef SNOW_RC_QUIT
202 || button == SNOW_RC_QUIT
203 #endif
206 #ifdef HAVE_LCD_CHARCELLS
207 pgfx_release();
208 #endif
209 return PLUGIN_OK;
211 else
212 if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
214 #ifdef HAVE_LCD_CHARCELLS
215 pgfx_release();
216 #endif
217 return PLUGIN_USB_CONNECTED;