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 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_UP
189 # define SOL_RIGHT BUTTON_SCROLL_DOWN
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.."
243 # error "Unknown keypad"
246 #define HK_LR "LEFT/RIGHT"
248 # define HK_UD "UP/DOWN"
255 static int helplines
;
256 static int displaylines
;
258 static char helptext
[] =
259 /* Use single spaces only! Close each line with one \0. */
261 HK_LR
": Move the cursor to the previous/ next column.\0"
262 HK_UD
": Move the cursor up/ down in the column.\0"
263 HK_MOVE
": Select cards, move cards, reveal hidden cards...\0"
264 HK_DRAW
": Deselect a card if it was selected. Else draw new card(s) from the remains stack.\0"
266 HK_REM2CUR
": Put the card on top of the remains stack on top of the cursor.\0"
267 HK_CUR2STACK
": Put the card under the cursor on one of the 4 final stacks.\0"
268 HK_REM2STACK
": Put the card on top of the remains stack on one of the 4 final stacks.\0"
272 * Misc constants, graphics and other defines
275 #include "card_back.h"
276 #include "card_deck.h"
277 #include "solitaire_suitsi.h"
279 #define CARD_GFX_WIDTH BMPWIDTH_card_back
280 #define CARD_GFX_HEIGHT BMPHEIGHT_card_back
281 #define CARD_WIDTH (BMPWIDTH_card_back+2)
282 #define CARD_HEIGHT (BMPHEIGHT_card_back+2)
287 # define SYMBOL_HEIGHT 12
288 #elif LCD_WIDTH >= 220
291 # define SYMBOL_HEIGHT 12
292 #elif LCD_WIDTH >= 160
294 # define SYMBOL_HEIGHT 11
295 #elif LCD_WIDTH >= 128
297 # define SYMBOL_HEIGHT 10
300 # define SYMBOL_HEIGHT 8
303 #define CARD_START (CARD_HEIGHT+2*MARGIN+1)
305 /* background color */
306 #ifdef HAVE_LCD_COLOR
307 # define BACKGROUND_COLOR LCD_RGBPACK(0,157,0)
308 # define FRAME_COLOR LCD_RGBPACK(23,119,218)
310 # define BACKGROUND_COLOR LCD_WHITE
311 # define FRAME_COLOR LCD_BLACK
315 #define CONFIG_FILENAME "sol.cfg"
317 #define NOT_A_CARD -1
319 /* number of cards per suit */
320 #define CARDS_PER_SUIT 13
322 /* number of suits */
325 #define NUM_CARDS ( CARDS_PER_SUIT * SUITS )
327 /* number of columns */
330 /* pseudo column numbers to be used for cursor coordinates */
331 /* columns COL_NUM to COL_NUM + SUITS - 1 correspond to the final stacks */
332 #define STACKS_COL COL_NUM
333 /* column COL_NUM + SUITS corresponds to the remains' stack */
334 #define REM_COL (STACKS_COL + SUITS)
343 bool used
: 1; /* this is what is used when dealing cards */
349 * LCD card drawing routines
352 static void draw_cursor( int x
, int y
)
354 rb
->lcd_set_drawmode( DRMODE_COMPLEMENT
);
355 rb
->lcd_fillrect( x
+1, y
+1, CARD_GFX_WIDTH
, CARD_GFX_HEIGHT
);
357 rb
->lcd_drawpixel( x
+1, y
+1 );
358 rb
->lcd_drawpixel( x
+1, y
+CARD_HEIGHT
-2 );
359 rb
->lcd_drawpixel( x
+CARD_WIDTH
-2, y
+1 );
360 rb
->lcd_drawpixel( x
+CARD_WIDTH
-2, y
+CARD_HEIGHT
-2 );
362 rb
->lcd_set_drawmode( DRMODE_SOLID
);
365 /* Draw a card's border, select it if it's selected and draw the cursor
366 * if the cursor is currently over the card */
367 static void draw_card_ext( int x
, int y
, bool selected
, bool cursor
)
370 int oldfg
= rb
->lcd_get_foreground();
372 rb
->lcd_set_foreground( LCD_BLACK
);
375 rb
->lcd_hline( x
+2, x
+CARD_WIDTH
-3, y
);
376 rb
->lcd_hline( x
+2, x
+CARD_WIDTH
-3, y
+CARD_HEIGHT
-1 );
377 rb
->lcd_vline( x
, y
+2, y
+CARD_HEIGHT
-3 );
378 rb
->lcd_vline( x
+CARD_WIDTH
-1, y
+2, y
+CARD_HEIGHT
-3 );
379 rb
->lcd_drawpixel( x
+1, y
+1 );
380 rb
->lcd_drawpixel( x
+1, y
+CARD_HEIGHT
-2 );
381 rb
->lcd_drawpixel( x
+CARD_WIDTH
-2, y
+1 );
382 rb
->lcd_drawpixel( x
+CARD_WIDTH
-2, y
+CARD_HEIGHT
-2 );
384 rb
->lcd_hline( x
+1, x
+CARD_WIDTH
-2, y
);
385 rb
->lcd_hline( x
+1, x
+CARD_WIDTH
-2, y
+CARD_HEIGHT
-1 );
386 rb
->lcd_vline( x
, y
+1, y
+CARD_HEIGHT
-2 );
387 rb
->lcd_vline( x
+CARD_WIDTH
-1, y
+1, y
+CARD_HEIGHT
-2 );
393 rb
->lcd_set_foreground( FRAME_COLOR
);
395 rb
->lcd_drawrect( x
+1, y
+1, CARD_WIDTH
-2, CARD_HEIGHT
-2 );
397 rb
->lcd_drawrect( x
+2, y
+2, CARD_WIDTH
-4, CARD_HEIGHT
-4 );
401 rb
->lcd_set_foreground( oldfg
);
410 /* Draw a card's inner graphics */
411 static void draw_card( card_t
*card
, int x
, int y
,
412 bool selected
, bool cursor
)
416 rb
->lcd_bitmap_part( card_deck
, CARD_GFX_WIDTH
* card
->num
,
417 CARD_GFX_HEIGHT
* card
->suit
, BMPWIDTH_card_deck
,
418 x
+1, y
+1, CARD_GFX_WIDTH
, CARD_GFX_HEIGHT
);
422 rb
->lcd_bitmap( card_back
, x
+1, y
+1,
423 CARD_GFX_WIDTH
, CARD_GFX_HEIGHT
);
425 draw_card_ext( x
, y
, selected
, cursor
);
428 /* Draw an empty stack */
429 static void draw_empty_stack( int s
, int x
, int y
, bool cursor
)
431 rb
->lcd_bitmap_part( solitaire_suitsi
, 0,
432 CARD_GFX_HEIGHT
* s
, BMPWIDTH_solitaire_suitsi
,
433 x
+1, y
+1, CARD_GFX_WIDTH
, CARD_GFX_HEIGHT
);
435 draw_card_ext( x
, y
, false, cursor
);
442 static void init_help(void)
447 char *para
= helptext
;
449 rb
->lcd_getstringsize(" ", &w_space
, &h
);
450 displaylines
= LCD_HEIGHT
/ h
;
451 para_len
= rb
->strlen(para
);
459 next
= rb
->strtok_r(para
, " ", &store
);
462 rb
->lcd_getstringsize(next
, &w
, NULL
);
465 if (x
+ w
> LCD_WIDTH
)
471 next
[-1] = ' '; /* re-concatenate string */
477 next
= rb
->strtok_r(NULL
, " ", &store
);
481 para
+= para_len
+ 1;
482 para_len
= rb
->strlen(para
);
487 enum help
{ HELP_QUIT
, HELP_USB
};
489 /* help for the not so intuitive interface */
490 enum help
solitaire_help( void )
494 int lastbutton
= BUTTON_NONE
;
495 bool fixed
= (displaylines
>= helplines
);
499 char *text
= helptext
;
500 int line
= fixed
? (displaylines
- helplines
) / 2 : 0;
503 rb
->lcd_clear_display();
505 for (i
= 0; i
< start
+ displaylines
; i
++)
508 rb
->lcd_puts(0, line
++, text
);
509 text
+= rb
->strlen(text
) + 1;
513 button
= rb
->button_get( true );
518 if( lastbutton
!= SOL_UP_PRE
)
521 case SOL_UP
|BUTTON_REPEAT
:
523 if (!fixed
&& start
> 0)
529 if( lastbutton
!= SOL_DOWN_PRE
)
532 case SOL_DOWN
|BUTTON_REPEAT
:
534 if (!fixed
&& start
< helplines
- displaylines
)
545 if( rb
->default_event_handler( button
) == SYS_USB_CONNECTED
)
549 if( button
!= BUTTON_NONE
)
555 * Custom menu / options
558 #define CFGFILE_VERSION 0
565 struct sol_config sol_disk
= {0, 0};
566 struct sol_config sol
;
568 static struct configdata config
[] = {
569 { TYPE_INT
, 0, 1, &sol_disk
.draw_type
, "draw_type", NULL
, NULL
},
570 { TYPE_INT
, 0, 1, &sol_disk
.auto_unhide
, "auto_unhide", NULL
, NULL
}
573 char draw_option_string
[32];
574 char unhide_option_string
[32];
576 static void create_draw_option_string(void)
578 if (sol
.draw_type
== 0)
579 rb
->strcpy(draw_option_string
, "Draw Three Cards");
581 rb
->strcpy(draw_option_string
, "Draw One Card");
584 static void create_unhide_option_string(void)
586 if (sol
.auto_unhide
== 0)
587 rb
->strcpy(unhide_option_string
, "Unhide manually");
589 rb
->strcpy(unhide_option_string
, "Unhide automatically");
592 void solitaire_init(void);
594 /* menu return codes */
595 enum { MENU_RESUME
, MENU_SAVE_AND_QUIT
, MENU_QUIT
, MENU_USB
};
597 int solitaire_menu(bool in_game
)
603 struct menu_item items
[7];
607 items
[i
++].desc
= "Resume Game";
608 items
[i
++].desc
= "Restart Game";
612 items
[i
++].desc
= "Start Game";
613 items
[i
++].desc
= draw_option_string
;
615 items
[i
++].desc
= unhide_option_string
;
616 items
[i
++].desc
= "Help";
617 items
[i
++].desc
= "Audio Playback";
620 items
[i
++].desc
= "Save and Quit";
622 items
[i
++].desc
= "Quit";
624 create_draw_option_string();
625 create_unhide_option_string();
626 m
= menu_init(rb
, items
, i
, NULL
, NULL
, NULL
, NULL
);
629 switch (menu_show(m
))
631 case MENU_SELECTED_EXIT
:
632 result
= MENU_RESUME
;
635 case MENU_ATTACHED_USB
:
640 result
= MENU_RESUME
;
647 result
= MENU_RESUME
;
651 sol
.draw_type
= (sol
.draw_type
+ 1) % 2;
652 create_draw_option_string();
657 sol
.auto_unhide
= (sol
.auto_unhide
+ 1) % 2;
658 create_unhide_option_string();
662 rb
->lcd_setmargins(0, 0);
663 if (solitaire_help() == HELP_USB
)
668 playback_control(rb
);
673 result
= MENU_SAVE_AND_QUIT
;
684 rb
->lcd_setmargins(0, 0);
692 /* player's cursor */
694 /* player's cursor column num */
701 card_t deck
[ NUM_CARDS
];
703 /* the remaining cards */
704 /* first card of the remains' stack */
706 /* upper visible card from the remains' stack */
708 /* number of cards drawn from the remains stack - 1 */
710 /* number of cards per draw of the remains' stack */
713 /* the 7 game columns */
715 /* the 4 final stacks */
719 * Card handling routines
722 int next_random_card( card_t
*deck
)
726 r
= rb
->rand()%(NUM_CARDS
)+1;
731 i
= (i
+ 1)%(NUM_CARDS
);
732 if( !deck
[i
].used
) r
--;
741 /* initialize the game */
742 void solitaire_init( void )
748 /* number of cards that are drawn on the remains' stack (by pressing F2) */
749 if( sol
.draw_type
== 0 )
759 for( i
=0; i
<SUITS
; i
++ )
761 for( j
=0; j
<CARDS_PER_SUIT
; j
++ )
763 #define card deck[i*CARDS_PER_SUIT+j]
768 card
.next
= NOT_A_CARD
;
773 /* deal the cards ... */
774 /* ... in the columns */
775 for( i
=0; i
<COL_NUM
; i
++ )
778 for( j
=0; j
<=i
; j
++ )
780 if( c
== NOT_A_CARD
)
782 cols
[i
] = next_random_card( deck
);
787 deck
[c
].next
= next_random_card( deck
);
791 deck
[c
].known
= false;
795 /* ... shuffle what's left of the deck */
796 rem
= next_random_card(deck
);
799 for( i
=1; i
< NUM_CARDS
- COL_NUM
* (COL_NUM
+ 1)/2; i
++ )
801 deck
[c
].next
= next_random_card( deck
);
805 /* we now finished dealing the cards. The game can start ! (at last) */
808 for( i
= 0; i
<SUITS
; i
++ )
810 stacks
[i
] = NOT_A_CARD
;
813 /* the cursor starts on upper left card */
817 /* no card is selected */
818 sel_card
= NOT_A_CARD
;
820 /* init the remainder */
821 cur_rem
= NOT_A_CARD
;
826 /* find the column number in which 'card' can be found */
827 int find_card_col( int card
)
832 if( card
== NOT_A_CARD
) return NOT_A_COL
;
834 for( i
=0; i
<COL_NUM
; i
++ )
837 while( c
!= NOT_A_CARD
)
839 if( c
== card
) return i
;
844 for( i
=0; i
<SUITS
; i
++ )
847 while( c
!= NOT_A_CARD
)
849 if( c
== card
) return STACKS_COL
+ i
;
857 /* find the card preceding 'card' */
858 /* if it doesn't exist, return NOT_A_CARD */
859 int find_prev_card( int card
){
862 for( i
=0; i
< NUM_CARDS
; i
++ )
864 if( deck
[i
].next
== card
) return i
;
870 /* find the last card of a given column */
871 int find_last_card( int col
)
879 else if( col
< REM_COL
)
881 c
= stacks
[col
- STACKS_COL
];
892 while(deck
[c
].next
!= NOT_A_CARD
)
898 enum move
{ MOVE_OK
, MOVE_NOT_OK
};
900 enum move
move_card( int dest_col
, int src_card
)
902 /* the column on which to take src_card */
905 /* the last card of dest_col */
908 /* the card under src_card */
911 /* you can't move no card (at least, it doesn't have any consequence) */
912 if( src_card
== NOT_A_CARD
) return MOVE_NOT_OK
;
913 /* you can't put a card back on the remains' stack */
914 if( dest_col
== REM_COL
) return MOVE_NOT_OK
;
915 /* you can't move an unknown card */
916 if( !deck
[src_card
].known
) return MOVE_NOT_OK
;
918 src_col
= find_card_col( src_card
);
919 dest_card
= find_last_card( dest_col
);
920 src_card_prev
= find_prev_card( src_card
);
922 /* you can't move more than one card at a time from the final stack */
923 /* to the rest of the game */
924 if( src_col
>= COL_NUM
&& src_col
< REM_COL
925 && deck
[src_card
].next
!= NOT_A_CARD
)
930 /* if we (that means dest) are on one of the 7 columns ... */
931 if( dest_col
< COL_NUM
)
933 /* ... check is we are on an empty color and that the src is a king */
934 if( dest_card
== NOT_A_CARD
935 && deck
[src_card
].num
== CARDS_PER_SUIT
- 1 )
937 /* this is a winning combination */
938 cols
[dest_col
] = src_card
;
940 /* ... or check if the cards follow one another and have
941 * different colorsuit */
942 else if(( deck
[dest_card
].suit
+ deck
[src_card
].suit
)%2==1
943 && deck
[dest_card
].num
== deck
[src_card
].num
+ 1 )
945 /* this is a winning combination */
946 deck
[dest_card
].next
= src_card
;
948 /* ... or, humpf, well that's not good news */
951 /* this is not a winning combination */
955 /* if we are on one of the 4 final stacks ... */
956 else if( dest_col
< REM_COL
)
958 /* ... check if we are on an empty stack... */
959 if( dest_card
== NOT_A_CARD
)
961 /* ... and the src is an ace and this is the correct final stack */
962 if( deck
[src_card
].num
== 0
963 && deck
[src_card
].suit
== dest_col
- STACKS_COL
)
965 /* this is a winning combination */
966 stacks
[dest_col
- STACKS_COL
] = src_card
;
970 /* this is not a winning combination */
974 else /* non-empty stack */
976 /* ...check if the cards follow one another, have the same suit and
977 * {that src has no .next element or is from the remains' stack} */
978 if( deck
[dest_card
].suit
== deck
[src_card
].suit
979 && deck
[dest_card
].num
+ 1 == deck
[src_card
].num
980 && (deck
[src_card
].next
== NOT_A_CARD
|| src_col
== REM_COL
) )
982 /* this is a winning combination */
983 deck
[dest_card
].next
= src_card
;
985 /* ... or, well that's not good news */
988 /* this is not a winning combination */
993 /* if we are on the remains' stack */
996 /* you can't move a card back to the remains' stack */
1000 /* if the src card is from the remains' stack, we don't want to take
1001 * the following cards */
1002 if( src_col
== REM_COL
)
1004 /* if src card is the first card from the stack */
1005 if( src_card_prev
== NOT_A_CARD
)
1007 rem
= deck
[src_card
].next
;
1009 /* if src card is not the first card from the stack */
1012 deck
[src_card_prev
].next
= deck
[src_card
].next
;
1014 deck
[src_card
].next
= NOT_A_CARD
;
1015 cur_rem
= src_card_prev
;
1018 /* if the src card is from somewhere else, just take everything */
1021 if( src_card_prev
== NOT_A_CARD
)
1023 if( src_col
< COL_NUM
)
1025 cols
[src_col
] = NOT_A_CARD
;
1029 stacks
[src_col
- STACKS_COL
] = NOT_A_CARD
;
1034 deck
[src_card_prev
].next
= NOT_A_CARD
;
1035 if (sol
.auto_unhide
)
1037 deck
[src_card_prev
].known
= true;
1041 sel_card
= NOT_A_CARD
;
1046 enum { SOLITAIRE_WIN
, SOLITAIRE_SAVE_AND_QUIT
, SOLITAIRE_QUIT
, SOLITAIRE_USB
};
1049 * Bouncing cards at the end of the game
1052 #define BC_ACCEL ((1<<16)*LCD_HEIGHT/128)
1053 #define BC_MYSPEED (6*BC_ACCEL)
1054 #define BC_MXSPEED (6*LCD_HEIGHT/128)
1056 int bouncing_cards( void )
1058 int i
, j
, x
, vx
, y
, fp_y
, fp_vy
, button
;
1060 /* flush the button queue */
1061 while( ( button
= rb
->button_get( false ) ) != BUTTON_NONE
)
1063 if( rb
->default_event_handler( button
) == SYS_USB_CONNECTED
)
1064 return SOLITAIRE_USB
;
1068 for( i
= CARDS_PER_SUIT
-1; i
>=0; i
-- )
1070 for( j
= 0; j
< SUITS
; j
++ )
1072 x
= LCD_WIDTH
-(CARD_WIDTH
*4+4+MARGIN
)+CARD_WIDTH
*j
+j
+1;
1076 vx
= rb
->rand() % (4*BC_MXSPEED
/3-2) - BC_MXSPEED
;
1080 vx
= rb
->rand() % (4*BC_MXSPEED
/3) - BC_MXSPEED
;
1085 fp_vy
= -rb
->rand() % BC_MYSPEED
;
1087 while( x
< LCD_WIDTH
&& x
+ CARD_WIDTH
> 0 )
1092 if( fp_y
>= (LCD_HEIGHT
-CARD_HEIGHT
) << 16 )
1095 fp_y
= (LCD_HEIGHT
-CARD_HEIGHT
) << 16;
1098 draw_card( &deck
[j
*CARDS_PER_SUIT
+i
], x
, y
,
1100 rb
->lcd_update_rect( x
<0?0:x
, y
<0?0:y
,
1101 CARD_WIDTH
, CARD_HEIGHT
);
1103 button
= rb
->button_get_w_tmo( 2 );
1104 if( rb
->default_event_handler( button
) == SYS_USB_CONNECTED
)
1105 return SOLITAIRE_USB
;
1106 if( button
== SOL_QUIT
|| button
== SOL_MOVE
)
1107 return SOLITAIRE_WIN
;
1111 return SOLITAIRE_WIN
;
1115 * Game save/load routines
1117 void get_save_filename( char *buf
)
1120 rb
->strcpy( buf
, rb
->plugin_get_current_filename() );
1121 s
= rb
->strrchr( buf
, '/' ) + 1;
1123 rb
->strcat( s
, "sol.save" );
1126 int open_save_file( int flags
)
1129 get_save_filename( buf
);
1130 return rb
->open( buf
, flags
);
1133 void delete_save_file( void )
1136 get_save_filename( buf
);
1143 int save_write( int fd
, const void *buf
, size_t count
, int *checksum
)
1146 if( rb
->PREFIX(write
)( fd
, buf
, count
) < (ssize_t
)count
)
1148 for( i
= 0; i
< count
; i
++ )
1149 *checksum
+= (int)(((const char *)buf
)[i
]);
1156 int save_read( int fd
, void *buf
, size_t count
, int *checksum
)
1159 if( rb
->PREFIX(read
)( fd
, buf
, count
) < (ssize_t
)count
)
1161 for( i
= 0; i
< count
; i
++ )
1162 *checksum
-= (int)(((const char *)buf
)[i
]);
1166 int save_game( void )
1168 int fd
= open_save_file( O_CREAT
|O_WRONLY
|O_TRUNC
);
1172 if( save_write( fd
, &cur_card
, sizeof( int ), &checksum
)
1173 || save_write( fd
, &cur_col
, sizeof( int ), &checksum
)
1174 || save_write( fd
, &sel_card
, sizeof( int ), &checksum
)
1175 || save_write( fd
, deck
, NUM_CARDS
* sizeof( card_t
), &checksum
)
1176 || save_write( fd
, &rem
, sizeof( int ), &checksum
)
1177 || save_write( fd
, &cur_rem
, sizeof( int ), &checksum
)
1178 || save_write( fd
, &count_rem
, sizeof( int ), &checksum
)
1179 || save_write( fd
, &cards_per_draw
, sizeof( int ), &checksum
)
1180 || save_write( fd
, cols
, COL_NUM
* sizeof( int ), &checksum
)
1181 || save_write( fd
, stacks
, SUITS
* sizeof( int ), &checksum
)
1182 || ( rb
->PREFIX(write
)( fd
, &checksum
, sizeof( int ) ) < (ssize_t
)(sizeof( int ) ) ) )
1185 rb
->splash( 2*HZ
, "Error while saving game. Aborting." );
1192 int load_game( void )
1194 int fd
= open_save_file( O_RDONLY
);
1198 if( ( rb
->PREFIX(lseek
)( fd
, -sizeof( int ), SEEK_END
) == -((ssize_t
)sizeof( int ))-1 )
1199 || ( rb
->PREFIX(read
)( fd
, &checksum
, sizeof( int ) ) < ((ssize_t
)sizeof( int )) )
1200 || ( rb
->PREFIX(lseek
)( fd
, 0, SEEK_SET
) == -1 )
1201 || save_read( fd
, &cur_card
, sizeof( int ), &checksum
)
1202 || save_read( fd
, &cur_col
, sizeof( int ), &checksum
)
1203 || save_read( fd
, &sel_card
, sizeof( int ), &checksum
)
1204 || save_read( fd
, deck
, NUM_CARDS
* sizeof( card_t
), &checksum
)
1205 || save_read( fd
, &rem
, sizeof( int ), &checksum
)
1206 || save_read( fd
, &cur_rem
, sizeof( int ), &checksum
)
1207 || save_read( fd
, &count_rem
, sizeof( int ), &checksum
)
1208 || save_read( fd
, &cards_per_draw
, sizeof( int ), &checksum
)
1209 || save_read( fd
, cols
, COL_NUM
* sizeof( int ), &checksum
)
1210 || save_read( fd
, stacks
, SUITS
* sizeof( int ), &checksum
) )
1213 rb
->splash( 2*HZ
, "Error while loading saved game. Aborting." );
1218 if( checksum
!= 42 )
1220 rb
->splash( 2*HZ
, "Save file was corrupted. Aborting." );
1228 * The main game loop
1230 * If skipmenu is defined to SOLITAIRE_QUIT, the menu will be skipped and
1234 int solitaire( int skipmenu
)
1238 int button
, lastbutton
= 0;
1240 int biggest_col_length
;
1242 rb
->srand( *rb
->current_tick
);
1243 if( skipmenu
!= SOLITAIRE_QUIT
)
1245 switch( solitaire_menu(false) )
1248 return SOLITAIRE_QUIT
;
1251 return SOLITAIRE_USB
;
1258 rb
->lcd_clear_display();
1260 /* get the biggest column length so that display can be "optimized" */
1261 biggest_col_length
= 0;
1263 for(i
=0;i
<COL_NUM
;i
++)
1268 if( c
!= NOT_A_CARD
)
1272 /* don't include the last card in the column length. */
1273 if( deck
[c
].next
== NOT_A_CARD
)
1275 break; /* no successor: get outta here. */
1286 /* make column distinguishable from an empty column,
1287 * and avoid division by zero while displaying */
1291 if( j
> biggest_col_length
)
1292 biggest_col_length
= j
;
1295 /* check if there are cards remaining in the game. */
1296 /* if there aren't any, that means you won :) */
1297 if( biggest_col_length
== 0 && rem
== NOT_A_CARD
)
1299 rb
->splash( HZ
, "You Won :)" );
1300 return bouncing_cards();
1303 /* draw the columns */
1304 for( i
= 0; i
< COL_NUM
; i
++ )
1310 if( c
== NOT_A_CARD
)
1312 /* draw the cursor on empty columns */
1315 draw_cursor( MARGIN
+ i
* (CARD_WIDTH
1316 +(LCD_WIDTH
-COL_NUM
*CARD_WIDTH
-2*MARGIN
)/(COL_NUM
-1)),
1322 draw_card( &deck
[c
], MARGIN
+ i
* (CARD_WIDTH
1323 +(LCD_WIDTH
-COL_NUM
*CARD_WIDTH
-2*MARGIN
)/(COL_NUM
-1)),
1324 j
, c
== sel_card
, c
== cur_card
);
1328 if( c
== NOT_A_CARD
) break;
1330 /* This is where we change the spacing between cards so that
1331 * they don't overflow out of the LCD */
1334 else if( deck
[h
].known
)
1335 j
+= min( SYMBOL_HEIGHT
,
1336 2 * (LCD_HEIGHT
- CARD_START
- CARD_HEIGHT
- MARGIN
)
1337 / biggest_col_length
);
1339 j
+= min( SYMBOL_HEIGHT
/ 2,
1340 (LCD_HEIGHT
- CARD_START
- CARD_HEIGHT
- MARGIN
)
1341 / biggest_col_length
);
1345 /* draw the stacks */
1346 for( i
=0; i
<SUITS
; i
++ )
1348 c
= find_last_card( STACKS_COL
+ i
);
1350 if( c
!= NOT_A_CARD
)
1352 draw_card( &deck
[c
],
1353 LCD_WIDTH
-(CARD_WIDTH
*4+4+MARGIN
)+CARD_WIDTH
*i
+i
+1,
1355 c
== sel_card
, cur_col
== STACKS_COL
+ i
);
1359 draw_empty_stack( i
,
1360 LCD_WIDTH
-(CARD_WIDTH
*4+4+MARGIN
)+CARD_WIDTH
*i
+i
+1,
1361 MARGIN
, cur_col
== STACKS_COL
+ i
);
1365 /* draw the remains */
1366 if( rem
!= NOT_A_CARD
&&
1367 ( cur_rem
== NOT_A_CARD
|| deck
[cur_rem
].next
!= NOT_A_CARD
) )
1369 /* gruik ! (we want to display a card back) */
1370 deck
[rem
].known
= false;
1371 draw_card( &deck
[rem
], MARGIN
, MARGIN
, false, false );
1372 deck
[rem
].known
= true;
1375 if( rem
!= NOT_A_CARD
&& cur_rem
!= NOT_A_CARD
)
1381 while( prevcard
!= cur_rem
&& count_rem
< cards_per_draw
-1 )
1383 prevcard
= deck
[prevcard
].next
;
1388 j
= CARD_WIDTH
+2*MARGIN
+1;
1389 for( i
= 0; i
< count_rem
; i
++ )
1390 prevcard
= find_prev_card(prevcard
);
1391 for( i
= 0; i
<= count_rem
; i
++ )
1393 draw_card( &deck
[prevcard
], j
,
1394 MARGIN
, sel_card
== prevcard
,
1395 cur_card
== prevcard
);
1396 prevcard
= deck
[prevcard
].next
;
1400 if( ( cur_rem
== NOT_A_CARD
|| rem
== NOT_A_CARD
)
1401 && cur_col
== REM_COL
)
1403 draw_cursor( CARD_WIDTH
+2*MARGIN
+1, MARGIN
);
1408 /* what to do when a key is pressed ... */
1409 button
= rb
->button_get( true );
1410 #if (CONFIG_KEYPAD == SANSA_E200_PAD)
1411 if (button
&(BUTTON_SCROLL_UP
|BUTTON_SCROLL_DOWN
))
1412 button
= button
& (~BUTTON_REPEAT
);
1416 /* move cursor to the last card of the previous column
1417 * or to the previous final stack
1418 * or to the remains stack */
1420 #ifdef SOL_RIGHT_PRE
1421 if( lastbutton
!= SOL_RIGHT_PRE
)
1424 if( cur_col
>= COL_NUM
)
1428 else if( cur_col
== COL_NUM
- 1 )
1434 cur_col
= (cur_col
+1)%(REM_COL
+1);
1436 if(cur_col
== REM_COL
)
1441 cur_card
= find_last_card( cur_col
);
1444 /* move cursor to the last card of the next column
1445 * or to the next final stack
1446 * or to the remains stack */
1449 if( lastbutton
!= SOL_LEFT_PRE
)
1456 else if( cur_col
>= COL_NUM
)
1458 cur_col
= COL_NUM
- 1;
1462 cur_col
= (cur_col
+ REM_COL
)%(REM_COL
+1);
1464 if( cur_col
== REM_COL
)
1469 cur_card
= find_last_card( cur_col
);
1472 /* move cursor to card that's bellow */
1475 if( lastbutton
!= SOL_DOWN_PRE
)
1478 case SOL_DOWN
|BUTTON_REPEAT
:
1480 if( cur_col
>= COL_NUM
)
1482 cur_col
= (cur_col
- COL_NUM
+ 1)%(SUITS
+ 1) + COL_NUM
;
1483 if( cur_col
== REM_COL
)
1489 cur_card
= find_last_card( cur_col
);
1493 if( cur_card
== NOT_A_CARD
) break;
1494 if( deck
[cur_card
].next
!= NOT_A_CARD
)
1496 cur_card
= deck
[cur_card
].next
;
1500 cur_card
= cols
[cur_col
];
1501 while( !deck
[ cur_card
].known
1502 && deck
[cur_card
].next
!= NOT_A_CARD
)
1504 cur_card
= deck
[cur_card
].next
;
1509 /* move cursor to card that's above */
1512 if( lastbutton
!= SOL_UP_PRE
)
1515 case SOL_UP
|BUTTON_REPEAT
:
1517 if( cur_col
>= COL_NUM
)
1519 cur_col
= (cur_col
- COL_NUM
+ SUITS
)%(SUITS
+ 1) + COL_NUM
;
1520 if( cur_col
== REM_COL
)
1526 cur_card
= find_last_card( cur_col
);
1530 if( cur_card
== NOT_A_CARD
) break;
1532 cur_card
= find_prev_card( cur_card
);
1533 if( cur_card
== NOT_A_CARD
)
1535 cur_card
= find_last_card( cur_col
);
1537 } while( deck
[cur_card
].next
!= NOT_A_CARD
1538 && !deck
[cur_card
].known
);
1541 /* Try to put card under cursor on one of the stacks */
1543 #ifdef SOL_CUR2STACK_PRE
1544 if( lastbutton
!= SOL_CUR2STACK_PRE
)
1547 move_card( deck
[cur_card
].suit
+ STACKS_COL
, cur_card
);
1550 /* Move cards arround, Uncover cards, ... */
1553 if( lastbutton
!= SOL_MOVE_PRE
)
1557 if( sel_card
== NOT_A_CARD
)
1559 if( cur_card
!= NOT_A_CARD
)
1561 if( deck
[cur_card
].next
== NOT_A_CARD
1562 && !deck
[cur_card
].known
)
1564 /* reveal a hidden card */
1565 deck
[cur_card
].known
= true;
1567 else if( cur_col
== REM_COL
&& cur_rem
== NOT_A_CARD
)
1574 sel_card
= cur_card
;
1578 else if( sel_card
== cur_card
)
1580 /* unselect card or try putting card on
1581 * one of the 4 stacks */
1582 if( move_card( deck
[sel_card
].suit
+ COL_NUM
, sel_card
)
1583 == MOVE_OK
&& cur_col
== REM_COL
)
1587 sel_card
= NOT_A_CARD
;
1591 /* try moving cards */
1592 /* the code in the else seems to not like moveing kings
1593 so if the selected card is a king do it the simple way */
1594 if (deck
[sel_card
].num
== CARDS_PER_SUIT
- 1)
1596 if (move_card( cur_col
, sel_card
) == MOVE_NOT_OK
)
1597 sel_card
= NOT_A_CARD
;
1603 retval
= move_card( cur_col
, sel_card
);
1604 if (retval
== MOVE_NOT_OK
)
1606 sel_card
= find_prev_card(sel_card
);
1608 } while ((retval
== MOVE_NOT_OK
) && (sel_card
!= NOT_A_CARD
));
1613 /* If the card on the top of the remains can be put where
1614 * the cursor is, go ahead */
1616 #ifdef SOL_REM2CUR_PRE
1617 if( lastbutton
!= SOL_REM2CUR_PRE
)
1620 move_card( cur_col
, cur_rem
);
1623 /* If the card on top of the remains can be put on one
1624 * of the stacks, do so */
1626 #ifdef SOL_REM2STACK_PRE
1627 if( lastbutton
!= SOL_REM2STACK_PRE
)
1630 move_card( deck
[cur_rem
].suit
+ COL_NUM
, cur_rem
);
1635 if( sel_card
!= NOT_A_CARD
)
1637 /* unselect selected card */
1638 sel_card
= NOT_A_CARD
;
1641 if( rem
!= NOT_A_CARD
&& cur_rem
!= NOT_A_CARD
)
1649 /* unselect selected card or ...
1650 * draw new cards from the remains of the deck */
1653 if( lastbutton
!= SOL_DRAW_PRE
)
1656 if( sel_card
!= NOT_A_CARD
)
1658 /* unselect selected card */
1659 sel_card
= NOT_A_CARD
;
1662 if( rem
!= NOT_A_CARD
)
1664 int cur_rem_old
= cur_rem
;
1666 /* draw new cards form the remains of the deck */
1667 if( cur_rem
== NOT_A_CARD
)
1669 /*if the cursor card is null*/
1671 i
= cards_per_draw
- 1;
1679 while( i
> 0 && deck
[cur_rem
].next
!= NOT_A_CARD
)
1681 cur_rem
= deck
[cur_rem
].next
;
1685 /* test if any cards are really left on
1686 * the remains' stack */
1687 if( i
== cards_per_draw
)
1689 cur_rem
= NOT_A_CARD
;
1692 /* if cursor was on remains' stack when new cards were
1693 * drawn, put cursor on top of remains' stack */
1694 if( cur_col
== REM_COL
&& cur_card
== cur_rem_old
)
1697 sel_card
= NOT_A_CARD
;
1707 switch( solitaire_menu(true) )
1709 case MENU_SAVE_AND_QUIT
:
1710 return SOLITAIRE_SAVE_AND_QUIT
;
1713 return SOLITAIRE_QUIT
;
1716 return SOLITAIRE_USB
;
1721 return SOLITAIRE_SAVE_AND_QUIT
;
1724 if( rb
->default_event_handler( button
) == SYS_USB_CONNECTED
)
1725 return SOLITAIRE_USB
;
1729 if( button
!= BUTTON_NONE
)
1730 lastbutton
= button
;
1732 /* fix incoherences concerning cur_col and cur_card */
1733 c
= find_card_col( cur_card
);
1734 if( c
!= NOT_A_COL
&& c
!= cur_col
)
1735 cur_card
= find_last_card( cur_col
);
1737 if( cur_card
== NOT_A_CARD
1738 && find_last_card( cur_col
) != NOT_A_CARD
)
1739 cur_card
= find_last_card( cur_col
);
1744 * Plugin entry point
1747 enum plugin_status
plugin_start( struct plugin_api
* api
, void* parameter
)
1755 rb
->splash( HZ
, "Welcome to Solitaire!" );
1757 configfile_init(rb
);
1758 configfile_load(CONFIG_FILENAME
, config
,
1759 sizeof(config
) / sizeof(config
[0]), CFGFILE_VERSION
);
1760 rb
->memcpy(&sol
, &sol_disk
, sizeof(sol
)); /* copy to running config */
1762 if( load_game() == 0 )
1764 rb
->splash( HZ
, "Resuming saved game." );
1765 result
= SOLITAIRE_QUIT
;
1768 result
= SOLITAIRE_WIN
;
1773 * Keep playing if a game was won (that means display the menu after
1774 * winning instead of quiting) */
1775 while( ( result
= solitaire( result
) ) == SOLITAIRE_WIN
);
1777 if( result
== SOLITAIRE_QUIT
)
1779 else /* result == SOLITAIRE_USB || result == SOLITAIRE_SAVE_AND_QUIT */
1782 if (rb
->memcmp(&sol
, &sol_disk
, sizeof(sol
))) /* save settings if changed */
1784 rb
->memcpy(&sol_disk
, &sol
, sizeof(sol
));
1785 configfile_save(CONFIG_FILENAME
, config
,
1786 sizeof(config
) / sizeof(config
[0]), CFGFILE_VERSION
);
1789 /* Exit the plugin */
1790 return ( result
== SOLITAIRE_USB
) ? PLUGIN_USB_CONNECTED
: PLUGIN_OK
;