summaryrefslogtreecommitdiff
path: root/apps/plugins
diff options
context:
space:
mode:
authorKevin Ferrare <kevin@rockbox.org>2008-01-22 08:02:31 +0000
committerKevin Ferrare <kevin@rockbox.org>2008-01-22 08:02:31 +0000
commiteb93be2dd9fdca99ffae450e0630045ece449a2f (patch)
tree713c96efcdedfe54b7876d483de2c91e14b84d81 /apps/plugins
parent7da7e7bdd2d88cefe09f8c9953df076875750c25 (diff)
downloadrockbox-eb93be2dd9fdca99ffae450e0630045ece449a2f.tar.gz
rockbox-eb93be2dd9fdca99ffae450e0630045ece449a2f.zip
Fire plugin : initializes palettes with a function instead of storing them in static arrays, changed the color LCD's palette to make it look nicer, switched the button API to the action API, reorganized code a little bit
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16138 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins')
-rw-r--r--apps/plugins/fire.c384
-rw-r--r--apps/plugins/lib/fixedpoint.h8
2 files changed, 159 insertions, 233 deletions
diff --git a/apps/plugins/fire.c b/apps/plugins/fire.c
index ed3509c168..9cee953e4a 100644
--- a/apps/plugins/fire.c
+++ b/apps/plugins/fire.c
@@ -21,8 +21,11 @@
21 21
22#include "plugin.h" 22#include "plugin.h"
23#include "helper.h" 23#include "helper.h"
24#ifdef HAVE_LCD_BITMAP
25
26#include "pluginlib_actions.h"
27#include "fixedpoint.h"
24 28
25#ifdef HAVE_LCD_BITMAP /* and also not for the Player */
26#ifndef HAVE_LCD_COLOR 29#ifndef HAVE_LCD_COLOR
27#include "grey.h" 30#include "grey.h"
28#endif 31#endif
@@ -38,190 +41,85 @@
38 41
39PLUGIN_HEADER 42PLUGIN_HEADER
40 43
41/******************************* Globals ***********************************/
42
43static struct plugin_api* rb; /* global api struct pointer */ 44static struct plugin_api* rb; /* global api struct pointer */
44 45
45static unsigned char fire[LCD_HEIGHT+3][FIRE_WIDTH];
46static unsigned char cooling_map[LCD_HEIGHT][FIRE_WIDTH];
47
48#ifndef HAVE_LCD_COLOR 46#ifndef HAVE_LCD_COLOR
49GREY_INFO_STRUCT 47GREY_INFO_STRUCT
50static unsigned char *gbuf;
51static size_t gbuf_size = 0;
52static unsigned char draw_buffer[FIRE_WIDTH]; 48static unsigned char draw_buffer[FIRE_WIDTH];
49
53#endif 50#endif
54 51
55/* Key assignement */ 52/* Key assignement */
53const struct button_mapping* plugin_contexts[]= {
54 generic_directions,
55#if defined(HAVE_REMOTE_LCD)
56 remote_directions,
57#endif
58 generic_actions
59};
56 60
57#if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD) 61#define FIRE_QUIT PLA_QUIT
58#define FIRE_QUIT BUTTON_OFF 62#define FIRE_SWITCH_FLAMES_TYPE PLA_FIRE
59#define FIRE_SWITCH_FLAMES_TYPE BUTTON_MODE 63#define FIRE_SWITCH_FLAMES_MOVING PLA_START
60#define FIRE_SWITCH_FLAMES_MOVING BUTTON_REC 64#if (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
61#define FIRE_INCREASE_MULT BUTTON_UP
62#define FIRE_DECREASE_MULT BUTTON_DOWN
63
64#define FIRE_RC_QUIT BUTTON_RC_STOP
65
66#elif CONFIG_KEYPAD == RECORDER_PAD
67#define FIRE_QUIT BUTTON_OFF
68#define FIRE_SWITCH_FLAMES_TYPE BUTTON_ON
69#define FIRE_SWITCH_FLAMES_MOVING BUTTON_PLAY
70#define FIRE_INCREASE_MULT BUTTON_UP
71#define FIRE_DECREASE_MULT BUTTON_DOWN
72
73#elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
74#define FIRE_QUIT BUTTON_OFF
75#define FIRE_SWITCH_FLAMES_TYPE BUTTON_ON
76#define FIRE_SWITCH_FLAMES_MOVING BUTTON_SELECT
77#define FIRE_INCREASE_MULT BUTTON_UP
78#define FIRE_DECREASE_MULT BUTTON_DOWN
79
80#elif CONFIG_KEYPAD == ONDIO_PAD
81#define FIRE_QUIT BUTTON_OFF
82#define FIRE_SWITCH_FLAMES_TYPE BUTTON_MENU
83#define FIRE_SWITCH_FLAMES_MOVING BUTTON_RIGHT
84#define FIRE_INCREASE_MULT BUTTON_UP
85#define FIRE_DECREASE_MULT BUTTON_DOWN
86
87#elif (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
88 (CONFIG_KEYPAD == IPOD_1G2G_PAD) 65 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
89#define FIRE_QUIT BUTTON_MENU 66#define FIRE_INCREASE_MULT PLA_RIGHT
90#define FIRE_SWITCH_FLAMES_TYPE BUTTON_SELECT 67#define FIRE_DECREASE_MULT PLA_LEFT
91#define FIRE_SWITCH_FLAMES_MOVING BUTTON_RIGHT 68#else
92#define FIRE_INCREASE_MULT BUTTON_SCROLL_FWD 69#define FIRE_INCREASE_MULT PLA_UP
93#define FIRE_DECREASE_MULT BUTTON_SCROLL_BACK 70#define FIRE_DECREASE_MULT PLA_DOWN
94
95#elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
96#define FIRE_QUIT BUTTON_POWER
97#define FIRE_SWITCH_FLAMES_TYPE BUTTON_LEFT
98#define FIRE_SWITCH_FLAMES_MOVING BUTTON_RIGHT
99#define FIRE_INCREASE_MULT BUTTON_UP
100#define FIRE_DECREASE_MULT BUTTON_DOWN
101
102#elif (CONFIG_KEYPAD == GIGABEAT_PAD)
103#define FIRE_QUIT BUTTON_POWER
104#define FIRE_SWITCH_FLAMES_TYPE BUTTON_LEFT
105#define FIRE_SWITCH_FLAMES_MOVING BUTTON_RIGHT
106#define FIRE_INCREASE_MULT BUTTON_UP
107#define FIRE_DECREASE_MULT BUTTON_DOWN
108
109#elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
110(CONFIG_KEYPAD == SANSA_C200_PAD)
111#define FIRE_QUIT BUTTON_POWER
112#define FIRE_SWITCH_FLAMES_TYPE BUTTON_LEFT
113#define FIRE_SWITCH_FLAMES_MOVING BUTTON_RIGHT
114#define FIRE_INCREASE_MULT BUTTON_UP
115#define FIRE_DECREASE_MULT BUTTON_DOWN
116
117#elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
118#define FIRE_QUIT BUTTON_POWER
119#define FIRE_SWITCH_FLAMES_TYPE BUTTON_LEFT
120#define FIRE_SWITCH_FLAMES_MOVING BUTTON_RIGHT
121#define FIRE_INCREASE_MULT BUTTON_SCROLL_UP
122#define FIRE_DECREASE_MULT BUTTON_SCROLL_DOWN
123
124#elif (CONFIG_KEYPAD == IRIVER_IFP7XX_PAD)
125#define FIRE_QUIT BUTTON_PLAY
126#define FIRE_SWITCH_FLAMES_TYPE BUTTON_MODE
127#define FIRE_SWITCH_FLAMES_MOVING BUTTON_EQ
128#define FIRE_INCREASE_MULT BUTTON_UP
129#define FIRE_DECREASE_MULT BUTTON_DOWN
130
131#endif 71#endif
132 72
133#define MIN_FLAME_VALUE 0 73#define MIN_FLAME_VALUE 0
134#define COOL_MAX (440/LCD_HEIGHT+2) 74#define COOL_MAX (440/LCD_HEIGHT+2)
135 75
136/* fast unsigned multiplication (16x16bit->32bit or 32x32bit->32bit,
137 * whichever is faster for the architecture) */
138#ifdef CPU_ARM
139#define FMULU(a, b) ((uint32_t) (((uint32_t) (a)) * ((uint32_t) (b))))
140#else /* SH1, coldfire */
141#define FMULU(a, b) ((uint32_t) (((uint16_t) (a)) * ((uint16_t) (b))))
142#endif
143
144#ifndef HAVE_LCD_COLOR 76#ifndef HAVE_LCD_COLOR
145static const unsigned char palette[256] = { 77static unsigned char palette[256];
146 0, 1, 3, 4, 6, 7, 9, 10, 12, 13, 15, 16, 18, 19, 21, 22, 78
147 24, 25, 27, 28, 30, 31, 33, 34, 36, 37, 39, 40, 42, 43, 45, 46, 79void color_palette_init(unsigned char* palette)
148 48, 49, 51, 52, 54, 55, 57, 59, 60, 61, 63, 64, 66, 67, 69, 70, 80{
149 72, 73, 75, 76, 78, 79, 81, 82, 84, 85, 87, 88, 90, 91, 93, 94, 81 int i;
150 96, 97, 99, 100, 102, 103, 105, 106, 108, 109, 111, 112, 114, 115, 117, 118, 82 for(i=0;i<=160;i++)//palette[i]=(3/2)*i
151 120, 121, 123, 124, 126, 127, 129, 130, 132, 133, 135, 136, 138, 139, 141, 142, 83 palette[i]=(i*3)/2;
152 144, 145, 147, 148, 150, 151, 153, 154, 156, 157, 159, 160, 162, 163, 165, 166, 84
153 168, 169, 171, 172, 174, 175, 177, 178, 180, 181, 183, 184, 186, 187, 189, 190,
154 192, 193, 195, 196, 198, 199, 201, 202, 204, 205, 207, 208, 210, 211, 213, 214,
155 216, 217, 219, 220, 222, 223, 225, 226, 228, 229, 231, 232, 234, 235, 237, 238,
156 /* 'regular' fire doesn't exceed this value */ 85 /* 'regular' fire doesn't exceed this value */
157 240, 240, 240, 240, 240, 240, 241, 241, 241, 241, 241, 241, 242, 242, 242, 242, 86 for(;i<=255;i++)//palette[i]=(3/20)*i+216
158 242, 242, 243, 243, 243, 243, 243, 243, 244, 244, 244, 244, 244, 244, 245, 245, 87 palette[i]=(i*3+20*217)/20;
159 245, 245, 245, 245, 246, 246, 246, 246, 246, 246, 247, 247, 247, 247, 247, 247, 88}
160 248, 248, 248, 248, 248, 248, 249, 249, 249, 249, 249, 249, 250, 250, 250, 250,
161 250, 250, 251, 251, 251, 251, 251, 251, 252, 252, 252, 252, 252, 252, 253, 253,
162 253, 253, 253, 253, 254, 254, 254, 254, 254, 254, 255, 255, 255, 255, 255, 255
163};
164#else 89#else
165#define L(r,g,b) LCD_RGBPACK(r,g,b) 90
166 91static fb_data palette[256];
167static const fb_data colorpalette[256] = { 92
168 L( 0, 0, 0), L( 5, 0, 0), L( 10, 0, 0), L( 15, 0, 0), L( 20, 0, 0), 93/*
169 L( 25, 0, 0), L( 30, 0, 0), L( 35, 0, 0), L( 40, 0, 0), L( 45, 0, 0), 94 * Color palette generation algorithm taken from
170 L( 50, 0, 0), L( 55, 0, 0), L( 60, 0, 0), L( 65, 0, 0), L( 70, 0, 0), 95 * the "The Demo Effects Collection" GPL project
171 L( 75, 0, 0), L( 80, 0, 0), L( 85, 0, 0), L( 90, 0, 0), L( 95, 0, 0), 96 * Copyright (C) 2002 W.P. van Paassen
172 L(100, 0, 0), L(105, 0, 0), L(110, 0, 0), L(115, 0, 0), L(120, 0, 0), 97 */
173 L(125, 0, 0), L(130, 0, 0), L(135, 0, 0), L(140, 0, 0), L(145, 0, 0), 98void color_palette_init(fb_data* palette)
174 L(150, 0, 0), L(155, 0, 0), L(160, 0, 0), L(165, 0, 0), L(170, 0, 0), 99{
175 L(175, 0, 0), L(180, 0, 0), L(185, 0, 0), L(186, 2, 0), L(187, 5, 1), 100 int i;
176 L(188, 6, 2), L(189, 8, 3), L(190, 10, 4), L(191, 12, 4), L(192, 14, 5), 101 for (i = 0; i < 32; i++){
177 L(193, 15, 6), L(194, 17, 7), L(195, 19, 8), L(196, 21, 8), L(197, 22, 9), 102 /* black to blue, 32 values*/
178 L(198, 24, 10), L(198, 26, 10), L(199, 28, 10), L(200, 29, 11), L(201, 32, 11), 103 palette[i]=LCD_RGBPACK(0, 0, 2*i);
179 L(202, 34, 12), L(203, 36, 13), L(204, 39, 13), L(205, 40, 14), L(206, 42, 14), 104
180 L(207, 43, 15), L(208, 46, 16), L(208, 48, 17), L(209, 50, 18), L(210, 51, 18), 105 /* blue to red, 32 values*/
181 L(212, 53, 19), L(213, 55, 20), L(214, 57, 21), L(215, 59, 22), L(216, 61, 22), 106 palette[i + 32]=LCD_RGBPACK(8*i, 0, 64 - 2*i);
182 L(217, 63, 23), L(217, 65, 24), L(218, 67, 24), L(219, 69, 25), L(220, 70, 25), 107
183 L(222, 72, 26), L(223, 74, 27), L(224, 76, 28), L(225, 78, 28), L(225, 80, 29), 108 /* red to yellow, 32 values*/
184 L(226, 82, 29), L(227, 84, 30), L(228, 86, 31), L(228, 88, 32), L(229, 90, 32), 109 palette[i + 64]=LCD_RGBPACK(255, 8*i, 0);
185 L(230, 92, 32), L(231, 94, 33), L(232, 96, 34), L(233, 98, 35), L(234, 99, 36), 110
186 L(235,101, 37), L(236,103, 37), L(237,105, 38), L(238,107, 39), L(240,109, 39), 111 /* yellow to white, 162 values */
187 L(240,111, 40), L(241,113, 40), L(242,114, 41), L(242,116, 42), L(243,119, 43), 112 palette[i + 96]=LCD_RGBPACK(255, 255, 0 + 4*i);
188 L(245,120, 43), L(246,122, 44), L(247,124, 44), L(248,126, 46), L(248,128, 47), 113 palette[i + 128]=LCD_RGBPACK(255, 255, 64 + 4*i);
189 L(249,130, 47), L(251,131, 47), L(252,133, 48), L(253,135, 49), L(253,138, 49), 114 palette[i + 160]=LCD_RGBPACK(255, 255, 128 + 4*i);
190 L(253,140, 50), L(254,143, 49), L(254,145, 48), L(253,148, 47), L(253,151, 46), 115 palette[i + 192]=LCD_RGBPACK(255, 255, 192 + i);
191 L(253,154, 45), L(253,156, 44), L(253,158, 44), L(252,162, 42), L(252,165, 41), 116 palette[i + 224]=LCD_RGBPACK(255, 255, 224 + i);
192 L(252,167, 41), L(252,170, 40), L(251,173, 40), L(252,175, 38), L(252,178, 37), 117 }
193 L(251,181, 37), L(251,183, 36), L(251,186, 35), L(250,189, 34), L(250,192, 33), 118}
194 L(250,194, 33), L(249,198, 31), L(249,200, 31), L(249,203, 30), L(249,206, 29), 119
195 L(249,209, 28), L(249,211, 27), L(249,214, 26), L(248,216, 25), L(248,219, 25),
196 L(248,222, 24), L(248,224, 23), L(248,227, 22), L(248,230, 21), L(248,232, 21),
197 L(247,236, 19), L(247,238, 23), L(247,239, 31), L(247,239, 45), L(247,240, 55),
198 L(248,240, 68), L(247,241, 78), L(248,241, 90), L(247,242,102), L(248,242,114),
199 L(247,243,125), L(248,243,138), L(248,243,153), L(248,244,162), L(248,245,174),
200 /* 'regular' fire doesn't exceed this value */
201 L(247,245,182), L(247,245,182), L(247,245,183), L(247,245,183), L(247,245,184),
202 L(247,245,184), L(247,245,185), L(247,245,185), L(247,245,186), L(247,245,186),
203 L(247,245,187), L(247,245,187), L(247,245,188), L(247,245,188), L(247,245,189),
204 L(247,245,189), L(248,245,190), L(248,245,190), L(248,245,191), L(248,245,191),
205 L(248,245,192), L(248,245,192), L(248,245,193), L(248,245,193), L(248,245,194),
206 L(248,245,194), L(248,245,195), L(248,245,195), L(248,245,196), L(248,245,196),
207 L(248,245,197), L(248,245,197), L(248,245,198), L(248,245,198), L(248,245,199),
208 L(248,245,199), L(248,245,200), L(248,245,200), L(248,245,201), L(248,245,201),
209 L(248,245,202), L(248,245,202), L(248,245,203), L(248,245,203), L(248,245,204),
210 L(248,245,204), L(248,245,205), L(248,245,205), L(248,246,206), L(248,246,206),
211 L(248,246,207), L(248,246,207), L(248,246,208), L(248,246,208), L(248,246,209),
212 L(248,246,209), L(248,246,210), L(248,246,210), L(248,246,211), L(248,246,211),
213 L(248,246,212), L(248,246,212), L(248,246,213), L(248,246,213), L(248,246,214),
214 L(248,246,214), L(248,246,215), L(248,246,215), L(248,246,216), L(248,246,216),
215 L(248,246,217), L(248,246,217), L(248,246,218), L(248,246,218), L(248,246,219),
216 L(248,246,219), L(248,246,220), L(248,246,220), L(248,246,221), L(248,246,221),
217 L(248,246,222), L(248,246,222), L(248,246,223), L(248,246,223), L(248,246,224),
218 L(248,246,224), L(248,246,225), L(248,246,225), L(248,246,226), L(248,246,226),
219 L(248,246,227), L(248,246,227), L(248,246,228), L(248,246,228), L(248,246,229),
220 L(248,246,229)
221};
222#endif 120#endif
223 121
224static inline void tab_init_rand(unsigned char *tab, unsigned int tab_size, 122static void tab_init_rand(unsigned char *tab, unsigned int tab_size,
225 int rand_max) 123 int rand_max)
226{ 124{
227 unsigned char *end = tab + tab_size; 125 unsigned char *end = tab + tab_size;
@@ -230,36 +128,30 @@ static inline void tab_init_rand(unsigned char *tab, unsigned int tab_size,
230 *tab++ = (unsigned char)rb->rand() % rand_max; 128 *tab++ = (unsigned char)rb->rand() % rand_max;
231} 129}
232 130
233static inline void fire_generate(int mult, int flames_type, bool moving) 131struct fire{
132 unsigned char fire[LCD_HEIGHT+3][FIRE_WIDTH];
133 unsigned char cooling_map[LCD_HEIGHT][FIRE_WIDTH];
134 int flames_type;
135 bool moving;
136 unsigned int mult;
137};
138
139static inline void fire_convolve(struct fire* fire)
234{ 140{
235 unsigned int pixel_value = 0; /* stop the compiler complaining */ 141 unsigned int pixel_value;
236 unsigned int cooling_value; 142 unsigned int cooling_value;
237 unsigned char *ptr, *end, *cool; 143 unsigned char *ptr, *end, *cool;
144 unsigned int mult=fire->mult;
238 145
239 /* Randomize the bottom line */
240 if(moving)
241 {/* moving must be true the first time the function is called */
242 ptr = &fire[LCD_HEIGHT][0];
243 end = ptr + FIRE_WIDTH;
244
245 do
246 {
247 *ptr++ = (MIN_FLAME_VALUE + rb->rand() % (256-MIN_FLAME_VALUE));
248 }
249 while (ptr < end);
250 }
251 rb->yield(); 146 rb->yield();
252
253 /* Convolve the pixels and handle cooling (to add nice shapes effects later) */ 147 /* Convolve the pixels and handle cooling (to add nice shapes effects later) */
254 cool = &cooling_map[0][0]; 148 cool = &fire->cooling_map[0][0];
255 ptr = &fire[0][0]; 149 ptr = &fire->fire[0][0];
256 end = ptr + LCD_HEIGHT*FIRE_WIDTH; 150 end = ptr + LCD_HEIGHT*FIRE_WIDTH;
257 151
258 switch (flames_type) 152 switch (fire->flames_type){
259 {
260 case 0: 153 case 0:
261 do 154 do{
262 {
263 pixel_value = ptr[FIRE_WIDTH-1] /* fire[y+1][x-1] */ 155 pixel_value = ptr[FIRE_WIDTH-1] /* fire[y+1][x-1] */
264 + ptr[2*FIRE_WIDTH] /* fire[y+2][x] */ 156 + ptr[2*FIRE_WIDTH] /* fire[y+2][x] */
265 + ptr[FIRE_WIDTH+1] /* fire[y+1][x+1] */ 157 + ptr[FIRE_WIDTH+1] /* fire[y+1][x+1] */
@@ -275,14 +167,12 @@ static inline void fire_generate(int mult, int flames_type, bool moving)
275 pixel_value = 255; 167 pixel_value = 255;
276 168
277 *ptr++ = pixel_value; 169 *ptr++ = pixel_value;
278 } 170 }while (ptr < end);
279 while (ptr < end);
280 break; 171 break;
281 172
282 case 1: 173 case 1:
283 mult -= 2; 174 mult -= 2;
284 do 175 do{
285 {
286 pixel_value = ptr[FIRE_WIDTH-1] /* fire[y+1][x-1] */ 176 pixel_value = ptr[FIRE_WIDTH-1] /* fire[y+1][x-1] */
287 + ptr[FIRE_WIDTH] /* fire[y+1][x] */ 177 + ptr[FIRE_WIDTH] /* fire[y+1][x] */
288 + ptr[FIRE_WIDTH+1] /* fire[y+1][x+1] */ 178 + ptr[FIRE_WIDTH+1] /* fire[y+1][x+1] */
@@ -298,8 +188,7 @@ static inline void fire_generate(int mult, int flames_type, bool moving)
298 pixel_value = 255; 188 pixel_value = 255;
299 189
300 *ptr++ = pixel_value; 190 *ptr++ = pixel_value;
301 } 191 }while (ptr < end);
302 while (ptr < end);
303 break; 192 break;
304 193
305 default: /* We should never reach this */ 194 default: /* We should never reach this */
@@ -308,13 +197,42 @@ static inline void fire_generate(int mult, int flames_type, bool moving)
308 rb->yield(); 197 rb->yield();
309} 198}
310 199
311static inline void fire_draw(void) 200static void fire_generate_bottom_seed(struct fire* fire)
201{
202 unsigned char *ptr, *end;
203 ptr = &fire->fire[LCD_HEIGHT][0];
204 end = ptr + FIRE_WIDTH;
205 do{
206 *ptr++ = (MIN_FLAME_VALUE + rb->rand() % (256-MIN_FLAME_VALUE));
207 }while (ptr < end);
208}
209
210static inline void fire_step(struct fire* fire)
211{
212 if(fire->moving){
213 /* Randomize the bottom line */
214 fire_generate_bottom_seed(fire);
215 /* Add here further effects like fire letters, ball ... */
216 }
217 fire_convolve(fire);
218}
219
220static void fire_init(struct fire* fire)
221{
222 fire->mult = 261;
223 fire->flames_type=0;
224 fire->moving=true;
225 rb->memset(&fire->fire[0][0], 0, sizeof(fire->fire));
226 tab_init_rand(&fire->cooling_map[0][0], LCD_HEIGHT*FIRE_WIDTH, COOL_MAX);
227 fire_generate_bottom_seed(fire);
228}
229
230static inline void fire_draw(struct fire* fire)
312{ 231{
313 int y; 232 int y;
314 unsigned char *src = &fire[0][0]; 233 unsigned char *src = &fire->fire[0][0];
315#ifndef HAVE_LCD_COLOR 234#ifndef HAVE_LCD_COLOR
316 unsigned char *dest, *end; 235 unsigned char *dest, *end;
317
318 for (y = 0; y < LCD_HEIGHT; y++) 236 for (y = 0; y < LCD_HEIGHT; y++)
319 { 237 {
320 dest = draw_buffer; 238 dest = draw_buffer;
@@ -327,6 +245,7 @@ static inline void fire_draw(void)
327 grey_ub_gray_bitmap(draw_buffer, 0, y, FIRE_WIDTH, 1); 245 grey_ub_gray_bitmap(draw_buffer, 0, y, FIRE_WIDTH, 1);
328 } 246 }
329#else 247#else
248
330 fb_data *dest, *end; 249 fb_data *dest, *end;
331 250
332 for (y = 0; y < LCD_HEIGHT; y++) 251 for (y = 0; y < LCD_HEIGHT; y++)
@@ -335,7 +254,7 @@ static inline void fire_draw(void)
335 end = dest + FIRE_WIDTH; 254 end = dest + FIRE_WIDTH;
336 255
337 do 256 do
338 *dest++ = colorpalette[*src++]; 257 *dest++ = palette[*src++];
339 while (dest < end); 258 while (dest < end);
340 } 259 }
341 rb->lcd_update(); 260 rb->lcd_update();
@@ -345,7 +264,6 @@ static inline void fire_draw(void)
345void cleanup(void *parameter) 264void cleanup(void *parameter)
346{ 265{
347 (void)parameter; 266 (void)parameter;
348
349#ifdef HAVE_ADJUSTABLE_CPU_FREQ 267#ifdef HAVE_ADJUSTABLE_CPU_FREQ
350 rb->cpu_boost(false); 268 rb->cpu_boost(false);
351#endif 269#endif
@@ -356,19 +274,13 @@ void cleanup(void *parameter)
356 backlight_use_settings(rb); /* backlight control in lib/helper.c */ 274 backlight_use_settings(rb); /* backlight control in lib/helper.c */
357} 275}
358 276
359/*
360 * Main function that also contain the main plasma
361 * algorithm.
362 */
363 277
364int main(void) 278#ifndef HAVE_LCD_COLOR
279int init_gray()
365{ 280{
366 int button; 281 unsigned char *gbuf;
367 int mult = 261; 282 size_t gbuf_size = 0;
368 int flames_type=0;
369 bool moving=true;
370 283
371#ifndef HAVE_LCD_COLOR
372 /* get the remainder of the plugin buffer */ 284 /* get the remainder of the plugin buffer */
373 gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size); 285 gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size);
374 286
@@ -380,53 +292,59 @@ int main(void)
380 /* switch on greyscale overlay */ 292 /* switch on greyscale overlay */
381 grey_set_position(FIRE_XPOS, 0); 293 grey_set_position(FIRE_XPOS, 0);
382 grey_show(true); 294 grey_show(true);
295 return PLUGIN_OK;
296}
383#endif 297#endif
384 298
299int main(void)
300{
301 struct fire fire;
302 int action;
303
304#ifndef HAVE_LCD_COLOR
305 if(init_gray()!=PLUGIN_OK)
306 return(PLUGIN_ERROR);
307#endif
308 color_palette_init(palette);
309
385#ifdef HAVE_ADJUSTABLE_CPU_FREQ 310#ifdef HAVE_ADJUSTABLE_CPU_FREQ
386 rb->cpu_boost(true); 311 rb->cpu_boost(true);
387#endif 312#endif
388 rb->memset(&fire[0][0], 0, sizeof(fire)); 313
389 tab_init_rand(&cooling_map[0][0], LCD_HEIGHT*FIRE_WIDTH, COOL_MAX); 314 fire_init(&fire);
390 while (true) 315 while (true){
391 { 316 fire_step(&fire);
392 fire_generate(mult, flames_type, moving); 317 fire_draw(&fire);
393 fire_draw();
394 rb->yield(); 318 rb->yield();
395 319
396 button = rb->button_get(false); 320 action = pluginlib_getaction(rb, 0, plugin_contexts, 1);
397 321
398 switch(button) 322 switch(action){
399 { 323 case FIRE_QUIT:
400#ifdef FIRE_RC_QUIT
401 case FIRE_RC_QUIT :
402#endif
403 case (FIRE_QUIT):
404 cleanup(NULL); 324 cleanup(NULL);
405 return PLUGIN_OK; 325 return PLUGIN_OK;
406 break;
407 326
408 case (FIRE_INCREASE_MULT): 327 case FIRE_INCREASE_MULT:
409 ++mult; 328 ++fire.mult;
410 break; 329 break;
411 330
412 case (FIRE_DECREASE_MULT): 331 case FIRE_DECREASE_MULT:
413 if (mult > 0) 332 if (fire.mult > 0)
414 --mult; 333 --fire.mult;
415 break; 334 break;
416 335
417 case (FIRE_SWITCH_FLAMES_TYPE): 336 case FIRE_SWITCH_FLAMES_TYPE:
418 flames_type = (flames_type + 1) % 2; 337 fire.flames_type = (fire.flames_type + 1) % 2;
419 break; 338 break;
420 339
421 case (FIRE_SWITCH_FLAMES_MOVING): 340 case FIRE_SWITCH_FLAMES_MOVING:
422 moving = !moving; 341 fire.moving = !fire.moving;
423 break; 342 break;
424 343
425 default: 344 default:
426 if (rb->default_event_handler_ex(button, cleanup, NULL) 345 if (rb->default_event_handler_ex(action, cleanup, NULL)
427 == SYS_USB_CONNECTED) 346 == SYS_USB_CONNECTED)
428 return PLUGIN_USB_CONNECTED; 347 return PLUGIN_USB_CONNECTED;
429 break;
430 } 348 }
431 } 349 }
432} 350}
@@ -437,7 +355,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
437{ 355{
438 int ret; 356 int ret;
439 357
440 rb = api; // copy to global api pointer 358 rb = api; //copy to global api pointer
441 (void)parameter; 359 (void)parameter;
442#if LCD_DEPTH > 1 360#if LCD_DEPTH > 1
443 rb->lcd_set_backdrop(NULL); 361 rb->lcd_set_backdrop(NULL);
diff --git a/apps/plugins/lib/fixedpoint.h b/apps/plugins/lib/fixedpoint.h
index 719915709a..a9650e7977 100644
--- a/apps/plugins/lib/fixedpoint.h
+++ b/apps/plugins/lib/fixedpoint.h
@@ -24,3 +24,11 @@ long fsqrt(long a, unsigned int fracbits);
24long cos_int(int val); 24long cos_int(int val);
25long sin_int(int val); 25long sin_int(int val);
26long flog(int x); 26long flog(int x);
27
28/* fast unsigned multiplication (16x16bit->32bit or 32x32bit->32bit,
29 * whichever is faster for the architecture) */
30#ifdef CPU_ARM
31#define FMULU(a, b) ((uint32_t) (((uint32_t) (a)) * ((uint32_t) (b))))
32#else /* SH1, coldfire */
33#define FMULU(a, b) ((uint32_t) (((uint16_t) (a)) * ((uint16_t) (b))))
34#endif