| 1 |
greg |
1.1 |
#ifndef lint |
| 2 |
greg |
2.3 |
static const char RCSid[] = "$Id$"; |
| 3 |
greg |
1.1 |
#endif |
| 4 |
|
|
/* |
| 5 |
|
|
* aed.c - driver for AED 512 terminal. |
| 6 |
greg |
2.3 |
*/ |
| 7 |
|
|
|
| 8 |
|
|
/* ==================================================================== |
| 9 |
|
|
* The Radiance Software License, Version 1.0 |
| 10 |
|
|
* |
| 11 |
|
|
* Copyright (c) 1990 - 2002 The Regents of the University of California, |
| 12 |
|
|
* through Lawrence Berkeley National Laboratory. All rights reserved. |
| 13 |
|
|
* |
| 14 |
|
|
* Redistribution and use in source and binary forms, with or without |
| 15 |
|
|
* modification, are permitted provided that the following conditions |
| 16 |
|
|
* are met: |
| 17 |
|
|
* |
| 18 |
|
|
* 1. Redistributions of source code must retain the above copyright |
| 19 |
|
|
* notice, this list of conditions and the following disclaimer. |
| 20 |
|
|
* |
| 21 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright |
| 22 |
|
|
* notice, this list of conditions and the following disclaimer in |
| 23 |
|
|
* the documentation and/or other materials provided with the |
| 24 |
|
|
* distribution. |
| 25 |
|
|
* |
| 26 |
|
|
* 3. The end-user documentation included with the redistribution, |
| 27 |
|
|
* if any, must include the following acknowledgment: |
| 28 |
|
|
* "This product includes Radiance software |
| 29 |
|
|
* (http://radsite.lbl.gov/) |
| 30 |
|
|
* developed by the Lawrence Berkeley National Laboratory |
| 31 |
|
|
* (http://www.lbl.gov/)." |
| 32 |
|
|
* Alternately, this acknowledgment may appear in the software itself, |
| 33 |
|
|
* if and wherever such third-party acknowledgments normally appear. |
| 34 |
|
|
* |
| 35 |
|
|
* 4. The names "Radiance," "Lawrence Berkeley National Laboratory" |
| 36 |
|
|
* and "The Regents of the University of California" must |
| 37 |
|
|
* not be used to endorse or promote products derived from this |
| 38 |
|
|
* software without prior written permission. For written |
| 39 |
|
|
* permission, please contact [email protected]. |
| 40 |
|
|
* |
| 41 |
|
|
* 5. Products derived from this software may not be called "Radiance", |
| 42 |
|
|
* nor may "Radiance" appear in their name, without prior written |
| 43 |
|
|
* permission of Lawrence Berkeley National Laboratory. |
| 44 |
|
|
* |
| 45 |
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED |
| 46 |
|
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 47 |
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 48 |
|
|
* DISCLAIMED. IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR |
| 49 |
|
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 50 |
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 51 |
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
| 52 |
|
|
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 53 |
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 54 |
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 55 |
|
|
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 56 |
|
|
* SUCH DAMAGE. |
| 57 |
|
|
* ==================================================================== |
| 58 |
greg |
1.1 |
* |
| 59 |
greg |
2.3 |
* This software consists of voluntary contributions made by many |
| 60 |
|
|
* individuals on behalf of Lawrence Berkeley National Laboratory. For more |
| 61 |
|
|
* information on Lawrence Berkeley National Laboratory, please see |
| 62 |
|
|
* <http://www.lbl.gov/>. |
| 63 |
greg |
1.1 |
*/ |
| 64 |
|
|
|
| 65 |
|
|
#include <stdio.h> |
| 66 |
|
|
|
| 67 |
|
|
#include "driver.h" |
| 68 |
|
|
|
| 69 |
|
|
#include "color.h" |
| 70 |
|
|
|
| 71 |
|
|
|
| 72 |
|
|
/* AED command characters */ |
| 73 |
|
|
|
| 74 |
|
|
#define AEDFMT "1888N" /* Format string to send to AED */ |
| 75 |
|
|
#define CSTAT 0100 /* Console status: lower case */ |
| 76 |
|
|
#define SCT 75 /* Set color lookup table */ |
| 77 |
|
|
#define SEC 67 /* Set color for vector drawing */ |
| 78 |
|
|
#define MOV 81 /* Set CAP (current access pointer) to x, y */ |
| 79 |
|
|
#define OPT 40 /* Miscellaneous terminal control */ |
| 80 |
|
|
#define SEN 71 /* Set encoding types */ |
| 81 |
|
|
#define RST 48 /* Reset terminal */ |
| 82 |
|
|
#define FFD 12 /* Clear screen */ |
| 83 |
|
|
#define EJC 85 /* Enable Joystick cursor positioning */ |
| 84 |
|
|
#define DJC 100 /* Disable Joystick cursor positioning */ |
| 85 |
|
|
#define SCC 99 /* Set Cursor Colors */ |
| 86 |
|
|
#define SCP 93 /* Set Cursor Parameters */ |
| 87 |
|
|
#define DFR 111 /* Draw Filled Rectangle */ |
| 88 |
|
|
#define RCP 106 /* Read Cursor Position */ |
| 89 |
|
|
#define ESC 27 /* Escape starts a command sequence */ |
| 90 |
|
|
#define SCS 96 /* Set Console Status */ |
| 91 |
|
|
#define END 1 /* Ctrl-A used to terminate command mode */ |
| 92 |
|
|
|
| 93 |
|
|
#define BLK 0 /* color table entry for black */ |
| 94 |
|
|
#define WHT 7 /* color table entry for white */ |
| 95 |
|
|
|
| 96 |
|
|
#define command(c) (putc(ESC, stdout), putc(c, stdout)) |
| 97 |
|
|
#define byte(b) putc(b, stdout) |
| 98 |
|
|
#define string(s) fputs(s, stdout) |
| 99 |
|
|
#define flush() fflush(stdout) |
| 100 |
|
|
|
| 101 |
greg |
1.3 |
#define GAMMA 2.5 /* exponent for color correction */ |
| 102 |
greg |
1.1 |
|
| 103 |
greg |
1.3 |
#define NCOLORS 248 /* our color table size */ |
| 104 |
greg |
1.2 |
#define MINPIX 8 /* minimum hardware color */ |
| 105 |
greg |
1.1 |
|
| 106 |
|
|
#define NCOLS 512 /* maximum # columns for output */ |
| 107 |
greg |
1.6 |
#define NROWS 483-COMHT /* maximum # rows for output */ |
| 108 |
greg |
1.1 |
#define COMHT 16 /* height of command line */ |
| 109 |
|
|
#define COMCW 63 /* maximum chars on command line */ |
| 110 |
|
|
|
| 111 |
|
|
int aed_close(), aed_clear(), aed_paintr(), |
| 112 |
|
|
aed_getcur(), aed_comout(), aed_errout(); |
| 113 |
|
|
|
| 114 |
|
|
static struct driver aed_driver = { |
| 115 |
|
|
aed_close, aed_clear, aed_paintr, aed_getcur, |
| 116 |
greg |
1.7 |
aed_comout, NULL, NULL, |
| 117 |
greg |
1.6 |
1.0, NCOLS, NROWS |
| 118 |
greg |
1.1 |
}; |
| 119 |
|
|
|
| 120 |
|
|
|
| 121 |
|
|
struct driver * |
| 122 |
greg |
1.5 |
aed_init(name, id) /* open AED */ |
| 123 |
|
|
char *name, *id; |
| 124 |
greg |
1.1 |
{ |
| 125 |
|
|
if (ttyset(&aed_driver, fileno(stdin)) < 0) { /* set tty driver */ |
| 126 |
gregl |
2.2 |
eputs("cannot access terminal\n"); |
| 127 |
greg |
1.1 |
return(NULL); |
| 128 |
|
|
} |
| 129 |
|
|
command(RST); /* reset AED */ |
| 130 |
|
|
longwait(2); |
| 131 |
|
|
command(OPT); |
| 132 |
|
|
byte(6); byte(1); /* AED command set */ |
| 133 |
|
|
command(SEN); |
| 134 |
|
|
string(AEDFMT); |
| 135 |
|
|
command(SCS); /* set console status */ |
| 136 |
|
|
byte(CSTAT); |
| 137 |
|
|
command(SCC); /* set cursor type */ |
| 138 |
|
|
byte(BLK); byte(WHT); byte(15); |
| 139 |
|
|
command(SCP); |
| 140 |
|
|
byte('+'); byte(0); byte(1); |
| 141 |
greg |
1.4 |
make_gmap(GAMMA); /* make color map */ |
| 142 |
gregl |
2.2 |
erract[USER].pf = /* set error vector */ |
| 143 |
|
|
erract[SYSTEM].pf = |
| 144 |
|
|
erract[INTERNAL].pf = |
| 145 |
|
|
erract[CONSISTENCY].pf = aed_errout; |
| 146 |
|
|
erract[COMMAND].pf = aed_errout; |
| 147 |
|
|
if (erract[WARNING].pf != NULL) |
| 148 |
|
|
erract[WARNING].pf = aed_errout; |
| 149 |
greg |
1.1 |
return(&aed_driver); |
| 150 |
|
|
} |
| 151 |
|
|
|
| 152 |
|
|
|
| 153 |
|
|
static |
| 154 |
|
|
aed_close() /* close AED */ |
| 155 |
|
|
{ |
| 156 |
gregl |
2.2 |
erract[USER].pf = /* reset error vector */ |
| 157 |
|
|
erract[SYSTEM].pf = |
| 158 |
|
|
erract[INTERNAL].pf = |
| 159 |
|
|
erract[CONSISTENCY].pf = eputs; |
| 160 |
|
|
erract[COMMAND].pf = NULL; |
| 161 |
|
|
if (erract[WARNING].pf != NULL) |
| 162 |
|
|
erract[WARNING].pf = wputs; |
| 163 |
greg |
1.1 |
aedsetcap(0, 0); /* go to bottom */ |
| 164 |
|
|
command(SEC); |
| 165 |
|
|
byte(WHT); /* white text */ |
| 166 |
|
|
byte(END); |
| 167 |
|
|
byte('\n'); /* scroll */ |
| 168 |
|
|
flush(); |
| 169 |
|
|
ttydone(); |
| 170 |
|
|
} |
| 171 |
|
|
|
| 172 |
|
|
|
| 173 |
|
|
static |
| 174 |
|
|
aed_clear(x, y) /* clear AED */ |
| 175 |
|
|
int x, y; |
| 176 |
|
|
{ |
| 177 |
|
|
command(FFD); |
| 178 |
greg |
1.4 |
new_ctab(NCOLORS); /* init color table */ |
| 179 |
greg |
1.3 |
flush(); |
| 180 |
greg |
1.1 |
} |
| 181 |
|
|
|
| 182 |
|
|
|
| 183 |
|
|
static |
| 184 |
|
|
aed_paintr(col, xmin, ymin, xmax, ymax) /* paint a rectangle */ |
| 185 |
|
|
COLOR col; |
| 186 |
|
|
int xmin, ymin, xmax, ymax; |
| 187 |
|
|
{ |
| 188 |
greg |
1.4 |
extern int anewcolr(); |
| 189 |
greg |
1.3 |
int ndx; |
| 190 |
|
|
|
| 191 |
greg |
1.4 |
ndx = get_pixel(col, anewcolr); /* calls anewcolr() */ |
| 192 |
greg |
1.3 |
command(SEC); /* draw rectangle */ |
| 193 |
|
|
byte(ndx+MINPIX); |
| 194 |
greg |
1.1 |
aedsetcap(xmin, ymin+COMHT); |
| 195 |
|
|
command(DFR); |
| 196 |
|
|
aedcoord(xmax-1, ymax+(-1+COMHT)); |
| 197 |
|
|
flush(); |
| 198 |
|
|
} |
| 199 |
|
|
|
| 200 |
|
|
|
| 201 |
|
|
static int |
| 202 |
|
|
aed_getcur(xp, yp) /* get cursor position */ |
| 203 |
|
|
int *xp, *yp; |
| 204 |
|
|
{ |
| 205 |
|
|
int com; |
| 206 |
|
|
|
| 207 |
|
|
command(EJC); /* enable cursor */ |
| 208 |
|
|
com = getch(); /* get key */ |
| 209 |
|
|
command(DJC); /* disable cursor */ |
| 210 |
|
|
aedgetcap(xp, yp); /* get cursor position */ |
| 211 |
|
|
*yp -= COMHT; /* convert coordinates */ |
| 212 |
|
|
return(com); /* return key hit */ |
| 213 |
|
|
} |
| 214 |
|
|
|
| 215 |
|
|
|
| 216 |
|
|
static |
| 217 |
|
|
aed_comout(out) /* output to command line */ |
| 218 |
|
|
register char *out; |
| 219 |
|
|
{ |
| 220 |
|
|
static int newl = 1; |
| 221 |
|
|
static int inmsg = 0; |
| 222 |
|
|
|
| 223 |
|
|
while (*out) { |
| 224 |
|
|
if (newl) { /* new line */ |
| 225 |
|
|
command(SEC); |
| 226 |
|
|
byte(BLK); |
| 227 |
|
|
aedsetcap(0, 0); |
| 228 |
|
|
command(DFR); |
| 229 |
|
|
aedcoord(NCOLS-1, COMHT-1); |
| 230 |
|
|
aedsetcap(1, 4); |
| 231 |
|
|
command(SEC); /* white text */ |
| 232 |
|
|
byte(WHT); |
| 233 |
|
|
byte(END); |
| 234 |
|
|
newl = 0; |
| 235 |
|
|
} |
| 236 |
|
|
switch (*out) { |
| 237 |
|
|
case '\n': /* end of line */ |
| 238 |
|
|
newl = 1; |
| 239 |
|
|
/* fall through */ |
| 240 |
|
|
case '\r': |
| 241 |
|
|
inmsg = 0; |
| 242 |
|
|
byte('\r'); |
| 243 |
|
|
break; |
| 244 |
|
|
case '\b': /* back space */ |
| 245 |
|
|
if (inmsg > 0 && --inmsg < COMCW) |
| 246 |
|
|
byte('\b'); |
| 247 |
|
|
break; |
| 248 |
|
|
default: /* character */ |
| 249 |
|
|
if (inmsg++ < COMCW) |
| 250 |
|
|
byte(*out); |
| 251 |
|
|
break; |
| 252 |
|
|
} |
| 253 |
|
|
out++; |
| 254 |
|
|
} |
| 255 |
|
|
flush(); |
| 256 |
|
|
} |
| 257 |
|
|
|
| 258 |
|
|
|
| 259 |
|
|
static |
| 260 |
|
|
aed_errout(msg) /* print an error message */ |
| 261 |
|
|
char *msg; |
| 262 |
|
|
{ |
| 263 |
|
|
aed_comout(msg); |
| 264 |
|
|
if (*msg && msg[strlen(msg)-1] == '\n') |
| 265 |
|
|
longwait(2); |
| 266 |
|
|
} |
| 267 |
|
|
|
| 268 |
|
|
|
| 269 |
|
|
/* |
| 270 |
|
|
* aedsetcap - sets AED's current access pointer to (x, y). |
| 271 |
|
|
*/ |
| 272 |
|
|
|
| 273 |
|
|
static |
| 274 |
|
|
aedsetcap(x, y) |
| 275 |
|
|
register int x, y; |
| 276 |
|
|
{ |
| 277 |
|
|
command(MOV); |
| 278 |
|
|
aedcoord(x, y); |
| 279 |
|
|
} |
| 280 |
|
|
|
| 281 |
|
|
/* |
| 282 |
|
|
* aedcoord - puts out an (x, y) coordinate in AED 8 bit format. |
| 283 |
|
|
*/ |
| 284 |
|
|
|
| 285 |
|
|
static |
| 286 |
|
|
aedcoord(x, y) |
| 287 |
|
|
register int x, y; |
| 288 |
|
|
{ |
| 289 |
|
|
byte(((x >> 4) & 0x30) | ((y >> 8) & 0x3)); |
| 290 |
|
|
byte(x & 0xff); |
| 291 |
|
|
byte(y & 0xff); |
| 292 |
|
|
} |
| 293 |
|
|
|
| 294 |
|
|
|
| 295 |
|
|
static |
| 296 |
|
|
aedgetcap(xp, yp) /* get cursor postion */ |
| 297 |
|
|
int *xp, *yp; |
| 298 |
|
|
{ |
| 299 |
|
|
register int c; |
| 300 |
|
|
/* get cursor postition */ |
| 301 |
|
|
command(RCP); |
| 302 |
|
|
flush(); |
| 303 |
|
|
c = getch(); |
| 304 |
|
|
*xp = (c & 0x30) << 4; |
| 305 |
|
|
*yp = (c & 0x3) << 8; |
| 306 |
|
|
*xp |= getch(); |
| 307 |
|
|
*yp |= getch(); |
| 308 |
|
|
} |
| 309 |
|
|
|
| 310 |
|
|
|
| 311 |
|
|
static |
| 312 |
greg |
1.3 |
anewcolr(index, r, g, b) /* enter a color into our table */ |
| 313 |
|
|
int index; |
| 314 |
|
|
int r, g, b; |
| 315 |
greg |
1.1 |
{ |
| 316 |
greg |
1.3 |
command(SCT); |
| 317 |
|
|
byte((index+MINPIX)&255); |
| 318 |
|
|
byte(1); |
| 319 |
|
|
byte(r); |
| 320 |
|
|
byte(g); |
| 321 |
|
|
byte(b); |
| 322 |
|
|
flush(); |
| 323 |
greg |
1.1 |
} |
| 324 |
|
|
|
| 325 |
|
|
|
| 326 |
|
|
static |
| 327 |
|
|
longwait(t) /* longer wait */ |
| 328 |
|
|
int t; |
| 329 |
|
|
{ |
| 330 |
|
|
flush(); |
| 331 |
|
|
sleep(t); |
| 332 |
|
|
} |