FreeCalypso > hg > freecalypso-ui-dev
comparison lcdemu/process.c @ 0:e7f1035f10d4
lcdemu: initial import from freecalypso-tools
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 14 Mar 2018 18:16:45 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e7f1035f10d4 |
---|---|
1 /* | |
2 * Processing of LCD output (input to us) | |
3 */ | |
4 | |
5 #include <stdio.h> | |
6 #include <stdint.h> | |
7 #include <stdlib.h> | |
8 #include <ctype.h> | |
9 #include <string.h> | |
10 #include <strings.h> | |
11 #include <X11/Xlib.h> | |
12 #include <X11/Xresource.h> | |
13 #include <X11/Xutil.h> | |
14 #include "globals.h" | |
15 | |
16 #define MAX_WIDTH 176 | |
17 | |
18 static unsigned | |
19 hexdecode(str) | |
20 char *str; | |
21 { | |
22 unsigned accum = 0; | |
23 int i, c, n; | |
24 | |
25 for (i = 0; i < 4; i++) { | |
26 c = str[i]; | |
27 if (isdigit(c)) | |
28 n = c - '0'; | |
29 else if (isupper(c)) | |
30 n = c - 'A' + 10; | |
31 else | |
32 n = c - 'a' + 10; | |
33 accum <<= 4; | |
34 accum |= n; | |
35 } | |
36 return(accum); | |
37 } | |
38 | |
39 process_input_line(line) | |
40 char *line; | |
41 { | |
42 int blitrow, blitcol, npix; | |
43 uint16_t pix16[MAX_WIDTH]; | |
44 char *cp; | |
45 XImage *xi; | |
46 | |
47 for (cp = line; isspace(*cp); cp++) | |
48 ; | |
49 if (!isdigit(*cp)) { | |
50 inv: fprintf(stderr, "fc-lcdemu: invalid input line\n"); | |
51 exit(1); | |
52 } | |
53 blitrow = atoi(cp); | |
54 while (isdigit(*cp)) | |
55 cp++; | |
56 if (!isspace(*cp)) | |
57 goto inv; | |
58 while (isspace(*cp)) | |
59 cp++; | |
60 if (!isdigit(*cp)) | |
61 goto inv; | |
62 blitcol = atoi(cp); | |
63 while (isdigit(*cp)) | |
64 cp++; | |
65 if (!isspace(*cp)) | |
66 goto inv; | |
67 while (isspace(*cp)) | |
68 cp++; | |
69 if (!isxdigit(*cp)) | |
70 goto inv; | |
71 for (npix = 0; *cp; ) { | |
72 if (!isxdigit(cp[0]) || !isxdigit(cp[1]) || | |
73 !isxdigit(cp[2]) || !isxdigit(cp[3])) | |
74 goto inv; | |
75 if (npix >= MAX_WIDTH) { | |
76 fprintf(stderr, | |
77 "fc-lcdemu error: input line exceeds MAX_WIDTH of %d pixels\n", | |
78 MAX_WIDTH); | |
79 exit(1); | |
80 } | |
81 pix16[npix++] = hexdecode(cp); | |
82 cp += 4; | |
83 } | |
84 xi = convert_function(pix16, npix); | |
85 XPutImage(mydisplay, mainwindow, mainwingc, xi, 0, 0, blitcol, blitrow, | |
86 npix, 1); | |
87 XDestroyImage(xi); | |
88 } | |
89 | |
90 input_on_stdin(inbuf, incount) | |
91 char *inbuf; | |
92 { | |
93 char *input_end = inbuf + incount; | |
94 static char linebuf[1024]; | |
95 static int linesz; | |
96 char *cp; | |
97 | |
98 for (cp = inbuf; cp < input_end; cp++) { | |
99 if (*cp == '\n') { | |
100 linebuf[linesz] = '\0'; | |
101 process_input_line(linebuf); | |
102 linesz = 0; | |
103 continue; | |
104 } | |
105 if (linesz < sizeof(linebuf) - 1) | |
106 linebuf[linesz++] = *cp; | |
107 } | |
108 } |