diff --git a/firmware/applications/life.c b/firmware/applications/life.c index 03bc23f..bafee14 100644 --- a/firmware/applications/life.c +++ b/firmware/applications/life.c @@ -2,9 +2,17 @@ #include "basic/basic.h" -#include "lcd/render.h" +//#include "lcd/render.h" #include "lcd/display.h" -#include "lcd/allfonts.h" +//#include "lcd/allfonts.h" + +#define BITSET_X (RESX+2) +#define BITSET_Y (RESY+2) +#define BITSET_SIZE (BITSET_X*BITSET_Y) + +#include "cbitset.h" + +typedef uint8_t uchar; unsigned char rnd1(); @@ -28,78 +36,63 @@ void fill_rect(char x0, char y0, char x1, char y1) { } #define STARTVALUE 10 -typedef unsigned char uchar; -typedef uchar row_t[RESY+2]; -uchar buf1[RESX+2][RESY+2]; -uchar buf2[RESX+2][RESY+2]; -row_t *life =buf1; -row_t *new =buf2; + +struct bitset _buf1,*buf1=&_buf1; +struct bitset _buf2,*buf2=&_buf2; + +struct bitset *life =&_buf1; +struct bitset *new =&_buf2; void swap_areas() { - row_t *tmp=life; + struct bitset *tmp=life; life=new; new=tmp; } -void fill_area(uchar area[RESX+2][RESY+2], uchar x0, uchar y0, uchar x1, uchar y1,uchar value) { +void fill_area(struct bitset *area, uchar x0, uchar y0, uchar x1, uchar y1,uchar value) { for(uchar x=x0; x<=x1; ++x) { for(uchar y=y0; y<=y1; ++y) { - area[x][y]=value; + bitset_set2(area,x,y,value); } } } -bool find_area(uchar area[RESX+2][RESY+2], uchar x0, uchar y0, uchar x1, uchar y1,uchar value) { +bool find_area(struct bitset *area, uchar x0, uchar y0, uchar x1, uchar y1,uchar value) { for(uchar x=x0; x<=x1; ++x) { for(uchar y=y0; y<=y1; ++y) { - if(area[x][y]==value) return true; + if(bitset_get2(area,x,y)==value) return true; } } return false; } -uint32_t sum_area(uchar area[RESX+2][RESY+2], uchar x0, uchar y0, uchar x1, uchar y1) { +uint32_t sum_area(struct bitset *area, uchar x0, uchar y0, uchar x1, uchar y1) { uint32_t sum=0; for(uchar x=x0; x<=x1; ++x) { for(uchar y=y0; y<=y1; ++y) { - sum+=area[x][y]; + sum+=bitset_get2(area,x,y); } } return sum; } void draw_area() { - for(uchar x=1; x<=RESX; ++x) { - for(uchar y=1; y<=RESY; ++y) { - lcdSetPixel(x,y,life[x+1][y+1]&1); + for(uchar x=0; x0; --x) { - for(uchar y=1; y