Initial release of Maemo 5 port of gnuplot
[gnuplot] / term / t410x.trm
1 /* Hello, Emacs, this is -*-C-*-
2  * $Id: t410x.trm,v 1.16 2006/07/21 02:35:48 sfeam Exp $
3  *
4  */
5
6 /* GNUPLOT - t410x.trm */
7
8 /*[
9  * Copyright 1990 - 1993, 1998, 2004
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: Tektronix 410x and 420x series terminals
42  *
43  * AUTHORS
44  *   Colin Kelley, Thomas Williams
45  *
46  * send your comments or suggestions to (gnuplot-info@lists.sourceforge.net).
47  *
48  */
49
50 /* Tektronix 410X and 420X driver written by Cary D. Renzema.
51  * email address: caryr@mxim.com
52  *
53  * I've tested this driver on the following terminals: 4106, 4107A, 4109
54  * and 4207.  It should work, without editing, on other terminals in the
55  * 410x and 420x families.  It will probably need to be changed to work
56  * on a 4105 (screen size and character rotation are two guesses).  This
57  * file can also be used as a start for a 411x driver.
58  *
59  * Cary R.
60  * April 5, 1990
61  */
62
63 /*
64  * adapted to the new terminal layout by Stefan Bodewig (Dec. 1995)
65  */
66
67 #include "driver.h"
68
69 #ifdef TERM_REGISTER
70 register_term(tek410x)
71 #endif
72
73 #ifdef TERM_PROTO
74 TERM_PUBLIC void T410X_init __PROTO((void));
75 TERM_PUBLIC void T410X_reset __PROTO((void));
76 TERM_PUBLIC void T410X_graphics __PROTO((void));
77 TERM_PUBLIC void T410X_text __PROTO((void));
78 TERM_PUBLIC void T410X_move __PROTO((unsigned int x, unsigned int y));
79 TERM_PUBLIC void T410X_vector __PROTO((unsigned int x, unsigned int y));
80 TERM_PUBLIC void T410X_point __PROTO((unsigned int x, unsigned int y, int number));
81 TERM_PUBLIC void T410X_linetype __PROTO((int linetype));
82 TERM_PUBLIC void T410X_put_text __PROTO((unsigned int x, unsigned int y, const char str[]));
83 TERM_PUBLIC int T410X_text_angle __PROTO((int ang));
84 #define T410XXMAX 4095
85 #define T410XYMAX 3131
86
87 #define T410XVCHAR      71
88 #define T410XHCHAR      51
89 #define T410XVTIC       36
90 #define T410XHTIC       36
91 #endif /* TERM_PROTO */
92
93 #ifndef TERM_PROTO_ONLY
94 #ifdef TERM_BODY
95 static void T410X_encode_x_y __PROTO((unsigned int x, unsigned int y));
96 static void T410X_encode_int __PROTO((int number));
97
98
99 static int T410X_angle = 0;
100
101 TERM_PUBLIC void
102 T410X_init()
103 {
104     fputs("\033%%!0\033MN0\033MCB7C;\033MQ1\033MT1", gpoutfile);
105     fputs("\033MG1\033RK!\033SK!\033LZ\033%%!1", gpoutfile);
106 /*
107          1. set tek mode
108          2. set character path to 0 (characters placed equal to rotation)
109          3. set character size to 59 height
110          4. set character precision to string
111          5. set character text index to 1
112          6. set character write mode to overstrike
113          7. clear the view
114          8. clear the segments
115          9. clear the dialog buffer
116         10. set ansi mode
117 */
118     (void) fflush(gpoutfile);
119 }
120
121
122 TERM_PUBLIC void
123 T410X_reset()
124 {
125     fputs("\033%%!0\033LZ\033%%!1", gpoutfile);
126 /*
127         1. set tek mode
128         2. clear the dialog buffer
129         3. set ansi mode
130 */
131     (void) fflush(gpoutfile);
132 }
133
134
135 TERM_PUBLIC void
136 T410X_graphics()
137 {
138     fputs("\033%%!0\033\014\033LV0", gpoutfile);
139 /*
140         1. set tek mode
141         2. clear the screen
142         3. set dialog area invisible
143 */
144     (void) fflush(gpoutfile);
145 }
146
147 TERM_PUBLIC void
148 T410X_text()
149 {
150     fputs("\033LV1\033%%!1", gpoutfile);
151 /*
152         1. set dialog area visible
153         2. set ansi mode
154 */
155     (void) fflush(gpoutfile);
156 }
157
158
159 TERM_PUBLIC void
160 T410X_move(unsigned int x, unsigned int y)
161 {
162     fputs("\033LF", gpoutfile);
163
164     (void) T410X_encode_x_y(x, y);
165     (void) fflush(gpoutfile);
166 }
167
168
169 TERM_PUBLIC void
170 T410X_vector(unsigned int x, unsigned int y)
171 {
172     fputs("\033LG", gpoutfile);
173     (void) T410X_encode_x_y(x, y);
174     (void) fflush(gpoutfile);
175 }
176
177
178 TERM_PUBLIC void
179 T410X_point(unsigned int x, unsigned int y, int number)
180 {
181     fputs("\033MM", gpoutfile);
182     (void) T410X_encode_int(GPMAX(number, 0) % 11);
183     fputs("\033LH", gpoutfile);
184     (void) T410X_encode_x_y(x, y);
185     (void) fflush(gpoutfile);
186 }
187
188
189 TERM_PUBLIC void
190 T410X_linetype(int linetype)
191 {
192     if (linetype < -2)
193         linetype = LT_BLACK;
194
195     switch (linetype) {
196     case LT_AXIS:
197         fputs("\033ML5", gpoutfile);
198         break;
199     case LT_BLACK:
200         fputs("\033ML?", gpoutfile);
201         break;
202     default:
203         fputs("\033ML", gpoutfile);
204         (void) T410X_encode_int(linetype % 14 + 2);
205         break;
206     }
207     fputs("\033MV", gpoutfile);
208     (void) T410X_encode_int(GPMAX(linetype, 0) % 8);
209     (void) fflush(gpoutfile);
210 }
211
212
213 TERM_PUBLIC void
214 T410X_put_text(unsigned int x, unsigned int y, const char str[])
215 {
216
217     if (T410X_angle == 0) {
218         (void) T410X_move(x, y - T410XVCHAR / 2 + 6);
219         fputs("\033MR00", gpoutfile);
220     } else {
221         (void) T410X_move(x + T410XHCHAR / 2 - 6, y);
222         fputs("\033MRE:0", gpoutfile);
223     }
224     (void) fputs("\033LT", gpoutfile);
225     (void) T410X_encode_int(strlen(str));
226     (void) fputs(str, gpoutfile);
227     (void) fflush(gpoutfile);
228 }
229
230 TERM_PUBLIC int
231 T410X_text_angle(int ang)
232 {
233
234     T410X_angle = ang;
235     return (TRUE);
236 }
237
238 /* These last two routines are based on fortran code found in the
239  * 4106/4107/4109/CX PROGRAMMERS manual.
240  */
241
242 static void
243 T410X_encode_x_y(unsigned int x, unsigned int y)
244 {
245     static char chix = 0, chiy = 0, cloy = 0, ceb = 0;
246
247     register unsigned int hix, lox, hiy, loy, eb, lx, ly;
248
249     lx = (x <= T410XXMAX) ? x : T410XXMAX;
250     ly = (y <= T410XYMAX) ? y : T410XYMAX;
251
252     hix = lx / 128 + 32;
253     lox = (lx / 4) % 32 + 64;
254     hiy = ly / 128 + 32;
255     loy = (ly / 4) % 32 + 96;
256     eb = (ly % 4) * 4 + lx % 4 + 96;
257
258     if (chiy != hiy)
259         (void) putc(hiy, gpoutfile);
260     if (ceb != eb)
261         (void) putc(eb, gpoutfile);
262     if ((cloy != loy) || (ceb != eb) || (chix != hix))
263         (void) putc(loy, gpoutfile);
264     if (chix != hix)
265         (void) putc(hix, gpoutfile);
266     (void) putc(lox, gpoutfile);
267
268     chix = hix;
269     chiy = hiy;
270     cloy = loy;
271     ceb = eb;
272 }
273
274
275 static void
276 T410X_encode_int(int number)
277 {
278     register unsigned int mag, hi1, hi2, lo;
279
280     mag = ABS(number);
281
282     hi1 = mag / 1024 + 64;
283     hi2 = (mag / 16) % 64 + 64;
284     lo = mag % 16 + 32;
285
286     if (number >= 0)
287         lo += 16;
288
289     if (hi1 != 64)
290         (void) putc(hi1, gpoutfile);
291     if ((hi2 != 64) || (hi1 != 64))
292         (void) putc(hi2, gpoutfile);
293     (void) putc(lo, gpoutfile);
294
295 }
296
297 #endif /* TERM_BODY */
298
299 #ifdef TERM_TABLE
300
301 TERM_TABLE_START(tek410x_driver)
302     "tek410x", "Tektronix 4106, 4107, 4109 and 420X terminals",
303     T410XXMAX, T410XYMAX, T410XVCHAR, T410XHCHAR,
304     T410XVTIC, T410XHTIC, options_null, T410X_init, T410X_reset,
305     T410X_text, null_scale, T410X_graphics, T410X_move, T410X_vector,
306     T410X_linetype, T410X_put_text, T410X_text_angle,
307     null_justify_text, T410X_point, do_arrow, set_font_null
308 TERM_TABLE_END(tek410x_driver)
309
310 #undef LAST_TERM
311 #define LAST_TERM tek410x_driver
312
313 #endif /* TERM_TABLE */
314 #endif /* TERM_PROTO_ONLY */
315
316 #ifdef TERM_HELP
317 START_HELP(tek410x)
318 "1 tek410x",
319 "?commands set terminal tek410x",
320 "?set terminal tek410x",
321 "?set term tek410x",
322 "?terminal tek410x",
323 "?term tek410x",
324 "?tek410x",
325 " The `tek410x` terminal driver supports the 410x and 420x family of Tektronix",
326 " terminals.  It has no options."
327 END_HELP(tek410x)
328 #endif