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 #ifdef HAVE_LCD_BITMAP
26 /* variable button definitions */
27 #if CONFIG_KEYPAD == RECORDER_PAD
28 #define PUZZLE_QUIT BUTTON_OFF
29 #define PUZZLE_LEFT BUTTON_LEFT
30 #define PUZZLE_RIGHT BUTTON_RIGHT
31 #define PUZZLE_UP BUTTON_UP
32 #define PUZZLE_DOWN BUTTON_DOWN
33 #define PUZZLE_SHUFFLE BUTTON_F1
34 #define PUZZLE_PICTURE BUTTON_F2
36 #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
37 #define PUZZLE_QUIT BUTTON_OFF
38 #define PUZZLE_LEFT BUTTON_LEFT
39 #define PUZZLE_RIGHT BUTTON_RIGHT
40 #define PUZZLE_UP BUTTON_UP
41 #define PUZZLE_DOWN BUTTON_DOWN
42 #define PUZZLE_SHUFFLE BUTTON_F1
43 #define PUZZLE_PICTURE BUTTON_F2
45 #elif CONFIG_KEYPAD == ONDIO_PAD
46 #define PUZZLE_QUIT BUTTON_OFF
47 #define PUZZLE_LEFT BUTTON_LEFT
48 #define PUZZLE_RIGHT BUTTON_RIGHT
49 #define PUZZLE_UP BUTTON_UP
50 #define PUZZLE_DOWN BUTTON_DOWN
51 #define PUZZLE_SHUFFLE_PICTURE_PRE BUTTON_MENU
52 #define PUZZLE_SHUFFLE (BUTTON_MENU | BUTTON_REPEAT)
53 #define PUZZLE_PICTURE (BUTTON_MENU | BUTTON_REL)
55 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
56 (CONFIG_KEYPAD == IRIVER_H300_PAD)
57 #define PUZZLE_QUIT BUTTON_OFF
58 #define PUZZLE_LEFT BUTTON_LEFT
59 #define PUZZLE_RIGHT BUTTON_RIGHT
60 #define PUZZLE_UP BUTTON_UP
61 #define PUZZLE_DOWN BUTTON_DOWN
62 #define PUZZLE_SHUFFLE BUTTON_SELECT
63 #define PUZZLE_PICTURE BUTTON_ON
65 #define PUZZLE_RC_QUIT BUTTON_RC_STOP
67 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
68 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
69 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
70 #define PUZZLE_QUIT (BUTTON_SELECT | BUTTON_MENU)
71 #define PUZZLE_LEFT BUTTON_LEFT
72 #define PUZZLE_RIGHT BUTTON_RIGHT
73 #define PUZZLE_UP BUTTON_MENU
74 #define PUZZLE_DOWN BUTTON_PLAY
75 #define PUZZLE_SHUFFLE (BUTTON_SELECT | BUTTON_LEFT)
76 #define PUZZLE_PICTURE (BUTTON_SELECT | BUTTON_RIGHT)
78 #elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
79 #define PUZZLE_QUIT BUTTON_POWER
80 #define PUZZLE_LEFT BUTTON_LEFT
81 #define PUZZLE_RIGHT BUTTON_RIGHT
82 #define PUZZLE_UP BUTTON_UP
83 #define PUZZLE_DOWN BUTTON_DOWN
84 #define PUZZLE_SHUFFLE BUTTON_REC
85 #define PUZZLE_PICTURE BUTTON_PLAY
87 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
88 #define PUZZLE_QUIT BUTTON_POWER
89 #define PUZZLE_LEFT BUTTON_LEFT
90 #define PUZZLE_RIGHT BUTTON_RIGHT
91 #define PUZZLE_UP BUTTON_UP
92 #define PUZZLE_DOWN BUTTON_DOWN
93 #define PUZZLE_SHUFFLE BUTTON_SELECT
94 #define PUZZLE_PICTURE BUTTON_A
96 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
97 (CONFIG_KEYPAD == SANSA_C200_PAD)
98 #define PUZZLE_QUIT BUTTON_POWER
99 #define PUZZLE_LEFT BUTTON_LEFT
100 #define PUZZLE_RIGHT BUTTON_RIGHT
101 #define PUZZLE_UP BUTTON_UP
102 #define PUZZLE_DOWN BUTTON_DOWN
103 #define PUZZLE_SHUFFLE BUTTON_REC
104 #define PUZZLE_PICTURE BUTTON_SELECT
106 #elif (CONFIG_KEYPAD == SANSA_FUZE_PAD)
107 #define PUZZLE_QUIT (BUTTON_HOME|BUTTON_REPEAT)
108 #define PUZZLE_LEFT BUTTON_LEFT
109 #define PUZZLE_RIGHT BUTTON_RIGHT
110 #define PUZZLE_UP BUTTON_UP
111 #define PUZZLE_DOWN BUTTON_DOWN
112 #define PUZZLE_SHUFFLE BUTTON_SELECT|BUTTON_DOWN
113 #define PUZZLE_PICTURE BUTTON_SELECT
115 #elif (CONFIG_KEYPAD == SANSA_CLIP_PAD)
116 #define PUZZLE_QUIT BUTTON_POWER
117 #define PUZZLE_LEFT BUTTON_LEFT
118 #define PUZZLE_RIGHT BUTTON_RIGHT
119 #define PUZZLE_UP BUTTON_UP
120 #define PUZZLE_DOWN BUTTON_DOWN
121 #define PUZZLE_SHUFFLE BUTTON_HOME
122 #define PUZZLE_PICTURE BUTTON_SELECT
124 #elif (CONFIG_KEYPAD == SANSA_M200_PAD)
125 #define PUZZLE_QUIT BUTTON_POWER
126 #define PUZZLE_LEFT BUTTON_LEFT
127 #define PUZZLE_RIGHT BUTTON_RIGHT
128 #define PUZZLE_UP BUTTON_UP
129 #define PUZZLE_DOWN BUTTON_DOWN
130 #define PUZZLE_SHUFFLE (BUTTON_SELECT | BUTTON_UP)
131 #define PUZZLE_PICTURE (BUTTON_SELECT | BUTTON_REL)
133 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
134 #define PUZZLE_QUIT BUTTON_POWER
135 #define PUZZLE_LEFT BUTTON_LEFT
136 #define PUZZLE_RIGHT BUTTON_RIGHT
137 #define PUZZLE_UP BUTTON_SCROLL_UP
138 #define PUZZLE_DOWN BUTTON_SCROLL_DOWN
139 #define PUZZLE_SHUFFLE BUTTON_REW
140 #define PUZZLE_PICTURE BUTTON_PLAY
142 #elif (CONFIG_KEYPAD == GIGABEAT_S_PAD)
143 #define PUZZLE_QUIT BUTTON_BACK
144 #define PUZZLE_LEFT BUTTON_LEFT
145 #define PUZZLE_RIGHT BUTTON_RIGHT
146 #define PUZZLE_UP BUTTON_UP
147 #define PUZZLE_DOWN BUTTON_DOWN
148 #define PUZZLE_SHUFFLE BUTTON_SELECT
149 #define PUZZLE_PICTURE BUTTON_MENU
151 #elif (CONFIG_KEYPAD == MROBE100_PAD)
152 #define PUZZLE_QUIT BUTTON_POWER
153 #define PUZZLE_LEFT BUTTON_LEFT
154 #define PUZZLE_RIGHT BUTTON_RIGHT
155 #define PUZZLE_UP BUTTON_UP
156 #define PUZZLE_DOWN BUTTON_DOWN
157 #define PUZZLE_SHUFFLE BUTTON_SELECT
158 #define PUZZLE_PICTURE BUTTON_DISPLAY
160 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
161 #define PUZZLE_QUIT BUTTON_RC_REC
162 #define PUZZLE_LEFT BUTTON_RC_REW
163 #define PUZZLE_RIGHT BUTTON_RC_FF
164 #define PUZZLE_UP BUTTON_RC_VOL_UP
165 #define PUZZLE_DOWN BUTTON_RC_VOL_DOWN
166 #define PUZZLE_SHUFFLE BUTTON_RC_MODE
167 #define PUZZLE_PICTURE BUTTON_RC_MENU
169 #elif (CONFIG_KEYPAD == COWOND2_PAD)
170 #define PUZZLE_QUIT BUTTON_POWER
171 #define PUZZLE_QUIT_TEXT "[POWER]"
173 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
174 #define PUZZLE_QUIT BUTTON_BACK
175 #define PUZZLE_LEFT BUTTON_LEFT
176 #define PUZZLE_RIGHT BUTTON_RIGHT
177 #define PUZZLE_UP BUTTON_UP
178 #define PUZZLE_DOWN BUTTON_DOWN
179 #define PUZZLE_SHUFFLE BUTTON_PLAY
180 #define PUZZLE_PICTURE BUTTON_MENU
182 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
183 #define PUZZLE_QUIT BUTTON_POWER
184 #define PUZZLE_LEFT BUTTON_LEFT
185 #define PUZZLE_RIGHT BUTTON_RIGHT
186 #define PUZZLE_UP BUTTON_UP
187 #define PUZZLE_DOWN BUTTON_DOWN
188 #define PUZZLE_SHUFFLE BUTTON_VIEW
189 #define PUZZLE_PICTURE BUTTON_MENU
191 #elif (CONFIG_KEYPAD == ONDAVX747_PAD) || CONFIG_KEYPAD == MROBE500_PAD
192 #define PUZZLE_QUIT BUTTON_POWER
193 #define PUZZLE_QUIT_TEXT "[POWER]"
196 #error No keymap defined!
199 #ifdef HAVE_TOUCHSCREEN
201 #define PUZZLE_QUIT BUTTON_TOPLEFT
204 #define PUZZLE_LEFT BUTTON_MIDLEFT
207 #define PUZZLE_RIGHT BUTTON_MIDRIGHT
210 #define PUZZLE_UP BUTTON_TOPMIDDLE
213 #define PUZZLE_DOWN BUTTON_BOTTOMMIDDLE
215 #ifndef PUZZLE_SHUFFLE
216 #define PUZZLE_SHUFFLE BUTTON_BOTTOMLEFT
218 #ifndef PUZZLE_PICTURE
219 #define PUZZLE_PICTURE BUTTON_CENTER
221 #ifndef PUZZLE_QUIT_TEXT
222 #define PUZZLE_QUIT_TEXT "[TOPLEFT]"
224 #ifndef PUZZLE_SHUFFLE_TEXT
225 #define PUZZLE_SHUFFLE_TEXT "[BOTTOMLEFT]"
227 #ifndef PUZZLE_PICTURE_TEXT
228 #define PUZZLE_PICTURE_TEXT "[CENTER]"
233 #include "lib/read_image.h"
234 #define READ_IMAGE read_image_file
236 #define READ_IMAGE rb->read_bmp_file
239 #include "pluginbitmaps/sliding_puzzle.h"
240 #define IMAGE_WIDTH BMPWIDTH_sliding_puzzle
241 #define IMAGE_HEIGHT BMPHEIGHT_sliding_puzzle
242 #define IMAGE_SIZE IMAGE_WIDTH
244 /* use a square image, (the default Archos bitmap looks square on its display)
245 Puzzle image dimension is min(lcd_height,lcd_width)
246 4x4 is more convenient for square puzzles
247 Note: sliding_puzzle.bmp should be evenly divisible by SPOTS_X
248 and SPOTS_Y, otherwise lcd_bitmap_part stride won't be correct */
251 #define SPOTS_WIDTH (IMAGE_WIDTH / SPOTS_X)
252 #define SPOTS_HEIGHT (IMAGE_HEIGHT / SPOTS_Y)
253 #define NUM_SPOTS (SPOTS_X*SPOTS_Y)
254 #define HOLE_ID (NUM_SPOTS)
255 #define INITIAL_HOLE (HOLE_ID-1)
259 PICMODE_NUMERALS
= 0,
260 PICMODE_INITIAL_PICTURE
,
261 PICMODE_DEFAULT_PICTURE
,
266 PICMODE_LAST_XXX
/* placeholder */
269 static const char* const picmode_descriptions
[] = {
276 "Shouldn't Get Here",
279 static int spots
[NUM_SPOTS
];
280 static int hole
= INITIAL_HOLE
, moves
;
281 static unsigned char s
[32];
282 static enum picmodes picmode
= PICMODE_INITIAL_PICTURE
;
283 static int num_font
= FONT_UI
;
284 static int moves_font
= FONT_UI
;
285 static int moves_y
= 0;
287 static unsigned char *img_buf
;
288 static size_t img_buf_len
;
290 static char albumart_path
[MAX_PATH
+1];
292 static char img_buf_path
[MAX_PATH
+1];
294 static const fb_data
* puzzle_bmp_ptr
;
295 /* initial_bmp_path points to selected bitmap if this game is launched
296 as a viewer for a .bmp file, or NULL if game is launched regular way */
297 static const char * initial_bmp_path
=NULL
;
300 const char * get_albumart_bmp_path(void)
302 struct mp3entry
* track
= rb
->audio_current_track();
304 if (!track
|| !track
->path
|| track
->path
[0] == '\0')
307 if (!rb
->search_albumart_files(track
, "", albumart_path
, MAX_PATH
) )
310 albumart_path
[ MAX_PATH
] = '\0';
311 return albumart_path
;
315 const char * get_random_bmp_path(void)
317 return(initial_bmp_path
);
320 static bool load_resize_bitmap(void)
323 const char * filename
= NULL
;
325 /* initially assume using the built-in default */
326 puzzle_bmp_ptr
= sliding_puzzle
;
329 /* some modes don't even need to touch disk and trivially succeed */
330 case PICMODE_NUMERALS
:
331 case PICMODE_DEFAULT_PICTURE
:
336 case PICMODE_ALBUM_ART
:
337 filename
= get_albumart_bmp_path();
342 if(NULL == (filename=get_random_bmp_path()) )
343 filename = initial_bmp_path;
346 case PICMODE_INITIAL_PICTURE
:
347 filename
= initial_bmp_path
;
351 if( filename
!= NULL
)
353 /* if we already loaded image before, don't touch disk */
354 if( 0 == rb
->strcmp( filename
, img_buf_path
) )
356 puzzle_bmp_ptr
= (const fb_data
*)img_buf
;
360 struct bitmap main_bitmap
;
361 rb
->memset(&main_bitmap
,0,sizeof(struct bitmap
));
362 main_bitmap
.data
= img_buf
;
364 main_bitmap
.width
= IMAGE_WIDTH
;
365 main_bitmap
.height
= IMAGE_HEIGHT
;
367 rc
= READ_IMAGE( filename
, &main_bitmap
,
369 FORMAT_NATIVE
|FORMAT_RESIZE
|FORMAT_DITHER
,
373 puzzle_bmp_ptr
= (const fb_data
*)img_buf
;
374 rb
->strcpy( img_buf_path
, filename
);
379 /* something must have failed. get_albumart_bmp_path could return
380 NULL if albumart doesn't exist or couldn't be loaded, or
381 read_bmp_file could have failed. return false and caller should
382 try the next mode (PICMODE_DEFAULT_PICTURE and PICMODE_NUMERALS will
387 /* draws a spot at the coordinates (x,y), range of p is 1-20 */
388 static void draw_spot(int p
, int x
, int y
)
395 /* the bottom-right cell of the default sliding_puzzle image is
396 an appropriate hole graphic */
397 rb
->lcd_bitmap_part(sliding_puzzle
, ((p
-1)%SPOTS_X
)*SPOTS_WIDTH
,
398 ((p
-1)/SPOTS_X
)*SPOTS_HEIGHT
,
399 IMAGE_WIDTH
, x
, y
, SPOTS_WIDTH
, SPOTS_HEIGHT
);
401 /* just draw a black rectangle */
402 int old_fg
= rb
->lcd_get_foreground();
403 rb
->lcd_set_foreground(LCD_BLACK
);
404 rb
->lcd_fillrect(x
,y
,SPOTS_WIDTH
,SPOTS_HEIGHT
);
405 rb
->lcd_set_foreground(old_fg
);
408 else if (picmode
!= PICMODE_NUMERALS
)
410 rb
->lcd_bitmap_part( puzzle_bmp_ptr
, ((p
-1)%SPOTS_X
)*SPOTS_WIDTH
,
411 ((p
-1)/SPOTS_X
)*SPOTS_HEIGHT
,
412 IMAGE_WIDTH
, x
, y
, SPOTS_WIDTH
, SPOTS_HEIGHT
);
414 rb
->lcd_drawrect(x
, y
, SPOTS_WIDTH
, SPOTS_HEIGHT
);
415 rb
->lcd_set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
416 rb
->lcd_fillrect(x
+1, y
+1, SPOTS_WIDTH
-2, SPOTS_HEIGHT
-2);
417 rb
->lcd_set_drawmode(DRMODE_SOLID
);
418 rb
->snprintf(s
, sizeof(s
), "%d", p
);
419 rb
->lcd_setfont(num_font
);
420 rb
->lcd_getstringsize(s
, &w
, &h
);
421 rb
->lcd_putsxy(x
+ (SPOTS_WIDTH
/2) - w
/ 2,
422 y
+ (SPOTS_HEIGHT
/2) - h
/ 2, s
);
426 /* check if the puzzle is solved */
427 static bool puzzle_finished(void)
430 for (i
=0; i
<NUM_SPOTS
; i
++)
431 if (spots
[i
] != (i
+1))
436 /* move a piece in any direction */
437 static void move_spot(int x
, int y
)
440 spots
[hole
] = spots
[hole
-x
-SPOTS_X
*y
];
441 hole
-= (x
+SPOTS_X
*y
);
443 rb
->lcd_setfont(moves_font
);
444 #if LCD_WIDTH > LCD_HEIGHT
445 rb
->snprintf(s
, sizeof(s
), "%d", moves
);
446 w
= rb
->lcd_getstringsize(s
, NULL
, NULL
);
447 rb
->lcd_putsxy((IMAGE_WIDTH
+1+(LCD_WIDTH
-IMAGE_WIDTH
-1)/2) - w
/ 2,
451 rb
->snprintf(s
, sizeof(s
), "Moves: %d", moves
);
452 rb
->lcd_putsxy(3, moves_y
, s
);
457 (hole
%SPOTS_X
)*SPOTS_WIDTH
,
458 (hole
/SPOTS_X
)*SPOTS_HEIGHT
);
459 draw_spot(spots
[hole
],
460 (hole
%SPOTS_X
)*SPOTS_WIDTH
+ (i
*x
*SPOTS_WIDTH
)/5,
461 (hole
/SPOTS_X
)*SPOTS_HEIGHT
+ (i
*y
*SPOTS_HEIGHT
)/5);
466 (hole
%SPOTS_X
)*SPOTS_WIDTH
,
467 (hole
/SPOTS_X
)*SPOTS_HEIGHT
);
468 draw_spot(spots
[hole
],
469 ((hole
%SPOTS_X
)+x
)*SPOTS_WIDTH
,
470 ((hole
/SPOTS_X
)+y
)*SPOTS_HEIGHT
);
473 spots
[hole
] = HOLE_ID
;
476 static void draw_playfield(void)
480 rb
->lcd_clear_display();
481 rb
->lcd_setfont(moves_font
);
482 #if LCD_WIDTH > LCD_HEIGHT
483 rb
->lcd_vline(IMAGE_WIDTH
, 0, LCD_HEIGHT
-1);
484 w
= rb
->lcd_getstringsize("Moves", NULL
, NULL
);
485 rb
->lcd_putsxy((IMAGE_WIDTH
+1+(LCD_WIDTH
-IMAGE_WIDTH
-1)/2) - w
/ 2,
487 rb
->snprintf(s
, sizeof(s
), "%d", moves
);
488 w
= rb
->lcd_getstringsize(s
, NULL
, NULL
);
489 rb
->lcd_putsxy((IMAGE_WIDTH
+1+(LCD_WIDTH
-IMAGE_WIDTH
-1)/2) - w
/ 2,
493 rb
->lcd_hline(0, LCD_WIDTH
-1, IMAGE_HEIGHT
);
494 rb
->snprintf(s
, sizeof(s
), "Moves: %d", moves
);
495 rb
->lcd_putsxy(3, moves_y
, s
);
498 /* draw spots to the lcd */
499 for (i
=0; i
<NUM_SPOTS
; i
++)
500 draw_spot(spots
[i
], (i
%SPOTS_X
)*SPOTS_WIDTH
, (i
/SPOTS_X
)*SPOTS_HEIGHT
);
505 /* initializes the puzzle */
506 static void puzzle_init(void)
508 int i
, r
, temp
, tsp
[NUM_SPOTS
];
513 for (i
=NUM_SPOTS
-1; i
>=0; i
--) {
514 r
= (rb
->rand() % (i
+1));
520 if (spots
[i
]==HOLE_ID
)
524 /* test if the puzzle is solvable */
525 for (i
=0; i
<NUM_SPOTS
; i
++)
529 /* First, check if the problem has even or odd parity,
530 depending on where the empty square is */
531 if ((((SPOTS_X
-1)-hole
%SPOTS_X
) + ((SPOTS_Y
-1)-hole
/SPOTS_X
))%2 == 1)
534 /* Now check how many swaps we need to solve it */
535 for (i
=0; i
<NUM_SPOTS
-1; i
++) {
536 while (tsp
[i
] != (i
+1)) {
538 tsp
[i
] = tsp
[temp
-1];
544 /* if the random puzzle isn't solvable just change two spots */
546 if (spots
[0]!=HOLE_ID
&& spots
[1]!=HOLE_ID
) {
560 /* the main game loop */
561 static int puzzle_loop(void)
564 int lastbutton
= BUTTON_NONE
;
569 button
= rb
->button_get(true);
571 #ifdef PUZZLE_RC_QUIT
575 /* get out of here */
579 #ifdef PUZZLE_SHUFFLE_PICTURE_PRE
580 if (lastbutton
!= PUZZLE_SHUFFLE_PICTURE_PRE
)
583 /* mix up the pieces */
588 #ifdef PUZZLE_SHUFFLE_PICTURE_PRE
589 if (lastbutton
!= PUZZLE_SHUFFLE_PICTURE_PRE
)
593 picmode
= (picmode
+1)%PICMODE_LAST_XXX
;
595 /* if load_resize_bitmap fails to load bitmap, try next picmode
599 load_success
= load_resize_bitmap();
601 picmode
= (picmode
+1)%PICMODE_LAST_XXX
;
603 while( !load_success
);
605 /* tell the user what mode we picked in the end! */
606 rb
->splash(HZ
,picmode_descriptions
[ picmode
] );
611 if ((hole
%SPOTS_X
)<(SPOTS_X
-1) && !puzzle_finished())
616 if ((hole
%SPOTS_X
)>0 && !puzzle_finished())
621 if ((hole
/SPOTS_X
)<(SPOTS_Y
-1) && !puzzle_finished())
626 if ((hole
/SPOTS_X
)>0 && !puzzle_finished())
631 if (rb
->default_event_handler(button
) == SYS_USB_CONNECTED
)
632 return PLUGIN_USB_CONNECTED
;
635 if (button
!= BUTTON_NONE
)
640 enum plugin_status
plugin_start(
641 const void* parameter
)
645 initial_bmp_path
=(const char *)parameter
;
646 img_buf
= rb
->plugin_get_buffer(&img_buf_len
);
647 picmode
= PICMODE_INITIAL_PICTURE
;
648 img_buf_path
[0] = '\0';
650 /* If launched as a viewer, just go straight to the game without
651 bothering with the splash or instructions page */
654 /* if not launched as a viewer, use default puzzle, and show help */
655 picmode
= PICMODE_DEFAULT_PICTURE
;
658 rb
->lcd_getstringsize((unsigned char *)"Sliding Puzzle", &w
, &h
);
661 rb
->lcd_clear_display();
662 rb
->lcd_putsxy(LCD_WIDTH
/2-w
, (LCD_HEIGHT
/2)-h
,
663 (unsigned char *)"Sliding Puzzle");
667 /* print instructions */
668 rb
->lcd_clear_display();
669 rb
->lcd_setfont(FONT_SYSFIXED
);
670 #if CONFIG_KEYPAD == RECORDER_PAD || CONFIG_KEYPAD == ARCHOS_AV300_PAD
671 rb
->lcd_putsxy(3, 18, "[OFF] to stop");
672 rb
->lcd_putsxy(3, 28, "[F1] shuffle");
673 rb
->lcd_putsxy(3, 38, "[F2] change pic");
674 #elif CONFIG_KEYPAD == ONDIO_PAD
675 rb
->lcd_putsxy(0, 18, "[OFF] to stop");
676 rb
->lcd_putsxy(0, 28, "[MODE..] shuffle");
677 rb
->lcd_putsxy(0, 38, "[MODE] change pic");
678 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
679 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
680 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
681 rb
->lcd_putsxy(0, 18, "[S-MENU] to stop");
682 rb
->lcd_putsxy(0, 28, "[S-LEFT] shuffle");
683 rb
->lcd_putsxy(0, 38, "[S-RIGHT] change pic");
684 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
685 (CONFIG_KEYPAD == IRIVER_H300_PAD)
686 rb
->lcd_putsxy(0, 18, "[STOP] to stop");
687 rb
->lcd_putsxy(0, 28, "[SELECT] shuffle");
688 rb
->lcd_putsxy(0, 38, "[PLAY] change pic");
689 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
690 rb
->lcd_putsxy(0, 18, "[OFF] to stop");
691 rb
->lcd_putsxy(0, 28, "[REC] shuffle");
692 rb
->lcd_putsxy(0, 38, "[PLAY] change pic");
693 #elif CONFIG_KEYPAD == GIGABEAT_PAD
694 rb
->lcd_putsxy(0, 18, "[POWER] to stop");
695 rb
->lcd_putsxy(0, 28, "[SELECT] shuffle");
696 rb
->lcd_putsxy(0, 38, "[A] change pic");
697 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
698 (CONFIG_KEYPAD == SANSA_C200_PAD)
699 rb
->lcd_putsxy(0, 18, "[OFF] to stop");
700 rb
->lcd_putsxy(0, 28, "[REC] shuffle");
701 rb
->lcd_putsxy(0, 38, "[SELECT] change pic");
702 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
703 rb
->lcd_putsxy(0, 18, "[OFF] to stop");
704 rb
->lcd_putsxy(0, 28, "[REW] shuffle");
705 rb
->lcd_putsxy(0, 38, "[PLAY] change pic");
706 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
707 rb
->lcd_putsxy(0, 18, "[BACK] to stop");
708 rb
->lcd_putsxy(0, 28, "[SELECT] shuffle");
709 rb
->lcd_putsxy(0, 38, "[MENU] change pic");
710 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
711 rb
->lcd_putsxy(0, 18, "[REC] to stop");
712 rb
->lcd_putsxy(0, 28, "[MODE] shuffle");
713 rb
->lcd_putsxy(0, 38, "[MENU] change pic");
715 #ifdef HAVE_TOUCHSCREEN
716 rb
->lcd_putsxy(0, 18, PUZZLE_QUIT_TEXT
" to stop");
717 rb
->lcd_putsxy(0, 28, PUZZLE_SHUFFLE_TEXT
" shuffle");
718 rb
->lcd_putsxy(0, 38, PUZZLE_PICTURE_TEXT
" change pic");
721 rb
->lcd_putsxy(0,48," pic->albumart->num");
723 rb
->lcd_putsxy(0,48," pic<->num");
726 rb
->button_get_w_tmo(HZ
*2);
731 if( !load_resize_bitmap() )
733 rb
->lcd_clear_display();
734 rb
->splash(HZ
*2,"Failed to load bitmap!");
738 /* Calculate possible font sizes and text positions */
739 rb
->lcd_setfont(FONT_UI
);
740 rb
->lcd_getstringsize("15", &w
, &h
);
741 if ((w
> (SPOTS_WIDTH
-2)) || (h
> (SPOTS_HEIGHT
-2)))
742 num_font
= FONT_SYSFIXED
;
744 #if LCD_WIDTH > LCD_HEIGHT
745 rb
->lcd_getstringsize("Moves", &w
, &h
);
746 if (w
> (LCD_WIDTH
-IMAGE_WIDTH
-1))
747 moves_font
= FONT_SYSFIXED
;
748 rb
->lcd_setfont(moves_font
);
749 rb
->lcd_getstringsize("Moves", &w
, &h
);
752 rb
->lcd_getstringsize("Moves: 999", &w
, &h
);
753 if ((w
> LCD_WIDTH
) || (h
> (LCD_HEIGHT
-IMAGE_HEIGHT
-1)))
754 moves_font
= FONT_SYSFIXED
;
755 rb
->lcd_setfont(moves_font
);
756 rb
->lcd_getstringsize("Moves: 999", &w
, &h
);
757 moves_y
= (IMAGE_HEIGHT
+1+(LCD_HEIGHT
-IMAGE_HEIGHT
-1)/2) - h
/ 2;
759 for (i
=0; i
<NUM_SPOTS
; i
++)
762 #ifdef HAVE_LCD_COLOR
763 rb
->lcd_set_background(LCD_BLACK
);
764 rb
->lcd_set_foreground(LCD_WHITE
);
765 rb
->lcd_set_backdrop(NULL
);
767 rb
->lcd_set_background(LCD_WHITE
);
768 rb
->lcd_set_foreground(LCD_BLACK
);
769 rb
->lcd_set_backdrop(NULL
);
775 return puzzle_loop();