1 /*-
2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * %sccs.include.proprietary.c%
6 */
7
8 #ifndef lint
9 static char sccsid[] = "@(#)subr.c 8.1 (Berkeley) 06/04/93";
10 #endif /* not lint */
11
12 #include <stdio.h>
13 #include "con.h"
abval(q)14 abval(q)
15 {
16 return (q>=0 ? q : -q);
17 }
18
xconv(xp)19 xconv (xp)
20 {
21 /* x position input is -2047 to +2047, output must be 0 to PAGSIZ*HORZRES */
22 xp += 2048;
23 /* the computation is newx = xp*(PAGSIZ*HORZRES)/4096 */
24 return (xoffset + xp /xscale);
25 }
26
yconv(yp)27 yconv (yp)
28 {
29 /* see description of xconv */
30 yp += 2048;
31 return (yp / yscale);
32 }
33
inplot()34 inplot()
35 {
36 stty(OUTF, &PTTY);
37 spew (ACK);
38 }
39
outplot()40 outplot()
41 {
42 spew(ESC);
43 spew(ACK);
44 fflush(stdout);
45 stty(OUTF, &ITTY);
46 }
47
spew(ch)48 spew(ch)
49 {
50 if(ch == UP)putc(ESC,stdout);
51 putc(ch, stdout);
52 }
53
tobotleft()54 tobotleft ()
55 {
56 move(-2048,-2048);
57 }
reset()58 reset()
59 {
60 outplot();
61 exit();
62 }
63
64 double
dist2(x1,y1,x2,y2)65 dist2 (x1, y1, x2, y2)
66 {
67 float t,v;
68 t = x2-x1;
69 v = y1-y2;
70 return (t*t+v*v);
71 }
72
swap(pa,pb)73 swap (pa, pb)
74 int *pa, *pb;
75 {
76 int t;
77 t = *pa;
78 *pa = *pb;
79 *pb = t;
80 }
movep(xg,yg)81 movep (xg, yg)
82 {
83 int i,ch;
84 if((xg == xnow) && (yg == ynow))return;
85 /* if we need to go to left margin, just CR */
86 if (xg < xnow/2)
87 {
88 spew(CR);
89 xnow = 0;
90 }
91 i = (xg-xnow)/HORZRES;
92 if(xnow < xg)ch = RIGHT;
93 else ch = LEFT;
94 xnow += i*HORZRES;
95 i = abval(i);
96 while(i--)spew(ch);
97 i = abval(xg-xnow);
98 inplot();
99 while(i--) spew(ch);
100 outplot();
101 i=(yg-ynow)/VERTRES;
102 if(ynow < yg)ch = UP;
103 else ch = DOWN;
104 ynow += i*VERTRES;
105 i = abval(i);
106 while(i--)spew(ch);
107 i=abval(yg-ynow);
108 inplot();
109 while(i--)spew(ch);
110 outplot();
111 xnow = xg; ynow = yg;
112 }
113
xsc(xi)114 xsc(xi){
115 int xa;
116 xa = (xi - obotx) * scalex + botx;
117 return(xa);
118 }
ysc(yi)119 ysc(yi){
120 int ya;
121 ya = (yi - oboty) *scaley +boty;
122 return(ya);
123 }
124