From be7b8d0f666dc08eb3366568006fc4194b32779d Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Sun, 29 May 2016 15:26:06 -0500 Subject: [PATCH] What else could I possibly be missing? --- avr/main.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/avr/main.c b/avr/main.c index 1219cc2..df5e0a8 100644 --- a/avr/main.c +++ b/avr/main.c @@ -10,14 +10,14 @@ #include #include -static volatile uint8_t bits = 0; -static volatile uint8_t value_in = 0x00; /* Data coming in from Game Boy */ -static volatile uint8_t value_out = 0x00; /* Data going out to Game Boy */ - static const uint16_t timer_counter_intervals[4] = { 1953, 977, 61, 31 }; +static volatile uint8_t bits = 0; +static volatile uint8_t value_in = 0x00; /* Data coming in from Game Boy */ +static volatile uint8_t value_out = 0x00; /* Data going out to Game Boy */ + static volatile tabby_avr_buffer buffer = { .len = 0, .cur = 0, @@ -48,9 +48,9 @@ ISR(TIMER0_COMPB_vect) { if (--bits == 0) { uart_putchar(value_in, NULL); - if (buffer.cur < buffer.len) { + if (buffer.cur < buffer.read) { value_out = buffer.data[buffer.cur++]; - } else { + } else if (buffer.cur == buffer.len) { buffer.len = 0; buffer.cur = 0; buffer.read = 0; @@ -70,11 +70,11 @@ ISR(TIMER0_COMPB_vect) { * SPI byte receipt interrupt vector */ ISR(SPI_STC_vect) { - uart_putchar(SPDR, NULL); + uart_putchar(SPDR); - if (buffer.cur < buffer.len) { + if (buffer.cur < buffer.read) { SPDR = buffer.data[buffer.cur++]; - } else { + } else if (buffer.cur == buffer.len) { buffer.len = 0; buffer.cur = 0; buffer.read = 0; @@ -198,7 +198,10 @@ int main() { buffer.data[buffer.read++] = c; if (buffer.read == buffer.len) { - goto reset; + state = TABBY_COMMAND_NONE; + received = 0; + + continue; } }