view lcdpoll/main.c @ 10:ad0d9f7c06e9 default tip

README: update for the present situation
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 29 Dec 2019 23:01:26 +0000
parents 45c81216d964
children
line wrap: on
line source

/*
 * 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);
	putchar('\n');
}

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();
}