From 97a5c2cebe705194cd6a141297d72f4c7a43da2c Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Sun, 2 Feb 2014 10:05:50 -0700 Subject: [PATCH] Stop letting scores go negative --- main.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/main.c b/main.c index 0765f64..390d990 100644 --- a/main.c +++ b/main.c @@ -23,8 +23,8 @@ volatile bool tick = false; // Set high when jiffy clock ticks // Clocks are in deciseconds -uint16_t score_a = 0; -uint16_t score_b = 0; +int16_t score_a = 0; +int16_t score_b = 0; int16_t period_clock = -(30 * 60 * 10); int16_t jam_duration = -(2 * 60 * 10); int16_t lineup_duration = (-30 * 10); @@ -76,6 +76,8 @@ const uint8_t indicator[] = { 0x00, 0x63, 0x0b, 0x0f, 0x04 }; +#define max(a, b) ((a)>(b)?(a):(b)) + void latch() { @@ -301,11 +303,11 @@ update_controller() } if (pressed & BTN_LEFT) { - score_a += inc; + score_a = max(score_a + inc, 0); } if (pressed & BTN_RIGHT) { - score_b += inc; + score_b = max(score_b + inc, 0); } }