1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
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"
32 #if (CONFIG_KEYPAD == IPOD_4G_PAD) || \
33 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
34 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
36 #define ROCKBLOX_OFF (BUTTON_MENU | BUTTON_SELECT)
37 #define ROCKBLOX_ROTATE_RIGHT BUTTON_SCROLL_BACK
38 #define ROCKBLOX_ROTATE_RIGHT2 (BUTTON_MENU | BUTTON_REL)
39 #define ROCKBLOX_ROTATE_LEFT BUTTON_SCROLL_FWD
40 #define ROCKBLOX_LEFT BUTTON_LEFT
41 #define ROCKBLOX_RIGHT BUTTON_RIGHT
42 #define ROCKBLOX_DOWN BUTTON_PLAY
43 #define ROCKBLOX_RESTART (BUTTON_SELECT | BUTTON_PLAY)
44 #define ROCKBLOX_DROP (BUTTON_SELECT | BUTTON_REL)
46 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
47 (CONFIG_KEYPAD == IRIVER_H300_PAD)
49 #define ROCKBLOX_OFF BUTTON_OFF
50 #define ROCKBLOX_ROTATE_RIGHT BUTTON_UP
51 #define ROCKBLOX_ROTATE_LEFT BUTTON_SELECT
52 #define ROCKBLOX_DOWN BUTTON_DOWN
53 #define ROCKBLOX_LEFT BUTTON_LEFT
54 #define ROCKBLOX_RIGHT BUTTON_RIGHT
55 #define ROCKBLOX_DROP BUTTON_MODE
56 #define ROCKBLOX_RESTART BUTTON_ON
58 #define ROCKBLOX_RC_OFF BUTTON_RC_STOP
60 #elif CONFIG_KEYPAD == RECORDER_PAD
62 #define ROCKBLOX_OFF BUTTON_OFF
63 #define ROCKBLOX_ROTATE_RIGHT BUTTON_UP
64 #define ROCKBLOX_ROTATE_LEFT BUTTON_PLAY
65 #define ROCKBLOX_DOWN BUTTON_DOWN
66 #define ROCKBLOX_LEFT BUTTON_LEFT
67 #define ROCKBLOX_RIGHT BUTTON_RIGHT
68 #define ROCKBLOX_DROP BUTTON_ON
69 #define ROCKBLOX_RESTART BUTTON_F1
71 #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
73 #define ROCKBLOX_OFF BUTTON_OFF
74 #define ROCKBLOX_ROTATE_RIGHT BUTTON_UP
75 #define ROCKBLOX_ROTATE_LEFT BUTTON_SELECT
76 #define ROCKBLOX_DOWN BUTTON_DOWN
77 #define ROCKBLOX_LEFT BUTTON_LEFT
78 #define ROCKBLOX_RIGHT BUTTON_RIGHT
79 #define ROCKBLOX_DROP BUTTON_ON
80 #define ROCKBLOX_RESTART BUTTON_F1
82 #elif CONFIG_KEYPAD == PLAYER_PAD
84 #define ROCKBLOX_OFF_PRE BUTTON_STOP
85 #define ROCKBLOX_OFF (BUTTON_STOP|BUTTON_REL)
86 #define ROCKBLOX_ROTATE_RIGHT BUTTON_PLAY
87 #define ROCKBLOX_ROTATE_LEFT (BUTTON_ON|BUTTON_PLAY)
88 #define ROCKBLOX_DOWN BUTTON_MENU
89 #define ROCKBLOX_LEFT BUTTON_LEFT
90 #define ROCKBLOX_RIGHT BUTTON_RIGHT
91 #define ROCKBLOX_DROP_PRE BUTTON_ON
92 #define ROCKBLOX_DROP (BUTTON_ON|BUTTON_REL)
93 #define ROCKBLOX_RESTART (BUTTON_STOP|BUTTON_MENU)
95 #elif CONFIG_KEYPAD == ONDIO_PAD
97 #define ROCKBLOX_OFF_PRE BUTTON_OFF
98 #define ROCKBLOX_OFF (BUTTON_OFF|BUTTON_REL)
99 #define ROCKBLOX_ROTATE_RIGHT BUTTON_UP
100 #define ROCKBLOX_ROTATE_LEFT (BUTTON_MENU|BUTTON_UP)
101 #define ROCKBLOX_DOWN BUTTON_DOWN
102 #define ROCKBLOX_LEFT BUTTON_LEFT
103 #define ROCKBLOX_RIGHT BUTTON_RIGHT
104 #define ROCKBLOX_DROP_PRE BUTTON_MENU
105 #define ROCKBLOX_DROP (BUTTON_MENU|BUTTON_REL)
106 #define ROCKBLOX_RESTART (BUTTON_OFF|BUTTON_MENU)
108 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
110 #define ROCKBLOX_OFF BUTTON_POWER
111 #define ROCKBLOX_ROTATE_RIGHT BUTTON_UP
112 #define ROCKBLOX_ROTATE_LEFT BUTTON_SELECT
113 #define ROCKBLOX_DOWN BUTTON_DOWN
114 #define ROCKBLOX_LEFT BUTTON_LEFT
115 #define ROCKBLOX_RIGHT BUTTON_RIGHT
116 #define ROCKBLOX_DROP BUTTON_REC
117 #define ROCKBLOX_RESTART BUTTON_PLAY
119 #elif CONFIG_KEYPAD == SANSA_E200_PAD
121 #define ROCKBLOX_OFF BUTTON_POWER
122 #define ROCKBLOX_ROTATE_RIGHT BUTTON_SCROLL_BACK
123 #define ROCKBLOX_ROTATE_RIGHT2 BUTTON_UP
124 #define ROCKBLOX_ROTATE_LEFT BUTTON_SCROLL_FWD
125 #define ROCKBLOX_DOWN BUTTON_DOWN
126 #define ROCKBLOX_LEFT BUTTON_LEFT
127 #define ROCKBLOX_RIGHT BUTTON_RIGHT
128 #define ROCKBLOX_DROP BUTTON_SELECT
129 #define ROCKBLOX_RESTART BUTTON_REC
131 #elif CONFIG_KEYPAD == SANSA_FUZE_PAD
133 #define ROCKBLOX_OFF (BUTTON_HOME|BUTTON_REPEAT)
134 #define ROCKBLOX_ROTATE_RIGHT BUTTON_SCROLL_BACK
135 #define ROCKBLOX_ROTATE_RIGHT2 BUTTON_UP
136 #define ROCKBLOX_ROTATE_LEFT BUTTON_SCROLL_FWD
137 #define ROCKBLOX_DOWN BUTTON_DOWN
138 #define ROCKBLOX_LEFT BUTTON_LEFT
139 #define ROCKBLOX_RIGHT BUTTON_RIGHT
140 #define ROCKBLOX_DROP (BUTTON_SELECT | BUTTON_REL)
141 #define ROCKBLOX_RESTART (BUTTON_SELECT | BUTTON_UP)
144 #elif CONFIG_KEYPAD == SANSA_C200_PAD
146 #define ROCKBLOX_OFF BUTTON_POWER
147 #define ROCKBLOX_ROTATE_RIGHT BUTTON_UP
148 #define ROCKBLOX_ROTATE_RIGHT2 BUTTON_VOL_DOWN
149 #define ROCKBLOX_ROTATE_LEFT BUTTON_VOL_UP
150 #define ROCKBLOX_DOWN BUTTON_DOWN
151 #define ROCKBLOX_LEFT BUTTON_LEFT
152 #define ROCKBLOX_RIGHT BUTTON_RIGHT
153 #define ROCKBLOX_DROP BUTTON_SELECT
154 #define ROCKBLOX_RESTART BUTTON_REC
156 #elif CONFIG_KEYPAD == SANSA_CLIP_PAD
158 #define ROCKBLOX_OFF BUTTON_POWER
159 #define ROCKBLOX_ROTATE_RIGHT BUTTON_UP
160 #define ROCKBLOX_ROTATE_RIGHT2 BUTTON_VOL_DOWN
161 #define ROCKBLOX_ROTATE_LEFT BUTTON_VOL_UP
162 #define ROCKBLOX_DOWN BUTTON_DOWN
163 #define ROCKBLOX_LEFT BUTTON_LEFT
164 #define ROCKBLOX_RIGHT BUTTON_RIGHT
165 #define ROCKBLOX_DROP BUTTON_SELECT
166 #define ROCKBLOX_RESTART BUTTON_HOME
168 #elif CONFIG_KEYPAD == SANSA_M200_PAD
170 #define ROCKBLOX_OFF BUTTON_POWER
171 #define ROCKBLOX_ROTATE_RIGHT BUTTON_UP
172 #define ROCKBLOX_ROTATE_RIGHT2 BUTTON_VOL_DOWN
173 #define ROCKBLOX_ROTATE_LEFT BUTTON_VOL_UP
174 #define ROCKBLOX_DOWN BUTTON_DOWN
175 #define ROCKBLOX_LEFT BUTTON_LEFT
176 #define ROCKBLOX_RIGHT BUTTON_RIGHT
177 #define ROCKBLOX_RESTART (BUTTON_SELECT | BUTTON_UP)
178 #define ROCKBLOX_DROP (BUTTON_SELECT | BUTTON_REL)
180 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
182 #define ROCKBLOX_OFF BUTTON_POWER
183 #define ROCKBLOX_ROTATE_RIGHT BUTTON_SCROLL_UP
184 #define ROCKBLOX_ROTATE_LEFT BUTTON_REW
185 #define ROCKBLOX_DOWN BUTTON_SCROLL_DOWN
186 #define ROCKBLOX_LEFT BUTTON_LEFT
187 #define ROCKBLOX_RIGHT BUTTON_RIGHT
188 #define ROCKBLOX_DROP BUTTON_FF
189 #define ROCKBLOX_RESTART BUTTON_PLAY
191 #elif CONFIG_KEYPAD == GIGABEAT_PAD
193 #define ROCKBLOX_OFF BUTTON_POWER
194 #define ROCKBLOX_ROTATE_RIGHT BUTTON_VOL_DOWN
195 #define ROCKBLOX_ROTATE_LEFT BUTTON_VOL_UP
196 #define ROCKBLOX_ROTATE BUTTON_UP
197 #define ROCKBLOX_DOWN BUTTON_DOWN
198 #define ROCKBLOX_LEFT BUTTON_LEFT
199 #define ROCKBLOX_RIGHT BUTTON_RIGHT
200 #define ROCKBLOX_DROP BUTTON_SELECT
201 #define ROCKBLOX_RESTART BUTTON_A
203 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
205 #define ROCKBLOX_OFF BUTTON_PLAY
206 #define ROCKBLOX_ROTATE_RIGHT BUTTON_UP
207 #define ROCKBLOX_ROTATE_LEFT BUTTON_SELECT
208 #define ROCKBLOX_DOWN BUTTON_DOWN
209 #define ROCKBLOX_LEFT BUTTON_LEFT
210 #define ROCKBLOX_RIGHT BUTTON_RIGHT
211 #define ROCKBLOX_DROP BUTTON_MODE
212 #define ROCKBLOX_RESTART BUTTON_EQ
214 #elif CONFIG_KEYPAD == MROBE500_PAD
215 #define ROCKBLOX_OFF BUTTON_POWER
217 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
218 #define ROCKBLOX_OFF BUTTON_BACK
219 #define ROCKBLOX_ROTATE_RIGHT BUTTON_VOL_DOWN
220 #define ROCKBLOX_ROTATE_LEFT BUTTON_VOL_UP
221 #define ROCKBLOX_ROTATE BUTTON_UP
222 #define ROCKBLOX_DOWN BUTTON_DOWN
223 #define ROCKBLOX_LEFT BUTTON_LEFT
224 #define ROCKBLOX_RIGHT BUTTON_RIGHT
225 #define ROCKBLOX_DROP BUTTON_SELECT
226 #define ROCKBLOX_RESTART BUTTON_PLAY
228 #elif CONFIG_KEYPAD == MROBE100_PAD
230 #define ROCKBLOX_OFF BUTTON_POWER
231 #define ROCKBLOX_ROTATE_RIGHT BUTTON_MENU
232 #define ROCKBLOX_ROTATE_LEFT BUTTON_PLAY
233 #define ROCKBLOX_ROTATE BUTTON_UP
234 #define ROCKBLOX_DOWN BUTTON_DOWN
235 #define ROCKBLOX_LEFT BUTTON_LEFT
236 #define ROCKBLOX_RIGHT BUTTON_RIGHT
237 #define ROCKBLOX_DROP BUTTON_SELECT
238 #define ROCKBLOX_RESTART BUTTON_DISPLAY
240 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
242 #define ROCKBLOX_OFF BUTTON_RC_REC
243 #define ROCKBLOX_ROTATE_RIGHT BUTTON_RC_VOL_DOWN
244 #define ROCKBLOX_ROTATE_LEFT BUTTON_RC_VOL_UP
245 #define ROCKBLOX_DOWN BUTTON_RC_MENU
246 #define ROCKBLOX_LEFT BUTTON_RC_REW
247 #define ROCKBLOX_RIGHT BUTTON_RC_FF
248 #define ROCKBLOX_DROP BUTTON_RC_PLAY
249 #define ROCKBLOX_RESTART BUTTON_RC_MODE
251 #elif CONFIG_KEYPAD == COWON_D2_PAD
252 #define ROCKBLOX_OFF BUTTON_POWER
253 #define ROCKBLOX_RESTART BUTTON_MENU
255 #elif CONFIG_KEYPAD == IAUDIO67_PAD
257 #define ROCKBLOX_OFF BUTTON_POWER
258 #define ROCKBLOX_ROTATE_RIGHT BUTTON_VOLDOWN
259 #define ROCKBLOX_ROTATE_LEFT BUTTON_VOLUP
260 #define ROCKBLOX_DOWN BUTTON_STOP
261 #define ROCKBLOX_LEFT BUTTON_LEFT
262 #define ROCKBLOX_RIGHT BUTTON_RIGHT
263 #define ROCKBLOX_DROP BUTTON_PLAY
264 #define ROCKBLOX_RESTART BUTTON_MENU
266 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
267 #define ROCKBLOX_OFF BUTTON_BACK
268 #define ROCKBLOX_ROTATE_RIGHT BUTTON_UP
269 #define ROCKBLOX_ROTATE_LEFT BUTTON_PLAY
270 #define ROCKBLOX_DOWN BUTTON_DOWN
271 #define ROCKBLOX_LEFT BUTTON_LEFT
272 #define ROCKBLOX_RIGHT BUTTON_RIGHT
273 #define ROCKBLOX_DROP BUTTON_SELECT
274 #define ROCKBLOX_RESTART BUTTON_CUSTOM
276 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
278 #define ROCKBLOX_OFF BUTTON_POWER
279 #define ROCKBLOX_ROTATE_RIGHT BUTTON_VOL_DOWN
280 #define ROCKBLOX_ROTATE_LEFT BUTTON_VOL_UP
281 #define ROCKBLOX_ROTATE BUTTON_UP
282 #define ROCKBLOX_DOWN BUTTON_DOWN
283 #define ROCKBLOX_LEFT BUTTON_LEFT
284 #define ROCKBLOX_RIGHT BUTTON_RIGHT
285 #define ROCKBLOX_DROP BUTTON_SELECT
286 #define ROCKBLOX_RESTART BUTTON_MENU
288 # elif CONFIG_KEYPAD == PHILIPS_SA9200_PAD
290 #define ROCKBLOX_OFF BUTTON_POWER
291 #define ROCKBLOX_ROTATE_RIGHT BUTTON_VOL_DOWN
292 #define ROCKBLOX_ROTATE_LEFT BUTTON_VOL_UP
293 #define ROCKBLOX_ROTATE BUTTON_UP
294 #define ROCKBLOX_DOWN BUTTON_DOWN
295 #define ROCKBLOX_LEFT BUTTON_PREV
296 #define ROCKBLOX_RIGHT BUTTON_NEXT
297 #define ROCKBLOX_DROP BUTTON_PLAY
298 #define ROCKBLOX_RESTART BUTTON_MENU
300 #elif CONFIG_KEYPAD == ONDAVX747_PAD
301 #define ROCKBLOX_OFF BUTTON_POWER
302 #define ROCKBLOX_RESTART BUTTON_MENU
303 #elif CONFIG_KEYPAD == ONDAVX777_PAD
304 #define ROCKBLOX_OFF BUTTON_POWER
306 #elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
308 #define ROCKBLOX_OFF (BUTTON_REC|BUTTON_PLAY)
309 #define ROCKBLOX_ROTATE_RIGHT BUTTON_UP
310 #define ROCKBLOX_ROTATE_LEFT BUTTON_DOWN
311 #define ROCKBLOX_DOWN BUTTON_REW
312 #define ROCKBLOX_LEFT BUTTON_LEFT
313 #define ROCKBLOX_RIGHT BUTTON_RIGHT
314 #define ROCKBLOX_DROP BUTTON_FFWD
315 #define ROCKBLOX_RESTART (BUTTON_REC|BUTTON_REW)
318 #error No keymap defined!
321 #ifdef HAVE_TOUCHSCREEN
323 #define ROCKBLOX_OFF BUTTON_TOPLEFT
325 #ifndef ROCKBLOX_ROTATE_RIGHT
326 #define ROCKBLOX_ROTATE_RIGHT BUTTON_BOTTOMRIGHT
328 #ifndef ROCKBLOX_ROTATE_LEFT
329 #define ROCKBLOX_ROTATE_LEFT BUTTON_BOTTOMLEFT
331 #ifndef ROCKBLOX_DOWN
332 #define ROCKBLOX_DOWN BUTTON_BOTTOMMIDDLE
334 #ifndef ROCKBLOX_LEFT
335 #define ROCKBLOX_LEFT BUTTON_MIDLEFT
337 #ifndef ROCKBLOX_RIGHT
338 #define ROCKBLOX_RIGHT BUTTON_MIDRIGHT
340 #ifndef ROCKBLOX_DROP
341 #define ROCKBLOX_DROP BUTTON_CENTER
343 #ifndef ROCKBLOX_RESTART
344 #define ROCKBLOX_RESTART BUTTON_TOPRIGHT
349 #define EMPTY_BLOCK 7
351 #define BOARD_WIDTH 10
353 #ifdef HAVE_LCD_BITMAP
355 #define BOARD_HEIGHT 20
357 #if (LCD_WIDTH == 640) && (LCD_HEIGHT == 480)
359 #define BLOCK_WIDTH 24
360 #define BLOCK_HEIGHT 24
370 #elif (LCD_WIDTH == 480) && (LCD_HEIGHT == 640)
372 #define BLOCK_WIDTH 30
373 #define BLOCK_HEIGHT 30
376 #define PREVIEW_X 342
377 #define PREVIEW_Y 482
383 #elif (LCD_WIDTH == 320) && (LCD_HEIGHT == 240)
385 #define BLOCK_WIDTH 12
386 #define BLOCK_HEIGHT 12
396 #elif (LCD_WIDTH == 240) && ((LCD_HEIGHT == 320) || (LCD_HEIGHT == 400))
398 #define BLOCK_WIDTH 15
399 #define BLOCK_HEIGHT 15
402 #define PREVIEW_X 171
403 #define PREVIEW_Y 241
408 #define HIGH_LABEL_X 172
409 #define HIGH_SCORE_Y 163
410 #define HIGH_LEVEL_Y 172
412 #elif (LCD_WIDTH == 220) && (LCD_HEIGHT == 176)
414 #define BLOCK_WIDTH 8
415 #define BLOCK_HEIGHT 8
418 #define PREVIEW_X 158
419 #define PREVIEW_Y 130
425 #elif (LCD_WIDTH == 176) && (LCD_HEIGHT == 132)
427 #define BLOCK_WIDTH 6
428 #define BLOCK_HEIGHT 6
431 #define PREVIEW_X 126
432 #define PREVIEW_Y 102
438 #elif (LCD_WIDTH == 176) && (LCD_HEIGHT == 220)
440 /* no room for the space in the highscore list */
443 #define BLOCK_WIDTH 10
444 #define BLOCK_HEIGHT 10
447 #define PREVIEW_X 124
448 #define PREVIEW_Y 174
453 #define HIGH_SCORE_Y 119
454 #define HIGH_LEVEL_Y 126
455 #define HIGH_LABEL_X 114
457 #elif (LCD_WIDTH == 160) && (LCD_HEIGHT == 128)
460 #define BLOCK_WIDTH 6
461 #define BLOCK_HEIGHT 6
464 #define PREVIEW_X 114
465 #define PREVIEW_Y 100
471 #elif (LCD_WIDTH == 138) && (LCD_HEIGHT == 110)
473 #define BLOCK_WIDTH 5
474 #define BLOCK_HEIGHT 5
484 #elif (LCD_WIDTH == 132) && (LCD_HEIGHT == 80)
486 #define BLOCK_WIDTH 4
487 #define BLOCK_HEIGHT 4
497 #elif (LCD_WIDTH == 128) && (LCD_HEIGHT == 128)
499 #define BLOCK_WIDTH 6
500 #define BLOCK_HEIGHT 6
504 #define PREVIEW_Y 100
510 /* NOTE: This is for the GoGear SA9200 and is only
511 temporary until I can get better coordinates! */
512 #elif (LCD_WIDTH == 128) && (LCD_HEIGHT == 160)
514 #define BLOCK_WIDTH 6
515 #define BLOCK_HEIGHT 6
519 #define PREVIEW_Y 100
525 #elif (LCD_WIDTH == 128) && (LCD_HEIGHT == 96)
527 #define BLOCK_WIDTH 4
528 #define BLOCK_HEIGHT 4
538 #elif (LCD_WIDTH == 128) && (LCD_HEIGHT == 64)
540 #define BLOCK_WIDTH 3
541 #define BLOCK_HEIGHT 3
551 #elif (LCD_WIDTH == 112) && (LCD_HEIGHT == 64)
553 #define BLOCK_WIDTH 4
554 #define BLOCK_HEIGHT 3
568 #define LEVEL_X LABEL_X
572 #define LINES_X LABEL_X
575 #define MYLCD(fn) rb->lcd_ ## fn
577 extern const fb_data rockblox_background
[];
579 #else /* HAVE_LCD_CHARCELLS */
581 #define BOARD_HEIGHT 14
583 #define BLOCK_WIDTH 1
584 #define BLOCK_HEIGHT 1
590 #define MYLCD(fn) pgfx_ ## fn
597 /* <<Explanation on Rockblox shapes>>
600 %% - O has 1 orientation
603 %% %% - Z has 2 orientations
607 %% %% - S has 2 orientations
611 % %%%% - I has 2 orientations
615 % % % %%% - L has 4 orientations
619 % % % %%% - J has 4 orientations
623 %% % %% % - T has 4 orientations
627 /* c=current f=figure o=orientation n=next */
628 static struct _rockblox_status
639 short board
[BOARD_HEIGHT
][BOARD_WIDTH
]; /* 20 rows of 10 blocks */
643 static void draw_next_block(void);
644 static void new_block(void);
646 #ifdef HAVE_SCROLLWHEEL
647 int wheel_events
= 0, last_wheel_event
= 0;
648 bool wheel_enabled
= false;
651 static const short scoring
[4] = { /* scoring for each number of lines */
652 #if BOARD_HEIGHT == 20
653 40 /* single */ , 100 /* double */ , 300 /* triple */ , 1200 /* rockblox */
654 #elif BOARD_HEIGHT == 14 /* Player special values */
655 60 /* single */ , 150 /* double */ , 500 /* triple */ , 2000 /* rockblox */
662 unsigned short color
[3]; /* color of figure (light,middle,shadow) */
664 unsigned short max_or
; /* max orientations */
665 signed short shapeX
[4], shapeY
[4]; /* implementation of figures */
668 /* array of figures */
669 figures
[BLOCKS_NUM
] = {
673 {LCD_RGBPACK (153, 255, 255), LCD_RGBPACK(0, 255, 255),
674 LCD_RGBPACK(0,153,153)},
676 {LCD_WHITE
, LCD_LIGHTGRAY
, LCD_DARKGRAY
},
685 {LCD_RGBPACK (255, 153, 128), LCD_RGBPACK (255, 0, 0),
686 LCD_RGBPACK (153, 0, 0)},
688 {LCD_WHITE
, LCD_LIGHTGRAY
, LCD_DARKGRAY
},
697 {LCD_RGBPACK (153, 255, 153), LCD_RGBPACK (0, 255, 0),
698 LCD_RGBPACK (0, 153, 0)},
700 {LCD_WHITE
, LCD_LIGHTGRAY
, LCD_DARKGRAY
},
709 {LCD_RGBPACK (153, 153, 255), LCD_RGBPACK (0, 0, 255),
710 LCD_RGBPACK (0, 0, 153)},
712 {LCD_WHITE
, LCD_LIGHTGRAY
, LCD_DARKGRAY
},
721 {LCD_RGBPACK (255, 255, 153), LCD_RGBPACK (255, 255, 0),
722 LCD_RGBPACK (153, 153, 0)},
724 {LCD_WHITE
, LCD_LIGHTGRAY
, LCD_DARKGRAY
},
733 {LCD_RGBPACK (255, 153, 255), LCD_RGBPACK (255, 0, 255),
734 LCD_RGBPACK (153, 0, 153)},
736 {LCD_WHITE
, LCD_LIGHTGRAY
, LCD_DARKGRAY
},
745 {LCD_RGBPACK (204, 204, 204), LCD_RGBPACK (153, 153, 153),
746 LCD_RGBPACK (85, 85, 85)},
748 {LCD_WHITE
, LCD_LIGHTGRAY
, LCD_DARKGRAY
},
756 bool resume_file
= false;
758 /* Rockbox File System only supports full filenames inc dir */
759 #define HIGH_SCORE PLUGIN_GAMES_DIR "/rockblox.score"
760 #define RESUME_FILE PLUGIN_GAMES_DIR "/rockblox.resume"
761 #define MAX_HIGH_SCORES 5
763 /* Default High Scores... */
764 struct highscore highest
[MAX_HIGH_SCORES
];
766 /* get random number from (0) to (range-1) */
767 static int t_rand (int range
)
769 return rb
->rand () % range
;
772 static inline void show_game_over (void)
774 rb
->splash(HZ
,"Game over!");
777 /* init the board array to have no blocks */
778 static void init_board (void)
781 for (i
= 0; i
< BOARD_WIDTH
; i
++)
782 for (j
= 0; j
< BOARD_HEIGHT
; j
++)
783 rockblox_status
.board
[j
][i
] = EMPTY_BLOCK
;
786 /* show the score, level and lines */
787 static void show_details (void)
789 char str
[25]; /* for strings */
791 #ifdef HAVE_LCD_BITMAP
793 rb
->lcd_set_foreground (LCD_BLACK
);
794 rb
->lcd_set_background (LCD_WHITE
);
796 rb
->snprintf (str
, sizeof (str
), "%d", rockblox_status
.score
);
797 rb
->lcd_putsxy (LABEL_X
, SCORE_Y
, str
);
798 rb
->snprintf (str
, sizeof (str
), "%d", rockblox_status
.level
);
799 rb
->lcd_putsxy (LEVEL_X
, LEVEL_Y
, str
);
800 rb
->snprintf (str
, sizeof (str
), "%d", rockblox_status
.lines
);
801 rb
->lcd_putsxy (LINES_X
, LINES_Y
, str
);
802 #else /* HAVE_LCD_CHARCELLS */
803 rb
->snprintf (str
, sizeof (str
), "L%d/%d", rockblox_status
.level
,
804 rockblox_status
.lines
);
805 rb
->lcd_puts (5, 0, str
);
806 rb
->snprintf (str
, sizeof (str
), "S%d", rockblox_status
.score
);
807 rb
->lcd_puts (5, 1, str
);
812 static void show_highscores (void)
815 char str
[25]; /* for strings */
817 for (i
= 0; i
<MAX_HIGH_SCORES
; i
++)
819 rb
->snprintf (str
, sizeof (str
), "%06d" _SPACE
"L%1d",
820 highest
[i
].score
, highest
[i
].level
);
821 rb
->lcd_putsxy (HIGH_LABEL_X
, HIGH_SCORE_Y
+ (10 * i
), str
);
826 static void load_game(void)
832 fd
= rb
->open(RESUME_FILE
, O_RDONLY
);
835 if (rb
->read(fd
, &rockblox_status
, sizeof(struct _rockblox_status
))
836 < (ssize_t
)sizeof(struct _rockblox_status
))
838 rb
->splash(HZ
/2, "Loading Rockblox resume info failed");
849 static void dump_resume(void)
853 fd
= rb
->open(RESUME_FILE
, O_WRONLY
|O_CREAT
);
857 if (rb
->write(fd
, &rockblox_status
, sizeof(struct _rockblox_status
))
867 rb
->splash(HZ
/2, "Writing Rockblox resume info failed");
871 static void init_rockblox (bool resume
)
877 rb
->snprintf(score_name
, sizeof(score_name
), "%04d%02d%02d %02d%02d%02d",
878 tm
->tm_year
+ 1900, tm
->tm_mon
+ 1, tm
->tm_mday
,
879 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
881 #ifdef HAVE_LCD_BITMAP
882 rb
->lcd_bitmap (rockblox_background
, 0, 0, LCD_WIDTH
, LCD_HEIGHT
);
883 #else /* HAVE_LCD_CHARCELLS */
885 pgfx_display_block (3, 0, 3, 1);
886 pgfx_display_block (4, 0, 3, 0);
887 pgfx_clear_display();
888 pgfx_fillrect (3, 0, 2, 14);
889 pgfx_fillrect (15, 7, 2, 7);
894 rockblox_status
.level
= 1;
895 rockblox_status
.lines
= 0;
896 rockblox_status
.score
= 0;
897 rockblox_status
.nf
= t_rand(BLOCKS_NUM
);
909 static inline int level_speed(int level
)
911 #if BOARD_HEIGHT == 20
912 return (5*HZ
) / (level
+ 9);
913 #elif BOARD_HEIGHT == 14
914 return (7*HZ
) / (level
+ 9);
918 static int getRelativeX (int figure
, int square
, int orientation
)
920 switch (orientation
) {
922 return figures
[figure
].shapeX
[square
];
924 return figures
[figure
].shapeY
[square
];
926 return -figures
[figure
].shapeX
[square
];
928 return -figures
[figure
].shapeY
[square
];
934 static int getRelativeY (int figure
, int square
, int orientation
)
936 switch (orientation
) {
938 return figures
[figure
].shapeY
[square
];
940 return -figures
[figure
].shapeX
[square
];
942 return -figures
[figure
].shapeY
[square
];
944 return figures
[figure
].shapeX
[square
];
950 /* redraw the while board on the screen */
951 static void refresh_board (void)
953 int i
, j
, x
, y
, block
;
956 rb
->lcd_set_foreground (LCD_BLACK
);
958 MYLCD(set_drawmode
) (DRMODE_SOLID
| DRMODE_INVERSEVID
);
961 MYLCD(fillrect
) (BOARD_X
, BOARD_Y
, BOARD_WIDTH
* BLOCK_WIDTH
,
962 BOARD_HEIGHT
* BLOCK_HEIGHT
);
965 MYLCD(set_drawmode
) (DRMODE_SOLID
);
968 for (i
= 0; i
< BOARD_WIDTH
; i
++)
969 for (j
= 0; j
< BOARD_HEIGHT
; j
++) {
970 block
= rockblox_status
.board
[j
][i
];
971 if (block
!= EMPTY_BLOCK
) {
972 #ifdef HAVE_LCD_BITMAP
975 rb
->lcd_set_foreground (figures
[block
].color
[1]);
977 rb
->lcd_fillrect (BOARD_X
+ i
* BLOCK_WIDTH
,
978 BOARD_Y
+ j
* BLOCK_HEIGHT
,
979 BLOCK_WIDTH
, BLOCK_HEIGHT
);
982 rb
->lcd_set_foreground (figures
[block
].color
[0]);
984 rb
->lcd_vline (BOARD_X
+ i
* BLOCK_WIDTH
,
985 BOARD_Y
+ j
* BLOCK_HEIGHT
,
986 BOARD_Y
+ (j
+ 1) * BLOCK_HEIGHT
- 2);
987 rb
->lcd_hline (BOARD_X
+ i
* BLOCK_WIDTH
,
988 BOARD_X
+ (i
+ 1) * BLOCK_WIDTH
- 2,
989 BOARD_Y
+ j
* BLOCK_HEIGHT
);
992 rb
->lcd_set_foreground (figures
[block
].color
[2]);
994 rb
->lcd_vline (BOARD_X
+ (i
+ 1) * BLOCK_WIDTH
- 1,
995 BOARD_Y
+ j
* BLOCK_HEIGHT
+ 1,
996 BOARD_Y
+ (j
+ 1) * BLOCK_HEIGHT
- 1);
997 rb
->lcd_hline (BOARD_X
+ i
* BLOCK_WIDTH
+ 1,
998 BOARD_X
+ (i
+ 1) * BLOCK_WIDTH
- 1,
999 BOARD_Y
+ (j
+ 1) * BLOCK_HEIGHT
- 1);
1000 #else /* HAVE_LCD_CHARCELLS */
1001 pgfx_drawpixel (BOARD_X
+ i
, BOARD_Y
+ j
);
1006 for (i
= 0; i
< 4; i
++) {
1007 x
= getRelativeX (rockblox_status
.cf
, i
, rockblox_status
.co
)
1008 + rockblox_status
.cx
;
1009 y
= getRelativeY (rockblox_status
.cf
, i
, rockblox_status
.co
)
1010 + rockblox_status
.cy
;
1011 #ifdef HAVE_LCD_BITMAP
1013 /* middle drawing */
1014 rb
->lcd_set_foreground (figures
[rockblox_status
.cf
].color
[1]);
1016 rb
->lcd_fillrect (BOARD_X
+ x
* BLOCK_WIDTH
,
1017 BOARD_Y
+ y
* BLOCK_HEIGHT
,
1018 BLOCK_WIDTH
, BLOCK_HEIGHT
);
1021 rb
->lcd_set_foreground (figures
[rockblox_status
.cf
].color
[0]);
1023 rb
->lcd_vline (BOARD_X
+ x
* BLOCK_WIDTH
, BOARD_Y
+ y
* BLOCK_HEIGHT
,
1024 BOARD_Y
+ (y
+ 1) * BLOCK_HEIGHT
- 2);
1025 rb
->lcd_hline (BOARD_X
+ x
* BLOCK_WIDTH
,
1026 BOARD_X
+ (x
+ 1) * BLOCK_WIDTH
- 2,
1027 BOARD_Y
+ y
* BLOCK_HEIGHT
);
1029 /* shadow drawing */
1030 rb
->lcd_set_foreground (figures
[rockblox_status
.cf
].color
[2]);
1032 rb
->lcd_vline (BOARD_X
+ (x
+ 1) * BLOCK_WIDTH
- 1,
1033 BOARD_Y
+ y
* BLOCK_HEIGHT
+ 1,
1034 BOARD_Y
+ (y
+ 1) * BLOCK_HEIGHT
- 1);
1035 rb
->lcd_hline (BOARD_X
+ x
* BLOCK_WIDTH
+ 1,
1036 BOARD_X
+ (x
+ 1) * BLOCK_WIDTH
- 1,
1037 BOARD_Y
+ (y
+ 1) * BLOCK_HEIGHT
- 1);
1038 #else /* HAVE_LCD_CHARCELLS */
1039 pgfx_drawpixel (BOARD_X
+ x
, BOARD_Y
+ y
);
1045 static bool canMoveTo (int x
, int y
, int newOrientation
)
1048 for (i
= 0; i
< 4; i
++) {
1049 ry
= getRelativeY (rockblox_status
.cf
, i
, newOrientation
) + y
;
1050 rx
= getRelativeX (rockblox_status
.cf
, i
, newOrientation
) + x
;
1051 if ((rx
< 0 || rx
>= BOARD_WIDTH
) ||
1052 (ry
< 0 || ry
>= BOARD_HEIGHT
) ||
1053 (rockblox_status
.board
[ry
][rx
] != EMPTY_BLOCK
))
1059 /* draws the preview of next block in the preview window */
1060 static void draw_next_block (void)
1063 /* clear preview window first */
1065 rb
->lcd_set_foreground (LCD_BLACK
);
1066 #elif LCD_DEPTH == 1
1067 MYLCD(set_drawmode
) (DRMODE_SOLID
| DRMODE_INVERSEVID
);
1071 MYLCD(fillrect
) (PREVIEW_X
, PREVIEW_Y
, BLOCK_WIDTH
* 4, BLOCK_HEIGHT
* 4);
1074 MYLCD(set_drawmode
) (DRMODE_SOLID
);
1077 /* draw the lightgray rectangles */
1079 rb
->lcd_set_foreground (LCD_RGBPACK (40, 40, 40));
1080 #elif LCD_DEPTH == 2
1081 rb
->lcd_set_foreground (LCD_DARKGRAY
);
1085 for (rx
= 0; rx
< 4; rx
++)
1086 for (ry
= 0; ry
< 4; ry
++)
1087 rb
->lcd_drawrect (PREVIEW_X
+ rx
* BLOCK_WIDTH
,
1088 PREVIEW_Y
+ ry
* BLOCK_HEIGHT
, BLOCK_WIDTH
,
1092 /* draw the figure */
1093 for (i
= 0; i
< 4; i
++) {
1094 rx
= getRelativeX (rockblox_status
.nf
, i
, 0) + 2;
1095 ry
= getRelativeY (rockblox_status
.nf
, i
, 0) + 2;
1096 #ifdef HAVE_LCD_BITMAP
1098 rb
->lcd_set_foreground (figures
[rockblox_status
.nf
].color
[1]); /* middle drawing */
1100 rb
->lcd_fillrect (PREVIEW_X
+ rx
* BLOCK_WIDTH
,
1101 PREVIEW_Y
+ ry
* BLOCK_HEIGHT
,
1102 BLOCK_WIDTH
, BLOCK_HEIGHT
);
1104 rb
->lcd_set_foreground (figures
[rockblox_status
.nf
].color
[0]); /* light drawing */
1106 rb
->lcd_vline (PREVIEW_X
+ rx
* BLOCK_WIDTH
,
1107 PREVIEW_Y
+ ry
* BLOCK_HEIGHT
,
1108 PREVIEW_Y
+ (ry
+ 1) * BLOCK_HEIGHT
- 2);
1109 rb
->lcd_hline (PREVIEW_X
+ rx
* BLOCK_WIDTH
,
1110 PREVIEW_X
+ (rx
+ 1) * BLOCK_WIDTH
- 2,
1111 PREVIEW_Y
+ ry
* BLOCK_HEIGHT
);
1113 rb
->lcd_set_foreground (figures
[rockblox_status
.nf
].color
[2]); /* shadow drawing */
1115 rb
->lcd_vline (PREVIEW_X
+ (rx
+ 1) * BLOCK_WIDTH
- 1,
1116 PREVIEW_Y
+ ry
* BLOCK_HEIGHT
+ 1,
1117 PREVIEW_Y
+ (ry
+ 1) * BLOCK_HEIGHT
- 1);
1118 rb
->lcd_hline (PREVIEW_X
+ rx
* BLOCK_WIDTH
+ 1,
1119 PREVIEW_X
+ (rx
+ 1) * BLOCK_WIDTH
- 1,
1120 PREVIEW_Y
+ (ry
+ 1) * BLOCK_HEIGHT
- 1);
1121 #else /* HAVE_LCD_CHARCELLS */
1122 pgfx_drawpixel (PREVIEW_X
+ rx
, PREVIEW_Y
+ ry
);
1128 /* move the block to a relative location */
1129 static void move_block (int x
, int y
, int o
)
1131 if (canMoveTo (rockblox_status
.cx
+ x
, rockblox_status
.cy
+ y
, o
)) {
1132 rockblox_status
.cy
+= y
;
1133 rockblox_status
.cx
+= x
;
1134 rockblox_status
.co
= o
;
1138 /* try to add a new block to play with (return true if gameover) */
1139 static void new_block (void)
1141 rockblox_status
.cy
= 1;
1142 rockblox_status
.cx
= 5;
1143 rockblox_status
.cf
= rockblox_status
.nf
;
1144 rockblox_status
.co
= 0; /* start at the same orientation all time */
1145 rockblox_status
.nf
= t_rand (BLOCKS_NUM
);
1146 rockblox_status
.gameover
= !canMoveTo (rockblox_status
.cx
,
1147 rockblox_status
.cy
, rockblox_status
.co
);
1153 /* check for filled rockblox_status.lines and do what necessary */
1154 static int check_lines (void)
1160 for (j
= 0; j
< BOARD_HEIGHT
; j
++) {
1161 for (i
= 0; ((i
< BOARD_WIDTH
) &&
1162 (rockblox_status
.board
[j
][i
] != EMPTY_BLOCK
)); i
++);
1163 if (i
== BOARD_WIDTH
) { /* woo hoo, we have a line */
1165 for (y
= j
; y
> 0; y
--)
1167 for (i
= 0; i
< BOARD_WIDTH
; i
++)
1169 rockblox_status
.board
[y
][i
] = rockblox_status
.board
[y
- 1][i
];
1178 /* moves down the figure and returns true if gameover */
1179 static void move_down (void)
1183 if (!canMoveTo (rockblox_status
.cx
, rockblox_status
.cy
+ 1, rockblox_status
.co
)) {
1184 /* save figure to board */
1185 for (i
= 0; i
< 4; i
++) {
1186 rx
= getRelativeX (rockblox_status
.cf
, i
, rockblox_status
.co
) + rockblox_status
.cx
;
1187 ry
= getRelativeY (rockblox_status
.cf
, i
, rockblox_status
.co
) + rockblox_status
.cy
;
1188 rockblox_status
.board
[ry
][rx
] = rockblox_status
.cf
;
1190 /* check if formed some lines */
1193 /* the original scoring from "http://en.wikipedia.org/wiki/Rockblox" */
1194 rockblox_status
.score
+= scoring
[l
- 1] * rockblox_status
.level
;
1195 rockblox_status
.lines
+= l
;
1196 rockblox_status
.level
= (int) rockblox_status
.lines
/ 10 + 1;
1202 /* generate a new figure */
1205 move_block (0, 1, rockblox_status
.co
);
1208 static bool rockblox_help(void)
1212 #define WORDS (sizeof help_text / sizeof (char*))
1213 char *help_text
[] = {
1214 "Rockblox", "", "Aim", "", "Make", "the", "falling", "blocks", "of", "different",
1215 "shapes", "form", "full", "rows.", "Whenever", "a", "row", "is", "completed,", "it",
1216 "will", "be", "cleared", "away", "and", "you", "gain", "points."
1219 static struct style_text formation
[]={
1220 { 0, TEXT_CENTER
|TEXT_UNDERLINE
},
1224 #ifdef HAVE_LCD_BITMAP
1225 rb
->lcd_setfont(FONT_UI
);
1227 #ifdef HAVE_LCD_COLOR
1228 rb
->lcd_set_background(LCD_BLACK
);
1229 rb
->lcd_set_foreground(LCD_WHITE
);
1231 if (display_text(WORDS
, help_text
, formation
, NULL
))
1234 button
= rb
->button_get(true);
1235 if ( rb
->default_event_handler( button
) == SYS_USB_CONNECTED
)
1237 } while( ( button
== BUTTON_NONE
)
1238 || ( button
& (BUTTON_REL
|BUTTON_REPEAT
) ) );
1239 #ifdef HAVE_LCD_BITMAP
1240 rb
->lcd_setfont(FONT_SYSFIXED
);
1245 static int rockblox_menu_cb(int action
, const struct menu_item_ex
*this_item
)
1247 int i
= ((intptr_t)this_item
);
1248 if(action
== ACTION_REQUEST_MENUITEM
1249 && !resume
&& (i
==0 || i
==5))
1250 return ACTION_EXIT_MENUITEM
;
1254 static int rockblox_menu(void)
1258 MENUITEM_STRINGLIST(main_menu
, "Rockblox Menu", rockblox_menu_cb
,
1259 "Resume Game", "Start New Game",
1260 "Help", "High Scores", "Playback Control",
1261 "Quit without Saving", "Quit");
1263 rb
->button_clear_queue();
1265 switch (rb
->do_menu(&main_menu
, &selected
, NULL
, false)) {
1268 rb
->remove(RESUME_FILE
);
1269 init_rockblox(true);
1272 init_rockblox(false);
1275 if (rockblox_help())
1279 #ifdef HAVE_LCD_BITMAP
1280 highscore_show(MAX_HIGH_SCORES
, highest
, MAX_HIGH_SCORES
, true);
1282 rb
->splashf(2*HZ
, "High Score: %d", highest
[0].score
);
1286 if (playback_control(NULL
))
1293 rb
->splash(HZ
*1, "Saving game ...");
1297 case MENU_ATTACHED_USB
:
1307 static int rockblox_loop (void)
1310 int lastbutton
= BUTTON_NONE
;
1311 long next_down_tick
= *rb
->current_tick
+ level_speed(rockblox_status
.level
);
1313 if (rockblox_menu()) {
1317 resume_file
= false;
1320 #ifdef HAS_BUTTON_HOLD
1321 if (rb
->button_hold ()) {
1322 /* Turn on backlight timeout (revert to settings) */
1323 backlight_use_settings(); /* backlight control in lib/helper.c */
1324 rb
->splash(0, "Paused");
1325 while (rb
->button_hold ())
1328 /* Turn off backlight timeout */
1329 backlight_force_on(); /* backlight control in lib/helper.c */
1331 /* get rid of the splash text */
1332 rb
->lcd_bitmap (rockblox_background
, 0, 0, LCD_WIDTH
, LCD_HEIGHT
);
1342 button
= rb
->button_get_w_tmo (MAX(next_down_tick
- *rb
->current_tick
, 1));
1344 #ifdef ROCKBLOX_RC_OFF
1345 case ROCKBLOX_RC_OFF
:
1348 #ifdef ROCKBLOX_OFF_PRE
1349 if (lastbutton
!= ROCKBLOX_OFF_PRE
)
1356 #if defined(ROCKBLOX_ROTATE)
1357 case ROCKBLOX_ROTATE
:
1359 case ROCKBLOX_ROTATE_RIGHT
:
1360 case ROCKBLOX_ROTATE_RIGHT
| BUTTON_REPEAT
:
1361 #ifdef HAVE_SCROLLWHEEL
1362 /* if the wheel is disabled, add an event to the stack. */
1363 if(wheel_enabled
== false)
1366 /* if it's enabled, go ahead and rotate.. */
1369 move_block (0, 0, (rockblox_status
.co
+ 1) % figures
[rockblox_status
.cf
].max_or
);
1372 case ROCKBLOX_ROTATE_LEFT
:
1373 case ROCKBLOX_ROTATE_LEFT
| BUTTON_REPEAT
:
1374 #ifdef HAVE_SCROLLWHEEL
1375 if(wheel_enabled
== false)
1381 (rockblox_status
.co
+ figures
[rockblox_status
.cf
].max_or
-
1382 1) % figures
[rockblox_status
.cf
].max_or
);
1385 #ifdef ROCKBLOX_ROTATE_RIGHT2
1386 case ROCKBLOX_ROTATE_RIGHT2
:
1387 move_block (0, 0, (rockblox_status
.co
+ 1) % figures
[rockblox_status
.cf
].max_or
);
1392 case ROCKBLOX_DOWN
| BUTTON_REPEAT
:
1393 move_block (0, 1, rockblox_status
.co
);
1396 case ROCKBLOX_RIGHT
:
1397 case ROCKBLOX_RIGHT
| BUTTON_REPEAT
:
1398 move_block (1, 0, rockblox_status
.co
);
1402 case ROCKBLOX_LEFT
| BUTTON_REPEAT
:
1403 move_block (-1, 0, rockblox_status
.co
);
1407 #ifdef ROCKBLOX_DROP_PRE
1408 if (lastbutton
!= ROCKBLOX_DROP_PRE
)
1411 while (canMoveTo (rockblox_status
.cx
, rockblox_status
.cy
+ 1, rockblox_status
.co
))
1412 move_block (0, 1, rockblox_status
.co
);
1414 #ifdef ROCKBLOX_RESTART
1415 case ROCKBLOX_RESTART
:
1416 rb
->splash (HZ
* 1, "Restarting...");
1417 init_rockblox (false);
1422 if (rb
->default_event_handler (button
) == SYS_USB_CONNECTED
)
1423 return PLUGIN_USB_CONNECTED
;
1426 if (button
!= BUTTON_NONE
)
1427 lastbutton
= button
;
1429 #ifdef HAVE_SCROLLWHEEL
1430 /* check if we should enable the scroll wheel, if events
1431 * begin to stack up... */
1432 if(wheel_enabled
== false)
1434 /* stopped rotating the wheel, reset the count */
1435 if(wheel_events
== last_wheel_event
)
1437 last_wheel_event
= 0;
1440 /* rotated the wheel a while constantly, enable it. */
1441 else if(wheel_events
> 3)
1443 wheel_enabled
= true;
1446 /* this evens out the last event and the "current" event.
1447 * if we get an event next time through button reading, it will
1448 * remain ahead of last_event. if we don't, they'll end up equaling
1449 * each other.. thus, the scroll count will be reset. */
1450 if(wheel_enabled
== false && wheel_events
> last_wheel_event
)
1455 if (TIME_AFTER(*rb
->current_tick
, next_down_tick
)) {
1457 next_down_tick
+= level_speed(rockblox_status
.level
);
1458 if (TIME_AFTER(*rb
->current_tick
, next_down_tick
))
1459 /* restart time "raster" when we had to wait longer than usual
1460 * (pause, game restart etc) */
1461 next_down_tick
= *rb
->current_tick
+ level_speed(rockblox_status
.level
);
1464 if (rockblox_status
.gameover
) {
1466 rb
->lcd_set_foreground (LCD_BLACK
);
1479 enum plugin_status
plugin_start (const void *parameter
)
1484 rb
->srand (*rb
->current_tick
);
1486 /* Load HighScore if any */
1487 highscore_load(HIGH_SCORE
, highest
, MAX_HIGH_SCORES
);
1490 rb
->lcd_set_backdrop(NULL
);
1493 #ifdef HAVE_LCD_BITMAP
1494 rb
->lcd_setfont (FONT_SYSFIXED
);
1496 if (!pgfx_init(4, 2))
1498 rb
->splash(HZ
*2, "Old LCD :(");
1502 /* Turn off backlight timeout */
1503 backlight_force_on(); /* backlight control in lib/helper.c */
1505 resume_file
= resume
;
1506 while(!rockblox_loop()) {
1508 int position
= highscore_update(rockblox_status
.score
, rockblox_status
.level
, "", highest
,
1510 if (position
== 0) {
1511 rb
->splash(HZ
*2, "New High Score");
1513 if (position
!= -1) {
1514 #ifdef HAVE_LCD_BITMAP
1515 highscore_show(position
, highest
, MAX_HIGH_SCORES
, true);
1517 rb
->splashf(2*HZ
, "High Score: %d", highest
[position
].score
);
1523 #ifndef HAVE_LCD_BITMAP
1526 /* Save user's HighScore */
1527 highscore_save(HIGH_SCORE
, highest
, MAX_HIGH_SCORES
);
1528 backlight_use_settings(); /* backlight control in lib/helper.c */