From 5b2a7017b4ba60c2f1cf40d48e18e949a9e7d2ee Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Sun, 12 Jan 2014 11:05:18 -0700 Subject: [PATCH] Yay, it works again --- avr.h | 11 +++++------ config.h | 8 ++++++++ main.c | 48 ++++++++++++++++++++---------------------------- 3 files changed, 33 insertions(+), 34 deletions(-) diff --git a/avr.h b/avr.h index 4e17752..d6a091f 100644 --- a/avr.h +++ b/avr.h @@ -7,13 +7,12 @@ #define bit(pin, bit, on) pin = (on ? (pin | bit) : (pin & ~bit)) -#define sin(on) bit(PORTA, _BV(3), on) -#define sclk(on) bit(PORTA, _BV(4), on) -#define sltch(on) bit(PORTA, _BV(5), on) +#define sin(on) bit(PORTA, _BV(SIN), on) +#define sclk(on) bit(PORTA, _BV(SCLK), on) +#define sltch(on) bit(PORTA, _BV(SLTCH), on) -#define nesclk(on) bit(PORTA, _BV(0), on) -#define nesltch(on) bit(PORTA, _BV(1), on) -#define NESOUT 2 +#define nesclk(on) bit(PORTA, _BV(NESCLK), on) +#define nesltch(on) bit(PORTA, _BV(NESLTCH), on) #define nesout() ((PINA & _BV(NESOUT)) << NESOUT) void init(void); diff --git a/config.h b/config.h index 8067923..4ace5a6 100644 --- a/config.h +++ b/config.h @@ -8,4 +8,12 @@ #define JAM_INDICATOR 1 #define JAM_DIGITS 3 +// Set these to the PORTA pins you use +#define SIN 0 +#define SCLK 1 +#define SLTCH 2 +#define NESCLK 3 +#define NESLTCH 4 +#define NESOUT 5 + #endif \ No newline at end of file diff --git a/main.c b/main.c index 886313a..45c39af 100644 --- a/main.c +++ b/main.c @@ -126,6 +126,22 @@ write_num(uint16_t number, int digits) } } +uint16_t +clock_of_jiffies(int16_t jiffies) +{ + uint16_t seconds; + uint16_t ret; + + // People read "0:00" as the time being out. + // Add 0.9 seconds to make the ALU's truncation be a "round up" + seconds = (abs(jiffies) + 9) / 10; + + ret = (seconds / 60) * 100; // Minutes + ret += seconds % 60; // Seconds + + return ret; +} + /* * Update all the digits */ @@ -133,12 +149,12 @@ void draw() { - uint16_t jclk; - uint16_t pclk; + uint16_t jclk = clock_of_jiffies(jam_clock); + uint16_t pclk = clock_of_jiffies(period_clock); bool blank = ((state == TIMEOUT) && (jiffies % 8 == 0)); // Segments test mode - if (1 || (KONAMI == state)) { + if (KONAMI == state) { int i; for (i = 0; i < 12; i += 1) { @@ -150,30 +166,6 @@ draw() return; } - jclk = (abs(jam_clock / 600) % 10) * 1000; - jclk += abs(jam_clock) % 600; - - pclk = (abs(period_clock / 10) / 60) * 100; - pclk += abs(period_clock / 10) % 60; - -#ifdef DEMO - if (jam_clock == 0) { - if (state == LINEUP) { - state = JAM; - jam_clock = jam_duration; - } else { - state = LINEUP; - jam_clock = lineup_duration; - } - } - - if (period_clock == 0) { - period_clock = -(30 * 60 * 10); - jam_clock = jam_duration; - state = JAM; - } -#endif - // Score A write_num(score_b, SCORE_DIGITS); @@ -329,7 +321,7 @@ setup() void loop() { - // update_controller(); + update_controller(); if (tick) { tick = false;