148521Sbostic /*- 248521Sbostic * Copyright (c) 1983 The Regents of the University of California. 348521Sbostic * All rights reserved. 448521Sbostic * 548521Sbostic * %sccs.include.proprietary.c% 648521Sbostic */ 748521Sbostic 813322Ssam #ifndef lint 9*57885Storek static char sccsid[] = "@(#)subr.c 4.3 (Berkeley) 02/10/93"; 1048521Sbostic #endif /* not lint */ 1113322Ssam 1213322Ssam #include <stdio.h> 1313322Ssam #include "con.h" 1413322Ssam abval(q) 1513322Ssam { 1613322Ssam return (q>=0 ? q : -q); 1713322Ssam } 1813322Ssam 1913322Ssam xconv (xp) 2013322Ssam { 2113322Ssam /* x position input is -2047 to +2047, output must be 0 to PAGSIZ*HORZRES */ 2213322Ssam xp += 2048; 2313322Ssam /* the computation is newx = xp*(PAGSIZ*HORZRES)/4096 */ 2413322Ssam return (xoffset + xp /xscale); 2513322Ssam } 2613322Ssam 2713322Ssam yconv (yp) 2813322Ssam { 2913322Ssam /* see description of xconv */ 3013322Ssam yp += 2048; 3113322Ssam return (yp / yscale); 3213322Ssam } 3313322Ssam 3413322Ssam inplot() 3513322Ssam { 3613322Ssam stty(OUTF, &PTTY); 3713322Ssam spew (ACK); 3813322Ssam } 3913322Ssam 4013322Ssam outplot() 4113322Ssam { 4213322Ssam spew(ESC); 4313322Ssam spew(ACK); 4413322Ssam fflush(stdout); 4513322Ssam stty(OUTF, &ITTY); 4613322Ssam } 4713322Ssam 4813322Ssam spew(ch) 4913322Ssam { 5013322Ssam if(ch == UP)putc(ESC,stdout); 5113322Ssam putc(ch, stdout); 5213322Ssam } 5313322Ssam 5413322Ssam tobotleft () 5513322Ssam { 5613322Ssam move(-2048,-2048); 5713322Ssam } 5813322Ssam reset() 5913322Ssam { 6013322Ssam outplot(); 6113322Ssam exit(); 6213322Ssam } 6313322Ssam 64*57885Storek double 6513322Ssam dist2 (x1, y1, x2, y2) 6613322Ssam { 6713322Ssam float t,v; 6813322Ssam t = x2-x1; 6913322Ssam v = y1-y2; 7013322Ssam return (t*t+v*v); 7113322Ssam } 7213322Ssam 7313322Ssam swap (pa, pb) 7413322Ssam int *pa, *pb; 7513322Ssam { 7613322Ssam int t; 7713322Ssam t = *pa; 7813322Ssam *pa = *pb; 7913322Ssam *pb = t; 8013322Ssam } 8113322Ssam movep (xg, yg) 8213322Ssam { 8313322Ssam int i,ch; 8413322Ssam if((xg == xnow) && (yg == ynow))return; 8513322Ssam /* if we need to go to left margin, just CR */ 8613322Ssam if (xg < xnow/2) 8713322Ssam { 8813322Ssam spew(CR); 8913322Ssam xnow = 0; 9013322Ssam } 9113322Ssam i = (xg-xnow)/HORZRES; 9213322Ssam if(xnow < xg)ch = RIGHT; 9313322Ssam else ch = LEFT; 9413322Ssam xnow += i*HORZRES; 9513322Ssam i = abval(i); 9613322Ssam while(i--)spew(ch); 9713322Ssam i = abval(xg-xnow); 9813322Ssam inplot(); 9913322Ssam while(i--) spew(ch); 10013322Ssam outplot(); 10113322Ssam i=(yg-ynow)/VERTRES; 10213322Ssam if(ynow < yg)ch = UP; 10313322Ssam else ch = DOWN; 10413322Ssam ynow += i*VERTRES; 10513322Ssam i = abval(i); 10613322Ssam while(i--)spew(ch); 10713322Ssam i=abval(yg-ynow); 10813322Ssam inplot(); 10913322Ssam while(i--)spew(ch); 11013322Ssam outplot(); 11113322Ssam xnow = xg; ynow = yg; 11213322Ssam } 11313322Ssam 11413322Ssam xsc(xi){ 11513322Ssam int xa; 11613322Ssam xa = (xi - obotx) * scalex + botx; 11713322Ssam return(xa); 11813322Ssam } 11913322Ssam ysc(yi){ 12013322Ssam int ya; 12113322Ssam ya = (yi - oboty) *scaley +boty; 12213322Ssam return(ya); 12313322Ssam } 124