diff options
Diffstat (limited to 'uisimulator')
-rw-r--r-- | uisimulator/app.c | 104 | ||||
-rw-r--r-- | uisimulator/bmp.c | 584 | ||||
-rw-r--r-- | uisimulator/icons.c | 50 | ||||
-rw-r--r-- | uisimulator/icons.h | 37 | ||||
-rw-r--r-- | uisimulator/menu.c | 187 | ||||
-rw-r--r-- | uisimulator/menu.h | 51 | ||||
-rw-r--r-- | uisimulator/screensaver.c | 129 | ||||
-rw-r--r-- | uisimulator/screensaver.h | 27 | ||||
-rw-r--r-- | uisimulator/tetris.c | 362 |
9 files changed, 0 insertions, 1531 deletions
diff --git a/uisimulator/app.c b/uisimulator/app.c deleted file mode 100644 index c5149d8171..0000000000 --- a/uisimulator/app.c +++ /dev/null | |||
@@ -1,104 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 Daniel Stenberg | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #include "lcd.h" | ||
21 | #include "button.h" | ||
22 | #include "kernel.h" | ||
23 | #include "menu.h" | ||
24 | |||
25 | /* Apps to include */ | ||
26 | #include "tree.h" | ||
27 | |||
28 | #ifdef HAVE_LCD_BITMAP | ||
29 | |||
30 | /*#include "screensaver.h"*/ | ||
31 | |||
32 | /*extern void tetris(void);*/ | ||
33 | |||
34 | void app_main(void) | ||
35 | { | ||
36 | int key; | ||
37 | |||
38 | menu_init(); | ||
39 | menu_draw(); | ||
40 | put_cursor_menu_top(); | ||
41 | |||
42 | while(1) { | ||
43 | key = button_get(); | ||
44 | |||
45 | if(!key) { | ||
46 | sleep(1); | ||
47 | continue; | ||
48 | } | ||
49 | |||
50 | switch(key) { | ||
51 | case BUTTON_UP: | ||
52 | if(is_cursor_menu_top()){ | ||
53 | /* wrap around to menu bottom */ | ||
54 | put_cursor_menu_bottom(); | ||
55 | } else { | ||
56 | /* move up */ | ||
57 | move_cursor_up(); | ||
58 | } | ||
59 | break; | ||
60 | case BUTTON_DOWN: | ||
61 | if(is_cursor_menu_bottom() ){ | ||
62 | /* wrap around to menu top */ | ||
63 | put_cursor_menu_top(); | ||
64 | } else { | ||
65 | /* move down */ | ||
66 | move_cursor_down(); | ||
67 | } | ||
68 | break; | ||
69 | case BUTTON_RIGHT: | ||
70 | case BUTTON_PLAY: | ||
71 | /* Erase current display state */ | ||
72 | lcd_clear_display(); | ||
73 | |||
74 | execute_menu_item(); | ||
75 | |||
76 | /* Return to previous display state */ | ||
77 | lcd_clear_display(); | ||
78 | menu_draw(); | ||
79 | break; | ||
80 | case BUTTON_OFF: | ||
81 | return; | ||
82 | default: | ||
83 | break; | ||
84 | } | ||
85 | |||
86 | lcd_update(); | ||
87 | } | ||
88 | } | ||
89 | |||
90 | #else | ||
91 | |||
92 | void app_main(void) | ||
93 | { | ||
94 | int key; | ||
95 | int cursor = 0; | ||
96 | |||
97 | lcd_puts(0,0, "Mooo!"); | ||
98 | lcd_puts(1,1, " Rockbox!"); | ||
99 | |||
100 | browse_root(); | ||
101 | |||
102 | } | ||
103 | |||
104 | #endif | ||
diff --git a/uisimulator/bmp.c b/uisimulator/bmp.c deleted file mode 100644 index 828f855295..0000000000 --- a/uisimulator/bmp.c +++ /dev/null | |||
@@ -1,584 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Linus Nielsen Feltzing | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | /********************************************************************* | ||
20 | * | ||
21 | * Converts BMP files to Rockbox bitmap format | ||
22 | * | ||
23 | * 1999-05-03 Linus Nielsen Feltzing | ||
24 | * | ||
25 | **********************************************/ | ||
26 | |||
27 | #include <stdio.h> | ||
28 | #include <stdlib.h> | ||
29 | #include <string.h> | ||
30 | #include <stdbool.h> | ||
31 | |||
32 | #include "file.h" | ||
33 | |||
34 | #ifdef __GNUC__ | ||
35 | #define STRUCT_PACKED __attribute__((packed)) | ||
36 | #endif | ||
37 | |||
38 | struct Fileheader | ||
39 | { | ||
40 | unsigned short Type; /* signature - 'BM' */ | ||
41 | unsigned long Size; /* file size in bytes */ | ||
42 | unsigned short Reserved1; /* 0 */ | ||
43 | unsigned short Reserved2; /* 0 */ | ||
44 | unsigned long OffBits; /* offset to bitmap */ | ||
45 | unsigned long StructSize; /* size of this struct (40) */ | ||
46 | unsigned long Width; /* bmap width in pixels */ | ||
47 | unsigned long Height; /* bmap height in pixels */ | ||
48 | unsigned short Planes; /* num planes - always 1 */ | ||
49 | unsigned short BitCount; /* bits per pixel */ | ||
50 | unsigned long Compression; /* compression flag */ | ||
51 | unsigned long SizeImage; /* image size in bytes */ | ||
52 | long XPelsPerMeter; /* horz resolution */ | ||
53 | long YPelsPerMeter; /* vert resolution */ | ||
54 | unsigned long ClrUsed; /* 0 -> color table size */ | ||
55 | unsigned long ClrImportant; /* important color count */ | ||
56 | } STRUCT_PACKED; | ||
57 | |||
58 | struct RGBQUAD | ||
59 | { | ||
60 | unsigned char rgbBlue; | ||
61 | unsigned char rgbGreen; | ||
62 | unsigned char rgbRed; | ||
63 | unsigned char rgbReserved; | ||
64 | } STRUCT_PACKED; | ||
65 | |||
66 | static struct Fileheader fh; | ||
67 | static unsigned char* bmp; | ||
68 | static struct RGBQUAD palette[2]; /* two colors only */ | ||
69 | |||
70 | static unsigned int bitmap_width, bitmap_height; | ||
71 | static unsigned char *bitmap; | ||
72 | |||
73 | #ifdef STANDALONE | ||
74 | static id_str[256]; | ||
75 | static bool compress = false; | ||
76 | static bool assembly = false; | ||
77 | static unsigned char* converted_bmp; | ||
78 | static unsigned char* compressed_bmp; | ||
79 | static unsigned int width; | ||
80 | static unsigned int converted_size; | ||
81 | static unsigned int compressed_size; | ||
82 | static unsigned int rounded_width; | ||
83 | #endif | ||
84 | |||
85 | #ifdef LITTLE_ENDIAN | ||
86 | #define readshort(x) x | ||
87 | #define readlong(x) x | ||
88 | #else | ||
89 | |||
90 | #define readshort(x) (((x&0xff00)>>8)|((x&0x00ff)<<8)) | ||
91 | #define readlong(x) (((x&0xff000000)>>24)| \ | ||
92 | ((x&0x00ff0000)>>8) | \ | ||
93 | ((x&0x0000ff00)<<8) | \ | ||
94 | ((x&0x000000ff)<<24)) | ||
95 | #endif | ||
96 | |||
97 | /********************************************************************* | ||
98 | * read_bmp_file() | ||
99 | * | ||
100 | * Reads a monochrome BMP file and puts the data in a 1-pixel-per-byte | ||
101 | * array. Returns 0 on success. | ||
102 | * | ||
103 | **********************************************/ | ||
104 | int read_bmp_file(char* filename, | ||
105 | int *get_width, /* in pixels */ | ||
106 | int *get_height, /* in pixels */ | ||
107 | char *bitmap) | ||
108 | { | ||
109 | long PaddedWidth; | ||
110 | int background; | ||
111 | int fd = open(filename, O_RDONLY); | ||
112 | long size; | ||
113 | unsigned int row, col, byte, bit; | ||
114 | int l; | ||
115 | unsigned char *bmp; | ||
116 | int width; | ||
117 | int height; | ||
118 | |||
119 | if(fd == -1) | ||
120 | { | ||
121 | debugf("error - can't open '%s'\n", filename); | ||
122 | return 1; | ||
123 | } | ||
124 | else | ||
125 | { | ||
126 | if(read(fd, &fh, sizeof(struct Fileheader)) != | ||
127 | sizeof(struct Fileheader)) | ||
128 | { | ||
129 | debugf("error - can't Read Fileheader Stucture\n"); | ||
130 | close(fd); | ||
131 | return 2; | ||
132 | } | ||
133 | |||
134 | /* Exit if not monochrome */ | ||
135 | if(readshort(fh.BitCount) > 8) | ||
136 | { | ||
137 | debugf("error - Bitmap must be less than 8, got %d\n", | ||
138 | readshort(fh.BitCount)); | ||
139 | close(fd); | ||
140 | return 2; | ||
141 | } | ||
142 | |||
143 | /* Exit if too wide */ | ||
144 | if(readlong(fh.Width) > 112) | ||
145 | { | ||
146 | debugf("error - Bitmap is too wide (%d pixels, max is 112)\n", | ||
147 | readlong(fh.Width)); | ||
148 | close(fd); | ||
149 | return 3; | ||
150 | } | ||
151 | debugf("Bitmap is %d pixels wide\n", readlong(fh.Width)); | ||
152 | |||
153 | /* Exit if too high */ | ||
154 | if(readlong(fh.Height) > 64) | ||
155 | { | ||
156 | debugf("error - Bitmap is too high (%d pixels, max is 64)\n", | ||
157 | readlong(fh.Height)); | ||
158 | close(fd); | ||
159 | return 4; | ||
160 | } | ||
161 | debugf("Bitmap is %d pixels heigh\n", readlong(fh.Height)); | ||
162 | |||
163 | for(l=0;l < 2;l++) | ||
164 | { | ||
165 | if(read(fd, &palette[l],sizeof(struct RGBQUAD)) != | ||
166 | sizeof(struct RGBQUAD)) | ||
167 | { | ||
168 | debugf("error - Can't read bitmap's color palette\n"); | ||
169 | close(fd); | ||
170 | return 5; | ||
171 | } | ||
172 | } | ||
173 | /* pass the other palettes */ | ||
174 | lseek(fd, 254*sizeof(struct RGBQUAD), SEEK_CUR); | ||
175 | |||
176 | /* Try to guess the foreground and background colors. | ||
177 | We assume that the foreground color is the darkest. */ | ||
178 | if(((int)palette[0].rgbRed + | ||
179 | (int)palette[0].rgbGreen + | ||
180 | (int)palette[0].rgbBlue) > | ||
181 | ((int)palette[1].rgbRed + | ||
182 | (int)palette[1].rgbGreen + | ||
183 | (int)palette[1].rgbBlue)) | ||
184 | { | ||
185 | background = 0; | ||
186 | } | ||
187 | else | ||
188 | { | ||
189 | background = 1; | ||
190 | } | ||
191 | |||
192 | /* width = readlong(fh.Width)*readshort(fh.BitCount); */ | ||
193 | |||
194 | width = readlong(fh.Width); | ||
195 | |||
196 | /* PaddedWidth = ((width+31)&(~0x1f))/8; */ | ||
197 | PaddedWidth = ((width+7)&(~0x7)); | ||
198 | size = PaddedWidth*readlong(fh.Height); | ||
199 | |||
200 | bmp = (unsigned char *)malloc(size); | ||
201 | |||
202 | if(bmp == NULL) | ||
203 | { | ||
204 | debugf("error - Out of memory\n"); | ||
205 | close(fd); | ||
206 | return 6; | ||
207 | } | ||
208 | else | ||
209 | { | ||
210 | if(read(fd, (unsigned char*)bmp,(long)size) != size) { | ||
211 | debugf("error - Can't read image\n"); | ||
212 | close(fd); | ||
213 | return 7; | ||
214 | } | ||
215 | } | ||
216 | |||
217 | bitmap_height = readlong(fh.Height); | ||
218 | bitmap_width = readlong(fh.Width); | ||
219 | |||
220 | *get_width = bitmap_width; | ||
221 | *get_height = bitmap_height; | ||
222 | |||
223 | #if 0 | ||
224 | /* Now convert the bitmap into an array with 1 byte per pixel, | ||
225 | exactly the size of the image */ | ||
226 | for(row = 0;row < bitmap_height;row++) { | ||
227 | bit = 7; | ||
228 | byte = 0; | ||
229 | for(col = 0;col < bitmap_width;col++) { | ||
230 | if((bmp[(bitmap_height - row - 1) * PaddedWidth + byte] & | ||
231 | (1 << bit))) { | ||
232 | |||
233 | bitmap[ (row/8) * bitmap_width + col ] |= 1<<(row&7); | ||
234 | } | ||
235 | else { | ||
236 | bitmap[ (row/8) * bitmap_width + col ] &= ~ 1<<(row&7); | ||
237 | } | ||
238 | if(bit) { | ||
239 | bit--; | ||
240 | } | ||
241 | else { | ||
242 | bit = 7; | ||
243 | byte++; | ||
244 | } | ||
245 | } | ||
246 | } | ||
247 | #else | ||
248 | /* Now convert the bitmap into an array with 1 byte per pixel, | ||
249 | exactly the size of the image */ | ||
250 | |||
251 | for(row = 0;row < bitmap_height;row++) { | ||
252 | for(col = 0;col < bitmap_width;col++) { | ||
253 | if(bmp[(bitmap_height-1 -row) * PaddedWidth + col]) { | ||
254 | bitmap[ (row/8) * bitmap_width + col ] &= ~ (1<<(row&7)); | ||
255 | } | ||
256 | else { | ||
257 | bitmap[ (row/8) * bitmap_width + col ] |= 1<<(row&7); | ||
258 | } | ||
259 | } | ||
260 | } | ||
261 | |||
262 | #endif | ||
263 | } | ||
264 | close(fd); | ||
265 | return 0; /* success */ | ||
266 | } | ||
267 | |||
268 | #ifdef STANDALONE | ||
269 | |||
270 | /********************************************************************* | ||
271 | ** read_next_converted_byte() | ||
272 | ** | ||
273 | ** Reads the next 6-pixel chunk from the 1-byte-per-pixel array, | ||
274 | ** padding the last byte with zeros if the size is not divisible by 6. | ||
275 | **********************************************/ | ||
276 | unsigned char read_next_converted_byte(void) | ||
277 | { | ||
278 | unsigned char dest; | ||
279 | unsigned int i; | ||
280 | static unsigned int row = 0, col = 0; | ||
281 | |||
282 | dest = 0; | ||
283 | for(i = 0;i < 6 && col < bitmap_width;i++,col++) | ||
284 | { | ||
285 | if(bitmap[row * bitmap_width + col]) | ||
286 | { | ||
287 | dest |= (unsigned char)(1 << (5-i)); | ||
288 | } | ||
289 | } | ||
290 | |||
291 | if(col >= bitmap_width) | ||
292 | { | ||
293 | col = 0; | ||
294 | row++; | ||
295 | } | ||
296 | |||
297 | return dest; | ||
298 | } | ||
299 | |||
300 | /********************************************************************* | ||
301 | ** convert_image() | ||
302 | ** | ||
303 | ** Converts the 1-byte-per-pixel array into a 6-pixel-per-byte array, | ||
304 | ** i.e the BMP_FORMAT_VANILLA format. | ||
305 | **********************************************/ | ||
306 | void convert_image(void) | ||
307 | { | ||
308 | int newsize; | ||
309 | unsigned int row, col; | ||
310 | |||
311 | rounded_width = fh.Width/6 + ((fh.Width%6)?1:0); | ||
312 | newsize = rounded_width * fh.Height; | ||
313 | |||
314 | converted_bmp = (unsigned char *)malloc(newsize); | ||
315 | |||
316 | for(row = 0;row < fh.Height;row++) | ||
317 | { | ||
318 | for(col = 0;col < rounded_width;col++) | ||
319 | { | ||
320 | converted_bmp[row * rounded_width + col] = read_next_converted_byte(); | ||
321 | } | ||
322 | } | ||
323 | converted_size = rounded_width * fh.Height; | ||
324 | } | ||
325 | |||
326 | #define COMPRESSED_ZEROS_AHEAD 0x40 | ||
327 | #define COMPRESSED_ONES_AHEAD 0x80 | ||
328 | |||
329 | /********************************************************************* | ||
330 | ** compress_image() | ||
331 | ** | ||
332 | ** Compresses the BMP_FORMAT_VANILLA format with a simple RLE | ||
333 | ** algorithm. The output is in the BMP_FORMAT_RLE format. | ||
334 | **********************************************/ | ||
335 | void compress_image(void) | ||
336 | { | ||
337 | unsigned int i, j, count; | ||
338 | unsigned int index = 0; | ||
339 | unsigned char val; | ||
340 | |||
341 | compressed_bmp = (unsigned char *)malloc(converted_size); | ||
342 | |||
343 | for(i = 0;i < converted_size;i++) | ||
344 | { | ||
345 | val = converted_bmp[i]; | ||
346 | |||
347 | if(val == 0|| val == 0x3f) | ||
348 | { | ||
349 | count = 0; | ||
350 | while(count < 0x4000 && (i + count) < converted_size && | ||
351 | converted_bmp[i+count] == val) | ||
352 | { | ||
353 | count++; | ||
354 | } | ||
355 | if(count > 2) | ||
356 | { | ||
357 | compressed_bmp[index++] = (unsigned char) | ||
358 | (((val == 0)?COMPRESSED_ZEROS_AHEAD:COMPRESSED_ONES_AHEAD) | | ||
359 | (count >> 8)); | ||
360 | compressed_bmp[index++] = (unsigned char)(count & 0xff); | ||
361 | } | ||
362 | else | ||
363 | { | ||
364 | for(j = 0;j < count;j++) | ||
365 | { | ||
366 | compressed_bmp[index++] = val; | ||
367 | } | ||
368 | } | ||
369 | i += count - 1; | ||
370 | } | ||
371 | else | ||
372 | { | ||
373 | compressed_bmp[index++] = val; | ||
374 | } | ||
375 | } | ||
376 | |||
377 | compressed_size = index; | ||
378 | } | ||
379 | |||
380 | /********************************************************************* | ||
381 | ** generate_c_source() | ||
382 | ** | ||
383 | ** Outputs a C source code with the converted/compressed bitmap in | ||
384 | ** an array, accompanied by some #define's | ||
385 | **********************************************/ | ||
386 | void generate_c_source(char *id, BOOL compressed) | ||
387 | { | ||
388 | FILE *f; | ||
389 | unsigned int i; | ||
390 | unsigned int size; | ||
391 | unsigned char *bmp; | ||
392 | |||
393 | size = compressed?compressed_size:converted_size; | ||
394 | bmp = compressed?compressed_bmp:converted_bmp; | ||
395 | |||
396 | f = stdout; | ||
397 | |||
398 | fprintf(f, "#define %s_WIDTH %d\n", id, rounded_width * 6); | ||
399 | fprintf(f, "#define %s_HEIGHT %d\n", id, fh.Height); | ||
400 | fprintf(f, "#define %s_SIZE %d\n", id, size + 6); | ||
401 | if(compressed) | ||
402 | { | ||
403 | fprintf(f, "#define %s_ORIGINAL_SIZE %d\n", id, converted_size); | ||
404 | } | ||
405 | fprintf(f, "#define %s_FORMAT %s\n", id, | ||
406 | compressed?"BMP_FORMAT_RLE":"BMP_FORMAT_VANILLA"); | ||
407 | fprintf(f, "\nconst unsigned char bmpdata_%s[] = {", id); | ||
408 | |||
409 | /* Header */ | ||
410 | fprintf(f, "\n %s, 0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,", | ||
411 | compressed?"BMP_FORMAT_RLE":"BMP_FORMAT_VANILLA", | ||
412 | size >> 8, size & 0xff, 2, fh.Height, rounded_width * 6); | ||
413 | |||
414 | for(i = 0;i < size;i++) | ||
415 | { | ||
416 | if(i % 10 == 0) | ||
417 | { | ||
418 | fprintf(f, "\n "); | ||
419 | } | ||
420 | fprintf(f, "0x%02x,", bmp[i]); | ||
421 | } | ||
422 | fprintf(f, "\n};"); | ||
423 | } | ||
424 | |||
425 | /********************************************************************* | ||
426 | ** generate_asm_source() | ||
427 | ** | ||
428 | ** Outputs an ASM source code with the converted/compressed bitmap in | ||
429 | ** an array, the first 2 bytes describing the X and Y size | ||
430 | **********************************************/ | ||
431 | void generate_asm_source(char *id, BOOL compressed) | ||
432 | { | ||
433 | FILE *f; | ||
434 | unsigned int i; | ||
435 | unsigned int size; | ||
436 | unsigned char *bmp; | ||
437 | |||
438 | size = compressed?compressed_size:converted_size; | ||
439 | bmp = compressed?compressed_bmp:converted_bmp; | ||
440 | |||
441 | f = stdout; | ||
442 | |||
443 | fprintf(f, "bmpdata_%s:\n", id); | ||
444 | /* Header */ | ||
445 | fprintf(f, "\n db %s, %.2xh,%.2xh,%.2xh,%.2xh,%.2xh,", | ||
446 | compressed?"1":"0", | ||
447 | size >> 8, size & 0xff, 2, fh.Height, rounded_width * 6); | ||
448 | |||
449 | for(i = 0;i < size;i++) | ||
450 | { | ||
451 | if(i % 10 == 0) | ||
452 | { | ||
453 | fprintf(f, "\n db "); | ||
454 | } | ||
455 | fprintf(f, "%.2xh,", bmp[i]); | ||
456 | } | ||
457 | fprintf(f, "\n"); | ||
458 | } | ||
459 | |||
460 | void print_usage(void) | ||
461 | { | ||
462 | printf("bmp2mt - Converts BMP files to MT Pro source code format\n"); | ||
463 | printf("build date: " __DATE__ "\n\n"); | ||
464 | printf("Usage: %s [-i <id>] [-c] [-a] <bitmap file>\n" | ||
465 | "-i <id> Bitmap ID (default is filename without extension)\n" | ||
466 | "-c Compress (BMP_FORMAT_RLE)\n" | ||
467 | "-f Frexx Format!!!\n" | ||
468 | "-a Assembly format source code\n", APPLICATION_NAME); | ||
469 | } | ||
470 | |||
471 | #pragma argsused | ||
472 | int main(int argc, char **argv) | ||
473 | { | ||
474 | char *bmp_filename = NULL; | ||
475 | char *id = NULL; | ||
476 | char errstr[80]; | ||
477 | int i; | ||
478 | |||
479 | for(i = 1;i < argc;i++) | ||
480 | { | ||
481 | if(argv[i][0] == '-') | ||
482 | { | ||
483 | switch(argv[i][1]) | ||
484 | { | ||
485 | case 'i': /* ID */ | ||
486 | if(argv[i][2]) | ||
487 | { | ||
488 | id = &argv[i][2]; | ||
489 | } | ||
490 | else if(argc > i+1) | ||
491 | { | ||
492 | id = argv[i+1]; | ||
493 | i++; | ||
494 | } | ||
495 | else | ||
496 | { | ||
497 | print_usage(); | ||
498 | exit(1); | ||
499 | } | ||
500 | break; | ||
501 | |||
502 | case 'c': /* Compressed */ | ||
503 | compress = true; | ||
504 | break; | ||
505 | |||
506 | case 'a': /* Assembly */ | ||
507 | assembly = true; | ||
508 | break; | ||
509 | |||
510 | default: | ||
511 | print_usage(); | ||
512 | exit(1); | ||
513 | break; | ||
514 | } | ||
515 | } | ||
516 | else | ||
517 | { | ||
518 | if(!bmp_filename) | ||
519 | { | ||
520 | bmp_filename = argv[i]; | ||
521 | } | ||
522 | else | ||
523 | { | ||
524 | print_usage(); | ||
525 | exit(1); | ||
526 | } | ||
527 | } | ||
528 | } | ||
529 | |||
530 | if(!bmp_filename) | ||
531 | { | ||
532 | print_usage(); | ||
533 | exit(1); | ||
534 | } | ||
535 | |||
536 | if(!id) | ||
537 | { | ||
538 | id = strdup(bmp_filename); | ||
539 | |||
540 | for(i = 0;id[i];i++) | ||
541 | { | ||
542 | if(id[i] == ' ') | ||
543 | { | ||
544 | id[i] = '_'; | ||
545 | } | ||
546 | else if(id[i] == '.') | ||
547 | { | ||
548 | id[i] = '\0'; | ||
549 | break; | ||
550 | } | ||
551 | else | ||
552 | { | ||
553 | id[i] = (char)toupper(id[i]); | ||
554 | } | ||
555 | } | ||
556 | } | ||
557 | |||
558 | read_bmp_file(bmp_filename); | ||
559 | convert_image(); | ||
560 | if(fh.Width % 6) | ||
561 | { | ||
562 | |||
563 | sprintf(errstr, "warning - width is not divisible by 6 (%d), " | ||
564 | "padding with zeros to %d\n", fh.Width, rounded_width*6); | ||
565 | print_error(errstr, 0); | ||
566 | } | ||
567 | |||
568 | if(compress) | ||
569 | { | ||
570 | compress_image(); | ||
571 | } | ||
572 | |||
573 | if(assembly) | ||
574 | { | ||
575 | generate_asm_source(id, compress); | ||
576 | } | ||
577 | else | ||
578 | { | ||
579 | generate_c_source(id, compress); | ||
580 | } | ||
581 | return 0; | ||
582 | } | ||
583 | |||
584 | #endif | ||
diff --git a/uisimulator/icons.c b/uisimulator/icons.c deleted file mode 100644 index 6627c7d06e..0000000000 --- a/uisimulator/icons.c +++ /dev/null | |||
@@ -1,50 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 Robert E. Hak | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #include <lcd.h> | ||
20 | |||
21 | #include "icons.h" | ||
22 | |||
23 | #ifdef HAVE_LCD_BITMAP | ||
24 | |||
25 | unsigned char bitmap_icons_6x8[LastIcon][6] = | ||
26 | { | ||
27 | /* Box_Filled */ | ||
28 | { 0x00, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f }, | ||
29 | /* Box_Empty */ | ||
30 | { 0x00, 0x7f, 0x41, 0x41, 0x41, 0x7f }, | ||
31 | /* Slider_Horizontal */ | ||
32 | { 0x00, 0x3e, 0x7f, 0x63, 0x7f, 0x3e }, | ||
33 | /* File */ | ||
34 | { 0x60, 0x7f, 0x03, 0x63, 0x7f, 0x00 }, | ||
35 | /* Folder */ | ||
36 | { 0x00, 0x7e, 0x41, 0x41, 0x42, 0x7e }, | ||
37 | /* Directory */ | ||
38 | { 0x3e, 0x26, 0x26, 0x24, 0x3c, 0x00 }, | ||
39 | /* Playlist */ | ||
40 | { 0x55, 0x00, 0x55, 0x55, 0x55, 0x00 }, | ||
41 | /* Repeat */ | ||
42 | { 0x39, 0x43, 0x47, 0x71, 0x61, 0x4e }, | ||
43 | /* Selected */ | ||
44 | { 0x00, 0x1c, 0x3e, 0x3e, 0x3e, 0x1c }, | ||
45 | /* Selector */ | ||
46 | { 0x00, 0x7f, 0x3e, 0x1c, 0x08, 0x00 }, | ||
47 | }; | ||
48 | |||
49 | |||
50 | #endif | ||
diff --git a/uisimulator/icons.h b/uisimulator/icons.h deleted file mode 100644 index 08e4a7e1e8..0000000000 --- a/uisimulator/icons.h +++ /dev/null | |||
@@ -1,37 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 Robert E. Hak | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #include <lcd.h> | ||
20 | |||
21 | /* | ||
22 | * Icons of size 6x8 pixels | ||
23 | */ | ||
24 | |||
25 | #ifdef HAVE_LCD_BITMAP | ||
26 | |||
27 | enum icons_6x8 { | ||
28 | Box_Filled, Box_Empty, Slider_Horizontal, File, | ||
29 | Folder, Directory, Playlist, Repeat, | ||
30 | Selected, Selector, LastIcon | ||
31 | }; | ||
32 | |||
33 | extern unsigned char bitmap_icons_6x8[LastIcon][6]; | ||
34 | extern icons_6x8; | ||
35 | |||
36 | #endif /* End HAVE_LCD_BITMAP */ | ||
37 | |||
diff --git a/uisimulator/menu.c b/uisimulator/menu.c deleted file mode 100644 index 5c8356c93a..0000000000 --- a/uisimulator/menu.c +++ /dev/null | |||
@@ -1,187 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 Robert E. Hak | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #include "lcd.h" | ||
21 | #include "menu.h" | ||
22 | |||
23 | #include "tree.h" | ||
24 | |||
25 | #ifdef HAVE_LCD_BITMAP | ||
26 | |||
27 | #include "screensaver.h" | ||
28 | extern void tetris(void); | ||
29 | |||
30 | |||
31 | #define MENU_ITEM_FONT 0 | ||
32 | #define MENU_ITEM_Y_LOC 6 | ||
33 | #define MENU_LINE_HEIGHT 8 | ||
34 | |||
35 | enum Main_Menu_Ids { | ||
36 | Tetris, Screen_Saver, Browse, Last_Id | ||
37 | }; | ||
38 | |||
39 | struct main_menu_items items[] = { | ||
40 | { Tetris, "Tetris", tetris }, | ||
41 | { Screen_Saver, "Screen Saver", screensaver }, | ||
42 | { Browse, "Browse", browse_root }, | ||
43 | }; | ||
44 | |||
45 | /* Global values for menuing */ | ||
46 | int menu_top; | ||
47 | int menu_bottom; | ||
48 | int menu_line_height; | ||
49 | int cursor; | ||
50 | |||
51 | int get_line_height(void) | ||
52 | { | ||
53 | return menu_line_height; | ||
54 | } | ||
55 | |||
56 | int is_cursor_menu_top(void) | ||
57 | { | ||
58 | return ((cursor == menu_top) ? 1 : 0); | ||
59 | } | ||
60 | |||
61 | int is_cursor_menu_bottom(void) | ||
62 | { | ||
63 | return ((cursor == menu_bottom) ? 1 : 0); | ||
64 | } | ||
65 | |||
66 | void put_cursor_menu_top(void) | ||
67 | { | ||
68 | put_cursor(menu_top); | ||
69 | } | ||
70 | |||
71 | void put_cursor_menu_bottom(void) | ||
72 | { | ||
73 | put_cursor(menu_bottom); | ||
74 | } | ||
75 | |||
76 | void move_cursor_up(void) | ||
77 | { | ||
78 | put_cursor(cursor-1); | ||
79 | } | ||
80 | |||
81 | void move_cursor_down(void) | ||
82 | { | ||
83 | put_cursor(cursor+1); | ||
84 | } | ||
85 | |||
86 | void redraw_cursor(void) | ||
87 | { | ||
88 | lcd_putsxy(0, cursor*menu_line_height, "-", 0); | ||
89 | } | ||
90 | |||
91 | /* | ||
92 | * Move the cursor to a particular id, | ||
93 | * current: where it is now | ||
94 | * target: where you want it to be | ||
95 | */ | ||
96 | void put_cursor(int target) | ||
97 | { | ||
98 | lcd_putsxy(0, cursor*menu_line_height, " ",0); | ||
99 | cursor = target; | ||
100 | lcd_putsxy(0, cursor*menu_line_height, "-",0); | ||
101 | } | ||
102 | |||
103 | /* We call the function pointer related to the current cursor position */ | ||
104 | void execute_menu_item(void) | ||
105 | { | ||
106 | /* call the proper function for this line */ | ||
107 | items[cursor].function(); | ||
108 | } | ||
109 | |||
110 | void add_menu_item(int location, char *string) | ||
111 | { | ||
112 | lcd_putsxy(MENU_ITEM_Y_LOC, MENU_LINE_HEIGHT*location, string, | ||
113 | MENU_ITEM_FONT); | ||
114 | if (location < menu_top) | ||
115 | menu_top = location; | ||
116 | if (location > menu_bottom) | ||
117 | menu_bottom = location; | ||
118 | } | ||
119 | |||
120 | void show_logo(void) | ||
121 | { | ||
122 | unsigned char buffer[112 * 8]; | ||
123 | |||
124 | int failure; | ||
125 | int width=0; | ||
126 | int height=0; | ||
127 | |||
128 | failure = read_bmp_file("/rockbox112.bmp", &width, &height, buffer); | ||
129 | |||
130 | debugf("read_bmp_file() returned %d, width %d height %d\n", | ||
131 | failure, width, height); | ||
132 | |||
133 | if(!failure) { | ||
134 | int i; | ||
135 | int eline; | ||
136 | for(i=0, eline=0; i< height; i+=8, eline++) { | ||
137 | int x,y; | ||
138 | |||
139 | /* the bitmap function doesn't work with full-height bitmaps | ||
140 | so we "stripe" the logo output */ | ||
141 | |||
142 | lcd_bitmap(&buffer[eline*width], 0, 24+i, width, | ||
143 | (height-i)>8?8:height-i, false); | ||
144 | |||
145 | #if 0 | ||
146 | /* for screen output debugging */ | ||
147 | for(y=0; y<8 && (i+y < height); y++) { | ||
148 | for(x=0; x < width; x++) { | ||
149 | |||
150 | if(buffer[eline*width + x] & (1<<y)) { | ||
151 | printf("*"); | ||
152 | } | ||
153 | else | ||
154 | printf(" "); | ||
155 | } | ||
156 | printf("\n"); | ||
157 | } | ||
158 | #endif | ||
159 | } | ||
160 | |||
161 | lcd_update(); | ||
162 | } | ||
163 | |||
164 | } | ||
165 | |||
166 | void menu_init(void) | ||
167 | { | ||
168 | menu_top = Tetris; | ||
169 | menu_bottom = Last_Id-1; | ||
170 | menu_line_height = MENU_LINE_HEIGHT; | ||
171 | cursor = menu_top; | ||
172 | } | ||
173 | |||
174 | void menu_draw(void) | ||
175 | { | ||
176 | int i = 0; | ||
177 | |||
178 | for (i = i; i < Last_Id; i++) | ||
179 | add_menu_item(items[i].menu_id, (char *) items[i].menu_desc); | ||
180 | |||
181 | show_logo(); | ||
182 | redraw_cursor(); | ||
183 | } | ||
184 | |||
185 | #endif /* end HAVE_LCD_BITMAP */ | ||
186 | |||
187 | |||
diff --git a/uisimulator/menu.h b/uisimulator/menu.h deleted file mode 100644 index 1e3075f7de..0000000000 --- a/uisimulator/menu.h +++ /dev/null | |||
@@ -1,51 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 Robert E. Hak | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #ifndef __MENU_H__ | ||
21 | #define __MENU_H__ | ||
22 | |||
23 | struct main_menu_items { | ||
24 | int menu_id; | ||
25 | const char *menu_desc; | ||
26 | void (*function) (void); | ||
27 | }; | ||
28 | |||
29 | int get_line_height(void); | ||
30 | |||
31 | /* Cursor calls */ | ||
32 | void put_cursor(int target); | ||
33 | void put_cursor_menu_top(void); | ||
34 | void put_cursor_menu_bottom(void); | ||
35 | void move_cursor_up(void); | ||
36 | void move_cursor_down(void); | ||
37 | int is_cursor_menu_top(void); | ||
38 | int is_cursor_menu_bottom(void); | ||
39 | |||
40 | /* Menu calls */ | ||
41 | void add_menu_item(int location, char *string); | ||
42 | void menu_init(void); | ||
43 | void menu_draw(void); | ||
44 | void execute_menu_item(void); | ||
45 | |||
46 | #endif /* End __MENU_H__ */ | ||
47 | |||
48 | |||
49 | |||
50 | |||
51 | |||
diff --git a/uisimulator/screensaver.c b/uisimulator/screensaver.c deleted file mode 100644 index b8144478e2..0000000000 --- a/uisimulator/screensaver.c +++ /dev/null | |||
@@ -1,129 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 Robert E. Hak (rhak at ramapo.edu) | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #ifdef HAVE_LCD_BITMAP | ||
21 | |||
22 | #include "screensaver.h" | ||
23 | #include "lcd.h" | ||
24 | #include "button.h" | ||
25 | #include "kernel.h" | ||
26 | |||
27 | #ifdef SIMULATOR | ||
28 | #include <stdio.h> | ||
29 | #include <string.h> | ||
30 | #endif | ||
31 | |||
32 | #define SS_TITLE "Boxes" | ||
33 | #define SS_TITLE_FONT 2 | ||
34 | |||
35 | void ss_loop(void) | ||
36 | { | ||
37 | int b; | ||
38 | int x2 = LCD_WIDTH/2; | ||
39 | int y2 = LCD_HEIGHT/2; | ||
40 | int x = LCD_WIDTH/2; | ||
41 | int y = LCD_HEIGHT/2; | ||
42 | int i = 0; | ||
43 | int center = 0; | ||
44 | int factor = 0; | ||
45 | int offset = 0; | ||
46 | |||
47 | if (LCD_HEIGHT < LCD_WIDTH) | ||
48 | center = LCD_HEIGHT/2; | ||
49 | else | ||
50 | center = LCD_WIDTH/2; | ||
51 | |||
52 | i = center+1; | ||
53 | while(1) | ||
54 | { | ||
55 | /* Grow */ | ||
56 | if ( i < 0 ) { | ||
57 | factor = 1; | ||
58 | i = 1; | ||
59 | } | ||
60 | |||
61 | /* Shrink */ | ||
62 | if (i >= center) { | ||
63 | factor = -1; | ||
64 | i = center; | ||
65 | } | ||
66 | |||
67 | offset=i*factor; | ||
68 | |||
69 | b = button_get(); | ||
70 | if ( b & BUTTON_OFF ) | ||
71 | return; | ||
72 | |||
73 | lcd_clear_display(); | ||
74 | lcd_drawrect(x-offset, y-offset, x2+offset, y2+offset); | ||
75 | lcd_update(); | ||
76 | |||
77 | i+=factor; | ||
78 | |||
79 | sleep(10); | ||
80 | } | ||
81 | } | ||
82 | |||
83 | |||
84 | void screensaver(void) | ||
85 | { | ||
86 | int w, h; | ||
87 | char *off = "[Off] to stop"; | ||
88 | int len = strlen(SS_TITLE); | ||
89 | |||
90 | lcd_getfontsize(SS_TITLE_FONT, &w, &h); | ||
91 | |||
92 | /* Get horizontel centering for text */ | ||
93 | len *= w; | ||
94 | if (len%2 != 0) | ||
95 | len = ((len+1)/2)+(w/2); | ||
96 | else | ||
97 | len /= 2; | ||
98 | |||
99 | if (h%2 != 0) | ||
100 | h = (h/2)+1; | ||
101 | else | ||
102 | h /= 2; | ||
103 | |||
104 | lcd_clear_display(); | ||
105 | lcd_putsxy(LCD_WIDTH/2-len, (LCD_HEIGHT/2)-h, SS_TITLE, SS_TITLE_FONT); | ||
106 | |||
107 | len = strlen(off); | ||
108 | lcd_getfontsize(0, &w, &h); | ||
109 | |||
110 | /* Get horizontel centering for text */ | ||
111 | len *= w; | ||
112 | if (len%2 != 0) | ||
113 | len = ((len+1)/2)+(w/2); | ||
114 | else | ||
115 | len /= 2; | ||
116 | |||
117 | if (h%2 != 0) | ||
118 | h = (h/2)+1; | ||
119 | else | ||
120 | h /= 2; | ||
121 | |||
122 | lcd_putsxy(LCD_WIDTH/2-len, LCD_HEIGHT-(2*h), off,0); | ||
123 | |||
124 | lcd_update(); | ||
125 | sleep(150); | ||
126 | ss_loop(); | ||
127 | } | ||
128 | |||
129 | #endif | ||
diff --git a/uisimulator/screensaver.h b/uisimulator/screensaver.h deleted file mode 100644 index 5c67b83b56..0000000000 --- a/uisimulator/screensaver.h +++ /dev/null | |||
@@ -1,27 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 Robert E. Hak | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #ifndef __SCREEN_SAVER_H__ | ||
21 | #define __SCREEN_SAVER_H__ | ||
22 | |||
23 | void ss_loop(void); | ||
24 | void screensaver(void); | ||
25 | |||
26 | #endif /*__SCREEN_SAVER_H__ */ | ||
27 | |||
diff --git a/uisimulator/tetris.c b/uisimulator/tetris.c deleted file mode 100644 index 24090eb67e..0000000000 --- a/uisimulator/tetris.c +++ /dev/null | |||
@@ -1,362 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 1999 Mattis Wadman (nappe@sudac.org) | ||
11 | * | ||
12 | * Heavily modified for embedded use by Björn Stenberg (bjorn@haxx.se) | ||
13 | * | ||
14 | * All files in this archive are subject to the GNU General Public License. | ||
15 | * See the file COPYING in the source tree root for full license agreement. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #ifdef HAVE_LCD_BITMAP | ||
23 | #include <stdbool.h> | ||
24 | #include "lcd.h" | ||
25 | #include "button.h" | ||
26 | #include "kernel.h" | ||
27 | |||
28 | #ifdef SIMULATOR | ||
29 | #include <stdio.h> | ||
30 | #endif | ||
31 | |||
32 | #define TETRIS_TITLE "Tetris!" | ||
33 | #define TETRIS_TITLE_FONT 2 | ||
34 | #define TETRIS_TITLE_XLOC 10 | ||
35 | #define TETRIS_TITLE_YLOC 32 | ||
36 | |||
37 | int start_x = 1; | ||
38 | int start_y = 1; | ||
39 | int max_x = 14; | ||
40 | int max_y = 24; | ||
41 | int current_x = 0; | ||
42 | int current_y = 0; | ||
43 | int current_f = 0; | ||
44 | int current_b = 0; | ||
45 | int level = 0; | ||
46 | short lines = 0; | ||
47 | int score = 0; | ||
48 | int next_b = 0; | ||
49 | int next_f = 0; | ||
50 | char virtual[LCD_WIDTH*LCD_HEIGHT]; | ||
51 | short level_speeds[10] = {1000,900,800,700,600,500,400,300,250,200}; | ||
52 | int blocks = 7; | ||
53 | int block_frames[7] = {1,2,2,2,4,4,4}; | ||
54 | |||
55 | /* | ||
56 | block_data is built up the following way | ||
57 | |||
58 | first array index specifies the block number | ||
59 | second array index specifies the rotation of the block | ||
60 | third array index specifies: | ||
61 | 0: x-coordinates of pixels | ||
62 | 1: y-coordinates of pixels | ||
63 | fourth array index specifies the coordinate of a pixel | ||
64 | |||
65 | each block consists of four pixels whose relative coordinates are given | ||
66 | with block_data | ||
67 | */ | ||
68 | |||
69 | int block_data[7][4][2][4] = | ||
70 | { | ||
71 | { | ||
72 | {{0,1,0,1},{0,0,1,1}} | ||
73 | }, | ||
74 | { | ||
75 | {{0,1,1,2},{1,1,0,0}}, | ||
76 | {{0,0,1,1},{0,1,1,2}} | ||
77 | }, | ||
78 | { | ||
79 | {{0,1,1,2},{0,0,1,1}}, | ||
80 | {{1,1,0,0},{0,1,1,2}} | ||
81 | }, | ||
82 | { | ||
83 | {{1,1,1,1},{0,1,2,3}}, | ||
84 | {{0,1,2,3},{2,2,2,2}} | ||
85 | }, | ||
86 | { | ||
87 | {{1,1,1,2},{2,1,0,0}}, | ||
88 | {{0,1,2,2},{1,1,1,2}}, | ||
89 | {{0,1,1,1},{2,2,1,0}}, | ||
90 | {{0,0,1,2},{0,1,1,1}} | ||
91 | }, | ||
92 | { | ||
93 | {{0,1,1,1},{0,0,1,2}}, | ||
94 | {{0,1,2,2},{1,1,1,0}}, | ||
95 | {{1,1,1,2},{0,1,2,2}}, | ||
96 | {{0,0,1,2},{2,1,1,1}} | ||
97 | }, | ||
98 | { | ||
99 | {{1,0,1,2},{0,1,1,1}}, | ||
100 | {{2,1,1,1},{1,0,1,2}}, | ||
101 | {{1,0,1,2},{2,1,1,1}}, | ||
102 | {{0,1,1,1},{1,0,1,2}} | ||
103 | } | ||
104 | }; | ||
105 | |||
106 | /* not even pseudo random :) */ | ||
107 | int t_rand(int range) | ||
108 | { | ||
109 | static int count; | ||
110 | count++; | ||
111 | return count % range; | ||
112 | } | ||
113 | |||
114 | void draw_frame(int fstart_x,int fstop_x,int fstart_y,int fstop_y) | ||
115 | { | ||
116 | lcd_drawline(fstart_x, fstart_y, fstop_x, fstart_y); | ||
117 | lcd_drawline(fstart_x, fstop_y, fstop_x, fstop_y); | ||
118 | |||
119 | lcd_drawline(fstart_x, fstart_y, fstart_x, fstop_y); | ||
120 | lcd_drawline(fstop_x, fstart_y, fstop_x, fstop_y); | ||
121 | } | ||
122 | |||
123 | void draw_block(int x,int y,int block,int frame,bool clear) | ||
124 | { | ||
125 | int i; | ||
126 | for(i=0;i < 4;i++) { | ||
127 | if (clear) | ||
128 | lcd_clearpixel(start_x+x+block_data[block][frame][0][i], | ||
129 | start_y+y+block_data[block][frame][1][i]); | ||
130 | else | ||
131 | lcd_drawpixel(start_x+x+block_data[block][frame][0][i], | ||
132 | start_y+y+block_data[block][frame][1][i]); | ||
133 | } | ||
134 | } | ||
135 | |||
136 | void to_virtual() | ||
137 | { | ||
138 | int i; | ||
139 | for(i=0;i < 4;i++) | ||
140 | *(virtual+ | ||
141 | ((current_y+block_data[current_b][current_f][1][i])*max_x)+ | ||
142 | (current_x+block_data[current_b][current_f][0][i])) = current_b+1; | ||
143 | } | ||
144 | |||
145 | bool gameover() | ||
146 | { | ||
147 | int i; | ||
148 | int frame, block, y, x; | ||
149 | |||
150 | x = current_x; | ||
151 | y = current_y; | ||
152 | block = current_b; | ||
153 | frame = current_f; | ||
154 | |||
155 | for(i=0;i < 4; i++){ | ||
156 | /* Do we have blocks touching? */ | ||
157 | if(*(virtual+((y+block_data[block][frame][1][i])*max_x)+x+ | ||
158 | block_data[block][frame][0][i]) != 0) | ||
159 | { | ||
160 | /* Are we at the top of the frame? */ | ||
161 | if(y+block_data[block][frame][1][i] < start_y) | ||
162 | { | ||
163 | /* Game over ;) */ | ||
164 | return true; | ||
165 | } | ||
166 | } | ||
167 | } | ||
168 | return false; | ||
169 | } | ||
170 | |||
171 | bool valid_position(int x,int y,int block,int frame) | ||
172 | { | ||
173 | int i; | ||
174 | for(i=0;i < 4;i++) | ||
175 | if( (*(virtual+((y+block_data[block][frame][1][i])*max_x)+x+ | ||
176 | block_data[block][frame][0][i]) != 0) || | ||
177 | (x+block_data[block][frame][0][i] < 0) || | ||
178 | (x+block_data[block][frame][0][i] > max_x-1) || | ||
179 | (y+block_data[block][frame][1][i] < 0) || | ||
180 | (y+block_data[block][frame][1][i] > max_y-1)) | ||
181 | return false; | ||
182 | return true; | ||
183 | } | ||
184 | |||
185 | void from_virtual() | ||
186 | { | ||
187 | int x,y; | ||
188 | for(y=0;y < max_y;y++) | ||
189 | for(x=0;x < max_x;x++) | ||
190 | if(*(virtual+(y*max_x)+x)) | ||
191 | lcd_drawpixel(start_x+x,start_y+y); | ||
192 | else | ||
193 | lcd_clearpixel(start_x+x,start_y+y); | ||
194 | } | ||
195 | |||
196 | void move_block(int x,int y,int f) | ||
197 | { | ||
198 | int last_frame = current_f; | ||
199 | if(f != 0) | ||
200 | { | ||
201 | current_f += f; | ||
202 | if(current_f > block_frames[current_b]-1) | ||
203 | current_f = 0; | ||
204 | if(current_f < 0) | ||
205 | current_f = block_frames[current_b]-1; | ||
206 | } | ||
207 | if(valid_position(current_x+x,current_y+y,current_b,current_f)) | ||
208 | { | ||
209 | draw_block(current_x,current_y,current_b,last_frame,true); | ||
210 | current_x += x; | ||
211 | current_y += y; | ||
212 | draw_block(current_x,current_y,current_b,current_f,false); | ||
213 | lcd_update(); | ||
214 | } | ||
215 | else | ||
216 | current_f = last_frame; | ||
217 | } | ||
218 | |||
219 | void new_block() | ||
220 | { | ||
221 | current_b = next_b; | ||
222 | current_f = next_f; | ||
223 | current_x = (int)((max_x)/2)-1; | ||
224 | current_y = 0; | ||
225 | next_b = t_rand(blocks); | ||
226 | next_f = t_rand(block_frames[next_b]); | ||
227 | draw_block(max_x+2,start_y-1,current_b,current_f,true); | ||
228 | draw_block(max_x+2,start_y-1,next_b,next_f,false); | ||
229 | if(!valid_position(current_x,current_y,current_b,current_f)) | ||
230 | { | ||
231 | draw_block(current_x,current_y,current_b,current_f,false); | ||
232 | lcd_update(); | ||
233 | } | ||
234 | else | ||
235 | draw_block(current_x,current_y,current_b,current_f,false); | ||
236 | } | ||
237 | |||
238 | int check_lines() | ||
239 | { | ||
240 | int x,y,i; | ||
241 | bool line; | ||
242 | int lines = 0; | ||
243 | for(y=0;y < max_y;y++) | ||
244 | { | ||
245 | line = true; | ||
246 | for(x=0;x < max_x;x++) | ||
247 | if(virtual[y*max_x+x] == 0) | ||
248 | line = false; | ||
249 | if(line) | ||
250 | { | ||
251 | lines++; | ||
252 | for(i=y;i > 1;i--) | ||
253 | for (x=0;x<max_x;x++) | ||
254 | virtual[i*max_x] = virtual[((i-1)*max_x)]; | ||
255 | for (x=0;x<max_x;x++) | ||
256 | virtual[max_x] = 0; | ||
257 | } | ||
258 | } | ||
259 | return lines; | ||
260 | } | ||
261 | |||
262 | void move_down() | ||
263 | { | ||
264 | int l; | ||
265 | if(!valid_position(current_x,current_y+1,current_b,current_f)) | ||
266 | { | ||
267 | to_virtual(); | ||
268 | l = check_lines(); | ||
269 | if(l) | ||
270 | { | ||
271 | lines += l; | ||
272 | level = (int)lines/10; | ||
273 | if(level > 9) | ||
274 | level = 9; | ||
275 | from_virtual(); | ||
276 | score += l*l; | ||
277 | } | ||
278 | new_block(); | ||
279 | move_block(0,0,0); | ||
280 | } | ||
281 | else | ||
282 | move_block(0,1,0); | ||
283 | } | ||
284 | |||
285 | void game_loop(void) | ||
286 | { | ||
287 | while(1) | ||
288 | { | ||
289 | int b=0; | ||
290 | int count = 0; | ||
291 | /* while(count*20 < level_speeds[level]) */ | ||
292 | { | ||
293 | b = button_get(); | ||
294 | if ( b & BUTTON_OFF ) | ||
295 | return; /* get out of here */ | ||
296 | |||
297 | if ( b & BUTTON_LEFT ) { | ||
298 | move_block(-1,0,0); | ||
299 | } | ||
300 | if ( b & BUTTON_RIGHT ) { | ||
301 | move_block(1,0,0); | ||
302 | } | ||
303 | if ( b & BUTTON_UP ) { | ||
304 | move_block(0,0,1); | ||
305 | } | ||
306 | if ( b & BUTTON_DOWN ) { | ||
307 | move_down(); | ||
308 | } | ||
309 | count++; | ||
310 | sleep(10); | ||
311 | } | ||
312 | if(gameover()) { | ||
313 | int w, h; | ||
314 | |||
315 | lcd_getfontsize(TETRIS_TITLE_FONT, &w, &h); | ||
316 | lcd_clearrect(TETRIS_TITLE_XLOC, TETRIS_TITLE_YLOC, | ||
317 | TETRIS_TITLE_XLOC+(w*sizeof(TETRIS_TITLE)), | ||
318 | TETRIS_TITLE_YLOC-h); | ||
319 | lcd_putsxy(TETRIS_TITLE_XLOC, TETRIS_TITLE_YLOC, "You lose!", | ||
320 | TETRIS_TITLE_FONT); | ||
321 | lcd_update(); | ||
322 | sleep(2); | ||
323 | return; | ||
324 | } | ||
325 | move_down(); | ||
326 | } | ||
327 | } | ||
328 | |||
329 | void init_tetris() | ||
330 | { | ||
331 | memset(&virtual, 0, sizeof(virtual)); | ||
332 | start_x = 1; | ||
333 | start_y = 1; | ||
334 | max_x = 14; | ||
335 | max_y = 24; | ||
336 | current_x = 0; | ||
337 | current_y = 0; | ||
338 | current_f = 0; | ||
339 | current_b = 0; | ||
340 | level = 0; | ||
341 | lines = 0; | ||
342 | score = 0; | ||
343 | next_b = 0; | ||
344 | next_f = 0; | ||
345 | } | ||
346 | |||
347 | void tetris(void) | ||
348 | { | ||
349 | init_tetris(); | ||
350 | |||
351 | draw_frame(start_x-1,start_x+max_x,start_y-1,start_y+max_y); | ||
352 | lcd_putsxy(TETRIS_TITLE_XLOC, TETRIS_TITLE_YLOC, TETRIS_TITLE, | ||
353 | TETRIS_TITLE_FONT); | ||
354 | lcd_update(); | ||
355 | |||
356 | next_b = t_rand(blocks); | ||
357 | next_f = t_rand(block_frames[next_b]); | ||
358 | new_block(); | ||
359 | game_loop(); | ||
360 | } | ||
361 | |||
362 | #endif | ||