comparison lcdpoll/main.c @ 3:06e900c54ae3

fc-lcdpoll program put together, compiles
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 14 Mar 2018 23:04:44 +0000
parents
children 45c81216d964
comparison
equal deleted inserted replaced
2:bff57443b0f7 3:06e900c54ae3
1 /*
2 * This is the main module for fc-lcdpoll.
3 */
4
5 #include <sys/types.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <strings.h>
10 #include <unistd.h>
11 #include <rvinterf/etm.h>
12 #include <rvinterf/localtypes.h>
13 #include <rvinterf/exitcodes.h>
14
15 extern char *socket_pathname;
16 extern char *rvinterf_ttyport, *rvinterf_Bopt, *rvinterf_lopt, *rvinterf_wopt;
17
18 u32 framebuffer_base_addr;
19
20 emit_lcd_string(row, col, buf)
21 unsigned row, col;
22 u_char *buf;
23 {
24 unsigned pos;
25
26 printf("%u %u ", row, col);
27 for (pos = 0; pos < 176; pos += 2)
28 printf("%02X%02X", buf[pos+1] ^ 0xFF, buf[pos] ^ 0xFF);
29 }
30
31 fb_poll()
32 {
33 unsigned row;
34 u_char buf[176];
35 int rc;
36
37 for (row = 0; row < 220; row++) {
38 rc = do_memory_read_32(framebuffer_base_addr + row * 356,
39 buf, 44);
40 if (rc)
41 exit(rc);
42 emit_lcd_string(row, 0, buf);
43 rc = do_memory_read_32(framebuffer_base_addr + row * 356 + 176,
44 buf, 44);
45 if (rc)
46 exit(rc);
47 emit_lcd_string(row, 88, buf);
48 fflush(stdout);
49 }
50 }
51
52 main(argc, argv)
53 char **argv;
54 {
55 extern int optind;
56 extern char *optarg;
57 int c, sopt = 0;
58
59 while ((c = getopt(argc, argv, "B:l:p:s:w:")) != EOF)
60 switch (c) {
61 case 'B':
62 rvinterf_Bopt = optarg;
63 continue;
64 case 'l':
65 rvinterf_lopt = optarg;
66 continue;
67 case 'p':
68 rvinterf_ttyport = optarg;
69 continue;
70 case 's':
71 socket_pathname = optarg;
72 sopt++;
73 continue;
74 case 'w':
75 rvinterf_wopt = optarg;
76 continue;
77 case '?':
78 default:
79 /* error msg already printed */
80 exit(ERROR_USAGE);
81 }
82 if (rvinterf_ttyport) {
83 if (sopt) {
84 fprintf(stderr,
85 "%s error: -p and -s options are mutually exclusive\n",
86 argv[0]);
87 exit(ERROR_USAGE);
88 }
89 launch_rvinterf();
90 } else {
91 if (rvinterf_Bopt || rvinterf_lopt || rvinterf_wopt) {
92 fprintf(stderr,
93 "%s error: -B, -l and -w options are meaningful only when launching rvinterf\n",
94 argv[0]);
95 exit(ERROR_USAGE);
96 }
97 connect_local_socket();
98 }
99 if (argc != optind + 1) {
100 fprintf(stderr, "usage: %s [options] framebuffer_base_addr\n",
101 argv[0]);
102 exit(ERROR_USAGE);
103 }
104 framebuffer_base_addr = strtoul(argv[optind], 0, 16);
105
106 for (;;)
107 fb_poll();
108 }