Revert unwanted submit.
[kugel-rb.git] / apps / plugins / rockblox.c
blobd86cb1c293fa39e2477ac7c7376ffb9ee4e559c0
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2005 Eli Sherer
12 * Heavily modified for embedded use by Björn Stenberg (bjorn@haxx.se)
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
22 ****************************************************************************/
23 #include "plugin.h"
24 #include "lib/display_text.h"
25 #include "lib/helper.h"
26 #include "lib/highscore.h"
27 #include "lib/playback_control.h"
28 #include "lib/playergfx.h"
29 #include "lib/mylcd.h"
33 #if (CONFIG_KEYPAD == IPOD_4G_PAD) || \
34 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
35 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
37 #define ROCKBLOX_OFF (BUTTON_MENU | BUTTON_SELECT)
38 #define ROCKBLOX_ROTATE_CCW BUTTON_SCROLL_BACK
39 #define ROCKBLOX_ROTATE_CCW2 (BUTTON_MENU | BUTTON_REL)
40 #define ROCKBLOX_ROTATE_CW BUTTON_SCROLL_FWD
41 #define ROCKBLOX_LEFT BUTTON_LEFT
42 #define ROCKBLOX_RIGHT BUTTON_RIGHT
43 #define ROCKBLOX_DOWN BUTTON_PLAY
44 #define ROCKBLOX_RESTART (BUTTON_SELECT | BUTTON_PLAY)
45 #define ROCKBLOX_DROP (BUTTON_SELECT | BUTTON_REL)
47 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
48 (CONFIG_KEYPAD == IRIVER_H300_PAD)
50 #define ROCKBLOX_OFF BUTTON_OFF
51 #define ROCKBLOX_ROTATE_CCW BUTTON_UP
52 #define ROCKBLOX_ROTATE_CW BUTTON_SELECT
53 #define ROCKBLOX_DOWN BUTTON_DOWN
54 #define ROCKBLOX_LEFT BUTTON_LEFT
55 #define ROCKBLOX_RIGHT BUTTON_RIGHT
56 #define ROCKBLOX_DROP BUTTON_MODE
57 #define ROCKBLOX_RESTART BUTTON_ON
59 #define ROCKBLOX_RC_OFF BUTTON_RC_STOP
61 #elif CONFIG_KEYPAD == RECORDER_PAD
63 #define ROCKBLOX_OFF BUTTON_OFF
64 #define ROCKBLOX_ROTATE_CCW BUTTON_UP
65 #define ROCKBLOX_ROTATE_CW BUTTON_PLAY
66 #define ROCKBLOX_DOWN BUTTON_DOWN
67 #define ROCKBLOX_LEFT BUTTON_LEFT
68 #define ROCKBLOX_RIGHT BUTTON_RIGHT
69 #define ROCKBLOX_DROP BUTTON_ON
70 #define ROCKBLOX_RESTART BUTTON_F1
72 #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
74 #define ROCKBLOX_OFF BUTTON_OFF
75 #define ROCKBLOX_ROTATE_CCW BUTTON_UP
76 #define ROCKBLOX_ROTATE_CW BUTTON_SELECT
77 #define ROCKBLOX_DOWN BUTTON_DOWN
78 #define ROCKBLOX_LEFT BUTTON_LEFT
79 #define ROCKBLOX_RIGHT BUTTON_RIGHT
80 #define ROCKBLOX_DROP BUTTON_ON
81 #define ROCKBLOX_RESTART BUTTON_F1
83 #elif CONFIG_KEYPAD == PLAYER_PAD
85 #define ROCKBLOX_OFF_PRE BUTTON_STOP
86 #define ROCKBLOX_OFF (BUTTON_STOP|BUTTON_REL)
87 #define ROCKBLOX_ROTATE_CCW BUTTON_PLAY
88 #define ROCKBLOX_ROTATE_CW (BUTTON_ON|BUTTON_PLAY)
89 #define ROCKBLOX_DOWN BUTTON_MENU
90 #define ROCKBLOX_LEFT BUTTON_LEFT
91 #define ROCKBLOX_RIGHT BUTTON_RIGHT
92 #define ROCKBLOX_DROP_PRE BUTTON_ON
93 #define ROCKBLOX_DROP (BUTTON_ON|BUTTON_REL)
94 #define ROCKBLOX_RESTART (BUTTON_STOP|BUTTON_MENU)
96 #elif CONFIG_KEYPAD == ONDIO_PAD
98 #define ROCKBLOX_OFF_PRE BUTTON_OFF
99 #define ROCKBLOX_OFF (BUTTON_OFF|BUTTON_REL)
100 #define ROCKBLOX_ROTATE_CCW BUTTON_UP
101 #define ROCKBLOX_ROTATE_CW (BUTTON_MENU|BUTTON_UP)
102 #define ROCKBLOX_DOWN BUTTON_DOWN
103 #define ROCKBLOX_LEFT BUTTON_LEFT
104 #define ROCKBLOX_RIGHT BUTTON_RIGHT
105 #define ROCKBLOX_DROP_PRE BUTTON_MENU
106 #define ROCKBLOX_DROP (BUTTON_MENU|BUTTON_REL)
107 #define ROCKBLOX_RESTART (BUTTON_OFF|BUTTON_MENU)
109 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
111 #define ROCKBLOX_OFF BUTTON_POWER
112 #define ROCKBLOX_ROTATE_CCW BUTTON_UP
113 #define ROCKBLOX_ROTATE_CW BUTTON_SELECT
114 #define ROCKBLOX_DOWN BUTTON_DOWN
115 #define ROCKBLOX_LEFT BUTTON_LEFT
116 #define ROCKBLOX_RIGHT BUTTON_RIGHT
117 #define ROCKBLOX_DROP BUTTON_REC
118 #define ROCKBLOX_RESTART BUTTON_PLAY
120 #elif CONFIG_KEYPAD == SANSA_E200_PAD
122 #define ROCKBLOX_OFF BUTTON_POWER
123 #define ROCKBLOX_ROTATE_CCW BUTTON_SCROLL_BACK
124 #define ROCKBLOX_ROTATE_CCW2 BUTTON_UP
125 #define ROCKBLOX_ROTATE_CW BUTTON_SCROLL_FWD
126 #define ROCKBLOX_DOWN BUTTON_DOWN
127 #define ROCKBLOX_LEFT BUTTON_LEFT
128 #define ROCKBLOX_RIGHT BUTTON_RIGHT
129 #define ROCKBLOX_DROP BUTTON_SELECT
130 #define ROCKBLOX_RESTART BUTTON_REC
132 #elif CONFIG_KEYPAD == SANSA_FUZE_PAD
134 #define ROCKBLOX_OFF (BUTTON_HOME|BUTTON_REPEAT)
135 #define ROCKBLOX_ROTATE_CCW BUTTON_SCROLL_BACK
136 #define ROCKBLOX_ROTATE_CCW2 BUTTON_UP
137 #define ROCKBLOX_ROTATE_CW BUTTON_SCROLL_FWD
138 #define ROCKBLOX_DOWN BUTTON_DOWN
139 #define ROCKBLOX_LEFT BUTTON_LEFT
140 #define ROCKBLOX_RIGHT BUTTON_RIGHT
141 #define ROCKBLOX_DROP (BUTTON_SELECT | BUTTON_REL)
142 #define ROCKBLOX_RESTART (BUTTON_SELECT | BUTTON_UP)
145 #elif CONFIG_KEYPAD == SANSA_C200_PAD
147 #define ROCKBLOX_OFF BUTTON_POWER
148 #define ROCKBLOX_ROTATE_CCW BUTTON_UP
149 #define ROCKBLOX_ROTATE_CCW2 BUTTON_VOL_DOWN
150 #define ROCKBLOX_ROTATE_CW BUTTON_VOL_UP
151 #define ROCKBLOX_DOWN BUTTON_DOWN
152 #define ROCKBLOX_LEFT BUTTON_LEFT
153 #define ROCKBLOX_RIGHT BUTTON_RIGHT
154 #define ROCKBLOX_DROP BUTTON_SELECT
155 #define ROCKBLOX_RESTART BUTTON_REC
157 #elif CONFIG_KEYPAD == SANSA_CLIP_PAD
159 #define ROCKBLOX_OFF BUTTON_POWER
160 #define ROCKBLOX_ROTATE_CCW BUTTON_UP
161 #define ROCKBLOX_ROTATE_CCW2 BUTTON_VOL_DOWN
162 #define ROCKBLOX_ROTATE_CW BUTTON_VOL_UP
163 #define ROCKBLOX_DOWN BUTTON_DOWN
164 #define ROCKBLOX_LEFT BUTTON_LEFT
165 #define ROCKBLOX_RIGHT BUTTON_RIGHT
166 #define ROCKBLOX_DROP BUTTON_SELECT
167 #define ROCKBLOX_RESTART BUTTON_HOME
169 #elif CONFIG_KEYPAD == SANSA_M200_PAD
171 #define ROCKBLOX_OFF BUTTON_POWER
172 #define ROCKBLOX_ROTATE_CCW BUTTON_UP
173 #define ROCKBLOX_ROTATE_CCW2 BUTTON_VOL_DOWN
174 #define ROCKBLOX_ROTATE_CW BUTTON_VOL_UP
175 #define ROCKBLOX_DOWN BUTTON_DOWN
176 #define ROCKBLOX_LEFT BUTTON_LEFT
177 #define ROCKBLOX_RIGHT BUTTON_RIGHT
178 #define ROCKBLOX_RESTART (BUTTON_SELECT | BUTTON_UP)
179 #define ROCKBLOX_DROP (BUTTON_SELECT | BUTTON_REL)
181 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
183 #define ROCKBLOX_OFF BUTTON_POWER
184 #define ROCKBLOX_ROTATE_CCW BUTTON_SCROLL_UP
185 #define ROCKBLOX_ROTATE_CW BUTTON_REW
186 #define ROCKBLOX_DOWN BUTTON_SCROLL_DOWN
187 #define ROCKBLOX_LEFT BUTTON_LEFT
188 #define ROCKBLOX_RIGHT BUTTON_RIGHT
189 #define ROCKBLOX_DROP BUTTON_FF
190 #define ROCKBLOX_RESTART BUTTON_PLAY
192 #elif CONFIG_KEYPAD == GIGABEAT_PAD
194 #define ROCKBLOX_OFF BUTTON_POWER
195 #define ROCKBLOX_ROTATE_CCW BUTTON_VOL_DOWN
196 #define ROCKBLOX_ROTATE_CW BUTTON_VOL_UP
197 #define ROCKBLOX_ROTATE BUTTON_UP
198 #define ROCKBLOX_DOWN BUTTON_DOWN
199 #define ROCKBLOX_LEFT BUTTON_LEFT
200 #define ROCKBLOX_RIGHT BUTTON_RIGHT
201 #define ROCKBLOX_DROP BUTTON_SELECT
202 #define ROCKBLOX_RESTART BUTTON_A
204 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
206 #define ROCKBLOX_OFF BUTTON_PLAY
207 #define ROCKBLOX_ROTATE_CCW BUTTON_UP
208 #define ROCKBLOX_ROTATE_CW BUTTON_SELECT
209 #define ROCKBLOX_DOWN BUTTON_DOWN
210 #define ROCKBLOX_LEFT BUTTON_LEFT
211 #define ROCKBLOX_RIGHT BUTTON_RIGHT
212 #define ROCKBLOX_DROP BUTTON_MODE
213 #define ROCKBLOX_RESTART BUTTON_EQ
215 #elif CONFIG_KEYPAD == MROBE500_PAD
216 #define ROCKBLOX_OFF BUTTON_POWER
218 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
219 #define ROCKBLOX_OFF BUTTON_BACK
220 #define ROCKBLOX_ROTATE_CCW BUTTON_VOL_DOWN
221 #define ROCKBLOX_ROTATE_CW BUTTON_VOL_UP
222 #define ROCKBLOX_ROTATE BUTTON_UP
223 #define ROCKBLOX_DOWN BUTTON_DOWN
224 #define ROCKBLOX_LEFT BUTTON_LEFT
225 #define ROCKBLOX_RIGHT BUTTON_RIGHT
226 #define ROCKBLOX_DROP BUTTON_SELECT
227 #define ROCKBLOX_RESTART BUTTON_PLAY
229 #elif CONFIG_KEYPAD == MROBE100_PAD
231 #define ROCKBLOX_OFF BUTTON_POWER
232 #define ROCKBLOX_ROTATE_CCW BUTTON_MENU
233 #define ROCKBLOX_ROTATE_CW BUTTON_PLAY
234 #define ROCKBLOX_ROTATE BUTTON_UP
235 #define ROCKBLOX_DOWN BUTTON_DOWN
236 #define ROCKBLOX_LEFT BUTTON_LEFT
237 #define ROCKBLOX_RIGHT BUTTON_RIGHT
238 #define ROCKBLOX_DROP BUTTON_SELECT
239 #define ROCKBLOX_RESTART BUTTON_DISPLAY
241 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
243 #define ROCKBLOX_OFF BUTTON_RC_REC
244 #define ROCKBLOX_ROTATE_CCW BUTTON_RC_VOL_DOWN
245 #define ROCKBLOX_ROTATE_CW BUTTON_RC_VOL_UP
246 #define ROCKBLOX_DOWN BUTTON_RC_MENU
247 #define ROCKBLOX_LEFT BUTTON_RC_REW
248 #define ROCKBLOX_RIGHT BUTTON_RC_FF
249 #define ROCKBLOX_DROP BUTTON_RC_PLAY
250 #define ROCKBLOX_RESTART BUTTON_RC_MODE
252 #elif CONFIG_KEYPAD == COWON_D2_PAD
254 #define ROCKBLOX_OFF BUTTON_POWER
255 #define ROCKBLOX_RESTART BUTTON_MENU
257 #elif CONFIG_KEYPAD == IAUDIO67_PAD
259 #define ROCKBLOX_OFF BUTTON_POWER
260 #define ROCKBLOX_ROTATE_CCW BUTTON_VOLDOWN
261 #define ROCKBLOX_ROTATE_CW BUTTON_VOLUP
262 #define ROCKBLOX_DOWN BUTTON_STOP
263 #define ROCKBLOX_LEFT BUTTON_LEFT
264 #define ROCKBLOX_RIGHT BUTTON_RIGHT
265 #define ROCKBLOX_DROP BUTTON_PLAY
266 #define ROCKBLOX_RESTART BUTTON_MENU
268 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
269 #define ROCKBLOX_OFF BUTTON_BACK
270 #define ROCKBLOX_ROTATE_CCW BUTTON_UP
271 #define ROCKBLOX_ROTATE_CW BUTTON_PLAY
272 #define ROCKBLOX_DOWN BUTTON_DOWN
273 #define ROCKBLOX_LEFT BUTTON_LEFT
274 #define ROCKBLOX_RIGHT BUTTON_RIGHT
275 #define ROCKBLOX_DROP BUTTON_SELECT
276 #define ROCKBLOX_RESTART BUTTON_CUSTOM
278 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
280 #define ROCKBLOX_OFF BUTTON_POWER
281 #define ROCKBLOX_ROTATE_CCW BUTTON_VOL_DOWN
282 #define ROCKBLOX_ROTATE_CW BUTTON_VOL_UP
283 #define ROCKBLOX_ROTATE BUTTON_UP
284 #define ROCKBLOX_DOWN BUTTON_DOWN
285 #define ROCKBLOX_LEFT BUTTON_LEFT
286 #define ROCKBLOX_RIGHT BUTTON_RIGHT
287 #define ROCKBLOX_DROP BUTTON_SELECT
288 #define ROCKBLOX_RESTART BUTTON_MENU
290 #elif CONFIG_KEYPAD == PHILIPS_HDD6330_PAD
292 #define ROCKBLOX_OFF BUTTON_POWER
293 #define ROCKBLOX_ROTATE_CCW BUTTON_PREV
294 #define ROCKBLOX_ROTATE_CW BUTTON_NEXT
295 #define ROCKBLOX_ROTATE BUTTON_UP
296 #define ROCKBLOX_DOWN BUTTON_DOWN
297 #define ROCKBLOX_LEFT BUTTON_LEFT
298 #define ROCKBLOX_RIGHT BUTTON_RIGHT
299 #define ROCKBLOX_DROP BUTTON_PLAY
300 #define ROCKBLOX_RESTART BUTTON_MENU
302 # elif CONFIG_KEYPAD == PHILIPS_SA9200_PAD
304 #define ROCKBLOX_OFF BUTTON_POWER
305 #define ROCKBLOX_ROTATE_CCW BUTTON_VOL_DOWN
306 #define ROCKBLOX_ROTATE_CW BUTTON_VOL_UP
307 #define ROCKBLOX_ROTATE BUTTON_UP
308 #define ROCKBLOX_DOWN BUTTON_DOWN
309 #define ROCKBLOX_LEFT BUTTON_PREV
310 #define ROCKBLOX_RIGHT BUTTON_NEXT
311 #define ROCKBLOX_DROP BUTTON_PLAY
312 #define ROCKBLOX_RESTART BUTTON_MENU
314 #elif CONFIG_KEYPAD == ONDAVX747_PAD
315 #define ROCKBLOX_OFF BUTTON_POWER
316 #define ROCKBLOX_RESTART BUTTON_MENU
317 #elif CONFIG_KEYPAD == ONDAVX777_PAD
318 #define ROCKBLOX_OFF BUTTON_POWER
320 #elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
322 #define ROCKBLOX_OFF (BUTTON_REC|BUTTON_PLAY)
323 #define ROCKBLOX_ROTATE_CCW BUTTON_UP
324 #define ROCKBLOX_ROTATE_CW BUTTON_DOWN
325 #define ROCKBLOX_DOWN BUTTON_REW
326 #define ROCKBLOX_LEFT BUTTON_LEFT
327 #define ROCKBLOX_RIGHT BUTTON_RIGHT
328 #define ROCKBLOX_DROP BUTTON_FFWD
329 #define ROCKBLOX_RESTART (BUTTON_REC|BUTTON_REW)
331 #elif CONFIG_KEYPAD == PBELL_VIBE500_PAD
333 #define ROCKBLOX_OFF BUTTON_REC
334 #define ROCKBLOX_ROTATE_CCW BUTTON_PLAY
335 #define ROCKBLOX_ROTATE_CW BUTTON_MENU
336 #define ROCKBLOX_DOWN BUTTON_DOWN
337 #define ROCKBLOX_LEFT BUTTON_PREV
338 #define ROCKBLOX_RIGHT BUTTON_NEXT
339 #define ROCKBLOX_DROP BUTTON_OK
340 #define ROCKBLOX_RESTART BUTTON_CANCEL
342 #elif CONFIG_KEYPAD == MPIO_HD200_PAD
343 #define ROCKBLOX_OFF (BUTTON_REC|BUTTON_PLAY)
344 #define ROCKBLOX_ROTATE_CCW BUTTON_REW
345 #define ROCKBLOX_ROTATE_CW BUTTON_FF
346 #define ROCKBLOX_DOWN BUTTON_FUNC
347 #define ROCKBLOX_LEFT BUTTON_VOL_DOWN
348 #define ROCKBLOX_RIGHT BUTTON_VOL_UP
349 #define ROCKBLOX_DROP BUTTON_PLAY
350 #define ROCKBLOX_RESTART BUTTON_REC
352 #elif CONFIG_KEYPAD == MPIO_HD300_PAD
353 #define ROCKBLOX_OFF (BUTTON_REC|BUTTON_REPEAT)
354 #define ROCKBLOX_ROTATE_CCW BUTTON_REW
355 #define ROCKBLOX_ROTATE_CW BUTTON_FF
356 #define ROCKBLOX_DOWN BUTTON_DOWN
357 #define ROCKBLOX_LEFT BUTTON_MENU
358 #define ROCKBLOX_RIGHT BUTTON_ENTER
359 #define ROCKBLOX_DROP BUTTON_PLAY
360 #define ROCKBLOX_RESTART BUTTON_REC
362 #else
363 #error No keymap defined!
364 #endif
366 #ifdef HAVE_TOUCHSCREEN
367 #ifndef ROCKBLOX_OFF
368 #define ROCKBLOX_OFF BUTTON_TOPLEFT
369 #endif
370 #ifdef ROCKBLOX_ROTATE_CCW
371 #define ROCKBLOX_ROTATE_CCW2 BUTTON_BOTTOMLEFT
372 #else
373 #define ROCKBLOX_ROTATE_CCW BUTTON_BOTTOMLEFT
374 #endif
375 #ifdef ROCKBLOX_ROTATE_CW
376 #define ROCKBLOX_ROTATE_CW2 BUTTON_BOTTOMRIGHT
377 #else
378 #define ROCKBLOX_ROTATE_CW BUTTON_BOTTOMRIGHT
379 #define ROCKBLOX_ROTATE_CW2 BUTTON_TOPMIDDLE
380 #endif
381 #ifndef ROCKBLOX_DOWN
382 #define ROCKBLOX_DOWN BUTTON_BOTTOMMIDDLE
383 #endif
384 #ifndef ROCKBLOX_LEFT
385 #define ROCKBLOX_LEFT BUTTON_MIDLEFT
386 #endif
387 #ifndef ROCKBLOX_RIGHT
388 #define ROCKBLOX_RIGHT BUTTON_MIDRIGHT
389 #endif
390 #ifndef ROCKBLOX_DROP
391 #define ROCKBLOX_DROP BUTTON_CENTER
392 #endif
393 #ifndef ROCKBLOX_RESTART
394 #define ROCKBLOX_RESTART BUTTON_TOPRIGHT
395 #endif
396 #endif
398 #define BLOCKS_NUM 7
399 #define EMPTY_BLOCK 7
401 #define BOARD_WIDTH 10
403 #ifdef HAVE_LCD_BITMAP
405 #define BOARD_HEIGHT 20
407 #if (LCD_WIDTH == 640) && (LCD_HEIGHT == 480)
409 #define BLOCK_WIDTH 24
410 #define BLOCK_HEIGHT 24
411 #define BOARD_X 172
412 #define BOARD_Y 0
413 #define PREVIEW_X 24
414 #define PREVIEW_Y 22
415 #define LABEL_X 482
416 #define SCORE_Y 50
417 #define LEVEL_Y 140
418 #define LINES_Y 210
420 #elif (LCD_WIDTH == 480) && (LCD_HEIGHT == 640)
422 #define BLOCK_WIDTH 30
423 #define BLOCK_HEIGHT 30
424 #define BOARD_X 14
425 #define BOARD_Y 2
426 #define PREVIEW_X 342
427 #define PREVIEW_Y 482
428 #define LABEL_X 344
429 #define SCORE_Y 58
430 #define LEVEL_Y 142
431 #define LINES_Y 218
433 #elif (LCD_WIDTH == 320) && (LCD_HEIGHT == 240)
435 #define BLOCK_WIDTH 12
436 #define BLOCK_HEIGHT 12
437 #define BOARD_X 86
438 #define BOARD_Y 0
439 #define PREVIEW_X 12
440 #define PREVIEW_Y 11
441 #define LABEL_X 242
442 #define SCORE_Y 25
443 #define LEVEL_Y 70
444 #define LINES_Y 105
446 #elif (LCD_WIDTH == 240) && ((LCD_HEIGHT == 320) || (LCD_HEIGHT == 400))
448 #define BLOCK_WIDTH 15
449 #define BLOCK_HEIGHT 15
450 #define BOARD_X 7
451 #define BOARD_Y 1
452 #define PREVIEW_X 171
453 #define PREVIEW_Y 241
454 #define LABEL_X 172
455 #define SCORE_Y 29
456 #define LEVEL_Y 71
457 #define LINES_Y 109
458 #define HIGH_LABEL_X 172
459 #define HIGH_SCORE_Y 163
460 #define HIGH_LEVEL_Y 172
462 #elif (LCD_WIDTH == 220) && (LCD_HEIGHT == 176)
464 #define BLOCK_WIDTH 8
465 #define BLOCK_HEIGHT 8
466 #define BOARD_X 27
467 #define BOARD_Y 5
468 #define PREVIEW_X 158
469 #define PREVIEW_Y 130
470 #define LABEL_X 147
471 #define SCORE_Y 20
472 #define LEVEL_Y 65
473 #define LINES_Y 100
475 #elif (LCD_WIDTH == 176) && (LCD_HEIGHT == 132)
477 #define BLOCK_WIDTH 6
478 #define BLOCK_HEIGHT 6
479 #define BOARD_X 25
480 #define BOARD_Y 1
481 #define PREVIEW_X 126
482 #define PREVIEW_Y 102
483 #define LABEL_X 112
484 #define SCORE_Y 17
485 #define LEVEL_Y 49
486 #define LINES_Y 81
488 #elif (LCD_WIDTH == 176) && (LCD_HEIGHT == 220)
490 /* no room for the space in the highscore list */
491 #define _SPACE ""
493 #define BLOCK_WIDTH 10
494 #define BLOCK_HEIGHT 10
495 #define BOARD_X 6
496 #define BOARD_Y 10
497 #define PREVIEW_X 124
498 #define PREVIEW_Y 174
499 #define LABEL_X 117
500 #define SCORE_Y 18
501 #define LEVEL_Y 52
502 #define LINES_Y 85
503 #define HIGH_SCORE_Y 119
504 #define HIGH_LEVEL_Y 126
505 #define HIGH_LABEL_X 114
507 #elif (LCD_WIDTH == 160) && (LCD_HEIGHT == 128)
510 #define BLOCK_WIDTH 6
511 #define BLOCK_HEIGHT 6
512 #define BOARD_X 22
513 #define BOARD_Y 3
514 #define PREVIEW_X 114
515 #define PREVIEW_Y 100
516 #define LABEL_X 101
517 #define SCORE_Y 17
518 #define LEVEL_Y 49
519 #define LINES_Y 82
521 #elif (LCD_WIDTH == 138) && (LCD_HEIGHT == 110)
523 #define BLOCK_WIDTH 5
524 #define BLOCK_HEIGHT 5
525 #define BOARD_X 14
526 #define BOARD_Y 0
527 #define PREVIEW_X 98
528 #define PREVIEW_Y 88
529 #define LABEL_X 80
530 #define SCORE_Y 15
531 #define LEVEL_Y 45
532 #define LINES_Y 74
534 #elif (LCD_WIDTH == 132) && (LCD_HEIGHT == 80)
536 #define BLOCK_WIDTH 4
537 #define BLOCK_HEIGHT 4
538 #define BOARD_X 10
539 #define BOARD_Y 0
540 #define PREVIEW_X 89
541 #define PREVIEW_Y 61
542 #define LABEL_X 78
543 #define SCORE_Y 10
544 #define LEVEL_Y 30
545 #define LINES_Y 50
547 #elif (LCD_WIDTH == 128) && (LCD_HEIGHT == 128)
549 #define BLOCK_WIDTH 6
550 #define BLOCK_HEIGHT 6
551 #define BOARD_X 4
552 #define BOARD_Y 3
553 #define PREVIEW_X 84
554 #define PREVIEW_Y 100
555 #define LABEL_X 71
556 #define SCORE_Y 17
557 #define LEVEL_Y 49
558 #define LINES_Y 82
560 #elif (LCD_WIDTH == 128) && (LCD_HEIGHT == 160)
562 #define BLOCK_WIDTH 7
563 #define BLOCK_HEIGHT 7
564 #define BOARD_X 4
565 #define BOARD_Y 5
566 #define PREVIEW_X 88
567 #define PREVIEW_Y 111
568 #define LABEL_X 82
569 #define SCORE_Y (2+16)
570 #define LEVEL_Y (36+16)
571 #define LINES_Y (70+16)
573 #elif (LCD_WIDTH == 128) && (LCD_HEIGHT == 96)
575 #define BLOCK_WIDTH 4
576 #define BLOCK_HEIGHT 4
577 #define BOARD_X 14
578 #define BOARD_Y 2
579 #define PREVIEW_X 89
580 #define PREVIEW_Y 76
581 #define LABEL_X 70
582 #define SCORE_Y 14
583 #define LEVEL_Y 39
584 #define LINES_Y 64
586 #elif (LCD_WIDTH == 128) && (LCD_HEIGHT == 64)
588 #define BLOCK_WIDTH 3
589 #define BLOCK_HEIGHT 3
590 #define BOARD_X 9
591 #define BOARD_Y 3
592 #define PREVIEW_X 53
593 #define PREVIEW_Y 5
594 #define LABEL_X 70
595 #define SCORE_Y 32
596 #define LEVEL_Y 13
597 #define LINES_Y 51
599 #elif (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
601 #define BLOCK_WIDTH 4
602 #define BLOCK_HEIGHT 3
603 #define BOARD_X 9
604 #define BOARD_Y 3
605 #define PREVIEW_X 59
606 #define PREVIEW_Y 5
607 #define LABEL_X 59
608 #define SCORE_Y 32
609 #define LEVEL_Y 13
610 #define LEVEL_X 78
611 #define LINES_Y 51
613 #endif
615 #ifndef LEVEL_X
616 #define LEVEL_X LABEL_X
617 #endif
619 #ifndef LINES_X
620 #define LINES_X LABEL_X
621 #endif
623 extern const fb_data rockblox_background[];
625 #else /* HAVE_LCD_CHARCELLS */
627 #define BOARD_HEIGHT 14
629 #define BLOCK_WIDTH 1
630 #define BLOCK_HEIGHT 1
631 #define BOARD_X 5
632 #define BOARD_Y 0
633 #define PREVIEW_X 15
634 #define PREVIEW_Y 1
636 #endif
638 #ifndef _SPACE
639 #define _SPACE " "
640 #endif
641 /* <<Explanation on Rockblox shapes>>
644 %% - O has 1 orientation
646 %% %
647 %% %% - Z has 2 orientations
650 %% %
651 %% %% - S has 2 orientations
655 % %%%% - I has 2 orientations
658 % %%
659 % % % %%% - L has 4 orientations
660 %% %%% % %
662 % %%
663 % % % %%% - J has 4 orientations
664 %% %%% % %
666 % % %%%
667 %% % %% % - T has 4 orientations
668 % %%% %
671 /* c=current f=figure o=orientation n=next */
672 static struct _rockblox_status
674 int gameover;
675 int lines;
676 int level;
677 int score;
678 int cx;
679 int cy;
680 int cf;
681 int co;
682 int nf;
683 short board[BOARD_HEIGHT][BOARD_WIDTH]; /* 20 rows of 10 blocks */
684 } rockblox_status;
686 /* prototypes */
687 static void draw_next_block(void);
688 static void new_block(void);
690 #ifdef HAVE_SCROLLWHEEL
691 int wheel_events = 0, last_wheel_event = 0;
692 bool wheel_enabled = false;
693 #endif
695 static const short scoring[4] = { /* scoring for each number of lines */
696 #if BOARD_HEIGHT == 20
697 40 /* single */ , 100 /* double */ , 300 /* triple */ , 1200 /* rockblox */
698 #elif BOARD_HEIGHT == 14 /* Player special values */
699 60 /* single */ , 150 /* double */ , 500 /* triple */ , 2000 /* rockblox */
700 #endif
703 struct figure
705 #if LCD_DEPTH >= 2
706 unsigned short color[3]; /* color of figure (light,middle,shadow) */
707 #endif
708 unsigned short max_or; /* max orientations */
709 signed short shapeX[4], shapeY[4]; /* implementation of figures */
712 /* array of figures */
713 figures[BLOCKS_NUM] = {
714 /* O */
716 #if LCD_DEPTH >= 16
717 {LCD_RGBPACK (153, 255, 255), LCD_RGBPACK(0, 255, 255),
718 LCD_RGBPACK(0,153,153)},
719 #elif LCD_DEPTH == 2
720 {LCD_WHITE, LCD_LIGHTGRAY, LCD_DARKGRAY},
721 #endif
723 {-1, 0, -1, 0},
724 {0, 0, 1, 1}
726 /* I */
728 #if LCD_DEPTH >= 16
729 {LCD_RGBPACK (255, 153, 128), LCD_RGBPACK (255, 0, 0),
730 LCD_RGBPACK (153, 0, 0)},
731 #elif LCD_DEPTH == 2
732 {LCD_WHITE, LCD_LIGHTGRAY, LCD_DARKGRAY},
733 #endif
735 {-2, -1, 0, 1},
736 {0, 0, 0, 0}
738 /* 'Z' */
740 #if LCD_DEPTH >= 16
741 {LCD_RGBPACK (153, 255, 153), LCD_RGBPACK (0, 255, 0),
742 LCD_RGBPACK (0, 153, 0)},
743 #elif LCD_DEPTH == 2
744 {LCD_WHITE, LCD_LIGHTGRAY, LCD_DARKGRAY},
745 #endif
747 {0, 1, -1, 0},
748 {0, 0, 1, 1}
750 /* 'S' */
752 #if LCD_DEPTH >= 16
753 {LCD_RGBPACK (153, 153, 255), LCD_RGBPACK (0, 0, 255),
754 LCD_RGBPACK (0, 0, 153)},
755 #elif LCD_DEPTH == 2
756 {LCD_WHITE, LCD_LIGHTGRAY, LCD_DARKGRAY},
757 #endif
759 {-1, 0, 0, 1},
760 {0, 0, 1, 1}
762 /* 'L' */
764 #if LCD_DEPTH >= 16
765 {LCD_RGBPACK (255, 255, 153), LCD_RGBPACK (255, 255, 0),
766 LCD_RGBPACK (153, 153, 0)},
767 #elif LCD_DEPTH == 2
768 {LCD_WHITE, LCD_LIGHTGRAY, LCD_DARKGRAY},
769 #endif
771 {-1, 0, 1, 1},
772 {0, 0, 0, 1}
774 /* 'J' */
776 #if LCD_DEPTH >= 16
777 {LCD_RGBPACK (255, 153, 255), LCD_RGBPACK (255, 0, 255),
778 LCD_RGBPACK (153, 0, 153)},
779 #elif LCD_DEPTH == 2
780 {LCD_WHITE, LCD_LIGHTGRAY, LCD_DARKGRAY},
781 #endif
783 {-1, 0, 1, -1},
784 {0, 0, 0, 1}
786 /* 'T' */
788 #if LCD_DEPTH >= 16
789 {LCD_RGBPACK (204, 204, 204), LCD_RGBPACK (153, 153, 153),
790 LCD_RGBPACK (85, 85, 85)},
791 #elif LCD_DEPTH == 2
792 {LCD_WHITE, LCD_LIGHTGRAY, LCD_DARKGRAY},
793 #endif
795 {-1, 0, 1, 0},
796 {0, 0, 0, 1}
799 bool resume = false;
800 bool resume_file = false;
802 /* Rockbox File System only supports full filenames inc dir */
803 #define SCORE_FILE PLUGIN_GAMES_DIR "/rockblox.score"
804 #define RESUME_FILE PLUGIN_GAMES_DIR "/rockblox.resume"
805 #define NUM_SCORES 5
807 /* Default High Scores... */
808 struct highscore highscores[NUM_SCORES];
810 /* get random number from (0) to (range-1) */
811 static int t_rand (int range)
813 return rb->rand () % range;
816 static inline void show_game_over (void)
818 rb->splash(HZ,"Game over!");
821 /* init the board array to have no blocks */
822 static void init_board (void)
824 int i, j;
825 for (i = 0; i < BOARD_WIDTH; i++)
826 for (j = 0; j < BOARD_HEIGHT; j++)
827 rockblox_status.board[j][i] = EMPTY_BLOCK;
830 /* show the score, level and lines */
831 static void show_details (void)
833 #ifdef HAVE_LCD_BITMAP
834 #if LCD_DEPTH >= 2
835 rb->lcd_set_foreground (LCD_BLACK);
836 rb->lcd_set_background (LCD_WHITE);
837 #endif
838 rb->lcd_putsxyf (LABEL_X, SCORE_Y, "%d", rockblox_status.score);
839 rb->lcd_putsxyf (LEVEL_X, LEVEL_Y, "%d", rockblox_status.level);
840 rb->lcd_putsxyf (LINES_X, LINES_Y, "%d", rockblox_status.lines);
841 #else /* HAVE_LCD_CHARCELLS */
842 rb->lcd_putsf (5, 0, "L%d/%d", rockblox_status.level,
843 rockblox_status.lines);
844 rb->lcd_putsf (5, 1, "S%d", rockblox_status.score);
845 #endif
848 #ifdef HIGH_SCORE_Y
849 static void show_highscores (void)
851 int i;
853 for (i = 0; i<NUM_SCORES; i++)
854 rb->lcd_putsxyf (HIGH_LABEL_X, HIGH_SCORE_Y + (10 * i),
855 "%06d" _SPACE "L%1d", highscores[i].score, highscores[i].level);
857 #endif
859 static void load_game(void)
861 int fd;
863 resume = false;
865 fd = rb->open(RESUME_FILE, O_RDONLY);
866 if (fd < 0) return;
868 if (rb->read(fd, &rockblox_status, sizeof(struct _rockblox_status))
869 < (ssize_t)sizeof(struct _rockblox_status))
871 rb->splash(HZ/2, "Loading Rockblox resume info failed");
872 return;
873 } else {
874 resume = true;
877 rb->close(fd);
879 return;
882 static void dump_resume(void)
884 int fd;
886 fd = rb->open(RESUME_FILE, O_WRONLY|O_CREAT, 0666);
887 if (fd < 0)
888 goto fail;
890 if (rb->write(fd, &rockblox_status, sizeof(struct _rockblox_status))
891 <= 0)
893 rb->close(fd);
894 goto fail;
896 rb->close(fd);
897 return;
899 fail:
900 rb->splash(HZ/2, "Writing Rockblox resume info failed");
901 return;
904 static void init_rockblox (bool resume)
906 char score_name[50];
907 struct tm* tm;
909 tm = rb->get_time();
910 rb->snprintf(score_name, sizeof(score_name), "%04d%02d%02d %02d%02d%02d",
911 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
912 tm->tm_hour, tm->tm_min, tm->tm_sec);
914 #ifdef HAVE_LCD_BITMAP
915 rb->lcd_bitmap (rockblox_background, 0, 0, LCD_WIDTH, LCD_HEIGHT);
916 #else /* HAVE_LCD_CHARCELLS */
917 pgfx_display (0, 0);
918 pgfx_display_block (3, 0, 3, 1);
919 pgfx_display_block (4, 0, 3, 0);
920 rb->lcd_puts(4, 1, " ");
921 pgfx_clear_display();
922 pgfx_fillrect (3, 0, 2, 14);
923 pgfx_fillrect (15, 7, 2, 7);
924 pgfx_update();
925 #endif
926 if (!resume)
928 rockblox_status.level = 1;
929 rockblox_status.lines = 0;
930 rockblox_status.score = 0;
931 rockblox_status.nf = t_rand(BLOCKS_NUM);
932 init_board ();
933 new_block ();
935 draw_next_block();
937 show_details ();
938 #ifdef HIGH_SCORE_Y
939 show_highscores ();
940 #endif
943 static inline int level_speed(int level)
945 #if BOARD_HEIGHT == 20
946 return (5*HZ) / (level + 9);
947 #elif BOARD_HEIGHT == 14
948 return (7*HZ) / (level + 9);
949 #endif
952 static int getRelativeX (int figure, int square, int orientation)
954 switch (orientation) {
955 case 0:
956 return figures[figure].shapeX[square];
957 case 1:
958 return figures[figure].shapeY[square];
959 case 2:
960 return -figures[figure].shapeX[square];
961 case 3:
962 return -figures[figure].shapeY[square];
963 default:
964 return 0;
968 static int getRelativeY (int figure, int square, int orientation)
970 switch (orientation) {
971 case 0:
972 return figures[figure].shapeY[square];
973 case 1:
974 return -figures[figure].shapeX[square];
975 case 2:
976 return -figures[figure].shapeY[square];
977 case 3:
978 return figures[figure].shapeX[square];
979 default:
980 return 0;
984 /* redraw the while board on the screen */
985 static void refresh_board (void)
987 int i, j, x, y, block;
989 #if LCD_DEPTH >= 2
990 rb->lcd_set_foreground (LCD_BLACK);
991 #elif LCD_DEPTH == 1
992 mylcd_set_drawmode (DRMODE_SOLID | DRMODE_INVERSEVID);
993 #endif
995 mylcd_fillrect (BOARD_X, BOARD_Y, BOARD_WIDTH * BLOCK_WIDTH,
996 BOARD_HEIGHT * BLOCK_HEIGHT);
998 #if LCD_DEPTH == 1
999 mylcd_set_drawmode (DRMODE_SOLID);
1000 #endif
1002 for (i = 0; i < BOARD_WIDTH; i++)
1003 for (j = 0; j < BOARD_HEIGHT; j++) {
1004 block = rockblox_status.board[j][i];
1005 if (block != EMPTY_BLOCK) {
1006 #ifdef HAVE_LCD_BITMAP
1007 #if LCD_DEPTH >= 2
1008 /* middle drawing */
1009 rb->lcd_set_foreground (figures[block].color[1]);
1010 #endif
1011 rb->lcd_fillrect (BOARD_X + i * BLOCK_WIDTH,
1012 BOARD_Y + j * BLOCK_HEIGHT,
1013 BLOCK_WIDTH, BLOCK_HEIGHT);
1014 #if LCD_DEPTH >= 2
1015 /* light drawing */
1016 rb->lcd_set_foreground (figures[block].color[0]);
1017 #endif
1018 rb->lcd_vline (BOARD_X + i * BLOCK_WIDTH,
1019 BOARD_Y + j * BLOCK_HEIGHT,
1020 BOARD_Y + (j + 1) * BLOCK_HEIGHT - 2);
1021 rb->lcd_hline (BOARD_X + i * BLOCK_WIDTH,
1022 BOARD_X + (i + 1) * BLOCK_WIDTH - 2,
1023 BOARD_Y + j * BLOCK_HEIGHT);
1024 #if LCD_DEPTH >= 2
1025 /* shadow drawing */
1026 rb->lcd_set_foreground (figures[block].color[2]);
1027 #endif
1028 rb->lcd_vline (BOARD_X + (i + 1) * BLOCK_WIDTH - 1,
1029 BOARD_Y + j * BLOCK_HEIGHT + 1,
1030 BOARD_Y + (j + 1) * BLOCK_HEIGHT - 1);
1031 rb->lcd_hline (BOARD_X + i * BLOCK_WIDTH + 1,
1032 BOARD_X + (i + 1) * BLOCK_WIDTH - 1,
1033 BOARD_Y + (j + 1) * BLOCK_HEIGHT - 1);
1034 #else /* HAVE_LCD_CHARCELLS */
1035 pgfx_drawpixel (BOARD_X + i, BOARD_Y + j);
1036 #endif
1040 for (i = 0; i < 4; i++) {
1041 x = getRelativeX (rockblox_status.cf, i, rockblox_status.co)
1042 + rockblox_status.cx;
1043 y = getRelativeY (rockblox_status.cf, i, rockblox_status.co)
1044 + rockblox_status.cy;
1045 #ifdef HAVE_LCD_BITMAP
1046 #if LCD_DEPTH >= 2
1047 /* middle drawing */
1048 rb->lcd_set_foreground (figures[rockblox_status.cf].color[1]);
1049 #endif
1050 rb->lcd_fillrect (BOARD_X + x * BLOCK_WIDTH,
1051 BOARD_Y + y * BLOCK_HEIGHT,
1052 BLOCK_WIDTH, BLOCK_HEIGHT);
1053 #if LCD_DEPTH >= 2
1054 /* light drawing */
1055 rb->lcd_set_foreground (figures[rockblox_status.cf].color[0]);
1056 #endif
1057 rb->lcd_vline (BOARD_X + x * BLOCK_WIDTH, BOARD_Y + y * BLOCK_HEIGHT,
1058 BOARD_Y + (y + 1) * BLOCK_HEIGHT - 2);
1059 rb->lcd_hline (BOARD_X + x * BLOCK_WIDTH,
1060 BOARD_X + (x + 1) * BLOCK_WIDTH - 2,
1061 BOARD_Y + y * BLOCK_HEIGHT);
1062 #if LCD_DEPTH >= 2
1063 /* shadow drawing */
1064 rb->lcd_set_foreground (figures[rockblox_status.cf].color[2]);
1065 #endif
1066 rb->lcd_vline (BOARD_X + (x + 1) * BLOCK_WIDTH - 1,
1067 BOARD_Y + y * BLOCK_HEIGHT + 1,
1068 BOARD_Y + (y + 1) * BLOCK_HEIGHT - 1);
1069 rb->lcd_hline (BOARD_X + x * BLOCK_WIDTH + 1,
1070 BOARD_X + (x + 1) * BLOCK_WIDTH - 1,
1071 BOARD_Y + (y + 1) * BLOCK_HEIGHT - 1);
1072 #else /* HAVE_LCD_CHARCELLS */
1073 pgfx_drawpixel (BOARD_X + x, BOARD_Y + y);
1074 #endif
1076 mylcd_update ();
1079 static bool canMoveTo (int x, int y, int newOrientation)
1081 int i, rx, ry;
1082 for (i = 0; i < 4; i++) {
1083 ry = getRelativeY (rockblox_status.cf, i, newOrientation) + y;
1084 rx = getRelativeX (rockblox_status.cf, i, newOrientation) + x;
1085 if ((rx < 0 || rx >= BOARD_WIDTH) ||
1086 (ry < 0 || ry >= BOARD_HEIGHT) ||
1087 (rockblox_status.board[ry][rx] != EMPTY_BLOCK))
1088 return false;
1090 return true;
1093 /* draws the preview of next block in the preview window */
1094 static void draw_next_block (void)
1096 int i, rx, ry;
1097 /* clear preview window first */
1098 #if LCD_DEPTH >= 2
1099 rb->lcd_set_foreground (LCD_BLACK);
1100 #elif LCD_DEPTH == 1
1101 mylcd_set_drawmode (DRMODE_SOLID | DRMODE_INVERSEVID);
1102 #endif
1104 /* 4x4 */
1105 mylcd_fillrect (PREVIEW_X, PREVIEW_Y, BLOCK_WIDTH * 4, BLOCK_HEIGHT * 4);
1107 #if LCD_DEPTH == 1
1108 mylcd_set_drawmode (DRMODE_SOLID);
1109 #endif
1111 /* draw the lightgray rectangles */
1112 #if LCD_DEPTH >= 16
1113 rb->lcd_set_foreground (LCD_RGBPACK (40, 40, 40));
1114 #elif LCD_DEPTH == 2
1115 rb->lcd_set_foreground (LCD_DARKGRAY);
1116 #endif
1118 #if LCD_DEPTH >= 2
1119 for (rx = 0; rx < 4; rx++)
1120 for (ry = 0; ry < 4; ry++)
1121 rb->lcd_drawrect (PREVIEW_X + rx * BLOCK_WIDTH,
1122 PREVIEW_Y + ry * BLOCK_HEIGHT, BLOCK_WIDTH,
1123 BLOCK_HEIGHT);
1124 #endif
1126 /* draw the figure */
1127 for (i = 0; i < 4; i++) {
1128 rx = getRelativeX (rockblox_status.nf, i, 0) + 2;
1129 ry = getRelativeY (rockblox_status.nf, i, 0) + 2;
1130 #ifdef HAVE_LCD_BITMAP
1131 #if LCD_DEPTH >= 2
1132 rb->lcd_set_foreground (figures[rockblox_status.nf].color[1]); /* middle drawing */
1133 #endif
1134 rb->lcd_fillrect (PREVIEW_X + rx * BLOCK_WIDTH,
1135 PREVIEW_Y + ry * BLOCK_HEIGHT,
1136 BLOCK_WIDTH, BLOCK_HEIGHT);
1137 #if LCD_DEPTH >= 2
1138 rb->lcd_set_foreground (figures[rockblox_status.nf].color[0]); /* light drawing */
1139 #endif
1140 rb->lcd_vline (PREVIEW_X + rx * BLOCK_WIDTH,
1141 PREVIEW_Y + ry * BLOCK_HEIGHT,
1142 PREVIEW_Y + (ry + 1) * BLOCK_HEIGHT - 2);
1143 rb->lcd_hline (PREVIEW_X + rx * BLOCK_WIDTH,
1144 PREVIEW_X + (rx + 1) * BLOCK_WIDTH - 2,
1145 PREVIEW_Y + ry * BLOCK_HEIGHT);
1146 #if LCD_DEPTH >= 2
1147 rb->lcd_set_foreground (figures[rockblox_status.nf].color[2]); /* shadow drawing */
1148 #endif
1149 rb->lcd_vline (PREVIEW_X + (rx + 1) * BLOCK_WIDTH - 1,
1150 PREVIEW_Y + ry * BLOCK_HEIGHT + 1,
1151 PREVIEW_Y + (ry + 1) * BLOCK_HEIGHT - 1);
1152 rb->lcd_hline (PREVIEW_X + rx * BLOCK_WIDTH + 1,
1153 PREVIEW_X + (rx + 1) * BLOCK_WIDTH - 1,
1154 PREVIEW_Y + (ry + 1) * BLOCK_HEIGHT - 1);
1155 #else /* HAVE_LCD_CHARCELLS */
1156 pgfx_drawpixel (PREVIEW_X + rx, PREVIEW_Y + ry);
1157 #endif
1162 /* move the block to a relative location */
1163 static void move_block (int x, int y, int o)
1165 if (canMoveTo (rockblox_status.cx + x, rockblox_status.cy + y, o)) {
1166 rockblox_status.cy += y;
1167 rockblox_status.cx += x;
1168 rockblox_status.co = o;
1172 /* try to add a new block to play with (return true if gameover) */
1173 static void new_block (void)
1175 rockblox_status.cy = 1;
1176 rockblox_status.cx = 5;
1177 rockblox_status.cf = rockblox_status.nf;
1178 rockblox_status.co = 0; /* start at the same orientation all time */
1179 rockblox_status.nf = t_rand (BLOCKS_NUM);
1180 rockblox_status.gameover = !canMoveTo (rockblox_status.cx,
1181 rockblox_status.cy, rockblox_status.co);
1183 draw_next_block ();
1187 /* check for filled rockblox_status.lines and do what necessary */
1188 static int check_lines (void)
1191 int i, j, y;
1192 int rockblox = 0;
1194 for (j = 0; j < BOARD_HEIGHT; j++) {
1195 for (i = 0; ((i < BOARD_WIDTH) &&
1196 (rockblox_status.board[j][i] != EMPTY_BLOCK)); i++);
1197 if (i == BOARD_WIDTH) { /* woo hoo, we have a line */
1198 rockblox++;
1199 for (y = j; y > 0; y--)
1201 for (i = 0; i < BOARD_WIDTH; i++)
1202 { /* fall line */
1203 rockblox_status.board[y][i] = rockblox_status.board[y - 1][i];
1209 return rockblox;
1212 /* moves down the figure and returns true if gameover */
1213 static void move_down (void)
1215 int l, i, rx, ry;
1217 if (!canMoveTo (rockblox_status.cx, rockblox_status.cy + 1, rockblox_status.co)) {
1218 /* save figure to board */
1219 for (i = 0; i < 4; i++) {
1220 rx = getRelativeX (rockblox_status.cf, i, rockblox_status.co) + rockblox_status.cx;
1221 ry = getRelativeY (rockblox_status.cf, i, rockblox_status.co) + rockblox_status.cy;
1222 rockblox_status.board[ry][rx] = rockblox_status.cf;
1224 /* check if formed some lines */
1225 l = check_lines ();
1226 if (l) {
1227 /* the original scoring from "http://en.wikipedia.org/wiki/Rockblox" */
1228 rockblox_status.score += scoring[l - 1] * rockblox_status.level;
1229 rockblox_status.lines += l;
1230 rockblox_status.level = (int) rockblox_status.lines / 10 + 1;
1233 /* show details */
1234 show_details ();
1236 /* generate a new figure */
1237 new_block ();
1238 } else
1239 move_block (0, 1, rockblox_status.co);
1242 static bool rockblox_help(void)
1244 static char *help_text[] = {
1245 "Rockblox", "", "Aim", "",
1246 "Make", "the", "falling", "blocks", "of",
1247 "different", "shapes", "form", "full", "rows.",
1248 "Whenever", "a", "row", "is", "completed,",
1249 "it", "will", "be", "cleared", "away",
1250 "and", "you", "gain", "points."
1252 static struct style_text formation[]={
1253 { 0, TEXT_CENTER|TEXT_UNDERLINE },
1254 { 2, C_RED },
1255 LAST_STYLE_ITEM
1258 #ifdef HAVE_LCD_BITMAP
1259 rb->lcd_setfont(FONT_UI);
1260 #endif
1261 #ifdef HAVE_LCD_COLOR
1262 rb->lcd_set_background(LCD_BLACK);
1263 rb->lcd_set_foreground(LCD_WHITE);
1264 #endif
1265 if (display_text(ARRAYLEN(help_text), help_text, formation, NULL, true))
1266 return true;
1267 #ifdef HAVE_LCD_BITMAP
1268 rb->lcd_setfont(FONT_SYSFIXED);
1269 #endif
1271 return false;
1274 static int rockblox_menu_cb(int action, const struct menu_item_ex *this_item)
1276 int i = ((intptr_t)this_item);
1277 if(action == ACTION_REQUEST_MENUITEM
1278 && !resume && (i==0 || i==5))
1279 return ACTION_EXIT_MENUITEM;
1280 return action;
1283 static int rockblox_menu(void)
1285 int selected = 0;
1287 MENUITEM_STRINGLIST(main_menu, "Rockblox Menu", rockblox_menu_cb,
1288 "Resume Game", "Start New Game",
1289 "Help", "High Scores", "Playback Control",
1290 "Quit without Saving", "Quit");
1292 rb->button_clear_queue();
1293 while (true) {
1294 switch (rb->do_menu(&main_menu, &selected, NULL, false)) {
1295 case 0:
1296 if(resume_file)
1297 rb->remove(RESUME_FILE);
1298 init_rockblox(true);
1299 return 0;
1300 case 1:
1301 init_rockblox(false);
1302 return 0;
1303 case 2:
1304 if (rockblox_help())
1305 return 1;
1306 break;
1307 case 3:
1308 highscore_show(-1, highscores, NUM_SCORES, true);
1309 break;
1310 case 4:
1311 if (playback_control(NULL))
1312 return 1;
1313 break;
1314 case 5:
1315 return 1;
1316 case 6:
1317 if (resume) {
1318 rb->splash(HZ*1, "Saving game ...");
1319 dump_resume();
1321 return 1;
1322 case MENU_ATTACHED_USB:
1323 return 1;
1324 default:
1325 return 1;
1326 break;
1332 static int rockblox_loop (void)
1334 int button;
1335 int lastbutton = BUTTON_NONE;
1336 long next_down_tick = *rb->current_tick + level_speed(rockblox_status.level);
1338 if (rockblox_menu()) {
1339 return 1;
1341 resume = false;
1342 resume_file = false;
1344 while (1) {
1345 #ifdef HAS_BUTTON_HOLD
1346 if (rb->button_hold ()) {
1347 /* Turn on backlight timeout (revert to settings) */
1348 backlight_use_settings();
1349 rb->splash(0, "Paused");
1350 while (rb->button_hold ())
1351 rb->sleep(HZ/10);
1353 /* Turn off backlight timeout */
1354 backlight_ignore_timeout();
1356 /* get rid of the splash text */
1357 rb->lcd_bitmap (rockblox_background, 0, 0, LCD_WIDTH, LCD_HEIGHT);
1358 show_details ();
1359 #ifdef HIGH_SCORE_Y
1360 show_highscores ();
1361 #endif
1362 draw_next_block ();
1363 refresh_board ();
1365 #endif
1367 button = rb->button_get_w_tmo (MAX(next_down_tick - *rb->current_tick, 1));
1368 switch (button) {
1369 #ifdef ROCKBLOX_RC_OFF
1370 case ROCKBLOX_RC_OFF:
1371 #endif
1372 case ROCKBLOX_OFF:
1373 #ifdef ROCKBLOX_OFF_PRE
1374 if (lastbutton != ROCKBLOX_OFF_PRE)
1375 break;
1376 #endif
1377 resume = true;
1378 return 0;
1379 break;
1381 #if defined(ROCKBLOX_ROTATE)
1382 case ROCKBLOX_ROTATE:
1383 #endif
1384 case ROCKBLOX_ROTATE_CCW:
1385 case ROCKBLOX_ROTATE_CCW | BUTTON_REPEAT:
1386 #ifdef HAVE_SCROLLWHEEL
1387 /* if the wheel is disabled, add an event to the stack. */
1388 if(wheel_enabled == false)
1389 wheel_events++;
1391 /* if it's enabled, go ahead and rotate.. */
1392 if(wheel_enabled)
1393 #endif
1394 #ifdef ROCKBLOX_ROTATE_CCW2
1395 /* fallback */
1396 case ROCKBLOX_ROTATE_CCW2:
1397 #endif
1398 move_block (0, 0, (rockblox_status.co + 1) % figures[rockblox_status.cf].max_or);
1399 break;
1401 case ROCKBLOX_ROTATE_CW:
1402 case ROCKBLOX_ROTATE_CW | BUTTON_REPEAT:
1403 #ifdef HAVE_SCROLLWHEEL
1404 if(wheel_enabled == false)
1405 wheel_events++;
1407 if(wheel_enabled)
1408 #endif
1409 #ifdef ROCKBLOX_ROTATE_CW2
1410 /* fallback */
1411 case ROCKBLOX_ROTATE_CW2:
1412 #endif
1413 move_block (0, 0,
1414 (rockblox_status.co + figures[rockblox_status.cf].max_or -
1415 1) % figures[rockblox_status.cf].max_or);
1416 break;
1418 case ROCKBLOX_DOWN:
1419 case ROCKBLOX_DOWN | BUTTON_REPEAT:
1420 move_block (0, 1, rockblox_status.co);
1421 break;
1423 case ROCKBLOX_RIGHT:
1424 case ROCKBLOX_RIGHT | BUTTON_REPEAT:
1425 move_block (1, 0, rockblox_status.co);
1426 break;
1428 case ROCKBLOX_LEFT:
1429 case ROCKBLOX_LEFT | BUTTON_REPEAT:
1430 move_block (-1, 0, rockblox_status.co);
1431 break;
1433 case ROCKBLOX_DROP:
1434 #ifdef ROCKBLOX_DROP_PRE
1435 if (lastbutton != ROCKBLOX_DROP_PRE)
1436 break;
1437 #endif
1438 while (canMoveTo (rockblox_status.cx, rockblox_status.cy + 1, rockblox_status.co))
1439 move_block (0, 1, rockblox_status.co);
1440 break;
1441 #ifdef ROCKBLOX_RESTART
1442 case ROCKBLOX_RESTART:
1443 rb->splash (HZ * 1, "Restarting...");
1444 init_rockblox (false);
1445 break;
1446 #endif
1448 default:
1449 if (rb->default_event_handler (button) == SYS_USB_CONNECTED)
1450 return PLUGIN_USB_CONNECTED;
1451 break;
1453 if (button != BUTTON_NONE)
1454 lastbutton = button;
1456 #ifdef HAVE_SCROLLWHEEL
1457 /* check if we should enable the scroll wheel, if events
1458 * begin to stack up... */
1459 if(wheel_enabled == false)
1461 /* stopped rotating the wheel, reset the count */
1462 if(wheel_events == last_wheel_event)
1464 last_wheel_event = 0;
1465 wheel_events = 0;
1467 /* rotated the wheel a while constantly, enable it. */
1468 else if(wheel_events > 3)
1470 wheel_enabled = true;
1473 /* this evens out the last event and the "current" event.
1474 * if we get an event next time through button reading, it will
1475 * remain ahead of last_event. if we don't, they'll end up equaling
1476 * each other.. thus, the scroll count will be reset. */
1477 if(wheel_enabled == false && wheel_events > last_wheel_event)
1478 last_wheel_event++;
1480 #endif
1482 if (TIME_AFTER(*rb->current_tick, next_down_tick)) {
1483 move_down ();
1484 next_down_tick += level_speed(rockblox_status.level);
1485 if (TIME_AFTER(*rb->current_tick, next_down_tick))
1486 /* restart time "raster" when we had to wait longer than usual
1487 * (pause, game restart etc) */
1488 next_down_tick = *rb->current_tick + level_speed(rockblox_status.level);
1491 if (rockblox_status.gameover) {
1492 #if LCD_DEPTH >= 2
1493 rb->lcd_set_foreground (LCD_BLACK);
1494 #endif
1495 show_game_over();
1496 resume = false;
1497 return 0;
1500 refresh_board ();
1503 return 0;
1506 enum plugin_status plugin_start (const void *parameter)
1509 (void) parameter;
1511 rb->srand (*rb->current_tick);
1513 /* Load HighScore if any */
1514 highscore_load(SCORE_FILE, highscores, NUM_SCORES);
1516 #if LCD_DEPTH > 1
1517 rb->lcd_set_backdrop(NULL);
1518 #endif
1520 #ifdef HAVE_LCD_BITMAP
1521 rb->lcd_setfont (FONT_SYSFIXED);
1522 #else
1523 if (!pgfx_init(4, 2))
1525 rb->splash(HZ*2, "Old LCD :(");
1526 return PLUGIN_OK;
1528 #endif
1529 /* Turn off backlight timeout */
1530 backlight_ignore_timeout();
1531 load_game();
1532 resume_file = resume;
1533 while(!rockblox_loop()) {
1534 if(!resume) {
1535 int position = highscore_update(rockblox_status.score,
1536 rockblox_status.level, "",
1537 highscores, NUM_SCORES);
1538 if (position != -1) {
1539 if (position == 0)
1540 rb->splash(HZ*2, "New High Score");
1541 highscore_show(position, highscores, NUM_SCORES, true);
1546 #ifndef HAVE_LCD_BITMAP
1547 pgfx_release();
1548 #endif
1549 /* Save user's HighScore */
1550 highscore_save(SCORE_FILE, highscores, NUM_SCORES);
1551 backlight_use_settings();
1553 return PLUGIN_OK;