home *** CD-ROM | disk | FTP | other *** search
/ Vectronix 2 / VECTRONIX2.iso / FILES_01 / LATTIC_3.LZH / EXAMPLES / ROCP.C < prev    next >
C/C++ Source or Header  |  1990-01-28  |  4KB  |  162 lines

  1. /*
  2.  * rocp - fully configure the machine after the style of the control panel
  3.  *
  4.  * Started 1/3/89 Alex G. Kiernan
  5.  *
  6.  * Compile using:
  7.  *
  8.  *    lc -v -w -csfm -O -Lavg rocp
  9.  *
  10.  * Copyright (c) 1990 HiSoft
  11.  */
  12.  
  13. #include <aes.h>
  14. #include <string.h>
  15. #include <stdlib.h>
  16. #include <stdio.h>
  17. #include <dos.h>
  18.  
  19. enum {EVD_GET,EVD_SET};
  20.  
  21. void rocp(const char *p)
  22. {
  23.     char *q;
  24.     
  25.     if (q=strstr(p,"#a"))            /* find start of rs232 info */
  26.     {
  27.         int flowctl, parity, bits;
  28.         char speed;
  29.         unsigned long rsstat;
  30.         union
  31.         {
  32.             struct
  33.             {
  34.                 unsigned u_d:1;
  35.                 unsigned u_l:2;
  36.                 unsigned u_as:2;
  37.                 unsigned u_pe:1;
  38.                 unsigned u_po:1;
  39.                 unsigned :1;
  40.             } b;
  41.             short w;
  42.         } ucr;
  43.         
  44.         /* We ignore the duplex and strip bits since these are the
  45.            preserve of the VT52 emulator */
  46.         sscanf(q,"#a%*1d%c%1d%1d%1d%*1d",
  47.             &speed,
  48.             &parity,
  49.             &bits,
  50.             &flowctl);
  51.         speed-='0';        /* adjust speed to give 0..15 */
  52.         rsstat=Rsconf(speed,flowctl,-1,-1,-1,-1);
  53.         ucr.w=(rsstat >> 24);    /* fetch ucr value */
  54.         ucr.b.u_l=bits;
  55.         if (parity)
  56.         {
  57.             ucr.b.u_po=parity-2;
  58.             ucr.b.u_pe=1;
  59.         }
  60.         else
  61.             ucr.b.u_pe=0;
  62.         Rsconf(-1,-1,ucr.w,-1,-1,-1);
  63.     }
  64.     if (q=strstr(p,"#b"))        /* find start of printer info */
  65.     {
  66.         int type, colour, density, quality, port, paper;
  67.  
  68.         sscanf(q,"#b%1d%1d%1d%1d%1d%1d",
  69.             &type,
  70.             &colour,
  71.             &density,
  72.             &quality,
  73.             &port,
  74.             &paper);
  75.         /* Expand the bits into the right place in the word */
  76.         Setprt((((((((((((paper)<<1)|
  77.                 port)<<1) |
  78.                 quality)<<1) |
  79.                 density)<<1) |
  80.                 colour)<<1) |
  81.                 type));
  82.     }
  83.     if (q=strstr(p,"#c"))        /* find start of workstation info */
  84.     {
  85.         int dblclick, click, bell, delay, speed;
  86.         short col[16];
  87.         unsigned char oldconterm;
  88.         volatile unsigned char *conterm=0x484;
  89.         void *save_ssp;
  90.  
  91.         /* col[] info is fetched in a funny order to allow for the
  92.            way the VDI maps logical to physical colours */
  93.         sscanf(q,"#c"
  94.             "%3hx%3hx%3hx%3hx%3hx%3hx%3hx%3hx%3hx%3hx%3hx%3hx%3hx%3hx%3hx%3hx"
  95.             "%1d%1d%1d%2d%2d",
  96.             &col[0],&col[15],&col[1],&col[2],
  97.             &col[4],&col[6],&col[3],&col[5],
  98.             &col[7],&col[8],&col[9],&col[10],
  99.             &col[12],&col[14],&col[11],&col[13],
  100.             &dblclick,
  101.             &click,
  102.             &bell,
  103.             &delay,
  104.             &speed);
  105.         switch (Getrez())    /* fudge for different resolutions */
  106.         {
  107.             case 1:            /* med res */
  108.                 col[3]=col[15];
  109.                 break;
  110.             case 2:            /* hi res */
  111.                 col[1]=col[15];
  112.                 break;
  113.         }
  114.         Setpallete(col);
  115.         Vsync();    /* ensure palette set before stack is reused */
  116.         Kbrate(delay,speed);
  117.         evnt_dclick(dblclick,EVD_SET);
  118.         save_ssp=Super(NULL);
  119.         oldconterm=(*conterm)&~0x05;
  120.         if (click)
  121.             oldconterm|=0x01;
  122.         if (bell)
  123.             oldconterm|=0x04;
  124.         *conterm=oldconterm;
  125.         Super(save_ssp);
  126.     }
  127. }
  128.  
  129. int main(void)
  130. {
  131.     char *p,*q;
  132.     int result=EXIT_FAILURE;
  133.     int size=256;
  134.     
  135.     if (appl_init()!=-1)
  136.     {
  137.         while (result!=EXIT_SUCCESS)
  138.         {
  139.             int cnt;
  140.         
  141.             if ((size<<=1)<0)                /* double memory allocation */
  142.                 break;                        /* shell info >32K */
  143.  
  144.             if (!(p=malloc(size)))            /* get some memory */
  145.                 break;                        /* failed so give up */
  146.  
  147.             shel_get(p,size);                /* fetch shell information */
  148.             for (q=p, cnt=size; cnt--; )    /* find terminator */
  149.                 if (*q++=='\x1a')            /* found the CTRL Z */
  150.                 {
  151.                     *--q='\0';                /* replace with a NUL */
  152.                     rocp(p);                /* setup desktop */
  153.                     result=EXIT_SUCCESS;
  154.                     break;
  155.                 }
  156.             free(p);                        /* release memory */
  157.         }
  158.         appl_exit();
  159.     }
  160.     return result;
  161. }
  162.