FreeCalypso > hg > freecalypso-sw
changeset 907:7a189b7bbd67
lcdemu: input processing implemented, compiles
author | Space Falcon <falcon@ivan.Harhan.ORG> |
---|---|
date | Mon, 07 Sep 2015 10:35:20 +0000 |
parents | 69623c4cbf6c |
children | ed5dcc53e0b3 |
files | lcdemu/process.c lcdemu/ximage.c |
diffstat | 2 files changed, 76 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/lcdemu/process.c Mon Sep 07 10:18:39 2015 +0000 +++ b/lcdemu/process.c Mon Sep 07 10:35:20 2015 +0000 @@ -3,6 +3,7 @@ */ #include <stdio.h> +#include <stdint.h> #include <stdlib.h> #include <ctype.h> #include <string.h> @@ -12,6 +13,80 @@ #include <X11/Xutil.h> #include "globals.h" +#define MAX_WIDTH 176 + +static unsigned +hexdecode(str) + char *str; +{ + unsigned accum = 0; + int i, c, n; + + for (i = 0; i < 4; i++) { + c = str[i]; + if (isdigit(c)) + n = c - '0'; + else if (isupper(c)) + n = c - 'A' + 10; + else + n = c - 'a' + 10; + accum <<= 4; + accum |= n; + } + return(accum); +} + +process_input_line(line) + char *line; +{ + int blitrow, blitcol, npix; + uint16_t pix16[MAX_WIDTH]; + char *cp; + XImage *xi; + + for (cp = line; isspace(*cp); cp++) + ; + if (!isdigit(*cp)) { +inv: fprintf(stderr, "fc-lcdemu: invalid input line\n"); + exit(1); + } + blitrow = atoi(cp); + while (isdigit(*cp)) + cp++; + if (!isspace(*cp)) + goto inv; + while (isspace(*cp)) + cp++; + if (!isdigit(*cp)) + goto inv; + blitcol = atoi(cp); + while (isdigit(*cp)) + cp++; + if (!isspace(*cp)) + goto inv; + while (isspace(*cp)) + cp++; + if (!isxdigit(*cp)) + goto inv; + for (npix = 0; *cp; ) { + if (!isxdigit(cp[0]) || !isxdigit(cp[1]) || + !isxdigit(cp[2]) || !isxdigit(cp[3])) + goto inv; + if (npix >= MAX_WIDTH) { + fprintf(stderr, + "fc-lcdemu error: input line exceeds MAX_WIDTH of %d pixels\n", + MAX_WIDTH); + exit(1); + } + pix16[npix++] = hexdecode(cp); + cp += 4; + } + xi = convert_function(pix16, npix); + XPutImage(mydisplay, mainwindow, mainwingc, xi, 0, 0, blitcol, blitrow, + npix, 1); + XDestroyImage(xi); +} + input_on_stdin(inbuf, incount) char *inbuf; { @@ -31,9 +106,3 @@ linebuf[linesz++] = *cp; } } - -process_input_line(line) - char *line; -{ - printf("Got input line: %s\n", line); -}
--- a/lcdemu/ximage.c Mon Sep 07 10:18:39 2015 +0000 +++ b/lcdemu/ximage.c Mon Sep 07 10:35:20 2015 +0000 @@ -52,7 +52,7 @@ break; default: fprintf(stderr, -"error: fc-ledemu has not been adapted for X11 depth != 24, yours is %d\n", +"error: fc-lcdemu has not been adapted for X11 depth != 24, yours is %d\n", display_depth); exit(1); }