Example program for the Cidco MailStation Z80 computer
1/*
2 * MailStation example program
3 * Copyright (c) 2019-2021 joshua stein <jcs@jcs.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <stdio.h>
19#include <string.h>
20#include <stdlib.h>
21
22#include "lib/mailstation.h"
23
24/* ignore first peekkey() if it returns power button */
25unsigned char lastkey = KEY_POWER;
26
27int process_keyboard(void);
28void process_input(unsigned char b);
29
30int
31main(void)
32{
33 screen_init();
34
35 wifi_init();
36
37 printf("Hello, World\n");
38
39 for (;;) {
40 if (process_keyboard() == KEY_POWER)
41 break;
42 }
43
44 return 0;
45}
46
47int
48process_keyboard(void)
49{
50 unsigned char b;
51
52 b = peekkey();
53
54 /* this breaks key-repeat, but it's needed to debounce */
55 if (b == 0)
56 lastkey = 0;
57 else if (b == lastkey)
58 b = 0;
59 else
60 lastkey = b;
61
62 if (b == 0)
63 return 0;
64
65 switch (b) {
66 case KEY_POWER:
67 delay(100);
68 powerdown();
69 break;
70 case KEY_F1:
71 break;
72 case KEY_MAIN_MENU:
73 break;
74 case KEY_PAGE_UP:
75 break;
76 case KEY_PAGE_DOWN:
77 break;
78 case KEY_UP:
79 break;
80 case KEY_DOWN:
81 break;
82 case KEY_LEFT:
83 break;
84 case KEY_RIGHT:
85 break;
86 case KEY_SIZE:
87 break;
88 default:
89 putchar(b);
90 }
91
92 return b;
93}