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