Fixed a bunch of bugs

This commit is contained in:
Neale Pickett 2014-02-02 12:31:33 -07:00
parent 97a5c2cebe
commit b443503e3c
4 changed files with 60 additions and 51 deletions

15
ISSUES.txt Normal file
View File

@ -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

4
avr.c
View File

@ -23,7 +23,7 @@ ISR(TIM1_COMPA_vect)
} }
void void
init(void) avr_init(void)
{ {
int i; int i;
@ -40,6 +40,8 @@ init(void)
TIMSK1 |= _BV(OCIE1A); TIMSK1 |= _BV(OCIE1A);
bit(PORTA, _BV(7), true); bit(PORTA, _BV(7), true);
PORTB = 0xff;
sei(); sei();
} }

2
avr.h
View File

@ -15,6 +15,6 @@
#define nesltch(on) bit(PORTA, _BV(NESLTCH), on) #define nesltch(on) bit(PORTA, _BV(NESLTCH), on)
#define nesout() ((PINA & _BV(NESOUT)) << NESOUT) #define nesout() ((PINA & _BV(NESOUT)) << NESOUT)
void init(void); void avr_init(void);
#endif #endif

90
main.c
View File

@ -30,12 +30,12 @@ int16_t jam_duration = -(2 * 60 * 10);
int16_t lineup_duration = (-30 * 10); int16_t lineup_duration = (-30 * 10);
int16_t jam_clock = 0; int16_t jam_clock = 0;
enum { enum {
SETUP = 0, TIMEOUT = 0,
JAM, JAM,
LINEUP, LINEUP,
TIMEOUT,
KONAMI KONAMI
} state = SETUP; } state = TIMEOUT;
bool setup = true;
// NES Controller buttons // NES Controller buttons
@ -156,11 +156,6 @@ write_pclock()
write(0); write(0);
write(0); 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 { } else {
write_num(pclk, 4); write_num(pclk, 4);
} }
@ -240,20 +235,19 @@ nesprobe()
void void
update_controller() update_controller()
{ {
static uint8_t last_val = 0; static uint8_t last_pressed = 0;
static uint32_t last_change = 0; static uint32_t last_change = 0;
static uint32_t last_typematic = 0; uint8_t held;
uint8_t cur;
uint8_t pressed; uint8_t pressed;
int inc = 1; int inc = 1;
cur = nesprobe(); held = nesprobe();
pressed = (last_val ^ cur) & cur; pressed = (last_pressed ^ held) & held;
if (last_val != cur) { if (last_pressed != held) {
last_change = jiffies; last_change = jiffies;
last_val = cur; last_pressed = held;
} }
if (pressed == konami_code[konami_pos]) { if (pressed == konami_code[konami_pos]) {
konami_pos += 1; konami_pos += 1;
@ -268,7 +262,7 @@ update_controller()
konami_pos = 0; konami_pos = 0;
} }
// Select means subtract // Select means subtract
if (cur & BTN_SELECT) { if (held & BTN_SELECT) {
inc = -1; inc = -1;
} }
@ -287,27 +281,38 @@ update_controller()
jam_clock = 1; jam_clock = 1;
} }
if ((state == TIMEOUT) || (state == SETUP)) { if ((held & BTN_START) && (state == TIMEOUT)) {
uint8_t v = pressed; int typematic;
if ((jiffies - last_change > 10) && (last_typematic < jiffies)) { // Set up typematic acceleration (issue #4)
v = cur; if (pressed & (BTN_UP | BTN_DOWN)) {
last_typematic = jiffies; 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) { if (held & BTN_UP) {
period_clock -= 10; period_clock -= typematic;
} }
if (v & BTN_DOWN) { if (held & BTN_DOWN) {
period_clock += 10; 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) { if (state != TIMEOUT) {
score_a = max(score_a + inc, 0); setup = false;
}
if (pressed & BTN_RIGHT) {
score_b = max(score_b + inc, 0);
} }
} }
@ -318,16 +323,6 @@ update_controller()
*/ */
void
setup()
{
// The TLC5941 required some setup.
// The TPIC doesn't.
// Hooray.
PORTB = 0xff;
}
void void
loop() loop()
{ {
@ -341,8 +336,6 @@ loop()
} }
switch (state) { switch (state) {
case SETUP:
break;
case JAM: case JAM:
case LINEUP: case LINEUP:
if (period_clock) { if (period_clock) {
@ -350,7 +343,7 @@ loop()
} }
// fall through // fall through
case TIMEOUT: case TIMEOUT:
if (jam_clock) { if (jam_clock && !setup) {
jam_clock += 1; jam_clock += 1;
} }
} }
@ -362,8 +355,7 @@ loop()
int int
main(void) main(void)
{ {
init(); avr_init();
setup();
for (;;) { for (;;) {
loop(); loop();
} }