checkwps: Do not error out on rwps for non-remote targets.
[maemo-rb.git] / apps / plugins / solitaire.c
blobfea92526be15ca8e1e56fe32bc4ec421118b1444
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
22 #include "plugin.h"
23 #include "lib/playback_control.h"
24 #include "lib/configfile.h"
25 #include "lib/display_text.h"
26 #include "button.h"
27 #include "lcd.h"
29 #define min(a,b) (a<b?a:b)
31 /**
32 * Key definitions
35 #if CONFIG_KEYPAD == RECORDER_PAD
36 # define SOL_QUIT BUTTON_OFF
37 # define SOL_UP BUTTON_UP
38 # define SOL_DOWN BUTTON_DOWN
39 # define SOL_LEFT BUTTON_LEFT
40 # define SOL_RIGHT BUTTON_RIGHT
41 # define SOL_MOVE BUTTON_ON
42 # define SOL_DRAW BUTTON_F1
43 # define SOL_REM2CUR BUTTON_PLAY
44 # define SOL_CUR2STACK BUTTON_F2
45 # define SOL_REM2STACK BUTTON_F3
46 # define HK_MOVE "ON"
47 # define HK_DRAW "F1"
48 # define HK_REM2CUR "PLAY"
49 # define HK_CUR2STACK "F2"
50 # define HK_REM2STACK "F3"
52 #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
53 # define SOL_QUIT BUTTON_OFF
54 # define SOL_UP BUTTON_UP
55 # define SOL_DOWN BUTTON_DOWN
56 # define SOL_LEFT BUTTON_LEFT
57 # define SOL_RIGHT BUTTON_RIGHT
58 # define SOL_MOVE BUTTON_ON
59 # define SOL_DRAW BUTTON_F1
60 # define SOL_REM2CUR BUTTON_SELECT
61 # define SOL_CUR2STACK BUTTON_F2
62 # define SOL_REM2STACK BUTTON_F3
63 # define HK_MOVE "ON"
64 # define HK_DRAW "F1"
65 # define HK_REM2CUR "SELECT"
66 # define HK_CUR2STACK "F2"
67 # define HK_REM2STACK "F3"
69 #elif CONFIG_KEYPAD == ONDIO_PAD
70 # define SOL_QUIT BUTTON_OFF
71 # define SOL_UP_PRE BUTTON_UP
72 # define SOL_UP (BUTTON_UP | BUTTON_REL)
73 # define SOL_DOWN_PRE BUTTON_DOWN
74 # define SOL_DOWN (BUTTON_DOWN | BUTTON_REL)
75 # define SOL_LEFT_PRE BUTTON_LEFT
76 # define SOL_LEFT (BUTTON_LEFT | BUTTON_REL)
77 # define SOL_RIGHT_PRE BUTTON_RIGHT
78 # define SOL_RIGHT (BUTTON_RIGHT | BUTTON_REL)
79 # define SOL_MOVE_PRE BUTTON_MENU
80 # define SOL_MOVE (BUTTON_MENU | BUTTON_REL)
81 # define SOL_DRAW_PRE BUTTON_MENU
82 # define SOL_DRAW (BUTTON_MENU | BUTTON_REPEAT)
83 # define SOL_REM2CUR_PRE BUTTON_DOWN
84 # define SOL_REM2CUR (BUTTON_DOWN | BUTTON_REPEAT)
85 # define SOL_CUR2STACK_PRE BUTTON_UP
86 # define SOL_CUR2STACK (BUTTON_UP | BUTTON_REPEAT)
87 # define SOL_REM2STACK_PRE BUTTON_RIGHT
88 # define SOL_REM2STACK (BUTTON_RIGHT | BUTTON_REPEAT)
89 # define HK_MOVE "MODE"
90 # define HK_DRAW "MODE.."
91 # define HK_REM2CUR "DOWN.."
92 # define HK_CUR2STACK "UP.."
93 # define HK_REM2STACK "RIGHT.."
95 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
96 (CONFIG_KEYPAD == IRIVER_H300_PAD)
97 # define SOL_QUIT BUTTON_OFF
98 # define SOL_UP BUTTON_UP
99 # define SOL_DOWN BUTTON_DOWN
100 # define SOL_LEFT BUTTON_LEFT
101 # define SOL_RIGHT BUTTON_RIGHT
102 # define SOL_MOVE_PRE BUTTON_SELECT
103 # define SOL_MOVE (BUTTON_SELECT | BUTTON_REL)
104 # define SOL_DRAW BUTTON_MODE
105 # define SOL_REM2CUR (BUTTON_LEFT | BUTTON_ON)
106 # define SOL_CUR2STACK_PRE BUTTON_SELECT
107 # define SOL_CUR2STACK (BUTTON_SELECT | BUTTON_REPEAT)
108 # define SOL_REM2STACK (BUTTON_RIGHT | BUTTON_ON)
109 # define SOL_REM BUTTON_REC
110 # define SOL_RC_QUIT BUTTON_RC_STOP
111 # define HK_MOVE "NAVI"
112 # define HK_DRAW "A-B"
113 # define HK_REM2CUR "PLAY+LEFT"
114 # define HK_CUR2STACK "NAVI.."
115 # define HK_REM2STACK "PLAY+RIGHT"
117 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
118 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
119 # define SOL_QUIT (BUTTON_SELECT | BUTTON_MENU)
120 # define SOL_UP BUTTON_SCROLL_BACK
121 # define SOL_DOWN BUTTON_SCROLL_FWD
122 # define SOL_LEFT_PRE BUTTON_LEFT
123 # define SOL_LEFT (BUTTON_LEFT | BUTTON_REL)
124 # define SOL_RIGHT_PRE BUTTON_RIGHT
125 # define SOL_RIGHT (BUTTON_RIGHT | BUTTON_REL)
126 # define SOL_MOVE_PRE BUTTON_SELECT
127 # define SOL_MOVE (BUTTON_SELECT | BUTTON_REL)
128 # define SOL_DRAW_PRE BUTTON_MENU
129 # define SOL_DRAW (BUTTON_MENU | BUTTON_REL)
130 # define SOL_REM2CUR BUTTON_PLAY
131 # define SOL_CUR2STACK_PRE BUTTON_MENU
132 # define SOL_CUR2STACK (BUTTON_MENU | BUTTON_REPEAT)
133 # define SOL_REM2STACK_PRE BUTTON_RIGHT
134 # define SOL_REM2STACK (BUTTON_RIGHT | BUTTON_REPEAT)
135 # define HK_UD "SCROLL U/D"
136 # define HK_MOVE "SELECT"
137 # define HK_DRAW "MENU"
138 # define HK_REM2CUR "PLAY"
139 # define HK_CUR2STACK "MENU.."
140 # define HK_REM2STACK "RIGHT.."
142 #elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
143 # define SOL_QUIT BUTTON_POWER
144 # define SOL_UP BUTTON_UP
145 # define SOL_DOWN BUTTON_DOWN
146 # define SOL_LEFT BUTTON_LEFT
147 # define SOL_RIGHT BUTTON_RIGHT
148 # define SOL_MOVE_PRE BUTTON_SELECT
149 # define SOL_MOVE (BUTTON_SELECT | BUTTON_REL)
150 # define SOL_DRAW_PRE BUTTON_PLAY
151 # define SOL_DRAW (BUTTON_PLAY | BUTTON_REL)
152 # define SOL_REM2CUR_PRE BUTTON_PLAY
153 # define SOL_REM2CUR (BUTTON_PLAY | BUTTON_REPEAT)
154 # define SOL_CUR2STACK_PRE BUTTON_SELECT
155 # define SOL_CUR2STACK (BUTTON_SELECT | BUTTON_REPEAT)
156 # define SOL_REM2STACK BUTTON_REC
157 # define HK_MOVE "SELECT"
158 # define HK_DRAW "PLAY"
159 # define HK_REM2CUR "PLAY.."
160 # define HK_CUR2STACK "SELECT.."
161 # define HK_REM2STACK "REC"
163 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
164 # define SOL_QUIT BUTTON_POWER
165 # define SOL_UP BUTTON_UP
166 # define SOL_DOWN BUTTON_DOWN
167 # define SOL_LEFT BUTTON_LEFT
168 # define SOL_RIGHT BUTTON_RIGHT
169 # define SOL_MOVE_PRE BUTTON_SELECT
170 # define SOL_MOVE (BUTTON_SELECT | BUTTON_REL)
171 # define SOL_DRAW BUTTON_MENU
172 # define SOL_REM2CUR (BUTTON_LEFT | BUTTON_A)
173 # define SOL_CUR2STACK (BUTTON_SELECT | BUTTON_REPEAT)
174 # define SOL_REM2STACK (BUTTON_RIGHT | BUTTON_A)
175 # define HK_MOVE "SELECT"
176 # define HK_DRAW "MENU"
177 # define HK_REM2CUR "A+LEFT"
178 # define HK_CUR2STACK "SELECT.."
179 # define HK_REM2STACK "A+RIGHT"
181 #elif (CONFIG_KEYPAD == SANSA_E200_PAD)
182 # define SOL_QUIT BUTTON_POWER
183 # define SOL_UP BUTTON_UP
184 # define SOL_DOWN BUTTON_DOWN
185 # define SOL_LEFT BUTTON_SCROLL_BACK
186 # define SOL_RIGHT BUTTON_SCROLL_FWD
187 # define SOL_MOVE BUTTON_SELECT
188 # define SOL_DRAW BUTTON_REC
189 # define SOL_REM2CUR BUTTON_LEFT
190 # define SOL_CUR2STACK_PRE BUTTON_REC
191 # define SOL_CUR2STACK (BUTTON_REC | BUTTON_RIGHT)
192 # define SOL_REM2STACK BUTTON_RIGHT
193 # define HK_MOVE "SELECT"
194 # define HK_DRAW "REC"
195 # define HK_REM2CUR "LEFT"
196 # define HK_CUR2STACK "DOUBLE SELECT"
197 # define HK_REM2STACK "RIGHT"
199 #elif (CONFIG_KEYPAD == SANSA_FUZE_PAD)
200 # define SOL_QUIT (BUTTON_HOME|BUTTON_REPEAT)
201 # define SOL_UP BUTTON_UP
202 # define SOL_DOWN BUTTON_DOWN
203 # define SOL_LEFT BUTTON_SCROLL_BACK
204 # define SOL_RIGHT BUTTON_SCROLL_FWD
205 # define SOL_MOVE (BUTTON_SELECT|BUTTON_REL)
206 # define SOL_DRAW (BUTTON_HOME|BUTTON_REL)
207 # define SOL_REM2CUR BUTTON_LEFT
208 # define SOL_CUR2STACK_PRE (BUTTON_RIGHT | BUTTON_REPEAT)
209 # define SOL_CUR2STACK BUTTON_RIGHT
210 # define SOL_REM2STACK (BUTTON_LEFT|BUTTON_REPEAT)
211 # define SOL_REM2STACK_PRE BUTTON_LEFT
212 # define HK_MOVE "SHORT SELECT"
213 # define HK_DRAW "SHORT HOME"
214 # define HK_REM2CUR "LEFT"
215 # define HK_CUR2STACK "DOUBLE SELECT"
216 # define HK_REM2STACK "LEFT"
218 #elif (CONFIG_KEYPAD == SANSA_C200_PAD)
219 # define SOL_QUIT BUTTON_POWER
220 # define SOL_UP BUTTON_UP
221 # define SOL_DOWN BUTTON_DOWN
222 # define SOL_LEFT BUTTON_LEFT
223 # define SOL_RIGHT BUTTON_RIGHT
224 # define SOL_MOVE_PRE BUTTON_SELECT
225 # define SOL_MOVE (BUTTON_SELECT | BUTTON_REL)
226 # define SOL_DRAW BUTTON_VOL_DOWN
227 # define SOL_REM2CUR BUTTON_REC
228 # define SOL_CUR2STACK_PRE BUTTON_SELECT
229 # define SOL_CUR2STACK (BUTTON_SELECT | BUTTON_REPEAT)
230 # define SOL_REM2STACK BUTTON_VOL_UP
231 # define HK_MOVE "SELECT"
232 # define HK_DRAW "REC"
233 # define HK_REM2CUR "LEFT"
234 # define HK_CUR2STACK "DOUBLE SELECT"
235 # define HK_REM2STACK "RIGHT"
237 #elif CONFIG_KEYPAD == SANSA_CLIP_PAD
238 # define SOL_QUIT BUTTON_POWER
239 # define SOL_UP BUTTON_UP
240 # define SOL_DOWN BUTTON_DOWN
241 # define SOL_LEFT BUTTON_LEFT
242 # define SOL_RIGHT BUTTON_RIGHT
243 # define SOL_MOVE_PRE BUTTON_SELECT
244 # define SOL_MOVE (BUTTON_SELECT | BUTTON_REL)
245 # define SOL_DRAW BUTTON_HOME
246 # define SOL_REM2CUR BUTTON_VOL_DOWN
247 # define SOL_CUR2STACK_PRE BUTTON_SELECT
248 # define SOL_CUR2STACK (BUTTON_SELECT | BUTTON_REPEAT)
249 # define SOL_REM2STACK BUTTON_VOL_UP
250 # define HK_MOVE "SELECT"
251 # define HK_DRAW "HOME"
252 # define HK_REM2CUR "LEFT"
253 # define HK_CUR2STACK "DOUBLE SELECT"
254 # define HK_REM2STACK "RIGHT"
256 #elif CONFIG_KEYPAD == SANSA_M200_PAD
257 # define SOL_QUIT BUTTON_POWER
258 # define SOL_UP BUTTON_UP
259 # define SOL_DOWN BUTTON_DOWN
260 # define SOL_LEFT BUTTON_LEFT
261 # define SOL_RIGHT BUTTON_RIGHT
262 # define SOL_MOVE_PRE BUTTON_SELECT
263 # define SOL_MOVE (BUTTON_SELECT | BUTTON_REL)
264 # define SOL_DRAW (BUTTON_SELECT | BUTTON_UP)
265 # define SOL_REM2CUR BUTTON_VOL_DOWN
266 # define SOL_CUR2STACK_PRE BUTTON_SELECT
267 # define SOL_CUR2STACK (BUTTON_SELECT | BUTTON_REPEAT)
268 # define SOL_REM2STACK BUTTON_VOL_UP
269 # define HK_MOVE "SELECT"
270 # define HK_DRAW "SELECT + UP"
271 # define HK_REM2CUR "LEFT"
272 # define HK_CUR2STACK "DOUBLE SELECT"
273 # define HK_REM2STACK "RIGHT"
275 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
276 # define SOL_QUIT BUTTON_POWER
277 # define SOL_UP BUTTON_SCROLL_UP
278 # define SOL_DOWN BUTTON_SCROLL_DOWN
279 # define SOL_LEFT_PRE BUTTON_LEFT
280 # define SOL_LEFT (BUTTON_LEFT | BUTTON_REL)
281 # define SOL_RIGHT_PRE BUTTON_RIGHT
282 # define SOL_RIGHT (BUTTON_RIGHT | BUTTON_REL)
283 # define SOL_MOVE BUTTON_PLAY
284 # define SOL_DRAW_PRE BUTTON_LEFT
285 # define SOL_DRAW (BUTTON_LEFT | BUTTON_REPEAT)
286 # define SOL_REM2CUR BUTTON_FF
287 # define SOL_CUR2STACK BUTTON_REW
288 # define SOL_REM2STACK_PRE BUTTON_RIGHT
289 # define SOL_REM2STACK (BUTTON_RIGHT | BUTTON_REPEAT)
290 # define HK_MOVE "PLAY"
291 # define HK_DRAW "LEFT.."
292 # define HK_REM2CUR "FF"
293 # define HK_CUR2STACK "REW"
294 # define HK_REM2STACK "RIGHT.."
296 #elif (CONFIG_KEYPAD == GIGABEAT_S_PAD)
297 # define SOL_QUIT BUTTON_BACK
298 # define SOL_UP BUTTON_UP
299 # define SOL_DOWN BUTTON_DOWN
300 # define SOL_LEFT BUTTON_LEFT
301 # define SOL_RIGHT BUTTON_RIGHT
302 # define SOL_MOVE_PRE BUTTON_SELECT
303 # define SOL_MOVE (BUTTON_SELECT | BUTTON_REL)
304 # define SOL_DRAW BUTTON_MENU
305 # define SOL_REM2CUR (BUTTON_LEFT | BUTTON_SELECT)
306 # define SOL_CUR2STACK (BUTTON_SELECT | BUTTON_REPEAT)
307 # define SOL_REM2STACK (BUTTON_RIGHT | BUTTON_SELECT)
308 # define HK_MOVE "SELECT"
309 # define HK_DRAW "MENU"
310 # define HK_REM2CUR "SELECT+LEFT"
311 # define HK_CUR2STACK "SELECT.."
312 # define HK_REM2STACK "SELECT+RIGHT"
314 #elif (CONFIG_KEYPAD == MROBE100_PAD)
315 # define SOL_QUIT BUTTON_POWER
316 # define SOL_UP BUTTON_UP
317 # define SOL_DOWN BUTTON_DOWN
318 # define SOL_LEFT BUTTON_LEFT
319 # define SOL_RIGHT BUTTON_RIGHT
320 # define SOL_MOVE_PRE BUTTON_SELECT
321 # define SOL_MOVE (BUTTON_SELECT | BUTTON_REL)
322 # define SOL_DRAW BUTTON_MENU
323 # define SOL_REM2CUR (BUTTON_LEFT | BUTTON_DISPLAY)
324 # define SOL_CUR2STACK (BUTTON_SELECT | BUTTON_REPEAT)
325 # define SOL_REM2STACK (BUTTON_RIGHT | BUTTON_DISPLAY)
326 # define HK_MOVE "SELECT"
327 # define HK_DRAW "MENU"
328 # define HK_REM2CUR "DISPLAY+LEFT"
329 # define HK_CUR2STACK "SELECT.."
330 # define HK_REM2STACK "DISPLAY+RIGHT"
332 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
333 # define SOL_QUIT BUTTON_RC_REC
334 # define SOL_UP BUTTON_RC_VOL_UP
335 # define SOL_DOWN BUTTON_RC_VOL_DOWN
336 # define SOL_LEFT BUTTON_RC_REW
337 # define SOL_RIGHT BUTTON_RC_FF
338 # define SOL_MOVE BUTTON_RC_PLAY
339 # define SOL_DRAW_PRE BUTTON_RC_MENU
340 # define SOL_DRAW (BUTTON_RC_MENU | BUTTON_REL)
341 # define SOL_REM2CUR_PRE BUTTON_RC_MENU
342 # define SOL_REM2CUR (BUTTON_RC_MENU | BUTTON_REPEAT)
343 # define SOL_CUR2STACK_PRE BUTTON_RC_MODE
344 # define SOL_CUR2STACK (BUTTON_RC_MODE | BUTTON_REL)
345 # define SOL_REM2STACK_PRE BUTTON_RC_MODE
346 # define SOL_REM2STACK (BUTTON_RC_MODE | BUTTON_REPEAT)
347 # define HK_LR "REW/FF"
348 # define HK_UD "VOL UP/DOWN"
349 # define HK_MOVE "PLAY"
350 # define HK_DRAW "MENU"
351 # define HK_REM2CUR "MENU.."
352 # define HK_CUR2STACK "MODE"
353 # define HK_REM2STACK "MODE.."
355 #elif (CONFIG_KEYPAD == COWON_D2_PAD)
356 # define SOL_QUIT BUTTON_POWER
358 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
359 # define SOL_QUIT BUTTON_BACK
360 # define SOL_UP BUTTON_UP
361 # define SOL_DOWN BUTTON_DOWN
362 # define SOL_LEFT BUTTON_LEFT
363 # define SOL_RIGHT BUTTON_RIGHT
364 # define SOL_MOVE_PRE BUTTON_SELECT
365 # define SOL_MOVE (BUTTON_SELECT | BUTTON_REL)
366 # define SOL_DRAW BUTTON_MENU
367 # define SOL_REM2CUR (BUTTON_LEFT | BUTTON_SELECT)
368 # define SOL_CUR2STACK (BUTTON_SELECT | BUTTON_REPEAT)
369 # define SOL_REM2STACK (BUTTON_RIGHT | BUTTON_SELECT)
370 # define HK_MOVE "MIDDLE"
371 # define HK_DRAW "MENU"
372 # define HK_REM2CUR "PLAY+LEFT"
373 # define HK_CUR2STACK "PLAY.."
374 # define HK_REM2STACK "PLAY+RIGHT"
376 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
377 # define SOL_QUIT BUTTON_POWER
378 # define SOL_UP BUTTON_UP
379 # define SOL_DOWN BUTTON_DOWN
380 # define SOL_LEFT BUTTON_LEFT
381 # define SOL_RIGHT BUTTON_RIGHT
382 # define SOL_MOVE_PRE BUTTON_SELECT
383 # define SOL_MOVE (BUTTON_SELECT | BUTTON_REL)
384 # define SOL_DRAW BUTTON_MENU
385 # define SOL_REM2CUR (BUTTON_LEFT | BUTTON_VIEW)
386 # define SOL_CUR2STACK (BUTTON_SELECT | BUTTON_REPEAT)
387 # define SOL_REM2STACK (BUTTON_RIGHT | BUTTON_VIEW)
388 # define HK_MOVE "SELECT"
389 # define HK_DRAW "MENU"
390 # define HK_REM2CUR "VIEW+LEFT"
391 # define HK_CUR2STACK "SELECT.."
392 # define HK_REM2STACK "VIEW+RIGHT"
394 #elif CONFIG_KEYPAD == PHILIPS_HDD6330_PAD
395 # define SOL_QUIT BUTTON_POWER
396 # define SOL_UP BUTTON_UP
397 # define SOL_DOWN BUTTON_DOWN
398 # define SOL_LEFT BUTTON_PREV
399 # define SOL_RIGHT BUTTON_NEXT
400 # define SOL_MOVE_PRE BUTTON_PLAY
401 # define SOL_MOVE (BUTTON_PLAY | BUTTON_REL)
402 # define SOL_DRAW BUTTON_MENU
403 # define SOL_REM2CUR BUTTON_LEFT
404 # define SOL_CUR2STACK (BUTTON_PLAY | BUTTON_REPEAT)
405 # define SOL_REM2STACK BUTTON_RIGHT
406 # define HK_MOVE "PLAY"
407 # define HK_DRAW "MENU"
408 # define HK_REM2CUR "LEFT"
409 # define HK_CUR2STACK "PLAY.."
410 # define HK_REM2STACK "RIGHT"
412 #elif CONFIG_KEYPAD == PHILIPS_SA9200_PAD
413 # define SOL_QUIT BUTTON_POWER
414 # define SOL_UP BUTTON_UP
415 # define SOL_DOWN BUTTON_DOWN
416 # define SOL_LEFT BUTTON_PREV
417 # define SOL_RIGHT BUTTON_NEXT
418 # define SOL_MOVE_PRE BUTTON_PLAY
419 # define SOL_MOVE (BUTTON_PLAY | BUTTON_REL)
420 # define SOL_DRAW BUTTON_MENU
421 # define SOL_REM2CUR BUTTON_LEFT
422 # define SOL_CUR2STACK (BUTTON_PLAY | BUTTON_REPEAT)
423 # define SOL_REM2STACK BUTTON_RIGHT
424 # define HK_MOVE "PLAY"
425 # define HK_DRAW "MENU"
426 # define HK_REM2CUR "LEFT"
427 # define HK_CUR2STACK "PLAY..."
428 # define HK_REM2STACK "RIGHT"
430 #elif (CONFIG_KEYPAD == ONDAVX747_PAD) || \
431 (CONFIG_KEYPAD == ONDAVX777_PAD) || \
432 CONFIG_KEYPAD == MROBE500_PAD
433 # define SOL_QUIT BUTTON_POWER
435 #elif (CONFIG_KEYPAD == SAMSUNG_YH_PAD)
436 # define SOL_QUIT BUTTON_REC
437 # define SOL_UP BUTTON_UP
438 # define SOL_DOWN BUTTON_DOWN
439 # define SOL_LEFT_PRE BUTTON_LEFT
440 # define SOL_LEFT (BUTTON_LEFT | BUTTON_REW)
441 # define SOL_RIGHT_PRE BUTTON_RIGHT
442 # define SOL_RIGHT (BUTTON_RIGHT | BUTTON_REW)
443 # define SOL_MOVE BUTTON_PLAY
444 # define SOL_DRAW_PRE (BUTTON_PLAY | BUTTON_RIGHT)
445 # define SOL_DRAW (BUTTON_PLAY | BUTTON_LEFT)
446 # define SOL_REM2CUR BUTTON_FFWD
447 # define SOL_CUR2STACK BUTTON_REW
448 # define SOL_REM2STACK_PRE (BUTTON_FFWD | BUTTON_RIGHT)
449 # define SOL_REM2STACK (BUTTON_FFWD | BUTTON_LEFT)
450 # define HK_MOVE "PLAY"
451 # define HK_DRAW "REW.."
452 # define HK_REM2CUR "FFWD"
453 # define HK_CUR2STACK "REW"
454 # define HK_REM2STACK "FFWD.."
456 #elif CONFIG_KEYPAD == PBELL_VIBE500_PAD
457 # define SOL_QUIT BUTTON_REC
458 # define SOL_UP BUTTON_UP
459 # define SOL_DOWN BUTTON_DOWN
460 # define SOL_LEFT BUTTON_PREV
461 # define SOL_RIGHT BUTTON_NEXT
462 # define SOL_MOVE_PRE BUTTON_OK
463 # define SOL_MOVE (BUTTON_OK | BUTTON_REL)
464 # define SOL_DRAW BUTTON_MENU
465 # define SOL_REM2CUR BUTTON_CANCEL
466 # define SOL_CUR2STACK BUTTON_PLAY
467 # define SOL_REM2STACK (BUTTON_PLAY | BUTTON_REPEAT)
468 # define HK_MOVE "OK"
469 # define HK_DRAW "MENU"
470 # define HK_REM2CUR "CANCEL"
471 # define HK_CUR2STACK "PLAY"
472 # define HK_REM2STACK "PLAY..."
474 #elif CONFIG_KEYPAD == MPIO_HD200_PAD
475 # define SOL_QUIT (BUTTON_REC | BUTTON_PLAY)
476 # define SOL_UP BUTTON_REW
477 # define SOL_DOWN BUTTON_FF
478 # define SOL_LEFT BUTTON_VOL_DOWN
479 # define SOL_RIGHT BUTTON_VOL_UP
480 # define SOL_MOVE_PRE BUTTON_FUNC
481 # define SOL_MOVE (BUTTON_FUNC | BUTTON_REL)
482 # define SOL_DRAW BUTTON_REC
483 # define SOL_REM2CUR (BUTTON_REC | BUTTON_REPEAT)
484 # define SOL_CUR2STACK BUTTON_PLAY
485 # define SOL_REM2STACK (BUTTON_PLAY | BUTTON_REPEAT)
486 # define HK_MOVE "FUNC"
487 # define HK_DRAW "REC"
488 # define HK_REM2CUR "REC.."
489 # define HK_CUR2STACK "PLAY"
490 # define HK_REM2STACK "PLAY...."
492 #elif CONFIG_KEYPAD == MPIO_HD300_PAD
493 # define SOL_QUIT (BUTTON_MENU | BUTTON_REPEAT)
494 # define SOL_UP BUTTON_UP
495 # define SOL_DOWN BUTTON_DOWN
496 # define SOL_LEFT BUTTON_REW
497 # define SOL_RIGHT BUTTON_FF
498 # define SOL_MOVE_PRE BUTTON_ENTER
499 # define SOL_MOVE (BUTTON_ENTER | BUTTON_REL)
500 # define SOL_DRAW BUTTON_MENU
501 # define SOL_REM2CUR (BUTTON_PLAY | BUTTON_REL)
502 # define SOL_CUR2STACK BUTTON_REC
503 # define SOL_REM2STACK (BUTTON_PLAY | BUTTON_REPEAT)
504 # define HK_MOVE "ENTER"
505 # define HK_DRAW "MENU"
506 # define HK_REM2CUR "PLAY"
507 # define HK_CUR2STACK "ENTER..."
508 # define HK_REM2STACK "PLAY...."
510 #elif CONFIG_KEYPAD == SANSA_FUZEPLUS_PAD
511 # define SOL_QUIT BUTTON_POWER
512 # define SOL_UP BUTTON_UP
513 # define SOL_DOWN BUTTON_DOWN
514 # define SOL_LEFT BUTTON_LEFT
515 # define SOL_RIGHT BUTTON_RIGHT
516 # define SOL_MOVE BUTTON_SELECT
517 # define SOL_DRAW BUTTON_BACK
518 # define SOL_REM2CUR BUTTON_BOTTOMLEFT
519 # define SOL_CUR2STACK BUTTON_PLAYPAUSE|BUTTON_REL
520 # define SOL_REM2STACK BUTTON_PLAYPAUSE|BUTTON_REPEAT
521 # define HK_MOVE "SELECT"
522 # define HK_DRAW "BACK"
523 # define HK_REM2CUR "BOTTOM-LEFT"
524 # define HK_CUR2STACK "PLAY-PAUSE"
525 # define HK_REM2STACK "BOTTOM-RIGHT"
527 #elif (CONFIG_KEYPAD == SANSA_CONNECT_PAD)
528 # define SOL_QUIT BUTTON_POWER
529 # define SOL_UP BUTTON_UP
530 # define SOL_DOWN BUTTON_DOWN
531 # define SOL_LEFT BUTTON_SCROLL_BACK
532 # define SOL_RIGHT BUTTON_SCROLL_FWD
533 # define SOL_MOVE BUTTON_SELECT
534 # define SOL_DRAW BUTTON_VOL_UP
535 # define SOL_REM2CUR BUTTON_LEFT
536 # define SOL_CUR2STACK_PRE BUTTON_VOL_DOWN
537 # define SOL_CUR2STACK BUTTON_NEXT
538 # define SOL_REM2STACK BUTTON_PREV
539 # define HK_MOVE "SELECT"
540 # define HK_DRAW "Vol+"
541 # define HK_REM2CUR "LEFT"
542 # define HK_CUR2STACK "NEXT"
543 # define HK_REM2STACK "PREV"
545 #elif (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
546 # define SOL_QUIT BUTTON_BACK
547 # define SOL_UP BUTTON_UP
548 # define SOL_DOWN BUTTON_DOWN
549 # define SOL_LEFT BUTTON_LEFT
550 # define SOL_RIGHT BUTTON_RIGHT
551 # define SOL_MOVE_PRE BUTTON_SELECT
552 # define SOL_MOVE (BUTTON_SELECT | BUTTON_REL)
553 # define SOL_DRAW BUTTON_MENU
554 # define SOL_REM2CUR (BUTTON_USER | BUTTON_REPEAT)
555 # define SOL_CUR2STACK (BUTTON_SELECT | BUTTON_REPEAT)
556 # define SOL_REM2STACK BUTTON_POWER
557 # define HK_MOVE "Select"
558 # define HK_DRAW "Menu"
559 # define HK_REM2CUR "Long User"
560 # define HK_CUR2STACK "Long Select.."
561 # define HK_REM2STACK "Power"
563 #elif (CONFIG_KEYPAD == HM60X_PAD)
564 # define SOL_QUIT BUTTON_POWER
565 # define SOL_UP BUTTON_UP
566 # define SOL_DOWN BUTTON_DOWN
567 # define SOL_LEFT BUTTON_LEFT
568 # define SOL_RIGHT BUTTON_RIGHT
569 # define SOL_MOVE_PRE BUTTON_SELECT
570 # define SOL_MOVE (BUTTON_POWER | BUTTON_SELECT)
571 # define SOL_DRAW (BUTTON_POWER | BUTTON_UP)
572 # define SOL_REM2CUR (BUTTON_POWER | BUTTON_DOWN)
573 # define SOL_CUR2STACK (BUTTON_POWER | BUTTON_LEFT)
574 # define SOL_REM2STACK (BUTTON_POWER | BUTTON_RIGHT)
575 # define HK_MOVE "SELECT + POWER"
576 # define HK_DRAW "UP + POWER"
577 # define HK_REM2CUR "DOWN + POWER"
578 # define HK_CUR2STACK "LEFT + POWER"
579 # define HK_REM2STACK "RIGHT + POWER"
581 #elif (CONFIG_KEYPAD == HM801_PAD)
582 # define SOL_QUIT BUTTON_POWER
583 # define SOL_UP BUTTON_UP
584 # define SOL_DOWN BUTTON_DOWN
585 # define SOL_LEFT BUTTON_LEFT
586 # define SOL_RIGHT BUTTON_RIGHT
587 # define SOL_MOVE_PRE BUTTON_PREV
588 # define SOL_MOVE BUTTON_NEXT
589 # define SOL_DRAW BUTTON_PLAY
590 # define SOL_REM2CUR BUTTON_SELECT
591 # define SOL_CUR2STACK (BUTTON_POWER | BUTTON_LEFT)
592 # define SOL_REM2STACK (BUTTON_POWER | BUTTON_RIGHT)
593 # define HK_MOVE "PREV"
594 # define HK_DRAW "PLAY"
595 # define HK_REM2CUR "SELECT"
596 # define HK_CUR2STACK "POWER + LEFT"
597 # define HK_REM2STACK "POWER + RIGHT"
599 #else
600 #error No keymap defined!
601 #endif
603 #ifdef HAVE_TOUCHSCREEN
604 //#ifndef SOL_QUIT
605 //# define SOL_QUIT BUTTON_TOPLEFT
606 //endif
607 #ifndef SOL_UP
608 # define SOL_UP BUTTON_TOPMIDDLE
609 #endif
610 #ifndef SOL_DOWN
611 # define SOL_DOWN BUTTON_BOTTOMMIDDLE
612 #endif
613 #ifndef SOL_LEFT
614 # define SOL_LEFT BUTTON_MIDLEFT
615 #endif
616 #ifndef SOL_RIGHT
617 # define SOL_RIGHT BUTTON_MIDRIGHT
618 #endif
619 #ifndef SOL_MOVE
620 # define SOL_MOVE BUTTON_CENTER
621 # define HK_MOVE "CENTRE"
622 #endif
623 #ifndef SOL_DRAW
624 # define SOL_DRAW BUTTON_TOPLEFT
625 # define HK_DRAW "TOPLEFT"
626 #endif
627 #ifndef SOL_REM2CUR
628 # define SOL_REM2CUR BUTTON_TOPRIGHT
629 # define HK_REM2CUR "TOPRIGHT"
630 #endif
631 #ifndef SOL_CUR2STACK
632 # define SOL_CUR2STACK BUTTON_BOTTOMLEFT
633 # define HK_CUR2STACK "BOTTOMLEFT"
634 #endif
635 #ifndef SOL_REM2STACK
636 # define SOL_REM2STACK BUTTON_BOTTOMRIGHT
637 # define HK_REM2STACK "BOTTOMRIGHT"
638 #endif
640 #endif
642 #ifndef HK_LR
643 # define HK_LR "LEFT/RIGHT"
644 #endif
645 #ifndef HK_UD
646 # define HK_UD "UP/DOWN"
647 #endif
650 * Misc constants, graphics and other defines
653 #include "pluginbitmaps/card_back.h"
654 #include "pluginbitmaps/card_deck.h"
655 #include "pluginbitmaps/solitaire_suitsi.h"
657 #define CARD_GFX_WIDTH BMPWIDTH_card_back
658 #define CARD_GFX_HEIGHT BMPHEIGHT_card_back
659 #define CARD_WIDTH (BMPWIDTH_card_back+2)
660 #define CARD_HEIGHT (BMPHEIGHT_card_back+2)
662 #if LCD_WIDTH >= 640
663 # define MARGIN 4
664 # define LARGE_CARD
665 # define SYMBOL_HEIGHT 24
667 #elif LCD_WIDTH >= 320
668 # define MARGIN 4
669 # define LARGE_CARD
670 # define SYMBOL_HEIGHT 12
671 #elif LCD_WIDTH >= 220
672 # define MARGIN 3
673 # define LARGE_CARD
674 # define SYMBOL_HEIGHT 12
675 #elif LCD_WIDTH >= 160
676 # define MARGIN 2
677 # define SYMBOL_HEIGHT 11
678 #elif LCD_WIDTH >= 128
679 # define MARGIN 1
680 # define SYMBOL_HEIGHT 10
681 #else
682 # define MARGIN 0
683 # define SYMBOL_HEIGHT 8
684 #endif
686 #define CARD_START (CARD_HEIGHT+2*MARGIN+1)
688 /* background color */
689 #ifdef HAVE_LCD_COLOR
690 # define BACKGROUND_COLOR LCD_RGBPACK(0,157,0)
691 # define FRAME_COLOR LCD_RGBPACK(23,119,218)
692 #elif LCD_DEPTH > 1
693 # define BACKGROUND_COLOR LCD_WHITE
694 # define FRAME_COLOR LCD_BLACK
695 #endif
698 #define CONFIG_FILENAME "sol.cfg"
700 #define NOT_A_CARD -1
702 /* number of cards per suit */
703 #define CARDS_PER_SUIT 13
705 /* number of suits */
706 #define SUITS 4
708 #define NUM_CARDS ( CARDS_PER_SUIT * SUITS )
710 /* number of columns */
711 #define COL_NUM 7
713 /* pseudo column numbers to be used for cursor coordinates */
714 /* columns COL_NUM to COL_NUM + SUITS - 1 correspond to the final stacks */
715 #define STACKS_COL COL_NUM
716 /* column COL_NUM + SUITS corresponds to the remains' stack */
717 #define REM_COL (STACKS_COL + SUITS)
719 #define NOT_A_COL -1
721 #if defined(SOL_LEFT_PRE) || defined(SOL_RIGHT_PRE) || \
722 defined(SOL_DOWN_PRE) || defined(SOL_UP_PRE) || \
723 defined(SOL_CUR2STACK_PRE) || defined(SOL_MOVE_PRE) || \
724 defined(SOL_REM2CUR_PRE) || defined(SOL_REM2STACK_PRE) || \
725 defined(SOL_DRAW_PRE)
726 # define NEED_LASTBUTTON_VAR
727 #endif
729 typedef struct
731 signed char suit;
732 signed char num;
733 bool known : 1;
734 bool used : 1; /* this is what is used when dealing cards */
735 signed char next;
736 } card_t;
740 * LCD card drawing routines
743 static void draw_cursor( int x, int y )
745 rb->lcd_set_drawmode( DRMODE_COMPLEMENT );
746 rb->lcd_fillrect( x+1, y+1, CARD_GFX_WIDTH, CARD_GFX_HEIGHT );
747 #ifdef LARGE_CARD
748 rb->lcd_drawpixel( x+1, y+1 );
749 rb->lcd_drawpixel( x+1, y+CARD_HEIGHT-2 );
750 rb->lcd_drawpixel( x+CARD_WIDTH-2, y+1 );
751 rb->lcd_drawpixel( x+CARD_WIDTH-2, y+CARD_HEIGHT-2 );
752 #endif
753 rb->lcd_set_drawmode( DRMODE_SOLID );
756 /* Draw a card's border, select it if it's selected and draw the cursor
757 * if the cursor is currently over the card */
758 static void draw_card_ext( int x, int y, bool selected, bool cursor )
760 #if LCD_DEPTH > 1
761 int oldfg = rb->lcd_get_foreground();
763 rb->lcd_set_foreground( LCD_BLACK );
764 #endif
765 #ifdef LARGE_CARD
766 rb->lcd_hline( x+2, x+CARD_WIDTH-3, y );
767 rb->lcd_hline( x+2, x+CARD_WIDTH-3, y+CARD_HEIGHT-1 );
768 rb->lcd_vline( x, y+2, y+CARD_HEIGHT-3 );
769 rb->lcd_vline( x+CARD_WIDTH-1, y+2, y+CARD_HEIGHT-3 );
770 rb->lcd_drawpixel( x+1, y+1 );
771 rb->lcd_drawpixel( x+1, y+CARD_HEIGHT-2 );
772 rb->lcd_drawpixel( x+CARD_WIDTH-2, y+1 );
773 rb->lcd_drawpixel( x+CARD_WIDTH-2, y+CARD_HEIGHT-2 );
774 #else
775 rb->lcd_hline( x+1, x+CARD_WIDTH-2, y );
776 rb->lcd_hline( x+1, x+CARD_WIDTH-2, y+CARD_HEIGHT-1 );
777 rb->lcd_vline( x, y+1, y+CARD_HEIGHT-2 );
778 rb->lcd_vline( x+CARD_WIDTH-1, y+1, y+CARD_HEIGHT-2 );
779 #endif
781 if( selected )
783 #if LCD_DEPTH > 1
784 rb->lcd_set_foreground( FRAME_COLOR );
785 #endif
786 rb->lcd_drawrect( x+1, y+1, CARD_WIDTH-2, CARD_HEIGHT-2 );
787 #ifdef LARGE_CARD
788 rb->lcd_drawrect( x+2, y+2, CARD_WIDTH-4, CARD_HEIGHT-4 );
789 #endif
791 #if LCD_DEPTH > 1
792 rb->lcd_set_foreground( oldfg );
793 #endif
795 if( cursor )
797 draw_cursor( x, y );
801 /* Draw a card's inner graphics */
802 static void draw_card( card_t *card, int x, int y,
803 bool selected, bool cursor )
805 if( card->known )
807 rb->lcd_bitmap_part( card_deck, CARD_GFX_WIDTH * card->num,
808 CARD_GFX_HEIGHT * card->suit,
809 STRIDE(SCREEN_MAIN,
810 BMPWIDTH_card_deck, BMPHEIGHT_card_deck),
811 x+1, y+1, CARD_GFX_WIDTH, CARD_GFX_HEIGHT );
813 else
815 rb->lcd_bitmap( card_back, x+1, y+1,
816 CARD_GFX_WIDTH, CARD_GFX_HEIGHT );
818 draw_card_ext( x, y, selected, cursor );
821 /* Draw an empty stack */
822 static void draw_empty_stack( int s, int x, int y, bool cursor )
824 rb->lcd_bitmap_part( solitaire_suitsi, 0,
825 CARD_GFX_HEIGHT * s,
826 STRIDE( SCREEN_MAIN,
827 BMPWIDTH_solitaire_suitsi, BMPHEIGHT_solitaire_suitsi),
828 x+1, y+1, CARD_GFX_WIDTH, CARD_GFX_HEIGHT );
830 draw_card_ext( x, y, false, cursor );
833 /* Help */
834 static bool solitaire_help( void )
836 static char* help_text[] = {
837 "Solitaire", "", "Controls", "",
838 HK_LR ":", "Move", "the", "cursor", "to", "the",
839 "previous/", "next", "column.", "",
840 HK_UD ":", "Move", "the", "cursor", "up/", "down", "in", "the",
841 "column.", "",
842 HK_MOVE ":", "Select", "cards,", "move", "cards...", "",
843 HK_DRAW ":", "Deselect", "a", "card", "if", "it", "was", "selected.",
844 "Else", "draw", "new", "card(s)", "from", "the", "remains",
845 "stack.", "", "",
846 "Shortcuts", "",
847 HK_REM2CUR ":", "Put", "the", "card", "on", "top", "of", "the",
848 "remains", "stack", "on", "top", "of", "the", "cursor.", "",
849 HK_CUR2STACK ":", "Put", "the", "card", "under", "the", "cursor",
850 "on", "one", "of", "the", "4", "final", "stacks.", "",
851 HK_REM2STACK ":", "Put", "the", "card", "on", "top", "of", "the",
852 "remains", "stack", "on", "one", "of", "the", "4", "final",
853 "stacks."
855 static struct style_text formation[]={
856 { 0, TEXT_CENTER|TEXT_UNDERLINE },
857 { 2, C_RED },
858 { 48, C_RED },
859 LAST_STYLE_ITEM
861 if (display_text(ARRAYLEN(help_text), help_text, formation, NULL, true))
862 return true;
863 return false;
867 * Custom menu / options
870 #define CFGFILE_VERSION 0
872 struct sol_config {
873 int draw_type;
876 struct sol_config sol_disk = {0};
877 struct sol_config sol;
879 static struct configdata config[] = {
880 { TYPE_INT, 0, 1, { .int_p = &sol_disk.draw_type }, "draw_type", NULL }
883 static const struct opt_items drawcards[2] = {
884 { "Draw Three Cards", -1 },
885 { "Draw One Card", -1 },
888 void solitaire_init(void);
890 /* menu return codes */
891 enum { MENU_RESUME, MENU_SAVE_AND_QUIT, MENU_QUIT, MENU_USB };
893 static bool _ingame;
894 static int solitaire_menu_cb(int action, const struct menu_item_ex *this_item)
896 int i = (intptr_t)this_item;
897 if( action == ACTION_REQUEST_MENUITEM )
899 if((!_ingame && (i==0 || i==5)) || ( _ingame && i==2 ))
900 return ACTION_EXIT_MENUITEM;
902 return action;
905 static int solitaire_menu(bool in_game)
907 int selected = 0;
908 int result = -1;
910 MENUITEM_STRINGLIST(menu, "Solitaire Menu", solitaire_menu_cb,
911 "Resume Game", "Start New Game",
912 "Draw Cards Option",
913 "Help", "Playback Control",
914 "Save and Quit", "Quit");
915 _ingame = in_game;
917 while (result < 0)
919 switch (rb->do_menu(&menu, &selected, NULL, false))
921 default:
922 result = MENU_RESUME;
923 break;
925 case MENU_ATTACHED_USB:
926 result = MENU_USB;
927 break;
929 case 0:
930 result = MENU_RESUME;
931 break;
933 case 1:
934 solitaire_init();
935 result = MENU_RESUME;
936 break;
938 case 2:
939 if (rb->set_option("Draw Cards Option", &sol.draw_type,
940 INT, drawcards, 2, NULL))
941 result = MENU_USB;
942 break;
944 case 3:
945 if (solitaire_help())
946 result = MENU_USB;
947 break;
949 case 4:
950 playback_control(NULL);
951 break;
953 case 5:
954 result = MENU_SAVE_AND_QUIT;
955 break;
957 case 6:
958 result = MENU_QUIT;
959 break;
962 return result;
966 * Global variables
969 /* player's cursor */
970 int cur_card;
971 /* player's cursor column num */
972 int cur_col;
974 /* selected card */
975 int sel_card;
977 /* the deck */
978 card_t deck[ NUM_CARDS ];
980 /* the remaining cards */
981 /* first card of the remains' stack */
982 int rem;
983 /* upper visible card from the remains' stack */
984 int cur_rem;
985 /* number of cards drawn from the remains stack - 1 */
986 int count_rem;
987 /* number of cards per draw of the remains' stack */
988 int cards_per_draw;
990 /* the 7 game columns */
991 int cols[COL_NUM];
992 /* the 4 final stacks */
993 int stacks[SUITS];
996 * Card handling routines
999 static int next_random_card( card_t *deck )
1001 int i,r;
1003 r = rb->rand()%(NUM_CARDS)+1;
1004 i = 0;
1006 while( r>0 )
1008 i = (i + 1)%(NUM_CARDS);
1009 if( !deck[i].used ) r--;
1012 deck[i].used = true;
1014 return i;
1018 /* initialize the game */
1019 void solitaire_init( void )
1022 int c;
1023 int i, j;
1025 /* number of cards that are drawn on the remains' stack (by pressing F2) */
1026 if( sol.draw_type == 0 )
1028 cards_per_draw = 3;
1030 else
1032 cards_per_draw = 1;
1035 /* init deck */
1036 for( i=0; i<SUITS; i++ )
1038 for( j=0; j<CARDS_PER_SUIT; j++ )
1040 #define card deck[i*CARDS_PER_SUIT+j]
1041 card.suit = i;
1042 card.num = j;
1043 card.known = true;
1044 card.used = false;
1045 card.next = NOT_A_CARD;
1046 #undef card
1050 /* deal the cards ... */
1051 /* ... in the columns */
1052 for( i=0; i<COL_NUM; i++ )
1054 c = NOT_A_CARD;
1055 for( j=0; j<=i; j++ )
1057 if( c == NOT_A_CARD )
1059 cols[i] = next_random_card( deck );
1060 c = cols[i];
1062 else
1064 deck[c].next = next_random_card( deck );
1065 c = deck[c].next;
1067 if( j < i )
1068 deck[c].known = false;
1072 /* ... shuffle what's left of the deck */
1073 rem = next_random_card(deck);
1074 c = rem;
1076 for( i=1; i < NUM_CARDS - COL_NUM * (COL_NUM + 1)/2; i++ )
1078 deck[c].next = next_random_card( deck );
1079 c = deck[c].next;
1082 /* we now finished dealing the cards. The game can start ! (at last) */
1084 /* init the stack */
1085 for( i = 0; i<SUITS; i++ )
1087 stacks[i] = NOT_A_CARD;
1090 /* the cursor starts on upper left card */
1091 cur_card = cols[0];
1092 cur_col = 0;
1094 /* no card is selected */
1095 sel_card = NOT_A_CARD;
1097 /* init the remainder */
1098 cur_rem = NOT_A_CARD;
1100 count_rem = -1;
1103 /* find the column number in which 'card' can be found */
1104 static int find_card_col( int card )
1106 int i;
1107 int c;
1109 if( card == NOT_A_CARD ) return NOT_A_COL;
1111 for( i=0; i<COL_NUM; i++ )
1113 c = cols[i];
1114 while( c != NOT_A_CARD )
1116 if( c == card ) return i;
1117 c = deck[c].next;
1121 for( i=0; i<SUITS; i++ )
1123 c = stacks[i];
1124 while( c != NOT_A_CARD )
1126 if( c == card ) return STACKS_COL + i;
1127 c = deck[c].next;
1131 return REM_COL;
1134 /* find the card preceding 'card' */
1135 /* if it doesn't exist, return NOT_A_CARD */
1136 static int find_prev_card( int card ){
1137 int i;
1139 for( i=0; i < NUM_CARDS; i++ )
1141 if( deck[i].next == card ) return i;
1144 return NOT_A_CARD;
1147 /* find the last card of a given column */
1148 static int find_last_card( int col )
1150 int c;
1152 if( col < COL_NUM )
1154 c = cols[col];
1156 else if( col < REM_COL )
1158 c = stacks[col - STACKS_COL];
1160 else
1162 c = cur_rem;
1165 if(c == NOT_A_CARD)
1166 return c;
1167 else
1169 while(deck[c].next != NOT_A_CARD)
1170 c = deck[c].next;
1171 return c;
1175 enum move { MOVE_OK, MOVE_NOT_OK };
1177 static enum move move_card( int dest_col, int src_card )
1179 /* the column on which to take src_card */
1180 int src_col;
1182 /* the last card of dest_col */
1183 int dest_card;
1185 /* the card under src_card */
1186 int src_card_prev;
1188 /* you can't move no card (at least, it doesn't have any consequence) */
1189 if( src_card == NOT_A_CARD ) return MOVE_NOT_OK;
1190 /* you can't put a card back on the remains' stack */
1191 if( dest_col == REM_COL ) return MOVE_NOT_OK;
1192 /* you can't move an unknown card */
1193 if( !deck[src_card].known ) return MOVE_NOT_OK;
1195 src_col = find_card_col( src_card );
1196 dest_card = find_last_card( dest_col );
1197 src_card_prev = find_prev_card( src_card );
1199 /* you can't move more than one card at a time from the final stack */
1200 /* to the rest of the game */
1201 if( src_col >= COL_NUM && src_col < REM_COL
1202 && deck[src_card].next != NOT_A_CARD )
1204 return MOVE_NOT_OK;
1207 /* if we (that means dest) are on one of the 7 columns ... */
1208 if( dest_col < COL_NUM )
1210 /* ... check is we are on an empty color and that the src is a king */
1211 if( dest_card == NOT_A_CARD
1212 && deck[src_card].num == CARDS_PER_SUIT - 1 )
1214 /* this is a winning combination */
1215 cols[dest_col] = src_card;
1217 /* ... or check if the cards follow one another and have
1218 * different colorsuit */
1219 else if(( deck[dest_card].suit + deck[src_card].suit)%2==1
1220 && deck[dest_card].num == deck[src_card].num + 1 )
1222 /* this is a winning combination */
1223 deck[dest_card].next = src_card;
1225 /* ... or, humpf, well that's not good news */
1226 else
1228 /* this is not a winning combination */
1229 return MOVE_NOT_OK;
1232 /* if we are on one of the 4 final stacks ... */
1233 else if( dest_col < REM_COL )
1235 /* ... check if we are on an empty stack... */
1236 if( dest_card == NOT_A_CARD )
1238 /* ... and the src is an ace and this is the correct final stack */
1239 if( deck[src_card].num == 0
1240 && deck[src_card].suit == dest_col - STACKS_COL )
1242 /* this is a winning combination */
1243 stacks[dest_col - STACKS_COL] = src_card;
1245 else
1247 /* this is not a winning combination */
1248 return MOVE_NOT_OK;
1251 else /* non-empty stack */
1253 /* ...check if the cards follow one another, have the same suit and
1254 * {that src has no .next element or is from the remains' stack} */
1255 if( deck[dest_card].suit == deck[src_card].suit
1256 && deck[dest_card].num + 1 == deck[src_card].num
1257 && (deck[src_card].next == NOT_A_CARD || src_col == REM_COL) )
1259 /* this is a winning combination */
1260 deck[dest_card].next = src_card;
1262 /* ... or, well that's not good news */
1263 else
1265 /* this is not a winning combination */
1266 return MOVE_NOT_OK;
1270 /* if we are on the remains' stack */
1271 else
1273 /* you can't move a card back to the remains' stack */
1274 return MOVE_NOT_OK;
1277 /* if the src card is from the remains' stack, we don't want to take
1278 * the following cards */
1279 if( src_col == REM_COL )
1281 /* if src card is the first card from the stack */
1282 if( src_card_prev == NOT_A_CARD )
1284 rem = deck[src_card].next;
1286 /* if src card is not the first card from the stack */
1287 else
1289 deck[src_card_prev].next = deck[src_card].next;
1291 deck[src_card].next = NOT_A_CARD;
1292 cur_rem = src_card_prev;
1293 count_rem--;
1295 /* if the src card is from somewhere else, just take everything */
1296 else
1298 if( src_card_prev == NOT_A_CARD )
1300 if( src_col < COL_NUM )
1302 cols[src_col] = NOT_A_CARD;
1304 else
1306 stacks[src_col - STACKS_COL] = NOT_A_CARD;
1309 else
1311 deck[src_card_prev].next = NOT_A_CARD;
1312 deck[src_card_prev].known = true;
1315 sel_card = NOT_A_CARD;
1316 /* tada ! */
1317 return MOVE_OK;
1320 enum { SOLITAIRE_WIN, SOLITAIRE_SAVE_AND_QUIT, SOLITAIRE_QUIT, SOLITAIRE_USB };
1323 * Bouncing cards at the end of the game
1326 #define BC_ACCEL ((1<<16)*LCD_HEIGHT/128)
1327 #define BC_MYSPEED (6*BC_ACCEL)
1328 #define BC_MXSPEED (6*LCD_HEIGHT/128)
1330 static int bouncing_cards( void )
1332 int i, j, x, vx, y, fp_y, fp_vy, button;
1334 /* flush the button queue */
1335 while( ( button = rb->button_get( false ) ) != BUTTON_NONE )
1337 if( rb->default_event_handler( button ) == SYS_USB_CONNECTED )
1338 return SOLITAIRE_USB;
1341 /* fun stuff :) */
1342 for( i = CARDS_PER_SUIT-1; i>=0; i-- )
1344 for( j = 0; j < SUITS; j++ )
1346 x = LCD_WIDTH-(CARD_WIDTH*4+4+MARGIN)+CARD_WIDTH*j+j+1;
1347 fp_y = MARGIN<<16;
1349 #if LCD_WIDTH > 200
1350 vx = rb->rand() % (4*BC_MXSPEED/3-2) - BC_MXSPEED;
1351 if( vx >= -1 )
1352 vx += 3;
1353 #else
1354 vx = rb->rand() % (4*BC_MXSPEED/3) - BC_MXSPEED;
1355 if( vx >= 0 )
1356 vx++;
1357 #endif
1359 fp_vy = -rb->rand() % BC_MYSPEED;
1361 while( x < LCD_WIDTH && x + CARD_WIDTH > 0 )
1363 fp_vy += BC_ACCEL;
1364 x += vx;
1365 fp_y += fp_vy;
1366 if( fp_y >= (LCD_HEIGHT-CARD_HEIGHT) << 16 )
1368 fp_vy = -fp_vy*4/5;
1369 fp_y = (LCD_HEIGHT-CARD_HEIGHT) << 16;
1371 y = fp_y >> 16;
1372 draw_card( &deck[j*CARDS_PER_SUIT+i], x, y,
1373 false, false );
1374 rb->lcd_update_rect( x<0?0:x, y<0?0:y,
1375 CARD_WIDTH, CARD_HEIGHT );
1377 button = rb->button_get_w_tmo( 2 );
1378 if( rb->default_event_handler( button ) == SYS_USB_CONNECTED )
1379 return SOLITAIRE_USB;
1380 if( button == SOL_QUIT || button == SOL_MOVE )
1381 return SOLITAIRE_WIN;
1385 return SOLITAIRE_WIN;
1389 * Game save/load routines
1391 static void get_save_filename( char *buf )
1393 #ifdef APPLICATION
1394 rb->snprintf(buf, sizeof(buf), PLUGIN_DATA_DIR "/sol.save");
1395 #else
1396 char *s;
1397 rb->strcpy( buf, rb->plugin_get_current_filename() );
1398 s = rb->strrchr( buf, '/' ) + 1;
1399 *s = '\0';
1400 rb->strcat( s, "sol.save" );
1401 #endif
1404 static int open_save_file( int flags )
1406 char buf[MAX_PATH];
1407 get_save_filename( buf );
1408 return rb->open( buf, flags, 0666);
1411 static void delete_save_file( void )
1413 char buf[MAX_PATH];
1414 get_save_filename( buf );
1415 rb->remove( buf );
1418 #ifdef write
1419 # undef write
1420 #endif
1421 static int save_write( int fd, const void *buf, size_t count, int *checksum )
1423 size_t i;
1424 if( rb->write( fd, buf, count ) < (ssize_t)count )
1425 return 1;
1426 for( i = 0; i < count; i++ )
1427 *checksum += (int)(((const char *)buf)[i]);
1428 return 0;
1431 #ifdef read
1432 # undef read
1433 #endif
1434 static int save_read( int fd, void *buf, size_t count, int *checksum )
1436 size_t i;
1437 if( rb->read( fd, buf, count ) < (ssize_t)count )
1438 return 1;
1439 for( i = 0; i < count; i++ )
1440 *checksum -= (int)(((const char *)buf)[i]);
1441 return 0;
1444 static int save_game( void )
1446 int fd = open_save_file( O_CREAT|O_WRONLY|O_TRUNC );
1447 int checksum = 42;
1448 if( fd < 0 )
1449 return -1;
1450 if( save_write( fd, &cur_card, sizeof( int ), &checksum )
1451 || save_write( fd, &cur_col, sizeof( int ), &checksum )
1452 || save_write( fd, &sel_card, sizeof( int ), &checksum )
1453 || save_write( fd, deck, NUM_CARDS * sizeof( card_t ), &checksum )
1454 || save_write( fd, &rem, sizeof( int ), &checksum )
1455 || save_write( fd, &cur_rem, sizeof( int ), &checksum )
1456 || save_write( fd, &count_rem, sizeof( int ), &checksum )
1457 || save_write( fd, &cards_per_draw, sizeof( int ), &checksum )
1458 || save_write( fd, cols, COL_NUM * sizeof( int ), &checksum )
1459 || save_write( fd, stacks, SUITS * sizeof( int ), &checksum )
1460 || ( rb->write( fd, &checksum, sizeof( int ) ) < (ssize_t)(sizeof( int ) ) ) )
1462 rb->close( fd );
1463 rb->splash( 2*HZ, "Error while saving game. Aborting." );
1464 return -2;
1466 rb->close( fd );
1467 return 0;
1470 static int load_game( void )
1472 int checksum, retval;
1474 int fd = open_save_file( O_RDONLY );
1475 if( fd < 0 )
1476 return -1;
1478 retval = 0; /* Assume good case */
1479 if( ( rb->lseek( fd, -sizeof( int ), SEEK_END ) == -((ssize_t)sizeof( int ))-1 )
1480 || ( rb->read( fd, &checksum, sizeof( int ) ) < ((ssize_t)sizeof( int )) )
1481 || ( rb->lseek( fd, 0, SEEK_SET ) == -1 )
1482 || save_read( fd, &cur_card, sizeof( int ), &checksum )
1483 || save_read( fd, &cur_col, sizeof( int ), &checksum )
1484 || save_read( fd, &sel_card, sizeof( int ), &checksum )
1485 || save_read( fd, deck, NUM_CARDS * sizeof( card_t ), &checksum )
1486 || save_read( fd, &rem, sizeof( int ), &checksum )
1487 || save_read( fd, &cur_rem, sizeof( int ), &checksum )
1488 || save_read( fd, &count_rem, sizeof( int ), &checksum )
1489 || save_read( fd, &cards_per_draw, sizeof( int ), &checksum )
1490 || save_read( fd, cols, COL_NUM * sizeof( int ), &checksum )
1491 || save_read( fd, stacks, SUITS * sizeof( int ), &checksum ) )
1493 rb->splash( 2*HZ, "Error while loading saved game. Aborting." );
1494 retval = -2;
1496 else if( checksum != 42 )
1498 rb->splash( 2*HZ, "Save file was corrupted. Aborting." );
1499 retval = -3;
1502 rb->close( fd );
1503 delete_save_file();
1504 return retval;
1508 * The main game loop
1510 * If skipmenu is defined to SOLITAIRE_QUIT, the menu will be skipped and
1511 * game will resume.
1514 static int solitaire( int skipmenu )
1517 int i,j;
1518 int button;
1519 #ifdef NEED_LASTBUTTON_VAR
1520 int lastbutton = 0;
1521 #endif
1522 int c,h,prevcard;
1523 int biggest_col_length;
1525 rb->srand( *rb->current_tick );
1526 if( skipmenu != SOLITAIRE_QUIT )
1528 switch( solitaire_menu(false) )
1530 case MENU_QUIT:
1531 return SOLITAIRE_QUIT;
1533 case MENU_USB:
1534 return SOLITAIRE_USB;
1536 solitaire_init();
1539 while( true )
1541 rb->lcd_clear_display();
1543 /* get the biggest column length so that display can be "optimized" */
1544 biggest_col_length = 0;
1546 for(i=0;i<COL_NUM;i++)
1548 j = 0;
1549 c = cols[i];
1551 if( c != NOT_A_CARD )
1553 while( true )
1555 /* don't include the last card in the column length. */
1556 if( deck[c].next == NOT_A_CARD )
1558 break; /* no successor: get outta here. */
1560 else
1562 if( deck[c].known )
1563 j += 2;
1564 else
1565 j++;
1567 c = deck[c].next;
1569 /* make column distinguishable from an empty column,
1570 * and avoid division by zero while displaying */
1571 if( j == 0 )
1572 j = 1;
1574 if( j > biggest_col_length )
1575 biggest_col_length = j;
1578 /* check if there are cards remaining in the game. */
1579 /* if there aren't any, that means you won :) */
1580 if( biggest_col_length == 0 && rem == NOT_A_CARD )
1582 rb->lcd_update();
1583 rb->splash( HZ, "You Won :)" );
1584 return bouncing_cards();
1587 /* draw the columns */
1588 for( i = 0; i < COL_NUM; i++ )
1590 c = cols[i];
1591 j = CARD_START;
1592 while( true )
1594 if( c == NOT_A_CARD )
1596 /* draw the cursor on empty columns */
1597 if( cur_col == i )
1599 draw_cursor( MARGIN + i * (CARD_WIDTH
1600 +(LCD_WIDTH-COL_NUM*CARD_WIDTH-2*MARGIN)/(COL_NUM-1)),
1601 j );
1603 break;
1606 draw_card( &deck[c], MARGIN + i * (CARD_WIDTH
1607 +(LCD_WIDTH-COL_NUM*CARD_WIDTH-2*MARGIN)/(COL_NUM-1)),
1608 j, c == sel_card, c == cur_card );
1610 h = c;
1611 c = deck[c].next;
1612 if( c == NOT_A_CARD ) break;
1614 /* This is where we change the spacing between cards so that
1615 * they don't overflow out of the LCD */
1616 if( h == cur_card )
1617 j += SYMBOL_HEIGHT;
1618 else if( deck[h].known )
1619 j += min( SYMBOL_HEIGHT,
1620 2 * (LCD_HEIGHT - CARD_START - CARD_HEIGHT - MARGIN)
1621 / biggest_col_length );
1622 else
1623 j += min( SYMBOL_HEIGHT / 2,
1624 (LCD_HEIGHT - CARD_START - CARD_HEIGHT - MARGIN)
1625 / biggest_col_length );
1629 /* draw the stacks */
1630 for( i=0; i<SUITS; i++ )
1632 c = find_last_card( STACKS_COL + i );
1634 if( c != NOT_A_CARD )
1636 draw_card( &deck[c],
1637 LCD_WIDTH-(CARD_WIDTH*4+4+MARGIN)+CARD_WIDTH*i+i+1,
1638 MARGIN,
1639 c == sel_card, cur_col == STACKS_COL + i );
1641 else
1643 draw_empty_stack( i,
1644 LCD_WIDTH-(CARD_WIDTH*4+4+MARGIN)+CARD_WIDTH*i+i+1,
1645 MARGIN, cur_col == STACKS_COL + i );
1649 /* draw the remains */
1650 if( rem != NOT_A_CARD &&
1651 ( cur_rem == NOT_A_CARD || deck[cur_rem].next != NOT_A_CARD ) )
1653 /* gruik ! (we want to display a card back) */
1654 deck[rem].known = false;
1655 draw_card( &deck[rem], MARGIN, MARGIN, false, false );
1656 deck[rem].known = true;
1659 if( rem != NOT_A_CARD && cur_rem != NOT_A_CARD )
1661 if( count_rem < 0 )
1663 prevcard = rem;
1664 count_rem = 0;
1665 while( prevcard != cur_rem && count_rem < cards_per_draw-1 )
1667 prevcard = deck[prevcard].next;
1668 count_rem++;
1671 prevcard = cur_rem;
1672 j = CARD_WIDTH+2*MARGIN+1;
1673 for( i = 0; i < count_rem; i++ )
1674 prevcard = find_prev_card(prevcard);
1675 for( i = 0; i <= count_rem; i++ )
1677 draw_card( &deck[prevcard], j,
1678 MARGIN, sel_card == prevcard,
1679 cur_card == prevcard );
1680 prevcard = deck[prevcard].next;
1681 j += CARD_WIDTH/2;
1684 if( ( cur_rem == NOT_A_CARD || rem == NOT_A_CARD )
1685 && cur_col == REM_COL )
1687 draw_cursor( CARD_WIDTH+2*MARGIN+1, MARGIN );
1690 rb->lcd_update();
1692 /* what to do when a key is pressed ... */
1693 button = rb->button_get( true );
1694 #if (CONFIG_KEYPAD == SANSA_E200_PAD) || (CONFIG_KEYPAD == SANSA_FUZE_PAD)
1695 if (button&(BUTTON_SCROLL_BACK|BUTTON_SCROLL_FWD))
1696 button = button & (~BUTTON_REPEAT);
1697 #endif
1698 switch( button )
1700 /* move cursor to the last card of the previous column
1701 * or to the previous final stack
1702 * or to the remains stack */
1703 case SOL_RIGHT:
1704 #ifdef SOL_RIGHT_PRE
1705 if( lastbutton != SOL_RIGHT_PRE )
1706 break;
1707 #endif
1708 if( cur_col >= COL_NUM )
1710 cur_col = 0;
1712 else if( cur_col == COL_NUM - 1 )
1714 cur_col = REM_COL;
1716 else
1718 cur_col = (cur_col+1)%(REM_COL+1);
1720 if(cur_col == REM_COL)
1722 cur_card = cur_rem;
1723 break;
1725 cur_card = find_last_card( cur_col );
1726 break;
1728 /* move cursor to the last card of the next column
1729 * or to the next final stack
1730 * or to the remains stack */
1731 case SOL_LEFT:
1732 #ifdef SOL_LEFT_PRE
1733 if( lastbutton != SOL_LEFT_PRE )
1734 break;
1735 #endif
1736 if( cur_col == 0 )
1738 cur_col = REM_COL;
1740 else if( cur_col >= COL_NUM )
1742 cur_col = COL_NUM - 1;
1744 else
1746 cur_col = (cur_col + REM_COL)%(REM_COL+1);
1748 if( cur_col == REM_COL )
1750 cur_card = cur_rem;
1751 break;
1753 cur_card = find_last_card( cur_col );
1754 break;
1756 /* move cursor to card that's bellow */
1757 case SOL_DOWN:
1758 #ifdef SOL_DOWN_PRE
1759 if( lastbutton != SOL_DOWN_PRE )
1760 break;
1761 #else
1762 case SOL_DOWN|BUTTON_REPEAT:
1763 #endif
1764 if( cur_col >= COL_NUM )
1766 cur_col = (cur_col - COL_NUM + 1)%(SUITS + 1) + COL_NUM;
1767 if( cur_col == REM_COL )
1769 cur_card = cur_rem;
1771 else
1773 cur_card = find_last_card( cur_col );
1775 break;
1777 if( cur_card == NOT_A_CARD ) break;
1778 if( deck[cur_card].next != NOT_A_CARD )
1780 cur_card = deck[cur_card].next;
1782 else
1784 cur_card = cols[cur_col];
1785 while( !deck[ cur_card].known
1786 && deck[cur_card].next != NOT_A_CARD )
1788 cur_card = deck[cur_card].next;
1791 break;
1793 /* move cursor to card that's above */
1794 case SOL_UP:
1795 #ifdef SOL_UP_PRE
1796 if( lastbutton != SOL_UP_PRE )
1797 break;
1798 #else
1799 case SOL_UP|BUTTON_REPEAT:
1800 #endif
1801 if( cur_col >= COL_NUM )
1803 cur_col = (cur_col - COL_NUM + SUITS)%(SUITS + 1) + COL_NUM;
1804 if( cur_col == REM_COL )
1806 cur_card = cur_rem;
1808 else
1810 cur_card = find_last_card( cur_col );
1812 break;
1814 if( cur_card == NOT_A_CARD ) break;
1815 do {
1816 cur_card = find_prev_card( cur_card );
1817 if( cur_card == NOT_A_CARD )
1819 cur_card = find_last_card( cur_col );
1821 } while( deck[cur_card].next != NOT_A_CARD
1822 && !deck[cur_card].known );
1823 break;
1825 /* Try to put card under cursor on one of the stacks */
1826 case SOL_CUR2STACK:
1827 #ifdef SOL_CUR2STACK_PRE
1828 if( lastbutton != SOL_CUR2STACK_PRE )
1829 break;
1830 #endif
1831 move_card( deck[cur_card].suit + STACKS_COL, cur_card );
1832 break;
1834 /* Move cards arround, Uncover cards, ... */
1835 case SOL_MOVE:
1836 #ifdef SOL_MOVE_PRE
1837 if( lastbutton != SOL_MOVE_PRE )
1838 break;
1839 #endif
1841 if( sel_card == NOT_A_CARD )
1843 if( cur_card != NOT_A_CARD )
1845 if( deck[cur_card].next == NOT_A_CARD
1846 && !deck[cur_card].known )
1848 /* reveal a hidden card */
1849 deck[cur_card].known = true;
1851 else if( cur_col == REM_COL && cur_rem == NOT_A_CARD )
1853 break;
1855 else
1857 /* select a card */
1858 sel_card = cur_card;
1862 else if( sel_card == cur_card )
1864 /* unselect card or try putting card on
1865 * one of the 4 stacks */
1866 if( move_card( deck[sel_card].suit + COL_NUM, sel_card )
1867 == MOVE_OK && cur_col == REM_COL )
1869 cur_card = cur_rem;
1871 sel_card = NOT_A_CARD;
1873 else
1875 /* try moving cards */
1876 /* The flexible move must not be used from the remains stack. */
1877 if (find_card_col(sel_card) == REM_COL)
1879 if (move_card( cur_col, sel_card ) == MOVE_NOT_OK)
1880 sel_card = NOT_A_CARD;
1882 else
1884 do {
1885 if (move_card( cur_col, sel_card) == MOVE_OK)
1886 break;
1887 sel_card = find_prev_card(sel_card);
1888 } while (sel_card != NOT_A_CARD);
1891 break;
1893 /* If the card on the top of the remains can be put where
1894 * the cursor is, go ahead */
1895 case SOL_REM2CUR:
1896 #ifdef SOL_REM2CUR_PRE
1897 if( lastbutton != SOL_REM2CUR_PRE )
1898 break;
1899 #endif
1900 move_card( cur_col, cur_rem );
1901 break;
1903 /* If the card on top of the remains can be put on one
1904 * of the stacks, do so */
1905 case SOL_REM2STACK:
1906 #ifdef SOL_REM2STACK_PRE
1907 if( lastbutton != SOL_REM2STACK_PRE )
1908 break;
1909 #endif
1910 move_card( deck[cur_rem].suit + COL_NUM, cur_rem );
1911 break;
1913 #ifdef SOL_REM
1914 case SOL_REM:
1915 if( sel_card != NOT_A_CARD )
1917 /* unselect selected card */
1918 sel_card = NOT_A_CARD;
1919 break;
1921 if( rem != NOT_A_CARD && cur_rem != NOT_A_CARD )
1923 sel_card = cur_rem;
1924 break;
1926 break;
1927 #endif
1929 /* unselect selected card or ...
1930 * draw new cards from the remains of the deck */
1931 case SOL_DRAW:
1932 #ifdef SOL_DRAW_PRE
1933 if( lastbutton != SOL_DRAW_PRE )
1934 break;
1935 #endif
1936 if( sel_card != NOT_A_CARD )
1938 /* unselect selected card */
1939 sel_card = NOT_A_CARD;
1940 break;
1942 if( rem != NOT_A_CARD )
1944 int cur_rem_old = cur_rem;
1945 count_rem = -1;
1946 /* draw new cards form the remains of the deck */
1947 if( cur_rem == NOT_A_CARD )
1949 /*if the cursor card is null*/
1950 cur_rem = rem;
1951 i = cards_per_draw - 1;
1952 count_rem++;
1954 else
1956 i = cards_per_draw;
1959 while( i > 0 && deck[cur_rem].next != NOT_A_CARD )
1961 cur_rem = deck[cur_rem].next;
1962 i--;
1963 count_rem++;
1965 /* test if any cards are really left on
1966 * the remains' stack */
1967 if( i == cards_per_draw )
1969 cur_rem = NOT_A_CARD;
1970 count_rem = -1;
1972 /* if cursor was on remains' stack when new cards were
1973 * drawn, put cursor on top of remains' stack */
1974 if( cur_col == REM_COL && cur_card == cur_rem_old )
1976 cur_card = cur_rem;
1977 sel_card = NOT_A_CARD;
1980 break;
1982 /* Show the menu */
1983 #ifdef SOL_RC_QUIT
1984 case SOL_RC_QUIT:
1985 #endif
1986 case SOL_QUIT:
1987 switch( solitaire_menu(true) )
1989 case MENU_SAVE_AND_QUIT:
1990 return SOLITAIRE_SAVE_AND_QUIT;
1992 case MENU_QUIT:
1993 return SOLITAIRE_QUIT;
1995 case MENU_USB:
1996 return SOLITAIRE_USB;
1998 break;
2000 case SYS_POWEROFF:
2001 return SOLITAIRE_SAVE_AND_QUIT;
2003 default:
2004 if( rb->default_event_handler( button ) == SYS_USB_CONNECTED )
2005 return SOLITAIRE_USB;
2006 break;
2009 #ifdef NEED_LASTBUTTON_VAR
2010 if( button != BUTTON_NONE )
2011 lastbutton = button;
2012 #endif
2014 /* fix incoherences concerning cur_col and cur_card */
2015 c = find_card_col( cur_card );
2016 if( c != NOT_A_COL && c != cur_col )
2017 cur_card = find_last_card( cur_col );
2019 if( cur_card == NOT_A_CARD
2020 && find_last_card( cur_col ) != NOT_A_CARD )
2021 cur_card = find_last_card( cur_col );
2023 rb->yield();
2028 * Plugin entry point
2031 enum plugin_status plugin_start(const void* parameter )
2033 int result;
2035 /* plugin init */
2036 (void)parameter;
2038 configfile_load(CONFIG_FILENAME, config,
2039 sizeof(config) / sizeof(config[0]), CFGFILE_VERSION);
2040 rb->memcpy(&sol, &sol_disk, sizeof(sol)); /* copy to running config */
2042 if( load_game() == 0 )
2044 rb->splash( HZ, "Resuming saved game." );
2045 result = SOLITAIRE_QUIT;
2047 else
2048 result = SOLITAIRE_WIN;
2050 /* play the game :)
2051 * Keep playing if a game was won (that means display the menu after
2052 * winning instead of quiting) */
2053 while( ( result = solitaire( result ) ) == SOLITAIRE_WIN );
2055 if( result != SOLITAIRE_QUIT )
2056 /* result == SOLITAIRE_USB || result == SOLITAIRE_SAVE_AND_QUIT */
2057 save_game();
2059 if (rb->memcmp(&sol, &sol_disk, sizeof(sol))) /* save settings if changed */
2061 rb->memcpy(&sol_disk, &sol, sizeof(sol));
2062 configfile_save(CONFIG_FILENAME, config,
2063 sizeof(config) / sizeof(config[0]), CFGFILE_VERSION);
2066 /* Exit the plugin */
2067 return ( result == SOLITAIRE_USB ) ? PLUGIN_USB_CONNECTED : PLUGIN_OK;