home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-01-28 | 61.1 KB | 2,105 lines |
- Path: sparky!uunet!ferkel.ucsb.edu!taco!rock!stanford.edu!ames!haven.umd.edu!darwin.sura.net!ukma!cs.widener.edu!dsinc!ub!galileo.cc.rochester.edu!ee.rochester.edu!rbc!al
- From: al@rbc.uucp (Al Davis)
- Newsgroups: alt.sources
- Subject: ACS circuit simulator part 17/20
- Message-ID: <1993Jan27.041026.11957@rbc.uucp>
- Date: 27 Jan 93 04:10:26 GMT
- Sender: al@rbc.uucp (Al Davis)
- Organization: Huh?
- Lines: 2094
-
- #! /bin/sh
- # This is a shell archive, meaning:
- # 1. Remove everything above the #! /bin/sh line.
- # 2. Save the resulting text in a file.
- # 3. Execute the file with /bin/sh (not csh) to create the files:
- # src/plot.c
- # src/plotbasi.c
- # src/plotherc.c
- # src/plotibm.c
- # src/plotpost.c
- # src/plotunix.c
- # src/plotx.c
- # src/plotz100.c
- # src/polar.c
- # src/probe.c
- # src/probe2.c
- # src/probe3.c
- # src/qfree.c
- # src/quit.c
- # src/time_it.c
- # src/title.c
- # src/tr.c
- # src/trim.c
- # src/tr_adv.c
- # src/tr_volts.c
- # src/tr_z.c
- # This archive created: Tue Jan 26 22:51:07 1993
- export PATH; PATH=/bin:$PATH
- if test -f 'src/plot.c'
- then
- echo shar: will not over-write existing file "'src/plot.c'"
- else
- cat << \SHAR_EOF > 'src/plot.c'
- /* plot 01/26/93
- * Copyright 1983-1992 Albert Davis
- * (this file is a mess. it should be redone.)
- */
- #include "ecah.h"
- #include "error.h"
- #include "io.h"
- #include "mode.h"
- #include "options.h"
- #include "pixelh.h"
- #include "probh.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- void plottr(double);
- void plotdc(double);
- void plotac(double);
- int plopen(int,double,double,int);
- void plclose(void);
- void plclear(void);
- void pllocate(void);
- static void plborder(void);
- static void calibrate(char*,double,double);
- static int round(double);
- static void plhead(int);
- static int point(double,double,double,int,int,int);
- static void plotarg(double,double,double,double,double,double,
- double,double,double,double,double,double);
- static void crtopen(int,int);
- static void ycal(double,double,double,double);
- static void xcal(void);
- /*--------------------------------------------------------------------------*/
- #define INDENT 8 /* beware mprintf! */
- #define CONSSCALE (opt.outwidth - INDENT - 2) /*console scale size in chr*/
- #define RESRVLINES 4
- extern const struct options opt;
- extern struct ioctrl io;
- extern char e_int[];
- extern struct graph *initcrt();
- extern int crtplot; /* flag: crt is in graphics mode */
- static int reset; /* flag: new graph. suppress 1st line */
- static int active; /* flag: plotting has opened */
- static int xmode;
- static double xstart, xstop;
- static int xlinswp;
- static char border[BUFLEN]; /* border string (keep, repeat at end) */
- static char emptydata[BUFLEN]; /* empty data, to copy then insert data */
- extern probe_t *plotlist[];
- extern const int sim_mode;
- static char *device;
- static struct graph *c;
- /*--------------------------------------------------------------------------*/
- void plottr(xx) /* plot a data point, transient */
- double xx;
- {
- if (active){
- double yy, zz;
- int ii;
- double lo[2], hi[2];
- probe_t prb; /* to hide MSC BUG */
- prb = plotlist[sim_mode][0];
- yy = trprobe(prb);
- prb = plotlist[sim_mode][1];
- zz = trprobe(prb);
- if (zz == NOT_VALID)
- zz = yy;
- for (ii = 0; ii <= 1; ii++){
- if (plotlist[sim_mode][ii].lo != plotlist[sim_mode][ii].hi){
- lo[ii] = plotlist[sim_mode][ii].lo;
- hi[ii] = plotlist[sim_mode][ii].hi;
- }else{
- lo[ii] = -5.;
- hi[ii] = 5.;
- }
- }
- plotarg( xx, yy, zz,
- xstart, lo[0], lo[1],
- xstop, hi[0], hi[1],
- 0., 0., 0. );
- }
- }
- /*--------------------------------------------------------------------------*/
- void plotdc(xx) /* plot a data point, DC */
- double xx;
- {
- plottr(xx);
- }
- /*--------------------------------------------------------------------------*/
- void plotac(xx) /* plot a data point -- AC */
- double xx;
- {
- if (active){
- double yy, zz;
- int ii;
- double lo[2], hi[2];
- probe_t prb; /* to hide MSC BUG */
- prb = plotlist[sim_mode][0];
- yy = acprobe(prb);
- prb = plotlist[sim_mode][1];
- zz = acprobe(prb);
- if (zz == NOT_VALID)
- zz = yy;
- for (ii = 0; ii <= 1; ii++){
- if (plotlist[sim_mode][ii].lo != plotlist[sim_mode][ii].hi){
- lo[ii] = plotlist[sim_mode][ii].lo;
- hi[ii] = plotlist[sim_mode][ii].hi;
- }else{
- lo[ii] = -5.;
- hi[ii] = 5.;
- }
- }
- plotarg( xx, yy, zz,
- xstart, lo[0], lo[1],
- xstop, hi[0], hi[1],
- 0., 0., 0. );
- }
- }
- /*--------------------------------------------------------------------------*/
- /* plopen: begin the plot. any type
- */
- int plopen(mode,start,stop,linswp) /* begin the plot (any type) */
- int mode;
- double start, stop;
- int linswp;
- {
- int fullgrid;
- if (start == stop)
- io.ploton = NO;
- if (!device){
- device = (testcrt()) ? "CRt" : "Ascii" ;
- }
- if (!io.ploton){
- plclear();
- return NO;
- }
- fullgrid = !(crtplot && mode==xmode && start==xstart && stop==xstop);
- xmode = mode;
- xstart = start;
- xstop = stop;
- xlinswp = linswp;
- if (*device=='C')
- crtopen(mode,fullgrid);
- else if (*device=='A')
- plhead(mode);
- else
- error(bWARNING, e_int, "plopen" );
- active = YES;
- return YES;
- }
- /*--------------------------------------------------------------------------*/
- /* plclose: finish up the plot (any type)
- */
- void plclose()
- {
- if (!active)
- return;
- if (*device=='C')
- (*c->fin)(); /* usually a stub, except for Hercules */
- else if (*device=='A')
- plborder();
- else
- error(bWARNING, e_int, "plclose" );
- active = NO;
- io.ploton = NO;
- }
- /*--------------------------------------------------------------------------*/
- /* plclear: clear graphics mode
- */
- void plclear()
- {
- active = NO;
- if (crtplot){
- crtplot = NO;
- (*c->can)();
- }
- }
- /*--------------------------------------------------------------------------*/
- /* pllocate: locate the cursor at the bottom of the plot.
- * select the primary color (CRT plot)
- */
- void pllocate()
- {
- if (crtplot)
- stext( 0, c->wh+2*c->lpc, "", c->pri);
- }
- /*--------------------------------------------------------------------------*/
- /* plborder: draw the border -- Ascii graphics
- */
- static void plborder()
- {
- mtab( INDENT, io.where );
- mputs( border, io.where );
- mputc( '\n', io.where );
- }
- /*--------------------------------------------------------------------------*/
- /* calibrate: calibrate the y axis. ascii plot.
- */
- static void calibrate(note,lo,hi) /* calibrate the y axis */
- char *note;
- double lo,hi;
- {
- static char nums[20]; /* this label string */
- static char highs[20]; /* the last label string */
- double number; /* value of this label */
- double range; /* hi - lo */
- int cal; /* char position within line */
- int stop; /* location of last label, stop printing */
- int filled; /* how far (characters) have been printed */
- int numsize; /* number of characters in this label */
- int start; /* starting position of this label */
- double markno; /* loop counter */
-
- (void)strcpy(highs, ftos(hi, "", 5, io.formaat));
- highs[8] = '\0'; /* trim to 8 chrs */
- /* *strchr(&highs[2],' ') = '\0'; */ /* make the top label, and save */
- stop = opt.outwidth - strlen(highs); /* space for it. */
-
- mputs(note, io.where);
- range = hi-lo;
- filled = 0;
- for (markno = 0.; markno < opt.ydivisions; markno++){
- number = lo + range * markno/opt.ydivisions ;
- if (fabs(number) < fabs(range)/(10.*CONSSCALE)){
- number = 0.;
- } /* label to put on this div. */
- (void)strcpy(nums, ftos(number, "", 5, io.formaat));
- nums[8] = '\0'; /* trim to 8 chrs */
- numsize = strlen(nums); /* center it over the mark */
- cal = round(INDENT + CONSSCALE * (markno/opt.ydivisions));
- start = cal - (numsize+1)/2;
- if (start > filled && start+numsize < stop){
- mtab( start, io.where ); /* if it fits, print it */
- mputs( nums, io.where );
- filled = start + numsize ;
- }
- }
- mtab( stop, io.where ); /* print the last calibration */
- mputs( highs, io.where );
- mputc( '\n', io.where );
- }
- /*--------------------------------------------------------------------------*/
- static int round(x)
- double x;
- {
- return (int)floor(x+.5);
- }
- /*--------------------------------------------------------------------------*/
- /* plhead: begin ascii graphics
- * print opening border, calibrations, etc.
- */
- static void plhead(mode)
- int mode;
- {
- int ii;
- double place; /* where to put this calibration mark */
- double incr; /* exact increment in characters */
-
- for (ii = 0; ii <= 1; ii++){
- double lo, hi;
- probe_t prb; /* to hide MSC BUG */
- if (plotlist[sim_mode][ii].lo != plotlist[sim_mode][ii].hi){
- lo = plotlist[sim_mode][ii].lo;
- hi = plotlist[sim_mode][ii].hi;
- }else{
- lo = -5.;
- hi = 5.;
- }
- prb = plotlist[sim_mode][ii];
- calibrate(probename(prb), lo, hi);
- }
- incr = (double)CONSSCALE / opt.ydivisions;
- (void)memset((void*)border, '-',(int)CONSSCALE); /*build strings : border*/
- (void)memset((void*)emptydata,' ',(int)CONSSCALE); /* and emptydata */
- for (place = 0.; place < (double)CONSSCALE; place += incr){
- border[round(place)] = '+';
- emptydata[round(place)] = '.'; /* tics in emptydata */
- }
- border[CONSSCALE] = '+'; /* fix ends of the strings */
- border[CONSSCALE+1] = '\0';
- emptydata[CONSSCALE] = emptydata[0] = '|';
- emptydata[CONSSCALE+1] = '\0';
-
- plborder(); /* print the border */
- }
- /*--------------------------------------------------------------------------*/
- /* point: return coordinate to plot in pixel #
- */
- static int point(yy,lo,hi,scale,offset,linswp)
- double yy; /* raw data */
- double lo,hi; /* limits: both ends of the plot */
- int scale; /* length of scale in pixels */
- int offset; /* pixel offset of start of plot area */
- int linswp; /* flag: linear scale (else log scale) */
- {
- int place;
-
- if (linswp)
- place = round( scale*(yy-lo)/(hi-lo));
- else
- place = round( scale*(log(yy/lo))/(log(hi/lo)));
-
- if (place < 0)
- place = 0;
- if (place > scale)
- place = scale;
- return place + offset;
- }
- /*--------------------------------------------------------------------------*/
- /* plotarg: plot all 2 selected probes at one time, freq, etc. point.
- */
- /*ARGSUSED*/
- static void plotarg(xx,yy,zz,xlo,ylo,zlo,xhi,yhi,zhi,xf,yf,zf)
- double xx, yy, zz; /* values */
- double xlo,ylo,zlo; /* lower limits */
- double xhi,yhi,zhi; /* upper limits */
- double xf, yf, zf; /* fold modulus != 0 means to suppress line */
- /* when the change is too big */
- {
- if (*device=='A'){
- auto char adata[BUFLEN]; /* actual data. copy emptydata, insert */
- char *xxs; /* string representation of xx */
- (void)memcpy((void*)adata,(void*)emptydata,BUFLEN); /* copy prototype */
- xxs = ftos( xx, " ", 5, io.formaat );
- adata[point(zz,zlo,zhi,CONSSCALE,0,1)] = '+'; /* zap data into string */
- adata[point(yy,ylo,yhi,CONSSCALE,0,1)] = '*';
- mprintf( io.where, "%-8.8s%s", xxs, adata );
- mputc( '\n', io.where );
- }else if (*device=='C'){
- static int xold, yold, zold;
- auto int xpt, ypt, zpt;
- auto int dy, dz;
- xpt = point( xx, xlo, xhi, c->ww, c->lm, xlinswp );
- ypt = point( yy, yhi, ylo, c->wh, c->tm, YES );
- zpt = point( zz, zhi, zlo, c->wh, c->tm, YES );
- if (reset){
- reset = NO;
- xold = xpt;
- yold = ypt;
- zold = zpt;
- }
- dy = ypt - yold;
- dz = zpt - zold;
- if ( !zf || ((double)abs(dz) < (double)(c->wh)*.8) )
- line( xold, zold, xpt, zpt, c->sec );
- if ( !yf || ((double)abs(dy) < (double)(c->wh)*.8) )
- line( xold, yold, xpt, ypt, c->pri );
- xold = xpt;
- yold = ypt;
- zold = zpt;
- }else{
- error(bWARNING, e_int, "plotarg");
- }
- }
- /*--------------------------------------------------------------------------*/
- /* crtopen: begin CRT graphics mode
- * clear screen, draw box, calibrate, etc.
- */
- static void crtopen(mode,fullgrid)
- int mode;
- int fullgrid;
- {
- int ii;
- double lo[2], hi[2];
- reset = YES;
- if (!fullgrid)
- return;
- crtplot = YES;
- c = initcrt();
- if (!c)
- error(bERROR, e_int, "crtopen: device not installed");
- initgraph(c);
- c->lm = INDENT * c->ppc ;
- c->rm = c->sw - (INDENT * c->ppc) -2;
- c->tm = 0 * c->lpc ;
- c->bm = c->sh - (RESRVLINES * c->lpc) -2;
- c->ww = c->rm - c->lm;
- c->wh = c->bm - c->tm;
- box( c->lm, c->tm, c->rm, c->bm, c->grid );
- for (ii = 0; ii <= 1; ii++){
- if (plotlist[sim_mode][ii].lo != plotlist[sim_mode][ii].hi){
- lo[ii] = plotlist[sim_mode][ii].lo;
- hi[ii] = plotlist[sim_mode][ii].hi;
- }else{
- lo[ii] = -5.;
- hi[ii] = 5.;
- }
- }
- ycal(lo[0],hi[0],lo[1],hi[1]);
- xcal();
- stext( 0, c->wh+2*c->lpc, "", c->pri);
- }
- /*--------------------------------------------------------------------------*/
- /* ycal: calibrate the Y axis on CRT display
- */
- static void ycal(ylo,yhi,zlo,zhi)
- double ylo,yhi,zlo,zhi;
- {
- double ynum, znum, yrange, zrange;
- double ratio;
- int cal;
- double markno;
- static char ystr[] = " ";
- static char zstr[] = " ";
- yrange = yhi-ylo;
- zrange = zhi-zlo;
- for (markno = 0.; markno < opt.ydivisions; markno++){
- ratio = markno / opt.ydivisions;
- ynum = ylo + yrange * ratio ;
- znum = zlo + zrange * ratio ;
- if (fabs(ynum) < fabs(yrange)/(10.*c->wh))
- ynum = 0.;
- if (fabs(znum) < fabs(zrange)/(10.*c->wh))
- znum = 0.;
- (void)strcpy(ystr, ftos(ynum,ystr,5,0));
- (void)strcpy(zstr, ftos(znum,zstr,5,0));
- ystr[8] = zstr[8] = '\0'; /* trim to 8 chrs */
- cal = round(c->bm - c->wh * ratio);
- if (cal != c->bm && cal != c->tm)
- line( c->lm, cal, c->rm, cal, c->grid );
- if (cal < c->lpc)
- cal = c->lpc-1;
- stext( 0, cal, ystr, c->pri);
- stext( c->rm+1*c->ppc, cal, zstr, c->sec);
- }
- (void)strcpy(ystr, ftos(yhi,ystr,5,0));
- (void)strcpy(zstr, ftos(zhi,zstr,5,0));
- ystr[8] = zstr[8] = '\0'; /* trim to 8 chrs */
- cal = (c->tm < c->lpc) ? c->lpc-1 : c->tm ;
- stext(0, cal, ystr, c->pri);
- stext(c->rm+1*c->ppc, cal, zstr, c->sec);
- }
- /*--------------------------------------------------------------------------*/
- /* xcal: calibrate the X axis on CRT display
- */
- static void xcal()
- {
- double xcal, ratio;
- int cal;
- double markno;
- static char str[] = " ";
-
- for (markno = 0.; markno <= opt.xdivisions; markno++){
- ratio = markno / opt.xdivisions;
- xcal = (xlinswp)
- ? xstart + (xstop-xstart) * ratio
- : xstart * pow( (xstop/xstart) , ratio );
- cal = round(c->lm + c->ww * ratio);
- if (cal != c->lm && cal != c->rm)
- line(cal, c->tm, cal, c->bm, c->grid);
- (void)strcpy(str, ftos(xcal, str, 5, 0));
- str[8] = '\0';
- stext(cal-2*c->ppc, c->wh+c->lpc, str, c->pri);
- }
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/plotbasi.c'
- then
- echo shar: will not over-write existing file "'src/plotbasi.c'"
- else
- cat << \SHAR_EOF > 'src/plotbasi.c'
- /* plotbasic 04/02/92
- * Copyright 1983-1992 Albert Davis
- * vector graphics, for pen plotters, etc.
- * indirect through basic draw strings.
- */
- #include "ecah.h"
- #include "pixelh.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- struct graph *initbasic(struct graph *);
- static void text(int,int,char*,int);
- static void drawline(int,int,int,int,int);
- static void finishp(void);
- static void cancel(void);
- /*--------------------------------------------------------------------------*/
- static FILE *device;
- static struct graph *d;
- /*--------------------------------------------------------------------------*/
- struct graph *initbasic(g)
- struct graph *g;
- {
- d = g;
- d->spx = (void(*)())NULL;
- d->lin = drawline;
- d->box = (void(*)())NULL;
- d->txt = text;
- d->can = cancel;
- d->fin = finishp;
- xclose( &device );
- device = fopen( PLOTFILE, "wt" ) ;
- return d;
- }
- /*--------------------------------------------------------------------------*/
- static void text(x,y,string,color)
- int x, y, color;
- char *string;
- {
- fprintf( device, "bm%d,%dc%d\"%s\"\n", x, y, color, string);
- }
- /*--------------------------------------------------------------------------*/
- static void drawline( x1, y1, x2, y2, color )
- int x1, y1, x2, y2, color;
- {
- fprintf( device, "BM%d,%dC%dM%d,%d\n", x1, y1, color, x2, y2 );
- }
- /*--------------------------------------------------------------------------*/
- static void finishp()
- {
- xclose( &device );
- if ( access("/dev/ecaplot", 00) == BAD) /* no driver */ /* is exe */
- if ( findfile("ecaplot.com", getenv("PATH"), X_OK)
- || findfile("ecaplot.exe", getenv("PATH"), X_OK)
- || findfile("ecaplot.bat", getenv("PATH"), X_OK) )
- system( "ecaplot" );
- }
- /*--------------------------------------------------------------------------*/
- static void cancel()
- {;}
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/plotherc.c'
- then
- echo shar: will not over-write existing file "'src/plotherc.c'"
- else
- cat << \SHAR_EOF > 'src/plotherc.c'
- /* Hercules video graphics primitives 04/02/92
- * Copyright 1983-1992 Albert Davis
- *
- */
- #include "ecah.h"
- #include "pixelh.h"
- #include <dos.h>
- /*--------------------------------------------------------------------------*/
- struct graph *initherc(struct graph *);
- static void text(int,int,char*,int);
- static void setpixel(int,int,int);
- static void finish(void);
- static void cancel(void);
- /*--------------------------------------------------------------------------*/
- extern void GMODE(void);
- extern void CLRSCR(void);
- extern void TEXTC(int,int,char*);
- extern void PLOT(int,int);
- extern void TMODE(void);
- static struct graph *d;
- /*--------------------------------------------------------------------------*/
- struct graph *initherc(g)
- struct graph *g;
- {
- d = g;
- d->spx = setpixel;
- d->lin = NULL;
- d->box = NULL;
- d->txt = text;
- d->can = cancel;
- d->fin = finish;
- GMODE();
- CLRSCR();
- return d;
- }
- /*--------------------------------------------------------------------------*/
- static void text(col,lin,string,color)
- int col, lin, color;
- char *string;
- {
- TEXTC(col,lin,string);
- }
- /*--------------------------------------------------------------------------*/
- static void setpixel(x,y,color)
- int x,y,color;
- {
- static int skip, oldcolor;
-
- if (!(--skip) || (color!=oldcolor))
- {
- oldcolor = color;
- skip = (color>=0) ? 1 : -color;
- PLOT(x,y);
- }
- }
- /*--------------------------------------------------------------------------*/
- static void finish()
- {
- auto int n;
- int ch;
-
- ch = ci();
- plclear();
- if (ch=='C'-'@')
- {
- n = 0;
- submit("",&n);
- xerror("\r");
- }
- }
- /*--------------------------------------------------------------------------*/
- static void cancel()
- {
- TMODE();
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/plotibm.c'
- then
- echo shar: will not over-write existing file "'src/plotibm.c'"
- else
- cat << \SHAR_EOF > 'src/plotibm.c'
- /* IBM video graphics primitives 04/02/92
- * Copyright 1983-1992 Albert Davis
- */
- #include "pixelh.h"
- #include <stdio.h>
- #include <dos.h>
- /*--------------------------------------------------------------------------*/
- struct graph *initibm(struct graph*);
- static void text(int,int,char*,int);
- static void setpixel(int,int,int);
- static void finish(void);
- static void cancel(void);
- static void mode(int);
- static void scr_curs(int,int);
- static void scr_puts(char*,int);
- /*--------------------------------------------------------------------------*/
- #define VIDEO_INT 0x10
- static struct graph *d;
- /*--------------------------------------------------------------------------*/
- struct graph *initibm(g)
- struct graph *g;
- {
- d = g;
- d->spx = setpixel;
- d->lin = NULL;
- d->box = NULL;
- d->txt = text;
- d->can = cancel;
- d->fin = finish;
- mode(d->gmode);
- return d;
- }
- /*--------------------------------------------------------------------------*/
- static void text(col,lin,string,color)
- int col, lin, color;
- char *string;
- {
- col /= d->ppc;
- lin /= d->lpc;
- scr_curs(lin,col);
- scr_puts(string,color);
- }
- /*--------------------------------------------------------------------------*/
- static void setpixel(x,y,color)
- int x,y,color;
- {
- union REGS inregs;
- static int skip, oldcolor;
-
- if (!(--skip) || (color!=oldcolor))
- {
- oldcolor = color;
- skip = (color>=0) ? 1 : -color;
-
- inregs.h.ah = 12; /* write dot */
- inregs.h.al = (unsigned char)((color>=0) ? color : d->pri) ;
- inregs.x.bx = 0; /* page, palette??????? */
- inregs.x.cx = x;
- inregs.x.dx = y;
- int86(VIDEO_INT, &inregs, &inregs); /*inregs changed */
- }
- }
- /*--------------------------------------------------------------------------*/
-
- static void finish()
- {;}
- /*--------------------------------------------------------------------------*/
- static void cancel()
- {
- if (d->gmode != d->tmode)
- mode(d->tmode);
- }
- /*--------------------------------------------------------------------------*/
- static void mode(video_mode)
- int video_mode;
- {
- union REGS inregs;
-
- inregs.h.al = (unsigned char)video_mode;
- inregs.h.ah = 0; /* set mode */
- int86(VIDEO_INT, &inregs, &inregs);
- }
- /*--------------------------------------------------------------------------*/
- static void scr_curs(lin,col)
- int lin, col;
- {
- union REGS inregs;
-
- inregs.h.ah = 2; /* move cursor */
- inregs.h.dh = (unsigned char)lin;
- inregs.h.dl = (unsigned char)col;
- inregs.h.bh = 0; /* page */
- int86(VIDEO_INT, &inregs, &inregs);
- }
- /*--------------------------------------------------------------------------*/
- static void scr_puts(string,color)
- char *string;
- int color;
- {
- union REGS inregs, outregs;
-
- inregs.h.ah = 14; /* write char, advance */
- inregs.h.bh = 0; /* page */
- inregs.h.bl = (unsigned char)((color>=0) ? color : d->pri) ;
- while (*string)
- {
- inregs.h.al = *string++;
- int86(VIDEO_INT, &inregs, &outregs);
- }
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/plotpost.c'
- then
- echo shar: will not over-write existing file "'src/plotpost.c'"
- else
- cat << \SHAR_EOF > 'src/plotpost.c'
- /* plotpostscript 04/02/92
- * Copyright 1983-1992 Albert Davis
- * vector graphics, for pen plotters, etc.
- * This is bogus. Use it only as a frame.
- */
- #include "ecah.h"
- #include "pixelh.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- struct graph *initpostscript(struct graph *);
- static void text(int,int,char*,int);
- static void drawline(int,int,int,int,int);
- static void finishp(void);
- static void cancel(void);
- /*--------------------------------------------------------------------------*/
- static FILE *device;
- static struct graph *d;
- /*--------------------------------------------------------------------------*/
- struct graph *initpostscript(g)
- struct graph *g;
- {
- d = g;
- d->spx = (void(*)())NULL;
- d->lin = drawline;
- d->box = (void(*)())NULL;
- d->txt = text;
- d->can = cancel;
- d->fin = finishp;
- xclose( &device );
- device = fopen( PLOTFILE, "wt" ) ;
- return d;
- }
- /*--------------------------------------------------------------------------*/
- static void text(x,y,string,color)
- int x, y, color;
- char *string;
- {
- int red, green, blue;
- red = (color & 0x03) << 2;
- green = ((color>>2) & 0x03) << 2;
- blue = ((color>>4) & 0x03) << 2;
- fprintf( device, "C%c%c%cm%c%c%c%c\"%s\"", red, green, blue,
- (x&0x7f), ((x>>8)&0x7f), (y&0x7f), ((y>>8)&0x7f), string );
- }
- /*--------------------------------------------------------------------------*/
- static void drawline( x1, y1, x2, y2, color )
- int x1, y1, x2, y2, color;
- {
- int red, green, blue;
- red = (color & 0x03) << 2;
- green = ((color>>2) & 0x03) << 2;
- blue = ((color>>4) & 0x03) << 2;
- fprintf( device, "C%c%c%cl%c%c%c%c%c%c%c%c", red, green, blue,
- (x1&0x7f), ((x1>>8)&0x7f), (y1&0x7f), ((y1>>8)&0x7f),
- (x2&0x7f), ((x2>>8)&0x7f), (y2&0x7f), ((y2>>8)&0x7f) );
-
- }
- /*--------------------------------------------------------------------------*/
- static void finishp()
- {
- xclose( &device );
- if ( access("/dev/ecaplot", 00) == BAD) /* no driver */ /* is exe */
- if ( findfile("ecaplot.com", getenv("PATH"), X_OK)
- || findfile("ecaplot.exe", getenv("PATH"), X_OK)
- || findfile("ecaplot.bat", getenv("PATH"), X_OK) )
- system( "ecaplot" );
- }
- /*--------------------------------------------------------------------------*/
- static void cancel()
- {;}
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/plotunix.c'
- then
- echo shar: will not over-write existing file "'src/plotunix.c'"
- else
- cat << \SHAR_EOF > 'src/plotunix.c'
- /* plotunix 04/02/92
- * Copyright 1983-1992 Albert Davis
- * vector graphics, for pen plotters, etc.
- * indirect through unix plot filters
- * This is bogus. It might work with minor changes.
- */
- #include "ecah.h"
- #include "pixelh.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- struct graph *initunix(struct graph *);
- static void text(int,int,char*,int);
- static void drawline(int,int,int,int,int);
- static void finishp(void);
- static void cancel(void);
- /*--------------------------------------------------------------------------*/
- static FILE *device;
- static struct graph *d;
- /*--------------------------------------------------------------------------*/
- struct graph *initunix(g)
- struct graph *g;
- {
- d = g;
- d->spx = (void(*)())NULL;
- d->lin = drawline;
- d->box = (void(*)())NULL;
- d->txt = text;
- d->can = cancel;
- d->fin = finishp;
- xclose( &device );
- device = fopen( PLOTFILE, "wt" ) ;
- return d;
- }
- /*--------------------------------------------------------------------------*/
- static void text(x,y,string,color)
- int x, y, color;
- char *string;
- {
- int red, green, blue;
- red = (color & 0x03) << 2;
- green = ((color>>2) & 0x03) << 2;
- blue = ((color>>4) & 0x03) << 2;
- fprintf( device, "C%c%c%cm%c%c%c%c\"%s\"", red, green, blue,
- (x&0x7f), ((x>>8)&0x7f), (y&0x7f), ((y>>8)&0x7f), string );
- }
- /*--------------------------------------------------------------------------*/
- static void drawline( x1, y1, x2, y2, color )
- int x1, y1, x2, y2, color;
- {
- int red, green, blue;
- red = (color & 0x03) << 2;
- green = ((color>>2) & 0x03) << 2;
- blue = ((color>>4) & 0x03) << 2;
- fprintf( device, "C%c%c%cl%c%c%c%c%c%c%c%c", red, green, blue,
- (x1&0x7f), ((x1>>8)&0x7f), (y1&0x7f), ((y1>>8)&0x7f),
- (x2&0x7f), ((x2>>8)&0x7f), (y2&0x7f), ((y2>>8)&0x7f) );
-
- }
- /*--------------------------------------------------------------------------*/
- static void finishp()
- {
- xclose( &device );
- if ( access("/dev/ecaplot", 00) == BAD) /* no driver */ /* is exe */
- if ( findfile("ecaplot.com", getenv("PATH"), X_OK)
- || findfile("ecaplot.exe", getenv("PATH"), X_OK)
- || findfile("ecaplot.bat", getenv("PATH"), X_OK) )
- system( "ecaplot" );
- }
- /*--------------------------------------------------------------------------*/
- static void cancel()
- {;}
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/plotx.c'
- then
- echo shar: will not over-write existing file "'src/plotx.c'"
- else
- cat << \SHAR_EOF > 'src/plotx.c'
- /* plotx 04/02/92
- * Copyright 1983-1992 Albert Davis
- * vector graphics, for pen plotters, etc.
- * indirect through x plot filters
- * This is bogus. Use it only as a frame.
- */
- #include "ecah.h"
- #include "pixelh.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- struct graph *initx(struct graph *);
- static void text(int,int,char*,int);
- static void drawline(int,int,int,int,int);
- static void finishp(void);
- static void cancel(void);
- /*--------------------------------------------------------------------------*/
- static FILE *device;
- static struct graph *d;
- /*--------------------------------------------------------------------------*/
- struct graph *initx(g)
- struct graph *g;
- {
- d = g;
- d->spx = (void(*)())NULL;
- d->lin = drawline;
- d->box = (void(*)())NULL;
- d->txt = text;
- d->can = cancel;
- d->fin = finishp;
- xclose( &device );
- device = fopen( PLOTFILE, "wt" ) ;
- return d;
- }
- /*--------------------------------------------------------------------------*/
- static void text(x,y,string,color)
- int x, y, color;
- char *string;
- {
- int red, green, blue;
- red = (color & 0x03) << 2;
- green = ((color>>2) & 0x03) << 2;
- blue = ((color>>4) & 0x03) << 2;
- fprintf( device, "C%c%c%cm%c%c%c%c\"%s\"", red, green, blue,
- (x&0x7f), ((x>>8)&0x7f), (y&0x7f), ((y>>8)&0x7f), string );
- }
- /*--------------------------------------------------------------------------*/
- static void drawline( x1, y1, x2, y2, color )
- int x1, y1, x2, y2, color;
- {
- int red, green, blue;
- red = (color & 0x03) << 2;
- green = ((color>>2) & 0x03) << 2;
- blue = ((color>>4) & 0x03) << 2;
- fprintf( device, "C%c%c%cl%c%c%c%c%c%c%c%c", red, green, blue,
- (x1&0x7f), ((x1>>8)&0x7f), (y1&0x7f), ((y1>>8)&0x7f),
- (x2&0x7f), ((x2>>8)&0x7f), (y2&0x7f), ((y2>>8)&0x7f) );
-
- }
- /*--------------------------------------------------------------------------*/
- static void finishp()
- {
- xclose( &device );
- if ( access("/dev/ecaplot", 00) == BAD) /* no driver */ /* is exe */
- if ( findfile("ecaplot.com", getenv("PATH"), X_OK)
- || findfile("ecaplot.exe", getenv("PATH"), X_OK)
- || findfile("ecaplot.bat", getenv("PATH"), X_OK) )
- system( "ecaplot" );
- }
- /*--------------------------------------------------------------------------*/
- static void cancel()
- {;}
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/plotz100.c'
- then
- echo shar: will not over-write existing file "'src/plotz100.c'"
- else
- cat << \SHAR_EOF > 'src/plotz100.c'
- /* Z-100 video graphics primitives 04/02/92
- * Copyright 1983-1992 Albert Davis
- * low resolution color
- * interlace off, 640 pixels per scan line
- */
- #include "ecah.h"
- #include "pixelh.h"
- /*--------------------------------------------------------------------------*/
- struct graph *initz100(struct graph *);
- static void text(int,int,char*,int);
- static int readpixl(int,int);
- static void setpixel(int,int,int);
- static void pokebit(int,unsigned int,unsigned int,char);
- static void putstr(char*);
- static void finish(void);
- static void cancel(void);
- /*--------------------------------------------------------------------------*/
- #define BLUMEM (unsigned)0xc000
- #define REDMEM (unsigned)0xd000
- #define GRNMEM (unsigned)0xe000
- #define XCOFF 32
- #define YCOFF 32
- #define BLUE 1
- #define RED 2
- #define GREEN 4
- /*--------------------------------------------------------------------------*/
- #define vidbit(z) (0x80>>(z%8))
- #define vidmem(x,y) (((y/9)<<11) + ((y%9)<<7) + (x/8))
- /*--------------------------------------------------------------------------*/
- static struct graph *d;
- /*--------------------------------------------------------------------------*/
- struct graph *initz100(g)
- struct graph *g;
- {
- d = g;
- d->spx = setpixel;
- d->lin = NULL;
- d->box = NULL;
- d->txt = text;
- d->can = cancel;
- d->fin = finish;
- putstr("\33E");
- outp(0xd8,0x78); /* port, value */
- return d;
- }
- /*--------------------------------------------------------------------------*/
- static void text(col,lin,string,color)
- int col, lin, color;
- char *string;
- {
- static char pos[5] = { 27, 'Y', ' ', ' ', 0 };
- static char clr[5] = { 27, 'm', ' ', ' ', 0 };
-
- col /= d->ppc;
- lin /= d->lpc;
- pos[3] = (char)(col + XCOFF);
- pos[2] = (char)(lin + YCOFF);
- clr[2] = (char)(color + '0');
- clr[3] = (char)(d->back + '0');
- putstr(clr);
- putstr(pos);
- putstr(string);
- }
- /*--------------------------------------------------------------------------*/
- static int readpixl(x,y)
- int x,y;
- {
- unsigned int place, bitmask;
- int blue, red, green;
- place = vidmem(x,y);
- bitmask = vidbit(x);
- blue = !!( peekb(BLUMEM,place) & bitmask );
- red = !!( peekb(REDMEM,place) & bitmask );
- green = !!( peekb(GRNMEM,place) & bitmask );
- return ( blue + (red<<1) + (green<<2) );
- }
- /*--------------------------------------------------------------------------*/
- static void setpixel(x,y,color)
- int x,y,color;
- {
- register int place;
- register char bitmask;
- static int skip, oldcolor;
-
- if (!(--skip) || (color!=oldcolor))
- {
- oldcolor = color;
- if (color>=0)
- skip = 1;
- else
- {
- skip = -color;
- color = d->pri;
- }
- place = vidmem(x,y);
- bitmask = (char)vidbit(x);
- pokebit (color&BLUE, BLUMEM, place, bitmask);
- pokebit (color&RED, REDMEM, place, bitmask);
- pokebit (color&GREEN, GRNMEM, place, bitmask);
- }
- }
- /*--------------------------------------------------------------------------*/
- static void pokebit (test, para, offset, bitmask)
- unsigned int para, offset;
- int test;
- char bitmask;
- {
- char ch;
- if (test)
- ch = peekb(para,offset) | bitmask;
- else
- ch = peekb(para,offset) & ~bitmask;
- pokeb(para,offset,ch);
- }
- /*--------------------------------------------------------------------------*/
- static void putstr(str)
- char *str;
- {
- while ( *str )
- putchar(*str++);
- }
- /*--------------------------------------------------------------------------*/
- static void finish()
- {
- putstr("\r");
- }
- /*--------------------------------------------------------------------------*/
- static void cancel()
- {;}
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/polar.c'
- then
- echo shar: will not over-write existing file "'src/polar.c'"
- else
- cat << \SHAR_EOF > 'src/polar.c'
- /* polar 03/23/92
- * Copyright 1983-1992 Albert Davis
- * Functions for use in converting to and from polar coordinates, etc.
- */
- #include "ecah.h"
- #include "options.h"
- #include "declare.h"
- /*LINTLIBRARY*/
- /*--------------------------------------------------------------------------*/
- complex_t polartocomplex(polar_t);
- polar_t complextopolar(complex_t);
- double real(double,double);
- double imag(double,double);
- double phase(double,double);
- double db(double);
- /*--------------------------------------------------------------------------*/
- extern const struct options opt;
- /*--------------------------------------------------------------------------*/
- complex_t polartocomplex(p)
- polar_t p;
- {
- complex_t c;
- c.x = p.mag * cos(p.phz*DTOR);
- c.y = p.mag * sin(p.phz*DTOR);
- return c;
- }
- /*--------------------------------------------------------------------------*/
- polar_t complextopolar(c)
- complex_t c;
- {
- polar_t p;
- p.mag = cabs(c);
- p.phz = RTOD * atan2(c.y,c.x);
- return p;
- }
- /*--------------------------------------------------------------------------*/
- double real(mag,phase)
- double mag, phase;
- {
- return ( mag * cos(phase*DTOR) );
- }
- /*--------------------------------------------------------------------------*/
- double imag(mag,phase)
- double mag, phase;
- {
- return ( mag * sin(phase*DTOR) );
- }
- /*--------------------------------------------------------------------------*/
- double phase(real,imag)
- double real,imag;
- {
- return ( RTOD * atan2(imag,real) );
- }
- /*--------------------------------------------------------------------------*/
- double db(value)
- double value;
- {
- return ( value<1.001e-50 || value<opt.floor ) ? -999.999 : (20*log10(value));
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/probe.c'
- then
- echo shar: will not over-write existing file "'src/probe.c'"
- else
- cat << \SHAR_EOF > 'src/probe.c'
- /* probe 01/06/93
- * Copyright 1983-1992 Albert Davis
- * select which point in circuit to look at.
- * command line operations
- */
- #include "ecah.h"
- #include "argparse.h"
- #include "branch.h"
- #include "error.h"
- #include "io.h"
- #include "mode.h"
- #include "probh.h"
- #include "status.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- void cmd_plot(const char*,int*);
- void cmd_print(const char*,int*);
- static void do_probe(const char*,int*,probe_t*[]);
- static void alloc_probe_list(probe_t**);
- static void add_probes(const char*,int*,probe_t*);
- static int add_all_nodes(int,probe_t*,probe_t*);
- static int add_branches(const char*,int*,int,probe_t*,probe_t*);
- static int add_node_list(const char*,int*,int,probe_t*,probe_t*);
- static void clear_probes(probe_t*);
- static void list_probes(probe_t*,const char*);
- /*--------------------------------------------------------------------------*/
- extern const struct ioctrl io;
- extern const struct status stats;
-
- extern probe_t *plotlist[];
- extern probe_t *probelist[];
- extern char e_om[], e_int[];
- /*--------------------------------------------------------------------------*/
- void cmd_plot(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- do_probe(cmd,cnt,plotlist);
- }
- /*--------------------------------------------------------------------------*/
- void cmd_print(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- do_probe(cmd,cnt,probelist);
- }
- /*--------------------------------------------------------------------------*/
- static void do_probe(cmd,cnt,probes)
- const char *cmd;
- int *cnt;
- probe_t *probes[];
- {
- int simtype = sNONE;
-
- allocate(sSTATUS);
-
- (void)argparse(cmd,cnt,ONEPASS,
- "TRan", aENUM, &simtype, sTRAN,
- "AC", aENUM, &simtype, sAC,
- "DC", aENUM, &simtype, sDC,
- "OP", aENUM, &simtype, sOP,
- "FOurier", aENUM, &simtype, sFOURIER,
- "");
- if (!simtype){
- if (!cmd[*cnt]){
- list_probes(probes[sTRAN] ,"tran");
- list_probes(probes[sAC] ,"ac");
- list_probes(probes[sDC] ,"dc");
- list_probes(probes[sOP] ,"op");
- list_probes(probes[sFOURIER],"fourier");
- }else if (pmatch(cmd,cnt,"CLEAR")){
- int ii;
- for (ii = sSTART; ii < sCOUNT; ++ii)
- clear_probes(probes[ii]);
- }else{
- syntax(cmd,cnt,bERROR);
- }
- }else{
- if (!cmd[*cnt]){
- list_probes(probes[simtype],"");
- }else if (pmatch(cmd,cnt,"CLEAR")){
- clear_probes(probes[simtype]);
- }else{
- alloc_probe_list(&(probes[simtype]));
- add_probes(cmd,cnt,probes[simtype]);
- }
- }
- }
- /*--------------------------------------------------------------------------*/
- static void alloc_probe_list(probes)
- probe_t **probes;
- {
- if (!*probes)
- *probes=(probe_t*)calloc(PROBECOUNT,sizeof(probe_t));
- if (!*probes)
- error(bERROR, e_om, "alloc_probe_list");
- }
- /*--------------------------------------------------------------------------*/
- static void add_probes(cmd,cnt,probes)
- const char *cmd;
- int *cnt;
- probe_t *probes;
- { /* BUG: ctostr may not advance */
- int probecount = 0; /* if its 1st char is a term */
- while (cmd[*cnt]){ /* can cause loss of rest or str */
- probe_t prb;
- int oldcount = probecount;
- int paren = 0;
- prb.lo = prb.hi = 0.;
- (void)ctostr(cmd,cnt,prb.what,LABELEN);
- if (!*(prb.what))
- syntax(cmd,cnt,bWARNING);
- paren += skiplparen(cmd,cnt);
- if (pmatch(cmd,cnt,"NODES")){ /* all nodes */
- probecount = add_all_nodes(probecount,probes,&prb);
- }else if (isdigit(cmd[*cnt])){ /* listed nodes (numbered) */
- probecount = add_node_list(cmd,cnt,probecount,probes,&prb);
- }else{ /* branches */
- probecount = add_branches(cmd,cnt,probecount,probes,&prb);
- }
- paren -= skiprparen(cmd,cnt);
- if (paren != 0)
- syntax(cmd,cnt,bWARNING);
- if (skiplparen(cmd,cnt)){
- double lo, hi;
- lo = ctof(cmd,cnt);
- hi = ctof(cmd,cnt);
- while (oldcount < probecount){
- probes[oldcount].lo = lo;
- probes[oldcount].hi = hi;
- ++oldcount;
- }
- if (!skiprparen(cmd,cnt))
- syntax(cmd,cnt,bWARNING);
- }
- if (probecount > PROBECOUNT)
- error(bERROR, e_int, "too many probes (missed trap)");
- }
- *probes[probecount].what = '\0';
- }
- /*--------------------------------------------------------------------------*/
- static int add_all_nodes(probecount,probes,prb)
- int probecount;
- probe_t *probes;
- probe_t *prb;
- {
- for (prb->p.node = 1;
- prb->p.node <= stats.user_nodes && prb->p.node < PROBECOUNT;
- prb->p.node++){
- probes[probecount++] = *prb;
- if (probecount > PROBECOUNT-1)
- error(bERROR, e_int, "too many probes");
- }
- return probecount;
- }
- /*--------------------------------------------------------------------------*/
- static int add_branches(cmd,cnt,probecount,probes,prb)
- const char *cmd;
- int *cnt;
- int probecount;
- probe_t *probes;
- probe_t *prb;
- {
- int savecnt;
- const branch_t *stop;
- savecnt = *cnt;
- stop = prb->p.brh = firstbranch_dev();
- if (exists(stop)){
- int savecnt;
- int newcnt;
- newcnt = savecnt = *cnt;
- do { /* look for all matching branches */
- *cnt = savecnt;
- prb->p.brh = findbranch(cmd, cnt, prb->p.brh, lastbranch_dev());
- if (exists(prb->p.brh)){
- probes[probecount++] = *prb;
- if (probecount > PROBECOUNT-1)
- error(bERROR, e_int, "too many probes");
- newcnt = *cnt;
- while (exists(prb->p.brh->parent)){ /* don't get lost */
- prb->p.brh = prb->p.brh->parent; /* in a subckt */
- }
- }else{
- *cnt = newcnt;
- break; /* didn't find, this time */
- }
- } while (prb->p.brh = nextbranch_dev(prb->p.brh), prb->p.brh != stop);
- }
- if (savecnt == *cnt){ /* didn't find matching branch */
- syntax(cmd,&savecnt,bWARNING);
- skiparg(cmd,cnt);
- }
- return probecount;
- }
- /*--------------------------------------------------------------------------*/
- static int add_node_list(cmd,cnt,probecount,probes,prb)
- const char *cmd;
- int *cnt;
- int probecount;
- probe_t *probes;
- probe_t *prb;
- {
- while (isdigit(cmd[*cnt])){
- int savecnt;
- savecnt = *cnt;
- prb->p.node = ctoi(cmd,cnt);
- if (prb->p.node <= stats.total_nodes){
- probes[probecount++] = *prb;
- if (probecount > PROBECOUNT-1)
- error(bERROR, e_int, "too many probes");
- }else{
- syntax(cmd,&savecnt,bWARNING);
- }
- }
- return probecount;
- }
- /*--------------------------------------------------------------------------*/
- static void clear_probes(probes)
- probe_t *probes;
- {
- if (probes)
- *probes[0].what = '\0';
- }
- /*--------------------------------------------------------------------------*/
- static void list_probes(probes,label)
- probe_t *probes;
- const char *label;
- {
- mprintf(io.mstdout, "%-7s", label);
- if (probes){
- int ii;
- for (ii = 0; *probes[ii].what; ii++){
- mprintf(io.mstdout, " %s", probename(probes[ii]));
- if (probes[ii].lo != probes[ii].hi){
- mprintf(io.mstdout, "(%s,%s)",
- ftos(probes[ii].lo,"",5,io.formaat),
- ftos(probes[ii].hi,"",5,io.formaat));
- }
- }
- }
- mprintf(io.mstdout, "\n");
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/probe2.c'
- then
- echo shar: will not over-write existing file "'src/probe2.c'"
- else
- cat << \SHAR_EOF > 'src/probe2.c'
- /* probe2 01/03/93
- * Copyright 1983-1992 Albert Davis
- * probe utilities - not related to the official list, but the strange ones
- * like worstcase and plotting
- */
- #include "ecah.h"
- #include "argparse.h"
- #include "branch.h"
- #include "error.h"
- #include "probh.h"
- #include "status.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- probe_t pr1set(const char*,int*);
- char *probename(probe_t);
- /*--------------------------------------------------------------------------*/
- extern const struct status stats;
- /*--------------------------------------------------------------------------*/
- /* pr1set: (set one probe)
- * Scan a command string.
- * Return a probe structure corresponding to the argument (eat it)
- * It does not actually set a probe point.
- * If the element or node does not exist, both what are brh are nulled.
- * There is no check for validity of the parameter name.
- */
- probe_t pr1set(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- probe_t prb;
-
- if (isalpha(cmd[*cnt])){
- (void)ctostr(cmd,cnt,prb.what,LABELEN);
- }else if (isdigit(cmd[*cnt])){
- (void)strcpy(prb.what, "V");
- }else{
- *prb.what = '\0';
- prb.p.node = 0;
- syntax(cmd,cnt,bWARNING);
- }
-
- if (isdigit(cmd[*cnt])){
- prb.p.node = ctoi(cmd,cnt);
- if (prb.p.node > stats.total_nodes){
- *prb.what = '\0';
- prb.p.node = 0;
- syntax(cmd,cnt,bWARNING);
- }
- }else{
- prb.p.brh = findbranch(cmd,cnt,firstbranch_dev(),lastbranch_dev());
- if (!exists(prb.p.brh)){
- *prb.what = '\0';
- prb.p.brh = (branch_t*)NULL;
- syntax(cmd,cnt,bWARNING);
- }
- }
- return prb;
- }
- /*--------------------------------------------------------------------------*/
- /* probename: returns a string corresponding to a possible probe point
- * (suitable for printing)
- * It has nothing to do with whether it was selected or not
- * the return string is static, and overwritten on every call.
- */
- char *probename(prb)
- probe_t prb;
- {
- static char string[BUFLEN+8];
-
- if (*prb.what){
- if (prb.p.node <= stats.total_nodes){
- sprintf(string, "%s(%u)", prb.what, prb.p.node);
- }else{
- sprintf(string, "%s(%s)", prb.what, printlabel(prb.p.brh,NO));
- }
- }else{
- sprintf(string,"undefined");
- }
- strcpy(&(string[BUFLEN-3]), "++");
- return string;
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/probe3.c'
- then
- echo shar: will not over-write existing file "'src/probe3.c'"
- else
- cat << \SHAR_EOF > 'src/probe3.c'
- /* probe3 01/03/93
- * Copyright 1983-1992 Albert Davis
- * probe utilities, related to the signal and bias probe lists
- */
- #include "ecah.h"
- #include "probh.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- int probcount(int);
- /*--------------------------------------------------------------------------*/
- extern probe_t *probelist[];
- /*--------------------------------------------------------------------------*/
- int probcount(simtype) /* count probes */
- int simtype; /* called by: fourier, random */
- {
- int ii;
- int count = 0;
-
- if (probelist[simtype]){
- for (ii = 0; *probelist[simtype][ii].what; ii++){
- count++;
- }
- }
- return count;
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/qfree.c'
- then
- echo shar: will not over-write existing file "'src/qfree.c'"
- else
- cat << \SHAR_EOF > 'src/qfree.c'
- /* qfree 04/02/92
- * Copyright 1983-1992 Albert Davis
- * free an area (as in free) and NULL its pointer
- *
- */
- #include "ecah.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- void qfree(void**);
- /*--------------------------------------------------------------------------*/
- void qfree(ptr)
- void **ptr;
- {
- if (*ptr)
- free(*ptr);
- *ptr = (void*)NULL;
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/quit.c'
- then
- echo shar: will not over-write existing file "'src/quit.c'"
- else
- cat << \SHAR_EOF > 'src/quit.c'
- /* quit 04/02/92
- * Copyright 1983-1992 Albert Davis
- * exits the program
- */
- #include "ecah.h"
- #include "mode.h"
- #include "options.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- void cmd_quit(const char*, int*);
- /*--------------------------------------------------------------------------*/
- extern const struct options opt;
- extern int run_mode; /* variations on handling of dot cmds */
- /*--------------------------------------------------------------------------*/
- /*ARGSUSED*/
- void cmd_quit(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- if (run_mode == rEXECUTE){
- if (match(cmd,"END") && opt.acct)
- cmd_status();
- exit(0);
- }
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/time_it.c'
- then
- echo shar: will not over-write existing file "'src/time_it.c'"
- else
- cat << \SHAR_EOF > 'src/time_it.c'
- /* time_it.c 12/31/92
- * Copyright 1983-1992 Albert Davis
- * Time a command, or whatever
- */
- /*--------------------------------------------------------------------------*/
- #include "ecah.h"
- #ifndef NOTIME
- /*--------------------------------------------------------------------------*/
- #include "error.h"
- #include "status.h"
- #include <sys/resource.h>
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- void time_fullreset(struct time_s*);
- void time_reset(struct time_s*);
- void time_zstart(struct time_s*);
- void time_start(struct time_s*);
- void time_stop(struct time_s*);
- void time_check(struct time_s*);
- /*--------------------------------------------------------------------------*/
- extern char e_int[];
- /*--------------------------------------------------------------------------*/
- void time_fullreset(y)
- struct time_s *y;
- {
- y->total_user = 0.;
- y->total_system= 0.;
- time_reset(y);
- }
- /*--------------------------------------------------------------------------*/
- void time_reset(y)
- struct time_s *y;
- {
- y->last_user = 0.;
- y->last_system = 0.;
- y->ref_user = 0.;
- y->ref_system = 0.;
- y->running = NO;
- }
- /*--------------------------------------------------------------------------*/
- void time_zstart(y)
- struct time_s *y;
- {
- time_reset(y);
- time_start(y);
- }
- /*--------------------------------------------------------------------------*/
- void time_start(y)
- struct time_s *y;
- {
- if (y->running){
- error(bWARNING, e_int, "clock already running");
- time_check(y);
- }else{
- struct rusage x;
- (void)getrusage(RUSAGE_SELF,&x);
- y->ref_user =
- (double)(x.ru_utime.tv_sec) + (double)(x.ru_utime.tv_usec)*1e-6;
- y->ref_system =
- (double)(x.ru_stime.tv_sec) + (double)(x.ru_stime.tv_usec)*1e-6;
- y->running = YES;
- }
- }
- /*--------------------------------------------------------------------------*/
- void time_stop(y)
- struct time_s *y;
- {
- if (!y->running){
- error(bWARNING, e_int, "clock not running");
- }else{
- struct rusage x;
- double utime, stime;
- double runtime;
- (void)getrusage(RUSAGE_SELF,&x);
-
- utime=(double)(x.ru_utime.tv_sec)+(double)(x.ru_utime.tv_usec)*1e-6;
- runtime = utime - y->ref_user;
- y->ref_user = 0.;
- y->last_user += runtime;
- y->total_user += runtime;
-
- stime=(double)(x.ru_stime.tv_sec)+(double)(x.ru_stime.tv_usec)*1e-6;
- runtime = stime - y->ref_system;
- y->ref_system = 0.;
- y->last_system += runtime;
- y->total_system+= runtime;
- y->running = NO;
- }
- }
- /*--------------------------------------------------------------------------*/
- void time_check(y)
- struct time_s *y;
- {
- if (y->running){
- time_stop(y);
- time_start(y);
- }
- }
- /*--------------------------------------------------------------------------*/
- #endif
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/title.c'
- then
- echo shar: will not over-write existing file "'src/title.c'"
- else
- cat << \SHAR_EOF > 'src/title.c'
- /* title 10/08/91
- * Copyright 1983-1992 Albert Davis
- * set title on printouts, etc.
- */
- #include "ecah.h"
- #include "io.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- void cmd_title(const char*,int*);
- /*--------------------------------------------------------------------------*/
- extern struct ioctrl io;
- extern char head[];
- /*--------------------------------------------------------------------------*/
- void cmd_title(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- io.where = (cmd[*cnt]) ? 0 : io.mstdout;
-
- if (cmd[*cnt])
- strcpy(head, &cmd[*cnt]);
- mprintf(io.where,"%s\n",head);
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/tr.c'
- then
- echo shar: will not over-write existing file "'src/tr.c'"
- else
- cat << \SHAR_EOF > 'src/tr.c'
- /* tr 03/23/92
- * Copyright 1983-1992 Albert Davis
- * tran and fourier commands -- top
- */
- #include "ecah.h"
- #include "mode.h"
- #include "status.h"
- #include "tr.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- void cmd_tr(const char*,int*);
- void cmd_fourier(const char*,int*);
- /*--------------------------------------------------------------------------*/
- extern struct status stats;
- extern int run_mode; /* variations on handling of dot cmds */
- extern int sim_mode; /* simulation type (AC, DC, ...) */
- /*--------------------------------------------------------------------------*/
- /* cmd_tr: transient analysis command
- */
- void cmd_tr(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- static transient_t tr;
-
- sim_mode = sTRAN;
- time_zstart(&(stats.total));
- time_zstart(&(stats.tran));
- stats.iter[sim_mode] = 0;
- stats.iter[iPRINTSTEP] = 0;
-
- allocate(sim_mode);
- tr_setup(cmd,cnt,&tr);
- if (run_mode != rEXECUTE)
- return;
- tr_sweep(&tr);
-
- time_stop(&(stats.tran));
- time_stop(&(stats.total));
- }
- /*--------------------------------------------------------------------------*/
- /* cmd_fourier: fourier analysis command
- * performs transient analysis, silently, then fft.
- * outputs results of fft
- */
- void cmd_fourier(cmd,cnt)
- const char *cmd;
- int *cnt;
- {
- static fourier_t fo;
-
- sim_mode = sFOURIER;
- time_zstart(&(stats.total));
- time_zstart(&(stats.four));
- stats.iter[sim_mode] = 0;
- stats.iter[iPRINTSTEP] = 0;
-
- allocate(sim_mode);
- fo_setup(cmd,cnt,&fo);
- if (run_mode != rEXECUTE)
- return;
- tr_sweep(&fo.tr);
- foout(fo.start,fo.stop,fo.step);
-
- time_stop(&(stats.four));
- time_stop(&(stats.total));
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/trim.c'
- then
- echo shar: will not over-write existing file "'src/trim.c'"
- else
- cat << \SHAR_EOF > 'src/trim.c'
- /* trim 11/06/89
- * Copyright 1983-1992 Albert Davis
- * remove whitespace from the end of strings
- */
- #include "ecah.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- char *trim(char*);
- /*--------------------------------------------------------------------------*/
- char *trim(string)
- char *string;
- {
- int index;
-
- index = strlen(string);
- while (index > 0 && !isgraph(string[--index]))
- string[index] = '\0' ;
- return string;
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/tr_adv.c'
- then
- echo shar: will not over-write existing file "'src/tr_adv.c'"
- else
- cat << \SHAR_EOF > 'src/tr_adv.c'
- /* tr_adv 02/15/92
- * Copyright 1983-1992 Albert Davis
- * Functions to set up the next time step, and next iteration
- */
- #include "ecah.h"
- #include "branch.h"
- #include "error.h"
- #include "mode.h"
- #include "status.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- void trsetup(branch_t*);
- /*--------------------------------------------------------------------------*/
- extern struct status stats;
- extern const int sim_mode;
- extern const int sim_phase;
- extern const double trtime; /* transient analysis time */
- /*--------------------------------------------------------------------------*/
- /* trsetup: set up guesses for model evaluation
- * saves old model inputs, and computes new inputs (volts and current)
- * also saves old matrix parameters, for convergence checking
- */
- void trsetup(brh)
- branch_t *brh;
- {
- if (exists(brh->parent)){
- brh->bypass = brh->parent->bypass;
- }
- brh->y2 = brh->y1;
- brh->y1 = brh->y0;
- brh->iter = stats.iter[iTOTAL];
- if (sim_mode == sDC || sim_phase == pINIT_DC){ /* initial dc */
- brh->mt1 = brh->m0;
- brh->steptime = brh->oldsteptime = trtime;
- brh->dt = 0.;
- }else if (brh->steptime != trtime){ /* new time step */
- if (brh->steptime < trtime){ /* forward */
- brh->oldsteptime = brh->steptime;
- brh->mt1 = brh->m0;
- brh->dt = trtime - brh->oldsteptime;
- brh->steptime = trtime;
- }else{ /*(brh->steptime > trtime)*/ /* backward */
- brh->dt = trtime - brh->oldsteptime;
- brh->steptime = trtime;
- }
- }
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/tr_volts.c'
- then
- echo shar: will not over-write existing file "'src/tr_volts.c'"
- else
- cat << \SHAR_EOF > 'src/tr_volts.c'
- /* trvolts 03/22/92
- * Copyright 1983-1992 Albert Davis
- * dc and tr volts between two nodes (4 different versions)
- */
- #include "ecah.h"
- #include "branch.h"
- #include "nodestat.h"
- #include "options.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- double dc_volts(node_t,node_t);
- double tr_volts(node_t,node_t);
- double tr_volts_limited(node_t,node_t);
- double tr_volts_t1(node_t,node_t);
- double logicval(int);
- /*--------------------------------------------------------------------------*/
- extern const double *volts; /* dc bias voltages */
- extern const double *imcon; /* transient voltages, most recent */
- extern const double *oldcon; /* transient voltages, 1 time ago */
- extern const struct nodestat *nstat;
- extern const struct options opt;
- /*--------------------------------------------------------------------------*/
- /* dc_volts: dc voltage for bias calculations
- */
- double dc_volts(n1,n2)
- node_t n1,n2;
- {
- return volts[n1.m] - volts[n2.m];
- }
- /*--------------------------------------------------------------------------*/
- /* tr_volts: transient voltage, best approximation, no limiting
- */
- double tr_volts(n1,n2)
- node_t n1,n2;
- {
- return imcon[n1.m] - imcon[n2.m];
- }
- /*--------------------------------------------------------------------------*/
- /* tr_volts_limited: transient voltage, best approximation, with limiting
- */
- double tr_volts_limited(n1,n2)
- node_t n1,n2;
- {
- double v;
- v = imcon[n1.m] - imcon[n2.m];
- if (v > opt.limit)
- v = opt.limit;
- if (v < -opt.limit)
- v = -opt.limit;
- return v;
- }
- /*--------------------------------------------------------------------------*/
- /* tr_volts_t1: transient voltage, 1 time ago
- */
- double tr_volts_t1(n1,n2)
- node_t n1,n2;
- {
- return oldcon[n1.m] - oldcon[n2.m];
- }
- /*--------------------------------------------------------------------------*/
- double logicval(n1) /* cryptic interpretation of logic value */
- int n1;
- {
- struct nodestat s;
- s = nstat[n1];
- return ( (2*s.lv0 + s.lv1)
- + (.1 * (opt.transits - s.quality))
- + (.01 * (2 - s.nodemode)));
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- if test -f 'src/tr_z.c'
- then
- echo shar: will not over-write existing file "'src/tr_z.c'"
- else
- cat << \SHAR_EOF > 'src/tr_z.c'
- /* tr_z 12/31/92
- * Copyright 1983-1992 Albert Davis
- * impedance looking across two nodes
- */
- #include "ecah.h"
- #include "branch.h"
- #include "error.h"
- #include "status.h"
- #include "declare.h"
- /*--------------------------------------------------------------------------*/
- double trz(node_t,node_t,double);
- /*--------------------------------------------------------------------------*/
- extern const struct status stats;
-
- extern const int decomp;
- extern const char e_om[];
-
- extern double *recon, *imcon;
- /*--------------------------------------------------------------------------*/
- /* trz: impedance looking across two nodes
- */
- /*ARGSUSED*/
- double trz(n1,n2,parallel)
- node_t n1,n2;
- double parallel;
- {
- static double *zapit;
- static unsigned gotsize;
- unsigned newsize;
- double *voltages; /* save right side vector */
- double *rightside;
- double raw_z;
-
- if (!decomp) /* can't do Z on transient first step. */
- return 0.0;
-
- newsize = ((unsigned)stats.total_nodes+2) * sizeof(double);
- if (!zapit){
- zapit = (double*)calloc(newsize,1); /* alloc memory */
- gotsize = newsize;
- }else if (newsize > gotsize){
- zapit = (double*)realloc((void*)zapit,newsize);
- gotsize = newsize;
- }
- if (!zapit)
- error(bERROR, e_om, "trz");
-
- rightside = recon; /* stash real voltages */
- voltages = imcon;
- imcon = recon = zapit;
-
- (void)memset((void*)recon,0,newsize);
- if (n1.m) /* build new rt side */
- recon[n1.m] = 1.; /* 1 amp current source */
- if (n2.m)
- recon[n2.m] = -1.;
-
- solve(); /* solve for volts */
- raw_z = tr_volts(n1,n2); /* volts is impedance */
-
- imcon = voltages; /* restore real stuff */
- recon = rightside;
- return 1. / ((1./raw_z)-parallel);
- }
- /*--------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------*/
- SHAR_EOF
- fi # end of overwriting check
- # End of shell archive
- exit 0
-