A couple more tweaks
[Rockbox.git] / apps / plugins / cube.c
blob31faf323f95c6937383611dcdbc59cec3f8d3c4c
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Damien Teney
11 * modified to use int instead of float math by Andreas Zwirtes
12 * heavily extended by Jens Arnold
14 * All files in this archive are subject to the GNU General Public License.
15 * See the file COPYING in the source tree root for full license agreement.
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 "gray.h"
23 #include "playergfx.h"
24 #include "xlcd.h"
25 #include "fixedpoint.h"
27 PLUGIN_HEADER
29 /* Loops that the values are displayed */
30 #define DISP_TIME 30
32 /* variable button definitions */
33 #if CONFIG_KEYPAD == RECORDER_PAD
34 #define CUBE_QUIT BUTTON_OFF
35 #define CUBE_X_INC BUTTON_RIGHT
36 #define CUBE_X_DEC BUTTON_LEFT
37 #define CUBE_Y_INC BUTTON_UP
38 #define CUBE_Y_DEC BUTTON_DOWN
39 #define CUBE_Z_INC BUTTON_F2
40 #define CUBE_Z_DEC BUTTON_F1
41 #define CUBE_MODE BUTTON_F3
42 #define CUBE_PAUSE BUTTON_PLAY
43 #define CUBE_HIGHSPEED BUTTON_ON
45 #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
46 #define CUBE_QUIT BUTTON_OFF
47 #define CUBE_X_INC BUTTON_RIGHT
48 #define CUBE_X_DEC BUTTON_LEFT
49 #define CUBE_Y_INC BUTTON_UP
50 #define CUBE_Y_DEC BUTTON_DOWN
51 #define CUBE_Z_INC BUTTON_F2
52 #define CUBE_Z_DEC BUTTON_F1
53 #define CUBE_MODE BUTTON_F3
54 #define CUBE_PAUSE BUTTON_SELECT
55 #define CUBE_HIGHSPEED BUTTON_ON
57 #elif CONFIG_KEYPAD == PLAYER_PAD
58 #define CUBE_QUIT BUTTON_STOP
59 #define CUBE_X_INC BUTTON_RIGHT
60 #define CUBE_X_DEC BUTTON_LEFT
61 #define CUBE_Y_INC (BUTTON_ON | BUTTON_RIGHT)
62 #define CUBE_Y_DEC (BUTTON_ON | BUTTON_LEFT)
63 #define CUBE_Z_INC (BUTTON_MENU | BUTTON_RIGHT)
64 #define CUBE_Z_DEC (BUTTON_MENU | BUTTON_LEFT)
65 #define CUBE_MODE_PRE BUTTON_MENU
66 #define CUBE_MODE (BUTTON_MENU | BUTTON_REL)
67 #define CUBE_PAUSE BUTTON_PLAY
68 #define CUBE_HIGHSPEED_PRE BUTTON_ON
69 #define CUBE_HIGHSPEED (BUTTON_ON | BUTTON_REL)
71 #elif CONFIG_KEYPAD == ONDIO_PAD
72 #define CUBE_QUIT BUTTON_OFF
73 #define CUBE_X_INC BUTTON_RIGHT
74 #define CUBE_X_DEC BUTTON_LEFT
75 #define CUBE_Y_INC BUTTON_UP
76 #define CUBE_Y_DEC BUTTON_DOWN
77 #define CUBE_Z_INC (BUTTON_MENU | BUTTON_UP)
78 #define CUBE_Z_DEC (BUTTON_MENU | BUTTON_DOWN)
79 #define CUBE_MODE_PRE BUTTON_MENU
80 #define CUBE_MODE (BUTTON_MENU | BUTTON_REL)
81 #define CUBE_PAUSE (BUTTON_MENU | BUTTON_LEFT)
82 #define CUBE_HIGHSPEED (BUTTON_MENU | BUTTON_RIGHT)
84 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
85 (CONFIG_KEYPAD == IRIVER_H300_PAD)
86 #define CUBE_QUIT BUTTON_OFF
87 #define CUBE_X_INC BUTTON_RIGHT
88 #define CUBE_X_DEC BUTTON_LEFT
89 #define CUBE_Y_INC BUTTON_UP
90 #define CUBE_Y_DEC BUTTON_DOWN
91 #define CUBE_Z_INC (BUTTON_ON | BUTTON_UP)
92 #define CUBE_Z_DEC (BUTTON_ON | BUTTON_DOWN)
93 #define CUBE_MODE BUTTON_MODE
94 #define CUBE_PAUSE_PRE BUTTON_ON
95 #define CUBE_PAUSE (BUTTON_ON | BUTTON_REL)
96 #define CUBE_HIGHSPEED BUTTON_SELECT
98 #define CUBE_RC_QUIT BUTTON_RC_STOP
100 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
101 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
102 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
103 #define CUBE_QUIT BUTTON_MENU
104 #define CUBE_X_INC BUTTON_RIGHT
105 #define CUBE_X_DEC BUTTON_LEFT
106 #define CUBE_Y_INC BUTTON_SCROLL_FWD
107 #define CUBE_Y_DEC BUTTON_SCROLL_BACK
108 #define CUBE_Z_INC (BUTTON_SELECT | BUTTON_RIGHT)
109 #define CUBE_Z_DEC (BUTTON_SELECT | BUTTON_LEFT)
110 #define CUBE_MODE (BUTTON_SELECT | BUTTON_MENU)
111 #define CUBE_PAUSE_PRE BUTTON_PLAY
112 #define CUBE_PAUSE (BUTTON_PLAY | BUTTON_REL)
113 #define CUBE_HIGHSPEED (BUTTON_SELECT | BUTTON_PLAY)
115 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
116 #define CUBE_QUIT BUTTON_PLAY
117 #define CUBE_X_INC BUTTON_RIGHT
118 #define CUBE_X_DEC BUTTON_LEFT
119 #define CUBE_Y_INC BUTTON_UP
120 #define CUBE_Y_DEC BUTTON_DOWN
121 #define CUBE_Z_INC BUTTON_MODE
122 #define CUBE_Z_DEC BUTTON_EQ
123 #define CUBE_MODE (BUTTON_SELECT | BUTTON_REPEAT)
124 #define CUBE_PAUSE (BUTTON_SELECT | BUTTON_REL)
125 #define CUBE_HIGHSPEED (BUTTON_MODE | BUTTON_EQ) /* TODO: this is impossible */
127 #elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
128 #define CUBE_QUIT BUTTON_POWER
129 #define CUBE_X_INC BUTTON_LEFT
130 #define CUBE_X_DEC BUTTON_RIGHT
131 #define CUBE_Y_INC BUTTON_UP
132 #define CUBE_Y_DEC BUTTON_DOWN
133 #define CUBE_Z_INC (BUTTON_PLAY | BUTTON_UP)
134 #define CUBE_Z_DEC (BUTTON_PLAY | BUTTON_DOWN)
135 #define CUBE_MODE BUTTON_SELECT
136 #define CUBE_PAUSE_PRE BUTTON_PLAY
137 #define CUBE_PAUSE (BUTTON_PLAY | BUTTON_REL)
138 #define CUBE_HIGHSPEED (BUTTON_REC | BUTTON_REL)
140 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
141 #define CUBE_QUIT BUTTON_POWER
142 #define CUBE_X_INC BUTTON_LEFT
143 #define CUBE_X_DEC BUTTON_RIGHT
144 #define CUBE_Y_INC BUTTON_UP
145 #define CUBE_Y_DEC BUTTON_DOWN
146 #define CUBE_Z_INC BUTTON_VOL_UP
147 #define CUBE_Z_DEC BUTTON_VOL_DOWN
148 #define CUBE_MODE BUTTON_MENU
149 #define CUBE_PAUSE BUTTON_SELECT
150 #define CUBE_HIGHSPEED BUTTON_A
152 #elif (CONFIG_KEYPAD == SANSA_E200_PAD)
153 #define CUBE_QUIT BUTTON_POWER
154 #define CUBE_X_INC BUTTON_LEFT
155 #define CUBE_X_DEC BUTTON_RIGHT
156 #define CUBE_Y_INC BUTTON_SCROLL_UP
157 #define CUBE_Y_DEC BUTTON_SCROLL_DOWN
158 #define CUBE_Z_INC BUTTON_UP
159 #define CUBE_Z_DEC BUTTON_DOWN
160 #define CUBE_MODE_PRE BUTTON_SELECT
161 #define CUBE_MODE (BUTTON_SELECT|BUTTON_REPEAT)
162 #define CUBE_PAUSE_PRE BUTTON_SELECT
163 #define CUBE_PAUSE (BUTTON_SELECT|BUTTON_REL)
164 #define CUBE_HIGHSPEED BUTTON_REC
166 #elif (CONFIG_KEYPAD == SANSA_C200_PAD)
167 #define CUBE_QUIT BUTTON_POWER
168 #define CUBE_X_INC BUTTON_LEFT
169 #define CUBE_X_DEC BUTTON_RIGHT
170 #define CUBE_Y_INC BUTTON_VOL_UP
171 #define CUBE_Y_DEC BUTTON_VOL_DOWN
172 #define CUBE_Z_INC BUTTON_UP
173 #define CUBE_Z_DEC BUTTON_DOWN
174 #define CUBE_MODE_PRE BUTTON_SELECT
175 #define CUBE_MODE (BUTTON_SELECT|BUTTON_REPEAT)
176 #define CUBE_PAUSE_PRE BUTTON_SELECT
177 #define CUBE_PAUSE (BUTTON_SELECT|BUTTON_REL)
178 #define CUBE_HIGHSPEED BUTTON_REC
181 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
182 #define CUBE_QUIT BUTTON_POWER
183 #define CUBE_X_INC BUTTON_LEFT
184 #define CUBE_X_DEC BUTTON_RIGHT
185 #define CUBE_Y_INC BUTTON_SCROLL_UP
186 #define CUBE_Y_DEC BUTTON_SCROLL_DOWN
187 #define CUBE_Z_INC (BUTTON_PLAY | BUTTON_SCROLL_UP)
188 #define CUBE_Z_DEC (BUTTON_PLAY | BUTTON_SCROLL_DOWN)
189 #define CUBE_MODE BUTTON_REW
190 #define CUBE_PAUSE_PRE BUTTON_PLAY
191 #define CUBE_PAUSE (BUTTON_PLAY | BUTTON_REL)
192 #define CUBE_HIGHSPEED (BUTTON_FF | BUTTON_REL)
194 #elif CONFIG_KEYPAD == MROBE500_PAD
195 #define CUBE_QUIT BUTTON_POWER
196 #define CUBE_X_INC BUTTON_LEFT
197 #define CUBE_X_DEC BUTTON_RIGHT
198 #define CUBE_Y_INC BUTTON_RC_PLAY
199 #define CUBE_Y_DEC BUTTON_RC_DOWN
200 #define CUBE_Z_INC BUTTON_RC_VOL_UP
201 #define CUBE_Z_DEC BUTTON_RC_VOL_DOWN
202 #define CUBE_MODE BUTTON_RC_MODE
203 #define CUBE_PAUSE_PRE BUTTON_RC_HEART
204 #define CUBE_PAUSE (BUTTON_RC_HEART | BUTTON_REL)
205 #define CUBE_HIGHSPEED BUTTON_RC_HEART
207 #endif
209 #ifdef HAVE_LCD_BITMAP
211 #define DIST (10 * MIN(LCD_HEIGHT, LCD_WIDTH) / 16)
212 static int x_off = LCD_WIDTH/2;
213 static int y_off = LCD_HEIGHT/2;
215 #if LCD_DEPTH == 1
216 #define USE_GSLIB
217 struct my_lcd {
218 void (*update)(void);
219 void (*clear_display)(void);
220 void (*drawline)(int x1, int y1, int x2, int y2);
221 void (*putsxy)(int x, int y, const unsigned char *string);
224 static struct my_lcd grayfuncs = {
225 gray_update, gray_clear_display, gray_drawline, gray_putsxy
227 static struct my_lcd lcdfuncs; /* initialised at runtime */
228 static struct my_lcd *mylcd = &grayfuncs;
230 #define MYLCD(fn) mylcd->fn
231 #define MY_FILLTRIANGLE(x1, y1, x2, y2, x3, y3) gray_filltriangle(x1, y1, x2, y2, x3, y3)
232 #define MY_SET_FOREGROUND(fg) gray_set_foreground(fg)
233 #define MY_GET_FOREGROUND() gray_get_foreground()
235 #else
236 #define MYLCD(fn) rb->lcd_ ## fn
237 #define MY_FILLTRIANGLE(x1, y1, x2, y2, x3, y3) xlcd_filltriangle(x1, y1, x2, y2, x3, y3)
238 #define MY_SET_FOREGROUND(fg) rb->lcd_set_foreground(fg)
239 #define MY_GET_FOREGROUND() rb->lcd_get_foreground()
240 #endif
242 #if CONFIG_LCD == LCD_SSD1815
243 #define ASPECT 320 /* = 1.25 (fixed point 24.8) */
244 #else
245 #define ASPECT 256 /* = 1.00 */
246 #endif
248 #else /* !LCD_BITMAP */
250 #define MYLCD(fn) pgfx_ ## fn
251 #define DIST 9
252 static int x_off = 10;
253 static int y_off = 7;
254 #define ASPECT 300 /* = 1.175 */
256 #endif /* !LCD_BITMAP */
258 struct point_3D {
259 long x, y, z;
262 struct point_2D {
263 long x, y;
266 struct line {
267 int start, end;
270 struct face {
271 int corner[4];
272 int line[4];
275 /* initial, unrotated cube corners */
276 static const struct point_3D sommet[8] =
278 {-DIST, -DIST, -DIST},
279 { DIST, -DIST, -DIST},
280 { DIST, DIST, -DIST},
281 {-DIST, DIST, -DIST},
282 {-DIST, -DIST, DIST},
283 { DIST, -DIST, DIST},
284 { DIST, DIST, DIST},
285 {-DIST, DIST, DIST}
288 /* The 12 lines forming the edges */
289 static const struct line lines[12] =
291 {0, 1}, {1, 2}, {2, 3}, {3, 0},
292 {4, 7}, {7, 6}, {6, 5}, {5, 4},
293 {0, 4}, {1, 5}, {2, 6}, {3, 7}
296 static bool lines_drawn[12];
298 /* The 6 faces of the cube; points are in clockwise order when viewed
299 from the outside */
300 static const struct face faces[6] =
302 {{0, 1, 2, 3}, {0, 1, 2, 3}},
303 {{4, 7, 6, 5}, {4, 5, 6, 7}},
304 {{0, 4, 5, 1}, {8, 7, 9, 0}},
305 {{2, 6, 7, 3}, {10, 5, 11, 2}},
306 {{0, 3, 7, 4}, {3, 11, 4, 8}},
307 {{1, 5, 6, 2}, {9, 6, 10, 1}}
310 #if LCD_DEPTH > 1 || defined(USE_GSLIB)
311 static const unsigned face_colors[6] =
313 #ifdef HAVE_LCD_COLOR
314 LCD_RGBPACK(255, 0, 0), LCD_RGBPACK(255, 0, 0), LCD_RGBPACK(0, 255, 0),
315 LCD_RGBPACK(0, 255, 0), LCD_RGBPACK(0, 0, 255), LCD_RGBPACK(0, 0, 255)
316 #elif defined(USE_GSLIB)
317 GRAY_LIGHTGRAY, GRAY_LIGHTGRAY, GRAY_DARKGRAY,
318 GRAY_DARKGRAY, GRAY_BLACK, GRAY_BLACK
319 #else
320 LCD_LIGHTGRAY, LCD_LIGHTGRAY, LCD_DARKGRAY,
321 LCD_DARKGRAY, LCD_BLACK, LCD_BLACK
322 #endif
324 #endif
326 enum {
327 #if LCD_DEPTH > 1 || defined(USE_GSLIB)
328 SOLID,
329 #endif
330 HIDDEN_LINES,
331 WIREFRAME,
332 NUM_MODES
335 static int mode = 0;
337 static struct point_3D point3D[8];
338 static struct point_2D point2D[8];
339 static long matrice[3][3];
341 static const int nb_points = 8;
342 static long z_off = 600;
344 static struct plugin_api* rb;
346 static void cube_rotate(int xa, int ya, int za)
348 int i;
349 /* Just to prevent unnecessary lookups */
350 long sxa, cxa, sya, cya, sza, cza;
352 sxa = sin_int(xa);
353 cxa = cos_int(xa);
354 sya = sin_int(ya);
355 cya = cos_int(ya);
356 sza = sin_int(za);
357 cza = cos_int(za);
359 /* calculate overall translation matrix */
360 matrice[0][0] = (cza * cya) >> 14;
361 matrice[1][0] = (sza * cya) >> 14;
362 matrice[2][0] = -sya;
364 matrice[0][1] = (((cza * sya) >> 14) * sxa - sza * cxa) >> 14;
365 matrice[1][1] = (((sza * sya) >> 14) * sxa + cxa * cza) >> 14;
366 matrice[2][1] = (sxa * cya) >> 14;
368 matrice[0][2] = (((cza * sya) >> 14) * cxa + sza * sxa) >> 14;
369 matrice[1][2] = (((sza * sya) >> 14) * cxa - cza * sxa) >> 14;
370 matrice[2][2] = (cxa * cya) >> 14;
372 /* apply translation matrix to all points */
373 for (i = 0; i < nb_points; i++)
375 point3D[i].x = matrice[0][0] * sommet[i].x + matrice[1][0] * sommet[i].y
376 + matrice[2][0] * sommet[i].z;
378 point3D[i].y = matrice[0][1] * sommet[i].x + matrice[1][1] * sommet[i].y
379 + matrice[2][1] * sommet[i].z;
381 point3D[i].z = matrice[0][2] * sommet[i].x + matrice[1][2] * sommet[i].y
382 + matrice[2][2] * sommet[i].z;
386 static void cube_viewport(void)
388 int i;
390 /* Do viewport transformation for all points */
391 for (i = 0; i < nb_points; i++)
393 #if ASPECT != 256
394 point2D[i].x = (point3D[i].x * ASPECT) / (point3D[i].z + (z_off << 14))
395 + x_off;
396 #else
397 point2D[i].x = (point3D[i].x << 8) / (point3D[i].z + (z_off << 14))
398 + x_off;
399 #endif
400 point2D[i].y = (point3D[i].y << 8) / (point3D[i].z + (z_off << 14))
401 + y_off;
405 static void cube_draw(void)
407 int i, j, line;
408 #if LCD_DEPTH > 1 || defined(USE_GSLIB)
409 unsigned old_foreground;
410 #endif
412 switch (mode)
414 #if LCD_DEPTH > 1 || defined(USE_GSLIB)
415 case SOLID:
417 old_foreground = MY_GET_FOREGROUND();
418 for (i = 0; i < 6; i++)
420 /* backface culling; if the shape winds counter-clockwise, we are
421 * looking at the backface, and the (simplified) cross product
422 * is < 0. Do not draw it. */
423 if (0 >= (point2D[faces[i].corner[1]].x - point2D[faces[i].corner[0]].x)
424 * (point2D[faces[i].corner[2]].y - point2D[faces[i].corner[1]].y)
425 - (point2D[faces[i].corner[1]].y - point2D[faces[i].corner[0]].y)
426 * (point2D[faces[i].corner[2]].x - point2D[faces[i].corner[1]].x))
427 continue;
429 MY_SET_FOREGROUND(face_colors[i]);
430 MY_FILLTRIANGLE(point2D[faces[i].corner[0]].x,
431 point2D[faces[i].corner[0]].y,
432 point2D[faces[i].corner[1]].x,
433 point2D[faces[i].corner[1]].y,
434 point2D[faces[i].corner[2]].x,
435 point2D[faces[i].corner[2]].y);
436 MY_FILLTRIANGLE(point2D[faces[i].corner[0]].x,
437 point2D[faces[i].corner[0]].y,
438 point2D[faces[i].corner[2]].x,
439 point2D[faces[i].corner[2]].y,
440 point2D[faces[i].corner[3]].x,
441 point2D[faces[i].corner[3]].y);
444 MY_SET_FOREGROUND(old_foreground);
445 break;
446 #endif /* (LCD_DEPTH > 1) || GSLIB */
448 case HIDDEN_LINES:
450 rb->memset(lines_drawn, 0, sizeof(lines_drawn));
451 for (i = 0; i < 6; i++)
453 /* backface culling; if the shape winds counter-clockwise, we are
454 * looking at the backface, and the (simplified) cross product
455 * is < 0. Do not draw it. */
456 if (0 >= (point2D[faces[i].corner[1]].x - point2D[faces[i].corner[0]].x)
457 * (point2D[faces[i].corner[2]].y - point2D[faces[i].corner[1]].y)
458 - (point2D[faces[i].corner[1]].y - point2D[faces[i].corner[0]].y)
459 * (point2D[faces[i].corner[2]].x - point2D[faces[i].corner[1]].x))
460 continue;
462 for (j = 0; j < 4; j++)
464 line = faces[i].line[j];
465 if (!lines_drawn[line])
467 lines_drawn[line] = true;
468 MYLCD(drawline)(point2D[lines[line].start].x,
469 point2D[lines[line].start].y,
470 point2D[lines[line].end].x,
471 point2D[lines[line].end].y);
475 break;
477 case WIREFRAME:
479 for (i = 0; i < 12; i++)
480 MYLCD(drawline)(point2D[lines[i].start].x,
481 point2D[lines[i].start].y,
482 point2D[lines[i].end].x,
483 point2D[lines[i].end].y);
484 break;
488 void cleanup(void *parameter)
490 (void)parameter;
492 #ifdef USE_GSLIB
493 gray_release();
494 #elif defined HAVE_LCD_CHARCELLS
495 pgfx_release();
496 #endif
499 enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
501 char buffer[30];
502 int t_disp = 0;
503 #ifdef USE_GSLIB
504 unsigned char *gbuf;
505 size_t gbuf_size = 0;
506 bool mode_switch = true;
507 #endif
509 int button;
510 int lastbutton = BUTTON_NONE;
511 int xa = 0;
512 int ya = 0;
513 int za = 0;
514 int xs = 1;
515 int ys = 3;
516 int zs = 1;
517 bool highspeed = false;
518 bool paused = false;
519 bool redraw = true;
520 bool exit = false;
522 (void)(parameter);
523 rb = api;
525 #ifdef HAVE_LCD_BITMAP
526 #if LCD_DEPTH > 1
527 xlcd_init(rb);
528 #elif defined(USE_GSLIB)
529 gbuf = (unsigned char *)rb->plugin_get_buffer(&gbuf_size);
530 if (gray_init(rb, gbuf, gbuf_size, true, LCD_WIDTH, LCD_HEIGHT, 3, 0, NULL)
531 != 3)
533 rb->splash(HZ, "Couldn't get grayscale buffer");
534 return PLUGIN_ERROR;
536 /* init lcd_ function pointers */
537 lcdfuncs.update = rb->lcd_update;
538 lcdfuncs.clear_display = rb->lcd_clear_display;
539 lcdfuncs.drawline = rb->lcd_drawline;
540 lcdfuncs.putsxy = rb->lcd_putsxy;
542 gray_setfont(FONT_SYSFIXED);
543 #endif
544 rb->lcd_setfont(FONT_SYSFIXED);
545 #else /* LCD_CHARCELLS */
546 if (!pgfx_init(rb, 4, 2))
548 rb->splash(HZ*2, "Old LCD :(");
549 return PLUGIN_OK;
551 pgfx_display(3, 0);
552 #endif
554 while(!exit)
556 if (highspeed)
557 rb->yield();
558 else
559 rb->sleep(4);
561 if (redraw)
563 MYLCD(clear_display)();
564 cube_rotate(xa, ya, za);
565 cube_viewport();
566 cube_draw();
567 redraw = false;
570 #ifdef HAVE_LCD_BITMAP
571 if (t_disp > 0)
573 t_disp--;
574 rb->snprintf(buffer, sizeof(buffer), "x:%d y:%d z:%d h:%d",
575 xs, ys, zs, highspeed);
576 MYLCD(putsxy)(0, LCD_HEIGHT-8, buffer);
577 if (t_disp == 0)
578 redraw = true;
580 #else
581 if (t_disp > 0)
583 if (t_disp == DISP_TIME)
585 rb->snprintf(buffer, sizeof(buffer), "x%d", xs);
586 rb->lcd_puts(0, 0, buffer);
587 rb->snprintf(buffer, sizeof(buffer), "y%d", ys);
588 rb->lcd_puts(0, 1, buffer);
589 pgfx_display(3, 0);
590 rb->snprintf(buffer, sizeof(buffer), "z%d", zs);
591 rb->lcd_puts(8, 0, buffer);
592 rb->snprintf(buffer, sizeof(buffer), "h%d", highspeed);
593 rb->lcd_puts(8, 1, buffer);
595 t_disp--;
596 if (t_disp == 0)
598 rb->lcd_clear_display();
599 pgfx_display(3, 0);
602 #endif
603 #ifdef USE_GSLIB
604 if (mode_switch)
606 gray_show(mode == SOLID);
607 mode_switch = false;
609 #endif
610 MYLCD(update)();
612 if (!paused)
614 xa += xs;
615 if (xa > 359)
616 xa -= 360;
617 else if (xa < 0)
618 xa += 360;
620 ya += ys;
621 if (ya > 359)
622 ya -= 360;
623 else if (ya < 0)
624 ya += 360;
626 za += zs;
627 if (za > 359)
628 za -= 360;
629 else if (za < 0)
630 za += 360;
631 redraw = true;
634 button = rb->button_get(false);
635 switch (button)
637 case CUBE_X_INC:
638 case (CUBE_X_INC|BUTTON_REPEAT):
639 if( !paused )
641 if( xs < 10)
642 xs++;
644 else
646 xa++;
647 if( xa > 359 )
648 xa -= 360;
650 t_disp = DISP_TIME;
651 redraw = true;
652 break;
654 case CUBE_X_DEC:
655 case (CUBE_X_DEC|BUTTON_REPEAT):
656 if( !paused )
658 if (xs > -10)
659 xs--;
661 else
663 xa--;
664 if( xa < 0 )
665 xa += 360;
667 t_disp = DISP_TIME;
668 redraw = true;
669 break;
671 case CUBE_Y_INC:
672 case (CUBE_Y_INC|BUTTON_REPEAT):
673 if( !paused )
675 if (ys < 10)
676 ys++;
678 else
680 ya++;
681 if( ya > 359 )
682 ya -= 360;
684 t_disp = DISP_TIME;
685 redraw = true;
686 break;
688 case CUBE_Y_DEC:
689 case (CUBE_Y_DEC|BUTTON_REPEAT):
690 if( !paused )
692 if (ys > -10)
693 ys--;
695 else
697 ya--;
698 if( ya < 0 )
699 ya += 360;
701 t_disp = DISP_TIME;
702 redraw = true;
703 break;
705 case CUBE_Z_INC:
706 case (CUBE_Z_INC|BUTTON_REPEAT):
707 if( !paused )
709 if (zs < 10)
710 zs++;
712 else
714 za++;
715 if( za > 359 )
716 za -= 360;
718 t_disp = DISP_TIME;
719 redraw = true;
720 break;
722 case CUBE_Z_DEC:
723 case (CUBE_Z_DEC|BUTTON_REPEAT):
724 if( !paused )
726 if (zs > -10)
727 zs--;
729 else
731 za--;
732 if( za < 0 )
733 za += 360;
735 t_disp = DISP_TIME;
736 redraw = true;
737 break;
739 case CUBE_MODE:
740 #ifdef CUBE_MODE_PRE
741 if (lastbutton != CUBE_MODE_PRE)
742 break;
743 #endif
744 if (++mode >= NUM_MODES)
745 mode = 0;
746 #ifdef USE_GSLIB
747 mylcd = (mode == SOLID) ? &grayfuncs : &lcdfuncs;
748 mode_switch = true;
749 #endif
750 redraw = true;
751 break;
753 case CUBE_PAUSE:
754 #ifdef CUBE_PAUSE_PRE
755 if (lastbutton != CUBE_PAUSE_PRE)
756 break;
757 #endif
758 paused = !paused;
759 break;
761 case CUBE_HIGHSPEED:
762 #ifdef CUBE_HIGHSPEED_PRE
763 if (lastbutton != CUBE_HIGHSPEED_PRE)
764 break;
765 #endif
766 highspeed = !highspeed;
767 t_disp = DISP_TIME;
768 break;
770 #ifdef CUBE_RC_QUIT
771 case CUBE_RC_QUIT:
772 #endif
773 case CUBE_QUIT:
774 exit = true;
775 break;
777 default:
778 if (rb->default_event_handler_ex(button, cleanup, NULL)
779 == SYS_USB_CONNECTED)
780 return PLUGIN_USB_CONNECTED;
781 break;
783 if (button != BUTTON_NONE)
784 lastbutton = button;
787 #ifdef USE_GSLIB
788 gray_release();
789 #elif defined(HAVE_LCD_CHARCELLS)
790 pgfx_release();
791 #endif
792 return PLUGIN_OK;