summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Menes <rmenes@rockbox.org>2009-03-31 14:38:01 +0000
committerRobert Menes <rmenes@rockbox.org>2009-03-31 14:38:01 +0000
commit843498fecabd6222d1144507fabe35c0cacda590 (patch)
tree8d84242ece58f62bff2df278f8188ae168271843
parent76e2ce3a4434bde33d2d39d0d1b64d4f9ba897d0 (diff)
downloadrockbox-843498fecabd6222d1144507fabe35c0cacda590.tar.gz
rockbox-843498fecabd6222d1144507fabe35c0cacda590.zip
FS#10079 by Justin Hannigan: Support for opening and viewing .cells files in rocklife. To use, simply select a .cells file in the file browser, and rocklife will launch and load it.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20591 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/plugins/rocklife.c73
-rw-r--r--apps/plugins/viewers.config1
2 files changed, 67 insertions, 7 deletions
diff --git a/apps/plugins/rocklife.c b/apps/plugins/rocklife.c
index 2d162fc595..05d4dc7884 100644
--- a/apps/plugins/rocklife.c
+++ b/apps/plugins/rocklife.c
@@ -82,7 +82,6 @@ PLUGIN_HEADER
82const struct button_mapping *plugin_contexts[] 82const struct button_mapping *plugin_contexts[]
83= {generic_directions, generic_actions}; 83= {generic_directions, generic_actions};
84 84
85
86unsigned char grid_a[LCD_WIDTH][LCD_HEIGHT]; 85unsigned char grid_a[LCD_WIDTH][LCD_HEIGHT];
87unsigned char grid_b[LCD_WIDTH][LCD_HEIGHT]; 86unsigned char grid_b[LCD_WIDTH][LCD_HEIGHT];
88int generation = 0; 87int generation = 0;
@@ -105,6 +104,48 @@ void init_grid(char *pgrid){
105 } 104 }
106} 105}
107 106
107/*fill grid with pattern from file (viewer mode)*/
108static bool load_cellfile(const char *file, char *pgrid){
109 int fd, file_size;
110 fd = rb->open(file, O_RDONLY);
111 if (fd==-1)
112 return false;
113
114 file_size = rb->filesize(fd);
115 if (file_size==-1)
116 return false;
117
118 char buf1[file_size];
119 int i, j, k, xmid, ymid;
120 j=0;
121 k=0;
122 xmid = (LCD_WIDTH>>1) - 2;
123 ymid = (LCD_HEIGHT>>1) - 2;
124
125 rb->read(fd, buf1, file_size - 1);
126
127 for(i=0; i<file_size; i++){
128
129 switch(buf1[i]){
130 case '.':
131 j=j++;
132 break;
133 case 'O':
134 set_cell(xmid + j, ymid + k, pgrid);
135 j++;
136 break;
137 case '\n':
138 k++;
139 j=0;
140 break;
141 default:
142 break;
143 }
144 }
145 rb->close(fd);
146 return true;
147}
148
108/* fill grid with initial pattern */ 149/* fill grid with initial pattern */
109static void setup_grid(char *pgrid, int pattern){ 150static void setup_grid(char *pgrid, int pattern){
110 int n, max; 151 int n, max;
@@ -391,6 +432,8 @@ static void next_generation(char *pgrid, char *pnext_grid){
391 generation++; 432 generation++;
392} 433}
393 434
435
436
394/**********************************/ 437/**********************************/
395/* this is the plugin entry point */ 438/* this is the plugin entry point */
396/**********************************/ 439/**********************************/
@@ -403,8 +446,7 @@ enum plugin_status plugin_start(const void* parameter)
403 char *pgrid; 446 char *pgrid;
404 char *pnext_grid; 447 char *pnext_grid;
405 char *ptemp; 448 char *ptemp;
406 449 (void)(parameter);
407 (void)parameter;
408 450
409 backlight_force_on(); /* backlight control in lib/helper.c */ 451 backlight_force_on(); /* backlight control in lib/helper.c */
410#if LCD_DEPTH > 1 452#if LCD_DEPTH > 1
@@ -420,8 +462,27 @@ enum plugin_status plugin_start(const void* parameter)
420 pgrid = (char *)grid_a; 462 pgrid = (char *)grid_a;
421 pnext_grid = (char *)grid_b; 463 pnext_grid = (char *)grid_b;
422 464
423 init_grid(pgrid); 465 init_grid(pgrid);
424 setup_grid(pgrid, pattern++); 466
467
468 if( parameter == NULL )
469 {
470 setup_grid(pgrid, pattern++);
471 }
472 else
473 {
474 if( load_cellfile(parameter, pgrid) )
475 {
476 rb->splashf( 1*HZ, "Cells loaded (%s)", (char *)parameter );
477 }
478 else
479 {
480 rb->splash( 1*HZ, "File Open Error");
481 setup_grid(pgrid, pattern++); /* fall back to stored patterns */
482 }
483 }
484
485
425 show_grid(pgrid); 486 show_grid(pgrid);
426 487
427 while(!quit) { 488 while(!quit) {
@@ -490,5 +551,3 @@ enum plugin_status plugin_start(const void* parameter)
490 backlight_use_settings(); /* backlight control in lib/helper.c */ 551 backlight_use_settings(); /* backlight control in lib/helper.c */
491 return PLUGIN_OK; 552 return PLUGIN_OK;
492} 553}
493
494
diff --git a/apps/plugins/viewers.config b/apps/plugins/viewers.config
index 3d5d7e1d35..ff77dd85b6 100644
--- a/apps/plugins/viewers.config
+++ b/apps/plugins/viewers.config
@@ -42,6 +42,7 @@ ppm,viewers/ppmviewer,2
42*,viewers/properties,- 42*,viewers/properties,-
43colours,apps/text_editor,11 43colours,apps/text_editor,11
44ssg,games/superdom,- 44ssg,games/superdom,-
45cells,games/rocklife,-
45link,viewers/shortcuts_view,- 46link,viewers/shortcuts_view,-
46*,viewers/shortcuts_append,- 47*,viewers/shortcuts_append,-
47*,apps/md5sum,- 48*,apps/md5sum,-