116704b77580ba29241eb52b9cf114deeb7e35eb
[uccvend-snackrom.git] / ROM2 / main.c
1 #include "display.h"
2 #include "keypad.h"
3 #include "chime.h"
4 #include "vend.h"
5
6 u16 uid;
7 u16 pin;
8
9 bool uid_enter() {
10         u8 uidpos;
11         /* the user has started to type in his/her UID. grab the last key and continue
12          * reading. Returns true if a UID was entered successfully.
13          * The UID will be entered as 5 digits. (shorter uids should be pre-padded
14          * with zeros)
15          */
16         uid = last_key%10; /* 10 => 0, it was _not_ reset (hopefuly :) */
17         set_msg("UID?      ", WRAP_NONE);
18         set_char((last_key%10)+'0', 5);
19
20         for (uidpos = 2; uidpos <= 5; uidpos++) {
21                 keypad_getkey();
22                 if (last_key == KEY_RESET) {
23                         uid = 0;
24                         return 0;
25                 }
26                 uid = (uid*10) + (last_key%10);
27                 set_char((last_key%10)+'0', 4+uidpos);
28         }
29         return 1;
30 }
31
32
33 bool pin_enter() {
34         u8 pinpos;
35         /* We ask for a pin, display a PIN: prompt. PINs must be a 4 digit number.
36          * Strictly, they must be 16-bit, but it's easier to use the guarantee that
37          * 4-digits numbers are < 65536
38          *
39          * Also display X's on screen as the pin is entered.
40          */
41         set_msg("PIN?      ", WRAP_NONE);
42         for (pinpos = 1; pinpos <= 5; pinpos++) {
43                 keypad_getkey();
44                 if (last_key == KEY_RESET) {
45                         pin = 0;
46                         return 0;
47                 }
48                 pin = (pin*10) + (last_key%10);
49                 set_char('X', 4+pinpos);
50         }
51         return 1;
52 }
53
54 int main() {
55         /* do stuff */
56         set_msg("UNIVERSITY", WRAP_NONE);
57         delay(1000);
58         set_msg(" COMPUTER ", WRAP_NONE);
59         delay(1000);
60         set_msg("   CLUB   ", WRAP_NONE);
61         delay(1000);
62
63         set_msg("UCC *** INSERT COINS OR USER-ID", WRAP_SCROLL_L);
64         while(1) {
65                 /* this needs to be a relatively tight loop to make sure we catch
66                  * keypresses
67                  */
68                 keypad_read();
69                 if (keypad_pressed()) {
70                         if (last_key != KEY_RESET) {
71                                 if (uid_enter() && pin_enter()) {
72                                         /* authenticate them */
73                                 } else {
74                                         uid = 0;
75                                         pin = 0;
76                                         /* move on */
77                                 }
78                         }
79                 }
80         }
81 }
82
83 void _start() {
84         /* Initialize Stuff.  Particularly some memory locations that can only be
85          * written in the first 64 clock cycles upon reset.
86          */
87         display_init();
88         set_bus_expanded();
89         /* enable RTI & set rate */
90         /* init coin mech */
91         main();
92 }
93
94 void rti() {
95         chime();
96 }

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