summaryrefslogtreecommitdiffstats
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.tar.bz2
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
const struct button_mapping *plugin_contexts[]
= {generic_directions, generic_actions};
-
unsigned char grid_a[LCD_WIDTH][LCD_HEIGHT];
unsigned char grid_b[LCD_WIDTH][LCD_HEIGHT];
int generation = 0;
@@ -105,6 +104,48 @@ void init_grid(char *pgrid){
}
}
+/*fill grid with pattern from file (viewer mode)*/
+static bool load_cellfile(const char *file, char *pgrid){
+ int fd, file_size;
+ fd = rb->open(file, O_RDONLY);
+ if (fd==-1)
+ return false;
+
+ file_size = rb->filesize(fd);
+ if (file_size==-1)
+ return false;
+
+ char buf1[file_size];
+ int i, j, k, xmid, ymid;
+ j=0;
+ k=0;
+ xmid = (LCD_WIDTH>>1) - 2;
+ ymid = (LCD_HEIGHT>>1) - 2;
+
+ rb->read(fd, buf1, file_size - 1);
+
+ for(i=0; i<file_size; i++){
+
+ switch(buf1[i]){
+ case '.':
+ j=j++;
+ break;
+ case 'O':
+ set_cell(xmid + j, ymid + k, pgrid);
+ j++;
+ break;
+ case '\n':
+ k++;
+ j=0;
+ break;
+ default:
+ break;
+ }
+ }
+ rb->close(fd);
+ return true;
+}
+
/* fill grid with initial pattern */
static void setup_grid(char *pgrid, int pattern){
int n, max;
@@ -391,6 +432,8 @@ static void next_generation(char *pgrid, char *pnext_grid){
generation++;
}
+
+
/**********************************/
/* this is the plugin entry point */
/**********************************/
@@ -403,8 +446,7 @@ enum plugin_status plugin_start(const void* parameter)
char *pgrid;
char *pnext_grid;
char *ptemp;
-
- (void)parameter;
+ (void)(parameter);
backlight_force_on(); /* backlight control in lib/helper.c */
#if LCD_DEPTH > 1
@@ -420,8 +462,27 @@ enum plugin_status plugin_start(const void* parameter)
pgrid = (char *)grid_a;
pnext_grid = (char *)grid_b;
- init_grid(pgrid);
- setup_grid(pgrid, pattern++);
+ init_grid(pgrid);
+
+
+ if( parameter == NULL )
+ {
+ setup_grid(pgrid, pattern++);
+ }
+ else
+ {
+ if( load_cellfile(parameter, pgrid) )
+ {
+ rb->splashf( 1*HZ, "Cells loaded (%s)", (char *)parameter );
+ }
+ else
+ {
+ rb->splash( 1*HZ, "File Open Error");
+ setup_grid(pgrid, pattern++); /* fall back to stored patterns */
+ }
+ }
+
+
show_grid(pgrid);
while(!quit) {
@@ -490,5 +551,3 @@ enum plugin_status plugin_start(const void* parameter)
backlight_use_settings(); /* backlight control in lib/helper.c */
return PLUGIN_OK;
}
-
-
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
*,viewers/properties,-
colours,apps/text_editor,11
ssg,games/superdom,-
+cells,games/rocklife,-
link,viewers/shortcuts_view,-
*,viewers/shortcuts_append,-
*,apps/md5sum,-