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