fix red.
[kugel-rb/myfork.git] / apps / plugins / rockblox.c
blob369252607310b4207609c9a900379640eb6e7e63
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/highscore.h"
25 #include "lib/playergfx.h"
26 #include "lib/helper.h"
28 PLUGIN_HEADER
30 #if (CONFIG_KEYPAD == IPOD_4G_PAD) || \
31 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
32 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
34 #define ROCKBLOX_OFF (BUTTON_MENU | BUTTON_SELECT)
35 #define ROCKBLOX_ROTATE_RIGHT BUTTON_SCROLL_BACK
36 #define ROCKBLOX_ROTATE_RIGHT2 (BUTTON_MENU | BUTTON_REL)
37 #define ROCKBLOX_ROTATE_LEFT BUTTON_SCROLL_FWD
38 #define ROCKBLOX_LEFT BUTTON_LEFT
39 #define ROCKBLOX_RIGHT BUTTON_RIGHT
40 #define ROCKBLOX_DOWN BUTTON_PLAY
41 #define ROCKBLOX_RESTART (BUTTON_SELECT | BUTTON_PLAY)
42 #define ROCKBLOX_DROP (BUTTON_SELECT | BUTTON_REL)
44 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
45 (CONFIG_KEYPAD == IRIVER_H300_PAD)
47 #define ROCKBLOX_OFF BUTTON_OFF
48 #define ROCKBLOX_ROTATE_RIGHT BUTTON_UP
49 #define ROCKBLOX_ROTATE_LEFT BUTTON_SELECT
50 #define ROCKBLOX_DOWN BUTTON_DOWN
51 #define ROCKBLOX_LEFT BUTTON_LEFT
52 #define ROCKBLOX_RIGHT BUTTON_RIGHT
53 #define ROCKBLOX_DROP BUTTON_MODE
54 #define ROCKBLOX_RESTART BUTTON_ON
56 #define ROCKBLOX_RC_OFF BUTTON_RC_STOP
58 #elif CONFIG_KEYPAD == RECORDER_PAD
60 #define ROCKBLOX_OFF BUTTON_OFF
61 #define ROCKBLOX_ROTATE_RIGHT BUTTON_UP
62 #define ROCKBLOX_ROTATE_LEFT BUTTON_PLAY
63 #define ROCKBLOX_DOWN BUTTON_DOWN
64 #define ROCKBLOX_LEFT BUTTON_LEFT
65 #define ROCKBLOX_RIGHT BUTTON_RIGHT
66 #define ROCKBLOX_DROP BUTTON_ON
67 #define ROCKBLOX_RESTART BUTTON_F1
69 #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
71 #define ROCKBLOX_OFF BUTTON_OFF
72 #define ROCKBLOX_ROTATE_RIGHT BUTTON_UP
73 #define ROCKBLOX_ROTATE_LEFT BUTTON_SELECT
74 #define ROCKBLOX_DOWN BUTTON_DOWN
75 #define ROCKBLOX_LEFT BUTTON_LEFT
76 #define ROCKBLOX_RIGHT BUTTON_RIGHT
77 #define ROCKBLOX_DROP BUTTON_ON
78 #define ROCKBLOX_RESTART BUTTON_F1
80 #elif CONFIG_KEYPAD == PLAYER_PAD
82 #define ROCKBLOX_OFF_PRE BUTTON_STOP
83 #define ROCKBLOX_OFF (BUTTON_STOP|BUTTON_REL)
84 #define ROCKBLOX_ROTATE_RIGHT BUTTON_PLAY
85 #define ROCKBLOX_ROTATE_LEFT (BUTTON_ON|BUTTON_PLAY)
86 #define ROCKBLOX_DOWN BUTTON_MENU
87 #define ROCKBLOX_LEFT BUTTON_LEFT
88 #define ROCKBLOX_RIGHT BUTTON_RIGHT
89 #define ROCKBLOX_DROP_PRE BUTTON_ON
90 #define ROCKBLOX_DROP (BUTTON_ON|BUTTON_REL)
91 #define ROCKBLOX_RESTART (BUTTON_STOP|BUTTON_MENU)
93 #elif CONFIG_KEYPAD == ONDIO_PAD
95 #define ROCKBLOX_OFF_PRE BUTTON_OFF
96 #define ROCKBLOX_OFF (BUTTON_OFF|BUTTON_REL)
97 #define ROCKBLOX_ROTATE_RIGHT BUTTON_UP
98 #define ROCKBLOX_ROTATE_LEFT (BUTTON_MENU|BUTTON_UP)
99 #define ROCKBLOX_DOWN BUTTON_DOWN
100 #define ROCKBLOX_LEFT BUTTON_LEFT
101 #define ROCKBLOX_RIGHT BUTTON_RIGHT
102 #define ROCKBLOX_DROP_PRE BUTTON_MENU
103 #define ROCKBLOX_DROP (BUTTON_MENU|BUTTON_REL)
104 #define ROCKBLOX_RESTART (BUTTON_OFF|BUTTON_MENU)
106 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
108 #define ROCKBLOX_OFF BUTTON_POWER
109 #define ROCKBLOX_ROTATE_RIGHT BUTTON_UP
110 #define ROCKBLOX_ROTATE_LEFT BUTTON_SELECT
111 #define ROCKBLOX_DOWN BUTTON_DOWN
112 #define ROCKBLOX_LEFT BUTTON_LEFT
113 #define ROCKBLOX_RIGHT BUTTON_RIGHT
114 #define ROCKBLOX_DROP BUTTON_REC
115 #define ROCKBLOX_RESTART BUTTON_PLAY
117 #elif CONFIG_KEYPAD == SANSA_E200_PAD
119 #define ROCKBLOX_OFF BUTTON_POWER
120 #define ROCKBLOX_ROTATE_RIGHT BUTTON_SCROLL_BACK
121 #define ROCKBLOX_ROTATE_RIGHT2 BUTTON_UP
122 #define ROCKBLOX_ROTATE_LEFT BUTTON_SCROLL_FWD
123 #define ROCKBLOX_DOWN BUTTON_DOWN
124 #define ROCKBLOX_LEFT BUTTON_LEFT
125 #define ROCKBLOX_RIGHT BUTTON_RIGHT
126 #define ROCKBLOX_DROP BUTTON_SELECT
127 #define ROCKBLOX_RESTART BUTTON_REC
129 #elif CONFIG_KEYPAD == SANSA_FUZE_PAD
131 #define ROCKBLOX_OFF (BUTTON_HOME|BUTTON_REPEAT)
132 #define ROCKBLOX_ROTATE_RIGHT BUTTON_SCROLL_BACK
133 #define ROCKBLOX_ROTATE_RIGHT2 BUTTON_UP
134 #define ROCKBLOX_ROTATE_LEFT BUTTON_SCROLL_FWD
135 #define ROCKBLOX_DOWN BUTTON_DOWN
136 #define ROCKBLOX_LEFT BUTTON_LEFT
137 #define ROCKBLOX_RIGHT BUTTON_RIGHT
138 #define ROCKBLOX_DROP (BUTTON_SELECT | BUTTON_REL)
139 #define ROCKBLOX_RESTART (BUTTON_SELECT | BUTTON_UP)
142 #elif CONFIG_KEYPAD == SANSA_C200_PAD
144 #define ROCKBLOX_OFF BUTTON_POWER
145 #define ROCKBLOX_ROTATE_RIGHT BUTTON_UP
146 #define ROCKBLOX_ROTATE_RIGHT2 BUTTON_VOL_DOWN
147 #define ROCKBLOX_ROTATE_LEFT BUTTON_VOL_UP
148 #define ROCKBLOX_DOWN BUTTON_DOWN
149 #define ROCKBLOX_LEFT BUTTON_LEFT
150 #define ROCKBLOX_RIGHT BUTTON_RIGHT
151 #define ROCKBLOX_DROP BUTTON_SELECT
152 #define ROCKBLOX_RESTART BUTTON_REC
154 #elif CONFIG_KEYPAD == SANSA_CLIP_PAD
156 #define ROCKBLOX_OFF BUTTON_POWER
157 #define ROCKBLOX_ROTATE_RIGHT BUTTON_UP
158 #define ROCKBLOX_ROTATE_RIGHT2 BUTTON_VOL_DOWN
159 #define ROCKBLOX_ROTATE_LEFT BUTTON_VOL_UP
160 #define ROCKBLOX_DOWN BUTTON_DOWN
161 #define ROCKBLOX_LEFT BUTTON_LEFT
162 #define ROCKBLOX_RIGHT BUTTON_RIGHT
163 #define ROCKBLOX_DROP BUTTON_SELECT
164 #define ROCKBLOX_RESTART BUTTON_HOME
166 #elif CONFIG_KEYPAD == SANSA_M200_PAD
168 #define ROCKBLOX_OFF BUTTON_POWER
169 #define ROCKBLOX_ROTATE_RIGHT BUTTON_UP
170 #define ROCKBLOX_ROTATE_RIGHT2 BUTTON_VOL_DOWN
171 #define ROCKBLOX_ROTATE_LEFT BUTTON_VOL_UP
172 #define ROCKBLOX_DOWN BUTTON_DOWN
173 #define ROCKBLOX_LEFT BUTTON_LEFT
174 #define ROCKBLOX_RIGHT BUTTON_RIGHT
175 #define ROCKBLOX_RESTART (BUTTON_SELECT | BUTTON_UP)
176 #define ROCKBLOX_DROP (BUTTON_SELECT | BUTTON_REL)
178 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
180 #define ROCKBLOX_OFF BUTTON_POWER
181 #define ROCKBLOX_ROTATE_RIGHT BUTTON_SCROLL_UP
182 #define ROCKBLOX_ROTATE_LEFT BUTTON_REW
183 #define ROCKBLOX_DOWN BUTTON_SCROLL_DOWN
184 #define ROCKBLOX_LEFT BUTTON_LEFT
185 #define ROCKBLOX_RIGHT BUTTON_RIGHT
186 #define ROCKBLOX_DROP BUTTON_FF
187 #define ROCKBLOX_RESTART BUTTON_PLAY
189 #elif CONFIG_KEYPAD == GIGABEAT_PAD
191 #define ROCKBLOX_OFF BUTTON_POWER
192 #define ROCKBLOX_ROTATE_RIGHT BUTTON_VOL_DOWN
193 #define ROCKBLOX_ROTATE_LEFT BUTTON_VOL_UP
194 #define ROCKBLOX_ROTATE BUTTON_UP
195 #define ROCKBLOX_DOWN BUTTON_DOWN
196 #define ROCKBLOX_LEFT BUTTON_LEFT
197 #define ROCKBLOX_RIGHT BUTTON_RIGHT
198 #define ROCKBLOX_DROP BUTTON_SELECT
199 #define ROCKBLOX_RESTART BUTTON_A
201 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
203 #define ROCKBLOX_OFF BUTTON_PLAY
204 #define ROCKBLOX_ROTATE_RIGHT BUTTON_UP
205 #define ROCKBLOX_ROTATE_LEFT BUTTON_SELECT
206 #define ROCKBLOX_DOWN BUTTON_DOWN
207 #define ROCKBLOX_LEFT BUTTON_LEFT
208 #define ROCKBLOX_RIGHT BUTTON_RIGHT
209 #define ROCKBLOX_DROP BUTTON_MODE
210 #define ROCKBLOX_RESTART BUTTON_EQ
212 #elif CONFIG_KEYPAD == MROBE500_PAD
213 #define ROCKBLOX_OFF BUTTON_POWER
215 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
216 #define ROCKBLOX_OFF BUTTON_BACK
217 #define ROCKBLOX_ROTATE_RIGHT BUTTON_VOL_DOWN
218 #define ROCKBLOX_ROTATE_LEFT BUTTON_VOL_UP
219 #define ROCKBLOX_ROTATE BUTTON_UP
220 #define ROCKBLOX_DOWN BUTTON_DOWN
221 #define ROCKBLOX_LEFT BUTTON_LEFT
222 #define ROCKBLOX_RIGHT BUTTON_RIGHT
223 #define ROCKBLOX_DROP BUTTON_SELECT
224 #define ROCKBLOX_RESTART BUTTON_PLAY
226 #elif CONFIG_KEYPAD == MROBE100_PAD
228 #define ROCKBLOX_OFF BUTTON_POWER
229 #define ROCKBLOX_ROTATE_RIGHT BUTTON_MENU
230 #define ROCKBLOX_ROTATE_LEFT BUTTON_PLAY
231 #define ROCKBLOX_ROTATE BUTTON_UP
232 #define ROCKBLOX_DOWN BUTTON_DOWN
233 #define ROCKBLOX_LEFT BUTTON_LEFT
234 #define ROCKBLOX_RIGHT BUTTON_RIGHT
235 #define ROCKBLOX_DROP BUTTON_SELECT
236 #define ROCKBLOX_RESTART BUTTON_DISPLAY
238 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
240 #define ROCKBLOX_OFF BUTTON_RC_REC
241 #define ROCKBLOX_ROTATE_RIGHT BUTTON_RC_VOL_DOWN
242 #define ROCKBLOX_ROTATE_LEFT BUTTON_RC_VOL_UP
243 #define ROCKBLOX_DOWN BUTTON_RC_MENU
244 #define ROCKBLOX_LEFT BUTTON_RC_REW
245 #define ROCKBLOX_RIGHT BUTTON_RC_FF
246 #define ROCKBLOX_DROP BUTTON_RC_PLAY
247 #define ROCKBLOX_RESTART BUTTON_RC_MODE
249 #elif CONFIG_KEYPAD == COWOND2_PAD
250 #define ROCKBLOX_OFF BUTTON_POWER
251 #define ROCKBLOX_RESTART BUTTON_MENU
253 #elif CONFIG_KEYPAD == IAUDIO67_PAD
255 #define ROCKBLOX_OFF BUTTON_POWER
256 #define ROCKBLOX_ROTATE_RIGHT BUTTON_VOLDOWN
257 #define ROCKBLOX_ROTATE_LEFT BUTTON_VOLUP
258 #define ROCKBLOX_DOWN BUTTON_STOP
259 #define ROCKBLOX_LEFT BUTTON_LEFT
260 #define ROCKBLOX_RIGHT BUTTON_RIGHT
261 #define ROCKBLOX_DROP BUTTON_PLAY
262 #define ROCKBLOX_RESTART BUTTON_MENU
264 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
265 #define ROCKBLOX_OFF BUTTON_BACK
266 #define ROCKBLOX_ROTATE_RIGHT BUTTON_UP
267 #define ROCKBLOX_ROTATE_LEFT BUTTON_PLAY
268 #define ROCKBLOX_DOWN BUTTON_DOWN
269 #define ROCKBLOX_LEFT BUTTON_LEFT
270 #define ROCKBLOX_RIGHT BUTTON_RIGHT
271 #define ROCKBLOX_DROP BUTTON_SELECT
272 #define ROCKBLOX_RESTART BUTTON_CUSTOM
274 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
276 #define ROCKBLOX_OFF BUTTON_POWER
277 #define ROCKBLOX_ROTATE_RIGHT BUTTON_VOL_DOWN
278 #define ROCKBLOX_ROTATE_LEFT BUTTON_VOL_UP
279 #define ROCKBLOX_ROTATE BUTTON_UP
280 #define ROCKBLOX_DOWN BUTTON_DOWN
281 #define ROCKBLOX_LEFT BUTTON_LEFT
282 #define ROCKBLOX_RIGHT BUTTON_RIGHT
283 #define ROCKBLOX_DROP BUTTON_SELECT
284 #define ROCKBLOX_RESTART BUTTON_MENU
286 #elif CONFIG_KEYPAD == ONDAVX747_PAD
287 #define ROCKBLOX_OFF BUTTON_POWER
288 #define ROCKBLOX_RESTART BUTTON_MENU
290 #elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
292 #define ROCKBLOX_OFF (BUTTON_REC|BUTTON_PLAY)
293 #define ROCKBLOX_ROTATE_RIGHT BUTTON_UP
294 #define ROCKBLOX_ROTATE_LEFT BUTTON_DOWN
295 #define ROCKBLOX_DOWN BUTTON_REW
296 #define ROCKBLOX_LEFT BUTTON_LEFT
297 #define ROCKBLOX_RIGHT BUTTON_RIGHT
298 #define ROCKBLOX_DROP BUTTON_FFWD
299 #define ROCKBLOX_RESTART (BUTTON_REC|BUTTON_REW)
301 #else
302 #error No keymap defined!
303 #endif
305 #ifdef HAVE_TOUCHSCREEN
306 #ifndef ROCKBLOX_OFF
307 #define ROCKBLOX_OFF BUTTON_TOPLEFT
308 #endif
309 #ifndef ROCKBLOX_ROTATE_RIGHT
310 #define ROCKBLOX_ROTATE_RIGHT BUTTON_BOTTOMRIGHT
311 #endif
312 #ifndef ROCKBLOX_ROTATE_LEFT
313 #define ROCKBLOX_ROTATE_LEFT BUTTON_BOTTOMLEFT
314 #endif
315 #ifndef ROCKBLOX_DOWN
316 #define ROCKBLOX_DOWN BUTTON_BOTTOMMIDDLE
317 #endif
318 #ifndef ROCKBLOX_LEFT
319 #define ROCKBLOX_LEFT BUTTON_MIDLEFT
320 #endif
321 #ifndef ROCKBLOX_RIGHT
322 #define ROCKBLOX_RIGHT BUTTON_MIDRIGHT
323 #endif
324 #ifndef ROCKBLOX_DROP
325 #define ROCKBLOX_DROP BUTTON_CENTER
326 #endif
327 #ifndef ROCKBLOX_RESTART
328 #define ROCKBLOX_RESTART BUTTON_TOPRIGHT
329 #endif
330 #endif
332 #define BLOCKS_NUM 7
333 #define EMPTY_BLOCK 7
335 #define BOARD_WIDTH 10
337 #ifdef HAVE_LCD_BITMAP
339 #define BOARD_HEIGHT 20
341 #if (LCD_WIDTH == 640) && (LCD_HEIGHT == 480)
343 #define BLOCK_WIDTH 24
344 #define BLOCK_HEIGHT 24
345 #define BOARD_X 172
346 #define BOARD_Y 0
347 #define PREVIEW_X 24
348 #define PREVIEW_Y 22
349 #define LABEL_X 482
350 #define SCORE_Y 50
351 #define LEVEL_Y 140
352 #define LINES_Y 210
354 #elif (LCD_WIDTH == 480) && (LCD_HEIGHT == 640)
356 #define BLOCK_WIDTH 30
357 #define BLOCK_HEIGHT 30
358 #define BOARD_X 14
359 #define BOARD_Y 2
360 #define PREVIEW_X 342
361 #define PREVIEW_Y 482
362 #define LABEL_X 344
363 #define SCORE_Y 58
364 #define LEVEL_Y 142
365 #define LINES_Y 218
367 #elif (LCD_WIDTH == 320) && (LCD_HEIGHT == 240)
369 #define BLOCK_WIDTH 12
370 #define BLOCK_HEIGHT 12
371 #define BOARD_X 86
372 #define BOARD_Y 0
373 #define PREVIEW_X 12
374 #define PREVIEW_Y 11
375 #define LABEL_X 242
376 #define SCORE_Y 25
377 #define LEVEL_Y 70
378 #define LINES_Y 105
380 #elif (LCD_WIDTH == 240) && ((LCD_HEIGHT == 320) || (LCD_HEIGHT == 400))
382 #define BLOCK_WIDTH 15
383 #define BLOCK_HEIGHT 15
384 #define BOARD_X 7
385 #define BOARD_Y 1
386 #define PREVIEW_X 171
387 #define PREVIEW_Y 241
388 #define LABEL_X 172
389 #define SCORE_Y 29
390 #define LEVEL_Y 71
391 #define LINES_Y 109
392 #define HIGH_LABEL_X 172
393 #define HIGH_SCORE_Y 163
394 #define HIGH_LEVEL_Y 172
396 #elif (LCD_WIDTH == 220) && (LCD_HEIGHT == 176)
398 #define BLOCK_WIDTH 8
399 #define BLOCK_HEIGHT 8
400 #define BOARD_X 27
401 #define BOARD_Y 5
402 #define PREVIEW_X 158
403 #define PREVIEW_Y 130
404 #define LABEL_X 147
405 #define SCORE_Y 20
406 #define LEVEL_Y 65
407 #define LINES_Y 100
409 #elif (LCD_WIDTH == 176) && (LCD_HEIGHT == 132)
411 #define BLOCK_WIDTH 6
412 #define BLOCK_HEIGHT 6
413 #define BOARD_X 25
414 #define BOARD_Y 1
415 #define PREVIEW_X 126
416 #define PREVIEW_Y 102
417 #define LABEL_X 112
418 #define SCORE_Y 17
419 #define LEVEL_Y 49
420 #define LINES_Y 81
422 #elif (LCD_WIDTH == 176) && (LCD_HEIGHT == 220)
424 /* no room for the space in the highscore list */
425 #define _SPACE ""
427 #define BLOCK_WIDTH 10
428 #define BLOCK_HEIGHT 10
429 #define BOARD_X 6
430 #define BOARD_Y 10
431 #define PREVIEW_X 124
432 #define PREVIEW_Y 174
433 #define LABEL_X 117
434 #define SCORE_Y 18
435 #define LEVEL_Y 52
436 #define LINES_Y 85
437 #define HIGH_SCORE_Y 119
438 #define HIGH_LEVEL_Y 126
439 #define HIGH_LABEL_X 114
441 #elif (LCD_WIDTH == 160) && (LCD_HEIGHT == 128)
444 #define BLOCK_WIDTH 6
445 #define BLOCK_HEIGHT 6
446 #define BOARD_X 22
447 #define BOARD_Y 3
448 #define PREVIEW_X 114
449 #define PREVIEW_Y 100
450 #define LABEL_X 101
451 #define SCORE_Y 17
452 #define LEVEL_Y 49
453 #define LINES_Y 82
455 #elif (LCD_WIDTH == 138) && (LCD_HEIGHT == 110)
457 #define BLOCK_WIDTH 5
458 #define BLOCK_HEIGHT 5
459 #define BOARD_X 14
460 #define BOARD_Y 0
461 #define PREVIEW_X 98
462 #define PREVIEW_Y 88
463 #define LABEL_X 80
464 #define SCORE_Y 15
465 #define LEVEL_Y 45
466 #define LINES_Y 74
468 #elif (LCD_WIDTH == 132) && (LCD_HEIGHT == 80)
470 #define BLOCK_WIDTH 4
471 #define BLOCK_HEIGHT 4
472 #define BOARD_X 10
473 #define BOARD_Y 0
474 #define PREVIEW_X 89
475 #define PREVIEW_Y 61
476 #define LABEL_X 78
477 #define SCORE_Y 10
478 #define LEVEL_Y 30
479 #define LINES_Y 50
481 #elif (LCD_WIDTH == 128) && (LCD_HEIGHT == 128)
483 #define BLOCK_WIDTH 6
484 #define BLOCK_HEIGHT 6
485 #define BOARD_X 4
486 #define BOARD_Y 3
487 #define PREVIEW_X 84
488 #define PREVIEW_Y 100
489 #define LABEL_X 71
490 #define SCORE_Y 17
491 #define LEVEL_Y 49
492 #define LINES_Y 82
494 #elif (LCD_WIDTH == 128) && (LCD_HEIGHT == 96)
496 #define BLOCK_WIDTH 4
497 #define BLOCK_HEIGHT 4
498 #define BOARD_X 14
499 #define BOARD_Y 2
500 #define PREVIEW_X 89
501 #define PREVIEW_Y 76
502 #define LABEL_X 70
503 #define SCORE_Y 14
504 #define LEVEL_Y 39
505 #define LINES_Y 64
507 #elif (LCD_WIDTH == 128) && (LCD_HEIGHT == 64)
509 #define BLOCK_WIDTH 3
510 #define BLOCK_HEIGHT 3
511 #define BOARD_X 9
512 #define BOARD_Y 3
513 #define PREVIEW_X 53
514 #define PREVIEW_Y 5
515 #define LABEL_X 70
516 #define SCORE_Y 32
517 #define LEVEL_Y 13
518 #define LINES_Y 51
520 #elif (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
522 #define BLOCK_WIDTH 4
523 #define BLOCK_HEIGHT 3
524 #define BOARD_X 9
525 #define BOARD_Y 3
526 #define PREVIEW_X 59
527 #define PREVIEW_Y 5
528 #define LABEL_X 59
529 #define SCORE_Y 32
530 #define LEVEL_Y 13
531 #define LEVEL_X 78
532 #define LINES_Y 51
534 #endif
536 #ifndef LEVEL_X
537 #define LEVEL_X LABEL_X
538 #endif
540 #ifndef LINES_X
541 #define LINES_X LABEL_X
542 #endif
544 #define MYLCD(fn) rb->lcd_ ## fn
546 extern const fb_data rockblox_background[];
548 #else /* HAVE_LCD_CHARCELLS */
550 #define BOARD_HEIGHT 14
552 #define BLOCK_WIDTH 1
553 #define BLOCK_HEIGHT 1
554 #define BOARD_X 5
555 #define BOARD_Y 0
556 #define PREVIEW_X 15
557 #define PREVIEW_Y 1
559 #define MYLCD(fn) pgfx_ ## fn
561 #endif
563 #ifndef _SPACE
564 #define _SPACE " "
565 #endif
566 /* <<Explanation on Rockblox shapes>>
569 %% - O has 1 orientation
571 %% %
572 %% %% - Z has 2 orientations
575 %% %
576 %% %% - S has 2 orientations
580 % %%%% - I has 2 orientations
583 % %%
584 % % % %%% - L has 4 orientations
585 %% %%% % %
587 % %%
588 % % % %%% - J has 4 orientations
589 %% %%% % %
591 % % %%%
592 %% % %% % - T has 4 orientations
593 % %%% %
596 /* c=current f=figure o=orientation n=next */
597 static struct _rockblox_status
599 int gameover;
600 int lines;
601 int level;
602 int score;
603 int cx;
604 int cy;
605 int cf;
606 int co;
607 int nf;
608 short board[BOARD_HEIGHT][BOARD_WIDTH]; /* 20 rows of 10 blocks */
609 } rockblox_status;
611 /* prototypes */
612 static void draw_next_block(void);
613 static void new_block(void);
615 #ifdef HAVE_SCROLLWHEEL
616 int wheel_events = 0, last_wheel_event = 0;
617 bool wheel_enabled = false;
618 #endif
620 static const short scoring[4] = { /* scoring for each number of lines */
621 #if BOARD_HEIGHT == 20
622 40 /* single */ , 100 /* double */ , 300 /* triple */ , 1200 /* rockblox */
623 #elif BOARD_HEIGHT == 14 /* Player special values */
624 60 /* single */ , 150 /* double */ , 500 /* triple */ , 2000 /* rockblox */
625 #endif
628 struct figure
630 #if LCD_DEPTH >= 2
631 unsigned short color[3]; /* color of figure (light,middle,shadow) */
632 #endif
633 unsigned short max_or; /* max orientations */
634 signed short shapeX[4], shapeY[4]; /* implementation of figures */
637 /* array of figures */
638 figures[BLOCKS_NUM] = {
639 /* O */
641 #if LCD_DEPTH >= 16
642 {LCD_RGBPACK (153, 255, 255), LCD_RGBPACK(0, 255, 255),
643 LCD_RGBPACK(0,153,153)},
644 #elif LCD_DEPTH == 2
645 {LCD_WHITE, LCD_LIGHTGRAY, LCD_DARKGRAY},
646 #endif
648 {-1, 0, -1, 0},
649 {0, 0, 1, 1}
651 /* I */
653 #if LCD_DEPTH >= 16
654 {LCD_RGBPACK (255, 153, 128), LCD_RGBPACK (255, 0, 0),
655 LCD_RGBPACK (153, 0, 0)},
656 #elif LCD_DEPTH == 2
657 {LCD_WHITE, LCD_LIGHTGRAY, LCD_DARKGRAY},
658 #endif
660 {-2, -1, 0, 1},
661 {0, 0, 0, 0}
663 /* 'Z' */
665 #if LCD_DEPTH >= 16
666 {LCD_RGBPACK (153, 255, 153), LCD_RGBPACK (0, 255, 0),
667 LCD_RGBPACK (0, 153, 0)},
668 #elif LCD_DEPTH == 2
669 {LCD_WHITE, LCD_LIGHTGRAY, LCD_DARKGRAY},
670 #endif
672 {0, 1, -1, 0},
673 {0, 0, 1, 1}
675 /* 'S' */
677 #if LCD_DEPTH >= 16
678 {LCD_RGBPACK (153, 153, 255), LCD_RGBPACK (0, 0, 255),
679 LCD_RGBPACK (0, 0, 153)},
680 #elif LCD_DEPTH == 2
681 {LCD_WHITE, LCD_LIGHTGRAY, LCD_DARKGRAY},
682 #endif
684 {-1, 0, 0, 1},
685 {0, 0, 1, 1}
687 /* 'L' */
689 #if LCD_DEPTH >= 16
690 {LCD_RGBPACK (255, 255, 153), LCD_RGBPACK (255, 255, 0),
691 LCD_RGBPACK (153, 153, 0)},
692 #elif LCD_DEPTH == 2
693 {LCD_WHITE, LCD_LIGHTGRAY, LCD_DARKGRAY},
694 #endif
696 {-1, 0, 1, 1},
697 {0, 0, 0, 1}
699 /* 'J' */
701 #if LCD_DEPTH >= 16
702 {LCD_RGBPACK (255, 153, 255), LCD_RGBPACK (255, 0, 255),
703 LCD_RGBPACK (153, 0, 153)},
704 #elif LCD_DEPTH == 2
705 {LCD_WHITE, LCD_LIGHTGRAY, LCD_DARKGRAY},
706 #endif
708 {-1, 0, 1, -1},
709 {0, 0, 0, 1}
711 /* 'T' */
713 #if LCD_DEPTH >= 16
714 {LCD_RGBPACK (204, 204, 204), LCD_RGBPACK (153, 153, 153),
715 LCD_RGBPACK (85, 85, 85)},
716 #elif LCD_DEPTH == 2
717 {LCD_WHITE, LCD_LIGHTGRAY, LCD_DARKGRAY},
718 #endif
720 {-1, 0, 1, 0},
721 {0, 0, 0, 1}
725 /* Rockbox File System only supports full filenames inc dir */
726 #define HIGH_SCORE PLUGIN_GAMES_DIR "/rockblox.score"
727 #define RESUME_FILE PLUGIN_GAMES_DIR "/rockblox.resume"
728 #define MAX_HIGH_SCORES 5
730 /* Default High Scores... */
731 struct highscore highest[MAX_HIGH_SCORES];
733 /* get random number from (0) to (range-1) */
734 static int t_rand (int range)
736 return rb->rand () % range;
739 static inline void show_game_over (void)
741 rb->splash(HZ,"Game over!");
744 /* init the board array to have no blocks */
745 static void init_board (void)
747 int i, j;
748 for (i = 0; i < BOARD_WIDTH; i++)
749 for (j = 0; j < BOARD_HEIGHT; j++)
750 rockblox_status.board[j][i] = EMPTY_BLOCK;
753 /* show the score, level and lines */
754 static void show_details (void)
756 char str[25]; /* for strings */
758 #ifdef HAVE_LCD_BITMAP
759 #if LCD_DEPTH >= 2
760 rb->lcd_set_foreground (LCD_BLACK);
761 rb->lcd_set_background (LCD_WHITE);
762 #endif
763 rb->snprintf (str, sizeof (str), "%d", rockblox_status.score);
764 rb->lcd_putsxy (LABEL_X, SCORE_Y, str);
765 rb->snprintf (str, sizeof (str), "%d", rockblox_status.level);
766 rb->lcd_putsxy (LEVEL_X, LEVEL_Y, str);
767 rb->snprintf (str, sizeof (str), "%d", rockblox_status.lines);
768 rb->lcd_putsxy (LINES_X, LINES_Y, str);
769 #else /* HAVE_LCD_CHARCELLS */
770 rb->snprintf (str, sizeof (str), "L%d/%d", rockblox_status.level,
771 rockblox_status.lines);
772 rb->lcd_puts (5, 0, str);
773 rb->snprintf (str, sizeof (str), "S%d", rockblox_status.score);
774 rb->lcd_puts (5, 1, str);
775 #endif
778 #ifdef HIGH_SCORE_Y
779 static void show_highscores (void)
781 int i;
782 char str[25]; /* for strings */
784 for (i = 0; i<MAX_HIGH_SCORES; i++)
786 rb->snprintf (str, sizeof (str), "%06d" _SPACE "L%1d",
787 highest[i].score, highest[i].level);
788 rb->lcd_putsxy (HIGH_LABEL_X, HIGH_SCORE_Y + (10 * i), str);
791 #endif
793 /* Returns >0 on successful read AND if the game wasn't over, else 0 */
794 static int load_resume(void)
796 int fd;
797 fd = rb->open(RESUME_FILE, O_RDONLY);
798 if (fd < 0)
799 return 0;
801 if (rb->read(fd, &rockblox_status, sizeof(struct _rockblox_status))
802 < (ssize_t)sizeof(struct _rockblox_status))
804 rb->splash(HZ/2, "Loading Rockblox resume info failed");
805 return 0;
808 rb->close(fd);
810 if (rockblox_status.gameover)
811 show_game_over();
813 return !rockblox_status.gameover;
816 /* Returns >0 on success, else 0 */
817 static int dump_resume(void)
819 int fd;
821 fd = rb->open(RESUME_FILE, O_WRONLY|O_CREAT);
822 if (fd < 0)
823 goto fail;
825 if (rb->write(fd, &rockblox_status, sizeof(struct _rockblox_status))
826 <= 0)
828 rb->close(fd);
829 goto fail;
831 rb->close(fd);
832 return 1;
834 fail:
835 rb->splash(HZ/2, "Writing Rockblox resume info failed");
836 return 0;
838 static void init_rockblox (bool resume)
840 char score_name[50];
841 struct tm* tm;
843 tm = rb->get_time();
844 rb->snprintf(score_name, sizeof(score_name), "%04d%02d%02d %02d%02d%02d",
845 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
846 tm->tm_hour, tm->tm_min, tm->tm_sec);
848 highscore_update(rockblox_status.score, rockblox_status.level,
849 score_name, highest, MAX_HIGH_SCORES);
851 #ifdef HAVE_LCD_BITMAP
852 rb->lcd_bitmap (rockblox_background, 0, 0, LCD_WIDTH, LCD_HEIGHT);
853 #else /* HAVE_LCD_CHARCELLS */
854 pgfx_display (0, 0);
855 pgfx_display_block (3, 0, 3, 1);
856 pgfx_display_block (4, 0, 3, 0);
857 pgfx_clear_display();
858 pgfx_fillrect (3, 0, 2, 14);
859 pgfx_fillrect (15, 7, 2, 7);
860 pgfx_update();
861 #endif
862 if (!resume || !load_resume())
864 rockblox_status.level = 1;
865 rockblox_status.lines = 0;
866 rockblox_status.score = 0;
867 rockblox_status.nf = t_rand(BLOCKS_NUM);
868 init_board ();
869 new_block ();
871 draw_next_block();
873 show_details ();
874 #ifdef HIGH_SCORE_Y
875 show_highscores ();
876 #endif
879 static inline int level_speed(int level)
881 #if BOARD_HEIGHT == 20
882 return (5*HZ) / (level + 9);
883 #elif BOARD_HEIGHT == 14
884 return (7*HZ) / (level + 9);
885 #endif
888 static int getRelativeX (int figure, int square, int orientation)
890 switch (orientation) {
891 case 0:
892 return figures[figure].shapeX[square];
893 case 1:
894 return figures[figure].shapeY[square];
895 case 2:
896 return -figures[figure].shapeX[square];
897 case 3:
898 return -figures[figure].shapeY[square];
899 default:
900 return 0;
904 static int getRelativeY (int figure, int square, int orientation)
906 switch (orientation) {
907 case 0:
908 return figures[figure].shapeY[square];
909 case 1:
910 return -figures[figure].shapeX[square];
911 case 2:
912 return -figures[figure].shapeY[square];
913 case 3:
914 return figures[figure].shapeX[square];
915 default:
916 return 0;
920 /* redraw the while board on the screen */
921 static void refresh_board (void)
923 int i, j, x, y, block;
925 #if LCD_DEPTH >= 2
926 rb->lcd_set_foreground (LCD_BLACK);
927 #elif LCD_DEPTH == 1
928 MYLCD(set_drawmode) (DRMODE_SOLID | DRMODE_INVERSEVID);
929 #endif
931 MYLCD(fillrect) (BOARD_X, BOARD_Y, BOARD_WIDTH * BLOCK_WIDTH,
932 BOARD_HEIGHT * BLOCK_HEIGHT);
934 #if LCD_DEPTH == 1
935 MYLCD(set_drawmode) (DRMODE_SOLID);
936 #endif
938 for (i = 0; i < BOARD_WIDTH; i++)
939 for (j = 0; j < BOARD_HEIGHT; j++) {
940 block = rockblox_status.board[j][i];
941 if (block != EMPTY_BLOCK) {
942 #ifdef HAVE_LCD_BITMAP
943 #if LCD_DEPTH >= 2
944 /* middle drawing */
945 rb->lcd_set_foreground (figures[block].color[1]);
946 #endif
947 rb->lcd_fillrect (BOARD_X + i * BLOCK_WIDTH,
948 BOARD_Y + j * BLOCK_HEIGHT,
949 BLOCK_WIDTH, BLOCK_HEIGHT);
950 #if LCD_DEPTH >= 2
951 /* light drawing */
952 rb->lcd_set_foreground (figures[block].color[0]);
953 #endif
954 rb->lcd_vline (BOARD_X + i * BLOCK_WIDTH,
955 BOARD_Y + j * BLOCK_HEIGHT,
956 BOARD_Y + (j + 1) * BLOCK_HEIGHT - 2);
957 rb->lcd_hline (BOARD_X + i * BLOCK_WIDTH,
958 BOARD_X + (i + 1) * BLOCK_WIDTH - 2,
959 BOARD_Y + j * BLOCK_HEIGHT);
960 #if LCD_DEPTH >= 2
961 /* shadow drawing */
962 rb->lcd_set_foreground (figures[block].color[2]);
963 #endif
964 rb->lcd_vline (BOARD_X + (i + 1) * BLOCK_WIDTH - 1,
965 BOARD_Y + j * BLOCK_HEIGHT + 1,
966 BOARD_Y + (j + 1) * BLOCK_HEIGHT - 1);
967 rb->lcd_hline (BOARD_X + i * BLOCK_WIDTH + 1,
968 BOARD_X + (i + 1) * BLOCK_WIDTH - 1,
969 BOARD_Y + (j + 1) * BLOCK_HEIGHT - 1);
970 #else /* HAVE_LCD_CHARCELLS */
971 pgfx_drawpixel (BOARD_X + i, BOARD_Y + j);
972 #endif
976 for (i = 0; i < 4; i++) {
977 x = getRelativeX (rockblox_status.cf, i, rockblox_status.co)
978 + rockblox_status.cx;
979 y = getRelativeY (rockblox_status.cf, i, rockblox_status.co)
980 + rockblox_status.cy;
981 #ifdef HAVE_LCD_BITMAP
982 #if LCD_DEPTH >= 2
983 /* middle drawing */
984 rb->lcd_set_foreground (figures[rockblox_status.cf].color[1]);
985 #endif
986 rb->lcd_fillrect (BOARD_X + x * BLOCK_WIDTH,
987 BOARD_Y + y * BLOCK_HEIGHT,
988 BLOCK_WIDTH, BLOCK_HEIGHT);
989 #if LCD_DEPTH >= 2
990 /* light drawing */
991 rb->lcd_set_foreground (figures[rockblox_status.cf].color[0]);
992 #endif
993 rb->lcd_vline (BOARD_X + x * BLOCK_WIDTH, BOARD_Y + y * BLOCK_HEIGHT,
994 BOARD_Y + (y + 1) * BLOCK_HEIGHT - 2);
995 rb->lcd_hline (BOARD_X + x * BLOCK_WIDTH,
996 BOARD_X + (x + 1) * BLOCK_WIDTH - 2,
997 BOARD_Y + y * BLOCK_HEIGHT);
998 #if LCD_DEPTH >= 2
999 /* shadow drawing */
1000 rb->lcd_set_foreground (figures[rockblox_status.cf].color[2]);
1001 #endif
1002 rb->lcd_vline (BOARD_X + (x + 1) * BLOCK_WIDTH - 1,
1003 BOARD_Y + y * BLOCK_HEIGHT + 1,
1004 BOARD_Y + (y + 1) * BLOCK_HEIGHT - 1);
1005 rb->lcd_hline (BOARD_X + x * BLOCK_WIDTH + 1,
1006 BOARD_X + (x + 1) * BLOCK_WIDTH - 1,
1007 BOARD_Y + (y + 1) * BLOCK_HEIGHT - 1);
1008 #else /* HAVE_LCD_CHARCELLS */
1009 pgfx_drawpixel (BOARD_X + x, BOARD_Y + y);
1010 #endif
1012 MYLCD(update) ();
1015 static bool canMoveTo (int x, int y, int newOrientation)
1017 int i, rx, ry;
1018 for (i = 0; i < 4; i++) {
1019 ry = getRelativeY (rockblox_status.cf, i, newOrientation) + y;
1020 rx = getRelativeX (rockblox_status.cf, i, newOrientation) + x;
1021 if ((rx < 0 || rx >= BOARD_WIDTH) ||
1022 (ry < 0 || ry >= BOARD_HEIGHT) ||
1023 (rockblox_status.board[ry][rx] != EMPTY_BLOCK))
1024 return false;
1026 return true;
1029 /* draws the preview of next block in the preview window */
1030 static void draw_next_block (void)
1032 int i, rx, ry;
1033 /* clear preview window first */
1034 #if LCD_DEPTH >= 2
1035 rb->lcd_set_foreground (LCD_BLACK);
1036 #elif LCD_DEPTH == 1
1037 MYLCD(set_drawmode) (DRMODE_SOLID | DRMODE_INVERSEVID);
1038 #endif
1040 /* 4x4 */
1041 MYLCD(fillrect) (PREVIEW_X, PREVIEW_Y, BLOCK_WIDTH * 4, BLOCK_HEIGHT * 4);
1043 #if LCD_DEPTH == 1
1044 MYLCD(set_drawmode) (DRMODE_SOLID);
1045 #endif
1047 /* draw the lightgray rectangles */
1048 #if LCD_DEPTH >= 16
1049 rb->lcd_set_foreground (LCD_RGBPACK (40, 40, 40));
1050 #elif LCD_DEPTH == 2
1051 rb->lcd_set_foreground (LCD_DARKGRAY);
1052 #endif
1054 #if LCD_DEPTH >= 2
1055 for (rx = 0; rx < 4; rx++)
1056 for (ry = 0; ry < 4; ry++)
1057 rb->lcd_drawrect (PREVIEW_X + rx * BLOCK_WIDTH,
1058 PREVIEW_Y + ry * BLOCK_HEIGHT, BLOCK_WIDTH,
1059 BLOCK_HEIGHT);
1060 #endif
1062 /* draw the figure */
1063 for (i = 0; i < 4; i++) {
1064 rx = getRelativeX (rockblox_status.nf, i, 0) + 2;
1065 ry = getRelativeY (rockblox_status.nf, i, 0) + 2;
1066 #ifdef HAVE_LCD_BITMAP
1067 #if LCD_DEPTH >= 2
1068 rb->lcd_set_foreground (figures[rockblox_status.nf].color[1]); /* middle drawing */
1069 #endif
1070 rb->lcd_fillrect (PREVIEW_X + rx * BLOCK_WIDTH,
1071 PREVIEW_Y + ry * BLOCK_HEIGHT,
1072 BLOCK_WIDTH, BLOCK_HEIGHT);
1073 #if LCD_DEPTH >= 2
1074 rb->lcd_set_foreground (figures[rockblox_status.nf].color[0]); /* light drawing */
1075 #endif
1076 rb->lcd_vline (PREVIEW_X + rx * BLOCK_WIDTH,
1077 PREVIEW_Y + ry * BLOCK_HEIGHT,
1078 PREVIEW_Y + (ry + 1) * BLOCK_HEIGHT - 2);
1079 rb->lcd_hline (PREVIEW_X + rx * BLOCK_WIDTH,
1080 PREVIEW_X + (rx + 1) * BLOCK_WIDTH - 2,
1081 PREVIEW_Y + ry * BLOCK_HEIGHT);
1082 #if LCD_DEPTH >= 2
1083 rb->lcd_set_foreground (figures[rockblox_status.nf].color[2]); /* shadow drawing */
1084 #endif
1085 rb->lcd_vline (PREVIEW_X + (rx + 1) * BLOCK_WIDTH - 1,
1086 PREVIEW_Y + ry * BLOCK_HEIGHT + 1,
1087 PREVIEW_Y + (ry + 1) * BLOCK_HEIGHT - 1);
1088 rb->lcd_hline (PREVIEW_X + rx * BLOCK_WIDTH + 1,
1089 PREVIEW_X + (rx + 1) * BLOCK_WIDTH - 1,
1090 PREVIEW_Y + (ry + 1) * BLOCK_HEIGHT - 1);
1091 #else /* HAVE_LCD_CHARCELLS */
1092 pgfx_drawpixel (PREVIEW_X + rx, PREVIEW_Y + ry);
1093 #endif
1098 /* move the block to a relative location */
1099 static void move_block (int x, int y, int o)
1101 if (canMoveTo (rockblox_status.cx + x, rockblox_status.cy + y, o)) {
1102 rockblox_status.cy += y;
1103 rockblox_status.cx += x;
1104 rockblox_status.co = o;
1108 /* try to add a new block to play with (return true if gameover) */
1109 static void new_block (void)
1111 rockblox_status.cy = 1;
1112 rockblox_status.cx = 5;
1113 rockblox_status.cf = rockblox_status.nf;
1114 rockblox_status.co = 0; /* start at the same orientation all time */
1115 rockblox_status.nf = t_rand (BLOCKS_NUM);
1116 rockblox_status.gameover = !canMoveTo (rockblox_status.cx,
1117 rockblox_status.cy, rockblox_status.co);
1119 draw_next_block ();
1123 /* check for filled rockblox_status.lines and do what necessary */
1124 static int check_lines (void)
1127 int i, j, y;
1128 int rockblox = 0;
1130 for (j = 0; j < BOARD_HEIGHT; j++) {
1131 for (i = 0; ((i < BOARD_WIDTH) &&
1132 (rockblox_status.board[j][i] != EMPTY_BLOCK)); i++);
1133 if (i == BOARD_WIDTH) { /* woo hoo, we have a line */
1134 rockblox++;
1135 for (y = j; y > 0; y--)
1137 for (i = 0; i < BOARD_WIDTH; i++)
1138 { /* fall line */
1139 rockblox_status.board[y][i] = rockblox_status.board[y - 1][i];
1145 return rockblox;
1148 /* moves down the figure and returns true if gameover */
1149 static void move_down (void)
1151 int l, i, rx, ry;
1153 if (!canMoveTo (rockblox_status.cx, rockblox_status.cy + 1, rockblox_status.co)) {
1154 /* save figure to board */
1155 for (i = 0; i < 4; i++) {
1156 rx = getRelativeX (rockblox_status.cf, i, rockblox_status.co) + rockblox_status.cx;
1157 ry = getRelativeY (rockblox_status.cf, i, rockblox_status.co) + rockblox_status.cy;
1158 rockblox_status.board[ry][rx] = rockblox_status.cf;
1160 /* check if formed some lines */
1161 l = check_lines ();
1162 if (l) {
1163 /* the original scoring from "http://en.wikipedia.org/wiki/Rockblox" */
1164 rockblox_status.score += scoring[l - 1] * rockblox_status.level;
1165 rockblox_status.lines += l;
1166 rockblox_status.level = (int) rockblox_status.lines / 10 + 1;
1169 /* show details */
1170 show_details ();
1172 /* generate a new figure */
1173 new_block ();
1174 } else
1175 move_block (0, 1, rockblox_status.co);
1178 static int rockblox_loop (void)
1180 int button;
1181 int lastbutton = BUTTON_NONE;
1182 long next_down_tick = *rb->current_tick + level_speed(rockblox_status.level);
1184 while (1) {
1185 #ifdef HAS_BUTTON_HOLD
1186 if (rb->button_hold ()) {
1187 /* Turn on backlight timeout (revert to settings) */
1188 backlight_use_settings(); /* backlight control in lib/helper.c */
1189 rb->splash(0, "Paused");
1190 while (rb->button_hold ())
1191 rb->sleep(HZ/10);
1193 /* Turn off backlight timeout */
1194 backlight_force_on(); /* backlight control in lib/helper.c */
1196 /* get rid of the splash text */
1197 rb->lcd_bitmap (rockblox_background, 0, 0, LCD_WIDTH, LCD_HEIGHT);
1198 show_details ();
1199 #ifdef HIGH_SCORE_Y
1200 show_highscores ();
1201 #endif
1202 draw_next_block ();
1203 refresh_board ();
1205 #endif
1207 button = rb->button_get_w_tmo (MAX(next_down_tick - *rb->current_tick, 1));
1208 switch (button) {
1209 #ifdef ROCKBLOX_RC_OFF
1210 case ROCKBLOX_RC_OFF:
1211 #endif
1212 case ROCKBLOX_OFF:
1213 #ifdef ROCKBLOX_OFF_PRE
1214 if (lastbutton != ROCKBLOX_OFF_PRE)
1215 break;
1216 #endif
1217 return PLUGIN_OK;
1219 #if defined(ROCKBLOX_ROTATE)
1220 case ROCKBLOX_ROTATE:
1221 #endif
1222 case ROCKBLOX_ROTATE_RIGHT:
1223 case ROCKBLOX_ROTATE_RIGHT | BUTTON_REPEAT:
1224 #ifdef HAVE_SCROLLWHEEL
1225 /* if the wheel is disabled, add an event to the stack. */
1226 if(wheel_enabled == false)
1227 wheel_events++;
1229 /* if it's enabled, go ahead and rotate.. */
1230 if(wheel_enabled)
1231 #endif
1232 move_block (0, 0, (rockblox_status.co + 1) % figures[rockblox_status.cf].max_or);
1233 break;
1235 case ROCKBLOX_ROTATE_LEFT:
1236 case ROCKBLOX_ROTATE_LEFT | BUTTON_REPEAT:
1237 #ifdef HAVE_SCROLLWHEEL
1238 if(wheel_enabled == false)
1239 wheel_events++;
1241 if(wheel_enabled)
1242 #endif
1243 move_block (0, 0,
1244 (rockblox_status.co + figures[rockblox_status.cf].max_or -
1245 1) % figures[rockblox_status.cf].max_or);
1246 break;
1248 #ifdef ROCKBLOX_ROTATE_RIGHT2
1249 case ROCKBLOX_ROTATE_RIGHT2:
1250 move_block (0, 0, (rockblox_status.co + 1) % figures[rockblox_status.cf].max_or);
1251 break;
1252 #endif
1254 case ROCKBLOX_DOWN:
1255 case ROCKBLOX_DOWN | BUTTON_REPEAT:
1256 move_block (0, 1, rockblox_status.co);
1257 break;
1259 case ROCKBLOX_RIGHT:
1260 case ROCKBLOX_RIGHT | BUTTON_REPEAT:
1261 move_block (1, 0, rockblox_status.co);
1262 break;
1264 case ROCKBLOX_LEFT:
1265 case ROCKBLOX_LEFT | BUTTON_REPEAT:
1266 move_block (-1, 0, rockblox_status.co);
1267 break;
1269 case ROCKBLOX_DROP:
1270 #ifdef ROCKBLOX_DROP_PRE
1271 if (lastbutton != ROCKBLOX_DROP_PRE)
1272 break;
1273 #endif
1274 while (canMoveTo (rockblox_status.cx, rockblox_status.cy + 1, rockblox_status.co))
1275 move_block (0, 1, rockblox_status.co);
1276 break;
1277 #ifdef ROCKBLOX_RESTART
1278 case ROCKBLOX_RESTART:
1279 rb->splash (HZ * 1, "Restarting...");
1280 init_rockblox (false);
1281 break;
1282 #endif
1284 default:
1285 if (rb->default_event_handler (button) == SYS_USB_CONNECTED)
1286 return PLUGIN_USB_CONNECTED;
1287 break;
1289 if (button != BUTTON_NONE)
1290 lastbutton = button;
1292 #ifdef HAVE_SCROLLWHEEL
1293 /* check if we should enable the scroll wheel, if events
1294 * begin to stack up... */
1295 if(wheel_enabled == false)
1297 /* stopped rotating the wheel, reset the count */
1298 if(wheel_events == last_wheel_event)
1300 last_wheel_event = 0;
1301 wheel_events = 0;
1303 /* rotated the wheel a while constantly, enable it. */
1304 else if(wheel_events > 3)
1306 wheel_enabled = true;
1309 /* this evens out the last event and the "current" event.
1310 * if we get an event next time through button reading, it will
1311 * remain ahead of last_event. if we don't, they'll end up equaling
1312 * each other.. thus, the scroll count will be reset. */
1313 if(wheel_enabled == false && wheel_events > last_wheel_event)
1314 last_wheel_event++;
1316 #endif
1318 if (TIME_AFTER(*rb->current_tick, next_down_tick)) {
1319 move_down ();
1320 next_down_tick += level_speed(rockblox_status.level);
1321 if (TIME_AFTER(*rb->current_tick, next_down_tick))
1322 /* restart time "raster" when we had to wait longer than usual
1323 * (pause, game restart etc) */
1324 next_down_tick = *rb->current_tick + level_speed(rockblox_status.level);
1327 if (rockblox_status.gameover) {
1328 #if LCD_DEPTH >= 2
1329 rb->lcd_set_foreground (LCD_BLACK);
1330 #endif
1331 show_game_over();
1332 init_rockblox (false);
1335 refresh_board ();
1338 return PLUGIN_OK;
1341 enum plugin_status plugin_start (const void *parameter)
1343 int ret;
1345 (void) parameter;
1347 rb->srand (*rb->current_tick);
1349 /* Load HighScore if any */
1350 highscore_load(HIGH_SCORE, highest, MAX_HIGH_SCORES);
1352 #if LCD_DEPTH > 1
1353 rb->lcd_set_backdrop(NULL);
1354 #endif
1356 #ifdef HAVE_LCD_BITMAP
1357 rb->lcd_setfont (FONT_SYSFIXED);
1358 #else
1359 if (!pgfx_init(4, 2))
1361 rb->splash(HZ*2, "Old LCD :(");
1362 return PLUGIN_OK;
1364 #endif
1365 /* Turn off backlight timeout */
1366 backlight_force_on(); /* backlight control in lib/helper.c */
1368 init_rockblox (true);
1369 ret = rockblox_loop ();
1371 #ifndef HAVE_LCD_BITMAP
1372 pgfx_release();
1373 #endif
1374 /* Save user's HighScore */
1375 highscore_save(HIGH_SCORE, highest, MAX_HIGH_SCORES);
1376 backlight_use_settings(); /* backlight control in lib/helper.c */
1378 dump_resume();
1380 return ret;