diff options
author | Kevin Ferrare <kevin@rockbox.org> | 2007-07-31 04:59:03 +0000 |
---|---|---|
committer | Kevin Ferrare <kevin@rockbox.org> | 2007-07-31 04:59:03 +0000 |
commit | df4f56b2b0a5343fb40cc749b24897f239c76be7 (patch) | |
tree | f324668f9b4c718649db29b6c7f9025bf115d309 /apps/plugins | |
parent | 4e8b171fc4cc3b62a1656ae67e92944ff855dcd3 (diff) | |
download | rockbox-df4f56b2b0a5343fb40cc749b24897f239c76be7.tar.gz rockbox-df4f56b2b0a5343fb40cc749b24897f239c76be7.zip |
plugins code cleanup : moved the duplicated fixed point table loockup based sinus/cosinus functions to fixedpoint.c, removed the bmp size definition in the clock.c|-(useless as the size is already defined in a .h generated with every bitmaps ...)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14087 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins')
-rw-r--r-- | apps/plugins/bubbles.c | 91 | ||||
-rw-r--r-- | apps/plugins/clock.c | 188 | ||||
-rw-r--r-- | apps/plugins/cube.c | 93 | ||||
-rw-r--r-- | apps/plugins/lib/fixedpoint.c | 66 | ||||
-rw-r--r-- | apps/plugins/lib/fixedpoint.h | 3 | ||||
-rw-r--r-- | apps/plugins/plasma.c | 57 |
6 files changed, 119 insertions, 379 deletions
diff --git a/apps/plugins/bubbles.c b/apps/plugins/bubbles.c index dca3ede4e0..25fd4f3c63 100644 --- a/apps/plugins/bubbles.c +++ b/apps/plugins/bubbles.c | |||
@@ -20,11 +20,13 @@ | |||
20 | ****************************************************************************/ | 20 | ****************************************************************************/ |
21 | 21 | ||
22 | #include "plugin.h" | 22 | #include "plugin.h" |
23 | #include "xlcd.h" | ||
24 | #include "pluginlib_actions.h" | ||
25 | 23 | ||
26 | #ifdef HAVE_LCD_BITMAP | 24 | #ifdef HAVE_LCD_BITMAP |
27 | 25 | ||
26 | #include "xlcd.h" | ||
27 | #include "pluginlib_actions.h" | ||
28 | #include "fixedpoint.h" | ||
29 | |||
28 | PLUGIN_HEADER | 30 | PLUGIN_HEADER |
29 | 31 | ||
30 | /* files */ | 32 | /* files */ |
@@ -1278,71 +1280,6 @@ struct game_context { | |||
1278 | struct tile playboard[BB_HEIGHT][BB_WIDTH]; | 1280 | struct tile playboard[BB_HEIGHT][BB_WIDTH]; |
1279 | }; | 1281 | }; |
1280 | 1282 | ||
1281 | /* | ||
1282 | * Precalculated sine and cosine * 16384 (fixed point 18.14) | ||
1283 | * Borrowed from cube.c plugin | ||
1284 | */ | ||
1285 | static const short sin_table[91] = { | ||
1286 | 0, 285, 571, 857, 1142, 1427, 1712, 1996, 2280, 2563, | ||
1287 | 2845, 3126, 3406, 3685, 3963, 4240, 4516, 4790, 5062, 5334, | ||
1288 | 5603, 5871, 6137, 6401, 6663, 6924, 7182, 7438, 7691, 7943, | ||
1289 | 8191, 8438, 8682, 8923, 9161, 9397, 9630, 9860, 10086, 10310, | ||
1290 | 10531, 10748, 10963, 11173, 11381, 11585, 11785, 11982, 12175, 12365, | ||
1291 | 12550, 12732, 12910, 13084, 13254, 13420, 13582, 13740, 13894, 14043, | ||
1292 | 14188, 14329, 14466, 14598, 14725, 14848, 14967, 15081, 15190, 15295, | ||
1293 | 15395, 15491, 15582, 15668, 15749, 15825, 15897, 15964, 16025, 16082, | ||
1294 | 16135, 16182, 16224, 16261, 16294, 16321, 16344, 16361, 16374, 16381, | ||
1295 | 16384 | ||
1296 | }; | ||
1297 | |||
1298 | static long sin(int val) { | ||
1299 | val = (val+360)%360; | ||
1300 | |||
1301 | if(val < 181) { | ||
1302 | if(val < 91) { | ||
1303 | /* phase 0-90 degree */ | ||
1304 | return (long)sin_table[val]; | ||
1305 | } else { | ||
1306 | /* phase 91-180 degree */ | ||
1307 | return (long)sin_table[180-val]; | ||
1308 | } | ||
1309 | } else { | ||
1310 | if(val < 271) { | ||
1311 | /* phase 181-270 degree */ | ||
1312 | return -(long)sin_table[val-180]; | ||
1313 | } else { | ||
1314 | /* phase 270-359 degree */ | ||
1315 | return -(long)sin_table[360-val]; | ||
1316 | } | ||
1317 | } | ||
1318 | return 0; | ||
1319 | } | ||
1320 | |||
1321 | static long cos(int val) { | ||
1322 | val = (val+360)%360; | ||
1323 | |||
1324 | if(val < 181) { | ||
1325 | if(val < 91) { | ||
1326 | /* phase 0-90 degree */ | ||
1327 | return (long)sin_table[90-val]; | ||
1328 | } else { | ||
1329 | /* phase 91-180 degree */ | ||
1330 | return -(long)sin_table[val-90]; | ||
1331 | } | ||
1332 | } else { | ||
1333 | if(val < 271) { | ||
1334 | /* phase 181-270 degree */ | ||
1335 | return -(long)sin_table[270-val]; | ||
1336 | } else { | ||
1337 | /* phase 270-359 degree */ | ||
1338 | return (long)sin_table[val-270]; | ||
1339 | } | ||
1340 | } | ||
1341 | return 0; | ||
1342 | } | ||
1343 | |||
1344 | |||
1345 | |||
1346 | static void bubbles_init(struct game_context* bb); | 1283 | static void bubbles_init(struct game_context* bb); |
1347 | static bool bubbles_nextlevel(struct game_context* bb); | 1284 | static bool bubbles_nextlevel(struct game_context* bb); |
1348 | static void bubbles_getonboard(struct game_context* bb); | 1285 | static void bubbles_getonboard(struct game_context* bb); |
@@ -1553,17 +1490,17 @@ static void bubbles_drawboard(struct game_context* bb) { | |||
1553 | ROW_HEIGHT*(BB_HEIGHT-2)+BUBBLE_HEIGHT); | 1490 | ROW_HEIGHT*(BB_HEIGHT-2)+BUBBLE_HEIGHT); |
1554 | 1491 | ||
1555 | /* draw arrow */ | 1492 | /* draw arrow */ |
1556 | tipx = SHOTX+BUBBLE_WIDTH/2+(((sin(bb->angle)>>4)*BUBBLE_WIDTH*3/2)>>10); | 1493 | tipx = SHOTX+BUBBLE_WIDTH/2+(((sin_int(bb->angle)>>4)*BUBBLE_WIDTH*3/2)>>10); |
1557 | tipy = SHOTY+BUBBLE_HEIGHT/2-(((cos(bb->angle)>>4)*BUBBLE_HEIGHT*3/2)>>10); | 1494 | tipy = SHOTY+BUBBLE_HEIGHT/2-(((cos_int(bb->angle)>>4)*BUBBLE_HEIGHT*3/2)>>10); |
1558 | 1495 | ||
1559 | rb->lcd_drawline(SHOTX+BUBBLE_WIDTH/2+(((sin(bb->angle)>>4)*BUBBLE_WIDTH/2)>>10), | 1496 | rb->lcd_drawline(SHOTX+BUBBLE_WIDTH/2+(((sin_int(bb->angle)>>4)*BUBBLE_WIDTH/2)>>10), |
1560 | SHOTY+BUBBLE_HEIGHT/2-(((cos(bb->angle)>>4)*BUBBLE_HEIGHT/2)>>10), | 1497 | SHOTY+BUBBLE_HEIGHT/2-(((cos_int(bb->angle)>>4)*BUBBLE_HEIGHT/2)>>10), |
1561 | tipx, tipy); | 1498 | tipx, tipy); |
1562 | xlcd_filltriangle(tipx, tipy, | 1499 | xlcd_filltriangle(tipx, tipy, |
1563 | tipx+(((sin(bb->angle-135)>>4)*BUBBLE_WIDTH/3)>>10), | 1500 | tipx+(((sin_int(bb->angle-135)>>4)*BUBBLE_WIDTH/3)>>10), |
1564 | tipy-(((cos(bb->angle-135)>>4)*BUBBLE_HEIGHT/3)>>10), | 1501 | tipy-(((cos_int(bb->angle-135)>>4)*BUBBLE_HEIGHT/3)>>10), |
1565 | tipx+(((sin(bb->angle+135)>>4)*BUBBLE_WIDTH/3)>>10), | 1502 | tipx+(((sin_int(bb->angle+135)>>4)*BUBBLE_WIDTH/3)>>10), |
1566 | tipy-(((cos(bb->angle+135)>>4)*BUBBLE_HEIGHT/3)>>10)); | 1503 | tipy-(((cos_int(bb->angle+135)>>4)*BUBBLE_HEIGHT/3)>>10)); |
1567 | 1504 | ||
1568 | /* draw text */ | 1505 | /* draw text */ |
1569 | rb->lcd_getstringsize(level, &w, &h); | 1506 | rb->lcd_getstringsize(level, &w, &h); |
@@ -1608,8 +1545,8 @@ static int bubbles_fire(struct game_context* bb) { | |||
1608 | 1545 | ||
1609 | /* get current bubble */ | 1546 | /* get current bubble */ |
1610 | bubblecur = bb->queue[bb->nextinq]; | 1547 | bubblecur = bb->queue[bb->nextinq]; |
1611 | shotxinc = ((sin(bb->angle)>>4)*BUBBLE_WIDTH)/3; | 1548 | shotxinc = ((sin_int(bb->angle)>>4)*BUBBLE_WIDTH)/3; |
1612 | shotyinc = ((-1*(cos(bb->angle)>>4))*BUBBLE_HEIGHT)/3; | 1549 | shotyinc = ((-1*(cos_int(bb->angle)>>4))*BUBBLE_HEIGHT)/3; |
1613 | shotxofs = shotyofs = 0; | 1550 | shotxofs = shotyofs = 0; |
1614 | 1551 | ||
1615 | /* advance the queue */ | 1552 | /* advance the queue */ |
diff --git a/apps/plugins/clock.c b/apps/plugins/clock.c index f2f6c779f2..8d0efeef43 100644 --- a/apps/plugins/clock.c +++ b/apps/plugins/clock.c | |||
@@ -93,125 +93,38 @@ Original release, featuring analog/digital modes and a few options. | |||
93 | #include "checkbox.h" | 93 | #include "checkbox.h" |
94 | #include "xlcd.h" | 94 | #include "xlcd.h" |
95 | #include "oldmenuapi.h" | 95 | #include "oldmenuapi.h" |
96 | #include "fixedpoint.h" | ||
96 | 97 | ||
97 | PLUGIN_HEADER | 98 | PLUGIN_HEADER |
98 | 99 | ||
99 | /* External bitmap references */ | 100 | /* External bitmap references */ |
100 | extern const fb_data clock_digits[]; | 101 | #include "clock_digits.h" |
101 | extern const fb_data clock_smalldigits[]; | 102 | #include "clock_smalldigits.h" |
102 | extern const fb_data clock_segments[]; | 103 | #include "clock_smallsegments.h" |
103 | extern const fb_data clock_smallsegments[]; | 104 | #include "clock_messages.h" |
104 | extern const fb_data clock_logo[]; | 105 | #include "clock_logo.h" |
105 | extern const fb_data clock_messages[]; | 106 | #include "clock_segments.h" |
106 | extern const fb_data clock_timesup[]; | 107 | |
107 | 108 | /* Bitmap positions/deltas, per LCD size */ | |
108 | /* Bitmap sizes/positions/deltas, per LCD size */ | 109 | #if (LCD_WIDTH >= 112) && (LCD_HEIGHT >= 64) && (LCD_DEPTH >= 1) /* Archos */ |
109 | #if (LCD_WIDTH >= 320) && (LCD_HEIGHT >=240) && (LCD_DEPTH >= 16) /* iPod 5G */ | ||
110 | #define DIGIT_WIDTH 50 | ||
111 | #define DIGIT_HEIGHT 70 | ||
112 | #define SMALLDIGIT_WIDTH 15 | ||
113 | #define SMALLDIGIT_HEIGHT 21 | ||
114 | #define SMALLSEG_WIDTH 15 | ||
115 | #define SMALLSEG_HEIGHT 21 | ||
116 | #define MESSAGE_HEIGHT 40 | ||
117 | #define MESSAGE_WIDTH 320 | ||
118 | #define LOGO_WIDTH 320 | ||
119 | #define LOGO_HEIGHT 160 | ||
120 | #define LCD_OFFSET 1.5 | ||
121 | #define HAND_W 3 | ||
122 | #elif (LCD_WIDTH >= 220) && (LCD_HEIGHT >= 176) && (LCD_DEPTH >= 16) /* H300 */ | ||
123 | #define DIGIT_WIDTH 35 | ||
124 | #define DIGIT_HEIGHT 49 | ||
125 | #define SMALLDIGIT_WIDTH 10 | ||
126 | #define SMALLDIGIT_HEIGHT 14 | ||
127 | #define SMALLSEG_WIDTH 10 | ||
128 | #define SMALLSEG_HEIGHT 14 | ||
129 | #define MESSAGE_HEIGHT 27 | ||
130 | #define MESSAGE_WIDTH 220 | ||
131 | #define LOGO_WIDTH 220 | ||
132 | #define LOGO_HEIGHT 110 | ||
133 | #define LCD_OFFSET 1.5 | ||
134 | #define HAND_W 3 | ||
135 | #elif (LCD_WIDTH >= 176) && (LCD_HEIGHT >= 132) && (LCD_DEPTH >=16) /* Nano */ | ||
136 | #define DIGIT_WIDTH 25 | ||
137 | #define DIGIT_HEIGHT 35 | ||
138 | #define SMALLDIGIT_WIDTH 10 | ||
139 | #define SMALLDIGIT_HEIGHT 14 | ||
140 | #define SMALLSEG_WIDTH 10 | ||
141 | #define SMALLSEG_HEIGHT 14 | ||
142 | #define MESSAGE_HEIGHT 22 | ||
143 | #define MESSAGE_WIDTH 176 | ||
144 | #define LOGO_WIDTH 176 | ||
145 | #define LOGO_HEIGHT 88 | ||
146 | #define LCD_OFFSET 1.5 | ||
147 | #define HAND_W 3 | ||
148 | #elif (LCD_WIDTH >= 160) && (LCD_HEIGHT >= 128) && (LCD_DEPTH >=16) /* iAudio, H10 */ | ||
149 | #define DIGIT_WIDTH 25 | ||
150 | #define DIGIT_HEIGHT 35 | ||
151 | #define SMALLDIGIT_WIDTH 10 | ||
152 | #define SMALLDIGIT_HEIGHT 14 | ||
153 | #define SMALLSEG_WIDTH 10 | ||
154 | #define SMALLSEG_HEIGHT 14 | ||
155 | #define MESSAGE_HEIGHT 20 | ||
156 | #define MESSAGE_WIDTH 160 | ||
157 | #define LOGO_WIDTH 160 | ||
158 | #define LOGO_HEIGHT 80 | ||
159 | #define LCD_OFFSET 1.5 | ||
160 | #define HAND_W 3 | ||
161 | #elif (LCD_WIDTH >= 128) && (LCD_HEIGHT >= 128) && (LCD_DEPTH >=16) /* H10 5/6GB */ | ||
162 | #define DIGIT_WIDTH 20 | ||
163 | #define DIGIT_HEIGHT 28 | ||
164 | #define SMALLDIGIT_WIDTH 10 | ||
165 | #define SMALLDIGIT_HEIGHT 14 | ||
166 | #define SMALLSEG_WIDTH 10 | ||
167 | #define SMALLSEG_HEIGHT 14 | ||
168 | #define MESSAGE_HEIGHT 16 | ||
169 | #define MESSAGE_WIDTH 128 | ||
170 | #define LOGO_WIDTH 128 | ||
171 | #define LOGO_HEIGHT 64 | ||
172 | #define LCD_OFFSET 1.5 | ||
173 | #define HAND_W 3 | ||
174 | #elif (LCD_WIDTH >= 160) && (LCD_HEIGHT >= 128) && (LCD_DEPTH >=2) /* iPod 3G, 4G */ | ||
175 | #define DIGIT_WIDTH 25 | ||
176 | #define DIGIT_HEIGHT 35 | ||
177 | #define SMALLDIGIT_WIDTH 10 | ||
178 | #define SMALLDIGIT_HEIGHT 14 | ||
179 | #define SMALLSEG_WIDTH 10 | ||
180 | #define SMALLSEG_HEIGHT 14 | ||
181 | #define MESSAGE_HEIGHT 20 | ||
182 | #define MESSAGE_WIDTH 160 | ||
183 | #define LOGO_WIDTH 160 | ||
184 | #define LOGO_HEIGHT 80 | ||
185 | #define LCD_OFFSET 1.5 | ||
186 | #define HAND_W 3 | ||
187 | #elif (LCD_WIDTH >= 138) && (LCD_HEIGHT >= 110) && (LCD_DEPTH >=2) /* iPod mini */ | ||
188 | #define DIGIT_WIDTH 23 | ||
189 | #define DIGIT_HEIGHT 32 | ||
190 | #define SMALLDIGIT_WIDTH 10 | ||
191 | #define SMALLDIGIT_HEIGHT 14 | ||
192 | #define SMALLSEG_WIDTH 10 | ||
193 | #define SMALLSEG_HEIGHT 14 | ||
194 | #define MESSAGE_HEIGHT 17 | ||
195 | #define MESSAGE_WIDTH 138 | ||
196 | #define LOGO_WIDTH 138 | ||
197 | #define LOGO_HEIGHT 69 | ||
198 | #define LCD_OFFSET 1.5 | ||
199 | #define HAND_W 3 | ||
200 | #elif (LCD_WIDTH >= 112) && (LCD_HEIGHT >= 64) && (LCD_DEPTH >= 1) /* Archos */ | ||
201 | #define DIGIT_WIDTH 16 | ||
202 | #define DIGIT_HEIGHT 20 | ||
203 | #define SMALLDIGIT_WIDTH 8 | ||
204 | #define SMALLDIGIT_HEIGHT 10 | ||
205 | #define SMALLSEG_WIDTH 10 | ||
206 | #define SMALLSEG_HEIGHT 12 | ||
207 | #define MESSAGE_HEIGHT 14 | ||
208 | #define MESSAGE_WIDTH 112 | ||
209 | #define LOGO_WIDTH 112 | ||
210 | #define LOGO_HEIGHT 50 | ||
211 | #define LCD_OFFSET 1 | 110 | #define LCD_OFFSET 1 |
212 | #define HAND_W 2 | 111 | #define HAND_W 2 |
112 | #else | ||
113 | #define LCD_OFFSET 1.5 | ||
114 | #define HAND_W 3 | ||
213 | #endif | 115 | #endif |
214 | 116 | ||
117 | #define DIGIT_WIDTH BMPWIDTH_clock_digits | ||
118 | #define DIGIT_HEIGHT (BMPHEIGHT_clock_digits/15) | ||
119 | #define SMALLDIGIT_WIDTH BMPWIDTH_clock_smalldigits | ||
120 | #define SMALLDIGIT_HEIGHT (BMPHEIGHT_clock_smalldigits/13) | ||
121 | #define SMALLSEG_WIDTH BMPWIDTH_clock_smallsegments | ||
122 | #define SMALLSEG_HEIGHT (BMPHEIGHT_clock_smallsegments/13) | ||
123 | #define MESSAGE_WIDTH BMPWIDTH_clock_messages | ||
124 | #define MESSAGE_HEIGHT (BMPHEIGHT_clock_messages/6) | ||
125 | #define LOGO_WIDTH BMPWIDTH_clock_logo | ||
126 | #define LOGO_HEIGHT BMPHEIGHT_clock_logo | ||
127 | |||
215 | /* Parts of larger bitmaps */ | 128 | /* Parts of larger bitmaps */ |
216 | #define COLON 10 | 129 | #define COLON 10 |
217 | #define DOT_FILLED 11 | 130 | #define DOT_FILLED 11 |
@@ -556,51 +469,6 @@ void reset_settings(void) | |||
556 | settings.plain[plain_blinkcolon] = false; | 469 | settings.plain[plain_blinkcolon] = false; |
557 | } | 470 | } |
558 | 471 | ||
559 | /************************************************ | ||
560 | * Precalculated sine * 16384 (fixed point 18.14) | ||
561 | ***********************************************/ | ||
562 | static const short sin_table[91] = | ||
563 | { | ||
564 | 0, 285, 571, 857, 1142, 1427, 1712, 1996, 2280, 2563, | ||
565 | 2845, 3126, 3406, 3685, 3963, 4240, 4516, 4790, 5062, 5334, | ||
566 | 5603, 5871, 6137, 6401, 6663, 6924, 7182, 7438, 7691, 7943, | ||
567 | 8191, 8438, 8682, 8923, 9161, 9397, 9630, 9860, 10086, 10310, | ||
568 | 10531, 10748, 10963, 11173, 11381, 11585, 11785, 11982, 12175, 12365, | ||
569 | 12550, 12732, 12910, 13084, 13254, 13420, 13582, 13740, 13894, 14043, | ||
570 | 14188, 14329, 14466, 14598, 14725, 14848, 14967, 15081, 15190, 15295, | ||
571 | 15395, 15491, 15582, 15668, 15749, 15825, 15897, 15964, 16025, 16082, | ||
572 | 16135, 16182, 16224, 16261, 16294, 16321, 16344, 16361, 16374, 16381, | ||
573 | 16384 | ||
574 | }; | ||
575 | |||
576 | /******************************* | ||
577 | * Sine function (from plasma.c) | ||
578 | ******************************/ | ||
579 | static short sin(int val) | ||
580 | { | ||
581 | /* value should be between 0 and 360 degree for correct lookup*/ | ||
582 | val%=360; | ||
583 | if(val<0) | ||
584 | val+=360; | ||
585 | |||
586 | /* Speed improvement through successive lookup */ | ||
587 | if (val < 181) | ||
588 | { | ||
589 | if (val < 91) | ||
590 | return (short)sin_table[val]; /* phase 0-90 degree */ | ||
591 | else | ||
592 | return (short)sin_table[180-val]; /* phase 91-180 degree */ | ||
593 | } | ||
594 | else | ||
595 | { | ||
596 | if (val < 271) | ||
597 | return -(short)sin_table[val-180]; /* phase 181-270 degree */ | ||
598 | else | ||
599 | return -(short)sin_table[360-val]; /* phase 270-359 degree */ | ||
600 | } | ||
601 | return 0; | ||
602 | } | ||
603 | |||
604 | /************************************************************** | 472 | /************************************************************** |
605 | * Simple function to check if we're switching to digital mode, | 473 | * Simple function to check if we're switching to digital mode, |
606 | * and if so, set bg/fg colors appropriately. | 474 | * and if so, set bg/fg colors appropriately. |
@@ -812,13 +680,13 @@ void init_clock(void) | |||
812 | 680 | ||
813 | for(i=0; i<ANALOG_VALUES; i++) | 681 | for(i=0; i<ANALOG_VALUES; i++) |
814 | { | 682 | { |
815 | xminute[i] = ((sin(360 * i / ANALOG_VALUES) | 683 | xminute[i] = ((sin_int(360 * i / ANALOG_VALUES) |
816 | * ANALOG_MIN_RADIUS) >> 14) + ANALOG_XCENTER; | 684 | * ANALOG_MIN_RADIUS) >> 14) + ANALOG_XCENTER; |
817 | yminute[i] = ((sin(360*i/ ANALOG_VALUES-90) | 685 | yminute[i] = ((sin_int(360*i/ ANALOG_VALUES-90) |
818 | * ANALOG_MIN_RADIUS) >> 14) + ANALOG_YCENTER; | 686 | * ANALOG_MIN_RADIUS) >> 14) + ANALOG_YCENTER; |
819 | xhour[i] = ((sin(360 * i / ANALOG_VALUES) | 687 | xhour[i] = ((sin_int(360 * i / ANALOG_VALUES) |
820 | * ANALOG_HR_RADIUS) >> 14) + ANALOG_XCENTER; | 688 | * ANALOG_HR_RADIUS) >> 14) + ANALOG_XCENTER; |
821 | yhour[i] = ((sin(360 * i / ANALOG_VALUES-90) | 689 | yhour[i] = ((sin_int(360 * i / ANALOG_VALUES-90) |
822 | * ANALOG_HR_RADIUS) >> 14) + ANALOG_YCENTER; | 690 | * ANALOG_HR_RADIUS) >> 14) + ANALOG_YCENTER; |
823 | 691 | ||
824 | /* Fullscreen initialization */ | 692 | /* Fullscreen initialization */ |
diff --git a/apps/plugins/cube.c b/apps/plugins/cube.c index 31e1613479..f5158e9b7a 100644 --- a/apps/plugins/cube.c +++ b/apps/plugins/cube.c | |||
@@ -22,6 +22,7 @@ | |||
22 | #include "gray.h" | 22 | #include "gray.h" |
23 | #include "playergfx.h" | 23 | #include "playergfx.h" |
24 | #include "xlcd.h" | 24 | #include "xlcd.h" |
25 | #include "fixedpoint.h" | ||
25 | 26 | ||
26 | PLUGIN_HEADER | 27 | PLUGIN_HEADER |
27 | 28 | ||
@@ -312,100 +313,20 @@ static long matrice[3][3]; | |||
312 | static const int nb_points = 8; | 313 | static const int nb_points = 8; |
313 | static long z_off = 600; | 314 | static long z_off = 600; |
314 | 315 | ||
315 | /* Precalculated sine and cosine * 16384 (fixed point 18.14) */ | ||
316 | static const short sin_table[91] = | ||
317 | { | ||
318 | 0, 285, 571, 857, 1142, 1427, 1712, 1996, 2280, 2563, | ||
319 | 2845, 3126, 3406, 3685, 3963, 4240, 4516, 4790, 5062, 5334, | ||
320 | 5603, 5871, 6137, 6401, 6663, 6924, 7182, 7438, 7691, 7943, | ||
321 | 8191, 8438, 8682, 8923, 9161, 9397, 9630, 9860, 10086, 10310, | ||
322 | 10531, 10748, 10963, 11173, 11381, 11585, 11785, 11982, 12175, 12365, | ||
323 | 12550, 12732, 12910, 13084, 13254, 13420, 13582, 13740, 13894, 14043, | ||
324 | 14188, 14329, 14466, 14598, 14725, 14848, 14967, 15081, 15190, 15295, | ||
325 | 15395, 15491, 15582, 15668, 15749, 15825, 15897, 15964, 16025, 16082, | ||
326 | 16135, 16182, 16224, 16261, 16294, 16321, 16344, 16361, 16374, 16381, | ||
327 | 16384 | ||
328 | }; | ||
329 | |||
330 | static struct plugin_api* rb; | 316 | static struct plugin_api* rb; |
331 | 317 | ||
332 | static long sin(int val) | ||
333 | { | ||
334 | /* Speed improvement through sukzessive lookup */ | ||
335 | if (val < 181) | ||
336 | { | ||
337 | if (val < 91) | ||
338 | { | ||
339 | /* phase 0-90 degree */ | ||
340 | return (long)sin_table[val]; | ||
341 | } | ||
342 | else | ||
343 | { | ||
344 | /* phase 91-180 degree */ | ||
345 | return (long)sin_table[180-val]; | ||
346 | } | ||
347 | } | ||
348 | else | ||
349 | { | ||
350 | if (val < 271) | ||
351 | { | ||
352 | /* phase 181-270 degree */ | ||
353 | return -(long)sin_table[val-180]; | ||
354 | } | ||
355 | else | ||
356 | { | ||
357 | /* phase 270-359 degree */ | ||
358 | return -(long)sin_table[360-val]; | ||
359 | } | ||
360 | } | ||
361 | return 0; | ||
362 | } | ||
363 | |||
364 | static long cos(int val) | ||
365 | { | ||
366 | /* Speed improvement through sukzessive lookup */ | ||
367 | if (val < 181) | ||
368 | { | ||
369 | if (val < 91) | ||
370 | { | ||
371 | /* phase 0-90 degree */ | ||
372 | return (long)sin_table[90-val]; | ||
373 | } | ||
374 | else | ||
375 | { | ||
376 | /* phase 91-180 degree */ | ||
377 | return -(long)sin_table[val-90]; | ||
378 | } | ||
379 | } | ||
380 | else | ||
381 | { | ||
382 | if (val < 271) | ||
383 | { | ||
384 | /* phase 181-270 degree */ | ||
385 | return -(long)sin_table[270-val]; | ||
386 | } | ||
387 | else | ||
388 | { | ||
389 | /* phase 270-359 degree */ | ||
390 | return (long)sin_table[val-270]; | ||
391 | } | ||
392 | } | ||
393 | return 0; | ||
394 | } | ||
395 | |||
396 | |||
397 | static void cube_rotate(int xa, int ya, int za) | 318 | static void cube_rotate(int xa, int ya, int za) |
398 | { | 319 | { |
399 | int i; | 320 | int i; |
400 | /* Just to prevent unnecessary lookups */ | 321 | /* Just to prevent unnecessary lookups */ |
401 | long sxa, cxa, sya, cya, sza, cza; | 322 | long sxa, cxa, sya, cya, sza, cza; |
402 | 323 | ||
403 | sxa = sin(xa); | 324 | sxa = sin_int(xa); |
404 | cxa = cos(xa); | 325 | cxa = cos_int(xa); |
405 | sya = sin(ya); | 326 | sya = sin_int(ya); |
406 | cya = cos(ya); | 327 | cya = cos_int(ya); |
407 | sza = sin(za); | 328 | sza = sin_int(za); |
408 | cza = cos(za); | 329 | cza = cos_int(za); |
409 | 330 | ||
410 | /* calculate overall translation matrix */ | 331 | /* calculate overall translation matrix */ |
411 | matrice[0][0] = (cza * cya) >> 14; | 332 | matrice[0][0] = (cza * cya) >> 14; |
diff --git a/apps/plugins/lib/fixedpoint.c b/apps/plugins/lib/fixedpoint.c index 56597c1364..cf69d9c31b 100644 --- a/apps/plugins/lib/fixedpoint.c +++ b/apps/plugins/lib/fixedpoint.c | |||
@@ -60,6 +60,21 @@ static const unsigned long atan_table[] = { | |||
60 | 0x00000000, /* +0.000000000 */ | 60 | 0x00000000, /* +0.000000000 */ |
61 | }; | 61 | }; |
62 | 62 | ||
63 | /* Precalculated sine and cosine * 16384 (2^14) (fixed point 18.14) */ | ||
64 | static const short sin_table[91] = | ||
65 | { | ||
66 | 0, 285, 571, 857, 1142, 1427, 1712, 1996, 2280, 2563, | ||
67 | 2845, 3126, 3406, 3685, 3963, 4240, 4516, 4790, 5062, 5334, | ||
68 | 5603, 5871, 6137, 6401, 6663, 6924, 7182, 7438, 7691, 7943, | ||
69 | 8191, 8438, 8682, 8923, 9161, 9397, 9630, 9860, 10086, 10310, | ||
70 | 10531, 10748, 10963, 11173, 11381, 11585, 11785, 11982, 12175, 12365, | ||
71 | 12550, 12732, 12910, 13084, 13254, 13420, 13582, 13740, 13894, 14043, | ||
72 | 14188, 14329, 14466, 14598, 14725, 14848, 14967, 15081, 15190, 15295, | ||
73 | 15395, 15491, 15582, 15668, 15749, 15825, 15897, 15964, 16025, 16082, | ||
74 | 16135, 16182, 16224, 16261, 16294, 16321, 16344, 16361, 16374, 16381, | ||
75 | 16384 | ||
76 | }; | ||
77 | |||
63 | /** | 78 | /** |
64 | * Implements sin and cos using CORDIC rotation. | 79 | * Implements sin and cos using CORDIC rotation. |
65 | * | 80 | * |
@@ -136,3 +151,54 @@ long fsqrt(long a, unsigned int fracbits) | |||
136 | return b; | 151 | return b; |
137 | } | 152 | } |
138 | 153 | ||
154 | /** | ||
155 | * Fixed point sinus using a lookup table | ||
156 | * don't forget to divide the result by 16384 to get the actual sinus value | ||
157 | * @param val sinus argument in degree | ||
158 | * @return sin(val)*16384 | ||
159 | */ | ||
160 | long sin_int(int val) | ||
161 | { | ||
162 | val = (val+360)%360; | ||
163 | if (val < 181) | ||
164 | { | ||
165 | if (val < 91)/* phase 0-90 degree */ | ||
166 | return (long)sin_table[val]; | ||
167 | else/* phase 91-180 degree */ | ||
168 | return (long)sin_table[180-val]; | ||
169 | } | ||
170 | else | ||
171 | { | ||
172 | if (val < 271)/* phase 181-270 degree */ | ||
173 | return -(long)sin_table[val-180]; | ||
174 | else/* phase 270-359 degree */ | ||
175 | return -(long)sin_table[360-val]; | ||
176 | } | ||
177 | return 0; | ||
178 | } | ||
179 | |||
180 | /** | ||
181 | * Fixed point cosinus using a lookup table | ||
182 | * don't forget to divide the result by 16384 to get the actual cosinus value | ||
183 | * @param val sinus argument in degree | ||
184 | * @return cos(val)*16384 | ||
185 | */ | ||
186 | long cos_int(int val) | ||
187 | { | ||
188 | val = (val+360)%360; | ||
189 | if (val < 181) | ||
190 | { | ||
191 | if (val < 91)/* phase 0-90 degree */ | ||
192 | return (long)sin_table[90-val]; | ||
193 | else/* phase 91-180 degree */ | ||
194 | return -(long)sin_table[val-90]; | ||
195 | } | ||
196 | else | ||
197 | { | ||
198 | if (val < 271)/* phase 181-270 degree */ | ||
199 | return -(long)sin_table[270-val]; | ||
200 | else/* phase 270-359 degree */ | ||
201 | return (long)sin_table[val-270]; | ||
202 | } | ||
203 | return 0; | ||
204 | } | ||
diff --git a/apps/plugins/lib/fixedpoint.h b/apps/plugins/lib/fixedpoint.h index ff773cb0c5..c58798930a 100644 --- a/apps/plugins/lib/fixedpoint.h +++ b/apps/plugins/lib/fixedpoint.h | |||
@@ -21,4 +21,5 @@ | |||
21 | 21 | ||
22 | long fsincos(unsigned long phase, long *cos); | 22 | long fsincos(unsigned long phase, long *cos); |
23 | long fsqrt(long a, unsigned int fracbits); | 23 | long fsqrt(long a, unsigned int fracbits); |
24 | 24 | long cos_int(int val); | |
25 | long sin_int(int val); | ||
diff --git a/apps/plugins/plasma.c b/apps/plugins/plasma.c index df22444b81..64d73a3757 100644 --- a/apps/plugins/plasma.c +++ b/apps/plugins/plasma.c | |||
@@ -29,6 +29,7 @@ | |||
29 | #ifndef HAVE_LCD_COLOR | 29 | #ifndef HAVE_LCD_COLOR |
30 | #include "gray.h" | 30 | #include "gray.h" |
31 | #endif | 31 | #endif |
32 | #include "fixedpoint.h" | ||
32 | 33 | ||
33 | PLUGIN_HEADER | 34 | PLUGIN_HEADER |
34 | 35 | ||
@@ -101,60 +102,6 @@ static int plasma_frequency; | |||
101 | 102 | ||
102 | #define WAV_AMP 90 | 103 | #define WAV_AMP 90 |
103 | 104 | ||
104 | |||
105 | /* Precalculated sine * 16384 (fixed point 18.14) */ | ||
106 | static const short sin_table[91] = | ||
107 | { | ||
108 | 0, 285, 571, 857, 1142, 1427, 1712, 1996, 2280, 2563, | ||
109 | 2845, 3126, 3406, 3685, 3963, 4240, 4516, 4790, 5062, 5334, | ||
110 | 5603, 5871, 6137, 6401, 6663, 6924, 7182, 7438, 7691, 7943, | ||
111 | 8191, 8438, 8682, 8923, 9161, 9397, 9630, 9860, 10086, 10310, | ||
112 | 10531, 10748, 10963, 11173, 11381, 11585, 11785, 11982, 12175, 12365, | ||
113 | 12550, 12732, 12910, 13084, 13254, 13420, 13582, 13740, 13894, 14043, | ||
114 | 14188, 14329, 14466, 14598, 14725, 14848, 14967, 15081, 15190, 15295, | ||
115 | 15395, 15491, 15582, 15668, 15749, 15825, 15897, 15964, 16025, 16082, | ||
116 | 16135, 16182, 16224, 16261, 16294, 16321, 16344, 16361, 16374, 16381, | ||
117 | 16384 | ||
118 | }; | ||
119 | |||
120 | static short sin(int val) | ||
121 | { | ||
122 | /* value should be between 0 and 360 degree for correct lookup*/ | ||
123 | val%=360; | ||
124 | if(val<0) | ||
125 | val+=360; | ||
126 | |||
127 | /* Speed improvement through successive lookup */ | ||
128 | if (val < 181) | ||
129 | { | ||
130 | if (val < 91) | ||
131 | { | ||
132 | /* phase 0-90 degree */ | ||
133 | return (short)sin_table[val]; | ||
134 | } | ||
135 | else | ||
136 | { | ||
137 | /* phase 91-180 degree */ | ||
138 | return (short)sin_table[180-val]; | ||
139 | } | ||
140 | } | ||
141 | else | ||
142 | { | ||
143 | if (val < 271) | ||
144 | { | ||
145 | /* phase 181-270 degree */ | ||
146 | return -(short)sin_table[val-180]; | ||
147 | } | ||
148 | else | ||
149 | { | ||
150 | /* phase 270-359 degree */ | ||
151 | return -(short)sin_table[360-val]; | ||
152 | } | ||
153 | } | ||
154 | return 0; | ||
155 | } | ||
156 | |||
157 | |||
158 | /* | 105 | /* |
159 | * Main wave function so we don't have to re-calc the sine | 106 | * Main wave function so we don't have to re-calc the sine |
160 | * curve every time. Mess around WAV_AMP and FREQ to make slighlty | 107 | * curve every time. Mess around WAV_AMP and FREQ to make slighlty |
@@ -167,7 +114,7 @@ static void wave_table_generate(void) | |||
167 | for (i=0;i<256;++i) | 114 | for (i=0;i<256;++i) |
168 | { | 115 | { |
169 | wave_array[i] = (unsigned char)((WAV_AMP | 116 | wave_array[i] = (unsigned char)((WAV_AMP |
170 | * (sin((i * 360 * plasma_frequency) / 256))) / 16384); | 117 | * (sin_int((i * 360 * plasma_frequency) / 256))) / 16384); |
171 | } | 118 | } |
172 | } | 119 | } |
173 | 120 | ||