1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate * CDDL HEADER START
3*0Sstevel@tonic-gate *
4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*0Sstevel@tonic-gate * with the License.
8*0Sstevel@tonic-gate *
9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate * and limitations under the License.
13*0Sstevel@tonic-gate *
14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate *
20*0Sstevel@tonic-gate * CDDL HEADER END
21*0Sstevel@tonic-gate */
22*0Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23*0Sstevel@tonic-gate /* All Rights Reserved */
24*0Sstevel@tonic-gate
25*0Sstevel@tonic-gate
26*0Sstevel@tonic-gate /*
27*0Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
28*0Sstevel@tonic-gate * Use is subject to license terms.
29*0Sstevel@tonic-gate */
30*0Sstevel@tonic-gate
31*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
32*0Sstevel@tonic-gate /*LINTLIBRARY*/
33*0Sstevel@tonic-gate
34*0Sstevel@tonic-gate #include <stdlib.h>
35*0Sstevel@tonic-gate #include <stdio.h>
36*0Sstevel@tonic-gate #include <signal.h>
37*0Sstevel@tonic-gate #include <unistd.h>
38*0Sstevel@tonic-gate #include <plot.h>
39*0Sstevel@tonic-gate #include "con.h"
40*0Sstevel@tonic-gate
41*0Sstevel@tonic-gate int xnow, ynow, OUTF;
42*0Sstevel@tonic-gate
43*0Sstevel@tonic-gate int
xconv(int xp)44*0Sstevel@tonic-gate xconv(int xp)
45*0Sstevel@tonic-gate {
46*0Sstevel@tonic-gate /*
47*0Sstevel@tonic-gate * x position input is -2047 to +2047,
48*0Sstevel@tonic-gate * output must be 0 to PAGSIZ*HORZRES
49*0Sstevel@tonic-gate */
50*0Sstevel@tonic-gate xp += 2048;
51*0Sstevel@tonic-gate /* the computation is newx = xp*(PAGSIZ*HORZRES)/4096 */
52*0Sstevel@tonic-gate return (xoffset + xp / xscale);
53*0Sstevel@tonic-gate }
54*0Sstevel@tonic-gate
55*0Sstevel@tonic-gate int
yconv(int yp)56*0Sstevel@tonic-gate yconv(int yp)
57*0Sstevel@tonic-gate {
58*0Sstevel@tonic-gate /* see description of xconv */
59*0Sstevel@tonic-gate yp += 2048;
60*0Sstevel@tonic-gate return (yp / yscale);
61*0Sstevel@tonic-gate }
62*0Sstevel@tonic-gate
63*0Sstevel@tonic-gate void
inplot(void)64*0Sstevel@tonic-gate inplot(void)
65*0Sstevel@tonic-gate {
66*0Sstevel@tonic-gate spew(ESC);
67*0Sstevel@tonic-gate spew(PLOTIN);
68*0Sstevel@tonic-gate }
69*0Sstevel@tonic-gate
70*0Sstevel@tonic-gate void
outplot(void)71*0Sstevel@tonic-gate outplot(void)
72*0Sstevel@tonic-gate {
73*0Sstevel@tonic-gate spew(ESC);
74*0Sstevel@tonic-gate spew(PLOTOUT);
75*0Sstevel@tonic-gate (void) fflush(stdout);
76*0Sstevel@tonic-gate }
77*0Sstevel@tonic-gate
78*0Sstevel@tonic-gate void
spew(char ch)79*0Sstevel@tonic-gate spew(char ch)
80*0Sstevel@tonic-gate {
81*0Sstevel@tonic-gate if (ch == UP) {
82*0Sstevel@tonic-gate (void) putc(ESC, stdout);
83*0Sstevel@tonic-gate ch = DOWN;
84*0Sstevel@tonic-gate }
85*0Sstevel@tonic-gate (void) putc(ch, stdout);
86*0Sstevel@tonic-gate }
87*0Sstevel@tonic-gate
88*0Sstevel@tonic-gate void
tobotleft(void)89*0Sstevel@tonic-gate tobotleft(void)
90*0Sstevel@tonic-gate {
91*0Sstevel@tonic-gate move(-2048, -2048);
92*0Sstevel@tonic-gate }
93*0Sstevel@tonic-gate
94*0Sstevel@tonic-gate void
reset(void)95*0Sstevel@tonic-gate reset(void)
96*0Sstevel@tonic-gate {
97*0Sstevel@tonic-gate (void) signal(SIGINT, SIG_IGN);
98*0Sstevel@tonic-gate outplot();
99*0Sstevel@tonic-gate (void) ioctl(OUTF, TCSETAW, &ITTY);
100*0Sstevel@tonic-gate _exit(0);
101*0Sstevel@tonic-gate }
102*0Sstevel@tonic-gate
103*0Sstevel@tonic-gate float
dist2(int x1,int y1,int x2,int y2)104*0Sstevel@tonic-gate dist2(int x1, int y1, int x2, int y2)
105*0Sstevel@tonic-gate {
106*0Sstevel@tonic-gate float t, v;
107*0Sstevel@tonic-gate t = x2 - x1;
108*0Sstevel@tonic-gate v = y1 - y2;
109*0Sstevel@tonic-gate return (t * t + v * v);
110*0Sstevel@tonic-gate }
111*0Sstevel@tonic-gate
112*0Sstevel@tonic-gate void
swap(int * pa,int * pb)113*0Sstevel@tonic-gate swap(int *pa, int *pb)
114*0Sstevel@tonic-gate {
115*0Sstevel@tonic-gate int t;
116*0Sstevel@tonic-gate t = *pa;
117*0Sstevel@tonic-gate *pa = *pb;
118*0Sstevel@tonic-gate *pb = t;
119*0Sstevel@tonic-gate }
120*0Sstevel@tonic-gate
121*0Sstevel@tonic-gate void
movep(int xg,int yg)122*0Sstevel@tonic-gate movep(int xg, int yg)
123*0Sstevel@tonic-gate {
124*0Sstevel@tonic-gate int i;
125*0Sstevel@tonic-gate char ch;
126*0Sstevel@tonic-gate if ((xg == xnow) && (yg == ynow))
127*0Sstevel@tonic-gate return;
128*0Sstevel@tonic-gate /* if we need to go to left margin, just CR */
129*0Sstevel@tonic-gate if (xg < xnow / 2) {
130*0Sstevel@tonic-gate spew(CR);
131*0Sstevel@tonic-gate xnow = 0;
132*0Sstevel@tonic-gate }
133*0Sstevel@tonic-gate i = (int)((xg - xnow) / HORZRES);
134*0Sstevel@tonic-gate if (xnow < xg)
135*0Sstevel@tonic-gate ch = RIGHT;
136*0Sstevel@tonic-gate else ch = LEFT;
137*0Sstevel@tonic-gate xnow += i * HORZRES;
138*0Sstevel@tonic-gate i = abs(i);
139*0Sstevel@tonic-gate while (i--)
140*0Sstevel@tonic-gate spew(ch);
141*0Sstevel@tonic-gate i = abs(xg - xnow);
142*0Sstevel@tonic-gate inplot();
143*0Sstevel@tonic-gate while (i--)
144*0Sstevel@tonic-gate spew(ch);
145*0Sstevel@tonic-gate outplot();
146*0Sstevel@tonic-gate i = (int)((yg - ynow) / VERTRES);
147*0Sstevel@tonic-gate if (ynow < yg)
148*0Sstevel@tonic-gate ch = UP;
149*0Sstevel@tonic-gate else ch = DOWN;
150*0Sstevel@tonic-gate ynow += i * VERTRES;
151*0Sstevel@tonic-gate i = abs(i);
152*0Sstevel@tonic-gate while (i--)
153*0Sstevel@tonic-gate spew(ch);
154*0Sstevel@tonic-gate i = abs(yg - ynow);
155*0Sstevel@tonic-gate inplot();
156*0Sstevel@tonic-gate while (i--)
157*0Sstevel@tonic-gate spew(ch);
158*0Sstevel@tonic-gate outplot();
159*0Sstevel@tonic-gate xnow = xg; ynow = yg;
160*0Sstevel@tonic-gate }
161*0Sstevel@tonic-gate
162*0Sstevel@tonic-gate int
xsc(int xi)163*0Sstevel@tonic-gate xsc(int xi)
164*0Sstevel@tonic-gate {
165*0Sstevel@tonic-gate int xa;
166*0Sstevel@tonic-gate xa = (int)((xi - obotx) * scalex + botx);
167*0Sstevel@tonic-gate return (xa);
168*0Sstevel@tonic-gate }
169*0Sstevel@tonic-gate
170*0Sstevel@tonic-gate int
ysc(int yi)171*0Sstevel@tonic-gate ysc(int yi)
172*0Sstevel@tonic-gate {
173*0Sstevel@tonic-gate int ya;
174*0Sstevel@tonic-gate ya = (int)((yi - oboty) *scaley +boty);
175*0Sstevel@tonic-gate return (ya);
176*0Sstevel@tonic-gate }
177