Accept both CR and LF to denote newline.
[uccvend-snackrom.git] / ROM2 / sci.c
index 4ce0d36..739d706 100644 (file)
@@ -1,4 +1,5 @@
 #include "vend.h"
+#include "chime.h"
 #include "sci.h"
 
 char sci_tx_buf[BUFFER_LEN];
@@ -32,13 +33,16 @@ void send_packet() {
 }
 
 void sci_rx_int() {
+       /* XXX FIXME we should do something about errors. nack? */
        if (sci_have_packet) {
                /* overrun :( */
                _io_ports[M6811_SCDR]; /* read it anyway */
                return;
        }
        sci_rx_buf[sci_rx_buf_ptr] = _io_ports[M6811_SCDR];
-       if (sci_rx_buf[sci_rx_buf_ptr] == '\n') {
+       if (sci_rx_buf[sci_rx_buf_ptr] == '\n' ||
+                       sci_rx_buf[sci_rx_buf_ptr] == '\r') {
+               if (sci_rx_buf_ptr == 0) return; /* we've read a blank packet in */
                sci_rx_buf[sci_rx_buf_ptr] = '\0';
                sci_have_packet = 1;
                sci_rx_buf_ptr = 0;
@@ -52,7 +56,12 @@ void sci_rx_int() {
 }
 
 void sci_interrupt_serial() {
+       chime_start();
+
        if (_io_ports[M6811_SCSR] & M6811_RDRF) sci_rx_int();
+
+       if (_io_ports[M6811_SCSR] & M6811_OR)
+               _io_ports[M6811_SCDR]; /* declare it a lost cause */
 }
 
 void msg_clr() {
@@ -61,15 +70,11 @@ void msg_clr() {
 }
 
 void send_ack() {
-       sci_tx_buf[0] = '!';
-       sci_tx_buf[1] = '\n';
-       sci_tx_buf[2] = '\0';
+       my_strncpy(sci_tx_buf, "!\n", BUFFER_LEN);
        send_packet();
 }
 
 void send_nack() {
-       sci_tx_buf[0] = '?';
-       sci_tx_buf[1] = '\n';
-       sci_tx_buf[2] = '\0';
+       my_strncpy(sci_tx_buf, "?\n", BUFFER_LEN);
        send_packet();
 }

UCC git Repository :: git.ucc.asn.au