Add proper svn:mime-type
[maemo-rb.git] / apps / plugins / rockblox1d.c
blobeb1ad1de90d3c7fe1d51bbf4234b79c4edb7c526
1 /*****************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// __ \_/ ___\| |/ /| __ \ / __ \ \/ /
5 * Jukebox | | ( (__) ) \___| ( | \_\ ( (__) ) (
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
23 #include "plugin.h"
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 defined(HAVE_TOUCHSCREEN)
129 #define ONEDROCKBLOX_DOWN BUTTON_BOTTOMMIDDLE
130 #define ONEDROCKBLOX_QUIT BUTTON_POWER
132 #else
133 #error No keymap defined!
134 #endif
136 #define mrand(max) (short)(rb->rand()%max)
138 #define TILES 11
140 /**********
141 ** Lots of defines for the drawing stuff :-)
142 ** The most ugly way i could think of...
145 #if (LCD_WIDTH > LCD_HEIGHT)
146 /* Any screens larger than the minis LCD */
147 #if (LCD_WIDTH > 132)
148 /* Max size of one block */
149 # define WIDTH (int)((LCD_HEIGHT * 0.85) / TILES)
150 /* Align the playing filed centered */
151 # define CENTER_X (int)(LCD_WIDTH/2-(WIDTH/2))
152 # define CENTER_Y (int)(LCD_HEIGHT/2-((WIDTH*TILES+TILES)/2))
153 /* Score box */
154 # define SCORE_X (int)(((CENTER_X+WIDTH+4) + (LCD_WIDTH-(CENTER_X+WIDTH+4))/2)-(f_width/2))
155 # define SCORE_Y (int)((LCD_HEIGHT/2)-(f_height/2))
156 /* Max. size of bricks is 4 blocks */
157 # define NEXT_H (WIDTH*4+3)
158 # define NEXT_X (int)(CENTER_X/2-WIDTH/2)
159 # define NEXT_Y (int)(LCD_HEIGHT/2-NEXT_H/2)
160 #else
161 /* Max size of one block */
162 # define WIDTH (int)((LCD_HEIGHT * 0.85) / TILES)
163 /* Align the playing left centered */
164 # define CENTER_X (int)(LCD_WIDTH*0.2)
165 # define CENTER_Y (int)(LCD_HEIGHT/2-((WIDTH*TILES+TILES)/2))
166 /* Score box */
167 # define SCORE_X (int)(((CENTER_X+WIDTH+4) + (LCD_WIDTH-(CENTER_X+WIDTH+4))/2)-(f_width/2))
168 # define SCORE_Y 16
169 /* Max. size of bricks is 4 blocks */
170 # define NEXT_H (WIDTH*4+3)
171 # define NEXT_X (score_x+f_width+7)
172 # define NEXT_Y (int)(LCD_HEIGHT-((4*WIDTH)+13))
173 #endif
174 #else
175 /* Max size of one block */
176 # define WIDTH (int)((LCD_HEIGHT * 0.8) / TILES)
177 /* Align the playing filed centered */
178 # define CENTER_X (int)(LCD_WIDTH/2-(WIDTH/2))
179 # define CENTER_Y 2
180 /* Score box */
181 # define SCORE_X (int)((LCD_WIDTH/2)-(f_width/2))
182 # define SCORE_Y (LCD_HEIGHT-(f_height+2))
183 /* Max. size of bricks is 4 blocks */
184 # define NEXT_H (WIDTH*4+3)
185 # define NEXT_X (int)(CENTER_X/2-WIDTH/2)
186 # define NEXT_Y (int)((LCD_HEIGHT * 0.8)/2-NEXT_H/2)
187 #endif
189 void draw_brick(int pos, int length) {
190 int i = pos;
191 rb->lcd_set_drawmode(DRMODE_BG|DRMODE_INVERSEVID);
192 rb->lcd_fillrect(CENTER_X, CENTER_Y, WIDTH, WIDTH * TILES + TILES);
193 rb->lcd_set_drawmode(DRMODE_SOLID);
195 for (i = pos; i < length + pos; ++i) {
196 if (i >= 0) rb->lcd_fillrect(CENTER_X, CENTER_Y+i+(WIDTH*i), WIDTH, WIDTH);
200 enum plugin_status plugin_start(const void* parameter)
202 int i;
203 int f_width, f_height;
204 int score_x;
206 bool quit = false;
207 int button;
209 int cycletime = 300;
210 int end;
212 int pos_cur_brick = 0;
213 int type_cur_brick = 0;
214 int type_next_brick = 0;
216 unsigned long int score = 34126;
218 (void)parameter;
220 #if LCD_DEPTH > 1
221 rb->lcd_set_backdrop(NULL);
222 rb->lcd_set_background(LCD_BLACK);
223 rb->lcd_set_foreground(LCD_WHITE);
224 #endif
226 rb->lcd_setfont(FONT_SYSFIXED);
228 rb->lcd_getstringsize("100000000", &f_width, &f_height);
230 rb->lcd_clear_display();
232 /***********
233 ** Draw EVERYTHING
236 /* Playing filed box */
237 rb->lcd_vline(CENTER_X-2, CENTER_Y, CENTER_Y + (WIDTH*TILES+TILES));
238 rb->lcd_vline(CENTER_X + WIDTH + 1, CENTER_Y,
239 CENTER_Y + (WIDTH*TILES+TILES));
240 rb->lcd_hline(CENTER_X-2, CENTER_X + WIDTH + 1,
241 CENTER_Y + (WIDTH*TILES+TILES));
243 /* Score box */
244 #if (LCD_WIDTH > LCD_HEIGHT)
245 rb->lcd_drawrect(SCORE_X-4, SCORE_Y-5, f_width+8, f_height+9);
246 rb->lcd_putsxy(SCORE_X-4, SCORE_Y-6-f_height, "score");
247 #else
248 rb->lcd_hline(0, LCD_WIDTH, SCORE_Y-5);
249 rb->lcd_putsxy(2, SCORE_Y-6-f_height, "score");
250 #endif
251 score_x = SCORE_X;
253 /* Next box */
254 rb->lcd_getstringsize("next", &f_width, NULL);
255 #if (LCD_WIDTH > LCD_HEIGHT) && !(LCD_WIDTH > 132)
256 rb->lcd_drawrect(NEXT_X-5, NEXT_Y-5, WIDTH+10, NEXT_H+10);
257 rb->lcd_putsxy(score_x-4, NEXT_Y-5, "next");
258 #else
259 rb->lcd_drawrect(NEXT_X-5, NEXT_Y-5, WIDTH+10, NEXT_H+10);
260 rb->lcd_putsxy(NEXT_X-5, NEXT_Y-5-f_height-1, "next");
261 #endif
263 /***********
264 ** GAMELOOP
266 rb->srand( *rb->current_tick );
268 type_cur_brick = 2 + mrand(3);
269 type_next_brick = 2 + mrand(3);
271 do {
272 end = *rb->current_tick + (cycletime * HZ) / 1000;
274 draw_brick(pos_cur_brick, type_cur_brick);
276 /* Draw next brick */
277 rb->lcd_set_drawmode(DRMODE_BG|DRMODE_INVERSEVID);
278 rb->lcd_fillrect(NEXT_X, NEXT_Y, WIDTH, WIDTH * 4 + 4);
279 rb->lcd_set_drawmode(DRMODE_SOLID);
281 for (i = 0; i < type_next_brick; ++i) {
282 rb->lcd_fillrect(NEXT_X,
283 NEXT_Y + ((type_next_brick % 2) ? (int)(WIDTH/2) : ((type_next_brick == 2) ? (WIDTH+1) : 0)) + (WIDTH*i) + i,
284 WIDTH, WIDTH);
287 /* Score box */
288 rb->lcd_putsxyf(score_x, SCORE_Y, "%8ld0", score);
290 rb->lcd_update();
292 button = rb->button_status();
294 switch(button) {
295 case ONEDROCKBLOX_DOWN:
296 case (ONEDROCKBLOX_DOWN|BUTTON_REPEAT):
297 cycletime = 100;
298 break;
299 case ONEDROCKBLOX_QUIT:
300 quit = true;
301 break;
302 default:
303 cycletime = 300;
304 if(rb->default_event_handler(button) == SYS_USB_CONNECTED) {
305 quit = true;
309 if ((pos_cur_brick + type_cur_brick) > 10) {
310 type_cur_brick = type_next_brick;
311 type_next_brick = 2 + mrand(3);
312 score += (type_cur_brick - 1) * 2;
313 pos_cur_brick = 1 - type_cur_brick;
314 } else {
315 ++pos_cur_brick;
318 if (TIME_BEFORE(*rb->current_tick, end))
319 rb->sleep(end-*rb->current_tick);
320 else
321 rb->yield();
323 } while (!quit);
325 return PLUGIN_OK;