ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/aed.c
Revision: 1.3
Committed: Tue Oct 3 11:10:02 1989 UTC (34 years, 7 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.2: +20 -25 lines
Log Message:
Improved color table allocation, second cut.

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