Colour targets: Revert an optimisation from almost 18 months ago that actually turned...
[Rockbox.git] / apps / plugins / snow.c
blobbe36d950d52e907304ea817bf2c637d8411e4ab4
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 "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 #else
68 #define SNOW_QUIT BUTTON_OFF
69 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
70 #define SNOW_RC_QUIT BUTTON_RC_STOP
71 #endif
72 #endif
74 static short particles[NUM_PARTICLES][2];
75 static const struct plugin_api* rb;
77 #ifdef HAVE_LCD_BITMAP
78 #if LCD_WIDTH >= 160
79 #define FLAKE_WIDTH 5
80 static const unsigned char flake[] = {0x0a,0x04,0x1f,0x04,0x0a};
81 #else
82 #define FLAKE_WIDTH 3
83 static const unsigned char flake[] = {0x02,0x07,0x02};
84 #endif
85 #endif
87 static bool particle_exists(int particle)
89 if (particles[particle][0]>=0 && particles[particle][1]>=0 &&
90 particles[particle][0]<SNOW_WIDTH && particles[particle][1]<SNOW_HEIGHT)
91 return true;
92 else
93 return false;
96 static int create_particle(void)
98 int i;
100 for (i=0; i<NUM_PARTICLES; i++) {
101 if (!particle_exists(i)) {
102 particles[i][0]=(rb->rand()%SNOW_WIDTH);
103 particles[i][1]=0;
104 return i;
107 return -1;
110 static void snow_move(void)
112 int i;
114 if (!(rb->rand()%2))
115 create_particle();
117 for (i=0; i<NUM_PARTICLES; i++) {
118 if (particle_exists(i)) {
119 MYLCD(set_drawmode)(DRMODE_SOLID|DRMODE_INVERSEVID);
120 #ifdef HAVE_LCD_BITMAP
121 rb->lcd_fillrect(particles[i][0],particles[i][1],
122 FLAKE_WIDTH,FLAKE_WIDTH);
123 #else
124 pgfx_drawpixel(particles[i][0],particles[i][1]);
125 #endif
126 MYLCD(set_drawmode)(DRMODE_SOLID);
127 #ifdef HAVE_REMOTE_LCD
128 if (particles[i][0] <= LCD_REMOTE_WIDTH
129 && particles[i][1] <= LCD_REMOTE_HEIGHT) {
130 rb->lcd_remote_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
131 rb->lcd_remote_fillrect(particles[i][0],particles[i][1],
132 FLAKE_WIDTH,FLAKE_WIDTH);
133 rb->lcd_remote_set_drawmode(DRMODE_SOLID);
135 #endif
136 switch ((rb->rand()%7)) {
137 case 0:
138 particles[i][0]++;
139 break;
141 case 1:
142 particles[i][0]--;
143 break;
145 case 2:
146 break;
148 default:
149 particles[i][1]++;
150 break;
152 if (particle_exists(i))
153 #ifdef HAVE_LCD_BITMAP
154 rb->lcd_mono_bitmap(flake,particles[i][0],particles[i][1],
155 FLAKE_WIDTH,FLAKE_WIDTH);
156 #else
157 pgfx_drawpixel(particles[i][0],particles[i][1]);
158 #endif
159 #ifdef HAVE_REMOTE_LCD
160 if (particles[i][0] <= LCD_REMOTE_WIDTH
161 && particles[i][1] <= LCD_REMOTE_HEIGHT) {
162 rb->lcd_remote_mono_bitmap(flake,particles[i][0],particles[i][1],
163 FLAKE_WIDTH,FLAKE_WIDTH);
165 #endif
171 static void snow_init(void)
173 int i;
175 for (i=0; i<NUM_PARTICLES; i++) {
176 particles[i][0]=-1;
177 particles[i][1]=-1;
179 #ifdef HAVE_LCD_CHARCELLS
180 pgfx_display(0, 0); /* display three times */
181 pgfx_display(4, 0);
182 pgfx_display(8, 0);
183 #endif
184 MYLCD(clear_display)();
185 #ifdef HAVE_REMOTE_LCD
186 rb->lcd_remote_clear_display();
187 #endif
190 enum plugin_status plugin_start(const struct plugin_api* api, const void* parameter)
192 int button;
193 (void)(parameter);
194 rb = api;
196 #ifdef HAVE_LCD_CHARCELLS
197 if (!pgfx_init(rb, 4, 2))
199 rb->splash(HZ*2, "Old LCD :(");
200 return PLUGIN_OK;
202 #endif
203 #ifdef HAVE_LCD_COLOR
204 rb->lcd_clear_display();
205 rb->lcd_set_foreground(LCD_WHITE);
206 rb->lcd_set_background(LCD_DEFAULT_BG);
207 #endif
208 snow_init();
209 while (1) {
210 snow_move();
211 MYLCD(update)();
212 #ifdef HAVE_REMOTE_LCD
213 rb->lcd_remote_update();
214 #endif
215 rb->sleep(HZ/20);
217 button = rb->button_get(false);
219 if (button == SNOW_QUIT
220 #ifdef SNOW_RC_QUIT
221 || button == SNOW_RC_QUIT
222 #endif
225 #ifdef HAVE_LCD_CHARCELLS
226 pgfx_release();
227 #endif
228 return PLUGIN_OK;
230 else
231 if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
233 #ifdef HAVE_LCD_CHARCELLS
234 pgfx_release();
235 #endif
236 return PLUGIN_USB_CONNECTED;