FreeCalypso > hg > freecalypso-sw
annotate lcdemu/process.c @ 1010:658fe6f1880f
rvinterf/lowlevel: handle TCH packet type in rvinterf and rvtdump
author | Mychaela Falconia <falcon@ivan.Harhan.ORG> |
---|---|
date | Sun, 20 Mar 2016 20:35:17 +0000 |
parents | 7a189b7bbd67 |
children |
rev | line source |
---|---|
903
312778104f54
lcdemu started, compiles and runs w/o actual functionality
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /* |
312778104f54
lcdemu started, compiles and runs w/o actual functionality
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 * Processing of LCD output (input to us) |
312778104f54
lcdemu started, compiles and runs w/o actual functionality
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 */ |
312778104f54
lcdemu started, compiles and runs w/o actual functionality
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 |
312778104f54
lcdemu started, compiles and runs w/o actual functionality
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 #include <stdio.h> |
907
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
6 #include <stdint.h> |
903
312778104f54
lcdemu started, compiles and runs w/o actual functionality
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 #include <stdlib.h> |
312778104f54
lcdemu started, compiles and runs w/o actual functionality
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 #include <ctype.h> |
312778104f54
lcdemu started, compiles and runs w/o actual functionality
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 #include <string.h> |
312778104f54
lcdemu started, compiles and runs w/o actual functionality
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 #include <strings.h> |
312778104f54
lcdemu started, compiles and runs w/o actual functionality
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 #include <X11/Xlib.h> |
312778104f54
lcdemu started, compiles and runs w/o actual functionality
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 #include <X11/Xresource.h> |
312778104f54
lcdemu started, compiles and runs w/o actual functionality
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 #include <X11/Xutil.h> |
312778104f54
lcdemu started, compiles and runs w/o actual functionality
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 #include "globals.h" |
312778104f54
lcdemu started, compiles and runs w/o actual functionality
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 |
907
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
16 #define MAX_WIDTH 176 |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
17 |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
18 static unsigned |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
19 hexdecode(str) |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
20 char *str; |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
21 { |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
22 unsigned accum = 0; |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
23 int i, c, n; |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
24 |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
25 for (i = 0; i < 4; i++) { |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
26 c = str[i]; |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
27 if (isdigit(c)) |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
28 n = c - '0'; |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
29 else if (isupper(c)) |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
30 n = c - 'A' + 10; |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
31 else |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
32 n = c - 'a' + 10; |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
33 accum <<= 4; |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
34 accum |= n; |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
35 } |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
36 return(accum); |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
37 } |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
38 |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
39 process_input_line(line) |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
40 char *line; |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
41 { |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
42 int blitrow, blitcol, npix; |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
43 uint16_t pix16[MAX_WIDTH]; |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
44 char *cp; |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
45 XImage *xi; |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
46 |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
47 for (cp = line; isspace(*cp); cp++) |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
48 ; |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
49 if (!isdigit(*cp)) { |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
50 inv: fprintf(stderr, "fc-lcdemu: invalid input line\n"); |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
51 exit(1); |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
52 } |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
53 blitrow = atoi(cp); |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
54 while (isdigit(*cp)) |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
55 cp++; |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
56 if (!isspace(*cp)) |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
57 goto inv; |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
58 while (isspace(*cp)) |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
59 cp++; |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
60 if (!isdigit(*cp)) |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
61 goto inv; |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
62 blitcol = atoi(cp); |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
63 while (isdigit(*cp)) |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
64 cp++; |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
65 if (!isspace(*cp)) |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
66 goto inv; |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
67 while (isspace(*cp)) |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
68 cp++; |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
69 if (!isxdigit(*cp)) |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
70 goto inv; |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
71 for (npix = 0; *cp; ) { |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
72 if (!isxdigit(cp[0]) || !isxdigit(cp[1]) || |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
73 !isxdigit(cp[2]) || !isxdigit(cp[3])) |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
74 goto inv; |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
75 if (npix >= MAX_WIDTH) { |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
76 fprintf(stderr, |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
77 "fc-lcdemu error: input line exceeds MAX_WIDTH of %d pixels\n", |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
78 MAX_WIDTH); |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
79 exit(1); |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
80 } |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
81 pix16[npix++] = hexdecode(cp); |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
82 cp += 4; |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
83 } |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
84 xi = convert_function(pix16, npix); |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
85 XPutImage(mydisplay, mainwindow, mainwingc, xi, 0, 0, blitcol, blitrow, |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
86 npix, 1); |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
87 XDestroyImage(xi); |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
88 } |
7a189b7bbd67
lcdemu: input processing implemented, compiles
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
905
diff
changeset
|
89 |
903
312778104f54
lcdemu started, compiles and runs w/o actual functionality
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
90 input_on_stdin(inbuf, incount) |
312778104f54
lcdemu started, compiles and runs w/o actual functionality
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
91 char *inbuf; |
312778104f54
lcdemu started, compiles and runs w/o actual functionality
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
92 { |
905
841982f31be3
lcdemu: got to input lines
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
903
diff
changeset
|
93 char *input_end = inbuf + incount; |
841982f31be3
lcdemu: got to input lines
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
903
diff
changeset
|
94 static char linebuf[1024]; |
841982f31be3
lcdemu: got to input lines
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
903
diff
changeset
|
95 static int linesz; |
841982f31be3
lcdemu: got to input lines
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
903
diff
changeset
|
96 char *cp; |
841982f31be3
lcdemu: got to input lines
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
903
diff
changeset
|
97 |
841982f31be3
lcdemu: got to input lines
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
903
diff
changeset
|
98 for (cp = inbuf; cp < input_end; cp++) { |
841982f31be3
lcdemu: got to input lines
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
903
diff
changeset
|
99 if (*cp == '\n') { |
841982f31be3
lcdemu: got to input lines
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
903
diff
changeset
|
100 linebuf[linesz] = '\0'; |
841982f31be3
lcdemu: got to input lines
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
903
diff
changeset
|
101 process_input_line(linebuf); |
841982f31be3
lcdemu: got to input lines
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
903
diff
changeset
|
102 linesz = 0; |
841982f31be3
lcdemu: got to input lines
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
903
diff
changeset
|
103 continue; |
841982f31be3
lcdemu: got to input lines
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
903
diff
changeset
|
104 } |
841982f31be3
lcdemu: got to input lines
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
903
diff
changeset
|
105 if (linesz < sizeof(linebuf) - 1) |
841982f31be3
lcdemu: got to input lines
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
903
diff
changeset
|
106 linebuf[linesz++] = *cp; |
841982f31be3
lcdemu: got to input lines
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
903
diff
changeset
|
107 } |
903
312778104f54
lcdemu started, compiles and runs w/o actual functionality
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
108 } |