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 ****************************************************************************/
23 /* variable button definitions */
24 #if CONFIG_KEYPAD == RECORDER_PAD
25 #define PUZZLE_QUIT BUTTON_OFF
26 #define PUZZLE_LEFT BUTTON_LEFT
27 #define PUZZLE_RIGHT BUTTON_RIGHT
28 #define PUZZLE_UP BUTTON_UP
29 #define PUZZLE_DOWN BUTTON_DOWN
30 #define PUZZLE_SHUFFLE BUTTON_F1
31 #define PUZZLE_PICTURE BUTTON_F2
33 #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
34 #define PUZZLE_QUIT BUTTON_OFF
35 #define PUZZLE_LEFT BUTTON_LEFT
36 #define PUZZLE_RIGHT BUTTON_RIGHT
37 #define PUZZLE_UP BUTTON_UP
38 #define PUZZLE_DOWN BUTTON_DOWN
39 #define PUZZLE_SHUFFLE BUTTON_F1
40 #define PUZZLE_PICTURE BUTTON_F2
42 #elif CONFIG_KEYPAD == ONDIO_PAD
43 #define PUZZLE_QUIT BUTTON_OFF
44 #define PUZZLE_LEFT BUTTON_LEFT
45 #define PUZZLE_RIGHT BUTTON_RIGHT
46 #define PUZZLE_UP BUTTON_UP
47 #define PUZZLE_DOWN BUTTON_DOWN
48 #define PUZZLE_SHUFFLE_PICTURE_PRE BUTTON_MENU
49 #define PUZZLE_SHUFFLE (BUTTON_MENU | BUTTON_REPEAT)
50 #define PUZZLE_PICTURE (BUTTON_MENU | BUTTON_REL)
52 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
53 (CONFIG_KEYPAD == IRIVER_H300_PAD)
54 #define PUZZLE_QUIT BUTTON_OFF
55 #define PUZZLE_LEFT BUTTON_LEFT
56 #define PUZZLE_RIGHT BUTTON_RIGHT
57 #define PUZZLE_UP BUTTON_UP
58 #define PUZZLE_DOWN BUTTON_DOWN
59 #define PUZZLE_SHUFFLE BUTTON_SELECT
60 #define PUZZLE_PICTURE BUTTON_ON
62 #define PUZZLE_RC_QUIT BUTTON_RC_STOP
64 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
65 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
66 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
67 #define PUZZLE_QUIT (BUTTON_SELECT | BUTTON_MENU)
68 #define PUZZLE_LEFT BUTTON_LEFT
69 #define PUZZLE_RIGHT BUTTON_RIGHT
70 #define PUZZLE_UP BUTTON_MENU
71 #define PUZZLE_DOWN BUTTON_PLAY
72 #define PUZZLE_SHUFFLE (BUTTON_SELECT | BUTTON_LEFT)
73 #define PUZZLE_PICTURE (BUTTON_SELECT | BUTTON_RIGHT)
75 #elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
76 #define PUZZLE_QUIT BUTTON_POWER
77 #define PUZZLE_LEFT BUTTON_LEFT
78 #define PUZZLE_RIGHT BUTTON_RIGHT
79 #define PUZZLE_UP BUTTON_UP
80 #define PUZZLE_DOWN BUTTON_DOWN
81 #define PUZZLE_SHUFFLE BUTTON_REC
82 #define PUZZLE_PICTURE BUTTON_PLAY
84 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
85 #define PUZZLE_QUIT BUTTON_POWER
86 #define PUZZLE_LEFT BUTTON_LEFT
87 #define PUZZLE_RIGHT BUTTON_RIGHT
88 #define PUZZLE_UP BUTTON_UP
89 #define PUZZLE_DOWN BUTTON_DOWN
90 #define PUZZLE_SHUFFLE BUTTON_SELECT
91 #define PUZZLE_PICTURE BUTTON_A
93 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
94 (CONFIG_KEYPAD == SANSA_C200_PAD)
95 #define PUZZLE_QUIT BUTTON_POWER
96 #define PUZZLE_LEFT BUTTON_LEFT
97 #define PUZZLE_RIGHT BUTTON_RIGHT
98 #define PUZZLE_UP BUTTON_UP
99 #define PUZZLE_DOWN BUTTON_DOWN
100 #define PUZZLE_SHUFFLE BUTTON_REC
101 #define PUZZLE_PICTURE BUTTON_SELECT
103 #elif (CONFIG_KEYPAD == SANSA_FUZE_PAD)
104 #define PUZZLE_QUIT (BUTTON_HOME|BUTTON_REPEAT)
105 #define PUZZLE_LEFT BUTTON_LEFT
106 #define PUZZLE_RIGHT BUTTON_RIGHT
107 #define PUZZLE_UP BUTTON_UP
108 #define PUZZLE_DOWN BUTTON_DOWN
109 #define PUZZLE_SHUFFLE BUTTON_SELECT|BUTTON_DOWN
110 #define PUZZLE_PICTURE BUTTON_SELECT
112 #elif (CONFIG_KEYPAD == SANSA_CLIP_PAD)
113 #define PUZZLE_QUIT BUTTON_POWER
114 #define PUZZLE_LEFT BUTTON_LEFT
115 #define PUZZLE_RIGHT BUTTON_RIGHT
116 #define PUZZLE_UP BUTTON_UP
117 #define PUZZLE_DOWN BUTTON_DOWN
118 #define PUZZLE_SHUFFLE BUTTON_HOME
119 #define PUZZLE_PICTURE BUTTON_SELECT
121 #elif (CONFIG_KEYPAD == SANSA_M200_PAD)
122 #define PUZZLE_QUIT BUTTON_POWER
123 #define PUZZLE_LEFT BUTTON_LEFT
124 #define PUZZLE_RIGHT BUTTON_RIGHT
125 #define PUZZLE_UP BUTTON_UP
126 #define PUZZLE_DOWN BUTTON_DOWN
127 #define PUZZLE_SHUFFLE (BUTTON_SELECT | BUTTON_UP)
128 #define PUZZLE_PICTURE (BUTTON_SELECT | BUTTON_REL)
130 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
131 #define PUZZLE_QUIT BUTTON_POWER
132 #define PUZZLE_LEFT BUTTON_LEFT
133 #define PUZZLE_RIGHT BUTTON_RIGHT
134 #define PUZZLE_UP BUTTON_SCROLL_UP
135 #define PUZZLE_DOWN BUTTON_SCROLL_DOWN
136 #define PUZZLE_SHUFFLE BUTTON_REW
137 #define PUZZLE_PICTURE BUTTON_PLAY
139 #elif (CONFIG_KEYPAD == GIGABEAT_S_PAD)
140 #define PUZZLE_QUIT BUTTON_BACK
141 #define PUZZLE_LEFT BUTTON_LEFT
142 #define PUZZLE_RIGHT BUTTON_RIGHT
143 #define PUZZLE_UP BUTTON_UP
144 #define PUZZLE_DOWN BUTTON_DOWN
145 #define PUZZLE_SHUFFLE BUTTON_SELECT
146 #define PUZZLE_PICTURE BUTTON_MENU
148 #elif (CONFIG_KEYPAD == MROBE100_PAD)
149 #define PUZZLE_QUIT BUTTON_POWER
150 #define PUZZLE_LEFT BUTTON_LEFT
151 #define PUZZLE_RIGHT BUTTON_RIGHT
152 #define PUZZLE_UP BUTTON_UP
153 #define PUZZLE_DOWN BUTTON_DOWN
154 #define PUZZLE_SHUFFLE BUTTON_SELECT
155 #define PUZZLE_PICTURE BUTTON_DISPLAY
157 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
158 #define PUZZLE_QUIT BUTTON_RC_REC
159 #define PUZZLE_LEFT BUTTON_RC_REW
160 #define PUZZLE_RIGHT BUTTON_RC_FF
161 #define PUZZLE_UP BUTTON_RC_VOL_UP
162 #define PUZZLE_DOWN BUTTON_RC_VOL_DOWN
163 #define PUZZLE_SHUFFLE BUTTON_RC_MODE
164 #define PUZZLE_PICTURE BUTTON_RC_MENU
166 #elif (CONFIG_KEYPAD == COWON_D2_PAD)
167 #define PUZZLE_QUIT BUTTON_POWER
168 #define PUZZLE_QUIT_TEXT "[POWER]"
170 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
171 #define PUZZLE_QUIT BUTTON_BACK
172 #define PUZZLE_LEFT BUTTON_LEFT
173 #define PUZZLE_RIGHT BUTTON_RIGHT
174 #define PUZZLE_UP BUTTON_UP
175 #define PUZZLE_DOWN BUTTON_DOWN
176 #define PUZZLE_SHUFFLE BUTTON_PLAY
177 #define PUZZLE_PICTURE BUTTON_MENU
179 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
180 #define PUZZLE_QUIT BUTTON_POWER
181 #define PUZZLE_LEFT BUTTON_LEFT
182 #define PUZZLE_RIGHT BUTTON_RIGHT
183 #define PUZZLE_UP BUTTON_UP
184 #define PUZZLE_DOWN BUTTON_DOWN
185 #define PUZZLE_SHUFFLE BUTTON_VIEW
186 #define PUZZLE_PICTURE BUTTON_MENU
188 #elif CONFIG_KEYPAD == PHILIPS_HDD6330_PAD
189 #define PUZZLE_QUIT BUTTON_POWER
190 #define PUZZLE_LEFT BUTTON_LEFT
191 #define PUZZLE_RIGHT BUTTON_RIGHT
192 #define PUZZLE_UP BUTTON_UP
193 #define PUZZLE_DOWN BUTTON_DOWN
194 #define PUZZLE_SHUFFLE BUTTON_NEXT
195 #define PUZZLE_PICTURE BUTTON_MENU
197 #elif CONFIG_KEYPAD == PHILIPS_SA9200_PAD
198 #define PUZZLE_QUIT BUTTON_POWER
199 #define PUZZLE_LEFT BUTTON_PREV
200 #define PUZZLE_RIGHT BUTTON_NEXT
201 #define PUZZLE_UP BUTTON_UP
202 #define PUZZLE_DOWN BUTTON_DOWN
203 #define PUZZLE_SHUFFLE BUTTON_RIGHT
204 #define PUZZLE_PICTURE BUTTON_MENU
206 #elif CONFIG_KEYPAD == ONDAVX747_PAD || \
207 CONFIG_KEYPAD == ONDAVX777_PAD || \
208 CONFIG_KEYPAD == MROBE500_PAD
209 #define PUZZLE_QUIT BUTTON_POWER
210 #define PUZZLE_QUIT_TEXT "[POWER]"
212 #elif (CONFIG_KEYPAD == SAMSUNG_YH_PAD)
213 #define PUZZLE_QUIT BUTTON_REC
214 #define PUZZLE_LEFT BUTTON_LEFT
215 #define PUZZLE_RIGHT BUTTON_RIGHT
216 #define PUZZLE_UP BUTTON_UP
217 #define PUZZLE_DOWN BUTTON_DOWN
218 #define PUZZLE_SHUFFLE BUTTON_REW
219 #define PUZZLE_PICTURE BUTTON_PLAY
221 #elif (CONFIG_KEYPAD == PBELL_VIBE500_PAD)
222 #define PUZZLE_QUIT BUTTON_REC
223 #define PUZZLE_LEFT BUTTON_PREV
224 #define PUZZLE_RIGHT BUTTON_NEXT
225 #define PUZZLE_UP BUTTON_UP
226 #define PUZZLE_DOWN BUTTON_DOWN
227 #define PUZZLE_SHUFFLE BUTTON_CANCEL
228 #define PUZZLE_PICTURE BUTTON_MENU
230 #elif CONFIG_KEYPAD == MPIO_HD200_PAD
231 #define PUZZLE_QUIT (BUTTON_REC | BUTTON_PLAY)
232 #define PUZZLE_LEFT BUTTON_VOL_DOWN
233 #define PUZZLE_RIGHT BUTTON_VOL_UP
234 #define PUZZLE_UP BUTTON_REW
235 #define PUZZLE_DOWN BUTTON_FF
236 #define PUZZLE_SHUFFLE BUTTON_REC
237 #define PUZZLE_PICTURE BUTTON_PLAY
239 #elif CONFIG_KEYPAD == MPIO_HD300_PAD
240 #define PUZZLE_QUIT (BUTTON_REC | BUTTON_REPEAT)
241 #define PUZZLE_LEFT BUTTON_REW
242 #define PUZZLE_RIGHT BUTTON_FF
243 #define PUZZLE_UP BUTTON_UP
244 #define PUZZLE_DOWN BUTTON_DOWN
245 #define PUZZLE_SHUFFLE BUTTON_ENTER
246 #define PUZZLE_PICTURE BUTTON_PLAY
249 #error No keymap defined!
252 #ifdef HAVE_TOUCHSCREEN
254 #define PUZZLE_QUIT BUTTON_TOPLEFT
257 #define PUZZLE_LEFT BUTTON_MIDLEFT
260 #define PUZZLE_RIGHT BUTTON_MIDRIGHT
263 #define PUZZLE_UP BUTTON_TOPMIDDLE
266 #define PUZZLE_DOWN BUTTON_BOTTOMMIDDLE
268 #ifndef PUZZLE_SHUFFLE
269 #define PUZZLE_SHUFFLE BUTTON_BOTTOMLEFT
271 #ifndef PUZZLE_PICTURE
272 #define PUZZLE_PICTURE BUTTON_CENTER
274 #ifndef PUZZLE_QUIT_TEXT
275 #define PUZZLE_QUIT_TEXT "[TOPLEFT]"
277 #ifndef PUZZLE_SHUFFLE_TEXT
278 #define PUZZLE_SHUFFLE_TEXT "[BOTTOMLEFT]"
280 #ifndef PUZZLE_PICTURE_TEXT
281 #define PUZZLE_PICTURE_TEXT "[CENTER]"
286 #include "lib/read_image.h"
287 #define READ_IMAGE read_image_file
289 #define READ_IMAGE rb->read_bmp_file
292 #include "pluginbitmaps/sliding_puzzle.h"
293 #define IMAGE_WIDTH BMPWIDTH_sliding_puzzle
294 #define IMAGE_HEIGHT BMPHEIGHT_sliding_puzzle
295 #define IMAGE_SIZE IMAGE_WIDTH
297 /* use a square image, (the default Archos bitmap looks square on its display)
298 Puzzle image dimension is min(lcd_height,lcd_width)
299 4x4 is more convenient for square puzzles
300 Note: sliding_puzzle.bmp should be evenly divisible by SPOTS_X
301 and SPOTS_Y, otherwise lcd_bitmap_part stride won't be correct */
304 #define SPOTS_WIDTH (IMAGE_WIDTH / SPOTS_X)
305 #define SPOTS_HEIGHT (IMAGE_HEIGHT / SPOTS_Y)
306 #define NUM_SPOTS (SPOTS_X*SPOTS_Y)
307 #define HOLE_ID (NUM_SPOTS)
308 #define INITIAL_HOLE (HOLE_ID-1)
312 PICMODE_NUMERALS
= 0,
313 PICMODE_INITIAL_PICTURE
,
314 PICMODE_DEFAULT_PICTURE
,
319 PICMODE_LAST_XXX
/* placeholder */
322 static const char* const picmode_descriptions
[] = {
329 "Shouldn't Get Here",
332 static int spots
[NUM_SPOTS
];
333 static int hole
= INITIAL_HOLE
, moves
;
334 static unsigned char s
[32];
335 static enum picmodes picmode
= PICMODE_INITIAL_PICTURE
;
336 static int num_font
= FONT_UI
;
337 static int moves_font
= FONT_UI
;
338 static int moves_y
= 0;
340 static unsigned char *img_buf
;
341 static size_t img_buf_len
;
343 static char albumart_path
[MAX_PATH
+1];
345 static char img_buf_path
[MAX_PATH
+1];
347 static const fb_data
* puzzle_bmp_ptr
;
348 /* initial_bmp_path points to selected bitmap if this game is launched
349 as a viewer for a .bmp file, or NULL if game is launched regular way */
350 static const char * initial_bmp_path
=NULL
;
353 const char * get_albumart_bmp_path(void)
355 struct mp3entry
* track
= rb
->audio_current_track();
357 if (!track
|| !track
->path
|| track
->path
[0] == '\0')
360 if (!rb
->search_albumart_files(track
, "", albumart_path
, MAX_PATH
) )
363 albumart_path
[ MAX_PATH
] = '\0';
364 return albumart_path
;
368 const char * get_random_bmp_path(void)
370 return(initial_bmp_path
);
373 static bool load_resize_bitmap(void)
376 const char * filename
= NULL
;
378 /* initially assume using the built-in default */
379 puzzle_bmp_ptr
= sliding_puzzle
;
382 /* some modes don't even need to touch disk and trivially succeed */
383 case PICMODE_NUMERALS
:
384 case PICMODE_DEFAULT_PICTURE
:
389 case PICMODE_ALBUM_ART
:
390 filename
= get_albumart_bmp_path();
395 if(NULL == (filename=get_random_bmp_path()) )
396 filename = initial_bmp_path;
399 case PICMODE_INITIAL_PICTURE
:
400 filename
= initial_bmp_path
;
404 if( filename
!= NULL
)
406 /* if we already loaded image before, don't touch disk */
407 if( 0 == rb
->strcmp( filename
, img_buf_path
) )
409 puzzle_bmp_ptr
= (const fb_data
*)img_buf
;
413 struct bitmap main_bitmap
;
414 rb
->memset(&main_bitmap
,0,sizeof(struct bitmap
));
415 main_bitmap
.data
= img_buf
;
417 main_bitmap
.width
= IMAGE_WIDTH
;
418 main_bitmap
.height
= IMAGE_HEIGHT
;
420 rc
= READ_IMAGE( filename
, &main_bitmap
,
422 FORMAT_NATIVE
|FORMAT_RESIZE
|FORMAT_DITHER
,
426 puzzle_bmp_ptr
= (const fb_data
*)img_buf
;
427 rb
->strcpy( img_buf_path
, filename
);
432 /* something must have failed. get_albumart_bmp_path could return
433 NULL if albumart doesn't exist or couldn't be loaded, or
434 read_bmp_file could have failed. return false and caller should
435 try the next mode (PICMODE_DEFAULT_PICTURE and PICMODE_NUMERALS will
440 /* draws a spot at the coordinates (x,y), range of p is 1-20 */
441 static void draw_spot(int p
, int x
, int y
)
448 /* the bottom-right cell of the default sliding_puzzle image is
449 an appropriate hole graphic */
450 rb
->lcd_bitmap_part(sliding_puzzle
, ((p
-1)%SPOTS_X
)*SPOTS_WIDTH
,
451 ((p
-1)/SPOTS_X
)*SPOTS_HEIGHT
,
453 BMPWIDTH_sliding_puzzle
, BMPHEIGHT_sliding_puzzle
),
454 x
, y
, SPOTS_WIDTH
, SPOTS_HEIGHT
);
456 /* just draw a black rectangle */
457 int old_fg
= rb
->lcd_get_foreground();
458 rb
->lcd_set_foreground(LCD_BLACK
);
459 rb
->lcd_fillrect(x
,y
,SPOTS_WIDTH
,SPOTS_HEIGHT
);
460 rb
->lcd_set_foreground(LCD_WHITE
);
461 rb
->lcd_drawrect(x
,y
,SPOTS_WIDTH
,SPOTS_HEIGHT
);
462 rb
->lcd_set_foreground(old_fg
);
465 else if (picmode
!= PICMODE_NUMERALS
)
467 rb
->lcd_bitmap_part( puzzle_bmp_ptr
, ((p
-1)%SPOTS_X
)*SPOTS_WIDTH
,
468 ((p
-1)/SPOTS_X
)*SPOTS_HEIGHT
,
470 BMPWIDTH_sliding_puzzle
, BMPHEIGHT_sliding_puzzle
),
471 x
, y
, SPOTS_WIDTH
, SPOTS_HEIGHT
);
473 rb
->lcd_drawrect(x
, y
, SPOTS_WIDTH
, SPOTS_HEIGHT
);
474 rb
->lcd_set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
475 rb
->lcd_fillrect(x
+1, y
+1, SPOTS_WIDTH
-2, SPOTS_HEIGHT
-2);
476 rb
->lcd_set_drawmode(DRMODE_SOLID
);
477 rb
->snprintf(s
, sizeof(s
), "%d", p
);
478 rb
->lcd_setfont(num_font
);
479 rb
->lcd_getstringsize(s
, &w
, &h
);
480 rb
->lcd_putsxy(x
+ (SPOTS_WIDTH
/2) - w
/ 2,
481 y
+ (SPOTS_HEIGHT
/2) - h
/ 2, s
);
485 /* check if the puzzle is solved */
486 static bool puzzle_finished(void)
489 for (i
=0; i
<NUM_SPOTS
; i
++)
490 if (spots
[i
] != (i
+1))
495 /* move a piece in any direction */
496 static void move_spot(int x
, int y
)
499 spots
[hole
] = spots
[hole
-x
-SPOTS_X
*y
];
500 hole
-= (x
+SPOTS_X
*y
);
502 rb
->lcd_setfont(moves_font
);
503 #if LCD_WIDTH > LCD_HEIGHT
504 rb
->snprintf(s
, sizeof(s
), "%d", moves
);
505 w
= rb
->lcd_getstringsize(s
, NULL
, NULL
);
506 rb
->lcd_putsxy((IMAGE_WIDTH
+1+(LCD_WIDTH
-IMAGE_WIDTH
-1)/2) - w
/ 2,
510 rb
->lcd_putsxyf(3, moves_y
, "Moves: %d", moves
);
515 (hole
%SPOTS_X
)*SPOTS_WIDTH
,
516 (hole
/SPOTS_X
)*SPOTS_HEIGHT
);
517 draw_spot(spots
[hole
],
518 (hole
%SPOTS_X
)*SPOTS_WIDTH
+ (i
*x
*SPOTS_WIDTH
)/5,
519 (hole
/SPOTS_X
)*SPOTS_HEIGHT
+ (i
*y
*SPOTS_HEIGHT
)/5);
524 (hole
%SPOTS_X
)*SPOTS_WIDTH
,
525 (hole
/SPOTS_X
)*SPOTS_HEIGHT
);
526 draw_spot(spots
[hole
],
527 ((hole
%SPOTS_X
)+x
)*SPOTS_WIDTH
,
528 ((hole
/SPOTS_X
)+y
)*SPOTS_HEIGHT
);
531 spots
[hole
] = HOLE_ID
;
534 static void draw_playfield(void)
538 rb
->lcd_clear_display();
539 rb
->lcd_setfont(moves_font
);
540 #if LCD_WIDTH > LCD_HEIGHT
541 rb
->lcd_vline(IMAGE_WIDTH
, 0, LCD_HEIGHT
-1);
542 w
= rb
->lcd_getstringsize("Moves", NULL
, NULL
);
543 rb
->lcd_putsxy((IMAGE_WIDTH
+1+(LCD_WIDTH
-IMAGE_WIDTH
-1)/2) - w
/ 2,
545 rb
->snprintf(s
, sizeof(s
), "%d", moves
);
546 w
= rb
->lcd_getstringsize(s
, NULL
, NULL
);
547 rb
->lcd_putsxy((IMAGE_WIDTH
+1+(LCD_WIDTH
-IMAGE_WIDTH
-1)/2) - w
/ 2,
551 rb
->lcd_hline(0, LCD_WIDTH
-1, IMAGE_HEIGHT
);
552 rb
->lcd_putsxyf(3, moves_y
, "Moves: %d", moves
);
555 /* draw spots to the lcd */
556 for (i
=0; i
<NUM_SPOTS
; i
++)
557 draw_spot(spots
[i
], (i
%SPOTS_X
)*SPOTS_WIDTH
, (i
/SPOTS_X
)*SPOTS_HEIGHT
);
562 /* initializes the puzzle */
563 static void puzzle_init(void)
565 int i
, r
, temp
, tsp
[NUM_SPOTS
];
570 for (i
=NUM_SPOTS
-1; i
>=0; i
--) {
571 r
= (rb
->rand() % (i
+1));
577 if (spots
[i
]==HOLE_ID
)
581 /* test if the puzzle is solvable */
582 for (i
=0; i
<NUM_SPOTS
; i
++)
586 /* First, check if the problem has even or odd parity,
587 depending on where the empty square is */
588 if ((((SPOTS_X
-1)-hole
%SPOTS_X
) + ((SPOTS_Y
-1)-hole
/SPOTS_X
))%2 == 1)
591 /* Now check how many swaps we need to solve it */
592 for (i
=0; i
<NUM_SPOTS
-1; i
++) {
593 while (tsp
[i
] != (i
+1)) {
595 tsp
[i
] = tsp
[temp
-1];
601 /* if the random puzzle isn't solvable just change two spots */
603 if (spots
[0]!=HOLE_ID
&& spots
[1]!=HOLE_ID
) {
617 /* the main game loop */
618 static int puzzle_loop(void)
621 int lastbutton
= BUTTON_NONE
;
626 button
= rb
->button_get(true);
628 #ifdef PUZZLE_RC_QUIT
632 /* get out of here */
636 #ifdef PUZZLE_SHUFFLE_PICTURE_PRE
637 if (lastbutton
!= PUZZLE_SHUFFLE_PICTURE_PRE
)
640 /* mix up the pieces */
645 #ifdef PUZZLE_SHUFFLE_PICTURE_PRE
646 if (lastbutton
!= PUZZLE_SHUFFLE_PICTURE_PRE
)
650 picmode
= (picmode
+1)%PICMODE_LAST_XXX
;
652 /* if load_resize_bitmap fails to load bitmap, try next picmode
656 load_success
= load_resize_bitmap();
658 picmode
= (picmode
+1)%PICMODE_LAST_XXX
;
660 while( !load_success
);
662 /* tell the user what mode we picked in the end! */
663 rb
->splash(HZ
,picmode_descriptions
[ picmode
] );
668 if ((hole
%SPOTS_X
)<(SPOTS_X
-1) && !puzzle_finished())
673 if ((hole
%SPOTS_X
)>0 && !puzzle_finished())
678 if ((hole
/SPOTS_X
)<(SPOTS_Y
-1) && !puzzle_finished())
683 if ((hole
/SPOTS_X
)>0 && !puzzle_finished())
688 if (rb
->default_event_handler(button
) == SYS_USB_CONNECTED
)
689 return PLUGIN_USB_CONNECTED
;
692 if (button
!= BUTTON_NONE
)
697 enum plugin_status
plugin_start(
698 const void* parameter
)
702 initial_bmp_path
=(const char *)parameter
;
703 img_buf
= rb
->plugin_get_buffer(&img_buf_len
);
704 picmode
= PICMODE_INITIAL_PICTURE
;
705 img_buf_path
[0] = '\0';
707 /* If launched as a viewer, just go straight to the game without
708 bothering with the splash or instructions page */
711 /* if not launched as a viewer, use default puzzle, and show help */
712 picmode
= PICMODE_DEFAULT_PICTURE
;
715 rb
->lcd_getstringsize((unsigned char *)"Sliding Puzzle", &w
, &h
);
718 rb
->lcd_clear_display();
719 rb
->lcd_putsxy(LCD_WIDTH
/2-w
, (LCD_HEIGHT
/2)-h
,
720 (unsigned char *)"Sliding Puzzle");
724 /* print instructions */
725 rb
->lcd_clear_display();
726 rb
->lcd_setfont(FONT_SYSFIXED
);
727 #if CONFIG_KEYPAD == RECORDER_PAD || CONFIG_KEYPAD == ARCHOS_AV300_PAD
728 rb
->lcd_putsxy(3, 18, "[OFF] to stop");
729 rb
->lcd_putsxy(3, 28, "[F1] shuffle");
730 rb
->lcd_putsxy(3, 38, "[F2] change pic");
731 #elif CONFIG_KEYPAD == ONDIO_PAD
732 rb
->lcd_putsxy(0, 18, "[OFF] to stop");
733 rb
->lcd_putsxy(0, 28, "[MODE..] shuffle");
734 rb
->lcd_putsxy(0, 38, "[MODE] change pic");
735 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
736 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
737 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
738 rb
->lcd_putsxy(0, 18, "[S-MENU] to stop");
739 rb
->lcd_putsxy(0, 28, "[S-LEFT] shuffle");
740 rb
->lcd_putsxy(0, 38, "[S-RIGHT] change pic");
741 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
742 (CONFIG_KEYPAD == IRIVER_H300_PAD)
743 rb
->lcd_putsxy(0, 18, "[STOP] to stop");
744 rb
->lcd_putsxy(0, 28, "[SELECT] shuffle");
745 rb
->lcd_putsxy(0, 38, "[PLAY] change pic");
746 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
747 rb
->lcd_putsxy(0, 18, "[OFF] to stop");
748 rb
->lcd_putsxy(0, 28, "[REC] shuffle");
749 rb
->lcd_putsxy(0, 38, "[PLAY] change pic");
750 #elif CONFIG_KEYPAD == GIGABEAT_PAD
751 rb
->lcd_putsxy(0, 18, "[POWER] to stop");
752 rb
->lcd_putsxy(0, 28, "[SELECT] shuffle");
753 rb
->lcd_putsxy(0, 38, "[A] change pic");
754 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
755 (CONFIG_KEYPAD == SANSA_C200_PAD)
756 rb
->lcd_putsxy(0, 18, "[OFF] to stop");
757 rb
->lcd_putsxy(0, 28, "[REC] shuffle");
758 rb
->lcd_putsxy(0, 38, "[SELECT] change pic");
759 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
760 rb
->lcd_putsxy(0, 18, "[OFF] to stop");
761 rb
->lcd_putsxy(0, 28, "[REW] shuffle");
762 rb
->lcd_putsxy(0, 38, "[PLAY] change pic");
763 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
764 rb
->lcd_putsxy(0, 18, "[BACK] to stop");
765 rb
->lcd_putsxy(0, 28, "[SELECT] shuffle");
766 rb
->lcd_putsxy(0, 38, "[MENU] change pic");
767 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
768 rb
->lcd_putsxy(0, 18, "[REC] to stop");
769 rb
->lcd_putsxy(0, 28, "[MODE] shuffle");
770 rb
->lcd_putsxy(0, 38, "[MENU] change pic");
772 #ifdef HAVE_TOUCHSCREEN
773 rb
->lcd_putsxy(0, 18, PUZZLE_QUIT_TEXT
" to stop");
774 rb
->lcd_putsxy(0, 28, PUZZLE_SHUFFLE_TEXT
" shuffle");
775 rb
->lcd_putsxy(0, 38, PUZZLE_PICTURE_TEXT
" change pic");
778 rb
->lcd_putsxy(0,48," pic->albumart->num");
780 rb
->lcd_putsxy(0,48," pic<->num");
783 rb
->button_get_w_tmo(HZ
*2);
788 if( !load_resize_bitmap() )
790 rb
->lcd_clear_display();
791 rb
->splash(HZ
*2,"Failed to load bitmap!");
795 /* Calculate possible font sizes and text positions */
796 rb
->lcd_setfont(FONT_UI
);
797 rb
->lcd_getstringsize("15", &w
, &h
);
798 if ((w
> (SPOTS_WIDTH
-2)) || (h
> (SPOTS_HEIGHT
-2)))
799 num_font
= FONT_SYSFIXED
;
801 #if LCD_WIDTH > LCD_HEIGHT
802 rb
->lcd_getstringsize("Moves", &w
, &h
);
803 if (w
> (LCD_WIDTH
-IMAGE_WIDTH
-1))
804 moves_font
= FONT_SYSFIXED
;
805 rb
->lcd_setfont(moves_font
);
806 rb
->lcd_getstringsize("Moves", &w
, &h
);
809 rb
->lcd_getstringsize("Moves: 999", &w
, &h
);
810 if ((w
> LCD_WIDTH
) || (h
> (LCD_HEIGHT
-IMAGE_HEIGHT
-1)))
811 moves_font
= FONT_SYSFIXED
;
812 rb
->lcd_setfont(moves_font
);
813 rb
->lcd_getstringsize("Moves: 999", &w
, &h
);
814 moves_y
= (IMAGE_HEIGHT
+1+(LCD_HEIGHT
-IMAGE_HEIGHT
-1)/2) - h
/ 2;
816 for (i
=0; i
<NUM_SPOTS
; i
++)
819 #ifdef HAVE_LCD_COLOR
820 rb
->lcd_set_background(LCD_BLACK
);
821 rb
->lcd_set_foreground(LCD_WHITE
);
822 rb
->lcd_set_backdrop(NULL
);
824 rb
->lcd_set_background(LCD_WHITE
);
825 rb
->lcd_set_foreground(LCD_BLACK
);
826 rb
->lcd_set_backdrop(NULL
);
832 return puzzle_loop();