1 /*****************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// __ \_/ ___\| |/ /| __ \ / __ \ \/ /
5 * Jukebox | | ( (__) ) \___| ( | \_\ ( (__) ) (
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2006 - 2008 Alexander Papst
11 * Idea from http://www.tetris1d.org
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ****************************************************************************/
25 #if CONFIG_KEYPAD == RECORDER_PAD
26 #define ONEDROCKBLOX_DOWN BUTTON_PLAY
27 #define ONEDROCKBLOX_QUIT BUTTON_OFF
29 #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
30 #define ONEDROCKBLOX_DOWN BUTTON_SELECT
31 #define ONEDROCKBLOX_QUIT BUTTON_OFF
33 #elif CONFIG_KEYPAD == ONDIO_PAD
34 #define ONEDROCKBLOX_DOWN BUTTON_RIGHT
35 #define ONEDROCKBLOX_QUIT BUTTON_OFF
37 #elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
38 #define ONEDROCKBLOX_DOWN BUTTON_SELECT
39 #define ONEDROCKBLOX_QUIT BUTTON_POWER
41 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
42 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
43 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
44 #define ONEDROCKBLOX_DOWN BUTTON_SELECT
45 #define ONEDROCKBLOX_QUIT (BUTTON_SELECT | BUTTON_MENU)
47 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
48 (CONFIG_KEYPAD == IRIVER_H300_PAD)
49 #define ONEDROCKBLOX_DOWN BUTTON_SELECT
50 #define ONEDROCKBLOX_QUIT BUTTON_OFF
52 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
53 #define ONEDROCKBLOX_DOWN BUTTON_SELECT
54 #define ONEDROCKBLOX_QUIT BUTTON_POWER
56 #elif CONFIG_KEYPAD == SANSA_E200_PAD || \
57 CONFIG_KEYPAD == SANSA_C200_PAD || \
58 CONFIG_KEYPAD == SANSA_CLIP_PAD || \
59 CONFIG_KEYPAD == SANSA_M200_PAD
60 #define ONEDROCKBLOX_DOWN BUTTON_SELECT
61 #define ONEDROCKBLOX_QUIT BUTTON_POWER
63 #elif CONFIG_KEYPAD == SANSA_FUZE_PAD
64 #define ONEDROCKBLOX_DOWN BUTTON_SELECT
65 #define ONEDROCKBLOX_QUIT BUTTON_HOME
67 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
68 #define ONEDROCKBLOX_DOWN BUTTON_PLAY
69 #define ONEDROCKBLOX_QUIT BUTTON_POWER
71 #elif (CONFIG_KEYPAD == GIGABEAT_S_PAD)
72 #define ONEDROCKBLOX_DOWN BUTTON_SELECT
73 #define ONEDROCKBLOX_QUIT BUTTON_BACK
75 #elif (CONFIG_KEYPAD == MROBE100_PAD)
76 #define ONEDROCKBLOX_DOWN BUTTON_SELECT
77 #define ONEDROCKBLOX_QUIT BUTTON_POWER
79 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
80 #define ONEDROCKBLOX_DOWN BUTTON_RC_PLAY
81 #define ONEDROCKBLOX_QUIT BUTTON_RC_REC
83 #elif (CONFIG_KEYPAD == COWON_D2_PAD)
84 #define ONEDROCKBLOX_DOWN BUTTON_MENU
85 #define ONEDROCKBLOX_QUIT BUTTON_POWER
87 #elif CONFIG_KEYPAD == IAUDIO67_PAD
88 #define ONEDROCKBLOX_DOWN BUTTON_MENU
89 #define ONEDROCKBLOX_QUIT BUTTON_POWER
91 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
92 #define ONEDROCKBLOX_DOWN BUTTON_SELECT
93 #define ONEDROCKBLOX_QUIT BUTTON_BACK
95 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
96 #define ONEDROCKBLOX_DOWN BUTTON_SELECT
97 #define ONEDROCKBLOX_QUIT BUTTON_POWER
99 #elif CONFIG_KEYPAD == PHILIPS_HDD6330_PAD
100 #define ONEDROCKBLOX_DOWN BUTTON_PLAY
101 #define ONEDROCKBLOX_QUIT BUTTON_POWER
103 #elif CONFIG_KEYPAD == PHILIPS_SA9200_PAD
104 #define ONEDROCKBLOX_DOWN BUTTON_PLAY
105 #define ONEDROCKBLOX_QUIT BUTTON_POWER
107 #elif (CONFIG_KEYPAD == ONDAVX747_PAD)
108 #define ONEDROCKBLOX_DOWN BUTTON_MENU
109 #define ONEDROCKBLOX_QUIT BUTTON_POWER
111 #elif (CONFIG_KEYPAD == SAMSUNG_YH_PAD)
112 #define ONEDROCKBLOX_DOWN BUTTON_DOWN
113 #define ONEDROCKBLOX_QUIT BUTTON_PLAY
115 #elif (CONFIG_KEYPAD == PBELL_VIBE500_PAD)
116 #define ONEDROCKBLOX_DOWN BUTTON_DOWN
117 #define ONEDROCKBLOX_QUIT BUTTON_REC
119 #elif (CONFIG_KEYPAD == MPIO_HD200_PAD)
120 #define ONEDROCKBLOX_DOWN BUTTON_FUNC
121 #define ONEDROCKBLOX_QUIT (BUTTON_REC | BUTTON_PLAY)
123 #elif (CONFIG_KEYPAD == MPIO_HD300_PAD)
124 #define ONEDROCKBLOX_DOWN BUTTON_DOWN
125 #define ONEDROCKBLOX_QUIT (BUTTON_REC | BUTTON_REPEAT)
127 #elif (CONFIG_KEYPAD == SANSA_FUZEPLUS_PAD)
128 #define ONEDROCKBLOX_DOWN BUTTON_DOWN
129 #define ONEDROCKBLOX_QUIT BUTTON_POWER
131 #elif defined(HAVE_TOUCHSCREEN)
133 #define ONEDROCKBLOX_DOWN BUTTON_BOTTOMMIDDLE
134 #define ONEDROCKBLOX_QUIT BUTTON_POWER
137 #error No keymap defined!
140 #define mrand(max) (short)(rb->rand()%max)
145 ** Lots of defines for the drawing stuff :-)
146 ** The most ugly way i could think of...
149 #if (LCD_WIDTH > LCD_HEIGHT)
150 /* Any screens larger than the minis LCD */
151 #if (LCD_WIDTH > 132)
152 /* Max size of one block */
153 # define WIDTH (int)((LCD_HEIGHT * 0.85) / TILES)
154 /* Align the playing filed centered */
155 # define CENTER_X (int)(LCD_WIDTH/2-(WIDTH/2))
156 # define CENTER_Y (int)(LCD_HEIGHT/2-((WIDTH*TILES+TILES)/2))
158 # define SCORE_X (int)(((CENTER_X+WIDTH+4) + (LCD_WIDTH-(CENTER_X+WIDTH+4))/2)-(f_width/2))
159 # define SCORE_Y (int)((LCD_HEIGHT/2)-(f_height/2))
160 /* Max. size of bricks is 4 blocks */
161 # define NEXT_H (WIDTH*4+3)
162 # define NEXT_X (int)(CENTER_X/2-WIDTH/2)
163 # define NEXT_Y (int)(LCD_HEIGHT/2-NEXT_H/2)
165 /* Max size of one block */
166 # define WIDTH (int)((LCD_HEIGHT * 0.85) / TILES)
167 /* Align the playing left centered */
168 # define CENTER_X (int)(LCD_WIDTH*0.2)
169 # define CENTER_Y (int)(LCD_HEIGHT/2-((WIDTH*TILES+TILES)/2))
171 # define SCORE_X (int)(((CENTER_X+WIDTH+4) + (LCD_WIDTH-(CENTER_X+WIDTH+4))/2)-(f_width/2))
173 /* Max. size of bricks is 4 blocks */
174 # define NEXT_H (WIDTH*4+3)
175 # define NEXT_X (score_x+f_width+7)
176 # define NEXT_Y (int)(LCD_HEIGHT-((4*WIDTH)+13))
179 /* Max size of one block */
180 # define WIDTH (int)((LCD_HEIGHT * 0.8) / TILES)
181 /* Align the playing filed centered */
182 # define CENTER_X (int)(LCD_WIDTH/2-(WIDTH/2))
185 # define SCORE_X (int)((LCD_WIDTH/2)-(f_width/2))
186 # define SCORE_Y (LCD_HEIGHT-(f_height+2))
187 /* Max. size of bricks is 4 blocks */
188 # define NEXT_H (WIDTH*4+3)
189 # define NEXT_X (int)(CENTER_X/2-WIDTH/2)
190 # define NEXT_Y (int)((LCD_HEIGHT * 0.8)/2-NEXT_H/2)
193 static void draw_brick(int pos
, int length
) {
195 rb
->lcd_set_drawmode(DRMODE_BG
|DRMODE_INVERSEVID
);
196 rb
->lcd_fillrect(CENTER_X
, CENTER_Y
, WIDTH
, WIDTH
* TILES
+ TILES
);
197 rb
->lcd_set_drawmode(DRMODE_SOLID
);
199 for (i
= pos
; i
< length
+ pos
; ++i
) {
200 if (i
>= 0) rb
->lcd_fillrect(CENTER_X
, CENTER_Y
+i
+(WIDTH
*i
), WIDTH
, WIDTH
);
204 enum plugin_status
plugin_start(const void* parameter
)
207 int f_width
, f_height
;
216 int pos_cur_brick
= 0;
217 int type_cur_brick
= 0;
218 int type_next_brick
= 0;
220 unsigned long int score
= 34126;
225 rb
->lcd_set_backdrop(NULL
);
226 rb
->lcd_set_background(LCD_BLACK
);
227 rb
->lcd_set_foreground(LCD_WHITE
);
230 rb
->lcd_setfont(FONT_SYSFIXED
);
232 rb
->lcd_getstringsize("100000000", &f_width
, &f_height
);
234 rb
->lcd_clear_display();
240 /* Playing filed box */
241 rb
->lcd_vline(CENTER_X
-2, CENTER_Y
, CENTER_Y
+ (WIDTH
*TILES
+TILES
));
242 rb
->lcd_vline(CENTER_X
+ WIDTH
+ 1, CENTER_Y
,
243 CENTER_Y
+ (WIDTH
*TILES
+TILES
));
244 rb
->lcd_hline(CENTER_X
-2, CENTER_X
+ WIDTH
+ 1,
245 CENTER_Y
+ (WIDTH
*TILES
+TILES
));
248 #if (LCD_WIDTH > LCD_HEIGHT)
249 rb
->lcd_drawrect(SCORE_X
-4, SCORE_Y
-5, f_width
+8, f_height
+9);
250 rb
->lcd_putsxy(SCORE_X
-4, SCORE_Y
-6-f_height
, "score");
252 rb
->lcd_hline(0, LCD_WIDTH
, SCORE_Y
-5);
253 rb
->lcd_putsxy(2, SCORE_Y
-6-f_height
, "score");
258 rb
->lcd_getstringsize("next", &f_width
, NULL
);
259 #if (LCD_WIDTH > LCD_HEIGHT) && !(LCD_WIDTH > 132)
260 rb
->lcd_drawrect(NEXT_X
-5, NEXT_Y
-5, WIDTH
+10, NEXT_H
+10);
261 rb
->lcd_putsxy(score_x
-4, NEXT_Y
-5, "next");
263 rb
->lcd_drawrect(NEXT_X
-5, NEXT_Y
-5, WIDTH
+10, NEXT_H
+10);
264 rb
->lcd_putsxy(NEXT_X
-5, NEXT_Y
-5-f_height
-1, "next");
270 rb
->srand( *rb
->current_tick
);
272 type_cur_brick
= 2 + mrand(3);
273 type_next_brick
= 2 + mrand(3);
276 end
= *rb
->current_tick
+ (cycletime
* HZ
) / 1000;
278 draw_brick(pos_cur_brick
, type_cur_brick
);
280 /* Draw next brick */
281 rb
->lcd_set_drawmode(DRMODE_BG
|DRMODE_INVERSEVID
);
282 rb
->lcd_fillrect(NEXT_X
, NEXT_Y
, WIDTH
, WIDTH
* 4 + 4);
283 rb
->lcd_set_drawmode(DRMODE_SOLID
);
285 for (i
= 0; i
< type_next_brick
; ++i
) {
286 rb
->lcd_fillrect(NEXT_X
,
287 NEXT_Y
+ ((type_next_brick
% 2) ? (int)(WIDTH
/2) : ((type_next_brick
== 2) ? (WIDTH
+1) : 0)) + (WIDTH
*i
) + i
,
292 rb
->lcd_putsxyf(score_x
, SCORE_Y
, "%8ld0", score
);
296 button
= rb
->button_status();
299 case ONEDROCKBLOX_DOWN
:
300 case (ONEDROCKBLOX_DOWN
|BUTTON_REPEAT
):
303 case ONEDROCKBLOX_QUIT
:
308 if(rb
->default_event_handler(button
) == SYS_USB_CONNECTED
) {
313 if ((pos_cur_brick
+ type_cur_brick
) > 10) {
314 type_cur_brick
= type_next_brick
;
315 type_next_brick
= 2 + mrand(3);
316 score
+= (type_cur_brick
- 1) * 2;
317 pos_cur_brick
= 1 - type_cur_brick
;
322 if (TIME_BEFORE(*rb
->current_tick
, end
))
323 rb
->sleep(end
-*rb
->current_tick
);