#include /* module print9 */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include TXHEADER tv[20]; /* Genus text structure */ union REGS inregs,outregs; char *ftoa(double,int); /****************************************************************************/ text(color,x,y,strng) /* place text starting at coords x,y */ char *strng; { texcolor(color); tex(x,y,strng); } /****************************************************************************/ tex(x,y,strng) /* color specified outside subroutine */ char *strng; { char string[127]; int i,fail=0; if(strlen(strng)>127) { warn("string length too long"); fail=1; goto abort; } strcpy(string,strng); for(i=0;i620) { strcpy(strng,"string too long"); goto again; } getimage(620-x,20,639,0); font(3); box3(YELLOW,2,BLACK,620-x,0,639,20,YELLOW,strng,""); wait=strlen(strng)/10+1; pause(wait); putimage(620-x,20,639,0); } /****************************************************************************/ illarg(void) /* place text in warning box */ { font(3); warn("ILLEGAL ARGUMENT"); } /****************************************************************************/ prompt(strng) /* place text at lower left of screen */ char *strng; { erase(); /* clear prompt line */ font(3); text(PALEBLUE,0,15,strng); } /****************************************************************************/ brief(strng) /* pause after message */ char *strng; { prompt(strng); pause(1); } /*****************************************************************************/ list(x,y,dy,strng) /* send list to screen in column format */ char *strng[]; { int i,y1; y1=y; for(i=0;strng[i];i++) /* list ends in null char */ { tex(x,y1,strng[i]); /* display string */ y1=y1-dy; /* move down dy pixels */ } return(i); } /****************************************************************************/ listlen(char *strng[]) /* find length of string list */ { int i; for(i=0;strng[i];i++); return(i); } /*****************************************************************************/ listm(x,dx,y,dy,n,strng,index) /* send list to screen in multi-column format */ char *strng[]; { unsigned char mask=1; int i,j=1,dex,y1=y,color; for(i=0;strng[i];i++,j++) /* list ends in null char */ { if(!(i%8)) mask=1; color=GREEN; dex=index*10+i/8; if(prohibs[dex]&mask) { frame(DARKBLUE,x-2,y1+2,x+40,y1-12); color=GREY; } text(color,x,y1,strng[i]); /* display string */ mask=mask<<1; y1=y1-dy; /* move down dy pixels */ if(j==n) { j=0; x=x+dx; /* move over dx pixels */ y1=y; /* top of column */ } } i=i%n; /* remainder */ return(i); /* length of last column */ } /*****************************************************************************/ vaxis(x,y,dy,n,value,dv,decpt) /* create vertical axis */ /* n = number of labels */ /* x,y = starting coordinates */ /* dy = distance between labels */ /* value = first label value */ /* decpt = number of digits to right of decimal point */ { int i,y1,label; y1=y; label=value; for(i=0;i0) /* not enough chars */ { for(i=b+1;i>-1;i--) numb[i+l]=numb[i]; /* shift right */ for(i=0;icounter[6]) { status[38]|=0x01; goto abort; /* time-out */ } } k=_bios_keybrd(_NKEYBRD_READ); /* wait for keyboard entry */ lsbyte=k&0xFF; if(lsbyte>=0x61&&lsbyte<=0x7A) lsbyte=lsbyte-0x20; /* convert lower to upper case */ if(lsbyte==0||lsbyte==0xE0) /* function key */ lsbyte=(k/256)|0x80; /* move char to lower byte */ abort: return(lsbyte); } /*****************************************************************************/ clkey(void) /* clear keyboard buffers */ { int i; for(i=0;i<=59;i++) if(keyboard[i]==CR||keyboard[i]==ESC||keyboard[i]>128) for(i=0;i<=59;i++) keyboard[i]=0; for(i=0;i<=59;i++) if(remotbuf[i]==CR||remotbuf[i]==ESC||remotbuf[i]>128) for(i=0;i<=59;i++) remotbuf[i]=0; for(i=0;i<=59;i++) if(localbuf[i]==CR||localbuf[i]==ESC||localbuf[i]>128) for(i=0;i<=59;i++) localbuf[i]=0; for(i=0;i<=59;i++) if(sysbuf[i]==CR||sysbuf[i]==ESC||sysbuf[i]>128) for(i=0;i<=59;i++) sysbuf[i]=0; for(i=0;i<=59;i++) parse[i]=0; } /*****************************************************************************/ clrkey(void) /* clear keyboard buffers */ { int i; for(i=0;i<=59;i++) { keyboard[i]=0; remotbuf[i]=0; localbuf[i]=0; parse[i]=0; } } /*****************************************************************************/ console(void) /* get keyboard input and put in buffer */ { int i,k=0; loop: if(_bios_keybrd(_NKEYBRD_READY)) /* is char avail? */ { k=caps(); /* read char from keyboard */ time(&keystart); /* start keyboard timer */ time(&scrstart); /* start screen-saver timer */ counter[9]=0; /* reset screen-saver timer */ i=strlen(keyboard); /* find end of string */ if((k==SP)&&!i) { clkey(); goto loop; } if(k==BS) { if(i) keyboard[i-1]=0; /* erase last char */ } else if(i<60) /* buffer limit */ keyboard[i]=k; /* add new char to buffer */ else clkey(); /* too many chars */ if(k==ESC) { clkey(); /* abort command input */ comseq=0; veriflag=0; statnum2=0; if(logno||histno ||(status[35]&0x80)) /* return to real-time */ { histno=0; logno=0; restdata(); /* restore database */ refresh=1; } } if(k<128) /* don't echo function keys */ prompt(keyboard); /* echo */ goto loop; /* test for another character */ } return(k); } /****************************************************************************/ notnum(strng) /* are there any non-numerals in string? */ char *strng; { int i,j=0; for(i=0;strng[i]!=CR&&strng[i];i++) /* delimiter = null or CR */ if(strng[i]<=0x2F ||strng[i]>=0x3A &&strng[i]!='-') j=1; if(j) warn("NON-NUMERAL"); return(j); } /****************************************************************************/ leading(n) /* add leading zeros if string length < n */ { int i,j,l; for(i=0;i<=n;i++) if(numb[i]==CR) numb[i]=0; /* replace CR with null */ i=strlen(numb); if(iy) { fail=1; if(counter[74]) /* odapc command flag */ { counter[74]=0; /* clear flag */ command3("ER2"); } clkey(); illarg(); } return(fail); } /****************************************************************************/ argu(n,x,y) /* is argument out of bounds? */ { int i,fail=0; if(parse[n]==CR) goto abort; /* no argument */ i=atoi(&parse[n]); if(iy) { fail=1; if(counter[74]) /* odapc command flag */ { counter[74]=0; /* clear flag */ command3("ER2"); } clkey(); illarg(); } else counter[53]=i; /* save argument */ abort: return(fail); } /**************************************************************************/ hex(byte) /* ascii hex representation */ { numb[0]=hexa((byte>>4)&0xF); /* upper nibble */ numb[1]=hexa(byte&0xF); /* lower nibble */ numb[2]=0; /* string terminator */ } /**************************************************************************/ hexa(num) /* binary to hex */ { if(num<=9) num=num+0x30; /* 0 to 9 */ else num=num+0x37; /* A to F */ return(num); } /*****************************************************************************/ comma(n) /* find position of comma number n in keyboard buffer */ { int i,j=0; for(i=0;parse[i]!=CR;i++) if(parse[i]==',') if(++j==n) break; return(i); } /*****************************************************************************/ sys(char *str) /* DOS command */ { int fail; clear(); if(gxSetMode(gxTEXT)) printf("CAN'T SET TEXT MODE\n"); if(fail=system(str)) /* DOS writes to screen */ printf("DOS FAILURE"); pause(2); if(gxSetMode(gxGRAPHICS)) printf("CAN'T SET GRAPHICS MODE\n"); refresh=1; return(fail); } /*****************************************************************************/ sysoff(char *str) /* DOS command */ { int fail; clear(); if(fail=system("echo off")) goto abort; if(fail=system(str)) /* DOS writes to screen */ goto abort; abort: fail=system("echo on"); if(fail) { printf("DOS FAILURE"); pause(2); } return(fail); } /****************************************************************************/ font(index) /* select font */ { int fail,fore,back; if(fail=txGetColor(&fore,&back)) { warn("can't get font colors\n"); goto abort; } if(fail=txSetFont(&tv[index])) { warn("can't select font\n"); goto abort; } if(fail=txSetColor(fore,back)) warn("can't set font colors\n"); abort: return(fail); } /****************************************************************************/ loadfont(void) /* load fonts into expanded memory */ /* note that if you try to print an undefined char in these fonts, strange things may happen to the program. For example, a CR in RMN12 changes the background colors! */ { char *name[]= { "RMN30.GFT", "RMN22.GFT", "RMN15.GFT", "RMN12.GFT", "SCR53.GFT", "COU13.GFT", 0 }; int i,fail; long free1,free2; printf("LOADING FONTS\n"); free1=gxVirtualFree(gxEMM)/1024; printf("%d k available expanded memory\n",free1); for(i=0;i<=5;i++) if(fail=txFileFont(gxEMM,name[i],&tv[i])) { printf("can't register font\n"); goto abort; } printf("ROTATING FONTS\n"); if(txRotateFont(&tv[2],tx090,gxEMM,&tv[6])) printf("can't rotate font\n"); if(txRotateFont(&tv[3],tx090,gxEMM,&tv[7])) printf("can't rotate font\n"); free2=gxVirtualFree(gxEMM)/1024; printf("%d k used by fonts\n",free1-free2); for(i=0;i<=7;i++) { if(fail=txSetFont(&tv[i])) { printf("can't select font\n"); goto abort; } if(txSetFace(txTRANS)) /* transparent text */ printf("can't set font face\n"); if(texcolor(WHITE)) /* white text on black background */ printf("can't set font colors\n"); } abort: return(fail); } /****************************************************************************/ freeram(void) /* free font memory */ { int i; for(i=0;i<=7;i++) if(txFreeFont(&tv[i])) printf("CAN'T FREE FONT RAM\n"); } /****************************************************************************/ texcolor(color) /* set text foreground color */ { int fail; if(fail=txSetColor(color,BLACK)) printf("CAN'T SET FONT COLOR\n"); return(fail); } /*****************************************************************************/ char *ftoa(double numba, int dec) /* floating point to ascii string */ { char str[20]; int i,len; double frac,n,mult; mult=exp(EXP*dec); frac=fabs(mult*modf(numba,&n)); ltoa((long)n,numb,10); /* integer */ if(modf(frac,&n)>.5) frac=frac+1; /* round up */ if(dec) { strcat(numb,"."); /* decimal pt */ ltoa((long)frac,str,10); /* fraction to string */ loop: if((len=strlen(str))0;i--) str[i]=str[i-1]; /* shift digits right */ str[len+1]=0; /* terminator */ str[0]='0'; /* leading zero */ goto loop; /* re-test */ } strcat(numb,str); /* fraction */ } return(numb); } /*****************************************************************************/ char *comp(double w, double x) /* convert reactance to component */ { char str[20]; double value; if(x>0) { value=x/w; /* inductance in uH */ strcpy(str," uH"); } else { value=-1.e6/(x*w); /* capacitance in pF */ strcpy(str," pF"); } ltoa((long)value,numb,10); /* value */ strcat(numb,str); /* units */ return(numb); } /****************************************************************************/ lefthit(void) /* read left mouse button hit queue */ { int hits; inregs.x.bx=0; /* left button queue */ inregs.x.ax=5; int86(0x33,&inregs,&outregs); hits=outregs.x.bx; return(hits); } /****************************************************************************/ righthit(void) /* read right mouse button hit queue */ { int hits; inregs.x.bx=1; /* right button queue */ inregs.x.ax=5; int86(0x33,&inregs,&outregs); hits=outregs.x.bx; return(hits); } /****************************************************************************/ click(void) /* read mouse buttons */ { int x1,y1,x2,y2,left,right,code=0; left=lefthit(); /* read left mouse button */ x1=outregs.x.cx; y1=479-outregs.x.dx; right=righthit(); /* read right mouse button */ x2=outregs.x.cx; y2=479-outregs.x.dx; if(left&&(!right)) { thous(100); /* wait for delayed finger */ right=righthit(); x2=outregs.x.cx; y2=479-outregs.x.dx; } if(right&&(!left)) { thous(100); /* wait for delayed finger */ left=lefthit(); x1=outregs.x.cx; y1=479-outregs.x.dx; } if(left) { code=1; /* click left */ if(left>1) code=4; /* double click */ else { thous(200); if(lefthit()) code=4; } outregs.x.cx=x1; outregs.x.dx=479-y1; } if(right) { code=2; /* click right */ if(right>1) code=5; /* double click */ else { thous(200); if(righthit()) code=5; } outregs.x.cx=x2; outregs.x.dx=479-y2; } if(left&&right) code=3; /* click both */ return(code); } /****************************************************************************/ leftrel(void) /* read left mouse button release queue */ { int hits; inregs.x.bx=0; /* left button queue */ inregs.x.ax=6; int86(0x33,&inregs,&outregs); hits=outregs.x.bx; return(hits); } /****************************************************************************/ rightrel(void) /* read right mouse button release queue */ { int hits; inregs.x.bx=1; /* right button queue */ inregs.x.ax=6; int86(0x33,&inregs,&outregs); hits=outregs.x.bx; return(hits); } /****************************************************************************/ inmouse(void) /* init mouse */ { int result; inregs.x.ax=0; int86(0x33,&inregs,&outregs); result=outregs.x.ax; return(result); } /****************************************************************************/ remouse(void) /* reset mouse (moves to center of screen) */ { inregs.x.ax=0x21; int86(0x33,&inregs,&outregs); return(outregs.x.ax); } /****************************************************************************/ onmouse(void) /* show mouse cursor */ { inregs.x.ax=1; int86(0x33,&inregs,&outregs); return(outregs.x.ax); } /****************************************************************************/ offmouse(void) /* hide mouse cursor */ { inregs.x.ax=2; int86(0x33,&inregs,&outregs); return(outregs.x.ax); } /****************************************************************************/ movmouse(x,y) /* move mouse cursor */ { inregs.x.ax=4; inregs.x.cx=x; inregs.x.dx=479-y; int86(0x33,&inregs,&outregs); return(outregs.x.ax); }