Don't forget to send device ID and status byte from Game Boy Printer to host

This commit is contained in:
XANTRONIX Development 2016-06-01 23:49:27 -05:00
parent 75b588a288
commit 4640fa8216

View file

@ -9,6 +9,12 @@
#define TIMER0_INTERVAL 1953 #define TIMER0_INTERVAL 1953
#define PACKET_BODY_SIZE 640 #define PACKET_BODY_SIZE 640
enum {
TABBY_SEND_READING = 0,
TABBY_SEND_BUFFERED = (1 << 0),
TABBY_SEND_COMPLETE = (1 << 1)
};
static volatile uint8_t bits = 0; static volatile uint8_t bits = 0;
static volatile uint8_t value_in = 0x00; /* Data coming in from Game Boy */ 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 uint8_t value_out = 0x00; /* Data going out to Game Boy */
@ -23,9 +29,9 @@ static volatile uint8_t body[PACKET_BODY_SIZE];
static volatile uint16_t sum = 0x0000; static volatile uint16_t sum = 0x0000;
static volatile uint8_t device = 0x00, static volatile uint8_t device = 0x00,
status = 0x00, status = 0x00,
buffered = 0; flags = TABBY_SEND_READING;
static volatile uint16_t i = 0, static volatile uint16_t i = 0,
b = 0; b = 0;
@ -34,7 +40,7 @@ static volatile uint16_t i = 0,
* Internal clock source interrupt vector * Internal clock source interrupt vector
*/ */
ISR(TIMER0_COMPB_vect) { ISR(TIMER0_COMPB_vect) {
if (!buffered) { if (!(flags & TABBY_SEND_BUFFERED)) {
reti(); reti();
} }
@ -73,9 +79,10 @@ ISR(TIMER0_COMPB_vect) {
status = value_in; status = value_in;
value_out = 0x00; value_out = 0x00;
i = 0; i = 0;
b = 0; b = 0;
buffered = 0; flags &= ~TABBY_SEND_BUFFERED;
flags |= TABBY_SEND_COMPLETE;
} }
bits = 8; bits = 8;
@ -154,10 +161,17 @@ int main() {
while (1) { while (1) {
uint8_t c; uint8_t c;
while (buffered) { while (flags != TABBY_SEND_READING) {
sleep_mode(); sleep_mode();
} }
if (flags & TABBY_SEND_COMPLETE) {
uart_putchar(device, NULL);
uart_putchar(status, NULL);
flags = TABBY_SEND_READING;
}
c = uart_getchar(NULL); c = uart_getchar(NULL);
switch (i) { switch (i) {
@ -220,9 +234,9 @@ int main() {
sum |= c << 8; sum |= c << 8;
if (sum == checksum()) { if (sum == checksum()) {
i = 0; i = 0;
b = 0; b = 0;
buffered = 1; flags |= TABBY_SEND_BUFFERED;
} }
} }
} }