From cef9ad954087c81b3bdf18258466828b85aca882 Mon Sep 17 00:00:00 2001 From: bernd Date: Tue, 19 Jul 2011 12:28:21 +0200 Subject: [PATCH] Added life application --- firmware/applications/life.c | 246 +++++++++++++++++++++++++++++++++++ 1 file changed, 246 insertions(+) create mode 100644 firmware/applications/life.c diff --git a/firmware/applications/life.c b/firmware/applications/life.c new file mode 100644 index 0000000..128a437 --- /dev/null +++ b/firmware/applications/life.c @@ -0,0 +1,246 @@ +#include + +#include "basic/basic.h" + +#include "lcd/render.h" +#include "lcd/display.h" +#include "lcd/allfonts.h" + +void ReinvokeISP(void); +void EnableWatchdog(uint32_t ms); +void delayms(uint32_t ms); + +/**************************************************************************/ +#define POS_PLAYER_Y 60 +#define ENEMY_ROWS 3 +#define ENEMY_COLUMNS 6 +#define DISABLED 255 + + +unsigned char rnd1(); + +struct gamestate { + char player; + char shot_x, shot_y; + char alive; + char move, direction, lastcol; + bool killed; + char enemy_x[ENEMY_ROWS][ENEMY_COLUMNS]; + char enemy_row_y[ENEMY_ROWS]; + +} game = {RESX/2-4, DISABLED, 0,ENEMY_ROWS*ENEMY_COLUMNS, 0, -1, ENEMY_COLUMNS-1, false}; +char key; + + +void checkISP(void) { + if(gpioGetValue(RB_BTN2)==0){ + gpioSetValue (RB_LED1, CFG_LED_ON); + delayms(200); + gpioSetValue (RB_LED1, CFG_LED_OFF); + while(gpioGetValue(RB_BTN0)==0); + EnableWatchdog(1000*5); + ReinvokeISP(); + } +} + + +void draw_rect(char x0, char y0, char x1, char y1) { + for(char x=x0; x<=x1; ++x) { + lcdSetPixel(x,y0,true); + lcdSetPixel(x,y1,true); + } + for(char y=y0+1; y0; --x) { + for(uchar y=1; y