1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23 /* All Rights Reserved */
24
25
26 /*
27 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
29 */
30
31 #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.3 */
32 /*LINTLIBRARY*/
33
34 #include <signal.h>
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <unistd.h>
38 #include <plot.h>
39 #include "con.h"
40
41 static void
delay(void)42 delay(void)
43 {
44 int i;
45 for (i = 0; i < 2; i++) {
46 (void) ioctl(OUTF, TCSBRK, 1);
47 }
48 }
49
50 int
xconv(int xp)51 xconv(int xp)
52 {
53 /*
54 * x position input is -2047 to +2047,
55 * output must be 0 to PAGSIZ*HORZRES
56 */
57 xp += 2048;
58 /* the computation is newx = xp*(PAGSIZ*HORZRES)/4096 */
59 return (int)(xoffset + xp / xscale);
60 }
61
62 int
yconv(int yp)63 yconv(int yp)
64 {
65 /* see description of xconv */
66 yp += 2048;
67 return (int)(yp / yscale);
68 }
69
70 void
inplot(void)71 inplot(void)
72 {
73 spew(ESC);
74 spew(INPLOT);
75 }
76
77 void
outplot(void)78 outplot(void)
79 {
80 spew(ESC);
81 spew(ACK);
82 spew(ESC);
83 spew(ACK);
84 (void) fflush(stdout);
85 }
86
87 void
spew(char ch)88 spew(char ch)
89 {
90 (void) putc(ch, stdout);
91 }
92
93 void
tobotleft(void)94 tobotleft(void)
95 {
96 move(-2048, -2048);
97 }
98
99 void
reset(void)100 reset(void)
101 {
102 struct termio ITTY;
103 (void) signal(SIGINT, SIG_IGN);
104 outplot();
105 (void) ioctl(OUTF, TCSETAW, &ITTY);
106 _exit(0);
107 }
108
109 float
dist2(int x1,int y1,int x2,int y2)110 dist2(int x1, int y1, int x2, int y2)
111 {
112 float t, v;
113 t = x2 - x1;
114 v = y1 - y2;
115 return (t * t + v * v);
116 }
117
118 void
swap(int * pa,int * pb)119 swap(int *pa, int *pb)
120 {
121 int t;
122 t = *pa;
123 *pa = *pb;
124 *pb = t;
125 }
126
127 #define DOUBLE 010
128 #define ADDR 0100
129 #define COM 060
130 #define MAXX 070
131 #define MAXY 07
132 #define SPACES 7
133
134 void
movep(int ix,int iy)135 movep(int ix, int iy)
136 {
137 int dx, dy, remx, remy, pts, i;
138 int xd, yd;
139 char c, addr, command;
140 if ((xnow == ix) && (ynow == iy))
141 return;
142 inplot();
143 dx = ix - xnow;
144 dy = iy - ynow;
145 command = COM|PENUP|((dx < 0) << 1)|(dy < 0);
146 dx = abs(dx);
147 dy = abs(dy);
148 xd = dx / (SPACES*2);
149 yd = dy / (SPACES*2);
150 pts = xd < yd ? xd : yd;
151 if ((i = pts) > 0) {
152 c = command|DOUBLE;
153 addr = ADDR;
154 if (xd > 0)
155 addr |= MAXX;
156 if (yd > 0)
157 addr |= MAXY;
158 spew(c);
159 delay();
160 while (i--) {
161 spew(addr);
162 delay();
163 }
164 }
165 if (xd != yd) {
166 if (xd > pts) {
167 i = xd - pts;
168 addr = ADDR|MAXX;
169 } else {
170 i = yd - pts;
171 addr = ADDR|MAXY;
172 }
173 c = command|DOUBLE;
174 spew(c);
175 delay();
176 while (i--) {
177 spew(addr);
178 delay();
179 }
180 }
181 remx = dx - xd * SPACES * 2;
182 remy = dy - yd * SPACES * 2;
183 addr = ADDR;
184 i = 0;
185 if (remx > 7) {
186 i = 1;
187 addr |= MAXX;
188 remx -= 7;
189 }
190 if (remy > 7) {
191 i = 1;
192 addr |= MAXY;
193 remy -= 7;
194 }
195 while (i--) {
196 spew(command);
197 delay();
198 spew(addr);
199 delay();
200 }
201 if ((remx > 0) || (remy > 0)) {
202 spew(command);
203 delay();
204 spew(ADDR|remx << 3|remy);
205 delay();
206 }
207 xnow = ix;
208 ynow = iy;
209 outplot();
210 }
211
212 int
xsc(int xi)213 xsc(int xi)
214 {
215 int xa;
216 xa = (int)((xi - obotx) * scalex + botx);
217 return (xa);
218 }
219
220 int
ysc(int yi)221 ysc(int yi)
222 {
223 int ya;
224 ya = (int)((yi - oboty) * scaley + boty);
225 return (ya);
226 }
227