ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/aed.c
Revision: 2.4
Committed: Tue Feb 25 02:47:22 2003 UTC (21 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R5
Changes since 2.3: +1 -56 lines
Log Message:
Replaced inline copyright notice with #include "copyright.h"

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id$";
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 "driver.h"
13
14 #include "color.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 int aed_close(), aed_clear(), aed_paintr(),
57 aed_getcur(), aed_comout(), aed_errout();
58
59 static struct driver aed_driver = {
60 aed_close, aed_clear, aed_paintr, aed_getcur,
61 aed_comout, NULL, NULL,
62 1.0, NCOLS, NROWS
63 };
64
65
66 struct driver *
67 aed_init(name, id) /* open AED */
68 char *name, *id;
69 {
70 if (ttyset(&aed_driver, fileno(stdin)) < 0) { /* set tty driver */
71 eputs("cannot access terminal\n");
72 return(NULL);
73 }
74 command(RST); /* reset AED */
75 longwait(2);
76 command(OPT);
77 byte(6); byte(1); /* AED command set */
78 command(SEN);
79 string(AEDFMT);
80 command(SCS); /* set console status */
81 byte(CSTAT);
82 command(SCC); /* set cursor type */
83 byte(BLK); byte(WHT); byte(15);
84 command(SCP);
85 byte('+'); byte(0); byte(1);
86 make_gmap(GAMMA); /* make color map */
87 erract[USER].pf = /* set error vector */
88 erract[SYSTEM].pf =
89 erract[INTERNAL].pf =
90 erract[CONSISTENCY].pf = aed_errout;
91 erract[COMMAND].pf = aed_errout;
92 if (erract[WARNING].pf != NULL)
93 erract[WARNING].pf = aed_errout;
94 return(&aed_driver);
95 }
96
97
98 static
99 aed_close() /* close AED */
100 {
101 erract[USER].pf = /* reset error vector */
102 erract[SYSTEM].pf =
103 erract[INTERNAL].pf =
104 erract[CONSISTENCY].pf = eputs;
105 erract[COMMAND].pf = NULL;
106 if (erract[WARNING].pf != NULL)
107 erract[WARNING].pf = wputs;
108 aedsetcap(0, 0); /* go to bottom */
109 command(SEC);
110 byte(WHT); /* white text */
111 byte(END);
112 byte('\n'); /* scroll */
113 flush();
114 ttydone();
115 }
116
117
118 static
119 aed_clear(x, y) /* clear AED */
120 int x, y;
121 {
122 command(FFD);
123 new_ctab(NCOLORS); /* init color table */
124 flush();
125 }
126
127
128 static
129 aed_paintr(col, xmin, ymin, xmax, ymax) /* paint a rectangle */
130 COLOR col;
131 int xmin, ymin, xmax, ymax;
132 {
133 extern int anewcolr();
134 int ndx;
135
136 ndx = get_pixel(col, anewcolr); /* calls anewcolr() */
137 command(SEC); /* draw rectangle */
138 byte(ndx+MINPIX);
139 aedsetcap(xmin, ymin+COMHT);
140 command(DFR);
141 aedcoord(xmax-1, ymax+(-1+COMHT));
142 flush();
143 }
144
145
146 static int
147 aed_getcur(xp, yp) /* get cursor position */
148 int *xp, *yp;
149 {
150 int com;
151
152 command(EJC); /* enable cursor */
153 com = getch(); /* get key */
154 command(DJC); /* disable cursor */
155 aedgetcap(xp, yp); /* get cursor position */
156 *yp -= COMHT; /* convert coordinates */
157 return(com); /* return key hit */
158 }
159
160
161 static
162 aed_comout(out) /* output to command line */
163 register char *out;
164 {
165 static int newl = 1;
166 static int inmsg = 0;
167
168 while (*out) {
169 if (newl) { /* new line */
170 command(SEC);
171 byte(BLK);
172 aedsetcap(0, 0);
173 command(DFR);
174 aedcoord(NCOLS-1, COMHT-1);
175 aedsetcap(1, 4);
176 command(SEC); /* white text */
177 byte(WHT);
178 byte(END);
179 newl = 0;
180 }
181 switch (*out) {
182 case '\n': /* end of line */
183 newl = 1;
184 /* fall through */
185 case '\r':
186 inmsg = 0;
187 byte('\r');
188 break;
189 case '\b': /* back space */
190 if (inmsg > 0 && --inmsg < COMCW)
191 byte('\b');
192 break;
193 default: /* character */
194 if (inmsg++ < COMCW)
195 byte(*out);
196 break;
197 }
198 out++;
199 }
200 flush();
201 }
202
203
204 static
205 aed_errout(msg) /* print an error message */
206 char *msg;
207 {
208 aed_comout(msg);
209 if (*msg && msg[strlen(msg)-1] == '\n')
210 longwait(2);
211 }
212
213
214 /*
215 * aedsetcap - sets AED's current access pointer to (x, y).
216 */
217
218 static
219 aedsetcap(x, y)
220 register int x, y;
221 {
222 command(MOV);
223 aedcoord(x, y);
224 }
225
226 /*
227 * aedcoord - puts out an (x, y) coordinate in AED 8 bit format.
228 */
229
230 static
231 aedcoord(x, y)
232 register int x, y;
233 {
234 byte(((x >> 4) & 0x30) | ((y >> 8) & 0x3));
235 byte(x & 0xff);
236 byte(y & 0xff);
237 }
238
239
240 static
241 aedgetcap(xp, yp) /* get cursor postion */
242 int *xp, *yp;
243 {
244 register int c;
245 /* get cursor postition */
246 command(RCP);
247 flush();
248 c = getch();
249 *xp = (c & 0x30) << 4;
250 *yp = (c & 0x3) << 8;
251 *xp |= getch();
252 *yp |= getch();
253 }
254
255
256 static
257 anewcolr(index, r, g, b) /* enter a color into our table */
258 int index;
259 int r, g, b;
260 {
261 command(SCT);
262 byte((index+MINPIX)&255);
263 byte(1);
264 byte(r);
265 byte(g);
266 byte(b);
267 flush();
268 }
269
270
271 static
272 longwait(t) /* longer wait */
273 int t;
274 {
275 flush();
276 sleep(t);
277 }