From b443503e3c77f4451f4b98e1016b103317af1583 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Sun, 2 Feb 2014 12:31:33 -0700 Subject: [PATCH] Fixed a bunch of bugs --- ISSUES.txt | 15 +++++++++ avr.c | 4 ++- avr.h | 2 +- main.c | 90 +++++++++++++++++++++++++----------------------------- 4 files changed, 60 insertions(+), 51 deletions(-) create mode 100644 ISSUES.txt diff --git a/ISSUES.txt b/ISSUES.txt new file mode 100644 index 0000000..08dace8 --- /dev/null +++ b/ISSUES.txt @@ -0,0 +1,15 @@ +Outstanding +----------- + +5. Make setup mode less confusing +6. Allow jam clock adjustments in setup +7. Unified build with multiple firmware targets + + +Fixed +----- + +1. Scores should not go negative +2. Konami Code position doesn't reset on non-sequence button +3. It is too easy to mess up scores when adjusting period clock time +4. Period clock adjustments take forever diff --git a/avr.c b/avr.c index 63ab3b0..4d793b0 100644 --- a/avr.c +++ b/avr.c @@ -23,7 +23,7 @@ ISR(TIM1_COMPA_vect) } void -init(void) +avr_init(void) { int i; @@ -40,6 +40,8 @@ init(void) TIMSK1 |= _BV(OCIE1A); bit(PORTA, _BV(7), true); + + PORTB = 0xff; sei(); } diff --git a/avr.h b/avr.h index d6a091f..91018cf 100644 --- a/avr.h +++ b/avr.h @@ -15,6 +15,6 @@ #define nesltch(on) bit(PORTA, _BV(NESLTCH), on) #define nesout() ((PINA & _BV(NESOUT)) << NESOUT) -void init(void); +void avr_init(void); #endif diff --git a/main.c b/main.c index 390d990..053371a 100644 --- a/main.c +++ b/main.c @@ -30,12 +30,12 @@ int16_t jam_duration = -(2 * 60 * 10); int16_t lineup_duration = (-30 * 10); int16_t jam_clock = 0; enum { - SETUP = 0, + TIMEOUT = 0, JAM, LINEUP, - TIMEOUT, KONAMI -} state = SETUP; +} state = TIMEOUT; +bool setup = true; // NES Controller buttons @@ -156,11 +156,6 @@ write_pclock() write(0); write(0); write(0); - } else if (state == SETUP) { - write(setup_digits[2]); - write(setup_digits[1]); - write(setup_digits[1]); - write(setup_digits[0]); } else { write_num(pclk, 4); } @@ -240,20 +235,19 @@ nesprobe() void update_controller() { - static uint8_t last_val = 0; + static uint8_t last_pressed = 0; static uint32_t last_change = 0; - static uint32_t last_typematic = 0; - uint8_t cur; + uint8_t held; uint8_t pressed; int inc = 1; - cur = nesprobe(); - pressed = (last_val ^ cur) & cur; - if (last_val != cur) { + held = nesprobe(); + pressed = (last_pressed ^ held) & held; + if (last_pressed != held) { last_change = jiffies; - last_val = cur; - } - + last_pressed = held; + } + if (pressed == konami_code[konami_pos]) { konami_pos += 1; @@ -268,7 +262,7 @@ update_controller() konami_pos = 0; } // Select means subtract - if (cur & BTN_SELECT) { + if (held & BTN_SELECT) { inc = -1; } @@ -287,27 +281,38 @@ update_controller() jam_clock = 1; } - if ((state == TIMEOUT) || (state == SETUP)) { - uint8_t v = pressed; + if ((held & BTN_START) && (state == TIMEOUT)) { + int typematic; - if ((jiffies - last_change > 10) && (last_typematic < jiffies)) { - v = cur; - last_typematic = jiffies; + // Set up typematic acceleration (issue #4) + if (pressed & (BTN_UP | BTN_DOWN)) { + typematic = 10; + } else if (jiffies - last_change < 20) { + typematic = 0; + } else if (jiffies - last_change < 500) { + typematic = 10; + } else { + typematic = 100; } - if (v & BTN_UP) { - period_clock -= 10; + if (held & BTN_UP) { + period_clock -= typematic; } - if (v & BTN_DOWN) { - period_clock += 10; + if (held & BTN_DOWN) { + period_clock += typematic; + } + } else { + // Score adjustment and clock adjustment are mutually exclusive (issue #3) + if (pressed & BTN_LEFT) { + score_a = max(score_a + inc, 0); + } + + if (pressed & BTN_RIGHT) { + score_b = max(score_b + inc, 0); } } - - if (pressed & BTN_LEFT) { - score_a = max(score_a + inc, 0); - } - - if (pressed & BTN_RIGHT) { - score_b = max(score_b + inc, 0); + + if (state != TIMEOUT) { + setup = false; } } @@ -318,16 +323,6 @@ update_controller() */ -void -setup() -{ - // The TLC5941 required some setup. - // The TPIC doesn't. - // Hooray. - - PORTB = 0xff; -} - void loop() { @@ -341,8 +336,6 @@ loop() } switch (state) { - case SETUP: - break; case JAM: case LINEUP: if (period_clock) { @@ -350,7 +343,7 @@ loop() } // fall through case TIMEOUT: - if (jam_clock) { + if (jam_clock && !setup) { jam_clock += 1; } } @@ -362,8 +355,7 @@ loop() int main(void) { - init(); - setup(); + avr_init(); for (;;) { loop(); }