1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2007 Tom Ross
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 "lib/configfile.h"
23 #include "lib/display_text.h"
24 #include "lib/playback_control.h"
26 #include "pluginbitmaps/pegbox_header.h"
27 #include "pluginbitmaps/pegbox_pieces.h"
31 #define CONFIG_FILE_NAME "pegbox.cfg"
33 #define ROWS 8 /* Number of rows on each board */
34 #define COLS 12 /* Number of columns on each board */
35 #define NUM_LEVELS 15 /* Number of levels */
46 #if CONFIG_KEYPAD == RECORDER_PAD
47 #define PEGBOX_SELECT BUTTON_ON
48 #define PEGBOX_QUIT BUTTON_OFF
49 #define PEGBOX_RESTART BUTTON_F2
50 #define PEGBOX_LVL_UP BUTTON_F1
51 #define PEGBOX_LVL_DOWN BUTTON_F3
52 #define PEGBOX_UP BUTTON_UP
53 #define PEGBOX_DOWN BUTTON_DOWN
54 #define PEGBOX_RIGHT BUTTON_RIGHT
55 #define PEGBOX_LEFT BUTTON_LEFT
57 #define SELECT_TEXT "ON"
58 #define QUIT_TEXT "OFF"
59 #define RESTART_TEXT "F2"
60 #define LVL_UP_TEXT "F1"
61 #define LVL_DOWN_TEXT "F3"
63 #elif CONFIG_KEYPAD == ONDIO_PAD
64 #define PEGBOX_SELECT BUTTON_OFF
65 #define PEGBOX_QUIT (BUTTON_MENU | BUTTON_LEFT)
66 #define PEGBOX_RESTART (BUTTON_MENU | BUTTON_RIGHT)
67 #define PEGBOX_LVL_UP (BUTTON_MENU | BUTTON_UP)
68 #define PEGBOX_LVL_DOWN (BUTTON_MENU | BUTTON_DOWN)
69 #define PEGBOX_UP BUTTON_UP
70 #define PEGBOX_DOWN BUTTON_DOWN
71 #define PEGBOX_RIGHT BUTTON_RIGHT
72 #define PEGBOX_LEFT BUTTON_LEFT
74 #define SELECT_TEXT "OFF"
75 #define QUIT_TEXT "M+LEFT"
76 #define RESTART_TEXT "M+RIGHT"
77 #define LVL_UP_TEXT "M+UP"
78 #define LVL_DOWN_TEXT "M+DOWN"
80 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
81 (CONFIG_KEYPAD == IRIVER_H300_PAD)
82 #define PEGBOX_SELECT BUTTON_SELECT
83 #define PEGBOX_QUIT BUTTON_OFF
84 #define PEGBOX_RESTART BUTTON_ON
85 #define PEGBOX_LVL_UP BUTTON_MODE
86 #define PEGBOX_LVL_DOWN BUTTON_REC
87 #define PEGBOX_UP BUTTON_UP
88 #define PEGBOX_DOWN BUTTON_DOWN
89 #define PEGBOX_RIGHT BUTTON_RIGHT
90 #define PEGBOX_LEFT BUTTON_LEFT
92 #define SELECT_TEXT "NAVI"
93 #define QUIT_TEXT "OFF"
94 #define RESTART_TEXT "ON"
95 #define LVL_UP_TEXT "AB"
96 #define LVL_DOWN_TEXT "REC"
98 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
99 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
100 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
101 #define PEGBOX_SELECT (BUTTON_SELECT|BUTTON_RIGHT)
102 #define PEGBOX_QUIT (BUTTON_SELECT|BUTTON_PLAY)
103 #define PEGBOX_RESTART (BUTTON_SELECT|BUTTON_LEFT)
104 #define PEGBOX_LVL_UP (BUTTON_SELECT|BUTTON_MENU)
105 #define PEGBOX_UP BUTTON_MENU
106 #define PEGBOX_DOWN BUTTON_PLAY
107 #define PEGBOX_RIGHT BUTTON_RIGHT
108 #define PEGBOX_LEFT BUTTON_LEFT
110 #define SELECT_TEXT "SELECT+RIGHT"
111 #define QUIT_TEXT "SELECT+PLAY"
112 #define RESTART_TEXT "SELECT+LEFT"
113 #define LVL_UP_TEXT "SELECT+MENU"
114 #define LVL_DOWN_TEXT "-"
116 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
117 #define PEGBOX_SELECT BUTTON_SELECT
118 #define PEGBOX_QUIT BUTTON_POWER
119 #define PEGBOX_RESTART BUTTON_REC
120 #define PEGBOX_LVL_UP BUTTON_PLAY
121 #define PEGBOX_UP BUTTON_UP
122 #define PEGBOX_DOWN BUTTON_DOWN
123 #define PEGBOX_RIGHT BUTTON_RIGHT
124 #define PEGBOX_LEFT BUTTON_LEFT
126 #define SELECT_TEXT "SELECT"
127 #define QUIT_TEXT "OFF"
128 #define RESTART_TEXT "REC"
129 #define LVL_UP_TEXT "PLAY"
130 #define LVL_DOWN_TEXT "-"
132 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
133 #define PEGBOX_SELECT BUTTON_MODE
134 #define PEGBOX_QUIT BUTTON_PLAY
135 #define PEGBOX_RESTART (BUTTON_EQ|BUTTON_MODE)
136 #define PEGBOX_LVL_UP (BUTTON_EQ|BUTTON_UP)
137 #define PEGBOX_LVL_DOWN (BUTTON_EQ|BUTTON_DOWN)
138 #define PEGBOX_UP BUTTON_UP
139 #define PEGBOX_DOWN BUTTON_DOWN
140 #define PEGBOX_RIGHT BUTTON_RIGHT
141 #define PEGBOX_LEFT BUTTON_LEFT
143 #define SELECT_TEXT "MODE"
144 #define QUIT_TEXT "PLAY"
145 #define RESTART_TEXT "EQ+MODE"
146 #define LVL_UP_TEXT "EQ+UP"
147 #define LVL_DOWN_TEXT "EQ+DOWN"
149 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
150 #define PEGBOX_SELECT BUTTON_PLAY
151 #define PEGBOX_QUIT BUTTON_POWER
152 #define PEGBOX_RESTART (BUTTON_FF|BUTTON_REPEAT)
153 #define PEGBOX_LVL_UP (BUTTON_FF|BUTTON_SCROLL_UP)
154 #define PEGBOX_LVL_DOWN (BUTTON_FF|BUTTON_SCROLL_DOWN)
155 #define PEGBOX_UP BUTTON_SCROLL_UP
156 #define PEGBOX_DOWN BUTTON_SCROLL_DOWN
157 #define PEGBOX_RIGHT BUTTON_RIGHT
158 #define PEGBOX_LEFT BUTTON_LEFT
160 #define SELECT_TEXT "PLAY"
161 #define QUIT_TEXT "OFF"
162 #define RESTART_TEXT "LONG FF"
163 #define LVL_UP_TEXT "FF+SCROLL_UP"
164 #define LVL_DOWN_TEXT "FF+SCROLL_DOWN"
166 #elif CONFIG_KEYPAD == SANSA_E200_PAD
167 #define PEGBOX_SELECT BUTTON_SELECT
168 #define PEGBOX_QUIT BUTTON_POWER
169 #define PEGBOX_RESTART BUTTON_REC
170 #define PEGBOX_LVL_UP BUTTON_SCROLL_BACK
171 #define PEGBOX_LVL_DOWN BUTTON_SCROLL_FWD
172 #define PEGBOX_UP BUTTON_UP
173 #define PEGBOX_DOWN BUTTON_DOWN
174 #define PEGBOX_RIGHT BUTTON_RIGHT
175 #define PEGBOX_LEFT BUTTON_LEFT
177 #define SELECT_TEXT "SELECT"
178 #define QUIT_TEXT "POWER"
179 #define RESTART_TEXT "REC"
180 #define LVL_UP_TEXT "SCROLL BACK"
181 #define LVL_DOWN_TEXT "SCROLL FWD"
183 #elif CONFIG_KEYPAD == SANSA_FUZE_PAD
184 #define PEGBOX_SELECT BUTTON_SELECT|BUTTON_REL
185 #define PEGBOX_QUIT (BUTTON_HOME|BUTTON_REPEAT)
186 #define PEGBOX_RESTART (BUTTON_SELECT|BUTTON_LEFT)
187 #define PEGBOX_LVL_UP (BUTTON_SELECT|BUTTON_UP)
188 #define PEGBOX_LVL_DOWN (BUTTON_SELECT|BUTTON_DOWN)
189 #define PEGBOX_UP BUTTON_UP
190 #define PEGBOX_DOWN BUTTON_DOWN
191 #define PEGBOX_RIGHT BUTTON_RIGHT
192 #define PEGBOX_LEFT BUTTON_LEFT
194 #define SELECT_TEXT "SELECT"
195 #define QUIT_TEXT "HOME"
196 #define RESTART_TEXT "SELECT & LEFT"
197 #define LVL_UP_TEXT "SELECT & UP"
198 #define LVL_DOWN_TEXT "SELECT & DOWN"
200 #elif CONFIG_KEYPAD == GIGABEAT_PAD
201 #define PEGBOX_SELECT BUTTON_SELECT
202 #define PEGBOX_QUIT BUTTON_POWER
203 #define PEGBOX_RESTART BUTTON_A
204 #define PEGBOX_LVL_UP BUTTON_VOL_UP
205 #define PEGBOX_LVL_DOWN BUTTON_VOL_DOWN
206 #define PEGBOX_UP BUTTON_UP
207 #define PEGBOX_DOWN BUTTON_DOWN
208 #define PEGBOX_RIGHT BUTTON_RIGHT
209 #define PEGBOX_LEFT BUTTON_LEFT
211 #define SELECT_TEXT "SELECT"
212 #define QUIT_TEXT "POWER"
213 #define RESTART_TEXT "A"
214 #define LVL_UP_TEXT "VOL+"
215 #define LVL_DOWN_TEXT "VOL-"
217 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
218 #define PEGBOX_SELECT BUTTON_SELECT
219 #define PEGBOX_QUIT BUTTON_BACK
220 #define PEGBOX_RESTART BUTTON_MENU
221 #define PEGBOX_LVL_UP BUTTON_VOL_UP
222 #define PEGBOX_LVL_DOWN BUTTON_VOL_DOWN
223 #define PEGBOX_UP BUTTON_UP
224 #define PEGBOX_DOWN BUTTON_DOWN
225 #define PEGBOX_RIGHT BUTTON_RIGHT
226 #define PEGBOX_LEFT BUTTON_LEFT
228 #define SELECT_TEXT "SELECT"
229 #define QUIT_TEXT "BACK"
230 #define RESTART_TEXT "MENU"
231 #define LVL_UP_TEXT "VOL+"
232 #define LVL_DOWN_TEXT "VOL-"
234 #elif CONFIG_KEYPAD == MROBE100_PAD
235 #define PEGBOX_SELECT BUTTON_SELECT
236 #define PEGBOX_QUIT BUTTON_POWER
237 #define PEGBOX_RESTART BUTTON_PLAY
238 #define PEGBOX_LVL_UP BUTTON_MENU
239 #define PEGBOX_LVL_DOWN BUTTON_DISPLAY
240 #define PEGBOX_UP BUTTON_UP
241 #define PEGBOX_DOWN BUTTON_DOWN
242 #define PEGBOX_RIGHT BUTTON_RIGHT
243 #define PEGBOX_LEFT BUTTON_LEFT
245 #define SELECT_TEXT "SELECT"
246 #define QUIT_TEXT "POWER"
247 #define RESTART_TEXT "PLAY"
248 #define LVL_UP_TEXT "MENU"
249 #define LVL_DOWN_TEXT "DISPLAY"
251 #elif CONFIG_KEYPAD == SANSA_C200_PAD
252 #define PEGBOX_SELECT BUTTON_SELECT
253 #define PEGBOX_QUIT BUTTON_POWER
254 #define PEGBOX_RESTART BUTTON_REC
255 #define PEGBOX_LVL_UP BUTTON_VOL_UP
256 #define PEGBOX_LVL_DOWN BUTTON_VOL_DOWN
257 #define PEGBOX_UP BUTTON_UP
258 #define PEGBOX_DOWN BUTTON_DOWN
259 #define PEGBOX_RIGHT BUTTON_RIGHT
260 #define PEGBOX_LEFT BUTTON_LEFT
262 #define SELECT_TEXT "SELECT"
263 #define QUIT_TEXT "POWER"
264 #define RESTART_TEXT "REC"
265 #define LVL_UP_TEXT "VOL+"
266 #define LVL_DOWN_TEXT "VOL-"
268 #elif CONFIG_KEYPAD == SANSA_CLIP_PAD
269 #define PEGBOX_SELECT BUTTON_SELECT
270 #define PEGBOX_QUIT BUTTON_POWER
271 #define PEGBOX_RESTART BUTTON_HOME
272 #define PEGBOX_LVL_UP BUTTON_VOL_UP
273 #define PEGBOX_LVL_DOWN BUTTON_VOL_DOWN
274 #define PEGBOX_UP BUTTON_UP
275 #define PEGBOX_DOWN BUTTON_DOWN
276 #define PEGBOX_RIGHT BUTTON_RIGHT
277 #define PEGBOX_LEFT BUTTON_LEFT
279 #define SELECT_TEXT "SELECT"
280 #define QUIT_TEXT "POWER"
281 #define RESTART_TEXT "HOME"
282 #define LVL_UP_TEXT "VOL+"
283 #define LVL_DOWN_TEXT "VOL-"
285 #elif CONFIG_KEYPAD == SANSA_M200_PAD
286 #define PEGBOX_SELECT (BUTTON_SELECT | BUTTON_REL)
287 #define PEGBOX_QUIT BUTTON_POWER
288 #define PEGBOX_RESTART (BUTTON_SELECT | BUTTON_UP)
289 #define PEGBOX_LVL_UP BUTTON_VOL_UP
290 #define PEGBOX_LVL_DOWN BUTTON_VOL_DOWN
291 #define PEGBOX_UP BUTTON_UP
292 #define PEGBOX_DOWN BUTTON_DOWN
293 #define PEGBOX_RIGHT BUTTON_RIGHT
294 #define PEGBOX_LEFT BUTTON_LEFT
296 #define SELECT_TEXT "SELECT"
297 #define QUIT_TEXT "POWER"
298 #define RESTART_TEXT "SELECT+UP"
299 #define LVL_UP_TEXT "VOL+"
300 #define LVL_DOWN_TEXT "VOL-"
303 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
304 #define PEGBOX_SELECT BUTTON_RC_PLAY
305 #define PEGBOX_QUIT BUTTON_RC_REC
306 #define PEGBOX_RESTART BUTTON_RC_MODE
307 #define PEGBOX_LVL_UP BUTTON_VOL_UP
308 #define PEGBOX_LVL_DOWN BUTTON_VOL_DOWN
309 #define PEGBOX_UP BUTTON_RC_VOL_UP
310 #define PEGBOX_DOWN BUTTON_RC_VOL_DOWN
311 #define PEGBOX_RIGHT BUTTON_RC_FF
312 #define PEGBOX_LEFT BUTTON_RC_REW
314 #define SELECT_TEXT "REM. PLAY"
315 #define QUIT_TEXT "REM. REC"
316 #define RESTART_TEXT "REM. MODE"
317 #define LVL_UP_TEXT "VOL+"
318 #define LVL_DOWN_TEXT "VOL-"
320 #elif CONFIG_KEYPAD == COWON_D2_PAD
321 #define PEGBOX_QUIT BUTTON_POWER
323 #define QUIT_TEXT "POWER"
325 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
326 #define PEGBOX_SELECT BUTTON_CUSTOM
327 #define PEGBOX_QUIT BUTTON_BACK
328 #define PEGBOX_RESTART BUTTON_SELECT
329 #define PEGBOX_LVL_UP BUTTON_PLAY
330 #define PEGBOX_LVL_DOWN BUTTON_MENU
331 #define PEGBOX_UP BUTTON_UP
332 #define PEGBOX_DOWN BUTTON_DOWN
333 #define PEGBOX_RIGHT BUTTON_RIGHT
334 #define PEGBOX_LEFT BUTTON_LEFT
336 #define SELECT_TEXT "CUSTOM"
337 #define QUIT_TEXT "BACK"
338 #define RESTART_TEXT "MIDDLE"
339 #define LVL_UP_TEXT "SELECT"
340 #define LVL_DOWN_TEXT "MENU"
342 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
343 #define PEGBOX_SELECT BUTTON_VIEW
344 #define PEGBOX_QUIT BUTTON_POWER
345 #define PEGBOX_RESTART BUTTON_MENU
346 #define PEGBOX_LVL_UP BUTTON_VOL_UP
347 #define PEGBOX_LVL_DOWN BUTTON_VOL_DOWN
348 #define PEGBOX_UP BUTTON_UP
349 #define PEGBOX_DOWN BUTTON_DOWN
350 #define PEGBOX_RIGHT BUTTON_RIGHT
351 #define PEGBOX_LEFT BUTTON_LEFT
353 #define SELECT_TEXT "VIEW"
354 #define QUIT_TEXT "POWER"
355 #define RESTART_TEXT "MENU"
356 #define LVL_UP_TEXT "VOL+"
357 #define LVL_DOWN_TEXT "VOL-"
359 #elif CONFIG_KEYPAD == PHILIPS_SA9200_PAD
360 #define PEGBOX_SELECT BUTTON_RIGHT
361 #define PEGBOX_QUIT BUTTON_POWER
362 #define PEGBOX_RESTART BUTTON_MENU
363 #define PEGBOX_LVL_UP BUTTON_VOL_UP
364 #define PEGBOX_LVL_DOWN BUTTON_VOL_DOWN
365 #define PEGBOX_UP BUTTON_UP
366 #define PEGBOX_DOWN BUTTON_DOWN
367 #define PEGBOX_RIGHT BUTTON_NEXT
368 #define PEGBOX_LEFT BUTTON_PREV
370 #define SELECT_TEXT "RIGHT"
371 #define QUIT_TEXT "POWER"
372 #define RESTART_TEXT "MENU"
373 #define LVL_UP_TEXT "VOL+"
374 #define LVL_DOWN_TEXT "VOL-"
376 #elif CONFIG_KEYPAD == ONDAVX747_PAD || \
377 CONFIG_KEYPAD == ONDAVX777_PAD || \
378 CONFIG_KEYPAD == MROBE500_PAD
379 #define PEGBOX_QUIT BUTTON_POWER
381 #define QUIT_TEXT "POWER"
383 #elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
384 #define PEGBOX_SAVE (BUTTON_REC|BUTTON_FFWD)
385 #define PEGBOX_QUIT (BUTTON_REC|BUTTON_PLAY)
386 #define PEGBOX_RESTART (BUTTON_REC|BUTTON_REW)
387 #define PEGBOX_LVL_UP BUTTON_FFWD
388 #define PEGBOX_LVL_DOWN BUTTON_REW
389 #define PEGBOX_UP BUTTON_UP
390 #define PEGBOX_DOWN BUTTON_DOWN
391 #define PEGBOX_RIGHT BUTTON_RIGHT
392 #define PEGBOX_LEFT BUTTON_LEFT
393 #define PEGBOX_SELECT BUTTON_PLAY
395 #define SAVE_TEXT "REC + FFWD"
396 #define QUIT_TEXT "REC + PLAY"
397 #define RESTART_TEXT "REC + REW"
398 #define LVL_UP_TEXT "FFWD"
399 #define LVL_DOWN_TEXT "REW"
400 #define SELECT_TEXT "PLAY"
402 #elif CONFIG_KEYPAD == PBELL_VIBE500_PAD
403 #define PEGBOX_SAVE (BUTTON_REC|BUTTON_OK)
404 #define PEGBOX_QUIT BUTTON_REC
405 #define PEGBOX_RESTART BUTTON_MENU
406 #define PEGBOX_LVL_UP BUTTON_OK
407 #define PEGBOX_LVL_DOWN BUTTON_CANCEL
408 #define PEGBOX_UP BUTTON_UP
409 #define PEGBOX_DOWN BUTTON_DOWN
410 #define PEGBOX_RIGHT BUTTON_NEXT
411 #define PEGBOX_LEFT BUTTON_PREV
412 #define PEGBOX_SELECT BUTTON_PLAY
414 #define SAVE_TEXT "REC + OK"
415 #define QUIT_TEXT "REC"
416 #define RESTART_TEXT "MENU"
417 #define LVL_UP_TEXT "OK"
418 #define LVL_DOWN_TEXT "CANCEL"
419 #define SELECT_TEXT "PLAY"
421 #elif CONFIG_KEYPAD == MPIO_HD200_PAD
422 #define PEGBOX_SAVE (BUTTON_PLAY|BUTTON_SELECT)
423 #define PEGBOX_QUIT (BUTTON_REC|BUTTON_PLAY)
424 #define PEGBOX_RESTART BUTTON_REC
425 #define PEGBOX_LVL_UP (BUTTON_PLAY|BUTTON_PREV)
426 #define PEGBOX_LVL_DOWN (BUTTON_PLAY|BUTTON_NEXT)
427 #define PEGBOX_UP BUTTON_PREV
428 #define PEGBOX_DOWN BUTTON_NEXT
429 #define PEGBOX_RIGHT BUTTON_VOL_UP
430 #define PEGBOX_LEFT BUTTON_VOL_DOWN
431 #define PEGBOX_SELECT BUTTON_SELECT
433 #define SAVE_TEXT "PLAY + SELECT"
434 #define QUIT_TEXT "REC + PLAY"
435 #define RESTART_TEXT "REC"
436 #define LVL_UP_TEXT "PREV"
437 #define LVL_DOWN_TEXT "NEXT"
438 #define SELECT_TEXT "SELECT"
441 #error Unsupported keymap!
444 #ifdef HAVE_TOUCHSCREEN
446 #define PEGBOX_QUIT BUTTON_TOPLEFT
448 #ifndef PEGBOX_SELECT
449 #define PEGBOX_SELECT BUTTON_CENTER
451 #ifndef PEGBOX_RESTART
452 #define PEGBOX_RESTART BUTTON_TOPRIGHT
454 #ifndef PEGBOX_LVL_UP
455 #define PEGBOX_LVL_UP BUTTON_BOTTOMLEFT
457 #ifndef PEGBOX_LVL_DOWN
458 #define PEGBOX_LVL_DOWN BUTTON_BOTTOMRIGHT
461 #define PEGBOX_UP BUTTON_TOPMIDDLE
464 #define PEGBOX_DOWN BUTTON_BOTTOMMIDDLE
467 #define PEGBOX_RIGHT BUTTON_MIDRIGHT
470 #define PEGBOX_LEFT BUTTON_MIDLEFT
473 #define SELECT_TEXT "CENTER"
476 #define QUIT_TEXT "TOPLEFT"
479 #define RESTART_TEXT "TOPRIGHT"
482 #define LVL_UP_TEXT "BOTTOMLEFT"
484 #ifndef LVL_DOWN_TEXT
485 #define LVL_DOWN_TEXT "BOTTOMRIGHT"
490 /* get several sizes from the bitmaps */
491 #ifdef BMPWIDTH_pegbox_pieces
492 #define PIECE_WIDTH BMPWIDTH_pegbox_pieces
493 #define PIECE_HEIGHT (BMPHEIGHT_pegbox_pieces/7)
495 /* dummy numbers to avoid #error in dependency generation */
496 #define PIECE_WIDTH 50
497 #define PIECE_HEIGHT 10
500 #define BOARD_WIDTH (12*PIECE_WIDTH)
501 #define BOARD_HEIGHT (8*PIECE_HEIGHT)
504 /* define a wide layout where the statistics are alongside the board, not above
505 * base calculation on the piece bitmaps for the 8x12 board */
506 #if (LCD_WIDTH - BOARD_WIDTH) > (LCD_HEIGHT - BOARD_HEIGHT)
511 #define HEADER_WIDTH BMPWIDTH_pegbox_header
512 #define HEADER_HEIGHT BMPHEIGHT_pegbox_header
515 #if defined WIDE_LAYOUT
517 #if ((BOARD_WIDTH + HEADER_WIDTH + 4) <= LCD_WIDTH)
522 #define BOARD_Y (LCD_HEIGHT-BOARD_HEIGHT)/2
524 #if (LCD_WIDTH >= 132) && (LCD_HEIGHT >= 80)
526 #define LEVEL_TEXT_Y 14
527 #define PEGS_TEXT_Y 58
528 #elif (LCD_WIDTH >= 128) && (LCD_HEIGHT >= 64)
530 #define LEVEL_TEXT_Y 27
531 #define PEGS_TEXT_Y 50
533 #error "Unsupported screen size"
536 #else /* "normal" layout */
538 #define BOARD_X (LCD_WIDTH-BOARD_WIDTH)/2
539 #if ((BOARD_HEIGHT + HEADER_HEIGHT + 4) <= LCD_HEIGHT)
540 #define BOARD_Y HEADER_HEIGHT+2
542 #define BOARD_Y HEADER_HEIGHT
546 #define LEVEL_TEXT_X 118
547 #define PEGS_TEXT_X 552
549 #elif LCD_WIDTH >= 320
550 #define LEVEL_TEXT_X 59
551 #define PEGS_TEXT_X 276
553 #elif LCD_WIDTH >= 240
554 #define LEVEL_TEXT_X 59
555 #define PEGS_TEXT_X 196
557 #elif LCD_WIDTH >= 220
558 #define LEVEL_TEXT_X 49
559 #define PEGS_TEXT_X 186
561 #elif LCD_WIDTH >= 176
562 #define LEVEL_TEXT_X 38
563 #define PEGS_TEXT_X 155
565 #elif LCD_WIDTH >= 160
566 #define LEVEL_TEXT_X 37
567 #define PEGS_TEXT_X 140
569 #elif LCD_WIDTH >= 138
570 #define LEVEL_TEXT_X 28
571 #define PEGS_TEXT_X 119
573 #elif LCD_WIDTH >= 128
574 #if HEADER_HEIGHT > 16
575 #define LEVEL_TEXT_X 26
576 #define PEGS_TEXT_X 107
579 #define LEVEL_TEXT_X 15
580 #define PEGS_TEXT_X 100
582 #endif /* HEADER_HEIGHT */
583 #elif LCD_WIDTH >= 112
584 #define LEVEL_TEXT_X 25
585 #define PEGS_TEXT_X 90
587 #endif /* LCD_WIDTH */
589 #endif /* WIDE_LAYOUT */
592 #ifdef HAVE_LCD_COLOR
593 #define BG_COLOR LCD_BLACK
594 #define TEXT_BG LCD_RGBPACK(189,189,189)
598 #ifdef HAVE_TOUCHSCREEN
599 #include "lib/pluginlib_touchscreen.h"
600 static struct ts_raster pegbox_raster
=
601 { BOARD_X
, BOARD_Y
, COLS
*PIECE_WIDTH
, ROWS
*PIECE_HEIGHT
,
602 PIECE_WIDTH
, PIECE_HEIGHT
};
603 static struct ts_raster_button_mapping pegbox_raster_btn
=
604 { &pegbox_raster
, false, false, true, false, true, {0, 0}, 0, 0, 0 };
608 struct game_context
{
610 unsigned int highlevel
;
611 signed int player_row
;
612 signed int player_col
;
613 unsigned int num_left
;
614 unsigned int playboard
[ROWS
][COLS
];
617 char levels
[NUM_LEVELS
][ROWS
][COLS
] = {
619 {{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,},
620 {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,},
621 {1, 0, 0, 0, 7, 0, 0, 5, 0, 0, 0, 1,},
622 {1, 0, 0, 0, 0, 3, 3, 2, 0, 0, 0, 1,},
623 {1, 0, 0, 0, 4, 6, 0, 5, 0, 0, 0, 1,},
624 {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,},
625 {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,},
626 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,}},
629 {{1, 1, 1, 1, 1,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0, 0, 1, 0, 0, 1, 1, 1, 1, 1,},
756 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,}},
759 {{0, 0, 0, 6, 0, 6, 0, 6, 0, 6, 0, 1,},
760 {0, 0, 0, 6, 0, 6, 0, 6, 0, 6, 0, 1,},
761 {0, 3, 4, 6, 0, 6, 0, 6, 0, 6, 0, 2,},
762 {0, 4, 0, 6, 0, 6, 4, 6, 0, 6, 0, 1,},
763 {0, 3, 0, 6, 0, 6, 0, 6, 0, 6, 0, 1,},
764 {7, 0, 0, 6, 4, 6, 0, 6, 0, 6, 0, 1,},
765 {0, 0, 4, 6, 0, 6, 0, 6, 4, 6, 0, 1,},
766 {0, 0, 4, 6, 0, 6, 0, 6, 0, 6, 0, 1,}}
769 /***********************************************************************
770 * pegbox_draw_board() draws the game's current level.
771 ************************************************************************/
772 static void pegbox_draw_board(struct game_context
* pb
)
774 unsigned int r
, c
, type
;
778 rb
->lcd_clear_display();
780 rb
->lcd_bitmap(pegbox_header
,LCD_WIDTH
-HEADER_WIDTH
,0,
781 HEADER_WIDTH
,LCD_HEIGHT
);
783 rb
->lcd_bitmap(pegbox_header
,(LCD_WIDTH
-HEADER_WIDTH
)/2,0,
784 HEADER_WIDTH
, HEADER_HEIGHT
);
785 #endif /* WIDE_LAYOUT */
787 #if ((BOARD_HEIGHT + HEADER_HEIGHT + 4) <= LCD_HEIGHT)
788 rb
->lcd_drawrect(BOARD_X
-2,BOARD_Y
-2,BOARD_WIDTH
+4,BOARD_HEIGHT
+4);
789 #endif /* enough space for a frame? */
791 #ifdef HAVE_LCD_COLOR
792 rb
->lcd_set_foreground(LCD_WHITE
);
793 rb
->lcd_fillrect(BOARD_X
-1,BOARD_Y
-1,BOARD_WIDTH
+2,BOARD_HEIGHT
+2);
794 rb
->lcd_set_foreground(LCD_BLACK
);
795 rb
->lcd_set_background(TEXT_BG
);
798 for (r
=0 ; r
< ROWS
; r
++) {
799 for (c
= 0 ; c
< COLS
; c
++) {
801 type
= pb
->playboard
[r
][c
];
804 rb
->lcd_bitmap_part(pegbox_pieces
, 0, (type
-1)*PIECE_HEIGHT
,
806 BMPWIDTH_pegbox_pieces
,BMPHEIGHT_pegbox_pieces
),
807 c
* PIECE_WIDTH
+ BOARD_X
,
808 r
* PIECE_HEIGHT
+ BOARD_Y
, PIECE_WIDTH
,
812 if(pb
->playboard
[r
][c
] == PLAYER
) {
816 else if (type
!= WALL
&& type
!= SPACE
&& type
!= HOLE
)
822 rb
->snprintf(str
, 3, "%d", pb
->level
);
823 rb
->lcd_putsxy(TEXT_X
, LEVEL_TEXT_Y
, str
);
824 rb
->snprintf(str
, 3, "%d", pb
->num_left
);
825 rb
->lcd_putsxy(TEXT_X
, PEGS_TEXT_Y
, str
);
827 rb
->snprintf(str
, 3, "%d", pb
->level
);
828 rb
->lcd_putsxy(LEVEL_TEXT_X
, TEXT_Y
, str
);
829 rb
->snprintf(str
, 3, "%d", pb
->num_left
);
830 rb
->lcd_putsxy(PEGS_TEXT_X
, TEXT_Y
, str
);
831 #endif /*WIDE_LAYOUT*/
833 #ifdef HAVE_LCD_COLOR
834 rb
->lcd_set_background(BG_COLOR
);
835 rb
->lcd_set_foreground(LCD_WHITE
);
837 /* print out the screen */
841 /*****************************************************************************
842 * pegbox_load_level() loads the player's current level from the array and sets the
844 ******************************************************************************/
845 static void pegbox_load_level(struct game_context
* pb
)
849 for(r
= 0; r
< ROWS
; r
++)
850 for(c
= 0; c
< COLS
; c
++)
851 pb
->playboard
[r
][c
] = levels
[pb
->level
-1][r
][c
];
854 /*****************************************************************************
855 * pegbox_new_piece() creates a new piece at a specified location. The player
856 * navigates through the pieces and selects one.
857 ******************************************************************************/
858 static void pegbox_new_piece(struct game_context
* pb
, unsigned int x_loc
,
864 pb
->playboard
[x_loc
][y_loc
] = TRIANGLE
;
867 pegbox_draw_board(pb
);
868 button
= rb
->button_get(true);
869 #ifdef HAVE_TOUCHSCREEN
870 if(button
& BUTTON_TOUCHSCREEN
)
872 pegbox_raster_btn
.two_d_from
.y
= x_loc
;
873 pegbox_raster_btn
.two_d_from
.x
= y_loc
;
875 struct ts_raster_button_result ret
=
876 touchscreen_raster_map_button(&pegbox_raster_btn
,
877 rb
->button_get_data() >> 16,
878 rb
->button_get_data() & 0xffff,
880 if(ret
.action
== TS_ACTION_TWO_D_MOVEMENT
)
882 if(ret
.to
.x
> ret
.from
.x
)
884 else if(ret
.to
.x
< ret
.from
.x
)
885 button
= PEGBOX_DOWN
;
886 else if(ret
.to
.y
> ret
.from
.y
)
887 button
= PEGBOX_LEFT
;
888 else if(ret
.to
.y
< ret
.from
.y
)
889 button
= PEGBOX_RIGHT
;
891 else if(ret
.action
== TS_ACTION_CLICK
892 && (unsigned)ret
.to
.x
== y_loc
893 && (unsigned)ret
.to
.y
== x_loc
)
894 button
= PEGBOX_SELECT
;
899 case (PEGBOX_LEFT
|BUTTON_REPEAT
):
901 case (PEGBOX_DOWN
|BUTTON_REPEAT
):
902 if (pb
->playboard
[x_loc
][y_loc
] < 5)
903 pb
->playboard
[x_loc
][y_loc
]++;
905 pb
->playboard
[x_loc
][y_loc
] = TRIANGLE
;
908 case (PEGBOX_RIGHT
|BUTTON_REPEAT
):
910 case (PEGBOX_UP
|BUTTON_REPEAT
):
911 if (pb
->playboard
[x_loc
][y_loc
] > 2)
912 pb
->playboard
[x_loc
][y_loc
]--;
914 pb
->playboard
[x_loc
][y_loc
] = CIRCLE
;
923 /*****************************************************************************
924 * pegbox_move_player() moves the player and pieces and updates the board accordingly.
925 ******************************************************************************/
926 static void pegbox_move_player(struct game_context
* pb
, signed int x_dir
,
929 unsigned int type1
, type2
;
930 signed int r1
,c1
,r2
,c2
;
932 r1
= pb
->player_row
+y_dir
;
933 c1
= pb
->player_col
+x_dir
;
934 r2
= pb
->player_row
+y_dir
*2;
935 c2
= pb
->player_col
+x_dir
*2;
937 type1
= pb
->playboard
[r1
][c1
];
938 type2
= pb
->playboard
[r2
][c2
];
940 if (r1
== ROWS
|| c1
== COLS
|| r1
< 0 || c1
< 0 || type1
== WALL
)
942 else if(type1
!= SPACE
) {
943 if (r2
== ROWS
|| c2
== COLS
|| r2
< 0 || c2
< 0 || type2
== WALL
)
948 pb
->playboard
[pb
->player_row
][pb
->player_col
] = SPACE
;
949 pb
->player_row
+= y_dir
;
950 pb
->player_col
+= x_dir
;
953 pegbox_draw_board(pb
);
954 rb
->splash(HZ
*2, "You fell down a hole!");
955 pegbox_load_level(pb
);
957 else if (type1
== SPACE
)
958 pb
->playboard
[r1
][c1
] = PLAYER
;
960 pb
->playboard
[r1
][c1
] = PLAYER
;
962 if (type1
== TRIANGLE
)
963 pb
->playboard
[r2
][c2
] = WALL
;
964 else if (type1
== CROSS
) {
965 pb
->playboard
[r1
][c1
] = SPACE
;
966 pegbox_new_piece(pb
, r2
, c2
);
967 pb
->playboard
[r1
][c1
] = PLAYER
;
970 pb
->playboard
[r2
][c2
] = SPACE
;
972 else if (type2
== SPACE
)
973 pb
->playboard
[r2
][c2
] = type1
;
974 else if (type2
== HOLE
) {
976 pb
->playboard
[r2
][c2
] = SPACE
;
979 rb
->splash(HZ
*2, "Illegal Move!");
980 pegbox_load_level(pb
);
984 pegbox_draw_board(pb
);
987 /***********************************************************************
988 * pegbox_help() display help text
989 ************************************************************************/
990 static bool pegbox_help(void)
992 static char* help_text
[] = {
993 "Pegbox", "", "Aim", "",
994 "To", "beat", "each", "level,", "you", "must", "destroy", "all", "of",
995 "the", "pegs.", "If", "two", "like", "pegs", "are", "pushed", "into",
996 "each", "other,", "they", "disappear", "except", "for", "triangles",
997 "which", "form", "a", "solid", "block", "and", "crosses", "which",
998 "allow", "you", "to", "choose", "a", "replacement", "block.", "", "",
1000 RESTART_TEXT
, "to", "restart", "level", "",
1001 LVL_UP_TEXT
, "to", "go", "up", "a", "level", "",
1002 LVL_DOWN_TEXT
, "to", "go", "down", "a", "level", "",
1003 SELECT_TEXT
, "to", "choose", "peg", "",
1004 QUIT_TEXT
, "to", "quit"
1006 static struct style_text formation
[]={
1007 { 0, TEXT_CENTER
|TEXT_UNDERLINE
},
1013 rb
->lcd_setfont(FONT_UI
);
1014 if (display_text(ARRAYLEN(help_text
), help_text
, formation
, NULL
, true))
1016 rb
->lcd_setfont(FONT_SYSFIXED
);
1021 /***********************************************************************
1022 * pegbox_menu() is the game menu
1023 ************************************************************************/
1024 static bool _ingame
;
1025 static int pegbox_menu_cb(int action
, const struct menu_item_ex
*this_item
)
1027 int i
= (intptr_t)this_item
;
1028 if( action
== ACTION_REQUEST_MENUITEM
)
1030 if((!_ingame
&& (i
==0 || i
==1)) || ( _ingame
&& i
==2 ))
1031 return ACTION_EXIT_MENUITEM
;
1036 static unsigned int pegbox_menu(struct game_context
* pb
, bool ingame
)
1039 int last_level
= pb
->level
;
1041 MENUITEM_STRINGLIST (main_menu
, "Pegbox Menu", pegbox_menu_cb
,
1042 "Resume Game", "Restart Level", "Start Game",
1043 "Select Level", "Help",
1044 "Playback Control", "Quit");
1046 rb
->button_clear_queue();
1049 switch (rb
->do_menu(&main_menu
, &selected
, NULL
, false)) {
1051 pb
->level
= last_level
;
1052 pegbox_draw_board(pb
);
1056 pegbox_load_level(pb
);
1057 pegbox_draw_board(pb
);
1060 if(rb
->set_int("Select Level", "", UNIT_INT
, &pb
->level
,
1061 NULL
, 1, 1, pb
->highlevel
, NULL
))
1069 if (playback_control(NULL
))
1074 case MENU_ATTACHED_USB
:
1082 /***********************************************************************
1083 * pegbox_main() is the main game subroutine
1084 ************************************************************************/
1085 static int pegbox_main(struct game_context
* pb
)
1089 if (pegbox_menu(pb
, false)==1) {
1094 button
= rb
->button_get(true);
1095 #ifdef HAVE_TOUCHSCREEN
1096 if(button
& BUTTON_TOUCHSCREEN
)
1098 pegbox_raster_btn
.two_d_from
.y
= pb
->player_row
;
1099 pegbox_raster_btn
.two_d_from
.x
= pb
->player_col
;
1101 struct ts_raster_button_result ret
=
1102 touchscreen_raster_map_button(&pegbox_raster_btn
,
1103 rb
->button_get_data() >> 16,
1104 rb
->button_get_data() & 0xffff,
1106 if(ret
.action
== TS_ACTION_TWO_D_MOVEMENT
)
1107 pegbox_move_player(pb
, ret
.to
.x
- ret
.from
.x
, ret
.to
.y
- ret
.from
.y
);
1111 case PEGBOX_LEFT
: /* move cursor left */
1112 case (PEGBOX_LEFT
|BUTTON_REPEAT
):
1113 pegbox_move_player(pb
, -1, 0);
1116 case PEGBOX_RIGHT
: /* move cursor right */
1117 case (PEGBOX_RIGHT
|BUTTON_REPEAT
):
1118 pegbox_move_player(pb
, 1, 0);
1121 case PEGBOX_DOWN
: /* move cursor down */
1122 case (PEGBOX_DOWN
|BUTTON_REPEAT
):
1123 pegbox_move_player(pb
, 0, 1);
1126 case PEGBOX_UP
: /* move cursor up */
1127 case (PEGBOX_UP
|BUTTON_REPEAT
):
1128 pegbox_move_player(pb
, 0, -1);
1132 if (pegbox_menu(pb
, true)==1) {
1137 #ifdef PEGBOX_RESTART
1138 case PEGBOX_RESTART
:
1139 pegbox_load_level(pb
);
1140 pegbox_draw_board(pb
);
1144 #ifdef PEGBOX_LVL_UP
1145 case (PEGBOX_LVL_UP
|BUTTON_REPEAT
):
1147 if (pb
->level
>= pb
->highlevel
) {
1152 pegbox_load_level(pb
);
1153 pegbox_draw_board(pb
);
1157 #ifdef PEGBOX_LVL_DOWN
1158 case (PEGBOX_LVL_DOWN
|BUTTON_REPEAT
):
1159 case PEGBOX_LVL_DOWN
:
1160 if(pb
->level
<= 1) {
1161 pb
->level
= pb
->highlevel
;
1165 pegbox_load_level(pb
);
1166 pegbox_draw_board(pb
);
1171 if (pb
->num_left
== 0) {
1172 rb
->splash(HZ
*2, "Nice Pegging!");
1173 if (pb
->level
== NUM_LEVELS
) {
1174 pegbox_draw_board(pb
);
1175 rb
->splash(HZ
*2, "Congratulations!");
1176 rb
->splash(HZ
*2, "You have finished the game!");
1177 if (pegbox_menu(pb
,false)==1) {
1183 pegbox_load_level(pb
);
1184 pegbox_draw_board(pb
);
1187 if(pb
->level
> pb
->highlevel
)
1188 pb
->highlevel
= pb
->level
;
1195 /*****************************************************************************
1196 * plugin entry point.
1197 ******************************************************************************/
1198 enum plugin_status
plugin_start(const void* parameter
)
1201 #ifdef HAVE_LCD_BITMAP
1202 rb
->lcd_setfont(FONT_SYSFIXED
);
1204 rb
->lcd_set_backdrop(NULL
);
1206 #ifdef HAVE_LCD_COLOR
1207 rb
->lcd_set_foreground(LCD_WHITE
);
1208 rb
->lcd_set_background(BG_COLOR
);
1210 rb
->lcd_clear_display();
1212 struct game_context pb
;
1215 struct configdata config
[] = {
1216 {TYPE_INT
, 1, NUM_LEVELS
, { .int_p
= &(pb
.level
) }, "level", NULL
},
1217 {TYPE_INT
, 1, NUM_LEVELS
, { .int_p
= &(pb
.highlevel
) }, "highlevel", NULL
},
1219 configfile_load(CONFIG_FILE_NAME
,config
,2,0);
1221 configfile_save(CONFIG_FILE_NAME
,config
,2,0);
1222 rb
->lcd_setfont(FONT_UI
);
1223 #endif /* HAVE_LCD_BITMAP */