| 1 | greg | 1.1 | #ifndef lint | 
| 2 | schorsch | 2.5 | static const char       RCSid[] = "$Id: aed.c,v 2.4 2003/02/25 02:47:22 greg Exp $"; | 
| 3 | greg | 1.1 | #endif | 
| 4 |  |  | /* | 
| 5 |  |  | *  aed.c - driver for AED 512 terminal. | 
| 6 | greg | 2.3 | */ | 
| 7 |  |  |  | 
| 8 | greg | 2.4 | #include "copyright.h" | 
| 9 | greg | 1.1 |  | 
| 10 |  |  | #include  <stdio.h> | 
| 11 |  |  |  | 
| 12 | schorsch | 2.5 | #include  "rterror.h" | 
| 13 |  |  | #include  "color.h" | 
| 14 | greg | 1.1 | #include  "driver.h" | 
| 15 |  |  |  | 
| 16 |  |  |  | 
| 17 |  |  | /* AED command characters */ | 
| 18 |  |  |  | 
| 19 |  |  | #define AEDFMT  "1888N" /* Format string to send to AED */ | 
| 20 |  |  | #define CSTAT   0100    /* Console status: lower case */ | 
| 21 |  |  | #define SCT     75      /* Set color lookup table */ | 
| 22 |  |  | #define SEC     67      /* Set color for vector drawing */ | 
| 23 |  |  | #define MOV     81      /* Set CAP (current access pointer) to x, y */ | 
| 24 |  |  | #define OPT     40      /* Miscellaneous terminal control */ | 
| 25 |  |  | #define SEN     71      /* Set encoding types */ | 
| 26 |  |  | #define RST     48      /* Reset terminal */ | 
| 27 |  |  | #define FFD     12      /* Clear screen */ | 
| 28 |  |  | #define EJC     85      /* Enable Joystick cursor positioning */ | 
| 29 |  |  | #define DJC     100     /* Disable Joystick cursor positioning */ | 
| 30 |  |  | #define SCC     99      /* Set Cursor Colors */ | 
| 31 |  |  | #define SCP     93      /* Set Cursor Parameters */ | 
| 32 |  |  | #define DFR     111     /* Draw Filled Rectangle */ | 
| 33 |  |  | #define RCP     106     /* Read Cursor Position */ | 
| 34 |  |  | #define ESC     27      /* Escape starts a command sequence */ | 
| 35 |  |  | #define SCS     96      /* Set Console Status */ | 
| 36 |  |  | #define END     1       /* Ctrl-A used to terminate command mode */ | 
| 37 |  |  |  | 
| 38 |  |  | #define BLK     0       /* color table entry for black */ | 
| 39 |  |  | #define WHT     7       /* color table entry for white */ | 
| 40 |  |  |  | 
| 41 |  |  | #define command(c)      (putc(ESC, stdout), putc(c, stdout)) | 
| 42 |  |  | #define byte(b)         putc(b, stdout) | 
| 43 |  |  | #define string(s)       fputs(s, stdout) | 
| 44 |  |  | #define flush()         fflush(stdout) | 
| 45 |  |  |  | 
| 46 | greg | 1.3 | #define  GAMMA          2.5             /* exponent for color correction */ | 
| 47 | greg | 1.1 |  | 
| 48 | greg | 1.3 | #define  NCOLORS        248             /* our color table size */ | 
| 49 | greg | 1.2 | #define  MINPIX         8               /* minimum hardware color */ | 
| 50 | greg | 1.1 |  | 
| 51 |  |  | #define  NCOLS          512             /* maximum # columns for output */ | 
| 52 | greg | 1.6 | #define  NROWS          483-COMHT       /* maximum # rows for output */ | 
| 53 | greg | 1.1 | #define  COMHT          16              /* height of command line */ | 
| 54 |  |  | #define  COMCW          63              /* maximum chars on command line */ | 
| 55 |  |  |  | 
| 56 | schorsch | 2.5 | static void  aed_close(void); | 
| 57 |  |  | static void aed_errout(char*); | 
| 58 |  |  | static void longwait(int t); | 
| 59 |  |  | static void aedgetcap(int  *xp, int *yp); | 
| 60 |  |  | static void aedsetcap(int  x, int y); | 
| 61 |  |  | static void anewcolr(int  index, int  r,int g,int b); | 
| 62 |  |  | static void aed_paintr(COLOR  col, int  xmin, int ymin, int xmax, int ymax); | 
| 63 |  |  | static void aedcoord(int  x, int y); | 
| 64 |  |  | static void aed_comout(char  *out); | 
| 65 |  |  | static int aed_getcur(int  *xp, int *yp); | 
| 66 |  |  | static aed_clear(int  x, int y); | 
| 67 | greg | 1.1 |  | 
| 68 |  |  | static struct driver  aed_driver = { | 
| 69 |  |  | aed_close, aed_clear, aed_paintr, aed_getcur, | 
| 70 | greg | 1.7 | aed_comout, NULL, NULL, | 
| 71 | greg | 1.6 | 1.0, NCOLS, NROWS | 
| 72 | greg | 1.1 | }; | 
| 73 |  |  |  | 
| 74 |  |  |  | 
| 75 |  |  | struct driver * | 
| 76 | greg | 1.5 | aed_init(name, id)                      /* open AED */ | 
| 77 |  |  | char  *name, *id; | 
| 78 | greg | 1.1 | { | 
| 79 |  |  | if (ttyset(&aed_driver, fileno(stdin)) < 0) {   /* set tty driver */ | 
| 80 | gregl | 2.2 | eputs("cannot access terminal\n"); | 
| 81 | greg | 1.1 | return(NULL); | 
| 82 |  |  | } | 
| 83 |  |  | command(RST);                                   /* reset AED */ | 
| 84 |  |  | longwait(2); | 
| 85 |  |  | command(OPT); | 
| 86 |  |  | byte(6); byte(1);                               /* AED command set */ | 
| 87 |  |  | command(SEN); | 
| 88 |  |  | string(AEDFMT); | 
| 89 |  |  | command(SCS);                                   /* set console status */ | 
| 90 |  |  | byte(CSTAT); | 
| 91 |  |  | command(SCC);                                   /* set cursor type */ | 
| 92 |  |  | byte(BLK); byte(WHT); byte(15); | 
| 93 |  |  | command(SCP); | 
| 94 |  |  | byte('+'); byte(0); byte(1); | 
| 95 | greg | 1.4 | make_gmap(GAMMA);                               /* make color map */ | 
| 96 | gregl | 2.2 | erract[USER].pf =                               /* set error vector */ | 
| 97 |  |  | erract[SYSTEM].pf = | 
| 98 |  |  | erract[INTERNAL].pf = | 
| 99 |  |  | erract[CONSISTENCY].pf = aed_errout; | 
| 100 |  |  | erract[COMMAND].pf = aed_errout; | 
| 101 |  |  | if (erract[WARNING].pf != NULL) | 
| 102 |  |  | erract[WARNING].pf = aed_errout; | 
| 103 | greg | 1.1 | return(&aed_driver); | 
| 104 |  |  | } | 
| 105 |  |  |  | 
| 106 |  |  |  | 
| 107 | schorsch | 2.5 | static void | 
| 108 |  |  | aed_close(void)                                 /* close AED */ | 
| 109 | greg | 1.1 | { | 
| 110 | gregl | 2.2 | erract[USER].pf =                       /* reset error vector */ | 
| 111 |  |  | erract[SYSTEM].pf = | 
| 112 |  |  | erract[INTERNAL].pf = | 
| 113 |  |  | erract[CONSISTENCY].pf = eputs; | 
| 114 |  |  | erract[COMMAND].pf = NULL; | 
| 115 |  |  | if (erract[WARNING].pf != NULL) | 
| 116 |  |  | erract[WARNING].pf = wputs; | 
| 117 | greg | 1.1 | aedsetcap(0, 0);                        /* go to bottom */ | 
| 118 |  |  | command(SEC); | 
| 119 |  |  | byte(WHT);                              /* white text */ | 
| 120 |  |  | byte(END); | 
| 121 |  |  | byte('\n');                             /* scroll */ | 
| 122 |  |  | flush(); | 
| 123 |  |  | ttydone(); | 
| 124 |  |  | } | 
| 125 |  |  |  | 
| 126 |  |  |  | 
| 127 |  |  | static | 
| 128 |  |  | aed_clear(x, y)                                 /* clear AED */ | 
| 129 |  |  | int  x, y; | 
| 130 |  |  | { | 
| 131 |  |  | command(FFD); | 
| 132 | greg | 1.4 | new_ctab(NCOLORS);                      /* init color table */ | 
| 133 | greg | 1.3 | flush(); | 
| 134 | greg | 1.1 | } | 
| 135 |  |  |  | 
| 136 |  |  |  | 
| 137 | schorsch | 2.5 | static void | 
| 138 | greg | 1.1 | aed_paintr(col, xmin, ymin, xmax, ymax)         /* paint a rectangle */ | 
| 139 |  |  | COLOR  col; | 
| 140 |  |  | int  xmin, ymin, xmax, ymax; | 
| 141 |  |  | { | 
| 142 | greg | 1.3 | int  ndx; | 
| 143 |  |  |  | 
| 144 | greg | 1.4 | ndx = get_pixel(col, anewcolr);         /* calls anewcolr() */ | 
| 145 | greg | 1.3 | command(SEC);                           /* draw rectangle */ | 
| 146 |  |  | byte(ndx+MINPIX); | 
| 147 | greg | 1.1 | aedsetcap(xmin, ymin+COMHT); | 
| 148 |  |  | command(DFR); | 
| 149 |  |  | aedcoord(xmax-1, ymax+(-1+COMHT)); | 
| 150 |  |  | flush(); | 
| 151 |  |  | } | 
| 152 |  |  |  | 
| 153 |  |  |  | 
| 154 |  |  | static int | 
| 155 |  |  | aed_getcur(xp, yp)                      /* get cursor position */ | 
| 156 |  |  | int  *xp, *yp; | 
| 157 |  |  | { | 
| 158 |  |  | int  com; | 
| 159 |  |  |  | 
| 160 |  |  | command(EJC);                   /* enable cursor */ | 
| 161 |  |  | com = getch();                  /* get key */ | 
| 162 |  |  | command(DJC);                   /* disable cursor */ | 
| 163 |  |  | aedgetcap(xp, yp);              /* get cursor position */ | 
| 164 |  |  | *yp -= COMHT;                   /* convert coordinates */ | 
| 165 |  |  | return(com);                    /* return key hit */ | 
| 166 |  |  | } | 
| 167 |  |  |  | 
| 168 |  |  |  | 
| 169 | schorsch | 2.5 | static void | 
| 170 | greg | 1.1 | aed_comout(out)                         /* output to command line */ | 
| 171 |  |  | register char  *out; | 
| 172 |  |  | { | 
| 173 |  |  | static int  newl = 1; | 
| 174 |  |  | static int  inmsg = 0; | 
| 175 |  |  |  | 
| 176 |  |  | while (*out) { | 
| 177 |  |  | if (newl) {                     /* new line */ | 
| 178 |  |  | command(SEC); | 
| 179 |  |  | byte(BLK); | 
| 180 |  |  | aedsetcap(0, 0); | 
| 181 |  |  | command(DFR); | 
| 182 |  |  | aedcoord(NCOLS-1, COMHT-1); | 
| 183 |  |  | aedsetcap(1, 4); | 
| 184 |  |  | command(SEC);           /* white text */ | 
| 185 |  |  | byte(WHT); | 
| 186 |  |  | byte(END); | 
| 187 |  |  | newl = 0; | 
| 188 |  |  | } | 
| 189 |  |  | switch (*out) { | 
| 190 |  |  | case '\n':                      /* end of line */ | 
| 191 |  |  | newl = 1; | 
| 192 |  |  | /* fall through */ | 
| 193 |  |  | case '\r': | 
| 194 |  |  | inmsg = 0; | 
| 195 |  |  | byte('\r'); | 
| 196 |  |  | break; | 
| 197 |  |  | case '\b':                      /* back space */ | 
| 198 |  |  | if (inmsg > 0 && --inmsg < COMCW) | 
| 199 |  |  | byte('\b'); | 
| 200 |  |  | break; | 
| 201 |  |  | default:                        /* character */ | 
| 202 |  |  | if (inmsg++ < COMCW) | 
| 203 |  |  | byte(*out); | 
| 204 |  |  | break; | 
| 205 |  |  | } | 
| 206 |  |  | out++; | 
| 207 |  |  | } | 
| 208 |  |  | flush(); | 
| 209 |  |  | } | 
| 210 |  |  |  | 
| 211 |  |  |  | 
| 212 | schorsch | 2.5 | static void | 
| 213 | greg | 1.1 | aed_errout(msg)                         /* print an error message */ | 
| 214 |  |  | char  *msg; | 
| 215 |  |  | { | 
| 216 |  |  | aed_comout(msg); | 
| 217 |  |  | if (*msg && msg[strlen(msg)-1] == '\n') | 
| 218 |  |  | longwait(2); | 
| 219 |  |  | } | 
| 220 |  |  |  | 
| 221 |  |  |  | 
| 222 |  |  | /* | 
| 223 |  |  | * aedsetcap - sets AED's current access pointer to (x, y). | 
| 224 |  |  | */ | 
| 225 |  |  |  | 
| 226 | schorsch | 2.5 | static void | 
| 227 | greg | 1.1 | aedsetcap(x, y) | 
| 228 |  |  | register int  x, y; | 
| 229 |  |  | { | 
| 230 |  |  | command(MOV); | 
| 231 |  |  | aedcoord(x, y); | 
| 232 |  |  | } | 
| 233 |  |  |  | 
| 234 |  |  | /* | 
| 235 |  |  | * aedcoord - puts out an (x, y) coordinate in AED 8 bit format. | 
| 236 |  |  | */ | 
| 237 |  |  |  | 
| 238 | schorsch | 2.5 | static void | 
| 239 | greg | 1.1 | aedcoord(x, y) | 
| 240 |  |  | register int  x, y; | 
| 241 |  |  | { | 
| 242 |  |  | byte(((x >> 4) & 0x30) | ((y >> 8) & 0x3)); | 
| 243 |  |  | byte(x & 0xff); | 
| 244 |  |  | byte(y & 0xff); | 
| 245 |  |  | } | 
| 246 |  |  |  | 
| 247 |  |  |  | 
| 248 | schorsch | 2.5 | static void | 
| 249 | greg | 1.1 | aedgetcap(xp, yp)               /* get cursor postion */ | 
| 250 |  |  | int  *xp, *yp; | 
| 251 |  |  | { | 
| 252 |  |  | register int  c; | 
| 253 |  |  | /* get cursor postition */ | 
| 254 |  |  | command(RCP); | 
| 255 |  |  | flush(); | 
| 256 |  |  | c = getch(); | 
| 257 |  |  | *xp = (c & 0x30) << 4; | 
| 258 |  |  | *yp = (c & 0x3) << 8; | 
| 259 |  |  | *xp |= getch(); | 
| 260 |  |  | *yp |= getch(); | 
| 261 |  |  | } | 
| 262 |  |  |  | 
| 263 |  |  |  | 
| 264 | schorsch | 2.5 | static void | 
| 265 | greg | 1.3 | anewcolr(index, r, g, b)                /* enter a color into our table */ | 
| 266 |  |  | int  index; | 
| 267 |  |  | int  r, g, b; | 
| 268 | greg | 1.1 | { | 
| 269 | greg | 1.3 | command(SCT); | 
| 270 |  |  | byte((index+MINPIX)&255); | 
| 271 |  |  | byte(1); | 
| 272 |  |  | byte(r); | 
| 273 |  |  | byte(g); | 
| 274 |  |  | byte(b); | 
| 275 |  |  | flush(); | 
| 276 | greg | 1.1 | } | 
| 277 |  |  |  | 
| 278 |  |  |  | 
| 279 | schorsch | 2.5 | static void | 
| 280 | greg | 1.1 | longwait(t)             /* longer wait */ | 
| 281 |  |  | int  t; | 
| 282 |  |  | { | 
| 283 |  |  | flush(); | 
| 284 |  |  | sleep(t); | 
| 285 |  |  | } |