More code
[uccvend-snackrom.git] / ROM2 / main.c
1 #include "display.h"
2 #include "keypad.h"
3 #include "chime.h"
4 #include "server.h"
5 #include "vend.h"
6
7 u16 uid;
8 u16 pin;
9
10 u16 scroll_timer;
11
12 bool uid_enter() {
13         u8 uidpos;
14         /* the user has started to type in his/her UID. grab the last key and continue
15          * reading. Returns true if a UID was entered successfully.
16          * The UID will be entered as 5 digits. (shorter uids should be pre-padded
17          * with zeros)
18          */
19         uid = last_key%10; /* 10 => 0, it was _not_ reset (hopefuly :) */
20         set_msg("UID?      ", WRAP_NONE);
21         set_char((last_key%10)+'0', 5);
22
23         for (uidpos = 2; uidpos <= 5; uidpos++) {
24                 keypad_getkey();
25                 if (last_key == KEY_RESET) {
26                         uid = 0;
27                         return 0;
28                 }
29                 uid = (uid*10) + (last_key%10);
30                 set_char((last_key%10)+'0', 4+uidpos);
31         }
32         return 1;
33 }
34
35
36 bool pin_enter() {
37         u8 pinpos;
38         /* We ask for a pin, display a PIN: prompt. PINs must be a 4 digit number.
39          * Strictly, they must be 16-bit, but it's easier to use the guarantee that
40          * 4-digits numbers are < 65536
41          *
42          * Also display X's on screen as the pin is entered.
43          */
44         set_msg("PIN?      ", WRAP_NONE);
45         for (pinpos = 1; pinpos <= 5; pinpos++) {
46                 keypad_getkey();
47                 if (last_key == KEY_RESET) {
48                         pin = 0;
49                         return 0;
50                 }
51                 pin = (pin*10) + (last_key%10);
52                 set_char('X', 4+pinpos);
53         }
54         return 1;
55 }
56
57 void selection_menu() {
58         set_msg("ENTER SELECTION OR INSERT COINS", WRAP_SCROLL);
59 }
60
61 int main() {
62         /* do stuff */
63         set_msg("UNIVERSITY", WRAP_NONE);
64         delay(1000);
65         set_msg(" COMPUTER ", WRAP_NONE);
66         delay(1000);
67         set_msg("   CLUB   ", WRAP_NONE);
68         delay(1000);
69
70         /* FIXME: want this message to be changeable from the server */
71         set_msg("UNIVERISTY COMPUTER CLUB *** INSERT COINS OR USER-ID ***",
72                         WRAP_SCROLL);
73         while(1) {
74                 /* this needs to be a relatively tight loop to make sure we catch
75                  * keypresses at the main menu
76                  */
77                 keypad_read();
78                 if (keypad_pressed()) {
79                         if (last_key != KEY_RESET) {
80                                 if (uid_enter() && pin_enter()) {
81                                         /* authenticate them */
82                                         switch (server_authenticate(uid, pin)) {
83                                                 case AUTH_GOOD:
84                                                         selection_menu();
85                                                 case AUTH_BAD:
86                                                         set_msg(" BAD USER ", WRAP_NONE);
87                                                         delay(1000);
88                                                         break;
89                                                 case AUTH_NO_MONEY:
90                                                         set_msg(" NO MONEY ", WRAP_NONE);
91                                                         delay(1000);
92                                                         break;
93                                                 case AUTH_LOCKED:
94                                                         set_msg("YOUR ACCOUNT IS LOCKED", WRAP_SCROLL);
95                                                         delay(1000);
96                                                         break;
97                                         }
98                                 }
99                                 uid = 0;
100                                 pin = 0;
101                                 /* move on */
102                         }
103                 }
104         }
105 }
106
107 void _start() {
108         /* Initialize Stuff.  Particularly some memory locations that can only be
109          * written in the first 64 clock cycles upon reset.
110          */
111         display_init();
112         set_bus_expanded();
113         /* enable RTI & set rate */
114         /* init coin mech */
115         main();
116 }
117
118 void rti() {
119         chime(); /* turn chime on or of as need be */
120
121         /* scroll the display if need be too */
122         if (scroll_timer == 0) {
123                 display_shift();
124                 scroll_timer = SCROLL_TIME;
125         }
126         scroll_timer--;
127 }

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