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