Work-in-progress iriver iFP-7xx port by Tomasz Malesinski
[Rockbox.git] / apps / plugins / snow.c
blob7fd0c8a3d6cba00f0386007ca31709d7737c451e
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 #ifdef HAVE_LCD_BITMAP
23 #define NUM_PARTICLES (LCD_WIDTH * LCD_HEIGHT / 72)
24 #define SNOW_HEIGHT LCD_HEIGHT
25 #define SNOW_WIDTH LCD_WIDTH
26 #define MYLCD(fn) rb->lcd_ ## fn
27 #else
28 #define NUM_PARTICLES 10
29 #define SNOW_HEIGHT 14
30 #define SNOW_WIDTH 20
31 #define MYLCD(fn) pgfx_ ## fn
32 #endif
34 /* variable button definitions */
35 #if CONFIG_KEYPAD == PLAYER_PAD
36 #define SNOW_QUIT BUTTON_STOP
37 #elif (CONFIG_KEYPAD == IPOD_4G_PAD)
38 #define SNOW_QUIT BUTTON_MENU
39 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
40 #define SNOW_QUIT BUTTON_PLAY
41 #else
42 #define SNOW_QUIT BUTTON_OFF
43 #endif
45 static short particles[NUM_PARTICLES][2];
46 static struct plugin_api* rb;
48 #ifdef HAVE_LCD_BITMAP
49 #if LCD_WIDTH >= 160
50 #define FLAKE_WIDTH 5
51 static const unsigned char flake[] = {0x0a,0x04,0x1f,0x04,0x0a};
52 #else
53 #define FLAKE_WIDTH 3
54 static const unsigned char flake[] = {0x02,0x07,0x02};
55 #endif
56 #endif
58 static bool particle_exists(int particle)
60 if (particles[particle][0]>=0 && particles[particle][1]>=0 &&
61 particles[particle][0]<SNOW_WIDTH && particles[particle][1]<SNOW_HEIGHT)
62 return true;
63 else
64 return false;
67 static int create_particle(void)
69 int i;
71 for (i=0; i<NUM_PARTICLES; i++) {
72 if (!particle_exists(i)) {
73 particles[i][0]=(rb->rand()%SNOW_WIDTH);
74 particles[i][1]=0;
75 return i;
78 return -1;
81 static void snow_move(void)
83 int i;
85 if (!(rb->rand()%2))
86 create_particle();
88 for (i=0; i<NUM_PARTICLES; i++) {
89 if (particle_exists(i)) {
90 MYLCD(set_drawmode)(DRMODE_SOLID|DRMODE_INVERSEVID);
91 #ifdef HAVE_LCD_BITMAP
92 rb->lcd_fillrect(particles[i][0],particles[i][1],
93 FLAKE_WIDTH,FLAKE_WIDTH);
94 #else
95 pgfx_drawpixel(particles[i][0],particles[i][1]);
96 #endif
97 MYLCD(set_drawmode)(DRMODE_SOLID);
98 #ifdef HAVE_REMOTE_LCD
99 if (particles[i][0] <= LCD_REMOTE_WIDTH
100 && particles[i][1] <= LCD_REMOTE_HEIGHT) {
101 rb->lcd_remote_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
102 rb->lcd_remote_fillrect(particles[i][0],particles[i][1],
103 FLAKE_WIDTH,FLAKE_WIDTH);
104 rb->lcd_remote_set_drawmode(DRMODE_SOLID);
106 #endif
107 switch ((rb->rand()%7)) {
108 case 0:
109 particles[i][0]++;
110 break;
112 case 1:
113 particles[i][0]--;
114 break;
116 case 2:
117 break;
119 default:
120 particles[i][1]++;
121 break;
123 if (particle_exists(i))
124 #ifdef HAVE_LCD_BITMAP
125 rb->lcd_mono_bitmap(flake,particles[i][0],particles[i][1],
126 FLAKE_WIDTH,FLAKE_WIDTH);
127 #else
128 pgfx_drawpixel(particles[i][0],particles[i][1]);
129 #endif
130 #ifdef HAVE_REMOTE_LCD
131 if (particles[i][0] <= LCD_REMOTE_WIDTH
132 && particles[i][1] <= LCD_REMOTE_HEIGHT) {
133 rb->lcd_remote_bitmap(flake,particles[i][0],particles[i][1],
134 FLAKE_WIDTH,FLAKE_WIDTH);
136 #endif
142 static void snow_init(void)
144 int i;
146 for (i=0; i<NUM_PARTICLES; i++) {
147 particles[i][0]=-1;
148 particles[i][1]=-1;
150 #ifdef HAVE_LCD_CHARCELLS
151 pgfx_display(0, 0); /* display three times */
152 pgfx_display(4, 0);
153 pgfx_display(8, 0);
154 #endif
155 MYLCD(clear_display)();
156 #ifdef HAVE_REMOTE_LCD
157 rb->lcd_remote_clear_display();
158 #endif
161 enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
163 int button;
164 TEST_PLUGIN_API(api);
165 (void)(parameter);
166 rb = api;
168 #ifdef HAVE_LCD_CHARCELLS
169 if (!pgfx_init(rb, 4, 2))
171 rb->splash(HZ*2, true, "Old LCD :(");
172 return PLUGIN_OK;
174 #endif
175 snow_init();
176 while (1) {
177 snow_move();
178 MYLCD(update)();
179 #ifdef HAVE_REMOTE_LCD
180 rb->lcd_remote_update();
181 #endif
182 rb->sleep(HZ/20);
184 button = rb->button_get(false);
186 if (button == SNOW_QUIT)
188 #ifdef HAVE_LCD_CHARCELLS
189 pgfx_release();
190 #endif
191 return PLUGIN_OK;
193 else
194 if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
196 #ifdef HAVE_LCD_CHARCELLS
197 pgfx_release();
198 #endif
199 return PLUGIN_USB_CONNECTED;