Annotation of OpenXM_contrib/gnuplot/term/atarivdi.trm, Revision 1.1.1.1
1.1 maekawa 1: /*
2: * $Id: atarivdi.trm,v 1.7 1998/06/18 14:59:18 ddenholm Exp $
3: *
4: */
5:
6: /* GNUPLOT - atari.trm */
7:
8: /*[
9: * Copyright 1992, 1993, 1998
10: *
11: * Permission to use, copy, and distribute this software and its
12: * documentation for any purpose with or without fee is hereby granted,
13: * provided that the above copyright notice appear in all copies and
14: * that both that copyright notice and this permission notice appear
15: * in supporting documentation.
16: *
17: * Permission to modify the software is granted, but not the right to
18: * distribute the complete modified source code. Modifications are to
19: * be distributed as patches to the released version. Permission to
20: * distribute binaries produced by compiling modified sources is granted,
21: * provided you
22: * 1. distribute the corresponding source modifications from the
23: * released version in the form of a patch file along with the binaries,
24: * 2. add special version identification to distinguish your version
25: * in addition to the base release version number,
26: * 3. provide your name and address as the primary contact for the
27: * support of your modified version, and
28: * 4. retain our contact information in regard to use of the base
29: * software.
30: * Permission to distribute the released version of the source code along
31: * with corresponding source modifications in the form of a patch file is
32: * granted with same provisions 2 through 4 for binary distributions.
33: *
34: * This software is provided "as is" without express or implied warranty
35: * to the extent permitted by applicable law.
36: ]*/
37:
38: /*
39: * This file is included by ../term.c.
40: *
41: * This terminal driver supports:
42: * Atari Screens working with the normal VDI
43: * (this should include TT and big screens)
44: *
45: * AUTHORS
46: * Alexander Lehmann
47: * HE Koechling
48: *
49: * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
50: *
51: * ATARI-related comments please to alexlehm@iti.informatik.th-darmstadt.de
52: *
53: */
54:
55: #include "driver.h"
56:
57: #ifdef TERM_REGISTER
58: register_term(vdi)
59: #endif
60:
61: #ifdef TERM_PROTO
62:
63: /* function-prototypes */
64: TERM_PUBLIC void VDI_options(void);
65: TERM_PUBLIC void VDI_init(void);
66: TERM_PUBLIC void VDI_reset(void);
67: TERM_PUBLIC void VDI_graphics(void);
68: TERM_PUBLIC void VDI_text(void);
69: TERM_PUBLIC void VDI_move(unsigned int x, unsigned int y);
70: TERM_PUBLIC void VDI_vector(unsigned int x, unsigned int y);
71: TERM_PUBLIC void VDI_linetype(int lt);
72: TERM_PUBLIC int VDI_text_angle(int ang);
73: TERM_PUBLIC void VDI_put_text(unsigned int x, unsigned int y, char *str);
74: TERM_PUBLIC int VDI_justify_text(enum JUSTIFY mode);
75: TERM_PUBLIC void VDI_point(unsigned int x, unsigned int y, int number);
76:
77: /* default to hi-res */
78: #define VDI_XMAX 640
79: #define VDI_YMAX 400
80: #define VDI_VCHAR 16
81: #define VDI_HCHAR 8
82: #define VDI_HTIC (VDI_XMAX/100)
83: #define VDI_VTIC VDI_HTIC
84:
85: #endif /* TERM_PROTO */
86:
87: #ifndef TERM_PROTO_ONLY
88: #ifdef TERM_BODY
89:
90: #ifdef __PUREC__
91: /* why did they have to change these names ??? */
92: # include <aes.h>
93: # include <vdi.h>
94: # include <tos.h>
95: #else /* !__PUREC__ i.e. __GNUC__, maybe others */
96: # include <aesbind.h>
97: # include <vdibind.h>
98: # include <osbind.h>
99: #endif
100:
101: #define VDI_yc(y) (VDI_maxycoord-(y))
102: #define VDI_LINETYPES_MAX 11
103:
104: static int VDI_linetypes[VDI_LINETYPES_MAX] =
105: {
106: 0xffff, 0x1111,
107: 0xffff, 0x5555, 0x3333, 0x7777,
108: 0x3f3f, 0x0f0f, 0x5f5f, 0xe4e4, 0x55f5
109: };
110:
111: static int VDI_lt;
112: static int vdi_vdi_handle = -1;
113: static int VDI_maxycoord;
114: static int VDI_rotation;
115: static int VDI_numcolors;
116: static int pxy[128]; /* Maximum of 64 pixels per v_pline */
117: static int pxy_index;
118: static int VDI_colors[16];
119: static int VDI_savecolors[16][3];
120: static int VDI_numpalette;
121:
122: #define VDI_c_height_default 6 /* well, well ... */
123:
124: static int VDI_c_height = VDI_c_height_default;
125:
126: static void vdi_flush_line(void);
127:
128: TERM_PUBLIC void VDI_options()
129: {
130: #define VDIHEXERROR "palette values 3 hex digits, please"
131: #define VDIHEIGHTERROR "expecting a character height"
132: char opt[4];
133: int i;
134: char *tok_end;
135:
136: term_options[0] = NUL;
137: VDI_c_height = VDI_c_height_default;
138:
139: for (i = 0; i < 17; i++) {
140: if (END_OF_COMMAND)
141: break;
142: if (token[c_token].length > 3) {
143: VDI_numpalette = 0;
144: VDI_c_height = VDI_c_height_default;
145: term_options[0] = NUL;
146: int_error(VDIHEXERROR, c_token);
147: }
148: capture(opt, c_token, c_token, 6);
149: if (!i) {
150: VDI_c_height = strtoul(opt, &tok_end, 10);
151: if (*tok_end != NUL) {
152: VDI_numpalette = 0;
153: VDI_c_height = VDI_c_height_default;
154: term_options[0] = NUL;
155: int_error(VDIHEIGHTERROR, c_token);
156: }
157: if (VDI_c_height > 999)
158: VDI_c_height = 999; /* avoid opt length overflow */
159: sprintf(opt, "%d ", VDI_c_height);
160: } else {
161: VDI_colors[i - 1] = strtoul(opt, &tok_end, 16);
162: if (*tok_end != NUL) {
163: VDI_numpalette = 0;
164: VDI_c_height = VDI_c_height_default;
165: term_options[0] = NUL;
166: int_error(VDIHEXERROR, c_token);
167: }
168: sprintf(opt, "%03X ", VDI_colors[i - 1]);
169: }
170: strcat(term_options, opt);
171: c_token++;
172: }
173: VDI_numpalette = (i == 0 ? 0 : i - 1);
174: }
175:
176: TERM_PUBLIC void VDI_init()
177: {
178: int work_in[11];
179: int work_out[57];
180: int i;
181: int hchar, wchar, dummy;
182: int rgb[3];
183: int num_save;
184: char *colors, *tok_end;
185:
186: if (VDI_numpalette == 0 && (colors = getenv("GNUCOLORS")) && *colors) {
187: for (i = 0; i < 17; i++) {
188: if (!i) {
189: VDI_c_height = strtoul(colors, &tok_end, 10);
190: if (colors == tok_end) {
191: i = 0;
192: VDI_c_height = VDI_c_height_default;
193: break;
194: }
195: } else {
196: if (*colors == NUL)
197: break;
198: VDI_colors[i] = strtoul(colors, &tok_end, 16);
199: if (colors == tok_end || (unsigned) VDI_colors[i] > 0xfff) {
200: i = 0;
201: break;
202: }
203: }
204: colors = tok_end;
205:
206: while (*colors == ' ')
207: colors++;
208: }
209: VDI_numpalette = (i == 0 ? 0 : i - 1);
210: }
211: vdi_vdi_handle = graf_handle(&wchar, &hchar, &dummy, &dummy);
212: if (!vdi_vdi_handle)
213: int_error("Fatal error opening virtual workstation", NO_CARET);
214:
215: for (i = 0; i < 10; work_in[i++] = 1);
216: work_in[10] = 2; /* use raster coordinates */
217: v_opnvwk(work_in, &vdi_vdi_handle, work_out);
218: if (!vdi_vdi_handle)
219: int_error("Fatal error opening virtual workstation", NO_CARET);
220:
221: vst_height(vdi_vdi_handle, VDI_c_height, &dummy, &dummy, &wchar, &hchar);
222:
223: vs_clip(vdi_vdi_handle, 0, work_in); /* turn clipping off */
224:
225: term->xmax = work_out[0] + 1;
226: term->ymax = work_out[1] + 1;
227: term->h_char = wchar;
228: term->v_char = hchar; /* hchar stands for height this time */
229: term->h_tic = (work_out[0] + 1) / 100;
230: term->v_tic = term->h_tic;
231:
232: VDI_maxycoord = work_out[1];
233: VDI_numcolors = work_out[13];
234: pxy_index = 0;
235:
236: for (i = 0; i < VDI_numpalette; i++) {
237: vq_color(vdi_vdi_handle, i, 1, VDI_savecolors[i]);
238:
239: rgb[0] = 1000 * (VDI_colors[i] >> 8);
240: rgb[0] /= 15;
241: rgb[1] = 1000 * ((VDI_colors[i] >> 4) & 15);
242: rgb[1] /= 15;
243: rgb[2] = 1000 * (VDI_colors[i] & 15);
244: rgb[2] /= 15;
245: vs_color(vdi_vdi_handle, i, rgb);
246: }
247: #ifdef __PUREC__
248: /* currently the PureC version runs as .prg and the GCC version runs as .ttp.
249: Let's hope that we soon figure out which way is the best */
250: v_hide_c(vdi_vdi_handle);
251: #endif
252: }
253:
254: TERM_PUBLIC void VDI_reset()
255: {
256: int i;
257:
258: if (vdi_vdi_handle != -1) {
259: for (i = 0; i < VDI_numpalette; i++) {
260: vs_color(vdi_vdi_handle, i, VDI_savecolors[i]);
261: }
262: #ifdef __PUREC__
263: /* see above */
264: v_show_c(vdi_vdi_handle, 0);
265: #endif
266: v_clsvwk(vdi_vdi_handle);
267: vdi_vdi_handle = -1;
268: }
269: }
270:
271: TERM_PUBLIC void VDI_graphics()
272: {
273: int pxy[8];
274: MFDB mfdb;
275:
276: fflush(stdout);
277: fflush(stderr);
278: Cconws("\033f"); /* turn cursor off */
279: /* apparently v_clrwk doesn't work with overscan. We'll blit the screen clear.
280: v_clrwk( vdi_vdi_handle );
281: */
282: mfdb.fd_addr = NULL; /* NULL means actual screen. So we don't need size etc. */
283:
284: pxy[0] = pxy[4] = 0;
285: pxy[1] = pxy[5] = 0;
286: pxy[2] = pxy[6] = term->xmax - 1;
287: pxy[3] = pxy[7] = term->ymax - 1;
288:
289: vro_cpyfm(vdi_vdi_handle, ALL_WHITE /*0 */ ,
290: pxy, &mfdb, &mfdb);
291:
292: pxy_index = 0;
293: }
294:
295: TERM_PUBLIC void VDI_text()
296: {
297: vdi_flush_line();
298: Cnecin(); /* wait for any char --> enable screen dump */
299: Cconws("\033e"); /* turn cursor on again */
300: }
301:
302: TERM_PUBLIC void VDI_move(unsigned int x, unsigned int y)
303: {
304: vdi_flush_line();
305:
306: pxy_index = 1;
307: pxy[0] = x;
308: pxy[1] = VDI_yc(y);
309: }
310:
311: TERM_PUBLIC void VDI_vector(unsigned int x, unsigned int y)
312: {
313: pxy[2 * pxy_index] = x;
314: pxy[2 * pxy_index + 1] = VDI_yc(y);
315: pxy_index++;
316:
317: if (pxy_index == 64) { /* we're all full */
318: vdi_flush_line();
319: }
320: }
321:
322: TERM_PUBLIC void VDI_linetype(int lt)
323: {
324: vdi_flush_line();
325:
326: VDI_lt = lt;
327: }
328:
329: TERM_PUBLIC void VDI_put_text(unsigned int x, unsigned int y, char *str)
330: {
331: int vchar = term->v_char;
332: int dummy;
333:
334: if (!strlen(str))
335: return;
336:
337: if (x < 0)
338: x = 0;
339: if (y < 0)
340: y = 0;
341:
342: /* align text left and to middle of char height */
343: vst_alignment(vdi_vdi_handle, 0, 5, &dummy, &dummy);
344: vst_rotation(vdi_vdi_handle, (VDI_rotation ? 900 : 0));
345: if (VDI_rotation)
346: v_gtext(vdi_vdi_handle, x - vchar / 2 + 1, VDI_yc(y) - 1, str);
347: else
348: v_gtext(vdi_vdi_handle, x + 1, VDI_yc(y) - vchar / 2 + 1, str);
349: }
350:
351: TERM_PUBLIC int VDI_text_angle(int ang)
352: {
353: VDI_rotation = ang;
354:
355: return TRUE;
356: }
357:
358: TERM_PUBLIC int VDI_justify_text(enum JUSTIFY mode)
359: {
360: return FALSE;
361: }
362:
363: TERM_PUBLIC void VDI_point(unsigned int x, unsigned int y, int number)
364: {
365: int old_linetype;
366:
367: if (VDI_numcolors == 2) {
368: line_and_point(x, y, number); /* monochrome */
369: } else {
370: /* we map colors that exceed our limit to dotted lines, but we can't do
371: that with the markers (sortof a generalized line_and_point) */
372: old_linetype = VDI_lt;
373: if (VDI_lt > VDI_numcolors - 2) {
374: /* same color, but no dots */
375: VDI_linetype(VDI_lt % (VDI_numcolors - 2));
376: }
377: do_point(x, y, number);
378: VDI_linetype(old_linetype);
379: }
380: }
381:
382: static void vdi_flush_line()
383: {
384: int line_type;
385: int color_index;
386: int i;
387:
388: if (pxy_index >= 2) {
389: if (VDI_numcolors == 2) { /* Monochrome */
390: color_index = 1;
391: line_type = VDI_lt;
392: if (line_type >= 0)
393: line_type %= (VDI_LINETYPES_MAX - 2);
394: } else { /* Color */
395: if (VDI_lt < 0) {
396: color_index = 1;
397: line_type = VDI_lt;
398: } else {
399: color_index = 2 + VDI_lt % (VDI_numcolors - 2);
400: line_type = (VDI_lt / (VDI_numcolors - 2)) % (VDI_LINETYPES_MAX - 2);
401: }
402: }
403:
404: vswr_mode(vdi_vdi_handle, MD_TRANS);
405: vsl_color(vdi_vdi_handle, color_index);
406:
407: vsl_type(vdi_vdi_handle, 7);
408: vsl_udsty(vdi_vdi_handle, VDI_linetypes[line_type + 2]);
409:
410: v_pline(vdi_vdi_handle, pxy_index, pxy);
411: }
412: if (pxy_index >= 1) {
413: pxy[0] = pxy[2 * (pxy_index - 1)];
414: pxy[1] = pxy[2 * (pxy_index - 1) + 1];
415: pxy_index = 1;
416: }
417: }
418:
419: #endif /* TERM_BODY */
420:
421: #ifdef TERM_TABLE
422:
423: TERM_TABLE_START(vdi_driver)
424: "vdi", "Atari VDI-Terminal",
425: VDI_XMAX, VDI_YMAX, VDI_VCHAR, VDI_HCHAR,
426: VDI_VTIC, VDI_HTIC, VDI_options, VDI_init, VDI_reset,
427: VDI_text, null_scale, VDI_graphics, VDI_move, VDI_vector,
428: VDI_linetype, VDI_put_text, VDI_text_angle,
429: VDI_justify_text, VDI_point, do_arrow, set_font_null,
430: 0, TERM_CAN_MULTIPLOT, 0, 0
431: TERM_TABLE_END(vdi_driver)
432:
433: #undef LAST_TERM
434: #define LAST_TERM vdi_driver
435:
436: #endif /* TERM_TABLE */
437:
438: #endif /* TERM_PROTO_ONLY */
439:
440: #ifdef TERM_HELP
441: START_HELP(vdi)
442: "1 atari ST (via VDI)",
443: "?commands set terminal vdi",
444: "?set terminal vdi",
445: "?set term vdi",
446: "?terminal vdi",
447: "?term vdi",
448: "?vdi",
449: " The `vdi` terminal is the same as the `atari` terminal, except that it sends",
450: " output to the screen via the VDI and not into AES-Windows.",
451: "",
452: " The `vdi` terminal has options to set the character size and the screen",
453: " colors.",
454: "",
455: " Syntax:",
456: " set terminal vdi {<fontsize>} {<col0> <col1> ... <col15.}",
457: "",
458: " The character size must appear if any colors are to be specified. Each of",
459: " the (up to 16) colors is given as a three-digit hex number, where the digits",
460: " represent RED, GREEN and BLUE (in that order). The range of 0--15 is scaled",
461: " to whatever color range the screen actually has. On a normal ST screen, odd",
462: " and even intensities are the same.",
463: "",
464: " Examples:",
465: " set terminal vdi 4 # use small (6x6) font",
466: " set terminal vdi 6 0 # set monochrome screen to white on black",
467: " set terminal vdi 13 0 fff f00 f0 f ff f0f",
468: " # set first seven colors to black, white, green, blue,",
469: " # cyan, purple, and yellow and use large font (8x16).",
470: "",
471: " Additionally, if an environment variable GNUCOLORS exists, its contents are",
472: " interpreted as an options string, but an explicit terminal option takes",
473: " precedence."
474: END_HELP(vdi)
475: #endif /* TERM_HELP */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>