More code
[uccvend-snackrom.git] / ROM2 / display.c
index af96921..da51973 100644 (file)
@@ -9,10 +9,12 @@
  *
  */
 
+#include "display.h"
 #include "vend.h"
 
 char display_buffer[10];    /* what each byte on the display reads          */
 char current_message[256];  /* message that is scrolled or switched between */
+u8   msg_length;            /* length of current_message                    */
 u8   wrap_mode;             /* whether to scroll or alternate between msgs  */
 u8   scroll_point;          /* how far through the message we have scrolled */
 
@@ -25,16 +27,35 @@ void set_msg(char* newmsg, u8 wrap) {
        char* dest = current_message;
        /* equivalent of a string copy */
        /* while (dest++ = newmsg++); */
+       msg_length = 0;
        while (newmsg) {
                dest = newmsg;
                dest++;
                newmsg++;
+               msg_length++;
        }
        wrap_mode = wrap;
        scroll_point = 0;
        display_update();
 }
 
+void display_shift() {
+       /* update the display for WRAP_SCROLL or WRAP_ALTERNATE modes */
+       switch (wrap_mode) {
+               case WRAP_SCROLL:
+                       scroll_point++;
+                       if (scroll_point >= msg_length) scroll_point = 0;
+                       display_update();
+                       break;
+               case WRAP_ALTERNATE:
+                       scroll_point += 10;
+                       if (scroll_point >= msg_length) scroll_point = 0;
+                       /* the above means that only sets of multiples of 10 characters
+                        * are shown (excess ones are not) */
+                       display_update();
+       }
+}
+
 void set_char(char c, u8 pos) {
        /* sets a single character */
        display_buffer[pos] = c;
@@ -67,15 +88,16 @@ void display_reset() {
 
 void display_update() {
        u8 i;
+
+       for (i=0; i < 10; i++) {
+               display_buffer[i] = current_message[(i+scroll_point)%msg_length];
+       }
+
+       /* hmmm, will this cause some flickering of the display? */
        display_reset();
        
        for (i=0; i < 10; i++) {
-               /* FIXME: we may need to fiddle with the character codes sent to the 
-                * controller. It doesn't seem like we have to, but datasheets for
-                * the "pin-for-pin" compatible MSC1937 from OKI suggest a different
-                * character set
-                */
-               display_send_byte(i[display_buffer]&0x7f);
+               display_send_byte(display_buffer[i]&0x7f);
        }
 }
 

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