Permalink
Browse files

exit bug fix

  • Loading branch information...
1 parent 33783d6 commit 8191a05743b3861254e26f6a602d57302fbd51f5 twobit committed Nov 1, 2011
Showing with 53 additions and 46 deletions.
  1. +53 −46 firmware/apps/replicate.c
View
@@ -8,69 +8,78 @@ typedef enum { INIT, SHOW, BREAK, LISTEN, SCORE, QUIT } State;
static State state = INIT;
static uint8_t chain[MAX_CHAIN_LENGTH];
-static uint8_t length = 1;
-static uint8_t step = 0;
-static uint8_t sub_step = 0;
+static uint8_t length;
+static uint8_t step;
+static uint8_t sub_step;
static char score[5] = { ' ', ' ', '0', '0', '0' };
static uint8_t tick() {
uint8_t x, y;
- if(state == INIT) {
- uint8_t i;
- for(i = 0; i < length; i++) chain[i] = rand() & 1;
- state = SHOW;
- }
+ switch(state) {
+ case INIT:
+ length = 1;
+ step = 0;
+ sub_step = 0;
+ state = SHOW;
+ for(x = 0; x < MAX_CHAIN_LENGTH; x++) chain[x] = rand() & 1;
- if(state == SHOW) {
+ case SHOW: {
- uint8_t side = chain[step];
- uint8_t color = sub_step < 7 ? 7 - sub_step : 0;
+ uint8_t side = chain[step];
+ uint8_t color = sub_step < 7 ? 7 - sub_step : 0;
- for(x = 0; x < LED_WIDTH; ++x) {
- uint8_t c = (x >= LED_WIDTH / 2) ^ side ? color : 0;
- for(y = 0; y < LED_HEIGHT; ++y)
- setLedXY(x, y, c);
- }
+ for(x = 0; x < LED_WIDTH; ++x) {
+ uint8_t c = (x >= LED_WIDTH / 2) ^ side ? color : 0;
+ for(y = 0; y < LED_HEIGHT; ++y)
+ setLedXY(x, y, c);
+ }
- ++sub_step;
- if(sub_step == 10) {
- sub_step = 0;
- ++step;
- if(step == length) {
- step = 0;
- state = LISTEN;
+ ++sub_step;
+ if(sub_step == 10) {
+ sub_step = 0;
+ ++step;
+ if(step == length) {
+ step = 0;
+ state = LISTEN;
+ }
}
+ break;
}
- }
- else if(state == BREAK) {
- ++sub_step;
- if(sub_step == 5) {
- sub_step = 0;
- state = SHOW;
- }
- }
- else if(state == SCORE) {
+ case BREAK:
+ ++sub_step;
+ if(sub_step == 5) {
+ sub_step = 0;
+ state = SHOW;
+ }
+ break;
- for(x = 0; x < LED_WIDTH; ++x) {
+ case SCORE:
+ for(x = 0; x < LED_WIDTH; ++x) {
- uint16_t p = (sub_step / 4) + x;
- char c = score[p / 4 % 5];
- uint8_t bits = 0;
- if((p & 3) < 3) bits = font[c - 32][p & 3];
+ uint16_t p = (sub_step / 4) + x;
+ char c = score[p / 4 % 5];
+ uint8_t bits = 0;
+ if((p & 3) < 3) bits = pgm_read_byte(&font[c - 32][p & 3]);
- for(y = 0; y < LED_HEIGHT; ++y) {
- setLedXY(x, y, 7 * (bits & 1));
- bits >>= 1;
+ for(y = 0; y < LED_HEIGHT; ++y) {
+ setLedXY(x, y, 7 * (bits & 1));
+ bits >>= 1;
+ }
}
- }
- ++sub_step;
+ ++sub_step;
+ break;
- }
+ case QUIT:
+ state = INIT;
+ return 1;
- return state == QUIT;
+ default:
+ break;
+ }
+ return 0;
}
static void key(key_type key, event_type event) {
@@ -85,8 +94,6 @@ static void key(key_type key, event_type event) {
// wow, you just beat the game!
if(length == MAX_CHAIN_LENGTH) goto DO_SCORE;
-
- chain[step] = rand() & 1;
step = 0;
++length;
state = BREAK;

0 comments on commit 8191a05

Please sign in to comment.