1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2004-2007 Antoine Cellerier <dionoea @t videolan d.t org>
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 #include "playback_control.h"
24 #include "configfile.h"
27 #include "oldmenuapi.h"
29 #ifdef HAVE_LCD_BITMAP
33 static const struct plugin_api
* rb
;
34 #define min(a,b) (a<b?a:b)
40 #if CONFIG_KEYPAD == RECORDER_PAD
41 # define SOL_QUIT BUTTON_OFF
42 # define SOL_UP BUTTON_UP
43 # define SOL_DOWN BUTTON_DOWN
44 # define SOL_LEFT BUTTON_LEFT
45 # define SOL_RIGHT BUTTON_RIGHT
46 # define SOL_MOVE BUTTON_ON
47 # define SOL_DRAW BUTTON_F1
48 # define SOL_REM2CUR BUTTON_PLAY
49 # define SOL_CUR2STACK BUTTON_F2
50 # define SOL_REM2STACK BUTTON_F3
53 # define HK_REM2CUR "PLAY"
54 # define HK_CUR2STACK "F2"
55 # define HK_REM2STACK "F3"
57 #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
58 # define SOL_QUIT BUTTON_OFF
59 # define SOL_UP BUTTON_UP
60 # define SOL_DOWN BUTTON_DOWN
61 # define SOL_LEFT BUTTON_LEFT
62 # define SOL_RIGHT BUTTON_RIGHT
63 # define SOL_MOVE BUTTON_ON
64 # define SOL_DRAW BUTTON_F1
65 # define SOL_REM2CUR BUTTON_SELECT
66 # define SOL_CUR2STACK BUTTON_F2
67 # define SOL_REM2STACK BUTTON_F3
70 # define HK_REM2CUR "SELECT"
71 # define HK_CUR2STACK "F2"
72 # define HK_REM2STACK "F3"
74 #elif CONFIG_KEYPAD == ONDIO_PAD
75 # define SOL_QUIT BUTTON_OFF
76 # define SOL_UP_PRE BUTTON_UP
77 # define SOL_UP (BUTTON_UP | BUTTON_REL)
78 # define SOL_DOWN_PRE BUTTON_DOWN
79 # define SOL_DOWN (BUTTON_DOWN | BUTTON_REL)
80 # define SOL_LEFT_PRE BUTTON_LEFT
81 # define SOL_LEFT (BUTTON_LEFT | BUTTON_REL)
82 # define SOL_RIGHT_PRE BUTTON_RIGHT
83 # define SOL_RIGHT (BUTTON_RIGHT | BUTTON_REL)
84 # define SOL_MOVE_PRE BUTTON_MENU
85 # define SOL_MOVE (BUTTON_MENU | BUTTON_REL)
86 # define SOL_DRAW_PRE BUTTON_MENU
87 # define SOL_DRAW (BUTTON_MENU | BUTTON_REPEAT)
88 # define SOL_REM2CUR_PRE BUTTON_DOWN
89 # define SOL_REM2CUR (BUTTON_DOWN | BUTTON_REPEAT)
90 # define SOL_CUR2STACK_PRE BUTTON_UP
91 # define SOL_CUR2STACK (BUTTON_UP | BUTTON_REPEAT)
92 # define SOL_REM2STACK_PRE BUTTON_RIGHT
93 # define SOL_REM2STACK (BUTTON_RIGHT | BUTTON_REPEAT)
94 # define HK_MOVE "MODE"
95 # define HK_DRAW "MODE.."
96 # define HK_REM2CUR "DOWN.."
97 # define HK_CUR2STACK "UP.."
98 # define HK_REM2STACK "RIGHT.."
100 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
101 (CONFIG_KEYPAD == IRIVER_H300_PAD)
102 # define SOL_QUIT BUTTON_OFF
103 # define SOL_UP BUTTON_UP
104 # define SOL_DOWN BUTTON_DOWN
105 # define SOL_LEFT BUTTON_LEFT
106 # define SOL_RIGHT BUTTON_RIGHT
107 # define SOL_MOVE_PRE BUTTON_SELECT
108 # define SOL_MOVE (BUTTON_SELECT | BUTTON_REL)
109 # define SOL_DRAW BUTTON_MODE
110 # define SOL_REM2CUR (BUTTON_LEFT | BUTTON_ON)
111 # define SOL_CUR2STACK_PRE BUTTON_SELECT
112 # define SOL_CUR2STACK (BUTTON_SELECT | BUTTON_REPEAT)
113 # define SOL_REM2STACK (BUTTON_RIGHT | BUTTON_ON)
114 # define SOL_REM BUTTON_REC
115 # define SOL_RC_QUIT BUTTON_RC_STOP
116 # define HK_MOVE "NAVI"
117 # define HK_DRAW "A-B"
118 # define HK_REM2CUR "PLAY+LEFT"
119 # define HK_CUR2STACK "NAVI.."
120 # define HK_REM2STACK "PLAY+RIGHT"
122 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
123 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
124 # define SOL_QUIT (BUTTON_SELECT | BUTTON_MENU)
125 # define SOL_UP BUTTON_SCROLL_BACK
126 # define SOL_DOWN BUTTON_SCROLL_FWD
127 # define SOL_LEFT_PRE BUTTON_LEFT
128 # define SOL_LEFT (BUTTON_LEFT | BUTTON_REL)
129 # define SOL_RIGHT_PRE BUTTON_RIGHT
130 # define SOL_RIGHT (BUTTON_RIGHT | BUTTON_REL)
131 # define SOL_MOVE_PRE BUTTON_SELECT
132 # define SOL_MOVE (BUTTON_SELECT | BUTTON_REL)
133 # define SOL_DRAW_PRE BUTTON_MENU
134 # define SOL_DRAW (BUTTON_MENU | BUTTON_REL)
135 # define SOL_REM2CUR BUTTON_PLAY
136 # define SOL_CUR2STACK_PRE BUTTON_MENU
137 # define SOL_CUR2STACK (BUTTON_MENU | BUTTON_REPEAT)
138 # define SOL_REM2STACK_PRE BUTTON_RIGHT
139 # define SOL_REM2STACK (BUTTON_RIGHT | BUTTON_REPEAT)
140 # define HK_UD "SCROLL U/D"
141 # define HK_MOVE "SELECT"
142 # define HK_DRAW "MENU"
143 # define HK_REM2CUR "PLAY"
144 # define HK_CUR2STACK "MENU.."
145 # define HK_REM2STACK "RIGHT.."
147 #elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
148 # define SOL_QUIT BUTTON_POWER
149 # define SOL_UP BUTTON_UP
150 # define SOL_DOWN BUTTON_DOWN
151 # define SOL_LEFT BUTTON_LEFT
152 # define SOL_RIGHT BUTTON_RIGHT
153 # define SOL_MOVE_PRE BUTTON_SELECT
154 # define SOL_MOVE (BUTTON_SELECT | BUTTON_REL)
155 # define SOL_DRAW_PRE BUTTON_PLAY
156 # define SOL_DRAW (BUTTON_PLAY | BUTTON_REL)
157 # define SOL_REM2CUR_PRE BUTTON_PLAY
158 # define SOL_REM2CUR (BUTTON_PLAY | BUTTON_REPEAT)
159 # define SOL_CUR2STACK_PRE BUTTON_SELECT
160 # define SOL_CUR2STACK (BUTTON_SELECT | BUTTON_REPEAT)
161 # define SOL_REM2STACK BUTTON_REC
162 # define HK_MOVE "SELECT"
163 # define HK_DRAW "PLAY"
164 # define HK_REM2CUR "PLAY.."
165 # define HK_CUR2STACK "SELECT.."
166 # define HK_REM2STACK "REC"
168 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
169 # define SOL_QUIT BUTTON_POWER
170 # define SOL_UP BUTTON_UP
171 # define SOL_DOWN BUTTON_DOWN
172 # define SOL_LEFT BUTTON_LEFT
173 # define SOL_RIGHT BUTTON_RIGHT
174 # define SOL_MOVE_PRE BUTTON_SELECT
175 # define SOL_MOVE (BUTTON_SELECT | BUTTON_REL)
176 # define SOL_DRAW BUTTON_MENU
177 # define SOL_REM2CUR (BUTTON_LEFT | BUTTON_A)
178 # define SOL_CUR2STACK (BUTTON_SELECT | BUTTON_REPEAT)
179 # define SOL_REM2STACK (BUTTON_RIGHT | BUTTON_A)
180 # define HK_MOVE "SELECT"
181 # define HK_DRAW "MENU"
182 # define HK_REM2CUR "A+LEFT"
183 # define HK_CUR2STACK "SELECT.."
184 # define HK_REM2STACK "A+RIGHT"
186 #elif (CONFIG_KEYPAD == SANSA_E200_PAD)
187 # define SOL_QUIT BUTTON_POWER
188 # define SOL_UP BUTTON_UP
189 # define SOL_DOWN BUTTON_DOWN
190 # define SOL_LEFT BUTTON_SCROLL_BACK
191 # define SOL_RIGHT BUTTON_SCROLL_FWD
192 # define SOL_MOVE BUTTON_SELECT
193 # define SOL_DRAW BUTTON_REC
194 # define SOL_REM2CUR BUTTON_LEFT
195 # define SOL_CUR2STACK_PRE BUTTON_REC
196 # define SOL_CUR2STACK (BUTTON_REC | BUTTON_RIGHT)
197 # define SOL_REM2STACK BUTTON_RIGHT
198 # define HK_MOVE "SELECT"
199 # define HK_DRAW "REC"
200 # define HK_REM2CUR "LEFT"
201 # define HK_CUR2STACK "DOUBLE SELECT"
202 # define HK_REM2STACK "RIGHT"
204 #elif (CONFIG_KEYPAD == SANSA_C200_PAD)
205 # define SOL_QUIT BUTTON_POWER
206 # define SOL_UP BUTTON_UP
207 # define SOL_DOWN BUTTON_DOWN
208 # define SOL_LEFT BUTTON_LEFT
209 # define SOL_RIGHT BUTTON_RIGHT
210 # define SOL_MOVE_PRE BUTTON_SELECT
211 # define SOL_MOVE (BUTTON_SELECT | BUTTON_REL)
212 # define SOL_DRAW BUTTON_VOL_DOWN
213 # define SOL_REM2CUR BUTTON_REC
214 # define SOL_CUR2STACK_PRE BUTTON_SELECT
215 # define SOL_CUR2STACK (BUTTON_SELECT | BUTTON_REPEAT)
216 # define SOL_REM2STACK BUTTON_VOL_UP
217 # define HK_MOVE "SELECT"
218 # define HK_DRAW "REC"
219 # define HK_REM2CUR "LEFT"
220 # define HK_CUR2STACK "DOUBLE SELECT"
221 # define HK_REM2STACK "RIGHT"
223 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
224 # define SOL_QUIT BUTTON_POWER
225 # define SOL_UP BUTTON_SCROLL_UP
226 # define SOL_DOWN BUTTON_SCROLL_DOWN
227 # define SOL_LEFT_PRE BUTTON_LEFT
228 # define SOL_LEFT (BUTTON_LEFT | BUTTON_REL)
229 # define SOL_RIGHT_PRE BUTTON_RIGHT
230 # define SOL_RIGHT (BUTTON_RIGHT | BUTTON_REL)
231 # define SOL_MOVE BUTTON_PLAY
232 # define SOL_DRAW_PRE BUTTON_LEFT
233 # define SOL_DRAW (BUTTON_LEFT | BUTTON_REPEAT)
234 # define SOL_REM2CUR BUTTON_FF
235 # define SOL_CUR2STACK BUTTON_REW
236 # define SOL_REM2STACK_PRE BUTTON_RIGHT
237 # define SOL_REM2STACK (BUTTON_RIGHT | BUTTON_REPEAT)
238 # define HK_MOVE "PLAY"
239 # define HK_DRAW "LEFT.."
240 # define HK_REM2CUR "FF"
241 # define HK_CUR2STACK "REW"
242 # define HK_REM2STACK "RIGHT.."
244 #elif (CONFIG_KEYPAD == GIGABEAT_S_PAD)
245 # define SOL_QUIT BUTTON_BACK
246 # define SOL_UP BUTTON_UP
247 # define SOL_DOWN BUTTON_DOWN
248 # define SOL_LEFT BUTTON_LEFT
249 # define SOL_RIGHT BUTTON_RIGHT
250 # define SOL_MOVE_PRE BUTTON_SELECT
251 # define SOL_MOVE (BUTTON_SELECT | BUTTON_REL)
252 # define SOL_DRAW BUTTON_MENU
253 # define SOL_REM2CUR (BUTTON_LEFT | BUTTON_SELECT)
254 # define SOL_CUR2STACK (BUTTON_SELECT | BUTTON_REPEAT)
255 # define SOL_REM2STACK (BUTTON_RIGHT | BUTTON_SELECT)
256 # define HK_MOVE "SELECT"
257 # define HK_DRAW "MENU"
258 # define HK_REM2CUR "SELECT+LEFT"
259 # define HK_CUR2STACK "SELECT.."
260 # define HK_REM2STACK "SELECT+RIGHT"
262 #elif (CONFIG_KEYPAD == MROBE100_PAD)
263 # define SOL_QUIT BUTTON_POWER
264 # define SOL_UP BUTTON_UP
265 # define SOL_DOWN BUTTON_DOWN
266 # define SOL_LEFT BUTTON_LEFT
267 # define SOL_RIGHT BUTTON_RIGHT
268 # define SOL_MOVE_PRE BUTTON_SELECT
269 # define SOL_MOVE (BUTTON_SELECT | BUTTON_REL)
270 # define SOL_DRAW BUTTON_MENU
271 # define SOL_REM2CUR (BUTTON_LEFT | BUTTON_DISPLAY)
272 # define SOL_CUR2STACK (BUTTON_SELECT | BUTTON_REPEAT)
273 # define SOL_REM2STACK (BUTTON_RIGHT | BUTTON_DISPLAY)
274 # define HK_MOVE "SELECT"
275 # define HK_DRAW "MENU"
276 # define HK_REM2CUR "DISPLAY+LEFT"
277 # define HK_CUR2STACK "SELECT.."
278 # define HK_REM2STACK "DISPLAY+RIGHT"
280 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
281 # define SOL_QUIT BUTTON_RC_REC
282 # define SOL_UP BUTTON_RC_VOL_UP
283 # define SOL_DOWN BUTTON_RC_VOL_DOWN
284 # define SOL_LEFT BUTTON_RC_REW
285 # define SOL_RIGHT BUTTON_RC_FF
286 # define SOL_MOVE BUTTON_RC_PLAY
287 # define SOL_DRAW_PRE BUTTON_RC_MENU
288 # define SOL_DRAW (BUTTON_RC_MENU | BUTTON_REL)
289 # define SOL_REM2CUR_PRE BUTTON_RC_MENU
290 # define SOL_REM2CUR (BUTTON_RC_MENU | BUTTON_REPEAT)
291 # define SOL_CUR2STACK_PRE BUTTON_RC_MODE
292 # define SOL_CUR2STACK (BUTTON_RC_MODE | BUTTON_REL)
293 # define SOL_REM2STACK_PRE BUTTON_RC_MODE
294 # define SOL_REM2STACK (BUTTON_RC_MODE | BUTTON_REPEAT)
295 # define HK_LR "REW/FF"
296 # define HK_UD "VOL UP/DOWN"
297 # define HK_MOVE "PLAY"
298 # define HK_DRAW "MENU"
299 # define HK_REM2CUR "MENU.."
300 # define HK_CUR2STACK "MODE"
301 # define HK_REM2STACK "MODE.."
303 #elif (CONFIG_KEYPAD == COWOND2_PAD)
304 # define SOL_QUIT BUTTON_POWER
307 #error No keymap defined!
312 //# define SOL_QUIT BUTTON_TOPLEFT
315 # define SOL_UP BUTTON_TOPMIDDLE
318 # define SOL_DOWN BUTTON_BOTTOMMIDDLE
321 # define SOL_LEFT BUTTON_MIDLEFT
324 # define SOL_RIGHT BUTTON_MIDRIGHT
327 # define SOL_MOVE BUTTON_CENTER
328 # define HK_MOVE "CENTRE"
331 # define SOL_DRAW BUTTON_TOPLEFT
332 # define HK_DRAW "TOPLEFT"
335 # define SOL_REM2CUR BUTTON_TOPRIGHT
336 # define HK_REM2CUR "TOPRIGHT"
338 #ifndef SOL_CUR2STACK
339 # define SOL_CUR2STACK BUTTON_BOTTOMLEFT
340 # define HK_CUR2STACK "BOTTOMLEFT"
342 #ifndef SOL_REM2STACK
343 # define SOL_REM2STACK BUTTON_BOTTOMRIGHT
344 # define HK_REM2STACK "BOTTOMRIGHT"
350 # define HK_LR "LEFT/RIGHT"
353 # define HK_UD "UP/DOWN"
360 static int helplines
;
361 static int displaylines
;
363 static char helptext
[] =
364 /* Use single spaces only! Close each line with one \0. */
366 HK_LR
": Move the cursor to the previous/ next column.\0"
367 HK_UD
": Move the cursor up/ down in the column.\0"
368 HK_MOVE
": Select cards, move cards, reveal hidden cards...\0"
369 HK_DRAW
": Deselect a card if it was selected. Else draw new card(s) from the remains stack.\0"
371 HK_REM2CUR
": Put the card on top of the remains stack on top of the cursor.\0"
372 HK_CUR2STACK
": Put the card under the cursor on one of the 4 final stacks.\0"
373 HK_REM2STACK
": Put the card on top of the remains stack on one of the 4 final stacks.\0"
377 * Misc constants, graphics and other defines
380 #include "card_back.h"
381 #include "card_deck.h"
382 #include "solitaire_suitsi.h"
384 #define CARD_GFX_WIDTH BMPWIDTH_card_back
385 #define CARD_GFX_HEIGHT BMPHEIGHT_card_back
386 #define CARD_WIDTH (BMPWIDTH_card_back+2)
387 #define CARD_HEIGHT (BMPHEIGHT_card_back+2)
392 # define SYMBOL_HEIGHT 12
393 #elif LCD_WIDTH >= 220
396 # define SYMBOL_HEIGHT 12
397 #elif LCD_WIDTH >= 160
399 # define SYMBOL_HEIGHT 11
400 #elif LCD_WIDTH >= 128
402 # define SYMBOL_HEIGHT 10
405 # define SYMBOL_HEIGHT 8
408 #define CARD_START (CARD_HEIGHT+2*MARGIN+1)
410 /* background color */
411 #ifdef HAVE_LCD_COLOR
412 # define BACKGROUND_COLOR LCD_RGBPACK(0,157,0)
413 # define FRAME_COLOR LCD_RGBPACK(23,119,218)
415 # define BACKGROUND_COLOR LCD_WHITE
416 # define FRAME_COLOR LCD_BLACK
420 #define CONFIG_FILENAME "sol.cfg"
422 #define NOT_A_CARD -1
424 /* number of cards per suit */
425 #define CARDS_PER_SUIT 13
427 /* number of suits */
430 #define NUM_CARDS ( CARDS_PER_SUIT * SUITS )
432 /* number of columns */
435 /* pseudo column numbers to be used for cursor coordinates */
436 /* columns COL_NUM to COL_NUM + SUITS - 1 correspond to the final stacks */
437 #define STACKS_COL COL_NUM
438 /* column COL_NUM + SUITS corresponds to the remains' stack */
439 #define REM_COL (STACKS_COL + SUITS)
448 bool used
: 1; /* this is what is used when dealing cards */
454 * LCD card drawing routines
457 static void draw_cursor( int x
, int y
)
459 rb
->lcd_set_drawmode( DRMODE_COMPLEMENT
);
460 rb
->lcd_fillrect( x
+1, y
+1, CARD_GFX_WIDTH
, CARD_GFX_HEIGHT
);
462 rb
->lcd_drawpixel( x
+1, y
+1 );
463 rb
->lcd_drawpixel( x
+1, y
+CARD_HEIGHT
-2 );
464 rb
->lcd_drawpixel( x
+CARD_WIDTH
-2, y
+1 );
465 rb
->lcd_drawpixel( x
+CARD_WIDTH
-2, y
+CARD_HEIGHT
-2 );
467 rb
->lcd_set_drawmode( DRMODE_SOLID
);
470 /* Draw a card's border, select it if it's selected and draw the cursor
471 * if the cursor is currently over the card */
472 static void draw_card_ext( int x
, int y
, bool selected
, bool cursor
)
475 int oldfg
= rb
->lcd_get_foreground();
477 rb
->lcd_set_foreground( LCD_BLACK
);
480 rb
->lcd_hline( x
+2, x
+CARD_WIDTH
-3, y
);
481 rb
->lcd_hline( x
+2, x
+CARD_WIDTH
-3, y
+CARD_HEIGHT
-1 );
482 rb
->lcd_vline( x
, y
+2, y
+CARD_HEIGHT
-3 );
483 rb
->lcd_vline( x
+CARD_WIDTH
-1, y
+2, y
+CARD_HEIGHT
-3 );
484 rb
->lcd_drawpixel( x
+1, y
+1 );
485 rb
->lcd_drawpixel( x
+1, y
+CARD_HEIGHT
-2 );
486 rb
->lcd_drawpixel( x
+CARD_WIDTH
-2, y
+1 );
487 rb
->lcd_drawpixel( x
+CARD_WIDTH
-2, y
+CARD_HEIGHT
-2 );
489 rb
->lcd_hline( x
+1, x
+CARD_WIDTH
-2, y
);
490 rb
->lcd_hline( x
+1, x
+CARD_WIDTH
-2, y
+CARD_HEIGHT
-1 );
491 rb
->lcd_vline( x
, y
+1, y
+CARD_HEIGHT
-2 );
492 rb
->lcd_vline( x
+CARD_WIDTH
-1, y
+1, y
+CARD_HEIGHT
-2 );
498 rb
->lcd_set_foreground( FRAME_COLOR
);
500 rb
->lcd_drawrect( x
+1, y
+1, CARD_WIDTH
-2, CARD_HEIGHT
-2 );
502 rb
->lcd_drawrect( x
+2, y
+2, CARD_WIDTH
-4, CARD_HEIGHT
-4 );
506 rb
->lcd_set_foreground( oldfg
);
515 /* Draw a card's inner graphics */
516 static void draw_card( card_t
*card
, int x
, int y
,
517 bool selected
, bool cursor
)
521 rb
->lcd_bitmap_part( card_deck
, CARD_GFX_WIDTH
* card
->num
,
522 CARD_GFX_HEIGHT
* card
->suit
, BMPWIDTH_card_deck
,
523 x
+1, y
+1, CARD_GFX_WIDTH
, CARD_GFX_HEIGHT
);
527 rb
->lcd_bitmap( card_back
, x
+1, y
+1,
528 CARD_GFX_WIDTH
, CARD_GFX_HEIGHT
);
530 draw_card_ext( x
, y
, selected
, cursor
);
533 /* Draw an empty stack */
534 static void draw_empty_stack( int s
, int x
, int y
, bool cursor
)
536 rb
->lcd_bitmap_part( solitaire_suitsi
, 0,
537 CARD_GFX_HEIGHT
* s
, BMPWIDTH_solitaire_suitsi
,
538 x
+1, y
+1, CARD_GFX_WIDTH
, CARD_GFX_HEIGHT
);
540 draw_card_ext( x
, y
, false, cursor
);
547 static void init_help(void)
552 char *para
= helptext
;
554 rb
->lcd_getstringsize(" ", &w_space
, &h
);
555 displaylines
= LCD_HEIGHT
/ h
;
556 para_len
= rb
->strlen(para
);
564 next
= rb
->strtok_r(para
, " ", &store
);
567 rb
->lcd_getstringsize(next
, &w
, NULL
);
570 if (x
+ w
> LCD_WIDTH
)
576 next
[-1] = ' '; /* re-concatenate string */
582 next
= rb
->strtok_r(NULL
, " ", &store
);
586 para
+= para_len
+ 1;
587 para_len
= rb
->strlen(para
);
592 enum help
{ HELP_QUIT
, HELP_USB
};
594 /* help for the not so intuitive interface */
595 enum help
solitaire_help( void )
599 int lastbutton
= BUTTON_NONE
;
600 bool fixed
= (displaylines
>= helplines
);
604 char *text
= helptext
;
605 int line
= fixed
? (displaylines
- helplines
) / 2 : 0;
608 rb
->lcd_clear_display();
610 for (i
= 0; i
< start
+ displaylines
; i
++)
613 rb
->lcd_puts(0, line
++, text
);
614 text
+= rb
->strlen(text
) + 1;
618 button
= rb
->button_get( true );
623 if( lastbutton
!= SOL_UP_PRE
)
626 case SOL_UP
|BUTTON_REPEAT
:
628 if (!fixed
&& start
> 0)
634 if( lastbutton
!= SOL_DOWN_PRE
)
637 case SOL_DOWN
|BUTTON_REPEAT
:
639 if (!fixed
&& start
< helplines
- displaylines
)
650 if( rb
->default_event_handler( button
) == SYS_USB_CONNECTED
)
654 if( button
!= BUTTON_NONE
)
660 * Custom menu / options
663 #define CFGFILE_VERSION 0
669 struct sol_config sol_disk
= {0};
670 struct sol_config sol
;
672 static struct configdata config
[] = {
673 { TYPE_INT
, 0, 1, &sol_disk
.draw_type
, "draw_type", NULL
, NULL
},
676 char draw_option_string
[32];
678 static void create_draw_option_string(void)
680 if (sol
.draw_type
== 0)
681 rb
->strcpy(draw_option_string
, "Draw Three Cards");
683 rb
->strcpy(draw_option_string
, "Draw One Card");
686 void solitaire_init(void);
688 /* menu return codes */
689 enum { MENU_RESUME
, MENU_SAVE_AND_QUIT
, MENU_QUIT
, MENU_USB
};
691 int solitaire_menu(bool in_game
)
697 struct menu_item items
[6];
701 items
[i
++].desc
= "Resume Game";
702 items
[i
++].desc
= "Restart Game";
706 items
[i
++].desc
= "Start Game";
707 items
[i
++].desc
= draw_option_string
;
709 items
[i
++].desc
= "Help";
710 items
[i
++].desc
= "Audio Playback";
713 items
[i
++].desc
= "Save and Quit";
715 items
[i
++].desc
= "Quit";
717 create_draw_option_string();
718 m
= menu_init(rb
, items
, i
, NULL
, NULL
, NULL
, NULL
);
721 switch (menu_show(m
))
723 case MENU_SELECTED_EXIT
:
724 result
= MENU_RESUME
;
727 case MENU_ATTACHED_USB
:
732 result
= MENU_RESUME
;
739 result
= MENU_RESUME
;
743 sol
.draw_type
= (sol
.draw_type
+ 1) % 2;
744 create_draw_option_string();
749 if (solitaire_help() == HELP_USB
)
754 playback_control(rb
, NULL
);
759 result
= MENU_SAVE_AND_QUIT
;
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
;