ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/aed.c
Revision: 2.5
Committed: Wed Aug 20 10:00:09 2003 UTC (20 years, 8 months ago) by schorsch
Content type: text/plain
Branch: MAIN
Changes since 2.4: +24 -16 lines
Log Message:
Continued ansification (though aed.c depends on tty.c, which doesn't work on Linux).

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: aed.c,v 2.4 2003/02/25 02:47:22 greg Exp $";
3 #endif
4 /*
5 * aed.c - driver for AED 512 terminal.
6 */
7
8 #include "copyright.h"
9
10 #include <stdio.h>
11
12 #include "rterror.h"
13 #include "color.h"
14 #include "driver.h"
15
16
17 /* AED command characters */
18
19 #define AEDFMT "1888N" /* Format string to send to AED */
20 #define CSTAT 0100 /* Console status: lower case */
21 #define SCT 75 /* Set color lookup table */
22 #define SEC 67 /* Set color for vector drawing */
23 #define MOV 81 /* Set CAP (current access pointer) to x, y */
24 #define OPT 40 /* Miscellaneous terminal control */
25 #define SEN 71 /* Set encoding types */
26 #define RST 48 /* Reset terminal */
27 #define FFD 12 /* Clear screen */
28 #define EJC 85 /* Enable Joystick cursor positioning */
29 #define DJC 100 /* Disable Joystick cursor positioning */
30 #define SCC 99 /* Set Cursor Colors */
31 #define SCP 93 /* Set Cursor Parameters */
32 #define DFR 111 /* Draw Filled Rectangle */
33 #define RCP 106 /* Read Cursor Position */
34 #define ESC 27 /* Escape starts a command sequence */
35 #define SCS 96 /* Set Console Status */
36 #define END 1 /* Ctrl-A used to terminate command mode */
37
38 #define BLK 0 /* color table entry for black */
39 #define WHT 7 /* color table entry for white */
40
41 #define command(c) (putc(ESC, stdout), putc(c, stdout))
42 #define byte(b) putc(b, stdout)
43 #define string(s) fputs(s, stdout)
44 #define flush() fflush(stdout)
45
46 #define GAMMA 2.5 /* exponent for color correction */
47
48 #define NCOLORS 248 /* our color table size */
49 #define MINPIX 8 /* minimum hardware color */
50
51 #define NCOLS 512 /* maximum # columns for output */
52 #define NROWS 483-COMHT /* maximum # rows for output */
53 #define COMHT 16 /* height of command line */
54 #define COMCW 63 /* maximum chars on command line */
55
56 static void aed_close(void);
57 static void aed_errout(char*);
58 static void longwait(int t);
59 static void aedgetcap(int *xp, int *yp);
60 static void aedsetcap(int x, int y);
61 static void anewcolr(int index, int r,int g,int b);
62 static void aed_paintr(COLOR col, int xmin, int ymin, int xmax, int ymax);
63 static void aedcoord(int x, int y);
64 static void aed_comout(char *out);
65 static int aed_getcur(int *xp, int *yp);
66 static aed_clear(int x, int y);
67
68 static struct driver aed_driver = {
69 aed_close, aed_clear, aed_paintr, aed_getcur,
70 aed_comout, NULL, NULL,
71 1.0, NCOLS, NROWS
72 };
73
74
75 struct driver *
76 aed_init(name, id) /* open AED */
77 char *name, *id;
78 {
79 if (ttyset(&aed_driver, fileno(stdin)) < 0) { /* set tty driver */
80 eputs("cannot access terminal\n");
81 return(NULL);
82 }
83 command(RST); /* reset AED */
84 longwait(2);
85 command(OPT);
86 byte(6); byte(1); /* AED command set */
87 command(SEN);
88 string(AEDFMT);
89 command(SCS); /* set console status */
90 byte(CSTAT);
91 command(SCC); /* set cursor type */
92 byte(BLK); byte(WHT); byte(15);
93 command(SCP);
94 byte('+'); byte(0); byte(1);
95 make_gmap(GAMMA); /* make color map */
96 erract[USER].pf = /* set error vector */
97 erract[SYSTEM].pf =
98 erract[INTERNAL].pf =
99 erract[CONSISTENCY].pf = aed_errout;
100 erract[COMMAND].pf = aed_errout;
101 if (erract[WARNING].pf != NULL)
102 erract[WARNING].pf = aed_errout;
103 return(&aed_driver);
104 }
105
106
107 static void
108 aed_close(void) /* close AED */
109 {
110 erract[USER].pf = /* reset error vector */
111 erract[SYSTEM].pf =
112 erract[INTERNAL].pf =
113 erract[CONSISTENCY].pf = eputs;
114 erract[COMMAND].pf = NULL;
115 if (erract[WARNING].pf != NULL)
116 erract[WARNING].pf = wputs;
117 aedsetcap(0, 0); /* go to bottom */
118 command(SEC);
119 byte(WHT); /* white text */
120 byte(END);
121 byte('\n'); /* scroll */
122 flush();
123 ttydone();
124 }
125
126
127 static
128 aed_clear(x, y) /* clear AED */
129 int x, y;
130 {
131 command(FFD);
132 new_ctab(NCOLORS); /* init color table */
133 flush();
134 }
135
136
137 static void
138 aed_paintr(col, xmin, ymin, xmax, ymax) /* paint a rectangle */
139 COLOR col;
140 int xmin, ymin, xmax, ymax;
141 {
142 int ndx;
143
144 ndx = get_pixel(col, anewcolr); /* calls anewcolr() */
145 command(SEC); /* draw rectangle */
146 byte(ndx+MINPIX);
147 aedsetcap(xmin, ymin+COMHT);
148 command(DFR);
149 aedcoord(xmax-1, ymax+(-1+COMHT));
150 flush();
151 }
152
153
154 static int
155 aed_getcur(xp, yp) /* get cursor position */
156 int *xp, *yp;
157 {
158 int com;
159
160 command(EJC); /* enable cursor */
161 com = getch(); /* get key */
162 command(DJC); /* disable cursor */
163 aedgetcap(xp, yp); /* get cursor position */
164 *yp -= COMHT; /* convert coordinates */
165 return(com); /* return key hit */
166 }
167
168
169 static void
170 aed_comout(out) /* output to command line */
171 register char *out;
172 {
173 static int newl = 1;
174 static int inmsg = 0;
175
176 while (*out) {
177 if (newl) { /* new line */
178 command(SEC);
179 byte(BLK);
180 aedsetcap(0, 0);
181 command(DFR);
182 aedcoord(NCOLS-1, COMHT-1);
183 aedsetcap(1, 4);
184 command(SEC); /* white text */
185 byte(WHT);
186 byte(END);
187 newl = 0;
188 }
189 switch (*out) {
190 case '\n': /* end of line */
191 newl = 1;
192 /* fall through */
193 case '\r':
194 inmsg = 0;
195 byte('\r');
196 break;
197 case '\b': /* back space */
198 if (inmsg > 0 && --inmsg < COMCW)
199 byte('\b');
200 break;
201 default: /* character */
202 if (inmsg++ < COMCW)
203 byte(*out);
204 break;
205 }
206 out++;
207 }
208 flush();
209 }
210
211
212 static void
213 aed_errout(msg) /* print an error message */
214 char *msg;
215 {
216 aed_comout(msg);
217 if (*msg && msg[strlen(msg)-1] == '\n')
218 longwait(2);
219 }
220
221
222 /*
223 * aedsetcap - sets AED's current access pointer to (x, y).
224 */
225
226 static void
227 aedsetcap(x, y)
228 register int x, y;
229 {
230 command(MOV);
231 aedcoord(x, y);
232 }
233
234 /*
235 * aedcoord - puts out an (x, y) coordinate in AED 8 bit format.
236 */
237
238 static void
239 aedcoord(x, y)
240 register int x, y;
241 {
242 byte(((x >> 4) & 0x30) | ((y >> 8) & 0x3));
243 byte(x & 0xff);
244 byte(y & 0xff);
245 }
246
247
248 static void
249 aedgetcap(xp, yp) /* get cursor postion */
250 int *xp, *yp;
251 {
252 register int c;
253 /* get cursor postition */
254 command(RCP);
255 flush();
256 c = getch();
257 *xp = (c & 0x30) << 4;
258 *yp = (c & 0x3) << 8;
259 *xp |= getch();
260 *yp |= getch();
261 }
262
263
264 static void
265 anewcolr(index, r, g, b) /* enter a color into our table */
266 int index;
267 int r, g, b;
268 {
269 command(SCT);
270 byte((index+MINPIX)&255);
271 byte(1);
272 byte(r);
273 byte(g);
274 byte(b);
275 flush();
276 }
277
278
279 static void
280 longwait(t) /* longer wait */
281 int t;
282 {
283 flush();
284 sleep(t);
285 }