1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 Vicentini Martin
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 ****************************************************************************/
25 /* variable button definitions */
26 #if CONFIG_KEYPAD == RECORDER_PAD
27 #define FLIPIT_LEFT BUTTON_LEFT
28 #define FLIPIT_RIGHT BUTTON_RIGHT
29 #define FLIPIT_UP BUTTON_UP
30 #define FLIPIT_DOWN BUTTON_DOWN
31 #define FLIPIT_QUIT BUTTON_OFF
32 #define FLIPIT_SHUFFLE BUTTON_F1
33 #define FLIPIT_SOLVE BUTTON_F2
34 #define FLIPIT_STEP_BY_STEP BUTTON_F3
35 #define FLIPIT_TOGGLE BUTTON_PLAY
37 #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
38 #define FLIPIT_LEFT BUTTON_LEFT
39 #define FLIPIT_RIGHT BUTTON_RIGHT
40 #define FLIPIT_UP BUTTON_UP
41 #define FLIPIT_DOWN BUTTON_DOWN
42 #define FLIPIT_QUIT BUTTON_OFF
43 #define FLIPIT_SHUFFLE BUTTON_F1
44 #define FLIPIT_SOLVE BUTTON_F2
45 #define FLIPIT_STEP_BY_STEP BUTTON_F3
46 #define FLIPIT_TOGGLE BUTTON_SELECT
48 #elif CONFIG_KEYPAD == PLAYER_PAD
49 #define FLIPIT_LEFT BUTTON_LEFT
50 #define FLIPIT_RIGHT BUTTON_RIGHT
51 #define FLIPIT_UP_PRE BUTTON_ON
52 #define FLIPIT_UP (BUTTON_ON | BUTTON_REL)
53 #define FLIPIT_DOWN BUTTON_MENU
54 #define FLIPIT_QUIT BUTTON_STOP
55 #define FLIPIT_SHUFFLE (BUTTON_ON | BUTTON_LEFT)
56 #define FLIPIT_SOLVE (BUTTON_ON | BUTTON_RIGHT)
57 #define FLIPIT_STEP_BY_STEP (BUTTON_ON | BUTTON_PLAY)
58 #define FLIPIT_TOGGLE BUTTON_PLAY
60 #elif CONFIG_KEYPAD == ONDIO_PAD
61 #define FLIPIT_LEFT BUTTON_LEFT
62 #define FLIPIT_RIGHT BUTTON_RIGHT
63 #define FLIPIT_UP BUTTON_UP
64 #define FLIPIT_DOWN BUTTON_DOWN
65 #define FLIPIT_QUIT BUTTON_OFF
66 #define FLIPIT_SHUFFLE (BUTTON_MENU | BUTTON_LEFT)
67 #define FLIPIT_SOLVE (BUTTON_MENU | BUTTON_UP)
68 #define FLIPIT_STEP_BY_STEP (BUTTON_MENU | BUTTON_RIGHT)
69 #define FLIPIT_TOGGLE_PRE BUTTON_MENU
70 #define FLIPIT_TOGGLE (BUTTON_MENU | BUTTON_REL)
72 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
73 (CONFIG_KEYPAD == IRIVER_H300_PAD)
74 #define FLIPIT_LEFT BUTTON_LEFT
75 #define FLIPIT_RIGHT BUTTON_RIGHT
76 #define FLIPIT_UP BUTTON_UP
77 #define FLIPIT_DOWN BUTTON_DOWN
78 #define FLIPIT_QUIT BUTTON_OFF
79 #define FLIPIT_SHUFFLE BUTTON_MODE
80 #define FLIPIT_SOLVE BUTTON_ON
81 #define FLIPIT_STEP_BY_STEP BUTTON_REC
82 #define FLIPIT_TOGGLE_PRE BUTTON_SELECT
83 #define FLIPIT_TOGGLE (BUTTON_SELECT | BUTTON_REL)
85 #define FLIPIT_RC_QUIT BUTTON_RC_STOP
87 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
88 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
89 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
91 #define FLIPIT_SCROLLWHEEL
92 #define FLIPIT_LEFT BUTTON_LEFT
93 #define FLIPIT_RIGHT BUTTON_RIGHT
94 #define FLIPIT_UP BUTTON_MENU
95 #define FLIPIT_DOWN BUTTON_PLAY
96 #define FLIPIT_NEXT BUTTON_SCROLL_FWD
97 #define FLIPIT_PREV BUTTON_SCROLL_BACK
98 #define FLIPIT_QUIT (BUTTON_SELECT | BUTTON_MENU)
99 #define FLIPIT_SHUFFLE (BUTTON_SELECT | BUTTON_LEFT)
100 #define FLIPIT_SOLVE (BUTTON_SELECT | BUTTON_PLAY)
101 #define FLIPIT_STEP_BY_STEP (BUTTON_SELECT | BUTTON_RIGHT)
102 #define FLIPIT_TOGGLE_PRE BUTTON_SELECT
103 #define FLIPIT_TOGGLE (BUTTON_SELECT | BUTTON_REL)
105 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
107 #define FLIPIT_LEFT BUTTON_LEFT
108 #define FLIPIT_RIGHT BUTTON_RIGHT
109 #define FLIPIT_UP BUTTON_UP
110 #define FLIPIT_DOWN BUTTON_DOWN
111 #define FLIPIT_QUIT BUTTON_POWER
112 #define FLIPIT_SHUFFLE BUTTON_REC
113 #define FLIPIT_SOLVE_PRE BUTTON_PLAY
114 #define FLIPIT_SOLVE (BUTTON_PLAY | BUTTON_REPEAT)
115 #define FLIPIT_STEP_PRE BUTTON_PLAY
116 #define FLIPIT_STEP_BY_STEP (BUTTON_PLAY | BUTTON_REL)
117 #define FLIPIT_TOGGLE BUTTON_SELECT
119 #elif CONFIG_KEYPAD == GIGABEAT_PAD
121 #define FLIPIT_LEFT BUTTON_LEFT
122 #define FLIPIT_RIGHT BUTTON_RIGHT
123 #define FLIPIT_UP BUTTON_UP
124 #define FLIPIT_DOWN BUTTON_DOWN
125 #define FLIPIT_QUIT BUTTON_POWER
126 #define FLIPIT_SHUFFLE BUTTON_MENU
127 #define FLIPIT_SOLVE BUTTON_VOL_UP
128 #define FLIPIT_STEP_BY_STEP BUTTON_VOL_DOWN
129 #define FLIPIT_TOGGLE BUTTON_SELECT
131 #elif CONFIG_KEYPAD == SANSA_E200_PAD
133 #define FLIPIT_SCROLLWHEEL
134 #define FLIPIT_LEFT BUTTON_LEFT
135 #define FLIPIT_RIGHT BUTTON_RIGHT
136 #define FLIPIT_UP BUTTON_UP
137 #define FLIPIT_DOWN BUTTON_DOWN
138 #define FLIPIT_NEXT BUTTON_SCROLL_FWD
139 #define FLIPIT_PREV BUTTON_SCROLL_BACK
140 #define FLIPIT_QUIT BUTTON_POWER
141 #define FLIPIT_SHUFFLE (BUTTON_REC | BUTTON_LEFT)
142 #define FLIPIT_SOLVE (BUTTON_REC | BUTTON_RIGHT)
143 #define FLIPIT_STEP_BY_STEP (BUTTON_REC | BUTTON_SELECT)
144 #define FLIPIT_TOGGLE BUTTON_SELECT
146 #elif (CONFIG_KEYPAD == SANSA_FUZE_PAD)
148 #define FLIPIT_SCROLLWHEEL
149 #define FLIPIT_LEFT BUTTON_LEFT
150 #define FLIPIT_RIGHT BUTTON_RIGHT
151 #define FLIPIT_UP BUTTON_UP
152 #define FLIPIT_DOWN BUTTON_DOWN
153 #define FLIPIT_NEXT BUTTON_SCROLL_FWD
154 #define FLIPIT_PREV BUTTON_SCROLL_BACK
155 #define FLIPIT_QUIT (BUTTON_HOME|BUTTON_REPEAT)
156 #define FLIPIT_SHUFFLE (BUTTON_SELECT | BUTTON_LEFT)
157 #define FLIPIT_SOLVE (BUTTON_SELECT | BUTTON_DOWN)
158 #define FLIPIT_STEP_BY_STEP (BUTTON_SELECT | BUTTON_RIGHT)
159 #define FLIPIT_TOGGLE_PRE BUTTON_SELECT
160 #define FLIPIT_TOGGLE (BUTTON_SELECT | BUTTON_REL)
162 #elif CONFIG_KEYPAD == SANSA_C200_PAD
164 #define FLIPIT_LEFT BUTTON_LEFT
165 #define FLIPIT_RIGHT BUTTON_RIGHT
166 #define FLIPIT_UP BUTTON_UP
167 #define FLIPIT_DOWN BUTTON_DOWN
168 #define FLIPIT_QUIT BUTTON_POWER
169 #define FLIPIT_SHUFFLE (BUTTON_REC | BUTTON_LEFT)
170 #define FLIPIT_SOLVE (BUTTON_REC | BUTTON_RIGHT)
171 #define FLIPIT_STEP_BY_STEP (BUTTON_REC | BUTTON_SELECT)
172 #define FLIPIT_TOGGLE BUTTON_SELECT
174 #elif CONFIG_KEYPAD == SANSA_CLIP_PAD
176 #define FLIPIT_LEFT BUTTON_LEFT
177 #define FLIPIT_RIGHT BUTTON_RIGHT
178 #define FLIPIT_UP BUTTON_UP
179 #define FLIPIT_DOWN BUTTON_DOWN
180 #define FLIPIT_QUIT BUTTON_POWER
181 #define FLIPIT_SHUFFLE (BUTTON_HOME | BUTTON_LEFT)
182 #define FLIPIT_SOLVE (BUTTON_HOME | BUTTON_RIGHT)
183 #define FLIPIT_STEP_BY_STEP (BUTTON_HOME | BUTTON_SELECT)
184 #define FLIPIT_TOGGLE BUTTON_SELECT
186 #elif CONFIG_KEYPAD == SANSA_M200_PAD
188 #define FLIPIT_LEFT BUTTON_LEFT
189 #define FLIPIT_RIGHT BUTTON_RIGHT
190 #define FLIPIT_UP BUTTON_UP
191 #define FLIPIT_DOWN BUTTON_DOWN
192 #define FLIPIT_QUIT BUTTON_POWER
193 #define FLIPIT_SHUFFLE (BUTTON_SELECT | BUTTON_LEFT)
194 #define FLIPIT_SOLVE (BUTTON_SELECT | BUTTON_RIGHT)
195 #define FLIPIT_STEP_BY_STEP (BUTTON_SELECT | BUTTON_UP)
196 #define FLIPIT_TOGGLE (BUTTON_SELECT | BUTTON_REL)
198 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
200 #define FLIPIT_LEFT BUTTON_LEFT
201 #define FLIPIT_RIGHT BUTTON_RIGHT
202 #define FLIPIT_UP BUTTON_SCROLL_UP
203 #define FLIPIT_DOWN BUTTON_SCROLL_DOWN
204 #define FLIPIT_QUIT BUTTON_POWER
205 #define FLIPIT_SHUFFLE (BUTTON_PLAY | BUTTON_LEFT)
206 #define FLIPIT_SOLVE (BUTTON_PLAY | BUTTON_RIGHT)
207 #define FLIPIT_STEP_BY_STEP (BUTTON_PLAY | BUTTON_SCROLL_UP)
208 #define FLIPIT_TOGGLE_PRE BUTTON_REW
209 #define FLIPIT_TOGGLE (BUTTON_REW | BUTTON_REL)
211 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
213 #define FLIPIT_LEFT BUTTON_LEFT
214 #define FLIPIT_RIGHT BUTTON_RIGHT
215 #define FLIPIT_UP BUTTON_UP
216 #define FLIPIT_DOWN BUTTON_DOWN
217 #define FLIPIT_QUIT BUTTON_BACK
218 #define FLIPIT_SHUFFLE BUTTON_MENU
219 #define FLIPIT_SOLVE BUTTON_VOL_UP
220 #define FLIPIT_STEP_BY_STEP BUTTON_VOL_DOWN
221 #define FLIPIT_TOGGLE BUTTON_SELECT
223 #elif CONFIG_KEYPAD == MROBE100_PAD
225 #define FLIPIT_LEFT BUTTON_LEFT
226 #define FLIPIT_RIGHT BUTTON_RIGHT
227 #define FLIPIT_UP BUTTON_UP
228 #define FLIPIT_DOWN BUTTON_DOWN
229 #define FLIPIT_QUIT BUTTON_POWER
230 #define FLIPIT_SHUFFLE BUTTON_MENU
231 #define FLIPIT_SOLVE BUTTON_PLAY
232 #define FLIPIT_STEP_BY_STEP BUTTON_DISPLAY
233 #define FLIPIT_TOGGLE BUTTON_SELECT
235 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
237 #define FLIPIT_LEFT BUTTON_RC_REW
238 #define FLIPIT_RIGHT BUTTON_RC_FF
239 #define FLIPIT_UP BUTTON_RC_VOL_UP
240 #define FLIPIT_DOWN BUTTON_RC_VOL_DOWN
241 #define FLIPIT_QUIT BUTTON_RC_REC
242 #define FLIPIT_SHUFFLE BUTTON_RC_MODE
243 #define FLIPIT_SOLVE_PRE BUTTON_RC_MENU
244 #define FLIPIT_SOLVE (BUTTON_RC_MENU|BUTTON_REPEAT)
245 #define FLIPIT_STEP_PRE BUTTON_RC_MENU
246 #define FLIPIT_STEP_BY_STEP (BUTTON_RC_MENU|BUTTON_REL)
247 #define FLIPIT_TOGGLE BUTTON_RC_PLAY
249 #define FLIPIT_RC_QUIT BUTTON_REC
251 #elif CONFIG_KEYPAD == COWOND2_PAD
253 #define FLIPIT_QUIT BUTTON_POWER
255 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
257 #define FLIPIT_LEFT BUTTON_LEFT
258 #define FLIPIT_RIGHT BUTTON_RIGHT
259 #define FLIPIT_UP BUTTON_UP
260 #define FLIPIT_DOWN BUTTON_DOWN
261 #define FLIPIT_QUIT BUTTON_BACK
262 #define FLIPIT_SHUFFLE BUTTON_CUSTOM
263 #define FLIPIT_SOLVE BUTTON_PLAY
264 #define FLIPIT_STEP_BY_STEP BUTTON_MENU
265 #define FLIPIT_TOGGLE BUTTON_SELECT
267 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
269 #define FLIPIT_LEFT BUTTON_LEFT
270 #define FLIPIT_RIGHT BUTTON_RIGHT
271 #define FLIPIT_UP BUTTON_UP
272 #define FLIPIT_DOWN BUTTON_DOWN
273 #define FLIPIT_QUIT BUTTON_POWER
274 #define FLIPIT_SHUFFLE BUTTON_MENU
275 #define FLIPIT_SOLVE BUTTON_VIEW
276 #define FLIPIT_STEP_BY_STEP BUTTON_PLAYLIST
277 #define FLIPIT_TOGGLE BUTTON_SELECT
279 #elif CONFIG_KEYPAD == ONDAVX747_PAD || CONFIG_KEYPAD == MROBE500_PAD
281 #define FLIPIT_QUIT BUTTON_POWER
283 #elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
285 #define FLIPIT_LEFT BUTTON_LEFT
286 #define FLIPIT_RIGHT BUTTON_RIGHT
287 #define FLIPIT_UP BUTTON_UP
288 #define FLIPIT_DOWN BUTTON_DOWN
289 #define FLIPIT_QUIT BUTTON_REC
290 #define FLIPIT_SHUFFLE BUTTON_PLAY
291 #define FLIPIT_SOLVE BUTTON_FFWD
292 #define FLIPIT_STEP_BY_STEP (BUTTON_PLAY|BUTTON_UP)
293 #define FLIPIT_TOGGLE (BUTTON_PLAY|BUTTON_DOWN)
297 #error No keymap defined!
300 #ifdef HAVE_TOUCHSCREEN
302 #define FLIPIT_LEFT BUTTON_MIDLEFT
305 #define FLIPIT_RIGHT BUTTON_MIDRIGHT
308 #define FLIPIT_UP BUTTON_TOPMIDDLE
311 #define FLIPIT_DOWN BUTTON_BOTTOMMIDDLE
314 #define FLIPIT_QUIT BUTTON_TOPLEFT
316 #ifndef FLIPIT_SHUFFLE
317 #define FLIPIT_SHUFFLE BUTTON_TOPRIGHT
320 #define FLIPIT_SOLVE BUTTON_BOTTOMLEFT
322 #ifndef FLIPIT_STEP_BY_STEP
323 #define FLIPIT_STEP_BY_STEP BUTTON_BOTTOMRIGHT
325 #ifndef FLIPIT_TOGGLE
326 #define FLIPIT_TOGGLE BUTTON_CENTER
330 static int spots
[20];
331 static int toggle
[20];
332 static int cursor_pos
, moves
;
334 #ifdef HAVE_LCD_BITMAP
336 #include "pluginbitmaps/flipit_cursor.h"
337 #include "pluginbitmaps/flipit_tokens.h"
339 #define PANEL_HEIGHT 12
340 #define TK_WIDTH BMPWIDTH_flipit_cursor
341 #define TK_HEIGHT BMPHEIGHT_flipit_cursor
342 #define TK_SPACE MAX(0, MIN((LCD_WIDTH - 5*TK_WIDTH)/4, \
343 (LCD_HEIGHT - PANEL_HEIGHT - 4*TK_HEIGHT)/4))
344 #define GRID_WIDTH (5*TK_WIDTH + 4*TK_SPACE)
345 #define GRID_LEFT ((LCD_WIDTH - GRID_WIDTH)/2)
346 #define GRID_HEIGHT (4*TK_HEIGHT + 4*TK_SPACE) /* includes grid-panel space */
347 #define GRID_TOP MAX(0, ((LCD_HEIGHT - PANEL_HEIGHT - GRID_HEIGHT)/2))
349 /* draw a spot at the coordinates (x,y), range of p is 0-19 */
350 static void draw_spot(int p
)
352 rb
->lcd_bitmap_part( flipit_tokens
, 0, spots
[p
] * TK_HEIGHT
, TK_WIDTH
,
353 GRID_LEFT
+ (p
%5) * (TK_WIDTH
+TK_SPACE
),
354 GRID_TOP
+ (p
/5) * (TK_HEIGHT
+TK_SPACE
),
355 TK_WIDTH
, TK_HEIGHT
);
358 /* draw the cursor at the current cursor position */
359 static void draw_cursor(void)
361 #ifdef HAVE_LCD_COLOR
362 rb
->lcd_bitmap_transparent( flipit_cursor
,
363 GRID_LEFT
+ (cursor_pos
%5) * (TK_WIDTH
+TK_SPACE
),
364 GRID_TOP
+ (cursor_pos
/5) * (TK_HEIGHT
+TK_SPACE
),
365 TK_WIDTH
, TK_HEIGHT
);
367 rb
->lcd_set_drawmode(DRMODE_FG
);
368 rb
->lcd_mono_bitmap( flipit_cursor
,
369 GRID_LEFT
+ (cursor_pos
%5) * (TK_WIDTH
+TK_SPACE
),
370 GRID_TOP
+ (cursor_pos
/5) * (TK_HEIGHT
+TK_SPACE
),
371 TK_WIDTH
, TK_HEIGHT
);
372 rb
->lcd_set_drawmode(DRMODE_SOLID
);
376 /* draw the info panel ... duh */
377 static void draw_info_panel(void)
381 rb
->lcd_set_drawmode( DRMODE_SOLID
|DRMODE_INVERSEVID
);
382 rb
->lcd_fillrect( GRID_LEFT
, GRID_TOP
+ 4*(TK_HEIGHT
+TK_SPACE
),
383 GRID_WIDTH
, PANEL_HEIGHT
);
384 rb
->lcd_set_drawmode( DRMODE_SOLID
);
385 rb
->lcd_drawrect( GRID_LEFT
, GRID_TOP
+ 4*(TK_HEIGHT
+TK_SPACE
),
386 GRID_WIDTH
, PANEL_HEIGHT
);
388 rb
->snprintf( s
, sizeof(s
), "Flips: %d", moves
);
389 rb
->lcd_putsxy( (LCD_WIDTH
- rb
->lcd_getstringsize(s
, NULL
, NULL
)) / 2,
390 GRID_TOP
+ 4*(TK_HEIGHT
+TK_SPACE
) + 2, s
);
393 #else /* HAVE_LCD_CHARCELLS */
395 static const unsigned char tk_pat
[4][7] = {
396 { 0x0e, 0x11, 0x0e, 0x00, 0x0e, 0x11, 0x0e }, /* white - white */
397 { 0x0e, 0x11, 0x0e, 0x00, 0x0e, 0x1f, 0x0e }, /* white - black */
398 { 0x0e, 0x1f, 0x0e, 0x00, 0x0e, 0x11, 0x0e }, /* black - white */
399 { 0x0e, 0x1f, 0x0e, 0x00, 0x0e, 0x1f, 0x0e } /* black - black */
402 static unsigned char cur_pat
[7];
403 static unsigned long gfx_chars
[5];
405 static void release_gfx(void)
409 for (i
= 0; i
< 5; i
++)
411 rb
->lcd_unlock_pattern(gfx_chars
[i
]);
414 static bool init_gfx(void)
418 for (i
= 0; i
< 5; i
++) {
419 if ((gfx_chars
[i
] = rb
->lcd_get_locked_pattern()) == 0) {
424 for (i
= 0; i
< 4; i
++)
425 rb
->lcd_define_pattern(gfx_chars
[i
], tk_pat
[i
]);
429 /* draw a spot at the coordinates (x,y), range of p is 0-19 */
430 static void draw_spot(int p
)
435 rb
->lcd_putc (p
%5, p
/10, gfx_chars
[2*spots
[p
]+spots
[p
+5]]);
438 /* draw the cursor at the current cursor position */
439 static void draw_cursor(void)
441 if ((cursor_pos
/5) & 1) {
442 rb
->memcpy( cur_pat
, tk_pat
[2*spots
[cursor_pos
-5]+spots
[cursor_pos
]], 7 );
447 rb
->memcpy( cur_pat
, tk_pat
[2*spots
[cursor_pos
]+spots
[cursor_pos
+5]], 7 );
451 rb
->lcd_define_pattern(gfx_chars
[4], cur_pat
);
452 rb
->lcd_putc( cursor_pos
%5, cursor_pos
/10, gfx_chars
[4] );
455 /* draw the info panel ... duh */
456 static void draw_info_panel(void)
460 rb
->lcd_puts( 6, 0, "Flips" );
461 rb
->snprintf( s
, sizeof(s
), "%d", moves
);
462 rb
->lcd_puts( 6, 1, s
);
467 /* clear the cursor where it is */
468 static inline void clear_cursor(void)
470 draw_spot( cursor_pos
);
473 /* check if the puzzle is finished */
474 static bool flipit_finished(void)
484 /* draws the toggled spots */
485 static void flipit_toggle(void)
487 spots
[cursor_pos
] = 1-spots
[cursor_pos
];
488 toggle
[cursor_pos
] = 1-toggle
[cursor_pos
];
489 draw_spot(cursor_pos
);
490 if (cursor_pos
%5 > 0) {
491 spots
[cursor_pos
-1] = 1-spots
[cursor_pos
-1];
492 draw_spot(cursor_pos
-1);
494 if (cursor_pos
%5 < 4) {
495 spots
[cursor_pos
+1] = 1-spots
[cursor_pos
+1];
496 draw_spot(cursor_pos
+1);
498 if (cursor_pos
/5 > 0) {
499 spots
[cursor_pos
-5] = 1-spots
[cursor_pos
-5];
500 draw_spot(cursor_pos
-5);
502 if (cursor_pos
/5 < 3) {
503 spots
[cursor_pos
+5] = 1-spots
[cursor_pos
+5];
504 draw_spot(cursor_pos
+5);
510 if (flipit_finished())
514 /* move the cursor in any direction */
515 static void move_cursor(int x
, int y
)
517 if (!(flipit_finished())) {
519 cursor_pos
= ( x
+ 5 + cursor_pos
%5 )%5
520 + ( ( y
+ 4 + cursor_pos
/5 )%4 )*5;
526 /* initialize the board */
527 static void flipit_init(void)
531 rb
->lcd_clear_display();
532 for (i
=0; i
<20; i
++) {
539 for (i
=0; i
<20; i
++) {
540 cursor_pos
= (rb
->rand() % 20);
551 /* the main game loop */
552 static bool flipit_loop(void)
556 int lastbutton
= BUTTON_NONE
;
560 button
= rb
->button_get(true);
562 #ifdef FLIPIT_RC_QUIT
566 /* get out of here */
570 /* mix up the pieces */
575 #ifdef FLIPIT_SOLVE_PRE
576 if (lastbutton
!= FLIPIT_SOLVE_PRE
)
579 /* solve the puzzle */
580 if (!flipit_finished()) {
593 case FLIPIT_STEP_BY_STEP
:
594 #ifdef FLIPIT_STEP_PRE
595 if (lastbutton
!= FLIPIT_STEP_PRE
)
598 if (!flipit_finished()) {
612 #ifdef FLIPIT_TOGGLE_PRE
613 if (lastbutton
!= FLIPIT_TOGGLE_PRE
)
616 /* toggle the pieces */
617 if (!flipit_finished()) {
631 /*move cursor though the entire field*/
632 #ifdef FLIPIT_SCROLLWHEEL
634 case FLIPIT_PREV
|BUTTON_REPEAT
:
635 if ((cursor_pos
)%5 == 0) {
644 case FLIPIT_NEXT
|BUTTON_REPEAT
:
645 if ((cursor_pos
+1)%5 == 0) {
655 if (lastbutton
!= FLIPIT_UP_PRE
)
666 if (rb
->default_event_handler(button
) == SYS_USB_CONNECTED
)
667 return PLUGIN_USB_CONNECTED
;
670 if (button
!= BUTTON_NONE
)
675 /* called function from outside */
676 enum plugin_status
plugin_start(const void* parameter
)
682 #ifdef HAVE_LCD_COLOR
683 rb
->lcd_set_background(LCD_WHITE
);
684 rb
->lcd_set_foreground(LCD_BLACK
);
688 rb
->lcd_set_backdrop(NULL
);
691 rb
->splash(HZ
, "FlipIt!");
693 #ifdef HAVE_LCD_BITMAP
694 /* print instructions */
695 rb
->lcd_clear_display();
696 rb
->lcd_setfont(FONT_SYSFIXED
);
697 #if CONFIG_KEYPAD == RECORDER_PAD
698 rb
->lcd_putsxy(2, 8, "[OFF] to stop");
699 rb
->lcd_putsxy(2, 18, "[PLAY] toggle");
700 rb
->lcd_putsxy(2, 28, "[F1] shuffle");
701 rb
->lcd_putsxy(2, 38, "[F2] solution");
702 rb
->lcd_putsxy(2, 48, "[F3] step by step");
703 #elif CONFIG_KEYPAD == ONDIO_PAD
704 rb
->lcd_putsxy(2, 8, "[OFF] to stop");
705 rb
->lcd_putsxy(2, 18, "[MODE] toggle");
706 rb
->lcd_putsxy(2, 28, "[M-LEFT] shuffle");
707 rb
->lcd_putsxy(2, 38, "[M-UP] solution");
708 rb
->lcd_putsxy(2, 48, "[M-RIGHT] step by step");
709 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
710 (CONFIG_KEYPAD == IRIVER_H300_PAD)
711 rb
->lcd_putsxy(2, 8, "[STOP] to stop");
712 rb
->lcd_putsxy(2, 18, "[SELECT] toggle");
713 rb
->lcd_putsxy(2, 28, "[MODE] shuffle");
714 rb
->lcd_putsxy(2, 38, "[PLAY] solution");
715 rb
->lcd_putsxy(2, 48, "[REC] step by step");
716 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
717 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
718 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
719 rb
->lcd_putsxy(2, 8, "[S-MENU] to stop");
720 rb
->lcd_putsxy(2, 18, "[SELECT] toggle");
721 rb
->lcd_putsxy(2, 28, "[S-LEFT] shuffle");
722 rb
->lcd_putsxy(2, 38, "[S-PLAY] solution");
723 rb
->lcd_putsxy(2, 48, "[S-RIGHT] step by step");
724 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
725 rb
->lcd_putsxy(2, 8, "[POWER] to stop");
726 rb
->lcd_putsxy(2, 18, "[SELECT] toggle");
727 rb
->lcd_putsxy(2, 28, "[REC] shuffle");
728 rb
->lcd_putsxy(2, 38, "[PLAY..] solution");
729 rb
->lcd_putsxy(2, 48, "[PLAY] step by step");
730 #elif CONFIG_KEYPAD == GIGABEAT_PAD
731 rb
->lcd_putsxy(2, 8, "[POWER] to stop");
732 rb
->lcd_putsxy(2, 18, "[SELECT] toggle");
733 rb
->lcd_putsxy(2, 28, "[MENU] shuffle");
734 rb
->lcd_putsxy(2, 38, "[VOL+] solution");
735 rb
->lcd_putsxy(2, 48, "[VOL-] step by step");
736 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
737 rb
->lcd_putsxy(2, 8, "[POWER] to stop");
738 rb
->lcd_putsxy(2, 18, "[REW] toggle");
739 rb
->lcd_putsxy(2, 28, "[PL-LEFT] shuffle");
740 rb
->lcd_putsxy(2, 38, "[PL-RIGHT] solution");
741 rb
->lcd_putsxy(2, 48, "[PL-UP] step by step");
742 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
743 rb
->lcd_putsxy(2, 8, "[BACK] to stop");
744 rb
->lcd_putsxy(2, 18, "[SELECT] toggle");
745 rb
->lcd_putsxy(2, 28, "[MENU] shuffle");
746 rb
->lcd_putsxy(2, 38, "[VOL+] solution");
747 rb
->lcd_putsxy(2, 48, "[VOL-] step by step");
748 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
749 (CONFIG_KEYPAD == SANSA_C200_PAD)
750 rb
->lcd_putsxy(2, 8, "[POWER] to stop");
751 rb
->lcd_putsxy(2, 18, "[SELECT] toggle");
752 rb
->lcd_putsxy(2, 28, "[REC-LEFT] shuffle");
753 rb
->lcd_putsxy(2, 38, "[REC-RIGHT] solution");
754 rb
->lcd_putsxy(2, 48, "[REC-SEL] step by step");
755 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
756 rb
->lcd_putsxy(2, 8, "[REC] to stop");
757 rb
->lcd_putsxy(2, 18, "[PLAY] toggle");
758 rb
->lcd_putsxy(2, 28, "[MODE] shuffle");
759 rb
->lcd_putsxy(2, 38, "[MENU..] solution");
760 rb
->lcd_putsxy(2, 48, "[MENU] step by step");
763 #ifdef HAVE_TOUCHSCREEN
764 rb
->lcd_putsxy(2, 8, "[BOTTOMLEFT] to stop");
765 rb
->lcd_putsxy(2, 18, "[CENTRE] toggle");
766 rb
->lcd_putsxy(2, 28, "[TOPRIGHT] shuffle");
767 rb
->lcd_putsxy(2, 38, "[BOTTOMLEFT] solution");
768 rb
->lcd_putsxy(2, 48, "[BOTTOMRIGHT] step by step");
772 #else /* HAVE_LCD_CHARCELLS */
776 rb
->button_get_w_tmo(HZ
*3);
778 rb
->lcd_clear_display();
780 for (i
=0; i
<20; i
++) {
786 rb
->srand(*rb
->current_tick
);
789 #ifdef HAVE_LCD_CHARCELLS