+ if ((sci_rx_buf[1] < '0') || (sci_rx_buf[1] > '9') ||
+ (sci_rx_buf[2] < '0') || (sci_rx_buf[2] > '9')) {
+ sci_rx_buf[1] = sci_rx_buf[2] = '0';
+ motor_reply((char*)&sci_rx_buf[1], MOTOR_NOSLOT);
+ return;
+ }
+
+ slot = (sci_rx_buf[1] - '0') * 10;
+ slot += sci_rx_buf[2] - '0';
+
+ motor_reply((char*)&sci_rx_buf[1], dispense_motor(slot));
+}
+
+void write_to_display() {
+ /* process a message in the form DXXXXXXXXXXX to send to display */
+ u8 i;
+ char buf[10];
+ for (i = 0; i < 10; i++)
+ if (sci_rx_buf[i+1])
+ buf[i] = sci_rx_buf[i+1];
+ else
+ break;
+
+ for (; i < 10; i++) /* pad the rest out with spaces */
+ buf[i] = ' ';
+
+ set_msg(buf);
+ send_ack();
+}
+
+void send_balance() {
+ wait_for_tx_free();
+ sci_tx_buf[0] = 'C';
+ sci_tx_buf[1] = have_change?'0':'1';
+ sci_tx_buf[2] = (coin_value/10000)%10;
+ sci_tx_buf[3] = (coin_value/1000)%10;
+ sci_tx_buf[4] = (coin_value/100)%10;
+ sci_tx_buf[5] = (coin_value/10)%10;
+ sci_tx_buf[6] = coin_value%10;
+ sci_tx_buf[7] = '\n';
+ sci_tx_buf[8] = 0;
+ send_packet();
+}
+
+void give_change() {
+ u16 cost;
+
+ if ((sci_rx_buf[1] < '0') || (sci_rx_buf[1] > '9') ||
+ (sci_rx_buf[2] < '0') || (sci_rx_buf[2] > '9') ||
+ (sci_rx_buf[3] < '0') || (sci_rx_buf[3] > '9') ||
+ (sci_rx_buf[4] < '0') || (sci_rx_buf[4] > '9') ||
+ (sci_rx_buf[5] < '0') || (sci_rx_buf[5] > '9')) {
+ send_nack();
+ }
+ cost = sci_rx_buf[1] - '0';
+ cost *= 10; cost = sci_rx_buf[2] - '0';
+ cost *= 10; cost = sci_rx_buf[3] - '0';
+ cost *= 10; cost = sci_rx_buf[4] - '0';
+ cost *= 10; cost = sci_rx_buf[5] - '0';
+
+ coin_cost(cost);
+ send_ack();
+}
+
+void send_keypress(u8 key) {
+ /* send a packet of the form KX with X being the key, or R for reset */
+ wait_for_tx_free();
+ sci_tx_buf[0] = 'K';
+ if (key == KEY_RESET)
+ sci_tx_buf[1] = 'R';
+ else
+ sci_tx_buf[1] = (key%10)+'0';
+ sci_tx_buf[2] = '\n';
+ sci_tx_buf[3] = 0;
+ send_packet();
+}
+
+void send_door_msg(bool open) {
+ wait_for_tx_free();
+ sci_tx_buf[0] = 'D';
+ sci_tx_buf[1] = open?'1':'0';
+ sci_tx_buf[2] = '\n';
+ sci_tx_buf[3] = 0;
+ send_packet();
+}
+
+void do_chime() {
+ chime_start();
+ send_ack();
+}