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