Don't forget to send device ID and status byte from Game Boy Printer to host
This commit is contained in:
parent
75b588a288
commit
4640fa8216
1 changed files with 25 additions and 11 deletions
36
avr/send.c
36
avr/send.c
|
@ -9,6 +9,12 @@
|
|||
#define TIMER0_INTERVAL 1953
|
||||
#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 value_in = 0x00; /* Data coming in from 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 uint8_t device = 0x00,
|
||||
status = 0x00,
|
||||
buffered = 0;
|
||||
static volatile uint8_t device = 0x00,
|
||||
status = 0x00,
|
||||
flags = TABBY_SEND_READING;
|
||||
|
||||
static volatile uint16_t i = 0,
|
||||
b = 0;
|
||||
|
@ -34,7 +40,7 @@ static volatile uint16_t i = 0,
|
|||
* Internal clock source interrupt vector
|
||||
*/
|
||||
ISR(TIMER0_COMPB_vect) {
|
||||
if (!buffered) {
|
||||
if (!(flags & TABBY_SEND_BUFFERED)) {
|
||||
reti();
|
||||
}
|
||||
|
||||
|
@ -73,9 +79,10 @@ ISR(TIMER0_COMPB_vect) {
|
|||
status = value_in;
|
||||
value_out = 0x00;
|
||||
|
||||
i = 0;
|
||||
b = 0;
|
||||
buffered = 0;
|
||||
i = 0;
|
||||
b = 0;
|
||||
flags &= ~TABBY_SEND_BUFFERED;
|
||||
flags |= TABBY_SEND_COMPLETE;
|
||||
}
|
||||
|
||||
bits = 8;
|
||||
|
@ -154,10 +161,17 @@ int main() {
|
|||
while (1) {
|
||||
uint8_t c;
|
||||
|
||||
while (buffered) {
|
||||
while (flags != TABBY_SEND_READING) {
|
||||
sleep_mode();
|
||||
}
|
||||
|
||||
if (flags & TABBY_SEND_COMPLETE) {
|
||||
uart_putchar(device, NULL);
|
||||
uart_putchar(status, NULL);
|
||||
|
||||
flags = TABBY_SEND_READING;
|
||||
}
|
||||
|
||||
c = uart_getchar(NULL);
|
||||
|
||||
switch (i) {
|
||||
|
@ -220,9 +234,9 @@ int main() {
|
|||
sum |= c << 8;
|
||||
|
||||
if (sum == checksum()) {
|
||||
i = 0;
|
||||
b = 0;
|
||||
buffered = 1;
|
||||
i = 0;
|
||||
b = 0;
|
||||
flags |= TABBY_SEND_BUFFERED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue