summaryrefslogtreecommitdiff
path: root/apps/recorder/tetris.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/recorder/tetris.c')
-rw-r--r--apps/recorder/tetris.c79
1 files changed, 42 insertions, 37 deletions
diff --git a/apps/recorder/tetris.c b/apps/recorder/tetris.c
index 2455f269b3..5264b8e789 100644
--- a/apps/recorder/tetris.c
+++ b/apps/recorder/tetris.c
@@ -30,6 +30,7 @@
30#include "kernel.h" 30#include "kernel.h"
31#include <string.h> 31#include <string.h>
32#include "menu.h" 32#include "menu.h"
33#include "screens.h"
33 34
34#ifdef SIMULATOR 35#ifdef SIMULATOR
35#include <stdio.h> 36#include <stdio.h>
@@ -106,12 +107,12 @@ static const char block_data[7][4][2][4] =
106 } 107 }
107}; 108};
108 109
109int t_rand(int range) 110static int t_rand(int range)
110{ 111{
111 return current_tick % range; 112 return current_tick % range;
112} 113}
113 114
114void draw_frame(int fstart_x,int fstop_x,int fstart_y,int fstop_y) 115static void draw_frame(int fstart_x,int fstop_x,int fstart_y,int fstop_y)
115{ 116{
116 lcd_drawline(fstart_x, fstart_y, fstop_x, fstart_y); 117 lcd_drawline(fstart_x, fstart_y, fstop_x, fstart_y);
117 lcd_drawline(fstart_x, fstop_y, fstop_x, fstop_y); 118 lcd_drawline(fstart_x, fstop_y, fstop_x, fstop_y);
@@ -123,7 +124,7 @@ void draw_frame(int fstart_x,int fstop_x,int fstart_y,int fstop_y)
123 lcd_drawline(fstart_x - 1, fstop_y + 1, fstop_x - 1, fstop_y + 1); 124 lcd_drawline(fstart_x - 1, fstop_y + 1, fstop_x - 1, fstop_y + 1);
124} 125}
125 126
126void draw_block(int x, int y, int block, int frame, bool clear) 127static void draw_block(int x, int y, int block, int frame, bool clear)
127{ 128{
128 int i, a, b; 129 int i, a, b;
129 for(i=0;i < 4;i++) { 130 for(i=0;i < 4;i++) {
@@ -144,7 +145,7 @@ void draw_block(int x, int y, int block, int frame, bool clear)
144 } 145 }
145} 146}
146 147
147void to_virtual(void) 148static void to_virtual(void)
148{ 149{
149 int i,a,b; 150 int i,a,b;
150 151
@@ -156,7 +157,7 @@ void to_virtual(void)
156 current_x + block_data[current_b][current_f][1][i] * 4 - b) = current_b + 1; 157 current_x + block_data[current_b][current_f][1][i] * 4 - b) = current_b + 1;
157} 158}
158 159
159bool block_touch (int x, int y) 160static bool block_touch (int x, int y)
160{ 161{
161 int a,b; 162 int a,b;
162 for (a = 0; a < 4; a++) 163 for (a = 0; a < 4; a++)
@@ -166,7 +167,7 @@ bool block_touch (int x, int y)
166 return false; 167 return false;
167} 168}
168 169
169bool gameover(void) 170static bool gameover(void)
170{ 171{
171 int i; 172 int i;
172 int frame, block, y, x; 173 int frame, block, y, x;
@@ -191,7 +192,7 @@ bool gameover(void)
191 return false; 192 return false;
192} 193}
193 194
194bool valid_position(int x, int y, int block, int frame) 195static bool valid_position(int x, int y, int block, int frame)
195{ 196{
196 int i; 197 int i;
197 for(i=0;i < 4;i++) 198 for(i=0;i < 4;i++)
@@ -204,7 +205,7 @@ bool valid_position(int x, int y, int block, int frame)
204 return true; 205 return true;
205} 206}
206 207
207void from_virtual(void) 208static void from_virtual(void)
208{ 209{
209 int x,y; 210 int x,y;
210 for(y = 0; y < max_y; y++) 211 for(y = 0; y < max_y; y++)
@@ -215,7 +216,7 @@ void from_virtual(void)
215 lcd_clearpixel(start_x + x, start_y + y); 216 lcd_clearpixel(start_x + x, start_y + y);
216} 217}
217 218
218void move_block(int x,int y,int f) 219static void move_block(int x,int y,int f)
219{ 220{
220 int last_frame = current_f; 221 int last_frame = current_f;
221 if(f != 0) 222 if(f != 0)
@@ -239,7 +240,7 @@ void move_block(int x,int y,int f)
239 current_f = last_frame; 240 current_f = last_frame;
240} 241}
241 242
242void new_block(void) 243static void new_block(void)
243{ 244{
244 current_b = next_b; 245 current_b = next_b;
245 current_f = next_f; 246 current_f = next_f;
@@ -266,7 +267,7 @@ void new_block(void)
266 draw_block(current_x, current_y, current_b, current_f, false); 267 draw_block(current_x, current_y, current_b, current_f, false);
267} 268}
268 269
269int check_lines(void) 270static int check_lines(void)
270{ 271{
271 int x,y,i,j; 272 int x,y,i,j;
272 bool line; 273 bool line;
@@ -298,7 +299,7 @@ int check_lines(void)
298 return lines / 4; 299 return lines / 4;
299} 300}
300 301
301void move_down(void) 302static void move_down(void)
302{ 303{
303 int l; 304 int l;
304 char s[25]; 305 char s[25];
@@ -327,7 +328,7 @@ void move_down(void)
327 move_block(-4,0,0); 328 move_block(-4,0,0);
328} 329}
329 330
330void game_loop(void) 331static bool game_loop(void)
331{ 332{
332 while(1) 333 while(1)
333 { 334 {
@@ -336,28 +337,32 @@ void game_loop(void)
336 { 337 {
337 switch(button_get_w_tmo(HZ/10)) 338 switch(button_get_w_tmo(HZ/10))
338 { 339 {
339 case BUTTON_OFF: 340 case BUTTON_OFF:
340 return; 341 return false;
341 342
342 case BUTTON_UP: 343 case BUTTON_UP:
343 case BUTTON_UP | BUTTON_REPEAT: 344 case BUTTON_UP | BUTTON_REPEAT:
344 move_block(0,-3,0); 345 move_block(0,-3,0);
345 break; 346 break;
346 347
347 case BUTTON_DOWN: 348 case BUTTON_DOWN:
348 case BUTTON_DOWN | BUTTON_REPEAT: 349 case BUTTON_DOWN | BUTTON_REPEAT:
349 move_block(0,3,0); 350 move_block(0,3,0);
350 break; 351 break;
351 352
352 case BUTTON_RIGHT: 353 case BUTTON_RIGHT:
353 case BUTTON_RIGHT | BUTTON_REPEAT: 354 case BUTTON_RIGHT | BUTTON_REPEAT:
354 move_block(0,0,1); 355 move_block(0,0,1);
355 break; 356 break;
356 357
357 case BUTTON_LEFT: 358 case BUTTON_LEFT:
358 case BUTTON_LEFT | BUTTON_REPEAT: 359 case BUTTON_LEFT | BUTTON_REPEAT:
359 move_down(); 360 move_down();
360 break; 361 break;
362
363 case SYS_USB_CONNECTED:
364 usb_screen();
365 return true;
361 } 366 }
362 367
363 count++; 368 count++;
@@ -369,14 +374,16 @@ void game_loop(void)
369 lcd_putsxy (2, 52, str(LANG_TETRIS_LOSE), 0); 374 lcd_putsxy (2, 52, str(LANG_TETRIS_LOSE), 0);
370 lcd_update(); 375 lcd_update();
371 sleep(HZ * 3); 376 sleep(HZ * 3);
372 return; 377 return false;
373 } 378 }
374 379
375 move_down(); 380 move_down();
376 } 381 }
382
383 return false;
377} 384}
378 385
379void init_tetris(void) 386static void init_tetris(void)
380{ 387{
381 memset(&virtual, 0, sizeof(virtual)); 388 memset(&virtual, 0, sizeof(virtual));
382 389
@@ -391,7 +398,7 @@ void init_tetris(void)
391 next_f = 0; 398 next_f = 0;
392} 399}
393 400
394Menu tetris(void) 401bool tetris(void)
395{ 402{
396 init_tetris(); 403 init_tetris();
397 404
@@ -402,9 +409,7 @@ Menu tetris(void)
402 next_b = t_rand(blocks); 409 next_b = t_rand(blocks);
403 next_f = t_rand(block_frames[next_b]); 410 next_f = t_rand(block_frames[next_b]);
404 new_block(); 411 new_block();
405 game_loop(); 412 return game_loop();
406
407 return MENU_OK;
408} 413}
409 414
410#endif 415#endif