#include #include #include #include #include #include #include #include static volatile tabby_printer_packet_header header = { .type = 0, .compression = 0, .size = 0 }; static volatile uint8_t body[648]; static volatile uint16_t sum = 0; static volatile uint16_t i = 0, b = 0; static inline uint16_t checksum() { uint16_t ret = header.data[2] + header.data[3] + header.data[4] + header.data[5]; size_t i; for (i=0; i>= 8; sum |= value << 8; b++; SPDR = 0; } else if (b == header.size + 1) { sum >>= 8; sum |= value << 8; b++; SPDR = 0x81; } else if (b == header.size + 2) { b++; SPDR = 0; } else if (b == header.size + 3) { i = 0; SPDR = 0; } } } } static void setup_clock_external() { /* * Configure MISO as output */ DDRB |= (1 << DDB4); /* * Configure SS as input */ DDRB &= ~(1 << DDB2); /* * Set SPI slave mode, and shift in/out most significant bit first */ SPCR &= ~((1 << MSTR) | (1 << DORD)); /* * Enable SPI in Mode 3 with interrupts */ SPCR |= (1 << CPOL) | (1 << CPHA) | (1 << SPIE) | (1 << SPE); /* * Initialize the SPI Data Register and serial buffer */ SPDR = 0; } int main() { /* * Best turn on the serial UART! */ uart_init(); /* * By default, the Game Boy link port is configured to monitor for external * clock pulses, so we'll go ahead and do that in this case. */ setup_clock_external(); /* * We do actually want to globally enable interrupts here, so here's that * one assembly instruction to do so. */ sei(); while (1) { sleep_mode(); } return 0; }