1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2004-2007 Antoine Cellerier <dionoea @t videolan d.t org>
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
21 #include "playback_control.h"
22 #include "configfile.h"
25 #include "oldmenuapi.h"
27 #ifdef HAVE_LCD_BITMAP
31 static const struct plugin_api
* rb
;
32 #define min(a,b) (a<b?a:b)
38 #if CONFIG_KEYPAD == RECORDER_PAD
39 # define SOL_QUIT BUTTON_OFF
40 # define SOL_UP BUTTON_UP
41 # define SOL_DOWN BUTTON_DOWN
42 # define SOL_LEFT BUTTON_LEFT
43 # define SOL_RIGHT BUTTON_RIGHT
44 # define SOL_MOVE BUTTON_ON
45 # define SOL_DRAW BUTTON_F1
46 # define SOL_REM2CUR BUTTON_PLAY
47 # define SOL_CUR2STACK BUTTON_F2
48 # define SOL_REM2STACK BUTTON_F3
51 # define HK_REM2CUR "PLAY"
52 # define HK_CUR2STACK "F2"
53 # define HK_REM2STACK "F3"
55 #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
56 # define SOL_QUIT BUTTON_OFF
57 # define SOL_UP BUTTON_UP
58 # define SOL_DOWN BUTTON_DOWN
59 # define SOL_LEFT BUTTON_LEFT
60 # define SOL_RIGHT BUTTON_RIGHT
61 # define SOL_MOVE BUTTON_ON
62 # define SOL_DRAW BUTTON_F1
63 # define SOL_REM2CUR BUTTON_SELECT
64 # define SOL_CUR2STACK BUTTON_F2
65 # define SOL_REM2STACK BUTTON_F3
68 # define HK_REM2CUR "SELECT"
69 # define HK_CUR2STACK "F2"
70 # define HK_REM2STACK "F3"
72 #elif CONFIG_KEYPAD == ONDIO_PAD
73 # define SOL_QUIT BUTTON_OFF
74 # define SOL_UP_PRE BUTTON_UP
75 # define SOL_UP (BUTTON_UP | BUTTON_REL)
76 # define SOL_DOWN_PRE BUTTON_DOWN
77 # define SOL_DOWN (BUTTON_DOWN | BUTTON_REL)
78 # define SOL_LEFT_PRE BUTTON_LEFT
79 # define SOL_LEFT (BUTTON_LEFT | BUTTON_REL)
80 # define SOL_RIGHT_PRE BUTTON_RIGHT
81 # define SOL_RIGHT (BUTTON_RIGHT | BUTTON_REL)
82 # define SOL_MOVE_PRE BUTTON_MENU
83 # define SOL_MOVE (BUTTON_MENU | BUTTON_REL)
84 # define SOL_DRAW_PRE BUTTON_MENU
85 # define SOL_DRAW (BUTTON_MENU | BUTTON_REPEAT)
86 # define SOL_REM2CUR_PRE BUTTON_DOWN
87 # define SOL_REM2CUR (BUTTON_DOWN | BUTTON_REPEAT)
88 # define SOL_CUR2STACK_PRE BUTTON_UP
89 # define SOL_CUR2STACK (BUTTON_UP | BUTTON_REPEAT)
90 # define SOL_REM2STACK_PRE BUTTON_RIGHT
91 # define SOL_REM2STACK (BUTTON_RIGHT | BUTTON_REPEAT)
92 # define HK_MOVE "MODE"
93 # define HK_DRAW "MODE.."
94 # define HK_REM2CUR "DOWN.."
95 # define HK_CUR2STACK "UP.."
96 # define HK_REM2STACK "RIGHT.."
98 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
99 (CONFIG_KEYPAD == IRIVER_H300_PAD)
100 # define SOL_QUIT BUTTON_OFF
101 # define SOL_UP BUTTON_UP
102 # define SOL_DOWN BUTTON_DOWN
103 # define SOL_LEFT BUTTON_LEFT
104 # define SOL_RIGHT BUTTON_RIGHT
105 # define SOL_MOVE_PRE BUTTON_SELECT
106 # define SOL_MOVE (BUTTON_SELECT | BUTTON_REL)
107 # define SOL_DRAW BUTTON_MODE
108 # define SOL_REM2CUR (BUTTON_LEFT | BUTTON_ON)
109 # define SOL_CUR2STACK_PRE BUTTON_SELECT
110 # define SOL_CUR2STACK (BUTTON_SELECT | BUTTON_REPEAT)
111 # define SOL_REM2STACK (BUTTON_RIGHT | BUTTON_ON)
112 # define SOL_REM BUTTON_REC
113 # define SOL_RC_QUIT BUTTON_RC_STOP
114 # define HK_MOVE "NAVI"
115 # define HK_DRAW "A-B"
116 # define HK_REM2CUR "PLAY+LEFT"
117 # define HK_CUR2STACK "NAVI.."
118 # define HK_REM2STACK "PLAY+RIGHT"
120 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
121 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
122 # define SOL_QUIT (BUTTON_SELECT | BUTTON_MENU)
123 # define SOL_UP BUTTON_SCROLL_BACK
124 # define SOL_DOWN BUTTON_SCROLL_FWD
125 # define SOL_LEFT_PRE BUTTON_LEFT
126 # define SOL_LEFT (BUTTON_LEFT | BUTTON_REL)
127 # define SOL_RIGHT_PRE BUTTON_RIGHT
128 # define SOL_RIGHT (BUTTON_RIGHT | BUTTON_REL)
129 # define SOL_MOVE_PRE BUTTON_SELECT
130 # define SOL_MOVE (BUTTON_SELECT | BUTTON_REL)
131 # define SOL_DRAW_PRE BUTTON_MENU
132 # define SOL_DRAW (BUTTON_MENU | BUTTON_REL)
133 # define SOL_REM2CUR BUTTON_PLAY
134 # define SOL_CUR2STACK_PRE BUTTON_MENU
135 # define SOL_CUR2STACK (BUTTON_MENU | BUTTON_REPEAT)
136 # define SOL_REM2STACK_PRE BUTTON_RIGHT
137 # define SOL_REM2STACK (BUTTON_RIGHT | BUTTON_REPEAT)
138 # define HK_UD "SCROLL U/D"
139 # define HK_MOVE "SELECT"
140 # define HK_DRAW "MENU"
141 # define HK_REM2CUR "PLAY"
142 # define HK_CUR2STACK "MENU.."
143 # define HK_REM2STACK "RIGHT.."
145 #elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
146 # define SOL_QUIT BUTTON_POWER
147 # define SOL_UP BUTTON_UP
148 # define SOL_DOWN BUTTON_DOWN
149 # define SOL_LEFT BUTTON_LEFT
150 # define SOL_RIGHT BUTTON_RIGHT
151 # define SOL_MOVE_PRE BUTTON_SELECT
152 # define SOL_MOVE (BUTTON_SELECT | BUTTON_REL)
153 # define SOL_DRAW_PRE BUTTON_PLAY
154 # define SOL_DRAW (BUTTON_PLAY | BUTTON_REL)
155 # define SOL_REM2CUR_PRE BUTTON_PLAY
156 # define SOL_REM2CUR (BUTTON_PLAY | BUTTON_REPEAT)
157 # define SOL_CUR2STACK_PRE BUTTON_SELECT
158 # define SOL_CUR2STACK (BUTTON_SELECT | BUTTON_REPEAT)
159 # define SOL_REM2STACK BUTTON_REC
160 # define HK_MOVE "SELECT"
161 # define HK_DRAW "PLAY"
162 # define HK_REM2CUR "PLAY.."
163 # define HK_CUR2STACK "SELECT.."
164 # define HK_REM2STACK "REC"
166 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
167 # define SOL_QUIT BUTTON_POWER
168 # define SOL_UP BUTTON_UP
169 # define SOL_DOWN BUTTON_DOWN
170 # define SOL_LEFT BUTTON_LEFT
171 # define SOL_RIGHT BUTTON_RIGHT
172 # define SOL_MOVE_PRE BUTTON_SELECT
173 # define SOL_MOVE (BUTTON_SELECT | BUTTON_REL)
174 # define SOL_DRAW BUTTON_MENU
175 # define SOL_REM2CUR (BUTTON_LEFT | BUTTON_A)
176 # define SOL_CUR2STACK (BUTTON_SELECT | BUTTON_REPEAT)
177 # define SOL_REM2STACK (BUTTON_RIGHT | BUTTON_A)
178 # define HK_MOVE "SELECT"
179 # define HK_DRAW "MENU"
180 # define HK_REM2CUR "A+LEFT"
181 # define HK_CUR2STACK "SELECT.."
182 # define HK_REM2STACK "A+RIGHT"
184 #elif (CONFIG_KEYPAD == SANSA_E200_PAD)
185 # define SOL_QUIT BUTTON_POWER
186 # define SOL_UP BUTTON_UP
187 # define SOL_DOWN BUTTON_DOWN
188 # define SOL_LEFT BUTTON_SCROLL_BACK
189 # define SOL_RIGHT BUTTON_SCROLL_FWD
190 # define SOL_MOVE BUTTON_SELECT
191 # define SOL_DRAW BUTTON_REC
192 # define SOL_REM2CUR BUTTON_LEFT
193 # define SOL_CUR2STACK_PRE BUTTON_REC
194 # define SOL_CUR2STACK (BUTTON_REC | BUTTON_RIGHT)
195 # define SOL_REM2STACK BUTTON_RIGHT
196 # define HK_MOVE "SELECT"
197 # define HK_DRAW "REC"
198 # define HK_REM2CUR "LEFT"
199 # define HK_CUR2STACK "DOUBLE SELECT"
200 # define HK_REM2STACK "RIGHT"
202 #elif (CONFIG_KEYPAD == SANSA_C200_PAD)
203 # define SOL_QUIT BUTTON_POWER
204 # define SOL_UP BUTTON_UP
205 # define SOL_DOWN BUTTON_DOWN
206 # define SOL_LEFT BUTTON_LEFT
207 # define SOL_RIGHT BUTTON_RIGHT
208 # define SOL_MOVE_PRE BUTTON_SELECT
209 # define SOL_MOVE (BUTTON_SELECT | BUTTON_REL)
210 # define SOL_DRAW BUTTON_VOL_DOWN
211 # define SOL_REM2CUR BUTTON_REC
212 # define SOL_CUR2STACK_PRE BUTTON_SELECT
213 # define SOL_CUR2STACK (BUTTON_SELECT | BUTTON_REPEAT)
214 # define SOL_REM2STACK BUTTON_VOL_UP
215 # define HK_MOVE "SELECT"
216 # define HK_DRAW "REC"
217 # define HK_REM2CUR "LEFT"
218 # define HK_CUR2STACK "DOUBLE SELECT"
219 # define HK_REM2STACK "RIGHT"
221 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
222 # define SOL_QUIT BUTTON_POWER
223 # define SOL_UP BUTTON_SCROLL_UP
224 # define SOL_DOWN BUTTON_SCROLL_DOWN
225 # define SOL_LEFT_PRE BUTTON_LEFT
226 # define SOL_LEFT (BUTTON_LEFT | BUTTON_REL)
227 # define SOL_RIGHT_PRE BUTTON_RIGHT
228 # define SOL_RIGHT (BUTTON_RIGHT | BUTTON_REL)
229 # define SOL_MOVE BUTTON_PLAY
230 # define SOL_DRAW_PRE BUTTON_LEFT
231 # define SOL_DRAW (BUTTON_LEFT | BUTTON_REPEAT)
232 # define SOL_REM2CUR BUTTON_FF
233 # define SOL_CUR2STACK BUTTON_REW
234 # define SOL_REM2STACK_PRE BUTTON_RIGHT
235 # define SOL_REM2STACK (BUTTON_RIGHT | BUTTON_REPEAT)
236 # define HK_MOVE "PLAY"
237 # define HK_DRAW "LEFT.."
238 # define HK_REM2CUR "FF"
239 # define HK_CUR2STACK "REW"
240 # define HK_REM2STACK "RIGHT.."
242 #elif (CONFIG_KEYPAD == GIGABEAT_S_PAD)
243 # define SOL_QUIT BUTTON_BACK
244 # define SOL_UP BUTTON_UP
245 # define SOL_DOWN BUTTON_DOWN
246 # define SOL_LEFT BUTTON_LEFT
247 # define SOL_RIGHT BUTTON_RIGHT
248 # define SOL_MOVE_PRE BUTTON_SELECT
249 # define SOL_MOVE (BUTTON_SELECT | BUTTON_REL)
250 # define SOL_DRAW BUTTON_MENU
251 # define SOL_REM2CUR (BUTTON_LEFT | BUTTON_SELECT)
252 # define SOL_CUR2STACK (BUTTON_SELECT | BUTTON_REPEAT)
253 # define SOL_REM2STACK (BUTTON_RIGHT | BUTTON_SELECT)
254 # define HK_MOVE "SELECT"
255 # define HK_DRAW "MENU"
256 # define HK_REM2CUR "SELECT+LEFT"
257 # define HK_CUR2STACK "SELECT.."
258 # define HK_REM2STACK "SELECT+RIGHT"
260 #elif (CONFIG_KEYPAD == MROBE100_PAD)
261 # define SOL_QUIT BUTTON_POWER
262 # define SOL_UP BUTTON_UP
263 # define SOL_DOWN BUTTON_DOWN
264 # define SOL_LEFT BUTTON_LEFT
265 # define SOL_RIGHT BUTTON_RIGHT
266 # define SOL_MOVE_PRE BUTTON_SELECT
267 # define SOL_MOVE (BUTTON_SELECT | BUTTON_REL)
268 # define SOL_DRAW BUTTON_MENU
269 # define SOL_REM2CUR (BUTTON_LEFT | BUTTON_DISPLAY)
270 # define SOL_CUR2STACK (BUTTON_SELECT | BUTTON_REPEAT)
271 # define SOL_REM2STACK (BUTTON_RIGHT | BUTTON_DISPLAY)
272 # define HK_MOVE "SELECT"
273 # define HK_DRAW "MENU"
274 # define HK_REM2CUR "DISPLAY+LEFT"
275 # define HK_CUR2STACK "SELECT.."
276 # define HK_REM2STACK "DISPLAY+RIGHT"
278 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
279 # define SOL_QUIT BUTTON_RC_REC
280 # define SOL_UP BUTTON_RC_VOL_UP
281 # define SOL_DOWN BUTTON_RC_VOL_DOWN
282 # define SOL_LEFT BUTTON_RC_REW
283 # define SOL_RIGHT BUTTON_RC_FF
284 # define SOL_MOVE BUTTON_RC_PLAY
285 # define SOL_DRAW_PRE BUTTON_RC_MENU
286 # define SOL_DRAW (BUTTON_RC_MENU | BUTTON_REL)
287 # define SOL_REM2CUR_PRE BUTTON_RC_MENU
288 # define SOL_REM2CUR (BUTTON_RC_MENU | BUTTON_REPEAT)
289 # define SOL_CUR2STACK_PRE BUTTON_RC_MODE
290 # define SOL_CUR2STACK (BUTTON_RC_MODE | BUTTON_REL)
291 # define SOL_REM2STACK_PRE BUTTON_RC_MODE
292 # define SOL_REM2STACK (BUTTON_RC_MODE | BUTTON_REPEAT)
293 # define HK_LR "REW/FF"
294 # define HK_UD "VOL UP/DOWN"
295 # define HK_MOVE "PLAY"
296 # define HK_DRAW "MENU"
297 # define HK_REM2CUR "MENU.."
298 # define HK_CUR2STACK "MODE"
299 # define HK_REM2STACK "MODE.."
301 #elif (CONFIG_KEYPAD == COWOND2_PAD)
302 # define SOL_QUIT BUTTON_POWER
305 #error No keymap defined!
310 //# define SOL_QUIT BUTTON_TOPLEFT
313 # define SOL_UP BUTTON_TOPMIDDLE
316 # define SOL_DOWN BUTTON_BOTTOMMIDDLE
319 # define SOL_LEFT BUTTON_MIDLEFT
322 # define SOL_RIGHT BUTTON_MIDRIGHT
325 # define SOL_MOVE BUTTON_CENTER
326 # define HK_MOVE "CENTRE"
329 # define SOL_DRAW BUTTON_TOPLEFT
330 # define HK_DRAW "TOPLEFT"
333 # define SOL_REM2CUR BUTTON_TOPRIGHT
334 # define HK_REM2CUR "TOPRIGHT"
336 #ifndef SOL_CUR2STACK
337 # define SOL_CUR2STACK BUTTON_BOTTOMLEFT
338 # define HK_CUR2STACK "BOTTOMLEFT"
340 #ifndef SOL_REM2STACK
341 # define SOL_REM2STACK BUTTON_BOTTOMRIGHT
342 # define HK_REM2STACK "BOTTOMRIGHT"
348 # define HK_LR "LEFT/RIGHT"
351 # define HK_UD "UP/DOWN"
358 static int helplines
;
359 static int displaylines
;
361 static char helptext
[] =
362 /* Use single spaces only! Close each line with one \0. */
364 HK_LR
": Move the cursor to the previous/ next column.\0"
365 HK_UD
": Move the cursor up/ down in the column.\0"
366 HK_MOVE
": Select cards, move cards, reveal hidden cards...\0"
367 HK_DRAW
": Deselect a card if it was selected. Else draw new card(s) from the remains stack.\0"
369 HK_REM2CUR
": Put the card on top of the remains stack on top of the cursor.\0"
370 HK_CUR2STACK
": Put the card under the cursor on one of the 4 final stacks.\0"
371 HK_REM2STACK
": Put the card on top of the remains stack on one of the 4 final stacks.\0"
375 * Misc constants, graphics and other defines
378 #include "card_back.h"
379 #include "card_deck.h"
380 #include "solitaire_suitsi.h"
382 #define CARD_GFX_WIDTH BMPWIDTH_card_back
383 #define CARD_GFX_HEIGHT BMPHEIGHT_card_back
384 #define CARD_WIDTH (BMPWIDTH_card_back+2)
385 #define CARD_HEIGHT (BMPHEIGHT_card_back+2)
390 # define SYMBOL_HEIGHT 12
391 #elif LCD_WIDTH >= 220
394 # define SYMBOL_HEIGHT 12
395 #elif LCD_WIDTH >= 160
397 # define SYMBOL_HEIGHT 11
398 #elif LCD_WIDTH >= 128
400 # define SYMBOL_HEIGHT 10
403 # define SYMBOL_HEIGHT 8
406 #define CARD_START (CARD_HEIGHT+2*MARGIN+1)
408 /* background color */
409 #ifdef HAVE_LCD_COLOR
410 # define BACKGROUND_COLOR LCD_RGBPACK(0,157,0)
411 # define FRAME_COLOR LCD_RGBPACK(23,119,218)
413 # define BACKGROUND_COLOR LCD_WHITE
414 # define FRAME_COLOR LCD_BLACK
418 #define CONFIG_FILENAME "sol.cfg"
420 #define NOT_A_CARD -1
422 /* number of cards per suit */
423 #define CARDS_PER_SUIT 13
425 /* number of suits */
428 #define NUM_CARDS ( CARDS_PER_SUIT * SUITS )
430 /* number of columns */
433 /* pseudo column numbers to be used for cursor coordinates */
434 /* columns COL_NUM to COL_NUM + SUITS - 1 correspond to the final stacks */
435 #define STACKS_COL COL_NUM
436 /* column COL_NUM + SUITS corresponds to the remains' stack */
437 #define REM_COL (STACKS_COL + SUITS)
446 bool used
: 1; /* this is what is used when dealing cards */
452 * LCD card drawing routines
455 static void draw_cursor( int x
, int y
)
457 rb
->lcd_set_drawmode( DRMODE_COMPLEMENT
);
458 rb
->lcd_fillrect( x
+1, y
+1, CARD_GFX_WIDTH
, CARD_GFX_HEIGHT
);
460 rb
->lcd_drawpixel( x
+1, y
+1 );
461 rb
->lcd_drawpixel( x
+1, y
+CARD_HEIGHT
-2 );
462 rb
->lcd_drawpixel( x
+CARD_WIDTH
-2, y
+1 );
463 rb
->lcd_drawpixel( x
+CARD_WIDTH
-2, y
+CARD_HEIGHT
-2 );
465 rb
->lcd_set_drawmode( DRMODE_SOLID
);
468 /* Draw a card's border, select it if it's selected and draw the cursor
469 * if the cursor is currently over the card */
470 static void draw_card_ext( int x
, int y
, bool selected
, bool cursor
)
473 int oldfg
= rb
->lcd_get_foreground();
475 rb
->lcd_set_foreground( LCD_BLACK
);
478 rb
->lcd_hline( x
+2, x
+CARD_WIDTH
-3, y
);
479 rb
->lcd_hline( x
+2, x
+CARD_WIDTH
-3, y
+CARD_HEIGHT
-1 );
480 rb
->lcd_vline( x
, y
+2, y
+CARD_HEIGHT
-3 );
481 rb
->lcd_vline( x
+CARD_WIDTH
-1, y
+2, y
+CARD_HEIGHT
-3 );
482 rb
->lcd_drawpixel( x
+1, y
+1 );
483 rb
->lcd_drawpixel( x
+1, y
+CARD_HEIGHT
-2 );
484 rb
->lcd_drawpixel( x
+CARD_WIDTH
-2, y
+1 );
485 rb
->lcd_drawpixel( x
+CARD_WIDTH
-2, y
+CARD_HEIGHT
-2 );
487 rb
->lcd_hline( x
+1, x
+CARD_WIDTH
-2, y
);
488 rb
->lcd_hline( x
+1, x
+CARD_WIDTH
-2, y
+CARD_HEIGHT
-1 );
489 rb
->lcd_vline( x
, y
+1, y
+CARD_HEIGHT
-2 );
490 rb
->lcd_vline( x
+CARD_WIDTH
-1, y
+1, y
+CARD_HEIGHT
-2 );
496 rb
->lcd_set_foreground( FRAME_COLOR
);
498 rb
->lcd_drawrect( x
+1, y
+1, CARD_WIDTH
-2, CARD_HEIGHT
-2 );
500 rb
->lcd_drawrect( x
+2, y
+2, CARD_WIDTH
-4, CARD_HEIGHT
-4 );
504 rb
->lcd_set_foreground( oldfg
);
513 /* Draw a card's inner graphics */
514 static void draw_card( card_t
*card
, int x
, int y
,
515 bool selected
, bool cursor
)
519 rb
->lcd_bitmap_part( card_deck
, CARD_GFX_WIDTH
* card
->num
,
520 CARD_GFX_HEIGHT
* card
->suit
, BMPWIDTH_card_deck
,
521 x
+1, y
+1, CARD_GFX_WIDTH
, CARD_GFX_HEIGHT
);
525 rb
->lcd_bitmap( card_back
, x
+1, y
+1,
526 CARD_GFX_WIDTH
, CARD_GFX_HEIGHT
);
528 draw_card_ext( x
, y
, selected
, cursor
);
531 /* Draw an empty stack */
532 static void draw_empty_stack( int s
, int x
, int y
, bool cursor
)
534 rb
->lcd_bitmap_part( solitaire_suitsi
, 0,
535 CARD_GFX_HEIGHT
* s
, BMPWIDTH_solitaire_suitsi
,
536 x
+1, y
+1, CARD_GFX_WIDTH
, CARD_GFX_HEIGHT
);
538 draw_card_ext( x
, y
, false, cursor
);
545 static void init_help(void)
550 char *para
= helptext
;
552 rb
->lcd_getstringsize(" ", &w_space
, &h
);
553 displaylines
= LCD_HEIGHT
/ h
;
554 para_len
= rb
->strlen(para
);
562 next
= rb
->strtok_r(para
, " ", &store
);
565 rb
->lcd_getstringsize(next
, &w
, NULL
);
568 if (x
+ w
> LCD_WIDTH
)
574 next
[-1] = ' '; /* re-concatenate string */
580 next
= rb
->strtok_r(NULL
, " ", &store
);
584 para
+= para_len
+ 1;
585 para_len
= rb
->strlen(para
);
590 enum help
{ HELP_QUIT
, HELP_USB
};
592 /* help for the not so intuitive interface */
593 enum help
solitaire_help( void )
597 int lastbutton
= BUTTON_NONE
;
598 bool fixed
= (displaylines
>= helplines
);
602 char *text
= helptext
;
603 int line
= fixed
? (displaylines
- helplines
) / 2 : 0;
606 rb
->lcd_clear_display();
608 for (i
= 0; i
< start
+ displaylines
; i
++)
611 rb
->lcd_puts(0, line
++, text
);
612 text
+= rb
->strlen(text
) + 1;
616 button
= rb
->button_get( true );
621 if( lastbutton
!= SOL_UP_PRE
)
624 case SOL_UP
|BUTTON_REPEAT
:
626 if (!fixed
&& start
> 0)
632 if( lastbutton
!= SOL_DOWN_PRE
)
635 case SOL_DOWN
|BUTTON_REPEAT
:
637 if (!fixed
&& start
< helplines
- displaylines
)
648 if( rb
->default_event_handler( button
) == SYS_USB_CONNECTED
)
652 if( button
!= BUTTON_NONE
)
658 * Custom menu / options
661 #define CFGFILE_VERSION 0
667 struct sol_config sol_disk
= {0};
668 struct sol_config sol
;
670 static struct configdata config
[] = {
671 { TYPE_INT
, 0, 1, &sol_disk
.draw_type
, "draw_type", NULL
, NULL
},
674 char draw_option_string
[32];
676 static void create_draw_option_string(void)
678 if (sol
.draw_type
== 0)
679 rb
->strcpy(draw_option_string
, "Draw Three Cards");
681 rb
->strcpy(draw_option_string
, "Draw One Card");
684 void solitaire_init(void);
686 /* menu return codes */
687 enum { MENU_RESUME
, MENU_SAVE_AND_QUIT
, MENU_QUIT
, MENU_USB
};
689 int solitaire_menu(bool in_game
)
695 struct menu_item items
[6];
699 items
[i
++].desc
= "Resume Game";
700 items
[i
++].desc
= "Restart Game";
704 items
[i
++].desc
= "Start Game";
705 items
[i
++].desc
= draw_option_string
;
707 items
[i
++].desc
= "Help";
708 items
[i
++].desc
= "Audio Playback";
711 items
[i
++].desc
= "Save and Quit";
713 items
[i
++].desc
= "Quit";
715 create_draw_option_string();
716 m
= menu_init(rb
, items
, i
, NULL
, NULL
, NULL
, NULL
);
719 switch (menu_show(m
))
721 case MENU_SELECTED_EXIT
:
722 result
= MENU_RESUME
;
725 case MENU_ATTACHED_USB
:
730 result
= MENU_RESUME
;
737 result
= MENU_RESUME
;
741 sol
.draw_type
= (sol
.draw_type
+ 1) % 2;
742 create_draw_option_string();
747 rb
->lcd_setmargins(0, 0);
748 if (solitaire_help() == HELP_USB
)
753 playback_control(rb
, NULL
);
758 result
= MENU_SAVE_AND_QUIT
;
769 rb
->lcd_setmargins(0, 0);
777 /* player's cursor */
779 /* player's cursor column num */
786 card_t deck
[ NUM_CARDS
];
788 /* the remaining cards */
789 /* first card of the remains' stack */
791 /* upper visible card from the remains' stack */
793 /* number of cards drawn from the remains stack - 1 */
795 /* number of cards per draw of the remains' stack */
798 /* the 7 game columns */
800 /* the 4 final stacks */
804 * Card handling routines
807 int next_random_card( card_t
*deck
)
811 r
= rb
->rand()%(NUM_CARDS
)+1;
816 i
= (i
+ 1)%(NUM_CARDS
);
817 if( !deck
[i
].used
) r
--;
826 /* initialize the game */
827 void solitaire_init( void )
833 /* number of cards that are drawn on the remains' stack (by pressing F2) */
834 if( sol
.draw_type
== 0 )
844 for( i
=0; i
<SUITS
; i
++ )
846 for( j
=0; j
<CARDS_PER_SUIT
; j
++ )
848 #define card deck[i*CARDS_PER_SUIT+j]
853 card
.next
= NOT_A_CARD
;
858 /* deal the cards ... */
859 /* ... in the columns */
860 for( i
=0; i
<COL_NUM
; i
++ )
863 for( j
=0; j
<=i
; j
++ )
865 if( c
== NOT_A_CARD
)
867 cols
[i
] = next_random_card( deck
);
872 deck
[c
].next
= next_random_card( deck
);
876 deck
[c
].known
= false;
880 /* ... shuffle what's left of the deck */
881 rem
= next_random_card(deck
);
884 for( i
=1; i
< NUM_CARDS
- COL_NUM
* (COL_NUM
+ 1)/2; i
++ )
886 deck
[c
].next
= next_random_card( deck
);
890 /* we now finished dealing the cards. The game can start ! (at last) */
893 for( i
= 0; i
<SUITS
; i
++ )
895 stacks
[i
] = NOT_A_CARD
;
898 /* the cursor starts on upper left card */
902 /* no card is selected */
903 sel_card
= NOT_A_CARD
;
905 /* init the remainder */
906 cur_rem
= NOT_A_CARD
;
911 /* find the column number in which 'card' can be found */
912 int find_card_col( int card
)
917 if( card
== NOT_A_CARD
) return NOT_A_COL
;
919 for( i
=0; i
<COL_NUM
; i
++ )
922 while( c
!= NOT_A_CARD
)
924 if( c
== card
) return i
;
929 for( i
=0; i
<SUITS
; i
++ )
932 while( c
!= NOT_A_CARD
)
934 if( c
== card
) return STACKS_COL
+ i
;
942 /* find the card preceding 'card' */
943 /* if it doesn't exist, return NOT_A_CARD */
944 int find_prev_card( int card
){
947 for( i
=0; i
< NUM_CARDS
; i
++ )
949 if( deck
[i
].next
== card
) return i
;
955 /* find the last card of a given column */
956 int find_last_card( int col
)
964 else if( col
< REM_COL
)
966 c
= stacks
[col
- STACKS_COL
];
977 while(deck
[c
].next
!= NOT_A_CARD
)
983 enum move
{ MOVE_OK
, MOVE_NOT_OK
};
985 enum move
move_card( int dest_col
, int src_card
)
987 /* the column on which to take src_card */
990 /* the last card of dest_col */
993 /* the card under src_card */
996 /* you can't move no card (at least, it doesn't have any consequence) */
997 if( src_card
== NOT_A_CARD
) return MOVE_NOT_OK
;
998 /* you can't put a card back on the remains' stack */
999 if( dest_col
== REM_COL
) return MOVE_NOT_OK
;
1000 /* you can't move an unknown card */
1001 if( !deck
[src_card
].known
) return MOVE_NOT_OK
;
1003 src_col
= find_card_col( src_card
);
1004 dest_card
= find_last_card( dest_col
);
1005 src_card_prev
= find_prev_card( src_card
);
1007 /* you can't move more than one card at a time from the final stack */
1008 /* to the rest of the game */
1009 if( src_col
>= COL_NUM
&& src_col
< REM_COL
1010 && deck
[src_card
].next
!= NOT_A_CARD
)
1015 /* if we (that means dest) are on one of the 7 columns ... */
1016 if( dest_col
< COL_NUM
)
1018 /* ... check is we are on an empty color and that the src is a king */
1019 if( dest_card
== NOT_A_CARD
1020 && deck
[src_card
].num
== CARDS_PER_SUIT
- 1 )
1022 /* this is a winning combination */
1023 cols
[dest_col
] = src_card
;
1025 /* ... or check if the cards follow one another and have
1026 * different colorsuit */
1027 else if(( deck
[dest_card
].suit
+ deck
[src_card
].suit
)%2==1
1028 && deck
[dest_card
].num
== deck
[src_card
].num
+ 1 )
1030 /* this is a winning combination */
1031 deck
[dest_card
].next
= src_card
;
1033 /* ... or, humpf, well that's not good news */
1036 /* this is not a winning combination */
1040 /* if we are on one of the 4 final stacks ... */
1041 else if( dest_col
< REM_COL
)
1043 /* ... check if we are on an empty stack... */
1044 if( dest_card
== NOT_A_CARD
)
1046 /* ... and the src is an ace and this is the correct final stack */
1047 if( deck
[src_card
].num
== 0
1048 && deck
[src_card
].suit
== dest_col
- STACKS_COL
)
1050 /* this is a winning combination */
1051 stacks
[dest_col
- STACKS_COL
] = src_card
;
1055 /* this is not a winning combination */
1059 else /* non-empty stack */
1061 /* ...check if the cards follow one another, have the same suit and
1062 * {that src has no .next element or is from the remains' stack} */
1063 if( deck
[dest_card
].suit
== deck
[src_card
].suit
1064 && deck
[dest_card
].num
+ 1 == deck
[src_card
].num
1065 && (deck
[src_card
].next
== NOT_A_CARD
|| src_col
== REM_COL
) )
1067 /* this is a winning combination */
1068 deck
[dest_card
].next
= src_card
;
1070 /* ... or, well that's not good news */
1073 /* this is not a winning combination */
1078 /* if we are on the remains' stack */
1081 /* you can't move a card back to the remains' stack */
1085 /* if the src card is from the remains' stack, we don't want to take
1086 * the following cards */
1087 if( src_col
== REM_COL
)
1089 /* if src card is the first card from the stack */
1090 if( src_card_prev
== NOT_A_CARD
)
1092 rem
= deck
[src_card
].next
;
1094 /* if src card is not the first card from the stack */
1097 deck
[src_card_prev
].next
= deck
[src_card
].next
;
1099 deck
[src_card
].next
= NOT_A_CARD
;
1100 cur_rem
= src_card_prev
;
1103 /* if the src card is from somewhere else, just take everything */
1106 if( src_card_prev
== NOT_A_CARD
)
1108 if( src_col
< COL_NUM
)
1110 cols
[src_col
] = NOT_A_CARD
;
1114 stacks
[src_col
- STACKS_COL
] = NOT_A_CARD
;
1119 deck
[src_card_prev
].next
= NOT_A_CARD
;
1120 deck
[src_card_prev
].known
= true;
1123 sel_card
= NOT_A_CARD
;
1128 enum { SOLITAIRE_WIN
, SOLITAIRE_SAVE_AND_QUIT
, SOLITAIRE_QUIT
, SOLITAIRE_USB
};
1131 * Bouncing cards at the end of the game
1134 #define BC_ACCEL ((1<<16)*LCD_HEIGHT/128)
1135 #define BC_MYSPEED (6*BC_ACCEL)
1136 #define BC_MXSPEED (6*LCD_HEIGHT/128)
1138 int bouncing_cards( void )
1140 int i
, j
, x
, vx
, y
, fp_y
, fp_vy
, button
;
1142 /* flush the button queue */
1143 while( ( button
= rb
->button_get( false ) ) != BUTTON_NONE
)
1145 if( rb
->default_event_handler( button
) == SYS_USB_CONNECTED
)
1146 return SOLITAIRE_USB
;
1150 for( i
= CARDS_PER_SUIT
-1; i
>=0; i
-- )
1152 for( j
= 0; j
< SUITS
; j
++ )
1154 x
= LCD_WIDTH
-(CARD_WIDTH
*4+4+MARGIN
)+CARD_WIDTH
*j
+j
+1;
1158 vx
= rb
->rand() % (4*BC_MXSPEED
/3-2) - BC_MXSPEED
;
1162 vx
= rb
->rand() % (4*BC_MXSPEED
/3) - BC_MXSPEED
;
1167 fp_vy
= -rb
->rand() % BC_MYSPEED
;
1169 while( x
< LCD_WIDTH
&& x
+ CARD_WIDTH
> 0 )
1174 if( fp_y
>= (LCD_HEIGHT
-CARD_HEIGHT
) << 16 )
1177 fp_y
= (LCD_HEIGHT
-CARD_HEIGHT
) << 16;
1180 draw_card( &deck
[j
*CARDS_PER_SUIT
+i
], x
, y
,
1182 rb
->lcd_update_rect( x
<0?0:x
, y
<0?0:y
,
1183 CARD_WIDTH
, CARD_HEIGHT
);
1185 button
= rb
->button_get_w_tmo( 2 );
1186 if( rb
->default_event_handler( button
) == SYS_USB_CONNECTED
)
1187 return SOLITAIRE_USB
;
1188 if( button
== SOL_QUIT
|| button
== SOL_MOVE
)
1189 return SOLITAIRE_WIN
;
1193 return SOLITAIRE_WIN
;
1197 * Game save/load routines
1199 void get_save_filename( char *buf
)
1202 rb
->strcpy( buf
, rb
->plugin_get_current_filename() );
1203 s
= rb
->strrchr( buf
, '/' ) + 1;
1205 rb
->strcat( s
, "sol.save" );
1208 int open_save_file( int flags
)
1211 get_save_filename( buf
);
1212 return rb
->open( buf
, flags
);
1215 void delete_save_file( void )
1218 get_save_filename( buf
);
1225 int save_write( int fd
, const void *buf
, size_t count
, int *checksum
)
1228 if( rb
->PREFIX(write
)( fd
, buf
, count
) < (ssize_t
)count
)
1230 for( i
= 0; i
< count
; i
++ )
1231 *checksum
+= (int)(((const char *)buf
)[i
]);
1238 int save_read( int fd
, void *buf
, size_t count
, int *checksum
)
1241 if( rb
->PREFIX(read
)( fd
, buf
, count
) < (ssize_t
)count
)
1243 for( i
= 0; i
< count
; i
++ )
1244 *checksum
-= (int)(((const char *)buf
)[i
]);
1248 int save_game( void )
1250 int fd
= open_save_file( O_CREAT
|O_WRONLY
|O_TRUNC
);
1254 if( save_write( fd
, &cur_card
, sizeof( int ), &checksum
)
1255 || save_write( fd
, &cur_col
, sizeof( int ), &checksum
)
1256 || save_write( fd
, &sel_card
, sizeof( int ), &checksum
)
1257 || save_write( fd
, deck
, NUM_CARDS
* sizeof( card_t
), &checksum
)
1258 || save_write( fd
, &rem
, sizeof( int ), &checksum
)
1259 || save_write( fd
, &cur_rem
, sizeof( int ), &checksum
)
1260 || save_write( fd
, &count_rem
, sizeof( int ), &checksum
)
1261 || save_write( fd
, &cards_per_draw
, sizeof( int ), &checksum
)
1262 || save_write( fd
, cols
, COL_NUM
* sizeof( int ), &checksum
)
1263 || save_write( fd
, stacks
, SUITS
* sizeof( int ), &checksum
)
1264 || ( rb
->PREFIX(write
)( fd
, &checksum
, sizeof( int ) ) < (ssize_t
)(sizeof( int ) ) ) )
1267 rb
->splash( 2*HZ
, "Error while saving game. Aborting." );
1274 int load_game( void )
1276 int fd
= open_save_file( O_RDONLY
);
1280 if( ( rb
->PREFIX(lseek
)( fd
, -sizeof( int ), SEEK_END
) == -((ssize_t
)sizeof( int ))-1 )
1281 || ( rb
->PREFIX(read
)( fd
, &checksum
, sizeof( int ) ) < ((ssize_t
)sizeof( int )) )
1282 || ( rb
->PREFIX(lseek
)( fd
, 0, SEEK_SET
) == -1 )
1283 || save_read( fd
, &cur_card
, sizeof( int ), &checksum
)
1284 || save_read( fd
, &cur_col
, sizeof( int ), &checksum
)
1285 || save_read( fd
, &sel_card
, sizeof( int ), &checksum
)
1286 || save_read( fd
, deck
, NUM_CARDS
* sizeof( card_t
), &checksum
)
1287 || save_read( fd
, &rem
, sizeof( int ), &checksum
)
1288 || save_read( fd
, &cur_rem
, sizeof( int ), &checksum
)
1289 || save_read( fd
, &count_rem
, sizeof( int ), &checksum
)
1290 || save_read( fd
, &cards_per_draw
, sizeof( int ), &checksum
)
1291 || save_read( fd
, cols
, COL_NUM
* sizeof( int ), &checksum
)
1292 || save_read( fd
, stacks
, SUITS
* sizeof( int ), &checksum
) )
1295 rb
->splash( 2*HZ
, "Error while loading saved game. Aborting." );
1300 if( checksum
!= 42 )
1302 rb
->splash( 2*HZ
, "Save file was corrupted. Aborting." );
1310 * The main game loop
1312 * If skipmenu is defined to SOLITAIRE_QUIT, the menu will be skipped and
1316 int solitaire( int skipmenu
)
1320 int button
, lastbutton
= 0;
1322 int biggest_col_length
;
1324 rb
->srand( *rb
->current_tick
);
1325 if( skipmenu
!= SOLITAIRE_QUIT
)
1327 switch( solitaire_menu(false) )
1330 return SOLITAIRE_QUIT
;
1333 return SOLITAIRE_USB
;
1340 rb
->lcd_clear_display();
1342 /* get the biggest column length so that display can be "optimized" */
1343 biggest_col_length
= 0;
1345 for(i
=0;i
<COL_NUM
;i
++)
1350 if( c
!= NOT_A_CARD
)
1354 /* don't include the last card in the column length. */
1355 if( deck
[c
].next
== NOT_A_CARD
)
1357 break; /* no successor: get outta here. */
1368 /* make column distinguishable from an empty column,
1369 * and avoid division by zero while displaying */
1373 if( j
> biggest_col_length
)
1374 biggest_col_length
= j
;
1377 /* check if there are cards remaining in the game. */
1378 /* if there aren't any, that means you won :) */
1379 if( biggest_col_length
== 0 && rem
== NOT_A_CARD
)
1381 rb
->splash( HZ
, "You Won :)" );
1382 return bouncing_cards();
1385 /* draw the columns */
1386 for( i
= 0; i
< COL_NUM
; i
++ )
1392 if( c
== NOT_A_CARD
)
1394 /* draw the cursor on empty columns */
1397 draw_cursor( MARGIN
+ i
* (CARD_WIDTH
1398 +(LCD_WIDTH
-COL_NUM
*CARD_WIDTH
-2*MARGIN
)/(COL_NUM
-1)),
1404 draw_card( &deck
[c
], MARGIN
+ i
* (CARD_WIDTH
1405 +(LCD_WIDTH
-COL_NUM
*CARD_WIDTH
-2*MARGIN
)/(COL_NUM
-1)),
1406 j
, c
== sel_card
, c
== cur_card
);
1410 if( c
== NOT_A_CARD
) break;
1412 /* This is where we change the spacing between cards so that
1413 * they don't overflow out of the LCD */
1416 else if( deck
[h
].known
)
1417 j
+= min( SYMBOL_HEIGHT
,
1418 2 * (LCD_HEIGHT
- CARD_START
- CARD_HEIGHT
- MARGIN
)
1419 / biggest_col_length
);
1421 j
+= min( SYMBOL_HEIGHT
/ 2,
1422 (LCD_HEIGHT
- CARD_START
- CARD_HEIGHT
- MARGIN
)
1423 / biggest_col_length
);
1427 /* draw the stacks */
1428 for( i
=0; i
<SUITS
; i
++ )
1430 c
= find_last_card( STACKS_COL
+ i
);
1432 if( c
!= NOT_A_CARD
)
1434 draw_card( &deck
[c
],
1435 LCD_WIDTH
-(CARD_WIDTH
*4+4+MARGIN
)+CARD_WIDTH
*i
+i
+1,
1437 c
== sel_card
, cur_col
== STACKS_COL
+ i
);
1441 draw_empty_stack( i
,
1442 LCD_WIDTH
-(CARD_WIDTH
*4+4+MARGIN
)+CARD_WIDTH
*i
+i
+1,
1443 MARGIN
, cur_col
== STACKS_COL
+ i
);
1447 /* draw the remains */
1448 if( rem
!= NOT_A_CARD
&&
1449 ( cur_rem
== NOT_A_CARD
|| deck
[cur_rem
].next
!= NOT_A_CARD
) )
1451 /* gruik ! (we want to display a card back) */
1452 deck
[rem
].known
= false;
1453 draw_card( &deck
[rem
], MARGIN
, MARGIN
, false, false );
1454 deck
[rem
].known
= true;
1457 if( rem
!= NOT_A_CARD
&& cur_rem
!= NOT_A_CARD
)
1463 while( prevcard
!= cur_rem
&& count_rem
< cards_per_draw
-1 )
1465 prevcard
= deck
[prevcard
].next
;
1470 j
= CARD_WIDTH
+2*MARGIN
+1;
1471 for( i
= 0; i
< count_rem
; i
++ )
1472 prevcard
= find_prev_card(prevcard
);
1473 for( i
= 0; i
<= count_rem
; i
++ )
1475 draw_card( &deck
[prevcard
], j
,
1476 MARGIN
, sel_card
== prevcard
,
1477 cur_card
== prevcard
);
1478 prevcard
= deck
[prevcard
].next
;
1482 if( ( cur_rem
== NOT_A_CARD
|| rem
== NOT_A_CARD
)
1483 && cur_col
== REM_COL
)
1485 draw_cursor( CARD_WIDTH
+2*MARGIN
+1, MARGIN
);
1490 /* what to do when a key is pressed ... */
1491 button
= rb
->button_get( true );
1492 #if (CONFIG_KEYPAD == SANSA_E200_PAD)
1493 if (button
&(BUTTON_SCROLL_BACK
|BUTTON_SCROLL_FWD
))
1494 button
= button
& (~BUTTON_REPEAT
);
1498 /* move cursor to the last card of the previous column
1499 * or to the previous final stack
1500 * or to the remains stack */
1502 #ifdef SOL_RIGHT_PRE
1503 if( lastbutton
!= SOL_RIGHT_PRE
)
1506 if( cur_col
>= COL_NUM
)
1510 else if( cur_col
== COL_NUM
- 1 )
1516 cur_col
= (cur_col
+1)%(REM_COL
+1);
1518 if(cur_col
== REM_COL
)
1523 cur_card
= find_last_card( cur_col
);
1526 /* move cursor to the last card of the next column
1527 * or to the next final stack
1528 * or to the remains stack */
1531 if( lastbutton
!= SOL_LEFT_PRE
)
1538 else if( cur_col
>= COL_NUM
)
1540 cur_col
= COL_NUM
- 1;
1544 cur_col
= (cur_col
+ REM_COL
)%(REM_COL
+1);
1546 if( cur_col
== REM_COL
)
1551 cur_card
= find_last_card( cur_col
);
1554 /* move cursor to card that's bellow */
1557 if( lastbutton
!= SOL_DOWN_PRE
)
1560 case SOL_DOWN
|BUTTON_REPEAT
:
1562 if( cur_col
>= COL_NUM
)
1564 cur_col
= (cur_col
- COL_NUM
+ 1)%(SUITS
+ 1) + COL_NUM
;
1565 if( cur_col
== REM_COL
)
1571 cur_card
= find_last_card( cur_col
);
1575 if( cur_card
== NOT_A_CARD
) break;
1576 if( deck
[cur_card
].next
!= NOT_A_CARD
)
1578 cur_card
= deck
[cur_card
].next
;
1582 cur_card
= cols
[cur_col
];
1583 while( !deck
[ cur_card
].known
1584 && deck
[cur_card
].next
!= NOT_A_CARD
)
1586 cur_card
= deck
[cur_card
].next
;
1591 /* move cursor to card that's above */
1594 if( lastbutton
!= SOL_UP_PRE
)
1597 case SOL_UP
|BUTTON_REPEAT
:
1599 if( cur_col
>= COL_NUM
)
1601 cur_col
= (cur_col
- COL_NUM
+ SUITS
)%(SUITS
+ 1) + COL_NUM
;
1602 if( cur_col
== REM_COL
)
1608 cur_card
= find_last_card( cur_col
);
1612 if( cur_card
== NOT_A_CARD
) break;
1614 cur_card
= find_prev_card( cur_card
);
1615 if( cur_card
== NOT_A_CARD
)
1617 cur_card
= find_last_card( cur_col
);
1619 } while( deck
[cur_card
].next
!= NOT_A_CARD
1620 && !deck
[cur_card
].known
);
1623 /* Try to put card under cursor on one of the stacks */
1625 #ifdef SOL_CUR2STACK_PRE
1626 if( lastbutton
!= SOL_CUR2STACK_PRE
)
1629 move_card( deck
[cur_card
].suit
+ STACKS_COL
, cur_card
);
1632 /* Move cards arround, Uncover cards, ... */
1635 if( lastbutton
!= SOL_MOVE_PRE
)
1639 if( sel_card
== NOT_A_CARD
)
1641 if( cur_card
!= NOT_A_CARD
)
1643 if( deck
[cur_card
].next
== NOT_A_CARD
1644 && !deck
[cur_card
].known
)
1646 /* reveal a hidden card */
1647 deck
[cur_card
].known
= true;
1649 else if( cur_col
== REM_COL
&& cur_rem
== NOT_A_CARD
)
1656 sel_card
= cur_card
;
1660 else if( sel_card
== cur_card
)
1662 /* unselect card or try putting card on
1663 * one of the 4 stacks */
1664 if( move_card( deck
[sel_card
].suit
+ COL_NUM
, sel_card
)
1665 == MOVE_OK
&& cur_col
== REM_COL
)
1669 sel_card
= NOT_A_CARD
;
1673 /* try moving cards */
1674 /* The flexible move must not be used from the remains stack. */
1675 if (find_card_col(sel_card
) == REM_COL
)
1677 if (move_card( cur_col
, sel_card
) == MOVE_NOT_OK
)
1678 sel_card
= NOT_A_CARD
;
1683 if (move_card( cur_col
, sel_card
) == MOVE_OK
)
1685 sel_card
= find_prev_card(sel_card
);
1686 } while (sel_card
!= NOT_A_CARD
);
1691 /* If the card on the top of the remains can be put where
1692 * the cursor is, go ahead */
1694 #ifdef SOL_REM2CUR_PRE
1695 if( lastbutton
!= SOL_REM2CUR_PRE
)
1698 move_card( cur_col
, cur_rem
);
1701 /* If the card on top of the remains can be put on one
1702 * of the stacks, do so */
1704 #ifdef SOL_REM2STACK_PRE
1705 if( lastbutton
!= SOL_REM2STACK_PRE
)
1708 move_card( deck
[cur_rem
].suit
+ COL_NUM
, cur_rem
);
1713 if( sel_card
!= NOT_A_CARD
)
1715 /* unselect selected card */
1716 sel_card
= NOT_A_CARD
;
1719 if( rem
!= NOT_A_CARD
&& cur_rem
!= NOT_A_CARD
)
1727 /* unselect selected card or ...
1728 * draw new cards from the remains of the deck */
1731 if( lastbutton
!= SOL_DRAW_PRE
)
1734 if( sel_card
!= NOT_A_CARD
)
1736 /* unselect selected card */
1737 sel_card
= NOT_A_CARD
;
1740 if( rem
!= NOT_A_CARD
)
1742 int cur_rem_old
= cur_rem
;
1744 /* draw new cards form the remains of the deck */
1745 if( cur_rem
== NOT_A_CARD
)
1747 /*if the cursor card is null*/
1749 i
= cards_per_draw
- 1;
1757 while( i
> 0 && deck
[cur_rem
].next
!= NOT_A_CARD
)
1759 cur_rem
= deck
[cur_rem
].next
;
1763 /* test if any cards are really left on
1764 * the remains' stack */
1765 if( i
== cards_per_draw
)
1767 cur_rem
= NOT_A_CARD
;
1770 /* if cursor was on remains' stack when new cards were
1771 * drawn, put cursor on top of remains' stack */
1772 if( cur_col
== REM_COL
&& cur_card
== cur_rem_old
)
1775 sel_card
= NOT_A_CARD
;
1785 switch( solitaire_menu(true) )
1787 case MENU_SAVE_AND_QUIT
:
1788 return SOLITAIRE_SAVE_AND_QUIT
;
1791 return SOLITAIRE_QUIT
;
1794 return SOLITAIRE_USB
;
1799 return SOLITAIRE_SAVE_AND_QUIT
;
1802 if( rb
->default_event_handler( button
) == SYS_USB_CONNECTED
)
1803 return SOLITAIRE_USB
;
1807 if( button
!= BUTTON_NONE
)
1808 lastbutton
= button
;
1810 /* fix incoherences concerning cur_col and cur_card */
1811 c
= find_card_col( cur_card
);
1812 if( c
!= NOT_A_COL
&& c
!= cur_col
)
1813 cur_card
= find_last_card( cur_col
);
1815 if( cur_card
== NOT_A_CARD
1816 && find_last_card( cur_col
) != NOT_A_CARD
)
1817 cur_card
= find_last_card( cur_col
);
1822 * Plugin entry point
1825 enum plugin_status
plugin_start( const struct plugin_api
* api
, const void* parameter
)
1833 rb
->splash( HZ
, "Welcome to Solitaire!" );
1835 configfile_init(rb
);
1836 configfile_load(CONFIG_FILENAME
, config
,
1837 sizeof(config
) / sizeof(config
[0]), CFGFILE_VERSION
);
1838 rb
->memcpy(&sol
, &sol_disk
, sizeof(sol
)); /* copy to running config */
1840 if( load_game() == 0 )
1842 rb
->splash( HZ
, "Resuming saved game." );
1843 result
= SOLITAIRE_QUIT
;
1846 result
= SOLITAIRE_WIN
;
1851 * Keep playing if a game was won (that means display the menu after
1852 * winning instead of quiting) */
1853 while( ( result
= solitaire( result
) ) == SOLITAIRE_WIN
);
1855 if( result
== SOLITAIRE_QUIT
)
1857 else /* result == SOLITAIRE_USB || result == SOLITAIRE_SAVE_AND_QUIT */
1860 if (rb
->memcmp(&sol
, &sol_disk
, sizeof(sol
))) /* save settings if changed */
1862 rb
->memcpy(&sol_disk
, &sol
, sizeof(sol
));
1863 configfile_save(CONFIG_FILENAME
, config
,
1864 sizeof(config
) / sizeof(config
[0]), CFGFILE_VERSION
);
1867 /* Exit the plugin */
1868 return ( result
== SOLITAIRE_USB
) ? PLUGIN_USB_CONNECTED
: PLUGIN_OK
;