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 == COWON_D2_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 == PHILIPS_SA9200_PAD
192 #define PUZZLE_QUIT BUTTON_POWER
193 #define PUZZLE_LEFT BUTTON_PREV
194 #define PUZZLE_RIGHT BUTTON_NEXT
195 #define PUZZLE_UP BUTTON_UP
196 #define PUZZLE_DOWN BUTTON_DOWN
197 #define PUZZLE_SHUFFLE BUTTON_RIGHT
198 #define PUZZLE_PICTURE BUTTON_MENU
200 #elif CONFIG_KEYPAD == ONDAVX747_PAD || \
201 CONFIG_KEYPAD == ONDAVX777_PAD || \
202 CONFIG_KEYPAD == MROBE500_PAD
203 #define PUZZLE_QUIT BUTTON_POWER
204 #define PUZZLE_QUIT_TEXT "[POWER]"
206 #elif (CONFIG_KEYPAD == SAMSUNG_YH_PAD)
207 #define PUZZLE_QUIT BUTTON_REC
208 #define PUZZLE_LEFT BUTTON_LEFT
209 #define PUZZLE_RIGHT BUTTON_RIGHT
210 #define PUZZLE_UP BUTTON_UP
211 #define PUZZLE_DOWN BUTTON_DOWN
212 #define PUZZLE_SHUFFLE BUTTON_REW
213 #define PUZZLE_PICTURE BUTTON_PLAY
215 #elif (CONFIG_KEYPAD == PBELL_VIBE500_PAD)
216 #define PUZZLE_QUIT BUTTON_REC
217 #define PUZZLE_LEFT BUTTON_PREV
218 #define PUZZLE_RIGHT BUTTON_NEXT
219 #define PUZZLE_UP BUTTON_UP
220 #define PUZZLE_DOWN BUTTON_DOWN
221 #define PUZZLE_SHUFFLE BUTTON_CANCEL
222 #define PUZZLE_PICTURE BUTTON_MENU
225 #error No keymap defined!
228 #ifdef HAVE_TOUCHSCREEN
230 #define PUZZLE_QUIT BUTTON_TOPLEFT
233 #define PUZZLE_LEFT BUTTON_MIDLEFT
236 #define PUZZLE_RIGHT BUTTON_MIDRIGHT
239 #define PUZZLE_UP BUTTON_TOPMIDDLE
242 #define PUZZLE_DOWN BUTTON_BOTTOMMIDDLE
244 #ifndef PUZZLE_SHUFFLE
245 #define PUZZLE_SHUFFLE BUTTON_BOTTOMLEFT
247 #ifndef PUZZLE_PICTURE
248 #define PUZZLE_PICTURE BUTTON_CENTER
250 #ifndef PUZZLE_QUIT_TEXT
251 #define PUZZLE_QUIT_TEXT "[TOPLEFT]"
253 #ifndef PUZZLE_SHUFFLE_TEXT
254 #define PUZZLE_SHUFFLE_TEXT "[BOTTOMLEFT]"
256 #ifndef PUZZLE_PICTURE_TEXT
257 #define PUZZLE_PICTURE_TEXT "[CENTER]"
262 #include "lib/read_image.h"
263 #define READ_IMAGE read_image_file
265 #define READ_IMAGE rb->read_bmp_file
268 #include "pluginbitmaps/sliding_puzzle.h"
269 #define IMAGE_WIDTH BMPWIDTH_sliding_puzzle
270 #define IMAGE_HEIGHT BMPHEIGHT_sliding_puzzle
271 #define IMAGE_SIZE IMAGE_WIDTH
273 /* use a square image, (the default Archos bitmap looks square on its display)
274 Puzzle image dimension is min(lcd_height,lcd_width)
275 4x4 is more convenient for square puzzles
276 Note: sliding_puzzle.bmp should be evenly divisible by SPOTS_X
277 and SPOTS_Y, otherwise lcd_bitmap_part stride won't be correct */
280 #define SPOTS_WIDTH (IMAGE_WIDTH / SPOTS_X)
281 #define SPOTS_HEIGHT (IMAGE_HEIGHT / SPOTS_Y)
282 #define NUM_SPOTS (SPOTS_X*SPOTS_Y)
283 #define HOLE_ID (NUM_SPOTS)
284 #define INITIAL_HOLE (HOLE_ID-1)
288 PICMODE_NUMERALS
= 0,
289 PICMODE_INITIAL_PICTURE
,
290 PICMODE_DEFAULT_PICTURE
,
295 PICMODE_LAST_XXX
/* placeholder */
298 static const char* const picmode_descriptions
[] = {
305 "Shouldn't Get Here",
308 static int spots
[NUM_SPOTS
];
309 static int hole
= INITIAL_HOLE
, moves
;
310 static unsigned char s
[32];
311 static enum picmodes picmode
= PICMODE_INITIAL_PICTURE
;
312 static int num_font
= FONT_UI
;
313 static int moves_font
= FONT_UI
;
314 static int moves_y
= 0;
316 static unsigned char *img_buf
;
317 static size_t img_buf_len
;
319 static char albumart_path
[MAX_PATH
+1];
321 static char img_buf_path
[MAX_PATH
+1];
323 static const fb_data
* puzzle_bmp_ptr
;
324 /* initial_bmp_path points to selected bitmap if this game is launched
325 as a viewer for a .bmp file, or NULL if game is launched regular way */
326 static const char * initial_bmp_path
=NULL
;
329 const char * get_albumart_bmp_path(void)
331 struct mp3entry
* track
= rb
->audio_current_track();
333 if (!track
|| !track
->path
|| track
->path
[0] == '\0')
336 if (!rb
->search_albumart_files(track
, "", albumart_path
, MAX_PATH
) )
339 albumart_path
[ MAX_PATH
] = '\0';
340 return albumart_path
;
344 const char * get_random_bmp_path(void)
346 return(initial_bmp_path
);
349 static bool load_resize_bitmap(void)
352 const char * filename
= NULL
;
354 /* initially assume using the built-in default */
355 puzzle_bmp_ptr
= sliding_puzzle
;
358 /* some modes don't even need to touch disk and trivially succeed */
359 case PICMODE_NUMERALS
:
360 case PICMODE_DEFAULT_PICTURE
:
365 case PICMODE_ALBUM_ART
:
366 filename
= get_albumart_bmp_path();
371 if(NULL == (filename=get_random_bmp_path()) )
372 filename = initial_bmp_path;
375 case PICMODE_INITIAL_PICTURE
:
376 filename
= initial_bmp_path
;
380 if( filename
!= NULL
)
382 /* if we already loaded image before, don't touch disk */
383 if( 0 == rb
->strcmp( filename
, img_buf_path
) )
385 puzzle_bmp_ptr
= (const fb_data
*)img_buf
;
389 struct bitmap main_bitmap
;
390 rb
->memset(&main_bitmap
,0,sizeof(struct bitmap
));
391 main_bitmap
.data
= img_buf
;
393 main_bitmap
.width
= IMAGE_WIDTH
;
394 main_bitmap
.height
= IMAGE_HEIGHT
;
396 rc
= READ_IMAGE( filename
, &main_bitmap
,
398 FORMAT_NATIVE
|FORMAT_RESIZE
|FORMAT_DITHER
,
402 puzzle_bmp_ptr
= (const fb_data
*)img_buf
;
403 rb
->strcpy( img_buf_path
, filename
);
408 /* something must have failed. get_albumart_bmp_path could return
409 NULL if albumart doesn't exist or couldn't be loaded, or
410 read_bmp_file could have failed. return false and caller should
411 try the next mode (PICMODE_DEFAULT_PICTURE and PICMODE_NUMERALS will
416 /* draws a spot at the coordinates (x,y), range of p is 1-20 */
417 static void draw_spot(int p
, int x
, int y
)
424 /* the bottom-right cell of the default sliding_puzzle image is
425 an appropriate hole graphic */
426 rb
->lcd_bitmap_part(sliding_puzzle
, ((p
-1)%SPOTS_X
)*SPOTS_WIDTH
,
427 ((p
-1)/SPOTS_X
)*SPOTS_HEIGHT
,
429 BMPWIDTH_sliding_puzzle
, BMPHEIGHT_sliding_puzzle
),
430 x
, y
, SPOTS_WIDTH
, SPOTS_HEIGHT
);
432 /* just draw a black rectangle */
433 int old_fg
= rb
->lcd_get_foreground();
434 rb
->lcd_set_foreground(LCD_BLACK
);
435 rb
->lcd_fillrect(x
,y
,SPOTS_WIDTH
,SPOTS_HEIGHT
);
436 rb
->lcd_set_foreground(LCD_WHITE
);
437 rb
->lcd_drawrect(x
,y
,SPOTS_WIDTH
,SPOTS_HEIGHT
);
438 rb
->lcd_set_foreground(old_fg
);
441 else if (picmode
!= PICMODE_NUMERALS
)
443 rb
->lcd_bitmap_part( puzzle_bmp_ptr
, ((p
-1)%SPOTS_X
)*SPOTS_WIDTH
,
444 ((p
-1)/SPOTS_X
)*SPOTS_HEIGHT
,
446 BMPWIDTH_sliding_puzzle
, BMPHEIGHT_sliding_puzzle
),
447 x
, y
, SPOTS_WIDTH
, SPOTS_HEIGHT
);
449 rb
->lcd_drawrect(x
, y
, SPOTS_WIDTH
, SPOTS_HEIGHT
);
450 rb
->lcd_set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
451 rb
->lcd_fillrect(x
+1, y
+1, SPOTS_WIDTH
-2, SPOTS_HEIGHT
-2);
452 rb
->lcd_set_drawmode(DRMODE_SOLID
);
453 rb
->snprintf(s
, sizeof(s
), "%d", p
);
454 rb
->lcd_setfont(num_font
);
455 rb
->lcd_getstringsize(s
, &w
, &h
);
456 rb
->lcd_putsxy(x
+ (SPOTS_WIDTH
/2) - w
/ 2,
457 y
+ (SPOTS_HEIGHT
/2) - h
/ 2, s
);
461 /* check if the puzzle is solved */
462 static bool puzzle_finished(void)
465 for (i
=0; i
<NUM_SPOTS
; i
++)
466 if (spots
[i
] != (i
+1))
471 /* move a piece in any direction */
472 static void move_spot(int x
, int y
)
475 spots
[hole
] = spots
[hole
-x
-SPOTS_X
*y
];
476 hole
-= (x
+SPOTS_X
*y
);
478 rb
->lcd_setfont(moves_font
);
479 #if LCD_WIDTH > LCD_HEIGHT
480 rb
->snprintf(s
, sizeof(s
), "%d", moves
);
481 w
= rb
->lcd_getstringsize(s
, NULL
, NULL
);
482 rb
->lcd_putsxy((IMAGE_WIDTH
+1+(LCD_WIDTH
-IMAGE_WIDTH
-1)/2) - w
/ 2,
486 rb
->snprintf(s
, sizeof(s
), "Moves: %d", moves
);
487 rb
->lcd_putsxy(3, moves_y
, s
);
492 (hole
%SPOTS_X
)*SPOTS_WIDTH
,
493 (hole
/SPOTS_X
)*SPOTS_HEIGHT
);
494 draw_spot(spots
[hole
],
495 (hole
%SPOTS_X
)*SPOTS_WIDTH
+ (i
*x
*SPOTS_WIDTH
)/5,
496 (hole
/SPOTS_X
)*SPOTS_HEIGHT
+ (i
*y
*SPOTS_HEIGHT
)/5);
501 (hole
%SPOTS_X
)*SPOTS_WIDTH
,
502 (hole
/SPOTS_X
)*SPOTS_HEIGHT
);
503 draw_spot(spots
[hole
],
504 ((hole
%SPOTS_X
)+x
)*SPOTS_WIDTH
,
505 ((hole
/SPOTS_X
)+y
)*SPOTS_HEIGHT
);
508 spots
[hole
] = HOLE_ID
;
511 static void draw_playfield(void)
515 rb
->lcd_clear_display();
516 rb
->lcd_setfont(moves_font
);
517 #if LCD_WIDTH > LCD_HEIGHT
518 rb
->lcd_vline(IMAGE_WIDTH
, 0, LCD_HEIGHT
-1);
519 w
= rb
->lcd_getstringsize("Moves", NULL
, NULL
);
520 rb
->lcd_putsxy((IMAGE_WIDTH
+1+(LCD_WIDTH
-IMAGE_WIDTH
-1)/2) - w
/ 2,
522 rb
->snprintf(s
, sizeof(s
), "%d", moves
);
523 w
= rb
->lcd_getstringsize(s
, NULL
, NULL
);
524 rb
->lcd_putsxy((IMAGE_WIDTH
+1+(LCD_WIDTH
-IMAGE_WIDTH
-1)/2) - w
/ 2,
528 rb
->lcd_hline(0, LCD_WIDTH
-1, IMAGE_HEIGHT
);
529 rb
->snprintf(s
, sizeof(s
), "Moves: %d", moves
);
530 rb
->lcd_putsxy(3, moves_y
, s
);
533 /* draw spots to the lcd */
534 for (i
=0; i
<NUM_SPOTS
; i
++)
535 draw_spot(spots
[i
], (i
%SPOTS_X
)*SPOTS_WIDTH
, (i
/SPOTS_X
)*SPOTS_HEIGHT
);
540 /* initializes the puzzle */
541 static void puzzle_init(void)
543 int i
, r
, temp
, tsp
[NUM_SPOTS
];
548 for (i
=NUM_SPOTS
-1; i
>=0; i
--) {
549 r
= (rb
->rand() % (i
+1));
555 if (spots
[i
]==HOLE_ID
)
559 /* test if the puzzle is solvable */
560 for (i
=0; i
<NUM_SPOTS
; i
++)
564 /* First, check if the problem has even or odd parity,
565 depending on where the empty square is */
566 if ((((SPOTS_X
-1)-hole
%SPOTS_X
) + ((SPOTS_Y
-1)-hole
/SPOTS_X
))%2 == 1)
569 /* Now check how many swaps we need to solve it */
570 for (i
=0; i
<NUM_SPOTS
-1; i
++) {
571 while (tsp
[i
] != (i
+1)) {
573 tsp
[i
] = tsp
[temp
-1];
579 /* if the random puzzle isn't solvable just change two spots */
581 if (spots
[0]!=HOLE_ID
&& spots
[1]!=HOLE_ID
) {
595 /* the main game loop */
596 static int puzzle_loop(void)
599 int lastbutton
= BUTTON_NONE
;
604 button
= rb
->button_get(true);
606 #ifdef PUZZLE_RC_QUIT
610 /* get out of here */
614 #ifdef PUZZLE_SHUFFLE_PICTURE_PRE
615 if (lastbutton
!= PUZZLE_SHUFFLE_PICTURE_PRE
)
618 /* mix up the pieces */
623 #ifdef PUZZLE_SHUFFLE_PICTURE_PRE
624 if (lastbutton
!= PUZZLE_SHUFFLE_PICTURE_PRE
)
628 picmode
= (picmode
+1)%PICMODE_LAST_XXX
;
630 /* if load_resize_bitmap fails to load bitmap, try next picmode
634 load_success
= load_resize_bitmap();
636 picmode
= (picmode
+1)%PICMODE_LAST_XXX
;
638 while( !load_success
);
640 /* tell the user what mode we picked in the end! */
641 rb
->splash(HZ
,picmode_descriptions
[ picmode
] );
646 if ((hole
%SPOTS_X
)<(SPOTS_X
-1) && !puzzle_finished())
651 if ((hole
%SPOTS_X
)>0 && !puzzle_finished())
656 if ((hole
/SPOTS_X
)<(SPOTS_Y
-1) && !puzzle_finished())
661 if ((hole
/SPOTS_X
)>0 && !puzzle_finished())
666 if (rb
->default_event_handler(button
) == SYS_USB_CONNECTED
)
667 return PLUGIN_USB_CONNECTED
;
670 if (button
!= BUTTON_NONE
)
675 enum plugin_status
plugin_start(
676 const void* parameter
)
680 initial_bmp_path
=(const char *)parameter
;
681 img_buf
= rb
->plugin_get_buffer(&img_buf_len
);
682 picmode
= PICMODE_INITIAL_PICTURE
;
683 img_buf_path
[0] = '\0';
685 /* If launched as a viewer, just go straight to the game without
686 bothering with the splash or instructions page */
689 /* if not launched as a viewer, use default puzzle, and show help */
690 picmode
= PICMODE_DEFAULT_PICTURE
;
693 rb
->lcd_getstringsize((unsigned char *)"Sliding Puzzle", &w
, &h
);
696 rb
->lcd_clear_display();
697 rb
->lcd_putsxy(LCD_WIDTH
/2-w
, (LCD_HEIGHT
/2)-h
,
698 (unsigned char *)"Sliding Puzzle");
702 /* print instructions */
703 rb
->lcd_clear_display();
704 rb
->lcd_setfont(FONT_SYSFIXED
);
705 #if CONFIG_KEYPAD == RECORDER_PAD || CONFIG_KEYPAD == ARCHOS_AV300_PAD
706 rb
->lcd_putsxy(3, 18, "[OFF] to stop");
707 rb
->lcd_putsxy(3, 28, "[F1] shuffle");
708 rb
->lcd_putsxy(3, 38, "[F2] change pic");
709 #elif CONFIG_KEYPAD == ONDIO_PAD
710 rb
->lcd_putsxy(0, 18, "[OFF] to stop");
711 rb
->lcd_putsxy(0, 28, "[MODE..] shuffle");
712 rb
->lcd_putsxy(0, 38, "[MODE] change pic");
713 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
714 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
715 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
716 rb
->lcd_putsxy(0, 18, "[S-MENU] to stop");
717 rb
->lcd_putsxy(0, 28, "[S-LEFT] shuffle");
718 rb
->lcd_putsxy(0, 38, "[S-RIGHT] change pic");
719 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
720 (CONFIG_KEYPAD == IRIVER_H300_PAD)
721 rb
->lcd_putsxy(0, 18, "[STOP] to stop");
722 rb
->lcd_putsxy(0, 28, "[SELECT] shuffle");
723 rb
->lcd_putsxy(0, 38, "[PLAY] change pic");
724 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
725 rb
->lcd_putsxy(0, 18, "[OFF] to stop");
726 rb
->lcd_putsxy(0, 28, "[REC] shuffle");
727 rb
->lcd_putsxy(0, 38, "[PLAY] change pic");
728 #elif CONFIG_KEYPAD == GIGABEAT_PAD
729 rb
->lcd_putsxy(0, 18, "[POWER] to stop");
730 rb
->lcd_putsxy(0, 28, "[SELECT] shuffle");
731 rb
->lcd_putsxy(0, 38, "[A] change pic");
732 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
733 (CONFIG_KEYPAD == SANSA_C200_PAD)
734 rb
->lcd_putsxy(0, 18, "[OFF] to stop");
735 rb
->lcd_putsxy(0, 28, "[REC] shuffle");
736 rb
->lcd_putsxy(0, 38, "[SELECT] change pic");
737 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
738 rb
->lcd_putsxy(0, 18, "[OFF] to stop");
739 rb
->lcd_putsxy(0, 28, "[REW] shuffle");
740 rb
->lcd_putsxy(0, 38, "[PLAY] change pic");
741 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
742 rb
->lcd_putsxy(0, 18, "[BACK] to stop");
743 rb
->lcd_putsxy(0, 28, "[SELECT] shuffle");
744 rb
->lcd_putsxy(0, 38, "[MENU] change pic");
745 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
746 rb
->lcd_putsxy(0, 18, "[REC] to stop");
747 rb
->lcd_putsxy(0, 28, "[MODE] shuffle");
748 rb
->lcd_putsxy(0, 38, "[MENU] change pic");
750 #ifdef HAVE_TOUCHSCREEN
751 rb
->lcd_putsxy(0, 18, PUZZLE_QUIT_TEXT
" to stop");
752 rb
->lcd_putsxy(0, 28, PUZZLE_SHUFFLE_TEXT
" shuffle");
753 rb
->lcd_putsxy(0, 38, PUZZLE_PICTURE_TEXT
" change pic");
756 rb
->lcd_putsxy(0,48," pic->albumart->num");
758 rb
->lcd_putsxy(0,48," pic<->num");
761 rb
->button_get_w_tmo(HZ
*2);
766 if( !load_resize_bitmap() )
768 rb
->lcd_clear_display();
769 rb
->splash(HZ
*2,"Failed to load bitmap!");
773 /* Calculate possible font sizes and text positions */
774 rb
->lcd_setfont(FONT_UI
);
775 rb
->lcd_getstringsize("15", &w
, &h
);
776 if ((w
> (SPOTS_WIDTH
-2)) || (h
> (SPOTS_HEIGHT
-2)))
777 num_font
= FONT_SYSFIXED
;
779 #if LCD_WIDTH > LCD_HEIGHT
780 rb
->lcd_getstringsize("Moves", &w
, &h
);
781 if (w
> (LCD_WIDTH
-IMAGE_WIDTH
-1))
782 moves_font
= FONT_SYSFIXED
;
783 rb
->lcd_setfont(moves_font
);
784 rb
->lcd_getstringsize("Moves", &w
, &h
);
787 rb
->lcd_getstringsize("Moves: 999", &w
, &h
);
788 if ((w
> LCD_WIDTH
) || (h
> (LCD_HEIGHT
-IMAGE_HEIGHT
-1)))
789 moves_font
= FONT_SYSFIXED
;
790 rb
->lcd_setfont(moves_font
);
791 rb
->lcd_getstringsize("Moves: 999", &w
, &h
);
792 moves_y
= (IMAGE_HEIGHT
+1+(LCD_HEIGHT
-IMAGE_HEIGHT
-1)/2) - h
/ 2;
794 for (i
=0; i
<NUM_SPOTS
; i
++)
797 #ifdef HAVE_LCD_COLOR
798 rb
->lcd_set_background(LCD_BLACK
);
799 rb
->lcd_set_foreground(LCD_WHITE
);
800 rb
->lcd_set_backdrop(NULL
);
802 rb
->lcd_set_background(LCD_WHITE
);
803 rb
->lcd_set_foreground(LCD_BLACK
);
804 rb
->lcd_set_backdrop(NULL
);
810 return puzzle_loop();