diff --git a/ISSUES.txt b/ISSUES.txt index 08dace8..a646976 100644 --- a/ISSUES.txt +++ b/ISSUES.txt @@ -1,8 +1,6 @@ Outstanding ----------- -5. Make setup mode less confusing -6. Allow jam clock adjustments in setup 7. Unified build with multiple firmware targets @@ -13,3 +11,6 @@ Fixed 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 +5. Make setup mode less confusing +6. Allow jam clock adjustments in setup +8. Debounce buttons \ No newline at end of file diff --git a/config.h b/config.h index 8e7fd4b..c5efa33 100644 --- a/config.h +++ b/config.h @@ -4,14 +4,9 @@ #define CLOCK_MHZ 16 #define CLOCK_HZ (CLOCK_MHZ * 1000000) -#define SCORE_DIGITS 2 -#define JAM_DIGITS 3 - -// Show an indicator (J/L/t) to the left of the jam clock -//#define JAM_INDICATOR - -// The jam clock is split across the period clock (easier folding, harder wiring) -//#define JAM_SPLIT +#define LINEUP_DEFAULT (-30 * 10) +#define JAM_DEFAULT (-2 * 60 * 10) +#define PERIOD_DEFAULT (-30 * 60 * 10) // Set these to the PORTA pins you use #define NESCLK 0 @@ -21,4 +16,79 @@ #define SCLK 4 #define SLTCH 5 +#define JAM_DIGITS 3 + + + +#if VARIANT == neale +// +// Neale variant +// +// With Jam indicator, split jam clock, and only 2 score digits. +// Also featuring goofy brain wiring. +// + +#define SCORE_DIGITS 2 +#define JAM_INDICATOR +#define JAM_SPLIT + +// I wired mine differently and I'm too lazy to fix it. +#undef NESCLK +#undef NESLTCH +#undef NESOUT +#undef SIN +#undef SCLK +#undef SLTCH + +#define NESCLK 3 +#define NESLTCH 4 +#define NESOUT 5 +#define SIN 0 +#define SCLK 1 +#define SLTCH 2 + + + +#elif VARIANT == susan1 +// +// Susan 1 variant +// +// Like the neale variant but with correct brain wiring +// + + +#define SCORE_DIGITS 2 +#define JAM_INDICATOR +#define JAM_SPLIT + + + +#elif VARIANT == susan2 +// +// Susan 2 variant +// + + +#define SCORE_DIGITS 3 + + + +#else +// +// Default variant +// +// Nobody has built this yet! +// But it's the one described by the instructions. +// + + + +#define SCORE_DIGITS 3 +#define JAM_SPLIT + + +#endif + + + #endif diff --git a/main.c b/main.c index 053371a..00058d8 100644 --- a/main.c +++ b/main.c @@ -21,14 +21,13 @@ volatile uint32_t jiffies = 0; // Elapsed time in deciseconds (tenths of a second) volatile bool tick = false; // Set high when jiffy clock ticks - // Clocks are in deciseconds 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); -int16_t jam_clock = 0; +int16_t period_clock = PERIOD_DEFAULT; +int16_t jam_duration = JAM_DEFAULT; +int16_t lineup_duration = LINEUP_DEFAULT; +int16_t jam_clock = JAM_DEFAULT; enum { TIMEOUT = 0, JAM, @@ -65,18 +64,16 @@ const uint8_t seven_segment_digits[] = { 0x7b, 0x60, 0x37, 0x76, 0x6c, 0x5e, 0x5f, 0x70, 0x7f, 0x7e }; -const uint8_t setup_digits[] = { - // [ = ] - 0x1b, 0x12, 0x72 -}; // keyed by state const uint8_t indicator[] = { - // '' J L T - - 0x00, 0x63, 0x0b, 0x0f, 0x04 + // t, J, L, - + 0x0f, 0x63, 0x0b, 0x04 }; #define max(a, b) ((a)>(b)?(a):(b)) +#define min(a, b) ((a)<(b)?(a):(b)) + void latch() @@ -235,18 +232,39 @@ nesprobe() void update_controller() { - static uint8_t last_pressed = 0; + static uint8_t last_held = 0; static uint32_t last_change = 0; + static uint32_t last_typematic = 0; uint8_t held; uint8_t pressed; + int typematic = 0; int inc = 1; held = nesprobe(); - pressed = (last_pressed ^ held) & held; - if (last_pressed != held) { + pressed = (last_held ^ held) & held; + + // Set up typematic acceleration + if (last_held != held) { + // Debounce + if (last_change == jiffies) { + return; + } last_change = jiffies; - last_pressed = held; - } + last_typematic = jiffies; + last_held = held; + typematic = 1; + } else if (jiffies > last_typematic) { + last_typematic = jiffies; + if (jiffies - last_change < 6) { + typematic = 0; + } else if (jiffies - last_change < 40) { + typematic = 1; + } else if (jiffies - last_change < 80) { + typematic = 10; + } else { + typematic = 20; + } + } if (pressed == konami_code[konami_pos]) { konami_pos += 1; @@ -258,13 +276,21 @@ update_controller() } else if (konami_pos > 3) { return; } - } else { + } else if (pressed) { konami_pos = 0; } // Select means subtract if (held & BTN_SELECT) { inc = -1; } + + if (setup && (held & BTN_START) && (pressed & BTN_SELECT)) { + jam_duration += 30 * 10; + if (jam_duration > -60 * 10) { + jam_duration = -120 * 10; + } + jam_clock = jam_duration; + } if ((pressed & BTN_A) && ((state != JAM) || (jam_clock == 0))) { state = JAM; @@ -282,32 +308,25 @@ update_controller() } if ((held & BTN_START) && (state == TIMEOUT)) { - int typematic; - - // 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 (held & BTN_UP) { - period_clock -= typematic; + period_clock -= typematic * 10; } if (held & BTN_DOWN) { - period_clock += typematic; + period_clock += typematic * 10; } + + period_clock = min(period_clock, 0); + period_clock = max(period_clock, -90 * 30 * 10); } else { - // Score adjustment and clock adjustment are mutually exclusive (issue #3) - if (pressed & BTN_LEFT) { - score_a = max(score_a + inc, 0); + // Score adjustment and clock adjustment are mutually exclusive + if (held & BTN_LEFT) { + score_a += typematic * inc; + score_a = max(score_a, 0); } - if (pressed & BTN_RIGHT) { - score_b = max(score_b + inc, 0); + if (held & BTN_RIGHT) { + score_b += typematic * inc; + score_b = max(score_b, 0); } }