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