ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/aed.c
Revision: 1.2
Committed: Mon Oct 2 17:12:34 1989 UTC (34 years, 7 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.1: +18 -89 lines
Log Message:
New adaptive color allocation scheme for rview

File Contents

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