home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / PCLO3.0R.DMS / in.adf / PlotSource / holecount.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-07-23  |  5.8 KB  |  182 lines

  1. /*
  2.  *
  3.  * hcount.c -- source for example layer postprocessor for PCLO
  4.  * Copyright (c) 1986 - SoftCircuits, Inc. - ALL RIGHTS RESERVED
  5.  *
  6.  */
  7.  
  8. /*
  9.  * Assembly language calls:
  10.  *     vcheck(layer);              determine extent of structures
  11.  *     encode(rdmuse,layer);       de-encrypt layer info
  12.  */
  13.  
  14. /* The following are the definitions for the data found in a board cell */
  15.  
  16. #define C_BLANK 0    /* empty cell */
  17. #define C_FAT   1    /* solidly filled cell*/
  18. #define C_TEBW  2    /* cell with 2 diagonal traces, top east, bottom west */
  19. #define C_TWBE  3    /* cell with 2 diagonal traces, top west, bottom east */
  20. #define C_VERT  4    /* vertical trace */
  21. #define C_HORZ  5    /* horizontal trace */
  22. #define C_NW    6    /* NorthWest diagonal trace */
  23. #define C_SE    7    /* SouthEast diagonal trace */
  24. #define C_SW    8    /* SouthWest diagonal trace */
  25. #define C_NE    9    /* NorthEast diagonal trace */
  26. #define C_TOPT  10   /* horizontal trace with connection to the top */
  27. #define C_BOTT  11   /* horizontal trace with connection to the bottom */
  28. #define C_LEFTT 12   /* vertical trace with connection to the left */
  29. #define C_RITET 13   /* vertical trace with connection to the right */
  30. #define C_FULL  14   /* connections everywhere; like a plus sign */
  31.  
  32. /* All of the following codes are "cylinders", they exist on all layers */
  33.  
  34. #define C_PAD   15   /* standard pad; used for ic pins, etc */
  35. #define C_VIA   16   /* feedthrough pad; used for circuit connections only */
  36. #define C_EDGE  17   /* shearline indicator; used to indicate edge of bd */
  37. #define C_DRILL 18   /* drill hole marker; used for tooling mounting holes */
  38. #define C_ONE   19   /* pin one pad; used to indicate orientation of items */
  39.  
  40. #include "exec/types.h"
  41. #include "exec/nodes.h"
  42. #include "exec/lists.h"
  43. #include "exec/ports.h"
  44. #include "exec/libraries.h"
  45. #include "exec/devices.h"
  46. #include "exec/io.h"
  47. #include "devices/serial.h"
  48. #include "lattice/stdio.h"
  49. #include "workbench/startup.h"
  50.  
  51. UBYTE tname[80];  /* temp area to hold full path/filename */
  52. UBYTE fname[80];  /* filename to process */
  53. UBYTE path[80];   /* path that BoardLib directory resides under */
  54. UBYTE *layer;     /* pointer to area where board data is kept */
  55. int rdmuse;       /* file encryptor key storage */
  56. float CostPerHole;/* used for input from user */
  57. extern struct WBStartup *WBenchMsg; /* place for WorkBench to pass us info */
  58.  
  59.  
  60. main(argc,argv)
  61.    int argc;
  62.    unsigned char *argv[];
  63. {
  64.    int x,y,cell,hcount,hotload;
  65.    struct WBArg *arg;
  66.       hcount=0;            /* no holes found yet */
  67.       hotload=0;           /* assume not parameterized on startup */
  68.       strcpy(&path[0],""); /* assume not a Wb startup, no path needed */
  69.       if (argc == 0)       /* workbench load */
  70.          {
  71.             if(WBenchMsg->sm_NumArgs == 2)
  72.                {
  73.                   arg = WBenchMsg->sm_ArgList;
  74.                   ++arg;
  75.                   strcpy(&fname[0],arg->wa_Name);
  76.                   strcpy(&path[0],":");
  77.                   hotload = 1;
  78.                }
  79.          }
  80.       else /* cli load */
  81.         {
  82.            if (argc == 2) /* there was an argument */
  83.                {
  84.                   strcpy(&fname[0],argv[1]);
  85.                   hotload = 1;
  86.                }
  87.          }
  88.       if (hotload == 0)
  89.          {
  90.             printf("Enter the name of the board to be checked: ");
  91.             scanf("%s",&fname[0]);
  92.          }
  93.       printf("Enter the cost per hole for this estimate: ");
  94.       scanf("%f",&CostPerHole);
  95.       if ((layer=(UBYTE*)calloc(65536,1))==NULL) /* get memory for layer */
  96.          {
  97.             printf("layer memory allocation failed -- Not Enough Memory");
  98.             jexit(20);
  99.          }
  100.       if (loadbd() != 1) jexit(20); /* load board specified in "fname" */
  101.       printf("counting holes;\n");
  102.       for (x=0; x<256; x++)
  103.          {
  104.             for (y=0; y<256; y++)
  105.                {
  106.                   cell=readbd(x,y);
  107.                   if (cell > C_FULL) /* Want: C_DRILL, C_PAD, C_VIA, C_ONE */
  108.                      {
  109.                         if (cell != C_EDGE)
  110.                            {
  111.                               hcount++;
  112.                            }
  113.                      }
  114.                }
  115.          }
  116.       printf("\nThe board %s contains %d holes\n",&fname[0],hcount);
  117.       printf("estimated prototype cost is $%1.2f\n",hcount*CostPerHole);
  118.       jexit(0);
  119.    }
  120.  
  121. jexit(parm)
  122.    int parm;
  123.    {
  124.    int i;
  125.       for (i=0; i<500000; i++);
  126.       exit(parm);
  127.    }
  128.  
  129. /*
  130.  * read a cell from the board:
  131. */
  132. readbd(xpos,ypos)
  133.    int xpos,ypos;
  134.    {
  135.    int data;
  136.       data=(int)layer[xpos+(ypos*256)];
  137.       return(data);
  138.    }
  139.  
  140. /*
  141.  * board load: 
  142.  */
  143. loadbd()
  144.    {
  145.    FILE *fp;
  146.  
  147.       strcpy(&tname[0],&path[0]);    /* setup base path for BoardLib */
  148.       strcat(&tname[0],"BoardLib/"); /* setup Directory for layer */
  149.       strcat(&tname[0],&fname[0]);   /* prefix full path to filename */
  150.       strcat(&tname[0],".layer1");   /* add extension to filename */
  151.  
  152.       if (fp = fopen(&tname[0],"r")) /* try and open layer1 file */
  153.          {
  154.             printf("Please wait -- loading '%s'\n",&tname[0]);
  155.                {
  156.                   if (fread(&rdmuse,4,1,fp) != 1)   /* get file encryptor */
  157.                      {
  158.                         printf("file error - entire file not loaded\n");
  159.                         return(0);
  160.                      }
  161.                   if (fread(layer,65536,1,fp) != 1)
  162.                      {
  163.                         printf("file error - entire file not loaded\n");
  164.                         return(0);
  165.                      }
  166.                   else
  167.                      {
  168.                         printf("file '%s' loaded successfully\n",&tname[0]);
  169.                      }
  170.                }
  171.             fclose(fp);
  172.             printf("stand by - normalizing record\n");
  173.             encode(rdmuse,layer);
  174.             return(1);
  175.          }
  176.       else
  177.          {
  178.             printf("'%s' file not found\n",&tname[0]);
  179.             return(0);
  180.          }
  181.    }
  182.