From 75b588a288d080336d760217a7cd8ea6c0e5900c Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Wed, 1 Jun 2016 23:40:40 -0500 Subject: [PATCH] Yikes, did I actually make a thing that might be used to talk to the Game Boy Printer? I think so. --- avr/Makefile | 7 ++- avr/send.c | 131 ++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 134 insertions(+), 4 deletions(-) diff --git a/avr/Makefile b/avr/Makefile index 7ade12e..459e5fc 100644 --- a/avr/Makefile +++ b/avr/Makefile @@ -54,8 +54,11 @@ $(RECV_ELF): $(RECV_OBJS) $(OBJS): %.o: %.c $(HEADERS_BUILD) $(CC) $(CFLAGS) -c $< -flash: $(IMAGE_BIN) - $(AVRDUDE) $(AVRDUDE_FLAGS) -U flash:w:$(IMAGE_BIN):r +flash-send: $(SEND_BIN) + $(AVRDUDE) $(AVRDUDE_FLAGS) -U flash:w:$(SEND_BIN):r + +flash-recv: $(RECV_BIN) + $(AVRDUDE) $(AVRDUDE_FLAGS) -U flash:w:$(RECV_BIN):r clean: $(RM) -f $(IMAGES_BIN) $(IMAGES_ELF) $(OBJS) diff --git a/avr/send.c b/avr/send.c index 7411ded..a662623 100644 --- a/avr/send.c +++ b/avr/send.c @@ -1,11 +1,13 @@ #include #include +#include #include #include #include -#define TIMER0_INTERVAL 1953 +#define TIMER0_INTERVAL 1953 +#define PACKET_BODY_SIZE 640 static volatile uint8_t bits = 0; static volatile uint8_t value_in = 0x00; /* Data coming in from Game Boy */ @@ -17,6 +19,14 @@ static volatile tabby_printer_packet header = { .size = 0 }; +static volatile uint8_t body[PACKET_BODY_SIZE]; + +static volatile uint16_t sum = 0x0000; + +static volatile uint8_t device = 0x00, + status = 0x00, + buffered = 0; + static volatile uint16_t i = 0, b = 0; @@ -24,6 +34,10 @@ static volatile uint16_t i = 0, * Internal clock source interrupt vector */ ISR(TIMER0_COMPB_vect) { + if (!buffered) { + reti(); + } + value_in >>= 1; PORTB |= (1 << PORTB5); @@ -41,6 +55,29 @@ ISR(TIMER0_COMPB_vect) { value_out <<= 1; if (--bits == 0) { + if (i < sizeof(header)) { + value_out = header.data[i++]; + } else if (b < header.size) { + value_out = body[b++]; + } else if (b == header.size) { + value_out = sum & 0x00ff; + b++; + } else if (b == header.size + 1) { + value_out = (sum & 0xff00) >> 8; + b++; + } else if (b == header.size + 2) { + device = value_in; + value_out = 0x00; + b++; + } else if (b == header.size + 3) { + status = value_in; + value_out = 0x00; + + i = 0; + b = 0; + buffered = 0; + } + bits = 8; } @@ -90,7 +127,24 @@ static void clock_setup() { TCCR1B = (1 << CS10); } +static uint16_t checksum() { + uint16_t sum = 0; + size_t i; + + for (i=2; i<6; i++) { + sum += header.data[i]; + } + + for (i=0; i