home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / TIERRA40.ZIP / BEAGLE / TOOLS.C < prev    next >
Text File  |  1992-09-11  |  21KB  |  717 lines

  1. /* tools.c  22-3-92  tools for graphis and windows */
  2. /*** Beagle Explorer: Version 3.1  Copyright (c) 1990, 1991, 1992  Tom Ray ***/
  3.  
  4. #include "beagle.h"
  5. #include "externb.h"
  6.  
  7. int    graphics_adapter = 0, graphics_mode = 0;
  8.  
  9. void grinit(char  path[])
  10. {   char  dir[120], *epath;
  11.     HWND  whgr, whins;
  12.     TRANSACTION  *ptgr;
  13.     int  i, drive, ndrive, ga, gm, max;
  14.     size_t  dln;
  15.  
  16.     detectgraph(&graphics_adapter,&graphics_mode);
  17.     ga = graphics_adapter; gm = graphics_mode;
  18.     initgraph(&ga,&gm,path);
  19.     if(ga > -1) goto found;
  20.     if(ga != -3)
  21.         initerror(ga);
  22.     /* look in current directory */
  23.     ga = graphics_adapter; gm = graphics_mode;
  24.     initgraph(&ga,&gm,"");
  25.     if(ga > -1) goto found;
  26.     if(ga != -3)
  27.         initerror(ga);
  28.     /* look in x:\tc directories for all drives */
  29.     drive  = getdisk(); /* drive = current drive */
  30.     ndrive = setdisk(drive); /* ndrive = number of drives */
  31.     for(i = 2; i < ndrive; i++)
  32.     {   sprintf(path,"%c:/tc", 'a' + i);
  33.         ga = graphics_adapter; gm = graphics_mode;
  34.         initgraph(&ga,&gm,path);
  35.         if(ga > -1) goto found;
  36.         if(ga != -3)
  37.             initerror(ga);
  38.     }
  39.     /* look in x:\tc\bgi directories for all drives */
  40.     for(i = 2; i < ndrive; i++)
  41.     {   sprintf(path,"%c:/tc/bgi", 'a' + i);
  42.         ga = graphics_adapter; gm = graphics_mode;
  43.         initgraph(&ga,&gm,path);
  44.         if(ga > -1) goto found;
  45.         if(ga != -3)
  46.             initerror(ga);
  47.     }
  48.     /* look in x:\bc\bgi directories for all drives */
  49.     for(i = 2; i < ndrive; i++)
  50.     {   sprintf(path,"%c:/bc/bgi", 'a' + i);
  51.         ga = graphics_adapter; gm = graphics_mode;
  52.         initgraph(&ga,&gm,path);
  53.         if(ga > -1) goto found;
  54.         if(ga != -3)
  55.             initerror(ga);
  56.     }
  57.     /* search path */
  58.     epath = getenv("PATH");
  59.     max = strlen(epath);
  60.     while((dln = strcspn(epath,";")) && max > 0)
  61.     {   strncpy(path,epath,dln); path[dln] = 0;
  62.         ga = graphics_adapter; gm = graphics_mode;
  63.         initgraph(&ga,&gm,path);
  64.         if(ga > -1) goto found;
  65.         if(ga != -3)
  66.             initerror(ga);
  67.         epath += dln + 1;
  68.         max -= dln + 1;
  69.     }
  70.     epath = getenv("PATH");
  71.     max = strlen(epath);
  72.     while((dln = strcspn(epath,";")) && max > 0)
  73.     {   strncpy(dir,epath,dln); dir[dln] = 0;
  74.         sprintf(path,"%s/bgi", dir);
  75.         ga = graphics_adapter; gm = graphics_mode;
  76.         initgraph(&ga,&gm,path);
  77.         if(ga > -1) goto found;
  78.         if(ga != -3)
  79.             initerror(ga);
  80.         epath += dln + 1;
  81.         max -= dln + 1;
  82.     }
  83.     /* ask user for path to bgi files */
  84.     whgr = wigen(3,4,3,50,FRSINGLE,"graphics drivers path");
  85.     vatputf(whgr,0,1,"graphics drivers were not found in the path:");
  86.     vatputf(whgr,2,1,"please enter the correct path");
  87.     ptgr = vpreload(4,0,NULLF,NULLF,NULLF,NULLF);
  88.     (*(ptgr->def))[0].use_ext = TRUE;
  89.     vdeffld(ptgr,0,STRING,1,1,"",-1,45,NULL,path,NO);
  90.     whins = wiinv(23,28, "Ctrl-Enter to continue");
  91.     visible(whgr,YES,YES);
  92.     ptgr->fld_valfn = gr_chk;
  93.     vread(ptgr,whgr,YES);
  94.     vdelete(whins,NONE);
  95.     vdelete(whgr,NONE);
  96.     ga = graphics_adapter; gm = graphics_mode;
  97.     initgraph(&ga,&gm,path);
  98.     if(ga < 0)
  99.         initerror(ga);
  100.     found:
  101.     resolutions();
  102.     setcolor(1);
  103.     restorecrtmode();
  104. }
  105.  
  106. void initerror(int  val)
  107. {   HWND  whgr;
  108.  
  109.     whgr = wigen(3,4,1,50,FRSINGLE,"initgraph error");
  110.     if(val == -2)
  111.         vatputf(whgr,0,1,"cannot detect a graphics card");
  112.     if(val == -3)
  113.         vatputf(whgr,0,1,"cannot find driver file");
  114.     if(val == -4)
  115.         vatputf(whgr,0,1,"invalid driver");
  116.     if(val == -5)
  117.         vatputf(whgr,0,1,"insufficient memory to load driver");
  118.     vexit(0);
  119. }
  120.  
  121. void grwisetup(char  path[])
  122. {   char  curdir[80];
  123.     HWND  whgr;
  124.     TRANSACTION  *ptgr;
  125.     int  success;
  126.  
  127.     getcwd(curdir,79);
  128.     success = chdir(path);
  129.     chdir(curdir);
  130.     if(success)
  131.     {   whgr = wigen(3,4,3,50,FRSINGLE,"graphics drivers path");
  132.         vatputf(whgr,0,1,"graphics drivers were not found in the path:");
  133.         vatputf(whgr,2,1,"please enter the correct path");
  134.         ptgr = vpreload(4,0,NULLF,NULLF,NULLF,NULLF);
  135.         (*(ptgr->def))[0].use_ext = TRUE;
  136.     vdeffld(ptgr,0,STRING,1,1,"",-1,45,NULL,path,NO);
  137.         visible(whgr,YES,YES);
  138.         ptgr->fld_valfn = gr_chk;
  139.         vread(ptgr,whgr,YES);
  140.         vdelete(whgr,NONE);
  141.     }
  142.     detectgraph(&graphics_adapter,&graphics_mode);
  143.     initgraph(&graphics_adapter,&graphics_mode,path);
  144.     resolutions();
  145.     setcolor(1);
  146.     restorecrtmode();
  147. }
  148.  
  149. int gr_chk(TRANSACTION  *tp)
  150. {   char  curdir[80];
  151.     int   success;
  152.  
  153.     getcwd(curdir,79);
  154.     success = chdir((*(tp->def))[tp->cur_fld].dataptr);
  155.     chdir(curdir);
  156.     if(success) return FALSE;
  157.     return TRUE;
  158. }
  159.  
  160. void resolutionn(void)
  161. {    x_res = getmaxx() + 1;
  162.      y_res = getmaxy() + 1;
  163. }
  164.  
  165. void resolutions(void)
  166. {   switch(graphics_adapter)
  167.     {   case CGA: switch(graphics_mode)
  168.         {   case CGAC0: x_res = 320; y_res = 200; return;
  169.             case CGAC1: x_res = 320; y_res = 200; return;
  170.             case CGAC2: x_res = 320; y_res = 200; return;
  171.             case CGAC3: x_res = 320; y_res = 200; return;
  172.             case CGAHI: x_res = 640; y_res = 200; return;
  173.         }
  174.         case MCGA: switch(graphics_mode)
  175.         {   case MCGAC0:  x_res = 320; y_res = 200; return;
  176.             case MCGAC1:  x_res = 320; y_res = 200; return;
  177.             case MCGAC2:  x_res = 320; y_res = 200; return;
  178.             case MCGAC3:  x_res = 320; y_res = 200; return;
  179.             case MCGAMED: x_res = 640; y_res = 200; return;
  180.             case MCGAHI:  x_res = 640; y_res = 480; return;
  181.         }
  182.         case EGA: switch(graphics_mode)
  183.         {   case EGALO: x_res = 640; y_res = 200; return;
  184.             case EGAHI: x_res = 640; y_res = 350; return;
  185.         }
  186.         case EGA64: switch(graphics_mode)
  187.         {   case EGA64LO: x_res = 640; y_res = 200; return;
  188.             case EGA64HI: x_res = 640; y_res = 350; return;
  189.         }
  190.         case EGAMONO: switch(graphics_mode)
  191.         {   case EGAMONOHI: x_res = 640; y_res = 350; return;
  192.         }
  193.         case IBM8514: switch(graphics_mode)
  194.         {   case IBM8514HI: x_res =  640; y_res = 480; return;
  195.             case IBM8514LO: x_res = 1024; y_res = 768; return;
  196.         }
  197.         case HERCMONO: switch(graphics_mode)
  198.         {   case HERCMONOHI: x_res = 720; y_res = 348; return;
  199.         }
  200.         case ATT400: switch(graphics_mode)
  201.         {   case ATT400C0:  x_res = 320; y_res = 200; return;
  202.             case ATT400C1:  x_res = 320; y_res = 200; return;
  203.             case ATT400C2:  x_res = 320; y_res = 200; return;
  204.             case ATT400C3:  x_res = 320; y_res = 200; return;
  205.             case ATT400MED: x_res = 640; y_res = 200; return;
  206.             case ATT400HI:  x_res = 640; y_res = 400; return;
  207.         }
  208.         case VGA: switch(graphics_mode)
  209.         {   case VGALO:  x_res = 640; y_res = 200; return;
  210.             case VGAMED: x_res = 640; y_res = 350; return;
  211.             case VGAHI:  x_res = 640; y_res = 480; return;
  212.         }
  213.         case PC3270: switch(graphics_mode)
  214.         {   case PC3270HI: x_res = 720; y_res = 350; return;
  215.         }
  216.     }
  217.     printf("\n\nUnable to proceed.\n");
  218.     printf("Requires CGA, MCGA, EGA, EGA64, EGAMONO, IBM8514, HERCMONO\n"
  219.         "ATT400, VGA or PC3270 adapter; with appropriate monitor.\n");
  220.     exit(0);
  221. }
  222.  
  223. /* graphics_adapter types:
  224.  
  225.     DETECT       0
  226.     CGA          1
  227.     MCGA         2
  228.     EGA          3
  229.     EGA64        4
  230.     EGAMONO      5
  231.     IBM8514      6
  232.     HERCMONO     7
  233.     ATT400       8
  234.     VGA          9
  235.     PC3270      10
  236.  
  237.    graphics_mode types:
  238.  
  239.    graphics    graphics    value   columns   palette     pages
  240.    adapter     modes               x rows
  241.  
  242.     CGA         CGAC0         0    320x200    C0           1
  243.                 CGAC1         1    320x200    C1           1
  244.                 CGAC2         2    320x200    C2           1
  245.                 CGAC3         3    320x200    C3           1
  246.                 CGAHI         4    640x200    2 color      1
  247.  
  248.     MCGA        MCGAC0        0    320x200    C0           1
  249.                 MCGAC1        1    320x200    C1           1
  250.                 MCGAC2        2    320x200    C2           1
  251.                 MCGAC3        3    320x200    C3           1
  252.                 MCGAMED       4    640x200    2 color      1
  253.                 MCGAHI        5    640x480    2 color      1
  254.  
  255.     EGA         EGALO         0    640x200    16 color     4
  256.                 EGAHI         1    640x350    16 color     2
  257.  
  258.     EGA64       EGA64LO       0    640x200    16 color     1
  259.                 EGA64HI       1    640x350    4 color      1
  260.  
  261.     EGAMONO     EGAMONOHI     3    640x350    2 color      1*
  262.                 EGAMONOHI     3    640x350    2 color      2**
  263.  
  264.     IBM8514     IBM8514HI     0    640x480    256 color
  265.                 IBM8514LO     0   1024x768    256 color
  266.  
  267.     HERCMONO    HERCMONOHI    0    720x348    2 color      2
  268.  
  269.     ATT400      ATT400C0      0    320x200    C0           1
  270.                 ATT400C1      1    320x200    C1           1
  271.                 ATT400C2      2    320x200    C2           1
  272.                 ATT400C3      3    320x200    C3           1
  273.                 ATT400MED     4    640x200    2 color      1
  274.                 ATT400HI      5    640x400    2 color      1
  275.  
  276.     VGA         VGALO         0    640x200    16 color     2
  277.                 VGAMED        1    640x350    16 color     2
  278.                 VGAHI         2    640x480    16 color     1
  279.  
  280.     PC3270      PC3270HI      0    720x350    2 color      1
  281.     
  282.      *  64K on EGAMONO card
  283.     ** 256K on EGAMONO card
  284. */
  285.  
  286. void g_keyboard(void)
  287. {   union u_type { int a; char b[3]; } keystroke;
  288.     int    get_keystroke(void);           /* declare a local subroutine */
  289.  
  290.     do keystroke.a = getkeystroke();
  291.     while (keystroke.b[0] != 27);        /* return if <Esc> is pressed */
  292. }
  293.  
  294. int getkeystroke(void)
  295. {   union REGS regs;
  296.  
  297.     regs.h.ah = 0;
  298.     return int86(0x16,®s,®s);
  299. }
  300.  
  301. void minmax(struct point  *p, struct xyrange  *r)
  302. {   if(r->f)
  303.     {   r->f = 0;
  304.         r->xn = r->xx = p->x;
  305.         r->yn = r->yx = p->y;
  306.     }
  307.     if(p->x < r->xn) r->xn = p->x; if(p->x > r->xx) r->xx = p->x;
  308.     if(p->y < r->yn) r->yn = p->y; if(p->y > r->yx) r->yx = p->y;
  309.     r->n++;
  310. }
  311.  
  312. struct point coords(struct point  *p)
  313. {   float    xl, yl, xmin, xmax, ymin, ymax, r = .75;
  314.     struct point  t;
  315.  
  316.     xmin = xnvf; xmax = xxvf; ymin = ynvf; ymax = yxvf;
  317.     xl = xmax - xmin; yl = ymax - ymin;
  318.     if(yl / xl >= r)
  319.     {   xmin -= (yl / r - xl) / 2.;
  320.         xmax += (yl / r - xl) / 2.;
  321.     }
  322.     else
  323.     {   ymin -= (r * xl - yl) / 2.;
  324.         ymax += (r * xl - yl) / 2.;
  325.     }
  326.     xl = xmax - xmin; yl = ymax - ymin;
  327.     t.x = 639. * (p->x - xmin) / xl; t.y = 479. - (479. * (p->y - ymin) / yl);
  328.     t.x = t.x * x_res / 640.; t.y = t.y * y_res / 480.;
  329.     return t;
  330. }
  331.  
  332. struct point rcoords(struct point  *p)
  333. {   float    xl, yl, xmin, xmax, ymin, ymax, r = .75;
  334.     struct point  t;
  335.  
  336.     xmin = xnvf; xmax = xxvf; ymin = ynvf; ymax = yxvf;
  337.     xl = xmax - xmin; yl = ymax - ymin;
  338.     if(yl / xl >= r)
  339.     {   xmin -= (yl / r - xl) / 2.;
  340.         xmax += (yl / r - xl) / 2.;
  341.     }
  342.     else
  343.     {   ymin -= (r * xl - yl) / 2.;
  344.         ymax += (r * xl - yl) / 2.;
  345.     }
  346.     xl = xmax - xmin; yl = ymax - ymin;
  347.     t.x = xmin + (p->x * (640. / 639.) * (xl / x_res));
  348.     t.y = ymin - ((p->y - (y_res * 479. / 480)) * (480. / 479.)*(yl/y_res));
  349.     return t;
  350. }
  351.  
  352. struct point * fxy(struct point  *p)
  353. {   struct point  t;
  354.  
  355.     t.x = (p->x - xnpl) / xlpl;
  356.     t.y = (p->y - ynpl) / ylpl;
  357.     return &t;
  358. }
  359.  
  360. struct point rrotr(struct point  *xy)
  361. {   struct point    p;
  362.  
  363.     if(rt) { p.x = xy->y; p.y = -xy->x; }
  364.     else p = *xy;
  365.     p.x = (p.x - xo) / xln; p.y = (p.y - yo) / yln;
  366.     return p;
  367. }
  368.  
  369. struct point rotr(struct point  *xy)
  370. {   struct point    p, t;
  371.  
  372.     t.x = xy->x * xln + xo; t.y = xy->y * yln + yo;
  373.     if(rt) { p.x = t.y; p.y = -t.x; }
  374.     else p = t;
  375.     return p;
  376. }
  377.  
  378. void sline(struct point  *p)
  379. {   struct point  t;
  380.  
  381.     t = rotr(p); minmax(&t,&xywin);
  382.     if(cad) fprintf(ouf, "li %.5f,%.5f;\n", t.x, t.y);
  383.     if(hp) fprintf(ouf, "pu %.5f,%.5f pd;\n", t.x, t.y);
  384.     if(scr)
  385.     {   t = coords(&t);
  386.         moveto((int) t.x,(int) t.y);
  387.     }
  388. }
  389.  
  390. void cline(struct point  *p)
  391. {   struct point  t;
  392.  
  393.     t = rotr(p); minmax(&t,&xywin);
  394.     if(cad) fprintf(ouf, "%.5f,%.5f;\n", t.x, t.y);
  395.     if(hp) fprintf(ouf, "pd %.5f,%.5f;\n", t.x, t.y);
  396.     if(scr)
  397.     {   t = coords(&t);
  398.         lineto((int) t.x,(int) t.y);
  399.     }
  400. }
  401.  
  402. void eline(struct point  *p)
  403. {   struct point  t;
  404.  
  405.     t = rotr(p); minmax(&t,&xywin);
  406.     if(cad) fprintf(ouf, "%.5f,%.5f;\npu;\n", t.x, t.y);
  407.     if(hp) fprintf(ouf, "pd %.5f,%.5f pu;\n", t.x, t.y);
  408.     if(scr)
  409.     {   t = coords(&t);
  410.         lineto((int) t.x,(int) t.y);
  411.     }
  412. }
  413.  
  414. void putpoint(struct point  *p, int color)
  415. {   struct point  t;
  416.  
  417.     t = rotr(p); minmax(&t,&xywin);
  418.     if(cad) fprintf(ouf, "%.5f,%.5f;\npu;\n", t.x, t.y);
  419.     if(hp) fprintf(ouf, "pd %.5f,%.5f pu;\n", t.x, t.y);
  420.     if(scr)
  421.     {   t = coords(&t);
  422.         putpixel((int) t.x, (int) t.y, color);
  423.     }
  424. }
  425.  
  426. void charsiz(float xz, float yz) /* sets character size and aspect ratio */
  427. {   if(cad) fprintf(ouf,"tz,%.5f;\nta,%.5f;\n", yz,  1.26 * xz / yz);
  428.     if(hp) fprintf(ouf,"sr %.5f,%.5f ;\n", xz, yz);
  429. }
  430.  
  431. void labchr(struct point  *p, float xz, float yz, float an, char lc)
  432. /* places a character centered at the coordinate p.  xz and yz are
  433. the character size.  an is the angle of the character */
  434. {   char    tmp[2];
  435.     struct point  t;
  436.  
  437.     if(rt) an -= 90.;
  438.     t = rotr(p); minmax(&t,&xywin);
  439.     if(cad)
  440.     {   if(an != 0 && !sclach) fprintf(ouf,"tr,%.5f;\n", an);
  441.         if(rt) { t.x -= xz / 2.; t.y += yz / 2.; }
  442.         else { t.x -= xz / 2.; t.y -= yz / 2.; }
  443.         fprintf(ouf,"tp,%.5f,%.5f,%c\n", t.x, t.y, lc);
  444.         if(an != 0 && !sclach) fprintf(ouf,"tr,0;\n");
  445.     }
  446.     if(hp)
  447.     {   if(an != 0 && !sclach) fprintf(ouf, "dr0,-1;\n");
  448.         fprintf(ouf,"pu%.5f,%.5f;cp-.333,-.25;lb%c;pu;\n",t.x,t.y,lc);
  449.         if(an != 0 && !sclach) fprintf(ouf,"dr;\n");
  450.     }
  451.     if(scr)
  452.     {   sprintf(tmp,"%c",lc); t = coords(&t);
  453.         outtextxy((int) t.x,(int) t.y,tmp);
  454.     }
  455. }
  456.  
  457. void labstr(struct point  *p, float xz, float yz, float an, char lab[])
  458. /* places a string, starting at the coordinate xp, yp */
  459. {   struct point  t;
  460.  
  461.     if(rt) an -= 90;
  462.     t = rotr(p); minmax(&t,&xywin);
  463.     if(cad)
  464.     {   if(an != 0) fprintf(ouf,"tr,%.5f;\n", an);
  465.         fprintf(ouf,"tp,%.5f,%.5f,%s\n", t.x, t.y, lab);
  466.         if(an != 0) fprintf(ouf,"tr,0;\n");
  467.     }
  468.     if(hp)
  469.     {   if(an == 90) fprintf(ouf, "dr0,1;\n");
  470.         if(an == -90) fprintf(ouf, "dr0,-1;\n");
  471.         fprintf(ouf,"pu%.5f,%.5f;lb%s;pu;\n", t.x, t.y, lab);
  472.         if(an != 0) fprintf(ouf,"dr;\n");
  473.     }
  474.     if(scr)
  475.     {   t = coords(&t);
  476.         outtextxy((int) t.x,(int) t.y,lab);
  477.     }
  478.     t.x += strlen(lab) * xz; t.y += yz;
  479.     t = rotr(&t); minmax(&t,&xywin);
  480. }
  481.  
  482. void curon(struct point  *p, int siz)
  483. {   float    cl;
  484.     struct point    t, u;
  485.  
  486.     u = rotr(p); minmax(&u,&xywin);
  487.     if(scr)
  488.     {   u = coords(&u);
  489.         moveto((int) u.x,(int) u.y + siz);
  490.         lineto((int) u.x,(int) u.y - siz);
  491.         moveto((int) u.x - 2 * siz,(int) u.y);
  492.         lineto((int) u.x + 2 * siz,(int) u.y);
  493.         moveto((int) u.x,(int) u.y);
  494.     }
  495.     else
  496.     {   cl = (yxvf - ynvf) * (float) siz / 200.;
  497.         eline(p); t = u;
  498.         t.y = u.y + cl; sline(&t); t.y = u.y - cl; eline(&t);
  499.         t.y = u.y;
  500.         t.x = u.x - cl; sline(&t); t.x = u.x + cl; eline(&t);
  501.         sline(&u);
  502.     }
  503. }
  504.  
  505. void curof(struct point  *p, int siz)
  506. {   struct point  t;
  507.  
  508.     t = rotr(p);
  509.     if(scr)
  510.     {   t = coords(&t); setcolor(0);
  511.         moveto((int) t.x,(int) t.y + siz);
  512.         lineto((int) t.x,(int) t.y - siz);
  513.         moveto((int) t.x - 2 * siz,(int) t.y);
  514.         lineto((int) t.x + 2 * siz,(int) t.y);
  515.         moveto((int) t.x,(int) t.y); setcolor(1);
  516.     }
  517. }
  518.  
  519. struct rect ptr(struct polar  *rth)
  520. {    struct rect xy;
  521.  
  522.     xy.dx = rth->r * cos(rth->th);
  523.     xy.dy = rth->r * sin(rth->th);
  524.     return xy;
  525. }
  526.  
  527. struct polar rtp(struct rect  *xy)
  528. {    struct polar    rth;
  529.  
  530.     rth.r = hypot(xy->dx,xy->dy);
  531.     rth.th = atanc(xy->dy,xy->dx);
  532.     return rth;
  533. }
  534.  
  535. float redangle(float th)
  536. {    if(th >  M_PI) th -= 2 * M_PI;
  537.     if(th < -M_PI) th += 2 * M_PI;
  538.     if(th >= -M_PI && th <= M_PI) return th;
  539.     return redangle(th);
  540. }
  541.  
  542. void ptro(float th, float r)
  543. {    xpr = r * cos(th);
  544.     ypr = r * sin(th);
  545. }
  546.  
  547. void rtpo(float x, float y)
  548. {    rpr = hypot(x,y);
  549.     thpr = atanc(y,x);
  550. }
  551.  
  552. float atanc(float y, float x)
  553. {    if(x != 0.) return atan2(y,x);
  554.     if(y >= 0) return M_PI_2;
  555.     else return -M_PI_2;
  556. }
  557.  
  558. void wind_setup(void)
  559. {   pclrattr(REVHELP);
  560.     PRM_NRM0 = REVHELP; PRM_SEL0 = REVEMPHNORML;
  561.     FLD_NRM0 = REVHELP; FLD_SEL0 = HELP;
  562. }
  563.  
  564. HWND wigen(int rp, int cp, int rs, int cs, char frame[7], char title[80])
  565. {   HWND whtmp;
  566.     whtmp = vcreat(rs,cs,REVHELP,NO);
  567.     vwind(whtmp,rs,cs,0,0); /* write with vatputs(whtmp,x,y,"string") */
  568.     vlocate(whtmp,rp,cp);
  569.     vframe(whtmp,REVEMPHNORML,frame);
  570.     visible(whtmp,YES,NO);
  571.     vtitle(whtmp,REVEMPHNORML,title);
  572.     return whtmp;
  573. }
  574.  
  575. HWND wigenlp(int  row_pos, int  col_pos, int  row_siz_log, int  col_siz_log,
  576.      int  row_siz_phy, int  col_siz_phy, char  frame[7], char  title[80])
  577. {   HWND whtmp;
  578.     whtmp = vcreat(row_siz_log, col_siz_log, REVHELP, NO);
  579.     vwind(whtmp, row_siz_phy, col_siz_phy, 0, 0);
  580.     vlocate(whtmp, row_pos, col_pos);
  581.     vframe(whtmp, REVEMPHNORML, frame);
  582.     visible(whtmp, YES, NO);
  583.     vtitle(whtmp, REVEMPHNORML, title);
  584.     return whtmp;
  585. }       /* write with vatputs(whtmp,x,y,"string") */
  586.  
  587. void wipak(int rp, int cp)
  588. {   whpak = vcreat(1,15,REVNORML,NO);
  589.     vwind(whpak,1,15,0,0);
  590.     vlocate(whpak,rp,cp);
  591.     vframe(whpak,REVNORML,FRSINGLE);
  592.     visible(whpak,YES,NO);
  593.     vratputs(whpak,0,1,REVHELP,"press any key");
  594.     getkey(); vdelete(whpak,NONE);
  595. }
  596.  
  597. void wiin(int x, int y)
  598. {   whinst = vcreat(1,42,REVNORML,NO);
  599.     vwind(whinst,1,42,0,0);
  600.     vlocate(whinst,x,y);
  601.     vframe(whinst,REVNORML,FRSINGLE);
  602.     vtitle(whinst,REVNORML,"instructions");
  603.     visible(whinst,YES,NO);
  604.     vratputs(whinst,0,1,REVHELP,
  605.         "\x1e\x1f, or ENTER; Ctrl ENTER to leave window");
  606. }
  607.  
  608. HWND wiinv(int x, int y, char  mes[80])
  609. {   HWND whinst;
  610.     int  meslen = strlen(mes) + 2;
  611.  
  612.     whinst = vcreat(1,meslen,REVNORML,NO);
  613.     vwind(whinst,1,meslen,0,0);
  614.     vlocate(whinst,x,y);
  615.     vframe(whinst,REVNORML,FRSINGLE);
  616.     vtitle(whinst,REVNORML,"instructions");
  617.     visible(whinst,YES,NO);
  618.     vratputf(whinst,0,1,REVHELP,"%s", mes);
  619.     return whinst;
  620. }
  621.  
  622. HWND wint(int x, int y, char  mes[80])
  623. {   HWND whinst;
  624.     int  meslen = strlen(mes) + 2;
  625.  
  626.     whinst = vcreat(1,meslen,REVNORML,NO);
  627.     vwind(whinst,1,meslen,0,0);
  628.     vlocate(whinst,x,y);
  629.     visible(whinst,YES,NO);
  630.     vratputf(whinst,0,1,REVHELP,"%s", mes);
  631.     return whinst;
  632. }
  633.  
  634. void wipw(int x, int y)
  635. {   whpw = vcreat(1,13,REVNORML,NO);
  636.     vwind(whpw,1,13,0,0);
  637.     vlocate(whpw,x,y);
  638.     vframe(whpw,REVNORML,FRSINGLE);
  639.     visible(whpw,YES,NO);
  640.     vratputs(whpw,0,1,REVHELP,"please wait");
  641. }
  642.  
  643. void wiwait(int rp, int cp)
  644. {   whwait = vcreat(1,13,REVNORML,NO);
  645.     vwind(whwait,1,13,0,0);
  646.     vlocate(whwait,rp,cp);
  647.     vframe(whwait,REVNORML,FRSINGLE);
  648.     visible(whwait,YES,NO);
  649.     vratputs(whwait,0,1,REVHELP,"please wait");
  650. }
  651.  
  652. void wiwaitm(int rp, int cp, char  mes[80])
  653. {   int    siz = 11;
  654.     if(strlen(mes)+2 > siz) siz = strlen(mes)+2;
  655.     whwaitm = vcreat(1,siz,REVNORML,NO);
  656.     vwind(whwaitm,1,siz,0,0);
  657.     vlocate(whwaitm,rp,cp);
  658.     vframe(whwaitm,REVNORML,FRSINGLE);
  659.     visible(whwaitm,YES,NO);
  660.     vtitle(whwaitm,REVNORML,"please wait");
  661.     vratputf(whwaitm,0,1,REVNORML,"%s", mes);
  662. }
  663.  
  664. void witest(int rp, int cp, int rs, int cs)
  665. {   whtest = vcreat(rs,cs,REVNORML,NO);
  666.     vwind(whtest,rs,cs,0,0); /* write with vatputs(whtest,x,y,"string") */
  667.     vlocate(whtest,rp,cp);
  668.     vframe(whtest,REVNORML,FRSINGLE);
  669.     visible(whtest,YES,NO);
  670.     vtitle(whtest,REVNORML,"test");
  671. }
  672.  
  673. void wierror(int rp, int cp, char  mes[80])
  674. {   int    siz = 7;
  675.     if(strlen(mes) + 2 > siz) siz = strlen(mes) + 2;
  676.     wherror = vcreat(1,siz,REVNORML,NO);
  677.     vwind(wherror,1,siz,0,0);
  678.     vlocate(wherror,rp,cp);
  679.     vframe(wherror,REVNORML,FRSINGLE);
  680.     visible(wherror,YES,YES);
  681.     vtitle(wherror,REVNORML,"error");
  682.     vratputf(wherror,0,1,REVNORML,"%s", mes);
  683.     wipak(rp + 3, cp);
  684.     vdelete(wherror,NONE);
  685. }
  686.  
  687. void nrerror(char  error_text[80])
  688. {   int    p, l;
  689.     HWND    wher;
  690.     void exit();
  691.  
  692.     l = strlen(error_text);
  693.     if(l < 27) l = 27; l += 2; p = (int) (80 - l) / 2.;
  694.     wher = wigen(9,p,3,l,FRDOUBLE,"fatal error");
  695.     vatputs(wher,0,1,"Run-time error...");
  696.     vatputf(wher,1,1,"%s",error_text);
  697.     vatputs(wher,2,1,"...now exiting to system...");
  698.     wipak(14,31);
  699.     vexit(1);
  700. }
  701.  
  702. void scroll(int  page, HWND  wi)
  703. {   unsigned  key = 0;
  704.  
  705.     while(key != ESC)
  706.     {   switch (key = getkey())
  707.         {   case CURUP: vmovedn(wi,1); break;
  708.             case CURDN: vmoveup(wi,1); break;
  709.             case CURLF: vmovelf(wi,1); break;
  710.             case CURRT: vmovert(wi,1); break;
  711.             case PGUP: vmovedn(wi,page); break;
  712.             case PGDN: vmoveup(wi,page); break;
  713.             default: break;
  714.         }
  715.     }
  716. }
  717.