Deprecating main.c & other functions in order to be a dumb terminal.
[uccvend-snackrom.git] / ROM2 / display.c
1 /*
2  * display.c - functions for controlling the display on the vending machine.
3  *
4  *
5  * XXX obsolted - with a backend on the server machine, we don't need to
6  * handle scrolling, etc here. Replaced by display_basic.[cho]
7  *
8  * Use set_msg(char*) to write a new message to the screen, replacing the
9  * previous one. The message can be at most 255 characters long. Use
10  * set_wrap_mode with one of the WRAP_* options in vend.h to set the scrolling
11  * behaviour. If the message is less than 10 characters, it is not scrolled.
12  * Otherwise, the message will scroll.
13  *
14  */
15
16 #include "display.h"
17 #include "vend.h"
18
19 char display_buffer[10];    /* what each byte on the display reads          */
20 char current_message[256];  /* message that is scrolled or switched between */
21 u8   msg_length;            /* length of current_message                    */
22 u8   wrap_mode;             /* whether to scroll or alternate between msgs  */
23 u8   scroll_point;          /* how far through the message we have scrolled */
24 bool have_scrolled;         /* true after one scroll (used for scroll_msg())*/
25
26 /* private prototypes */
27 void display_send_byte(char c);
28 void display_reset();
29 void display_update();
30
31 void append_msg(char* newmsg, u8 wrap) {
32         char* dest = current_message+msg_length;
33         /* equivalent of a string copy */
34         while (newmsg) {
35                 dest = newmsg;
36                 dest++;
37                 newmsg++;
38                 msg_length++;
39         }
40         wrap_mode = wrap;
41 }
42
43 void set_msg(char* newmsg, u8 wrap) {
44         msg_length = 0;
45         append_msg(newmsg, wrap);
46         scroll_point = 0;
47         display_update();
48 }
49
50 void scroll_msg(char* newmsg) {
51         /* puts a message on display and does not return until the message has
52          * scrolled across once.
53          */
54         set_msg(newmsg, WRAP_SCROLL);
55         have_scrolled = 0;
56         while (!have_scrolled);
57 }
58
59 void display_shift() {
60         /* update the display for WRAP_SCROLL or WRAP_ALTERNATE modes */
61         switch (wrap_mode) {
62                 case WRAP_SCROLL:
63                 case WRAP_ALTERNATE:
64                         scroll_point++;
65                         if (scroll_point >= msg_length) {
66                                 scroll_point = 0;
67                                 have_scrolled = 1;
68                         }
69                         display_update();
70                         break;
71         }
72 }
73
74 void set_char(char c, u8 pos) {
75         /* sets a single character */
76         display_buffer[pos] = c;
77         display_update();
78 }
79
80 void display_send_byte(char c) {
81         bset_misc_output(A3800_DISPLAY_WRITE);  /* enable the display clock */
82
83         _io_ports[M6811_SPDR] = c;                  /* load SPI with byte */
84         while(!(_io_ports[M6811_SPDR]&M6811_SPIE)); /* wait for completion */
85         _io_ports[M6811_SPDR];                      /* SPDR read to clear SPIE flag */
86 }
87
88 #define DISPLAY_DELAY  100 /* ms to delay between ops - could be tweaked */
89 void display_reset() {
90         /* lower the reset line for a while */
91         bclr((void*)&_io_ports[M6811_PORTA], PORTA_DISP_RESET);
92         delay(DISPLAY_DELAY);
93         bset((void*)&_io_ports[M6811_PORTA], PORTA_DISP_RESET);
94
95         spi_enable();
96         delay(DISPLAY_DELAY);
97
98         display_send_byte(0xC0 | 10);    /* tell the controller there are 10 digits */
99         display_send_byte(0xE0);    /* set duty cycle to 100%                  */
100
101         spi_disable();
102 }
103
104 void display_update() {
105         u8 i;
106
107         for (i=0; i < 10; i++) {
108                 display_buffer[i] = current_message[
109                         (i+(wrap_mode==WRAP_ALTERNATE?scroll_point/10:scroll_point))
110                         %msg_length];
111         }
112
113         /* hmmm, will this cause some flickering of the display? */
114         display_reset();
115         
116         for (i=0; i < 10; i++) {
117                 display_send_byte(display_buffer[i]&0x7f);
118         }
119 }
120
121 void display_init() {
122         display_reset();
123 }
124

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