FreeCalypso > hg > freecalypso-ui-dev
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lcdpoll/main.c Wed Mar 14 23:04:44 2018 +0000 @@ -0,0 +1,108 @@ +/* + * This is the main module for fc-lcdpoll. + */ + +#include <sys/types.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> +#include <unistd.h> +#include <rvinterf/etm.h> +#include <rvinterf/localtypes.h> +#include <rvinterf/exitcodes.h> + +extern char *socket_pathname; +extern char *rvinterf_ttyport, *rvinterf_Bopt, *rvinterf_lopt, *rvinterf_wopt; + +u32 framebuffer_base_addr; + +emit_lcd_string(row, col, buf) + unsigned row, col; + u_char *buf; +{ + unsigned pos; + + printf("%u %u ", row, col); + for (pos = 0; pos < 176; pos += 2) + printf("%02X%02X", buf[pos+1] ^ 0xFF, buf[pos] ^ 0xFF); +} + +fb_poll() +{ + unsigned row; + u_char buf[176]; + int rc; + + for (row = 0; row < 220; row++) { + rc = do_memory_read_32(framebuffer_base_addr + row * 356, + buf, 44); + if (rc) + exit(rc); + emit_lcd_string(row, 0, buf); + rc = do_memory_read_32(framebuffer_base_addr + row * 356 + 176, + buf, 44); + if (rc) + exit(rc); + emit_lcd_string(row, 88, buf); + fflush(stdout); + } +} + +main(argc, argv) + char **argv; +{ + extern int optind; + extern char *optarg; + int c, sopt = 0; + + while ((c = getopt(argc, argv, "B:l:p:s:w:")) != EOF) + switch (c) { + case 'B': + rvinterf_Bopt = optarg; + continue; + case 'l': + rvinterf_lopt = optarg; + continue; + case 'p': + rvinterf_ttyport = optarg; + continue; + case 's': + socket_pathname = optarg; + sopt++; + continue; + case 'w': + rvinterf_wopt = optarg; + continue; + case '?': + default: + /* error msg already printed */ + exit(ERROR_USAGE); + } + if (rvinterf_ttyport) { + if (sopt) { + fprintf(stderr, + "%s error: -p and -s options are mutually exclusive\n", + argv[0]); + exit(ERROR_USAGE); + } + launch_rvinterf(); + } else { + if (rvinterf_Bopt || rvinterf_lopt || rvinterf_wopt) { + fprintf(stderr, +"%s error: -B, -l and -w options are meaningful only when launching rvinterf\n", + argv[0]); + exit(ERROR_USAGE); + } + connect_local_socket(); + } + if (argc != optind + 1) { + fprintf(stderr, "usage: %s [options] framebuffer_base_addr\n", + argv[0]); + exit(ERROR_USAGE); + } + framebuffer_base_addr = strtoul(argv[optind], 0, 16); + + for (;;) + fb_poll(); +}