fix red.
[kugel-rb/myfork.git] / apps / plugins / pegbox.c
blobd9c3d9870eba558be178f1c10187f106f9167b6f
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
21 #include "plugin.h"
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"
29 PLUGIN_HEADER
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 */
37 #define SPACE 0
38 #define WALL 1
39 #define TRIANGLE 2
40 #define CROSS 3
41 #define SQUARE 4
42 #define CIRCLE 5
43 #define HOLE 6
44 #define PLAYER 7
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 == COWOND2_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 == ONDAVX747_PAD || CONFIG_KEYPAD == MROBE500_PAD
360 #define PEGBOX_QUIT BUTTON_POWER
362 #define QUIT_TEXT "POWER"
364 #elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
365 #define PEGBOX_SAVE (BUTTON_REC|BUTTON_FFWD)
366 #define PEGBOX_QUIT (BUTTON_REC|BUTTON_PLAY)
367 #define PEGBOX_RESTART (BUTTON_REC|BUTTON_REW)
368 #define PEGBOX_LVL_UP BUTTON_FFWD
369 #define PEGBOX_LVL_DOWN BUTTON_REW
370 #define PEGBOX_UP BUTTON_UP
371 #define PEGBOX_DOWN BUTTON_DOWN
372 #define PEGBOX_RIGHT BUTTON_RIGHT
373 #define PEGBOX_LEFT BUTTON_LEFT
374 #define PEGBOX_SELECT BUTTON_PLAY
376 #define SAVE_TEXT "REC + FFWD"
377 #define QUIT_TEXT "REC + PLAY"
378 #define RESTART_TEXT "REC + REW"
379 #define LVL_UP_TEXT "FFWD"
380 #define LVL_DOWN_TEXT "REW"
381 #define SELECT_TEXT "PLAY"
383 #else
384 #error Unsupported keymap!
385 #endif
387 #ifdef HAVE_TOUCHSCREEN
388 #ifndef PEGBOX_QUIT
389 #define PEGBOX_QUIT BUTTON_TOPLEFT
390 #endif
391 #ifndef PEGBOX_SELECT
392 #define PEGBOX_SELECT BUTTON_CENTER
393 #endif
394 #ifndef PEGBOX_RESTART
395 #define PEGBOX_RESTART BUTTON_TOPRIGHT
396 #endif
397 #ifndef PEGBOX_LVL_UP
398 #define PEGBOX_LVL_UP BUTTON_BOTTOMLEFT
399 #endif
400 #ifndef PEGBOX_LVL_DOWN
401 #define PEGBOX_LVL_DOWN BUTTON_BOTTOMRIGHT
402 #endif
403 #ifndef PEGBOX_UP
404 #define PEGBOX_UP BUTTON_TOPMIDDLE
405 #endif
406 #ifndef PEGBOX_DOWN
407 #define PEGBOX_DOWN BUTTON_BOTTOMMIDDLE
408 #endif
409 #ifndef PEGBOX_RIGHT
410 #define PEGBOX_RIGHT BUTTON_MIDRIGHT
411 #endif
412 #ifndef PEGBOX_LEFT
413 #define PEGBOX_LEFT BUTTON_MIDLEFT
414 #endif
415 #ifndef SELECT_TEXT
416 #define SELECT_TEXT "CENTER"
417 #endif
418 #ifndef QUIT_TEXT
419 #define QUIT_TEXT "TOPLEFT"
420 #endif
421 #ifndef RESTART_TEXT
422 #define RESTART_TEXT "TOPRIGHT"
423 #endif
424 #ifndef LVL_UP_TEXT
425 #define LVL_UP_TEXT "BOTTOMLEFT"
426 #endif
427 #ifndef LVL_DOWN_TEXT
428 #define LVL_DOWN_TEXT "BOTTOMRIGHT"
429 #endif
430 #endif
433 /* get several sizes from the bitmaps */
434 #ifdef BMPWIDTH_pegbox_pieces
435 #define PIECE_WIDTH BMPWIDTH_pegbox_pieces
436 #define PIECE_HEIGHT (BMPHEIGHT_pegbox_pieces/7)
437 #else
438 /* dummy numbers to avoid #error in dependency generation */
439 #define PIECE_WIDTH 50
440 #define PIECE_HEIGHT 10
441 #endif
443 #define BOARD_WIDTH (12*PIECE_WIDTH)
444 #define BOARD_HEIGHT (8*PIECE_HEIGHT)
447 /* define a wide layout where the statistics are alongside the board, not above
448 * base calculation on the piece bitmaps for the 8x12 board */
449 #if (LCD_WIDTH - BOARD_WIDTH) > (LCD_HEIGHT - BOARD_HEIGHT)
450 #define WIDE_LAYOUT
451 #endif
454 #define HEADER_WIDTH BMPWIDTH_pegbox_header
455 #define HEADER_HEIGHT BMPHEIGHT_pegbox_header
458 #if defined WIDE_LAYOUT
460 #if ((BOARD_WIDTH + HEADER_WIDTH + 4) <= LCD_WIDTH)
461 #define BOARD_X 2
462 #else
463 #define BOARD_X 1
464 #endif
465 #define BOARD_Y (LCD_HEIGHT-BOARD_HEIGHT)/2
467 #if (LCD_WIDTH >= 132) && (LCD_HEIGHT >= 80)
468 #define TEXT_X 116
469 #define LEVEL_TEXT_Y 14
470 #define PEGS_TEXT_Y 58
471 #elif (LCD_WIDTH >= 128) && (LCD_HEIGHT >= 64)
472 #define TEXT_X 112
473 #define LEVEL_TEXT_Y 27
474 #define PEGS_TEXT_Y 50
475 #else
476 #error "Unsupported screen size"
477 #endif
479 #else /* "normal" layout */
481 #define BOARD_X (LCD_WIDTH-BOARD_WIDTH)/2
482 #if ((BOARD_HEIGHT + HEADER_HEIGHT + 4) <= LCD_HEIGHT)
483 #define BOARD_Y HEADER_HEIGHT+2
484 #else
485 #define BOARD_Y HEADER_HEIGHT
486 #endif
488 #if LCD_WIDTH >= 640
489 #define LEVEL_TEXT_X 118
490 #define PEGS_TEXT_X 552
491 #define TEXT_Y 56
492 #elif LCD_WIDTH >= 320
493 #define LEVEL_TEXT_X 59
494 #define PEGS_TEXT_X 276
495 #define TEXT_Y 28
496 #elif LCD_WIDTH >= 240
497 #define LEVEL_TEXT_X 59
498 #define PEGS_TEXT_X 196
499 #define TEXT_Y 28
500 #elif LCD_WIDTH >= 220
501 #define LEVEL_TEXT_X 49
502 #define PEGS_TEXT_X 186
503 #define TEXT_Y 28
504 #elif LCD_WIDTH >= 176
505 #define LEVEL_TEXT_X 38
506 #define PEGS_TEXT_X 155
507 #define TEXT_Y 17
508 #elif LCD_WIDTH >= 160
509 #define LEVEL_TEXT_X 37
510 #define PEGS_TEXT_X 140
511 #define TEXT_Y 13
512 #elif LCD_WIDTH >= 138
513 #define LEVEL_TEXT_X 28
514 #define PEGS_TEXT_X 119
515 #define TEXT_Y 15
516 #elif LCD_WIDTH >= 128
517 #if HEADER_HEIGHT > 16
518 #define LEVEL_TEXT_X 26
519 #define PEGS_TEXT_X 107
520 #define TEXT_Y 31
521 #else
522 #define LEVEL_TEXT_X 15
523 #define PEGS_TEXT_X 100
524 #define TEXT_Y 5
525 #endif /* HEADER_HEIGHT */
526 #elif LCD_WIDTH >= 112
527 #define LEVEL_TEXT_X 25
528 #define PEGS_TEXT_X 90
529 #define TEXT_Y 0
530 #endif /* LCD_WIDTH */
532 #endif /* WIDE_LAYOUT */
535 #ifdef HAVE_LCD_COLOR
536 #define BG_COLOR LCD_BLACK
537 #define TEXT_BG LCD_RGBPACK(189,189,189)
538 #endif
541 #ifdef HAVE_TOUCHSCREEN
542 #include "lib/pluginlib_touchscreen.h"
543 static struct ts_raster pegbox_raster =
544 { BOARD_X, BOARD_Y, COLS*PIECE_WIDTH, ROWS*PIECE_HEIGHT,
545 PIECE_WIDTH, PIECE_HEIGHT };
546 static struct ts_raster_button_mapping pegbox_raster_btn =
547 { &pegbox_raster, false, false, true, false, true, {0, 0}, 0, 0, 0 };
548 #endif
551 struct game_context {
552 unsigned int level;
553 unsigned int highlevel;
554 signed int player_row;
555 signed int player_col;
556 unsigned int num_left;
557 unsigned int playboard[ROWS][COLS];
560 char levels[NUM_LEVELS][ROWS][COLS] = {
561 /* Level 1 */
562 {{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,},
563 {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,},
564 {1, 0, 0, 0, 7, 0, 0, 5, 0, 0, 0, 1,},
565 {1, 0, 0, 0, 0, 3, 3, 2, 0, 0, 0, 1,},
566 {1, 0, 0, 0, 4, 6, 0, 5, 0, 0, 0, 1,},
567 {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,},
568 {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,},
569 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,}},
571 /* Level 2 */
572 {{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,},
573 {1, 1, 1, 0, 0, 0, 2, 2, 0, 0, 0, 1,},
574 {1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1,},
575 {1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1,},
576 {7, 0, 0, 0, 2, 2, 5, 5, 0, 0, 0, 1,},
577 {1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1,},
578 {1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1,},
579 {1, 1, 1, 0, 0, 0, 2, 2, 0, 0, 0, 1,}},
581 /* Level 3 */
582 {{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,},
583 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,},
584 {1, 0, 0, 0, 0, 0, 2, 0, 7, 0, 0, 0,},
585 {1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 2, 1,},
586 {1, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 1,},
587 {1, 1, 1, 1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0, 1,}}
712 /***********************************************************************
713 * pegbox_draw_board() draws the game's current level.
714 ************************************************************************/
715 static void pegbox_draw_board(struct game_context* pb)
717 unsigned int r, c, type;
718 pb->num_left = 0;
719 char str[5];
721 rb->lcd_clear_display();
722 #ifdef WIDE_LAYOUT
723 rb->lcd_bitmap(pegbox_header,LCD_WIDTH-HEADER_WIDTH,0,
724 HEADER_WIDTH,LCD_HEIGHT);
725 #else
726 rb->lcd_bitmap(pegbox_header,(LCD_WIDTH-HEADER_WIDTH)/2,0,
727 HEADER_WIDTH, HEADER_HEIGHT);
728 #endif /* WIDE_LAYOUT */
730 #if ((BOARD_HEIGHT + HEADER_HEIGHT + 4) <= LCD_HEIGHT)
731 rb->lcd_drawrect(BOARD_X-2,BOARD_Y-2,BOARD_WIDTH+4,BOARD_HEIGHT+4);
732 #endif /* enough space for a frame? */
734 #ifdef HAVE_LCD_COLOR
735 rb->lcd_set_foreground(LCD_WHITE);
736 rb->lcd_fillrect(BOARD_X-1,BOARD_Y-1,BOARD_WIDTH+2,BOARD_HEIGHT+2);
737 rb->lcd_set_foreground(LCD_BLACK);
738 rb->lcd_set_background(TEXT_BG);
739 #endif
741 for (r=0 ; r < ROWS ; r++) {
742 for (c = 0 ; c < COLS ; c++) {
744 type = pb->playboard[r][c];
746 if(type != SPACE) {
747 rb->lcd_bitmap_part(pegbox_pieces, 0, (type-1)*PIECE_HEIGHT,
748 PIECE_WIDTH, c * PIECE_WIDTH + BOARD_X,
749 r * PIECE_HEIGHT + BOARD_Y, PIECE_WIDTH,
750 PIECE_HEIGHT);
753 if(pb->playboard[r][c] == PLAYER) {
754 pb->player_row=r;
755 pb->player_col=c;
757 else if (type != WALL && type != SPACE && type != HOLE)
758 pb->num_left++;
762 #ifdef WIDE_LAYOUT
763 rb->snprintf(str, 3, "%d", pb->level);
764 rb->lcd_putsxy(TEXT_X, LEVEL_TEXT_Y, str);
765 rb->snprintf(str, 3, "%d", pb->num_left);
766 rb->lcd_putsxy(TEXT_X, PEGS_TEXT_Y, str);
767 #else
768 rb->snprintf(str, 3, "%d", pb->level);
769 rb->lcd_putsxy(LEVEL_TEXT_X, TEXT_Y, str);
770 rb->snprintf(str, 3, "%d", pb->num_left);
771 rb->lcd_putsxy(PEGS_TEXT_X, TEXT_Y, str);
772 #endif /*WIDE_LAYOUT*/
774 #ifdef HAVE_LCD_COLOR
775 rb->lcd_set_background(BG_COLOR);
776 rb->lcd_set_foreground(LCD_WHITE);
777 #endif
778 /* print out the screen */
779 rb->lcd_update();
782 /*****************************************************************************
783 * pegbox_load_level() loads the player's current level from the array and sets the
784 * player's position.
785 ******************************************************************************/
786 static void pegbox_load_level(struct game_context* pb)
788 int r, c;
790 for(r = 0; r < ROWS; r++)
791 for(c = 0; c < COLS; c++)
792 pb->playboard[r][c] = levels[pb->level-1][r][c];
795 /*****************************************************************************
796 * pegbox_new_piece() creates a new piece at a specified location. The player
797 * navigates through the pieces and selects one.
798 ******************************************************************************/
799 static void pegbox_new_piece(struct game_context* pb, unsigned int x_loc,
800 unsigned int y_loc)
802 int button;
803 bool exit = false;
805 pb->playboard[x_loc][y_loc] = TRIANGLE;
807 while (!exit) {
808 pegbox_draw_board(pb);
809 button = rb->button_get(true);
810 #ifdef HAVE_TOUCHSCREEN
811 if(button & BUTTON_TOUCHSCREEN)
813 pegbox_raster_btn.two_d_from.y = x_loc;
814 pegbox_raster_btn.two_d_from.x = y_loc;
816 struct ts_raster_button_result ret =
817 touchscreen_raster_map_button(&pegbox_raster_btn,
818 rb->button_get_data() >> 16,
819 rb->button_get_data() & 0xffff,
820 button);
821 if(ret.action == TS_ACTION_TWO_D_MOVEMENT)
823 if(ret.to.x > ret.from.x)
824 button = PEGBOX_UP;
825 else if(ret.to.x < ret.from.x)
826 button = PEGBOX_DOWN;
827 else if(ret.to.y > ret.from.y)
828 button = PEGBOX_LEFT;
829 else if(ret.to.y < ret.from.y)
830 button = PEGBOX_RIGHT;
832 else if(ret.action == TS_ACTION_CLICK
833 && (unsigned)ret.to.x == y_loc
834 && (unsigned)ret.to.y == x_loc)
835 button = PEGBOX_SELECT;
837 #endif
838 switch(button){
839 case PEGBOX_LEFT:
840 case (PEGBOX_LEFT|BUTTON_REPEAT):
841 case PEGBOX_DOWN:
842 case (PEGBOX_DOWN|BUTTON_REPEAT):
843 if (pb->playboard[x_loc][y_loc] < 5)
844 pb->playboard[x_loc][y_loc]++;
845 else
846 pb->playboard[x_loc][y_loc] = TRIANGLE;
847 break;
848 case PEGBOX_RIGHT:
849 case (PEGBOX_RIGHT|BUTTON_REPEAT):
850 case PEGBOX_UP:
851 case (PEGBOX_UP|BUTTON_REPEAT):
852 if (pb->playboard[x_loc][y_loc] > 2)
853 pb->playboard[x_loc][y_loc]--;
854 else
855 pb->playboard[x_loc][y_loc] = CIRCLE;
856 break;
857 case PEGBOX_SELECT:
858 exit=true;
859 break;
864 /*****************************************************************************
865 * pegbox_move_player() moves the player and pieces and updates the board accordingly.
866 ******************************************************************************/
867 static void pegbox_move_player(struct game_context* pb, signed int x_dir,
868 signed int y_dir)
870 unsigned int type1, type2;
871 signed int r1,c1,r2,c2;
873 r1 = pb->player_row+y_dir;
874 c1 = pb->player_col+x_dir;
875 r2 = pb->player_row+y_dir*2;
876 c2 = pb->player_col+x_dir*2;
878 type1 = pb->playboard[r1][c1];
879 type2 = pb->playboard[r2][c2];
881 if (r1 == ROWS || c1 == COLS || r1 < 0 || c1 < 0 || type1 == WALL)
882 return;
883 else if(type1 != SPACE) {
884 if (r2 == ROWS || c2 == COLS || r2 < 0 || c2 < 0 || type2 == WALL)
885 return;
889 pb->playboard[pb->player_row][pb->player_col] = SPACE;
890 pb->player_row += y_dir;
891 pb->player_col += x_dir;
893 if (type1 == HOLE) {
894 pegbox_draw_board(pb);
895 rb->splash(HZ*2, "You fell down a hole!");
896 pegbox_load_level(pb);
898 else if (type1 == SPACE)
899 pb->playboard[r1][c1] = PLAYER;
900 else {
901 pb->playboard[r1][c1] = PLAYER;
902 if(type1 == type2) {
903 if (type1 == TRIANGLE)
904 pb->playboard[r2][c2] = WALL;
905 else if (type1 == CROSS) {
906 pb->playboard[r1][c1] = SPACE;
907 pegbox_new_piece(pb, r2, c2);
908 pb->playboard[r1][c1] = PLAYER;
910 else
911 pb->playboard[r2][c2] = SPACE;
913 else if (type2 == SPACE)
914 pb->playboard[r2][c2] = type1;
915 else if (type2 == HOLE) {
916 if (type1 == SQUARE)
917 pb->playboard[r2][c2] = SPACE;
919 else {
920 rb->splash(HZ*2, "Illegal Move!");
921 pegbox_load_level(pb);
925 pegbox_draw_board(pb);
928 /***********************************************************************
929 * pegbox_help() display help text
930 ************************************************************************/
931 static bool pegbox_help(void)
933 int button;
934 #define WORDS (sizeof help_text / sizeof (char*))
935 static char* help_text[] = {
936 "Pegbox", "", "Aim", "",
937 "To", "beat", "each", "level,", "you", "must", "destroy", "all", "of",
938 "the", "pegs.", "If", "two", "like", "pegs", "are", "pushed", "into",
939 "each", "other,", "they", "disappear", "except", "for", "triangles",
940 "which", "form", "a", "solid", "block", "and", "crosses", "which",
941 "allow", "you", "to", "choose", "a", "replacement", "block.", "", "",
942 "Controls", "",
943 RESTART_TEXT, "to", "restart", "level", "",
944 LVL_UP_TEXT, "to", "go", "up", "a", "level", "",
945 LVL_DOWN_TEXT, "to", "go", "down", "a", "level", "",
946 SELECT_TEXT, "to", "choose", "peg", "",
947 QUIT_TEXT, "to", "quit"
949 static struct style_text formation[]={
950 { 0, TEXT_CENTER|TEXT_UNDERLINE },
951 { 2, C_RED },
952 { 46, C_RED },
953 { -1, 0 }
956 rb->lcd_setfont(FONT_UI);
958 if (display_text(WORDS, help_text, formation, NULL))
959 return true;
960 do {
961 button = rb->button_get(true);
962 if ( rb->default_event_handler( button ) == SYS_USB_CONNECTED )
963 return true;
964 } while( ( button == BUTTON_NONE )
965 || ( button & (BUTTON_REL|BUTTON_REPEAT) ) );
966 rb->lcd_setfont(FONT_SYSFIXED);
967 return false;
970 /***********************************************************************
971 * pegbox_menu() is the game menu
972 ************************************************************************/
973 static bool _ingame;
974 static int pegbox_menu_cb(int action, const struct menu_item_ex *this_item)
976 int i = (intptr_t)this_item;
977 if( action == ACTION_REQUEST_MENUITEM )
979 if((!_ingame && (i==0 || i==1)) || ( _ingame && i==2 ))
980 return ACTION_EXIT_MENUITEM;
982 return action;
985 static unsigned int pegbox_menu(struct game_context* pb, bool ingame)
987 int selected = 0;
988 int last_level = pb->level;
990 MENUITEM_STRINGLIST (main_menu, "Pegbox Menu", pegbox_menu_cb,
991 "Resume Game", "Restart Level", "Start Game",
992 "Select Level", "Help",
993 "Playback Control", "Quit");
994 _ingame = ingame;
995 rb->button_clear_queue();
997 while (true) {
998 switch (rb->do_menu(&main_menu, &selected, NULL, false)) {
999 case 0:
1000 pb->level = last_level;
1001 pegbox_draw_board(pb);
1002 return 0;
1003 case 1:
1004 case 2:
1005 pegbox_load_level(pb);
1006 pegbox_draw_board(pb);
1007 return 0;
1008 case 3:
1009 if(rb->set_int("Select Level", "", UNIT_INT, &pb->level,
1010 NULL, 1, 1, pb->highlevel, NULL))
1011 return 1;
1012 break;
1013 case 4:
1014 if (pegbox_help())
1015 return 1;
1016 break;
1017 case 5:
1018 if (playback_control(NULL))
1019 return 1;
1020 break;
1021 case 6:
1022 return 1;
1023 case MENU_ATTACHED_USB:
1024 return 1;
1025 default:
1026 break;
1031 /***********************************************************************
1032 * pegbox_main() is the main game subroutine
1033 ************************************************************************/
1034 static int pegbox_main(struct game_context* pb)
1036 int button;
1038 if (pegbox_menu(pb, false)==1) {
1039 return 1;
1042 while (true) {
1043 button = rb->button_get(true);
1044 #ifdef HAVE_TOUCHSCREEN
1045 if(button & BUTTON_TOUCHSCREEN)
1047 pegbox_raster_btn.two_d_from.y = pb->player_row;
1048 pegbox_raster_btn.two_d_from.x = pb->player_col;
1050 struct ts_raster_button_result ret =
1051 touchscreen_raster_map_button(&pegbox_raster_btn,
1052 rb->button_get_data() >> 16,
1053 rb->button_get_data() & 0xffff,
1054 button);
1055 if(ret.action == TS_ACTION_TWO_D_MOVEMENT)
1056 pegbox_move_player(pb, ret.to.x - ret.from.x, ret.to.y - ret.from.y);
1058 #endif
1059 switch(button){
1060 case PEGBOX_LEFT: /* move cursor left */
1061 case (PEGBOX_LEFT|BUTTON_REPEAT):
1062 pegbox_move_player(pb, -1, 0);
1063 break;
1065 case PEGBOX_RIGHT: /* move cursor right */
1066 case (PEGBOX_RIGHT|BUTTON_REPEAT):
1067 pegbox_move_player(pb, 1, 0);
1068 break;
1070 case PEGBOX_DOWN: /* move cursor down */
1071 case (PEGBOX_DOWN|BUTTON_REPEAT):
1072 pegbox_move_player(pb, 0, 1);
1073 break;
1075 case PEGBOX_UP: /* move cursor up */
1076 case (PEGBOX_UP|BUTTON_REPEAT):
1077 pegbox_move_player(pb, 0, -1);
1078 break;
1080 case PEGBOX_QUIT:
1081 if (pegbox_menu(pb, true)==1) {
1082 return 1;
1084 break;
1086 #ifdef PEGBOX_RESTART
1087 case PEGBOX_RESTART:
1088 pegbox_load_level(pb);
1089 pegbox_draw_board(pb);
1090 break;
1091 #endif
1093 #ifdef PEGBOX_LVL_UP
1094 case (PEGBOX_LVL_UP|BUTTON_REPEAT):
1095 case PEGBOX_LVL_UP:
1096 if (pb->level >= pb->highlevel) {
1097 pb->level = 1;
1098 } else {
1099 pb->level++;
1101 pegbox_load_level(pb);
1102 pegbox_draw_board(pb);
1103 break;
1104 #endif
1106 #ifdef PEGBOX_LVL_DOWN
1107 case (PEGBOX_LVL_DOWN|BUTTON_REPEAT):
1108 case PEGBOX_LVL_DOWN:
1109 if(pb->level <= 1) {
1110 pb->level = pb->highlevel;
1111 } else {
1112 pb->level--;
1114 pegbox_load_level(pb);
1115 pegbox_draw_board(pb);
1116 break;
1117 #endif
1120 if (pb->num_left == 0) {
1121 rb->splash(HZ*2, "Nice Pegging!");
1122 if (pb->level == NUM_LEVELS) {
1123 pegbox_draw_board(pb);
1124 rb->splash(HZ*2, "Congratulations!");
1125 rb->splash(HZ*2, "You have finished the game!");
1126 if (pegbox_menu(pb,false)==1) {
1127 return 1;
1130 else {
1131 pb->level++;
1132 pegbox_load_level(pb);
1133 pegbox_draw_board(pb);
1136 if(pb->level > pb->highlevel)
1137 pb->highlevel = pb->level;
1141 return PLUGIN_OK;
1144 /*****************************************************************************
1145 * plugin entry point.
1146 ******************************************************************************/
1147 enum plugin_status plugin_start(const void* parameter)
1149 (void)parameter;
1150 #ifdef HAVE_LCD_BITMAP
1151 rb->lcd_setfont(FONT_SYSFIXED);
1152 #if LCD_DEPTH > 1
1153 rb->lcd_set_backdrop(NULL);
1154 #endif
1155 #ifdef HAVE_LCD_COLOR
1156 rb->lcd_set_foreground(LCD_WHITE);
1157 rb->lcd_set_background(BG_COLOR);
1158 #endif
1159 rb->lcd_clear_display();
1161 struct game_context pb;
1162 pb.level=1;
1163 pb.highlevel=1;
1164 struct configdata config[] = {
1165 {TYPE_INT, 1, NUM_LEVELS, { .int_p = &(pb.level) }, "level", NULL},
1166 {TYPE_INT, 1, NUM_LEVELS, { .int_p = &(pb.highlevel) }, "highlevel", NULL},
1168 configfile_load(CONFIG_FILE_NAME,config,2,0);
1169 pegbox_main(&pb);
1170 configfile_save(CONFIG_FILE_NAME,config,2,0);
1171 rb->lcd_setfont(FONT_UI);
1172 #endif /* HAVE_LCD_BITMAP */
1174 return PLUGIN_OK;