| 1 |
greg |
1.1 |
#ifndef lint
|
| 2 |
greg |
1.5 |
static const char RCSid[] = "$Id: aed5.c,v 1.4 2003/11/15 02:13:36 schorsch Exp $";
|
| 3 |
greg |
1.1 |
#endif
|
| 4 |
|
|
/*
|
| 5 |
|
|
* aed.c - driver for AED 512 terminal.
|
| 6 |
|
|
*
|
| 7 |
|
|
* 7/8/86
|
| 8 |
|
|
*/
|
| 9 |
|
|
|
| 10 |
|
|
#include <fcntl.h>
|
| 11 |
|
|
|
| 12 |
schorsch |
1.3 |
#include "platform.h"
|
| 13 |
|
|
#include "rtprocess.h"
|
| 14 |
greg |
1.1 |
#include "meta.h"
|
| 15 |
|
|
|
| 16 |
|
|
|
| 17 |
|
|
/* AED command characters */
|
| 18 |
|
|
|
| 19 |
|
|
#define AEDFMT "1888N" /* Format string to send to AED */
|
| 20 |
|
|
#define SCT 75 /* Set color lookup table */
|
| 21 |
|
|
#define SEC 67 /* Set color for vector drawing */
|
| 22 |
|
|
#define SBC 91 /* Set background color */
|
| 23 |
|
|
#define MOV 81 /* Set CAP (current access pointer) to x, y */
|
| 24 |
|
|
#define MVR 105 /* Set CAP relative */
|
| 25 |
|
|
#define DVA 65 /* Draw vector to new CAP x, y */
|
| 26 |
|
|
#define DVR 108 /* Draw vector relative */
|
| 27 |
|
|
#define WHR 92 /* Write horizontal runs */
|
| 28 |
|
|
#define OPT 40 /* Miscellaneous terminal control */
|
| 29 |
|
|
#define SEN 71 /* Set encoding types */
|
| 30 |
|
|
#define RST 48 /* Reset terminal */
|
| 31 |
|
|
#define FFD 12 /* Clear screen */
|
| 32 |
|
|
#define SCS 96 /* Set status */
|
| 33 |
|
|
#define DAI 114 /* Define area of interest */
|
| 34 |
|
|
#define EJC 85 /* Enable Joystick cursor positioning */
|
| 35 |
|
|
#define DJC 100 /* Disable Joystick cursor positioning */
|
| 36 |
|
|
#define SCC 99 /* Set Cursor Colors */
|
| 37 |
|
|
#define SCP 93 /* Set Cursor Parameters */
|
| 38 |
|
|
#define RCP 106 /* Read Cursor Position */
|
| 39 |
|
|
#define SAP 94 /* Set alphanumeric parameters */
|
| 40 |
|
|
#define SLS 49 /* Set Line Style */
|
| 41 |
|
|
#define DFR 111 /* Draw Filled Rectangle */
|
| 42 |
|
|
#define MAXRLEN 255 /* Maximum runlength for a span */
|
| 43 |
|
|
#define NUL 0 /* Null terminates run sequences */
|
| 44 |
|
|
#define ESC 27 /* Escape starts a command sequence */
|
| 45 |
|
|
#define END 1 /* Ctrl-A used to terminate command mode */
|
| 46 |
|
|
|
| 47 |
|
|
#define command(c) (putc(ESC, stdout), putc(c, stdout))
|
| 48 |
|
|
#define byte(b) putc(b, stdout)
|
| 49 |
|
|
#define ascii(c) putc(c, stdout)
|
| 50 |
|
|
|
| 51 |
|
|
#define BKGCOL 7 /* Background color (white) */
|
| 52 |
|
|
|
| 53 |
|
|
#define NROWS 512 /* # rows for output */
|
| 54 |
|
|
#define NCOLS 512 /* # columns for output */
|
| 55 |
|
|
|
| 56 |
|
|
#define xconv(x) CONV(x, NCOLS)
|
| 57 |
|
|
#define yconv(y) CONV(y, NROWS)
|
| 58 |
|
|
|
| 59 |
|
|
#define XCOM "pexpand +vOCIs -tpSUR %s"
|
| 60 |
|
|
|
| 61 |
|
|
char *progname;
|
| 62 |
|
|
|
| 63 |
|
|
static short newpage = TRUE;
|
| 64 |
|
|
|
| 65 |
|
|
static int curx = -1, /* current position */
|
| 66 |
|
|
cury = -1;
|
| 67 |
|
|
|
| 68 |
|
|
static int curcol = -1; /* current color */
|
| 69 |
|
|
|
| 70 |
|
|
static short curmod = -1; /* current line drawing mode */
|
| 71 |
|
|
|
| 72 |
|
|
static short cmode[4] = {0, 1, 2, 4}; /* color map */
|
| 73 |
|
|
|
| 74 |
|
|
static short lmode[4] = {255, 15, 85, 39}; /* line map */
|
| 75 |
|
|
|
| 76 |
|
|
static PRIMITIVE nextp;
|
| 77 |
|
|
|
| 78 |
schorsch |
1.4 |
static void init(void);
|
| 79 |
|
|
static void plot(FILE *infp);
|
| 80 |
|
|
static void doprim(register PRIMITIVE *p);
|
| 81 |
|
|
static void doglobal(PRIMITIVE *g);
|
| 82 |
|
|
static void longwait(int t);
|
| 83 |
|
|
static void shortwait(int t);
|
| 84 |
|
|
static void plotlseg(register PRIMITIVE *p);
|
| 85 |
|
|
static void printstr(register PRIMITIVE *p);
|
| 86 |
|
|
static void fillrect(register PRIMITIVE *p);
|
| 87 |
|
|
static void setcolor(int cn);
|
| 88 |
|
|
static void move(int x, int y);
|
| 89 |
|
|
static void draw(int x, int y);
|
| 90 |
|
|
static void aedcoord(register int x, register int y);
|
| 91 |
greg |
1.1 |
|
| 92 |
|
|
|
| 93 |
schorsch |
1.4 |
int
|
| 94 |
greg |
1.1 |
main(argc, argv)
|
| 95 |
|
|
int argc;
|
| 96 |
|
|
char **argv;
|
| 97 |
|
|
{
|
| 98 |
schorsch |
1.3 |
FILE *fp;
|
| 99 |
greg |
1.1 |
char comargs[200], shcom[300];
|
| 100 |
|
|
short condonly = FALSE, conditioned = FALSE;
|
| 101 |
|
|
|
| 102 |
|
|
progname = *argv++;
|
| 103 |
|
|
argc--;
|
| 104 |
|
|
|
| 105 |
|
|
while (argc && **argv == '-') {
|
| 106 |
|
|
switch (*(*argv+1)) {
|
| 107 |
|
|
case 'c':
|
| 108 |
|
|
condonly = TRUE;
|
| 109 |
|
|
break;
|
| 110 |
|
|
case 'r':
|
| 111 |
|
|
conditioned = TRUE;
|
| 112 |
|
|
break;
|
| 113 |
|
|
default:
|
| 114 |
|
|
error(WARNING, "unknown option");
|
| 115 |
|
|
break;
|
| 116 |
|
|
}
|
| 117 |
|
|
argv++;
|
| 118 |
|
|
argc--;
|
| 119 |
|
|
}
|
| 120 |
|
|
|
| 121 |
|
|
if (conditioned) {
|
| 122 |
|
|
init();
|
| 123 |
|
|
if (argc)
|
| 124 |
|
|
while (argc) {
|
| 125 |
|
|
fp = efopen(*argv, "r");
|
| 126 |
|
|
plot(fp);
|
| 127 |
|
|
fclose(fp);
|
| 128 |
|
|
argv++;
|
| 129 |
|
|
argc--;
|
| 130 |
|
|
}
|
| 131 |
|
|
else
|
| 132 |
|
|
plot(stdin);
|
| 133 |
|
|
} else {
|
| 134 |
|
|
comargs[0] = '\0';
|
| 135 |
|
|
while (argc) {
|
| 136 |
|
|
strcat(comargs, " ");
|
| 137 |
|
|
strcat(comargs, *argv);
|
| 138 |
|
|
argv++;
|
| 139 |
|
|
argc--;
|
| 140 |
|
|
}
|
| 141 |
|
|
sprintf(shcom, XCOM, comargs);
|
| 142 |
|
|
if (condonly)
|
| 143 |
|
|
return(system(shcom));
|
| 144 |
|
|
else {
|
| 145 |
|
|
init();
|
| 146 |
|
|
if ((fp = popen(shcom, "r")) == NULL)
|
| 147 |
|
|
error(SYSTEM, "cannot execute input filter");
|
| 148 |
|
|
plot(fp);
|
| 149 |
|
|
return(pclose(fp));
|
| 150 |
|
|
}
|
| 151 |
|
|
}
|
| 152 |
|
|
return(0);
|
| 153 |
|
|
}
|
| 154 |
|
|
|
| 155 |
|
|
|
| 156 |
|
|
|
| 157 |
|
|
|
| 158 |
schorsch |
1.4 |
static void
|
| 159 |
|
|
plot( /* plot meta-file */
|
| 160 |
|
|
FILE *infp
|
| 161 |
|
|
)
|
| 162 |
greg |
1.1 |
|
| 163 |
|
|
{
|
| 164 |
|
|
|
| 165 |
|
|
do {
|
| 166 |
|
|
readp(&nextp, infp);
|
| 167 |
|
|
while (isprim(nextp.com)) {
|
| 168 |
|
|
doprim(&nextp);
|
| 169 |
|
|
fargs(&nextp);
|
| 170 |
|
|
readp(&nextp, infp);
|
| 171 |
|
|
}
|
| 172 |
|
|
doglobal(&nextp);
|
| 173 |
|
|
fargs(&nextp);
|
| 174 |
|
|
}
|
| 175 |
|
|
while (nextp.com != PEOF);
|
| 176 |
|
|
|
| 177 |
|
|
}
|
| 178 |
|
|
|
| 179 |
|
|
|
| 180 |
|
|
|
| 181 |
|
|
|
| 182 |
schorsch |
1.4 |
static void
|
| 183 |
|
|
doglobal( /* execute a global command */
|
| 184 |
|
|
PRIMITIVE *g
|
| 185 |
|
|
)
|
| 186 |
greg |
1.1 |
|
| 187 |
|
|
{
|
| 188 |
|
|
int tty;
|
| 189 |
|
|
char c;
|
| 190 |
|
|
|
| 191 |
|
|
switch (g->com) {
|
| 192 |
|
|
|
| 193 |
|
|
case PEOF:
|
| 194 |
|
|
break;
|
| 195 |
|
|
|
| 196 |
|
|
case PDRAW:
|
| 197 |
|
|
fflush(stdout);
|
| 198 |
|
|
break;
|
| 199 |
|
|
|
| 200 |
|
|
case PEOP:
|
| 201 |
|
|
newpage = TRUE;
|
| 202 |
|
|
if (!isatty(fileno(stdout)))
|
| 203 |
|
|
break;
|
| 204 |
|
|
/* fall through */
|
| 205 |
|
|
|
| 206 |
greg |
1.2 |
case PPAUS:
|
| 207 |
greg |
1.1 |
fflush(stdout);
|
| 208 |
|
|
tty = open(TTY, O_RDWR);
|
| 209 |
|
|
if (g->args != NULL) {
|
| 210 |
|
|
write(tty, g->args, strlen(g->args));
|
| 211 |
|
|
write(tty, " - (hit return to continue)", 27);
|
| 212 |
|
|
}
|
| 213 |
|
|
else
|
| 214 |
|
|
write(tty, "\007", 1);
|
| 215 |
|
|
do {
|
| 216 |
|
|
c = '\n';
|
| 217 |
|
|
read(tty, &c, 1);
|
| 218 |
|
|
}
|
| 219 |
|
|
while (c != '\n' && c != '\r');
|
| 220 |
|
|
close(tty);
|
| 221 |
|
|
break;
|
| 222 |
|
|
|
| 223 |
|
|
default:
|
| 224 |
|
|
sprintf(errmsg, "unknown command '%c' in doglobal", g->com);
|
| 225 |
|
|
error(WARNING, errmsg);
|
| 226 |
|
|
break;
|
| 227 |
|
|
}
|
| 228 |
|
|
|
| 229 |
|
|
}
|
| 230 |
|
|
|
| 231 |
|
|
|
| 232 |
|
|
|
| 233 |
schorsch |
1.4 |
static void
|
| 234 |
|
|
doprim( /* plot primitive */
|
| 235 |
|
|
register PRIMITIVE *p
|
| 236 |
|
|
)
|
| 237 |
greg |
1.1 |
|
| 238 |
|
|
{
|
| 239 |
|
|
|
| 240 |
|
|
if (newpage) { /* clear screen */
|
| 241 |
|
|
command(FFD);
|
| 242 |
|
|
shortwait(50);
|
| 243 |
|
|
newpage = FALSE;
|
| 244 |
|
|
}
|
| 245 |
|
|
|
| 246 |
|
|
switch (p->com) {
|
| 247 |
|
|
|
| 248 |
|
|
case PLSEG:
|
| 249 |
|
|
plotlseg(p);
|
| 250 |
|
|
break;
|
| 251 |
|
|
|
| 252 |
|
|
case PMSTR:
|
| 253 |
|
|
printstr(p);
|
| 254 |
|
|
break;
|
| 255 |
|
|
|
| 256 |
|
|
case PRFILL:
|
| 257 |
|
|
fillrect(p);
|
| 258 |
|
|
break;
|
| 259 |
|
|
|
| 260 |
|
|
default:
|
| 261 |
|
|
sprintf(errmsg, "unknown command '%c' in doprim", p->com);
|
| 262 |
|
|
error(WARNING, errmsg);
|
| 263 |
|
|
return;
|
| 264 |
|
|
}
|
| 265 |
|
|
|
| 266 |
|
|
}
|
| 267 |
|
|
|
| 268 |
|
|
|
| 269 |
|
|
|
| 270 |
|
|
|
| 271 |
|
|
|
| 272 |
schorsch |
1.4 |
static void
|
| 273 |
|
|
printstr( /* output a string */
|
| 274 |
|
|
register PRIMITIVE *p
|
| 275 |
|
|
)
|
| 276 |
greg |
1.1 |
|
| 277 |
|
|
{
|
| 278 |
|
|
static int hsp[4] = {6, 5, 4, 3};
|
| 279 |
|
|
char font, size;
|
| 280 |
|
|
int hspace, vspace = 18;
|
| 281 |
|
|
|
| 282 |
|
|
hspace = hsp[(p->arg0 >> 4) & 03];
|
| 283 |
|
|
|
| 284 |
|
|
if (p->arg0 & 04)
|
| 285 |
|
|
hspace *= 2;
|
| 286 |
|
|
|
| 287 |
|
|
if (hspace > 16) {
|
| 288 |
|
|
font = '7'; size = '2';
|
| 289 |
|
|
} else if (hspace > 12) {
|
| 290 |
|
|
font = '5'; size = '2';
|
| 291 |
|
|
} else if (hspace > 8) {
|
| 292 |
|
|
font = '7'; size = '1';
|
| 293 |
|
|
} else {
|
| 294 |
|
|
font = '5'; size = '1';
|
| 295 |
|
|
}
|
| 296 |
|
|
|
| 297 |
|
|
command(SAP);
|
| 298 |
|
|
ascii(size); ascii(font);
|
| 299 |
|
|
byte(hspace); byte(vspace);
|
| 300 |
|
|
ascii('L');
|
| 301 |
|
|
|
| 302 |
|
|
setcolor(p->arg0 & 03);
|
| 303 |
|
|
|
| 304 |
|
|
move(p->xy[XMN], p->xy[YMX]);
|
| 305 |
|
|
|
| 306 |
|
|
putc(END, stdout);
|
| 307 |
|
|
fputs(p->args, stdout);
|
| 308 |
|
|
|
| 309 |
|
|
curx = -1;
|
| 310 |
|
|
cury = -1;
|
| 311 |
|
|
}
|
| 312 |
|
|
|
| 313 |
|
|
|
| 314 |
|
|
|
| 315 |
|
|
|
| 316 |
schorsch |
1.4 |
static void
|
| 317 |
|
|
plotlseg( /* plot a line segment */
|
| 318 |
|
|
register PRIMITIVE *p
|
| 319 |
|
|
)
|
| 320 |
greg |
1.1 |
|
| 321 |
|
|
{
|
| 322 |
|
|
static short right = FALSE;
|
| 323 |
|
|
int y1, y2;
|
| 324 |
|
|
short lm = (p->arg0 >> 4) & 03;
|
| 325 |
|
|
|
| 326 |
|
|
if (p->arg0 & 0100) {
|
| 327 |
|
|
y1 = p->xy[YMX];
|
| 328 |
|
|
y2 = p->xy[YMN];
|
| 329 |
|
|
}
|
| 330 |
|
|
else {
|
| 331 |
|
|
y1 = p->xy[YMN];
|
| 332 |
|
|
y2 = p->xy[YMX];
|
| 333 |
|
|
}
|
| 334 |
|
|
|
| 335 |
|
|
setcolor(p->arg0 & 03);
|
| 336 |
|
|
|
| 337 |
|
|
if (lm != curmod) {
|
| 338 |
|
|
command(SLS);
|
| 339 |
|
|
byte(lmode[lm]); byte(85);
|
| 340 |
|
|
curmod = lm;
|
| 341 |
|
|
}
|
| 342 |
|
|
|
| 343 |
|
|
if (p->xy[XMN] == curx && y1 == cury)
|
| 344 |
|
|
draw(p->xy[XMX], y2);
|
| 345 |
|
|
else if (p->xy[XMX] == curx && y2 == cury)
|
| 346 |
|
|
draw(p->xy[XMN], y1);
|
| 347 |
schorsch |
1.4 |
else if ((right = !right)) {
|
| 348 |
greg |
1.1 |
move(p->xy[XMN], y1);
|
| 349 |
|
|
draw(p->xy[XMX], y2);
|
| 350 |
|
|
} else {
|
| 351 |
|
|
move(p->xy[XMX], y2);
|
| 352 |
|
|
draw(p->xy[XMN], y1);
|
| 353 |
|
|
}
|
| 354 |
|
|
}
|
| 355 |
|
|
|
| 356 |
|
|
|
| 357 |
schorsch |
1.4 |
static void
|
| 358 |
|
|
fillrect(
|
| 359 |
|
|
register PRIMITIVE *p
|
| 360 |
|
|
)
|
| 361 |
greg |
1.1 |
|
| 362 |
|
|
{
|
| 363 |
|
|
|
| 364 |
|
|
setcolor(p->arg0 & 03);
|
| 365 |
|
|
move(p->xy[XMN], p->xy[YMN]);
|
| 366 |
|
|
curx = xconv(p->xy[XMX]);
|
| 367 |
|
|
cury = yconv(p->xy[YMX]);
|
| 368 |
|
|
command(DFR);
|
| 369 |
|
|
aedcoord(curx, cury);
|
| 370 |
|
|
|
| 371 |
|
|
}
|
| 372 |
|
|
|
| 373 |
schorsch |
1.4 |
static void
|
| 374 |
|
|
init(void) /* initialize terminal */
|
| 375 |
greg |
1.1 |
{
|
| 376 |
|
|
/* Reset AED and tell it the data format */
|
| 377 |
|
|
command(RST);
|
| 378 |
|
|
longwait(2);
|
| 379 |
|
|
command(OPT);
|
| 380 |
|
|
byte(6); byte(1); /* AED command set */
|
| 381 |
|
|
command(SEN); fputs(AEDFMT, stdout);
|
| 382 |
|
|
command(SBC); byte(BKGCOL);
|
| 383 |
|
|
}
|
| 384 |
|
|
|
| 385 |
|
|
|
| 386 |
schorsch |
1.4 |
static void
|
| 387 |
|
|
setcolor( /* set color */
|
| 388 |
|
|
int cn
|
| 389 |
|
|
)
|
| 390 |
greg |
1.1 |
{
|
| 391 |
|
|
if (cn != curcol) {
|
| 392 |
|
|
command(SEC);
|
| 393 |
|
|
byte(cmode[cn]);
|
| 394 |
|
|
curcol = cn;
|
| 395 |
|
|
}
|
| 396 |
|
|
}
|
| 397 |
|
|
|
| 398 |
|
|
|
| 399 |
schorsch |
1.4 |
static void
|
| 400 |
|
|
move( /* move to coordinate (x,y) */
|
| 401 |
|
|
int x,
|
| 402 |
|
|
int y
|
| 403 |
|
|
)
|
| 404 |
greg |
1.1 |
{
|
| 405 |
|
|
command(MOV);
|
| 406 |
|
|
aedcoord(xconv(x), yconv(y));
|
| 407 |
|
|
curx = x;
|
| 408 |
|
|
cury = y;
|
| 409 |
|
|
}
|
| 410 |
|
|
|
| 411 |
|
|
|
| 412 |
schorsch |
1.4 |
static void
|
| 413 |
|
|
draw( /* draw vector from CAP to (x,y) */
|
| 414 |
|
|
int x,
|
| 415 |
|
|
int y
|
| 416 |
|
|
)
|
| 417 |
greg |
1.1 |
{
|
| 418 |
|
|
command(DVA);
|
| 419 |
|
|
aedcoord(xconv(x), yconv(y));
|
| 420 |
|
|
curx = x;
|
| 421 |
|
|
cury = y;
|
| 422 |
|
|
}
|
| 423 |
|
|
|
| 424 |
|
|
|
| 425 |
|
|
/*
|
| 426 |
|
|
* aedcoord - puts out an (x, y) coordinate in AED 8 bit format.
|
| 427 |
|
|
*/
|
| 428 |
|
|
|
| 429 |
schorsch |
1.4 |
static void
|
| 430 |
|
|
aedcoord(
|
| 431 |
|
|
register int x,
|
| 432 |
|
|
register int y
|
| 433 |
|
|
)
|
| 434 |
greg |
1.1 |
{
|
| 435 |
|
|
putc(((x >> 4) & 0x30) | ((y >> 8) & 0x3), stdout);
|
| 436 |
|
|
putc(x & 0xff, stdout);
|
| 437 |
|
|
putc(y & 0xff, stdout);
|
| 438 |
|
|
}
|
| 439 |
|
|
|
| 440 |
|
|
|
| 441 |
schorsch |
1.4 |
static void
|
| 442 |
|
|
longwait( /* longer wait */
|
| 443 |
|
|
int t
|
| 444 |
|
|
)
|
| 445 |
greg |
1.1 |
{
|
| 446 |
|
|
fflush(stdout);
|
| 447 |
|
|
sleep(t);
|
| 448 |
|
|
}
|
| 449 |
|
|
|
| 450 |
|
|
|
| 451 |
schorsch |
1.4 |
static void
|
| 452 |
|
|
shortwait( /* shorter wait */
|
| 453 |
|
|
int t
|
| 454 |
|
|
)
|
| 455 |
greg |
1.1 |
{
|
| 456 |
|
|
register long l = t*1000;
|
| 457 |
|
|
|
| 458 |
|
|
fflush(stdout);
|
| 459 |
|
|
while (l--)
|
| 460 |
|
|
;
|
| 461 |
|
|
}
|