reworkings
[uccvend-snackrom.git] / ROM2 / display.c
index ee3e94b..3ab045b 100644 (file)
@@ -4,52 +4,78 @@
  * Use set_msg(char*) to write a new message to the screen, replacing the previous
  * one. The message can be at most 1023 characters long. Use set_wrap_mode with
  * one of the WRAP_* options in vend.h to set the scrolling behaviour. If the
- * message is less than 10 characters, it is centered and is not scrolled.
- * Otherwise, the message will scroll.
+ * message is less than 10 characters, it is not scrolled.  Otherwise, the
+ * message will scroll.
  *
  */
 
-
 #include "vend.h"
 
 char display_buffer[10];    /* what each byte on the display reads          */
 char current_message[1024]; /* message that is scrolled or switched between */
 u8   wrap_mode;             /* whether to scroll or alternate between msgs  */
 
+/* private prototypes */
+void display_send_byte(char c);
+void display_reset();
+void display_update();
+
+
 void set_msg(char* newmsg) {
        char* dest = current_message;
+       /* equivalent of a string copy */
        /* while (dest++ = newmsg++); */
        while (newmsg) {
                dest = newmsg;
                dest++;
                newmsg++;
        }
+       display_update();
 }
 
-void __inline__ set_wrap_mode(u8 new_wrap_mode) {
+inline void set_wrap_mode(u8 new_wrap_mode) {
        /* in theory it should be inlined anyway? */
        wrap_mode = new_wrap_mode;
 }
 
-void display_send_byte(u8 b) {
-       bset_3800(A3800_DISPLAY_WRITE);
+void display_send_byte(char c) {
+       *_misc_output |= A3800_DISPLAY_WRITE;  /* enable the display clock */
+
+       _io_ports[M6811_SPDR] = c;            /* load SPI with byte */
+       while(!(_io_ports[M6811_SPDR]&0x80)); /* wait for completion */
 }
 
 #define DISPLAY_DELAY  100 /* ms to delay between ops - could be tweaked */
 void display_reset() {
-       /* lower the reset line for 100ms */
-       bclr(PORTA, PORTA_DISP_RESET);
+       /* lower the reset line for a while */
+       _io_ports[M6811_PORTA] &= ~PORTA_DISP_RESET;
        delay(DISPLAY_DELAY);
-       bset(PORTA, PORTA_DISP_RESET);
+       _io_ports[M6811_PORTA] |= PORTA_DISP_RESET;
 
-       /* enable the SPI */
-       bset(SPCR, SPCR_SPE);
+       _io_ports[M6811_SPCR] |= M6811_SPE;       /* enable the SPI */
        delay(DISPLAY_DELAY);
 
-       /* tell the controller there are 10 digits */
+       display_send_byte(0xCA);    /* tell the controller there are 10 digits */
+       display_send_byte(0xE0);    /* set duty cycle to 100%                  */
+
+       _io_ports[M6811_SPCR] &= ~M6811_SPE;       /* disable the SPI again */
+}
+
+void display_update() {
+       int i;
+       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);
+       }
 }
 
-void display_refresh() {
+void display_init() {
        display_reset();
 }
+

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