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 "lib/playback_control.h"
24 #include "lib/configfile.h"
28 #ifdef HAVE_LCD_BITMAP
32 #define min(a,b) (a<b?a:b)
38 #if CONFIG_KEYPAD == RECORDER_PAD
39 # define SOL_QUIT BUTTON_OFF
40 # define SOL_UP BUTTON_UP
41 # define SOL_DOWN BUTTON_DOWN
42 # define SOL_LEFT BUTTON_LEFT
43 # define SOL_RIGHT BUTTON_RIGHT
44 # define SOL_MOVE BUTTON_ON
45 # define SOL_DRAW BUTTON_F1
46 # define SOL_REM2CUR BUTTON_PLAY
47 # define SOL_CUR2STACK BUTTON_F2
48 # define SOL_REM2STACK BUTTON_F3
51 # define HK_REM2CUR "PLAY"
52 # define HK_CUR2STACK "F2"
53 # define HK_REM2STACK "F3"
55 #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
56 # define SOL_QUIT BUTTON_OFF
57 # define SOL_UP BUTTON_UP
58 # define SOL_DOWN BUTTON_DOWN
59 # define SOL_LEFT BUTTON_LEFT
60 # define SOL_RIGHT BUTTON_RIGHT
61 # define SOL_MOVE BUTTON_ON
62 # define SOL_DRAW BUTTON_F1
63 # define SOL_REM2CUR BUTTON_SELECT
64 # define SOL_CUR2STACK BUTTON_F2
65 # define SOL_REM2STACK BUTTON_F3
68 # define HK_REM2CUR "SELECT"
69 # define HK_CUR2STACK "F2"
70 # define HK_REM2STACK "F3"
72 #elif CONFIG_KEYPAD == ONDIO_PAD
73 # define SOL_QUIT BUTTON_OFF
74 # define SOL_UP_PRE BUTTON_UP
75 # define SOL_UP (BUTTON_UP | BUTTON_REL)
76 # define SOL_DOWN_PRE BUTTON_DOWN
77 # define SOL_DOWN (BUTTON_DOWN | BUTTON_REL)
78 # define SOL_LEFT_PRE BUTTON_LEFT
79 # define SOL_LEFT (BUTTON_LEFT | BUTTON_REL)
80 # define SOL_RIGHT_PRE BUTTON_RIGHT
81 # define SOL_RIGHT (BUTTON_RIGHT | BUTTON_REL)
82 # define SOL_MOVE_PRE BUTTON_MENU
83 # define SOL_MOVE (BUTTON_MENU | BUTTON_REL)
84 # define SOL_DRAW_PRE BUTTON_MENU
85 # define SOL_DRAW (BUTTON_MENU | BUTTON_REPEAT)
86 # define SOL_REM2CUR_PRE BUTTON_DOWN
87 # define SOL_REM2CUR (BUTTON_DOWN | BUTTON_REPEAT)
88 # define SOL_CUR2STACK_PRE BUTTON_UP
89 # define SOL_CUR2STACK (BUTTON_UP | BUTTON_REPEAT)
90 # define SOL_REM2STACK_PRE BUTTON_RIGHT
91 # define SOL_REM2STACK (BUTTON_RIGHT | BUTTON_REPEAT)
92 # define HK_MOVE "MODE"
93 # define HK_DRAW "MODE.."
94 # define HK_REM2CUR "DOWN.."
95 # define HK_CUR2STACK "UP.."
96 # define HK_REM2STACK "RIGHT.."
98 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
99 (CONFIG_KEYPAD == IRIVER_H300_PAD)
100 # define SOL_QUIT BUTTON_OFF
101 # define SOL_UP BUTTON_UP
102 # define SOL_DOWN BUTTON_DOWN
103 # define SOL_LEFT BUTTON_LEFT
104 # define SOL_RIGHT BUTTON_RIGHT
105 # define SOL_MOVE_PRE BUTTON_SELECT
106 # define SOL_MOVE (BUTTON_SELECT | BUTTON_REL)
107 # define SOL_DRAW BUTTON_MODE
108 # define SOL_REM2CUR (BUTTON_LEFT | BUTTON_ON)
109 # define SOL_CUR2STACK_PRE BUTTON_SELECT
110 # define SOL_CUR2STACK (BUTTON_SELECT | BUTTON_REPEAT)
111 # define SOL_REM2STACK (BUTTON_RIGHT | BUTTON_ON)
112 # define SOL_REM BUTTON_REC
113 # define SOL_RC_QUIT BUTTON_RC_STOP
114 # define HK_MOVE "NAVI"
115 # define HK_DRAW "A-B"
116 # define HK_REM2CUR "PLAY+LEFT"
117 # define HK_CUR2STACK "NAVI.."
118 # define HK_REM2STACK "PLAY+RIGHT"
120 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
121 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
122 # define SOL_QUIT (BUTTON_SELECT | BUTTON_MENU)
123 # define SOL_UP BUTTON_SCROLL_BACK
124 # define SOL_DOWN BUTTON_SCROLL_FWD
125 # define SOL_LEFT_PRE BUTTON_LEFT
126 # define SOL_LEFT (BUTTON_LEFT | BUTTON_REL)
127 # define SOL_RIGHT_PRE BUTTON_RIGHT
128 # define SOL_RIGHT (BUTTON_RIGHT | BUTTON_REL)
129 # define SOL_MOVE_PRE BUTTON_SELECT
130 # define SOL_MOVE (BUTTON_SELECT | BUTTON_REL)
131 # define SOL_DRAW_PRE BUTTON_MENU
132 # define SOL_DRAW (BUTTON_MENU | BUTTON_REL)
133 # define SOL_REM2CUR BUTTON_PLAY
134 # define SOL_CUR2STACK_PRE BUTTON_MENU
135 # define SOL_CUR2STACK (BUTTON_MENU | BUTTON_REPEAT)
136 # define SOL_REM2STACK_PRE BUTTON_RIGHT
137 # define SOL_REM2STACK (BUTTON_RIGHT | BUTTON_REPEAT)
138 # define HK_UD "SCROLL U/D"
139 # define HK_MOVE "SELECT"
140 # define HK_DRAW "MENU"
141 # define HK_REM2CUR "PLAY"
142 # define HK_CUR2STACK "MENU.."
143 # define HK_REM2STACK "RIGHT.."
145 #elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
146 # define SOL_QUIT BUTTON_POWER
147 # define SOL_UP BUTTON_UP
148 # define SOL_DOWN BUTTON_DOWN
149 # define SOL_LEFT BUTTON_LEFT
150 # define SOL_RIGHT BUTTON_RIGHT
151 # define SOL_MOVE_PRE BUTTON_SELECT
152 # define SOL_MOVE (BUTTON_SELECT | BUTTON_REL)
153 # define SOL_DRAW_PRE BUTTON_PLAY
154 # define SOL_DRAW (BUTTON_PLAY | BUTTON_REL)
155 # define SOL_REM2CUR_PRE BUTTON_PLAY
156 # define SOL_REM2CUR (BUTTON_PLAY | BUTTON_REPEAT)
157 # define SOL_CUR2STACK_PRE BUTTON_SELECT
158 # define SOL_CUR2STACK (BUTTON_SELECT | BUTTON_REPEAT)
159 # define SOL_REM2STACK BUTTON_REC
160 # define HK_MOVE "SELECT"
161 # define HK_DRAW "PLAY"
162 # define HK_REM2CUR "PLAY.."
163 # define HK_CUR2STACK "SELECT.."
164 # define HK_REM2STACK "REC"
166 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
167 # define SOL_QUIT BUTTON_POWER
168 # define SOL_UP BUTTON_UP
169 # define SOL_DOWN BUTTON_DOWN
170 # define SOL_LEFT BUTTON_LEFT
171 # define SOL_RIGHT BUTTON_RIGHT
172 # define SOL_MOVE_PRE BUTTON_SELECT
173 # define SOL_MOVE (BUTTON_SELECT | BUTTON_REL)
174 # define SOL_DRAW BUTTON_MENU
175 # define SOL_REM2CUR (BUTTON_LEFT | BUTTON_A)
176 # define SOL_CUR2STACK (BUTTON_SELECT | BUTTON_REPEAT)
177 # define SOL_REM2STACK (BUTTON_RIGHT | BUTTON_A)
178 # define HK_MOVE "SELECT"
179 # define HK_DRAW "MENU"
180 # define HK_REM2CUR "A+LEFT"
181 # define HK_CUR2STACK "SELECT.."
182 # define HK_REM2STACK "A+RIGHT"
184 #elif (CONFIG_KEYPAD == SANSA_E200_PAD)
185 # define SOL_QUIT BUTTON_POWER
186 # define SOL_UP BUTTON_UP
187 # define SOL_DOWN BUTTON_DOWN
188 # define SOL_LEFT BUTTON_SCROLL_BACK
189 # define SOL_RIGHT BUTTON_SCROLL_FWD
190 # define SOL_MOVE BUTTON_SELECT
191 # define SOL_DRAW BUTTON_REC
192 # define SOL_REM2CUR BUTTON_LEFT
193 # define SOL_CUR2STACK_PRE BUTTON_REC
194 # define SOL_CUR2STACK (BUTTON_REC | BUTTON_RIGHT)
195 # define SOL_REM2STACK BUTTON_RIGHT
196 # define HK_MOVE "SELECT"
197 # define HK_DRAW "REC"
198 # define HK_REM2CUR "LEFT"
199 # define HK_CUR2STACK "DOUBLE SELECT"
200 # define HK_REM2STACK "RIGHT"
202 #elif (CONFIG_KEYPAD == SANSA_FUZE_PAD)
203 # define SOL_QUIT (BUTTON_HOME|BUTTON_REPEAT)
204 # define SOL_UP BUTTON_UP
205 # define SOL_DOWN BUTTON_DOWN
206 # define SOL_LEFT BUTTON_SCROLL_BACK
207 # define SOL_RIGHT BUTTON_SCROLL_FWD
208 # define SOL_MOVE (BUTTON_SELECT|BUTTON_REL)
209 # define SOL_DRAW (BUTTON_HOME|BUTTON_REL)
210 # define SOL_REM2CUR BUTTON_LEFT
211 # define SOL_CUR2STACK_PRE (BUTTON_RIGHT | BUTTON_REPEAT)
212 # define SOL_CUR2STACK BUTTON_RIGHT
213 # define SOL_REM2STACK (BUTTON_LEFT|BUTTON_REPEAT)
214 # define SOL_REM2STACK_PRE BUTTON_LEFT
215 # define HK_MOVE "SHORT SELECT"
216 # define HK_DRAW "SHORT HOME"
217 # define HK_REM2CUR "LEFT"
218 # define HK_CUR2STACK "DOUBLE SELECT"
219 # define HK_REM2STACK "LEFT"
221 #elif (CONFIG_KEYPAD == SANSA_C200_PAD)
222 # define SOL_QUIT BUTTON_POWER
223 # define SOL_UP BUTTON_UP
224 # define SOL_DOWN BUTTON_DOWN
225 # define SOL_LEFT BUTTON_LEFT
226 # define SOL_RIGHT BUTTON_RIGHT
227 # define SOL_MOVE_PRE BUTTON_SELECT
228 # define SOL_MOVE (BUTTON_SELECT | BUTTON_REL)
229 # define SOL_DRAW BUTTON_VOL_DOWN
230 # define SOL_REM2CUR BUTTON_REC
231 # define SOL_CUR2STACK_PRE BUTTON_SELECT
232 # define SOL_CUR2STACK (BUTTON_SELECT | BUTTON_REPEAT)
233 # define SOL_REM2STACK BUTTON_VOL_UP
234 # define HK_MOVE "SELECT"
235 # define HK_DRAW "REC"
236 # define HK_REM2CUR "LEFT"
237 # define HK_CUR2STACK "DOUBLE SELECT"
238 # define HK_REM2STACK "RIGHT"
240 #elif CONFIG_KEYPAD == SANSA_CLIP_PAD
241 # define SOL_QUIT BUTTON_POWER
242 # define SOL_UP BUTTON_UP
243 # define SOL_DOWN BUTTON_DOWN
244 # define SOL_LEFT BUTTON_LEFT
245 # define SOL_RIGHT BUTTON_RIGHT
246 # define SOL_MOVE_PRE BUTTON_SELECT
247 # define SOL_MOVE (BUTTON_SELECT | BUTTON_REL)
248 # define SOL_DRAW BUTTON_HOME
249 # define SOL_REM2CUR BUTTON_VOL_DOWN
250 # define SOL_CUR2STACK_PRE BUTTON_SELECT
251 # define SOL_CUR2STACK (BUTTON_SELECT | BUTTON_REPEAT)
252 # define SOL_REM2STACK BUTTON_VOL_UP
253 # define HK_MOVE "SELECT"
254 # define HK_DRAW "HOME"
255 # define HK_REM2CUR "LEFT"
256 # define HK_CUR2STACK "DOUBLE SELECT"
257 # define HK_REM2STACK "RIGHT"
259 #elif CONFIG_KEYPAD == SANSA_M200_PAD
260 # define SOL_QUIT BUTTON_POWER
261 # define SOL_UP BUTTON_UP
262 # define SOL_DOWN BUTTON_DOWN
263 # define SOL_LEFT BUTTON_LEFT
264 # define SOL_RIGHT BUTTON_RIGHT
265 # define SOL_MOVE_PRE BUTTON_SELECT
266 # define SOL_MOVE (BUTTON_SELECT | BUTTON_REL)
267 # define SOL_DRAW (BUTTON_SELECT | BUTTON_UP)
268 # define SOL_REM2CUR BUTTON_VOL_DOWN
269 # define SOL_CUR2STACK_PRE BUTTON_SELECT
270 # define SOL_CUR2STACK (BUTTON_SELECT | BUTTON_REPEAT)
271 # define SOL_REM2STACK BUTTON_VOL_UP
272 # define HK_MOVE "SELECT"
273 # define HK_DRAW "SELECT + UP"
274 # define HK_REM2CUR "LEFT"
275 # define HK_CUR2STACK "DOUBLE SELECT"
276 # define HK_REM2STACK "RIGHT"
278 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
279 # define SOL_QUIT BUTTON_POWER
280 # define SOL_UP BUTTON_SCROLL_UP
281 # define SOL_DOWN BUTTON_SCROLL_DOWN
282 # define SOL_LEFT_PRE BUTTON_LEFT
283 # define SOL_LEFT (BUTTON_LEFT | BUTTON_REL)
284 # define SOL_RIGHT_PRE BUTTON_RIGHT
285 # define SOL_RIGHT (BUTTON_RIGHT | BUTTON_REL)
286 # define SOL_MOVE BUTTON_PLAY
287 # define SOL_DRAW_PRE BUTTON_LEFT
288 # define SOL_DRAW (BUTTON_LEFT | BUTTON_REPEAT)
289 # define SOL_REM2CUR BUTTON_FF
290 # define SOL_CUR2STACK BUTTON_REW
291 # define SOL_REM2STACK_PRE BUTTON_RIGHT
292 # define SOL_REM2STACK (BUTTON_RIGHT | BUTTON_REPEAT)
293 # define HK_MOVE "PLAY"
294 # define HK_DRAW "LEFT.."
295 # define HK_REM2CUR "FF"
296 # define HK_CUR2STACK "REW"
297 # define HK_REM2STACK "RIGHT.."
299 #elif (CONFIG_KEYPAD == GIGABEAT_S_PAD)
300 # define SOL_QUIT BUTTON_BACK
301 # define SOL_UP BUTTON_UP
302 # define SOL_DOWN BUTTON_DOWN
303 # define SOL_LEFT BUTTON_LEFT
304 # define SOL_RIGHT BUTTON_RIGHT
305 # define SOL_MOVE_PRE BUTTON_SELECT
306 # define SOL_MOVE (BUTTON_SELECT | BUTTON_REL)
307 # define SOL_DRAW BUTTON_MENU
308 # define SOL_REM2CUR (BUTTON_LEFT | BUTTON_SELECT)
309 # define SOL_CUR2STACK (BUTTON_SELECT | BUTTON_REPEAT)
310 # define SOL_REM2STACK (BUTTON_RIGHT | BUTTON_SELECT)
311 # define HK_MOVE "SELECT"
312 # define HK_DRAW "MENU"
313 # define HK_REM2CUR "SELECT+LEFT"
314 # define HK_CUR2STACK "SELECT.."
315 # define HK_REM2STACK "SELECT+RIGHT"
317 #elif (CONFIG_KEYPAD == MROBE100_PAD)
318 # define SOL_QUIT BUTTON_POWER
319 # define SOL_UP BUTTON_UP
320 # define SOL_DOWN BUTTON_DOWN
321 # define SOL_LEFT BUTTON_LEFT
322 # define SOL_RIGHT BUTTON_RIGHT
323 # define SOL_MOVE_PRE BUTTON_SELECT
324 # define SOL_MOVE (BUTTON_SELECT | BUTTON_REL)
325 # define SOL_DRAW BUTTON_MENU
326 # define SOL_REM2CUR (BUTTON_LEFT | BUTTON_DISPLAY)
327 # define SOL_CUR2STACK (BUTTON_SELECT | BUTTON_REPEAT)
328 # define SOL_REM2STACK (BUTTON_RIGHT | BUTTON_DISPLAY)
329 # define HK_MOVE "SELECT"
330 # define HK_DRAW "MENU"
331 # define HK_REM2CUR "DISPLAY+LEFT"
332 # define HK_CUR2STACK "SELECT.."
333 # define HK_REM2STACK "DISPLAY+RIGHT"
335 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
336 # define SOL_QUIT BUTTON_RC_REC
337 # define SOL_UP BUTTON_RC_VOL_UP
338 # define SOL_DOWN BUTTON_RC_VOL_DOWN
339 # define SOL_LEFT BUTTON_RC_REW
340 # define SOL_RIGHT BUTTON_RC_FF
341 # define SOL_MOVE BUTTON_RC_PLAY
342 # define SOL_DRAW_PRE BUTTON_RC_MENU
343 # define SOL_DRAW (BUTTON_RC_MENU | BUTTON_REL)
344 # define SOL_REM2CUR_PRE BUTTON_RC_MENU
345 # define SOL_REM2CUR (BUTTON_RC_MENU | BUTTON_REPEAT)
346 # define SOL_CUR2STACK_PRE BUTTON_RC_MODE
347 # define SOL_CUR2STACK (BUTTON_RC_MODE | BUTTON_REL)
348 # define SOL_REM2STACK_PRE BUTTON_RC_MODE
349 # define SOL_REM2STACK (BUTTON_RC_MODE | BUTTON_REPEAT)
350 # define HK_LR "REW/FF"
351 # define HK_UD "VOL UP/DOWN"
352 # define HK_MOVE "PLAY"
353 # define HK_DRAW "MENU"
354 # define HK_REM2CUR "MENU.."
355 # define HK_CUR2STACK "MODE"
356 # define HK_REM2STACK "MODE.."
358 #elif (CONFIG_KEYPAD == COWOND2_PAD)
359 # define SOL_QUIT BUTTON_POWER
361 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
362 # define SOL_QUIT BUTTON_BACK
363 # define SOL_UP BUTTON_UP
364 # define SOL_DOWN BUTTON_DOWN
365 # define SOL_LEFT BUTTON_LEFT
366 # define SOL_RIGHT BUTTON_RIGHT
367 # define SOL_MOVE_PRE BUTTON_SELECT
368 # define SOL_MOVE (BUTTON_SELECT | BUTTON_REL)
369 # define SOL_DRAW BUTTON_MENU
370 # define SOL_REM2CUR (BUTTON_LEFT | BUTTON_SELECT)
371 # define SOL_CUR2STACK (BUTTON_SELECT | BUTTON_REPEAT)
372 # define SOL_REM2STACK (BUTTON_RIGHT | BUTTON_SELECT)
373 # define HK_MOVE "MIDDLE"
374 # define HK_DRAW "MENU"
375 # define HK_REM2CUR "PLAY+LEFT"
376 # define HK_CUR2STACK "PLAY.."
377 # define HK_REM2STACK "PLAY+RIGHT"
379 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
380 # define SOL_QUIT BUTTON_POWER
381 # define SOL_UP BUTTON_UP
382 # define SOL_DOWN BUTTON_DOWN
383 # define SOL_LEFT BUTTON_LEFT
384 # define SOL_RIGHT BUTTON_RIGHT
385 # define SOL_MOVE_PRE BUTTON_SELECT
386 # define SOL_MOVE (BUTTON_SELECT | BUTTON_REL)
387 # define SOL_DRAW BUTTON_MENU
388 # define SOL_REM2CUR (BUTTON_LEFT | BUTTON_VIEW)
389 # define SOL_CUR2STACK (BUTTON_SELECT | BUTTON_REPEAT)
390 # define SOL_REM2STACK (BUTTON_RIGHT | BUTTON_VIEW)
391 # define HK_MOVE "SELECT"
392 # define HK_DRAW "MENU"
393 # define HK_REM2CUR "VIEW+LEFT"
394 # define HK_CUR2STACK "SELECT.."
395 # define HK_REM2STACK "VIEW+RIGHT"
397 #elif (CONFIG_KEYPAD == ONDAVX747_PAD) || CONFIG_KEYPAD == MROBE500_PAD
398 # define SOL_QUIT BUTTON_POWER
401 #error No keymap defined!
404 #ifdef HAVE_TOUCHSCREEN
406 //# define SOL_QUIT BUTTON_TOPLEFT
409 # define SOL_UP BUTTON_TOPMIDDLE
412 # define SOL_DOWN BUTTON_BOTTOMMIDDLE
415 # define SOL_LEFT BUTTON_MIDLEFT
418 # define SOL_RIGHT BUTTON_MIDRIGHT
421 # define SOL_MOVE BUTTON_CENTER
422 # define HK_MOVE "CENTRE"
425 # define SOL_DRAW BUTTON_TOPLEFT
426 # define HK_DRAW "TOPLEFT"
429 # define SOL_REM2CUR BUTTON_TOPRIGHT
430 # define HK_REM2CUR "TOPRIGHT"
432 #ifndef SOL_CUR2STACK
433 # define SOL_CUR2STACK BUTTON_BOTTOMLEFT
434 # define HK_CUR2STACK "BOTTOMLEFT"
436 #ifndef SOL_REM2STACK
437 # define SOL_REM2STACK BUTTON_BOTTOMRIGHT
438 # define HK_REM2STACK "BOTTOMRIGHT"
444 # define HK_LR "LEFT/RIGHT"
447 # define HK_UD "UP/DOWN"
454 static int helplines
;
455 static int displaylines
;
457 static char helptext
[] =
458 /* Use single spaces only! Close each line with one \0. */
460 HK_LR
": Move the cursor to the previous/ next column.\0"
461 HK_UD
": Move the cursor up/ down in the column.\0"
462 HK_MOVE
": Select cards, move cards, reveal hidden cards...\0"
463 HK_DRAW
": Deselect a card if it was selected. Else draw new card(s) from the remains stack.\0"
465 HK_REM2CUR
": Put the card on top of the remains stack on top of the cursor.\0"
466 HK_CUR2STACK
": Put the card under the cursor on one of the 4 final stacks.\0"
467 HK_REM2STACK
": Put the card on top of the remains stack on one of the 4 final stacks.\0"
471 * Misc constants, graphics and other defines
474 #include "pluginbitmaps/card_back.h"
475 #include "pluginbitmaps/card_deck.h"
476 #include "pluginbitmaps/solitaire_suitsi.h"
478 #define CARD_GFX_WIDTH BMPWIDTH_card_back
479 #define CARD_GFX_HEIGHT BMPHEIGHT_card_back
480 #define CARD_WIDTH (BMPWIDTH_card_back+2)
481 #define CARD_HEIGHT (BMPHEIGHT_card_back+2)
486 # define SYMBOL_HEIGHT 12
487 #elif LCD_WIDTH >= 220
490 # define SYMBOL_HEIGHT 12
491 #elif LCD_WIDTH >= 160
493 # define SYMBOL_HEIGHT 11
494 #elif LCD_WIDTH >= 128
496 # define SYMBOL_HEIGHT 10
499 # define SYMBOL_HEIGHT 8
502 #define CARD_START (CARD_HEIGHT+2*MARGIN+1)
504 /* background color */
505 #ifdef HAVE_LCD_COLOR
506 # define BACKGROUND_COLOR LCD_RGBPACK(0,157,0)
507 # define FRAME_COLOR LCD_RGBPACK(23,119,218)
509 # define BACKGROUND_COLOR LCD_WHITE
510 # define FRAME_COLOR LCD_BLACK
514 #define CONFIG_FILENAME "sol.cfg"
516 #define NOT_A_CARD -1
518 /* number of cards per suit */
519 #define CARDS_PER_SUIT 13
521 /* number of suits */
524 #define NUM_CARDS ( CARDS_PER_SUIT * SUITS )
526 /* number of columns */
529 /* pseudo column numbers to be used for cursor coordinates */
530 /* columns COL_NUM to COL_NUM + SUITS - 1 correspond to the final stacks */
531 #define STACKS_COL COL_NUM
532 /* column COL_NUM + SUITS corresponds to the remains' stack */
533 #define REM_COL (STACKS_COL + SUITS)
542 bool used
: 1; /* this is what is used when dealing cards */
548 * LCD card drawing routines
551 static void draw_cursor( int x
, int y
)
553 rb
->lcd_set_drawmode( DRMODE_COMPLEMENT
);
554 rb
->lcd_fillrect( x
+1, y
+1, CARD_GFX_WIDTH
, CARD_GFX_HEIGHT
);
556 rb
->lcd_drawpixel( x
+1, y
+1 );
557 rb
->lcd_drawpixel( x
+1, y
+CARD_HEIGHT
-2 );
558 rb
->lcd_drawpixel( x
+CARD_WIDTH
-2, y
+1 );
559 rb
->lcd_drawpixel( x
+CARD_WIDTH
-2, y
+CARD_HEIGHT
-2 );
561 rb
->lcd_set_drawmode( DRMODE_SOLID
);
564 /* Draw a card's border, select it if it's selected and draw the cursor
565 * if the cursor is currently over the card */
566 static void draw_card_ext( int x
, int y
, bool selected
, bool cursor
)
569 int oldfg
= rb
->lcd_get_foreground();
571 rb
->lcd_set_foreground( LCD_BLACK
);
574 rb
->lcd_hline( x
+2, x
+CARD_WIDTH
-3, y
);
575 rb
->lcd_hline( x
+2, x
+CARD_WIDTH
-3, y
+CARD_HEIGHT
-1 );
576 rb
->lcd_vline( x
, y
+2, y
+CARD_HEIGHT
-3 );
577 rb
->lcd_vline( x
+CARD_WIDTH
-1, y
+2, y
+CARD_HEIGHT
-3 );
578 rb
->lcd_drawpixel( x
+1, y
+1 );
579 rb
->lcd_drawpixel( x
+1, y
+CARD_HEIGHT
-2 );
580 rb
->lcd_drawpixel( x
+CARD_WIDTH
-2, y
+1 );
581 rb
->lcd_drawpixel( x
+CARD_WIDTH
-2, y
+CARD_HEIGHT
-2 );
583 rb
->lcd_hline( x
+1, x
+CARD_WIDTH
-2, y
);
584 rb
->lcd_hline( x
+1, x
+CARD_WIDTH
-2, y
+CARD_HEIGHT
-1 );
585 rb
->lcd_vline( x
, y
+1, y
+CARD_HEIGHT
-2 );
586 rb
->lcd_vline( x
+CARD_WIDTH
-1, y
+1, y
+CARD_HEIGHT
-2 );
592 rb
->lcd_set_foreground( FRAME_COLOR
);
594 rb
->lcd_drawrect( x
+1, y
+1, CARD_WIDTH
-2, CARD_HEIGHT
-2 );
596 rb
->lcd_drawrect( x
+2, y
+2, CARD_WIDTH
-4, CARD_HEIGHT
-4 );
600 rb
->lcd_set_foreground( oldfg
);
609 /* Draw a card's inner graphics */
610 static void draw_card( card_t
*card
, int x
, int y
,
611 bool selected
, bool cursor
)
615 rb
->lcd_bitmap_part( card_deck
, CARD_GFX_WIDTH
* card
->num
,
616 CARD_GFX_HEIGHT
* card
->suit
, BMPWIDTH_card_deck
,
617 x
+1, y
+1, CARD_GFX_WIDTH
, CARD_GFX_HEIGHT
);
621 rb
->lcd_bitmap( card_back
, x
+1, y
+1,
622 CARD_GFX_WIDTH
, CARD_GFX_HEIGHT
);
624 draw_card_ext( x
, y
, selected
, cursor
);
627 /* Draw an empty stack */
628 static void draw_empty_stack( int s
, int x
, int y
, bool cursor
)
630 rb
->lcd_bitmap_part( solitaire_suitsi
, 0,
631 CARD_GFX_HEIGHT
* s
, BMPWIDTH_solitaire_suitsi
,
632 x
+1, y
+1, CARD_GFX_WIDTH
, CARD_GFX_HEIGHT
);
634 draw_card_ext( x
, y
, false, cursor
);
641 static void init_help(void)
646 char *para
= helptext
;
648 rb
->lcd_getstringsize(" ", &w_space
, &h
);
649 displaylines
= LCD_HEIGHT
/ h
;
650 para_len
= rb
->strlen(para
);
658 next
= rb
->strtok_r(para
, " ", &store
);
661 rb
->lcd_getstringsize(next
, &w
, NULL
);
664 if (x
+ w
> LCD_WIDTH
)
670 next
[-1] = ' '; /* re-concatenate string */
676 next
= rb
->strtok_r(NULL
, " ", &store
);
680 para
+= para_len
+ 1;
681 para_len
= rb
->strlen(para
);
686 enum help
{ HELP_QUIT
, HELP_USB
};
688 /* help for the not so intuitive interface */
689 enum help
solitaire_help( void )
693 int lastbutton
= BUTTON_NONE
;
694 bool fixed
= (displaylines
>= helplines
);
698 char *text
= helptext
;
699 int line
= fixed
? (displaylines
- helplines
) / 2 : 0;
702 rb
->lcd_clear_display();
704 for (i
= 0; i
< start
+ displaylines
; i
++)
707 rb
->lcd_puts(0, line
++, text
);
708 text
+= rb
->strlen(text
) + 1;
712 button
= rb
->button_get( true );
717 if( lastbutton
!= SOL_UP_PRE
)
720 case SOL_UP
|BUTTON_REPEAT
:
722 if (!fixed
&& start
> 0)
728 if( lastbutton
!= SOL_DOWN_PRE
)
731 case SOL_DOWN
|BUTTON_REPEAT
:
733 if (!fixed
&& start
< helplines
- displaylines
)
744 if( rb
->default_event_handler( button
) == SYS_USB_CONNECTED
)
748 if( button
!= BUTTON_NONE
)
756 * Custom menu / options
759 #define CFGFILE_VERSION 0
765 struct sol_config sol_disk
= {0};
766 struct sol_config sol
;
768 static struct configdata config
[] = {
769 { TYPE_INT
, 0, 1, { .int_p
= &sol_disk
.draw_type
}, "draw_type", NULL
}
772 static const struct opt_items drawcards
[2] = {
773 { "Draw Three Cards", -1 },
774 { "Draw One Card", -1 },
777 void solitaire_init(void);
779 /* menu return codes */
780 enum { MENU_RESUME
, MENU_SAVE_AND_QUIT
, MENU_QUIT
, MENU_USB
};
783 int solitaire_menu_cb(int action
, const struct menu_item_ex
*this_item
)
785 int i
= (intptr_t)this_item
;
786 if( action
== ACTION_REQUEST_MENUITEM
)
788 if((!_ingame
&& (i
==0 || i
==5)) || ( _ingame
&& i
==2 ))
789 return ACTION_EXIT_MENUITEM
;
794 int solitaire_menu(bool in_game
)
799 MENUITEM_STRINGLIST(menu
, "Solitaire Menu", solitaire_menu_cb
,
800 "Resume Game", "Start New Game",
802 "Help", "Playback Control",
803 "Save and Quit", "Quit");
808 switch (rb
->do_menu(&menu
, &selected
, NULL
, false))
811 result
= MENU_RESUME
;
814 case MENU_ATTACHED_USB
:
819 result
= MENU_RESUME
;
824 result
= MENU_RESUME
;
828 if (rb
->set_option("Draw Cards Option", &sol
.draw_type
,
829 INT
, drawcards
, 2, NULL
))
834 if (solitaire_help() == HELP_USB
)
839 playback_control(NULL
);
843 result
= MENU_SAVE_AND_QUIT
;
858 /* player's cursor */
860 /* player's cursor column num */
867 card_t deck
[ NUM_CARDS
];
869 /* the remaining cards */
870 /* first card of the remains' stack */
872 /* upper visible card from the remains' stack */
874 /* number of cards drawn from the remains stack - 1 */
876 /* number of cards per draw of the remains' stack */
879 /* the 7 game columns */
881 /* the 4 final stacks */
885 * Card handling routines
888 int next_random_card( card_t
*deck
)
892 r
= rb
->rand()%(NUM_CARDS
)+1;
897 i
= (i
+ 1)%(NUM_CARDS
);
898 if( !deck
[i
].used
) r
--;
907 /* initialize the game */
908 void solitaire_init( void )
914 /* number of cards that are drawn on the remains' stack (by pressing F2) */
915 if( sol
.draw_type
== 0 )
925 for( i
=0; i
<SUITS
; i
++ )
927 for( j
=0; j
<CARDS_PER_SUIT
; j
++ )
929 #define card deck[i*CARDS_PER_SUIT+j]
934 card
.next
= NOT_A_CARD
;
939 /* deal the cards ... */
940 /* ... in the columns */
941 for( i
=0; i
<COL_NUM
; i
++ )
944 for( j
=0; j
<=i
; j
++ )
946 if( c
== NOT_A_CARD
)
948 cols
[i
] = next_random_card( deck
);
953 deck
[c
].next
= next_random_card( deck
);
957 deck
[c
].known
= false;
961 /* ... shuffle what's left of the deck */
962 rem
= next_random_card(deck
);
965 for( i
=1; i
< NUM_CARDS
- COL_NUM
* (COL_NUM
+ 1)/2; i
++ )
967 deck
[c
].next
= next_random_card( deck
);
971 /* we now finished dealing the cards. The game can start ! (at last) */
974 for( i
= 0; i
<SUITS
; i
++ )
976 stacks
[i
] = NOT_A_CARD
;
979 /* the cursor starts on upper left card */
983 /* no card is selected */
984 sel_card
= NOT_A_CARD
;
986 /* init the remainder */
987 cur_rem
= NOT_A_CARD
;
992 /* find the column number in which 'card' can be found */
993 int find_card_col( int card
)
998 if( card
== NOT_A_CARD
) return NOT_A_COL
;
1000 for( i
=0; i
<COL_NUM
; i
++ )
1003 while( c
!= NOT_A_CARD
)
1005 if( c
== card
) return i
;
1010 for( i
=0; i
<SUITS
; i
++ )
1013 while( c
!= NOT_A_CARD
)
1015 if( c
== card
) return STACKS_COL
+ i
;
1023 /* find the card preceding 'card' */
1024 /* if it doesn't exist, return NOT_A_CARD */
1025 int find_prev_card( int card
){
1028 for( i
=0; i
< NUM_CARDS
; i
++ )
1030 if( deck
[i
].next
== card
) return i
;
1036 /* find the last card of a given column */
1037 int find_last_card( int col
)
1045 else if( col
< REM_COL
)
1047 c
= stacks
[col
- STACKS_COL
];
1058 while(deck
[c
].next
!= NOT_A_CARD
)
1064 enum move
{ MOVE_OK
, MOVE_NOT_OK
};
1066 enum move
move_card( int dest_col
, int src_card
)
1068 /* the column on which to take src_card */
1071 /* the last card of dest_col */
1074 /* the card under src_card */
1077 /* you can't move no card (at least, it doesn't have any consequence) */
1078 if( src_card
== NOT_A_CARD
) return MOVE_NOT_OK
;
1079 /* you can't put a card back on the remains' stack */
1080 if( dest_col
== REM_COL
) return MOVE_NOT_OK
;
1081 /* you can't move an unknown card */
1082 if( !deck
[src_card
].known
) return MOVE_NOT_OK
;
1084 src_col
= find_card_col( src_card
);
1085 dest_card
= find_last_card( dest_col
);
1086 src_card_prev
= find_prev_card( src_card
);
1088 /* you can't move more than one card at a time from the final stack */
1089 /* to the rest of the game */
1090 if( src_col
>= COL_NUM
&& src_col
< REM_COL
1091 && deck
[src_card
].next
!= NOT_A_CARD
)
1096 /* if we (that means dest) are on one of the 7 columns ... */
1097 if( dest_col
< COL_NUM
)
1099 /* ... check is we are on an empty color and that the src is a king */
1100 if( dest_card
== NOT_A_CARD
1101 && deck
[src_card
].num
== CARDS_PER_SUIT
- 1 )
1103 /* this is a winning combination */
1104 cols
[dest_col
] = src_card
;
1106 /* ... or check if the cards follow one another and have
1107 * different colorsuit */
1108 else if(( deck
[dest_card
].suit
+ deck
[src_card
].suit
)%2==1
1109 && deck
[dest_card
].num
== deck
[src_card
].num
+ 1 )
1111 /* this is a winning combination */
1112 deck
[dest_card
].next
= src_card
;
1114 /* ... or, humpf, well that's not good news */
1117 /* this is not a winning combination */
1121 /* if we are on one of the 4 final stacks ... */
1122 else if( dest_col
< REM_COL
)
1124 /* ... check if we are on an empty stack... */
1125 if( dest_card
== NOT_A_CARD
)
1127 /* ... and the src is an ace and this is the correct final stack */
1128 if( deck
[src_card
].num
== 0
1129 && deck
[src_card
].suit
== dest_col
- STACKS_COL
)
1131 /* this is a winning combination */
1132 stacks
[dest_col
- STACKS_COL
] = src_card
;
1136 /* this is not a winning combination */
1140 else /* non-empty stack */
1142 /* ...check if the cards follow one another, have the same suit and
1143 * {that src has no .next element or is from the remains' stack} */
1144 if( deck
[dest_card
].suit
== deck
[src_card
].suit
1145 && deck
[dest_card
].num
+ 1 == deck
[src_card
].num
1146 && (deck
[src_card
].next
== NOT_A_CARD
|| src_col
== REM_COL
) )
1148 /* this is a winning combination */
1149 deck
[dest_card
].next
= src_card
;
1151 /* ... or, well that's not good news */
1154 /* this is not a winning combination */
1159 /* if we are on the remains' stack */
1162 /* you can't move a card back to the remains' stack */
1166 /* if the src card is from the remains' stack, we don't want to take
1167 * the following cards */
1168 if( src_col
== REM_COL
)
1170 /* if src card is the first card from the stack */
1171 if( src_card_prev
== NOT_A_CARD
)
1173 rem
= deck
[src_card
].next
;
1175 /* if src card is not the first card from the stack */
1178 deck
[src_card_prev
].next
= deck
[src_card
].next
;
1180 deck
[src_card
].next
= NOT_A_CARD
;
1181 cur_rem
= src_card_prev
;
1184 /* if the src card is from somewhere else, just take everything */
1187 if( src_card_prev
== NOT_A_CARD
)
1189 if( src_col
< COL_NUM
)
1191 cols
[src_col
] = NOT_A_CARD
;
1195 stacks
[src_col
- STACKS_COL
] = NOT_A_CARD
;
1200 deck
[src_card_prev
].next
= NOT_A_CARD
;
1201 deck
[src_card_prev
].known
= true;
1204 sel_card
= NOT_A_CARD
;
1209 enum { SOLITAIRE_WIN
, SOLITAIRE_SAVE_AND_QUIT
, SOLITAIRE_QUIT
, SOLITAIRE_USB
};
1212 * Bouncing cards at the end of the game
1215 #define BC_ACCEL ((1<<16)*LCD_HEIGHT/128)
1216 #define BC_MYSPEED (6*BC_ACCEL)
1217 #define BC_MXSPEED (6*LCD_HEIGHT/128)
1219 int bouncing_cards( void )
1221 int i
, j
, x
, vx
, y
, fp_y
, fp_vy
, button
;
1223 /* flush the button queue */
1224 while( ( button
= rb
->button_get( false ) ) != BUTTON_NONE
)
1226 if( rb
->default_event_handler( button
) == SYS_USB_CONNECTED
)
1227 return SOLITAIRE_USB
;
1231 for( i
= CARDS_PER_SUIT
-1; i
>=0; i
-- )
1233 for( j
= 0; j
< SUITS
; j
++ )
1235 x
= LCD_WIDTH
-(CARD_WIDTH
*4+4+MARGIN
)+CARD_WIDTH
*j
+j
+1;
1239 vx
= rb
->rand() % (4*BC_MXSPEED
/3-2) - BC_MXSPEED
;
1243 vx
= rb
->rand() % (4*BC_MXSPEED
/3) - BC_MXSPEED
;
1248 fp_vy
= -rb
->rand() % BC_MYSPEED
;
1250 while( x
< LCD_WIDTH
&& x
+ CARD_WIDTH
> 0 )
1255 if( fp_y
>= (LCD_HEIGHT
-CARD_HEIGHT
) << 16 )
1258 fp_y
= (LCD_HEIGHT
-CARD_HEIGHT
) << 16;
1261 draw_card( &deck
[j
*CARDS_PER_SUIT
+i
], x
, y
,
1263 rb
->lcd_update_rect( x
<0?0:x
, y
<0?0:y
,
1264 CARD_WIDTH
, CARD_HEIGHT
);
1266 button
= rb
->button_get_w_tmo( 2 );
1267 if( rb
->default_event_handler( button
) == SYS_USB_CONNECTED
)
1268 return SOLITAIRE_USB
;
1269 if( button
== SOL_QUIT
|| button
== SOL_MOVE
)
1270 return SOLITAIRE_WIN
;
1274 return SOLITAIRE_WIN
;
1278 * Game save/load routines
1280 void get_save_filename( char *buf
)
1283 rb
->strcpy( buf
, rb
->plugin_get_current_filename() );
1284 s
= rb
->strrchr( buf
, '/' ) + 1;
1286 rb
->strcat( s
, "sol.save" );
1289 int open_save_file( int flags
)
1292 get_save_filename( buf
);
1293 return rb
->open( buf
, flags
);
1296 void delete_save_file( void )
1299 get_save_filename( buf
);
1306 int save_write( int fd
, const void *buf
, size_t count
, int *checksum
)
1309 if( rb
->write( fd
, buf
, count
) < (ssize_t
)count
)
1311 for( i
= 0; i
< count
; i
++ )
1312 *checksum
+= (int)(((const char *)buf
)[i
]);
1319 int save_read( int fd
, void *buf
, size_t count
, int *checksum
)
1322 if( rb
->read( fd
, buf
, count
) < (ssize_t
)count
)
1324 for( i
= 0; i
< count
; i
++ )
1325 *checksum
-= (int)(((const char *)buf
)[i
]);
1329 int save_game( void )
1331 int fd
= open_save_file( O_CREAT
|O_WRONLY
|O_TRUNC
);
1335 if( save_write( fd
, &cur_card
, sizeof( int ), &checksum
)
1336 || save_write( fd
, &cur_col
, sizeof( int ), &checksum
)
1337 || save_write( fd
, &sel_card
, sizeof( int ), &checksum
)
1338 || save_write( fd
, deck
, NUM_CARDS
* sizeof( card_t
), &checksum
)
1339 || save_write( fd
, &rem
, sizeof( int ), &checksum
)
1340 || save_write( fd
, &cur_rem
, sizeof( int ), &checksum
)
1341 || save_write( fd
, &count_rem
, sizeof( int ), &checksum
)
1342 || save_write( fd
, &cards_per_draw
, sizeof( int ), &checksum
)
1343 || save_write( fd
, cols
, COL_NUM
* sizeof( int ), &checksum
)
1344 || save_write( fd
, stacks
, SUITS
* sizeof( int ), &checksum
)
1345 || ( rb
->write( fd
, &checksum
, sizeof( int ) ) < (ssize_t
)(sizeof( int ) ) ) )
1348 rb
->splash( 2*HZ
, "Error while saving game. Aborting." );
1355 int load_game( void )
1357 int checksum
, retval
;
1359 int fd
= open_save_file( O_RDONLY
);
1363 retval
= 0; /* Assume good case */
1364 if( ( rb
->lseek( fd
, -sizeof( int ), SEEK_END
) == -((ssize_t
)sizeof( int ))-1 )
1365 || ( rb
->read( fd
, &checksum
, sizeof( int ) ) < ((ssize_t
)sizeof( int )) )
1366 || ( rb
->lseek( fd
, 0, SEEK_SET
) == -1 )
1367 || save_read( fd
, &cur_card
, sizeof( int ), &checksum
)
1368 || save_read( fd
, &cur_col
, sizeof( int ), &checksum
)
1369 || save_read( fd
, &sel_card
, sizeof( int ), &checksum
)
1370 || save_read( fd
, deck
, NUM_CARDS
* sizeof( card_t
), &checksum
)
1371 || save_read( fd
, &rem
, sizeof( int ), &checksum
)
1372 || save_read( fd
, &cur_rem
, sizeof( int ), &checksum
)
1373 || save_read( fd
, &count_rem
, sizeof( int ), &checksum
)
1374 || save_read( fd
, &cards_per_draw
, sizeof( int ), &checksum
)
1375 || save_read( fd
, cols
, COL_NUM
* sizeof( int ), &checksum
)
1376 || save_read( fd
, stacks
, SUITS
* sizeof( int ), &checksum
) )
1378 rb
->splash( 2*HZ
, "Error while loading saved game. Aborting." );
1381 else if( checksum
!= 42 )
1383 rb
->splash( 2*HZ
, "Save file was corrupted. Aborting." );
1393 * The main game loop
1395 * If skipmenu is defined to SOLITAIRE_QUIT, the menu will be skipped and
1399 int solitaire( int skipmenu
)
1403 int button
, lastbutton
= 0;
1405 int biggest_col_length
;
1407 rb
->srand( *rb
->current_tick
);
1408 if( skipmenu
!= SOLITAIRE_QUIT
)
1410 switch( solitaire_menu(false) )
1413 return SOLITAIRE_QUIT
;
1416 return SOLITAIRE_USB
;
1423 rb
->lcd_clear_display();
1425 /* get the biggest column length so that display can be "optimized" */
1426 biggest_col_length
= 0;
1428 for(i
=0;i
<COL_NUM
;i
++)
1433 if( c
!= NOT_A_CARD
)
1437 /* don't include the last card in the column length. */
1438 if( deck
[c
].next
== NOT_A_CARD
)
1440 break; /* no successor: get outta here. */
1451 /* make column distinguishable from an empty column,
1452 * and avoid division by zero while displaying */
1456 if( j
> biggest_col_length
)
1457 biggest_col_length
= j
;
1460 /* check if there are cards remaining in the game. */
1461 /* if there aren't any, that means you won :) */
1462 if( biggest_col_length
== 0 && rem
== NOT_A_CARD
)
1465 rb
->splash( HZ
, "You Won :)" );
1466 return bouncing_cards();
1469 /* draw the columns */
1470 for( i
= 0; i
< COL_NUM
; i
++ )
1476 if( c
== NOT_A_CARD
)
1478 /* draw the cursor on empty columns */
1481 draw_cursor( MARGIN
+ i
* (CARD_WIDTH
1482 +(LCD_WIDTH
-COL_NUM
*CARD_WIDTH
-2*MARGIN
)/(COL_NUM
-1)),
1488 draw_card( &deck
[c
], MARGIN
+ i
* (CARD_WIDTH
1489 +(LCD_WIDTH
-COL_NUM
*CARD_WIDTH
-2*MARGIN
)/(COL_NUM
-1)),
1490 j
, c
== sel_card
, c
== cur_card
);
1494 if( c
== NOT_A_CARD
) break;
1496 /* This is where we change the spacing between cards so that
1497 * they don't overflow out of the LCD */
1500 else if( deck
[h
].known
)
1501 j
+= min( SYMBOL_HEIGHT
,
1502 2 * (LCD_HEIGHT
- CARD_START
- CARD_HEIGHT
- MARGIN
)
1503 / biggest_col_length
);
1505 j
+= min( SYMBOL_HEIGHT
/ 2,
1506 (LCD_HEIGHT
- CARD_START
- CARD_HEIGHT
- MARGIN
)
1507 / biggest_col_length
);
1511 /* draw the stacks */
1512 for( i
=0; i
<SUITS
; i
++ )
1514 c
= find_last_card( STACKS_COL
+ i
);
1516 if( c
!= NOT_A_CARD
)
1518 draw_card( &deck
[c
],
1519 LCD_WIDTH
-(CARD_WIDTH
*4+4+MARGIN
)+CARD_WIDTH
*i
+i
+1,
1521 c
== sel_card
, cur_col
== STACKS_COL
+ i
);
1525 draw_empty_stack( i
,
1526 LCD_WIDTH
-(CARD_WIDTH
*4+4+MARGIN
)+CARD_WIDTH
*i
+i
+1,
1527 MARGIN
, cur_col
== STACKS_COL
+ i
);
1531 /* draw the remains */
1532 if( rem
!= NOT_A_CARD
&&
1533 ( cur_rem
== NOT_A_CARD
|| deck
[cur_rem
].next
!= NOT_A_CARD
) )
1535 /* gruik ! (we want to display a card back) */
1536 deck
[rem
].known
= false;
1537 draw_card( &deck
[rem
], MARGIN
, MARGIN
, false, false );
1538 deck
[rem
].known
= true;
1541 if( rem
!= NOT_A_CARD
&& cur_rem
!= NOT_A_CARD
)
1547 while( prevcard
!= cur_rem
&& count_rem
< cards_per_draw
-1 )
1549 prevcard
= deck
[prevcard
].next
;
1554 j
= CARD_WIDTH
+2*MARGIN
+1;
1555 for( i
= 0; i
< count_rem
; i
++ )
1556 prevcard
= find_prev_card(prevcard
);
1557 for( i
= 0; i
<= count_rem
; i
++ )
1559 draw_card( &deck
[prevcard
], j
,
1560 MARGIN
, sel_card
== prevcard
,
1561 cur_card
== prevcard
);
1562 prevcard
= deck
[prevcard
].next
;
1566 if( ( cur_rem
== NOT_A_CARD
|| rem
== NOT_A_CARD
)
1567 && cur_col
== REM_COL
)
1569 draw_cursor( CARD_WIDTH
+2*MARGIN
+1, MARGIN
);
1574 /* what to do when a key is pressed ... */
1575 button
= rb
->button_get( true );
1576 #if (CONFIG_KEYPAD == SANSA_E200_PAD) || (CONFIG_KEYPAD == SANSA_FUZE_PAD)
1577 if (button
&(BUTTON_SCROLL_BACK
|BUTTON_SCROLL_FWD
))
1578 button
= button
& (~BUTTON_REPEAT
);
1582 /* move cursor to the last card of the previous column
1583 * or to the previous final stack
1584 * or to the remains stack */
1586 #ifdef SOL_RIGHT_PRE
1587 if( lastbutton
!= SOL_RIGHT_PRE
)
1590 if( cur_col
>= COL_NUM
)
1594 else if( cur_col
== COL_NUM
- 1 )
1600 cur_col
= (cur_col
+1)%(REM_COL
+1);
1602 if(cur_col
== REM_COL
)
1607 cur_card
= find_last_card( cur_col
);
1610 /* move cursor to the last card of the next column
1611 * or to the next final stack
1612 * or to the remains stack */
1615 if( lastbutton
!= SOL_LEFT_PRE
)
1622 else if( cur_col
>= COL_NUM
)
1624 cur_col
= COL_NUM
- 1;
1628 cur_col
= (cur_col
+ REM_COL
)%(REM_COL
+1);
1630 if( cur_col
== REM_COL
)
1635 cur_card
= find_last_card( cur_col
);
1638 /* move cursor to card that's bellow */
1641 if( lastbutton
!= SOL_DOWN_PRE
)
1644 case SOL_DOWN
|BUTTON_REPEAT
:
1646 if( cur_col
>= COL_NUM
)
1648 cur_col
= (cur_col
- COL_NUM
+ 1)%(SUITS
+ 1) + COL_NUM
;
1649 if( cur_col
== REM_COL
)
1655 cur_card
= find_last_card( cur_col
);
1659 if( cur_card
== NOT_A_CARD
) break;
1660 if( deck
[cur_card
].next
!= NOT_A_CARD
)
1662 cur_card
= deck
[cur_card
].next
;
1666 cur_card
= cols
[cur_col
];
1667 while( !deck
[ cur_card
].known
1668 && deck
[cur_card
].next
!= NOT_A_CARD
)
1670 cur_card
= deck
[cur_card
].next
;
1675 /* move cursor to card that's above */
1678 if( lastbutton
!= SOL_UP_PRE
)
1681 case SOL_UP
|BUTTON_REPEAT
:
1683 if( cur_col
>= COL_NUM
)
1685 cur_col
= (cur_col
- COL_NUM
+ SUITS
)%(SUITS
+ 1) + COL_NUM
;
1686 if( cur_col
== REM_COL
)
1692 cur_card
= find_last_card( cur_col
);
1696 if( cur_card
== NOT_A_CARD
) break;
1698 cur_card
= find_prev_card( cur_card
);
1699 if( cur_card
== NOT_A_CARD
)
1701 cur_card
= find_last_card( cur_col
);
1703 } while( deck
[cur_card
].next
!= NOT_A_CARD
1704 && !deck
[cur_card
].known
);
1707 /* Try to put card under cursor on one of the stacks */
1709 #ifdef SOL_CUR2STACK_PRE
1710 if( lastbutton
!= SOL_CUR2STACK_PRE
)
1713 move_card( deck
[cur_card
].suit
+ STACKS_COL
, cur_card
);
1716 /* Move cards arround, Uncover cards, ... */
1719 if( lastbutton
!= SOL_MOVE_PRE
)
1723 if( sel_card
== NOT_A_CARD
)
1725 if( cur_card
!= NOT_A_CARD
)
1727 if( deck
[cur_card
].next
== NOT_A_CARD
1728 && !deck
[cur_card
].known
)
1730 /* reveal a hidden card */
1731 deck
[cur_card
].known
= true;
1733 else if( cur_col
== REM_COL
&& cur_rem
== NOT_A_CARD
)
1740 sel_card
= cur_card
;
1744 else if( sel_card
== cur_card
)
1746 /* unselect card or try putting card on
1747 * one of the 4 stacks */
1748 if( move_card( deck
[sel_card
].suit
+ COL_NUM
, sel_card
)
1749 == MOVE_OK
&& cur_col
== REM_COL
)
1753 sel_card
= NOT_A_CARD
;
1757 /* try moving cards */
1758 /* The flexible move must not be used from the remains stack. */
1759 if (find_card_col(sel_card
) == REM_COL
)
1761 if (move_card( cur_col
, sel_card
) == MOVE_NOT_OK
)
1762 sel_card
= NOT_A_CARD
;
1767 if (move_card( cur_col
, sel_card
) == MOVE_OK
)
1769 sel_card
= find_prev_card(sel_card
);
1770 } while (sel_card
!= NOT_A_CARD
);
1775 /* If the card on the top of the remains can be put where
1776 * the cursor is, go ahead */
1778 #ifdef SOL_REM2CUR_PRE
1779 if( lastbutton
!= SOL_REM2CUR_PRE
)
1782 move_card( cur_col
, cur_rem
);
1785 /* If the card on top of the remains can be put on one
1786 * of the stacks, do so */
1788 #ifdef SOL_REM2STACK_PRE
1789 if( lastbutton
!= SOL_REM2STACK_PRE
)
1792 move_card( deck
[cur_rem
].suit
+ COL_NUM
, cur_rem
);
1797 if( sel_card
!= NOT_A_CARD
)
1799 /* unselect selected card */
1800 sel_card
= NOT_A_CARD
;
1803 if( rem
!= NOT_A_CARD
&& cur_rem
!= NOT_A_CARD
)
1811 /* unselect selected card or ...
1812 * draw new cards from the remains of the deck */
1815 if( lastbutton
!= SOL_DRAW_PRE
)
1818 if( sel_card
!= NOT_A_CARD
)
1820 /* unselect selected card */
1821 sel_card
= NOT_A_CARD
;
1824 if( rem
!= NOT_A_CARD
)
1826 int cur_rem_old
= cur_rem
;
1828 /* draw new cards form the remains of the deck */
1829 if( cur_rem
== NOT_A_CARD
)
1831 /*if the cursor card is null*/
1833 i
= cards_per_draw
- 1;
1841 while( i
> 0 && deck
[cur_rem
].next
!= NOT_A_CARD
)
1843 cur_rem
= deck
[cur_rem
].next
;
1847 /* test if any cards are really left on
1848 * the remains' stack */
1849 if( i
== cards_per_draw
)
1851 cur_rem
= NOT_A_CARD
;
1854 /* if cursor was on remains' stack when new cards were
1855 * drawn, put cursor on top of remains' stack */
1856 if( cur_col
== REM_COL
&& cur_card
== cur_rem_old
)
1859 sel_card
= NOT_A_CARD
;
1869 switch( solitaire_menu(true) )
1871 case MENU_SAVE_AND_QUIT
:
1872 return SOLITAIRE_SAVE_AND_QUIT
;
1875 return SOLITAIRE_QUIT
;
1878 return SOLITAIRE_USB
;
1883 return SOLITAIRE_SAVE_AND_QUIT
;
1886 if( rb
->default_event_handler( button
) == SYS_USB_CONNECTED
)
1887 return SOLITAIRE_USB
;
1891 if( button
!= BUTTON_NONE
)
1892 lastbutton
= button
;
1894 /* fix incoherences concerning cur_col and cur_card */
1895 c
= find_card_col( cur_card
);
1896 if( c
!= NOT_A_COL
&& c
!= cur_col
)
1897 cur_card
= find_last_card( cur_col
);
1899 if( cur_card
== NOT_A_CARD
1900 && find_last_card( cur_col
) != NOT_A_CARD
)
1901 cur_card
= find_last_card( cur_col
);
1908 * Plugin entry point
1911 enum plugin_status
plugin_start(const void* parameter
)
1918 rb
->splash( HZ
, "Welcome to Solitaire!" );
1920 configfile_load(CONFIG_FILENAME
, config
,
1921 sizeof(config
) / sizeof(config
[0]), CFGFILE_VERSION
);
1922 rb
->memcpy(&sol
, &sol_disk
, sizeof(sol
)); /* copy to running config */
1924 if( load_game() == 0 )
1926 rb
->splash( HZ
, "Resuming saved game." );
1927 result
= SOLITAIRE_QUIT
;
1930 result
= SOLITAIRE_WIN
;
1935 * Keep playing if a game was won (that means display the menu after
1936 * winning instead of quiting) */
1937 while( ( result
= solitaire( result
) ) == SOLITAIRE_WIN
);
1939 if( result
!= SOLITAIRE_QUIT
)
1940 /* result == SOLITAIRE_USB || result == SOLITAIRE_SAVE_AND_QUIT */
1943 if (rb
->memcmp(&sol
, &sol_disk
, sizeof(sol
))) /* save settings if changed */
1945 rb
->memcpy(&sol_disk
, &sol
, sizeof(sol
));
1946 configfile_save(CONFIG_FILENAME
, config
,
1947 sizeof(config
) / sizeof(config
[0]), CFGFILE_VERSION
);
1950 /* Exit the plugin */
1951 return ( result
== SOLITAIRE_USB
) ? PLUGIN_USB_CONNECTED
: PLUGIN_OK
;