home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 13 / 13.iso / p / p078 / 3.img / NETFORMS.PLB / SPICE.CH < prev    next >
Encoding:
Text File  |  1991-10-14  |  14.1 KB  |  608 lines

  1. /*
  2.     /2
  3.     /L Do not append sheet number to labels
  4.     /N Use node names
  5.     /I Include unconnected pins
  6.  */
  7.  
  8. /*  VERSION="1.10   14-OCT-91"
  9.  *      - Changed unconnected pins from net "0" to " "
  10.  *      - Added /I switch to allow unconnected pins to be given a net
  11.  *      - Changed so that the GND net is always "0", even with /N set
  12.  *      - Altered PostFile to handle sheets with zero parts
  13.  *      - Corrected format of subcircuit calls
  14.  *      - Added warnings for names with illegal characters
  15.  *      - Added code to strip path information from sheet filenames
  16.  *      - Made '$' a legal character (needed for digital simulation)
  17.  *      - Removed unneeded call to MakeInstanceFile()
  18.  *      - Added Version message
  19.  *      - Corrected int to unsigned comparison
  20.  *
  21.  *  Capacities:
  22.  *      - Part Names are not checked for length
  23.  *      - Module Names are not checked for length
  24.  *      - Reference Strings are not checked for length
  25.  *      - Node Names are not checked for length
  26.  *      - Node Numbers are limited to 5 digits
  27.  *      - Pin Numbers are not checked for length
  28.  *
  29.  *  Characters:
  30.  *      - Node names are limited to { '_', '$', '0-9' , 'a-z', 'A-Z' } if /N is present
  31.  *
  32.  *      Even if your version of SPICE does not allow alphabetic node names,
  33.  *      you can still give nodes names if they represent numerical
  34.  *      values (such as '14').  These node 'numbers' will not
  35.  *      overlap with the system defined ones since system node numbers
  36.  *      begin at 10000 (except GND, which is always 0).
  37.  *
  38.  *      Unconnected pins will generate a warning and a space, " ", will
  39.  *      be output instead of a number.  If /I is present, then unconnected
  40.  *      pins will not generate a warning and will be given a net number
  41.  *      starting at 32767 and decreasing with each additional unconnected pin.
  42.  *
  43.  *      The .MAP file that is generated is only valid if the /N switch is
  44.  *      not used (since labels will be output to the netlist instead of
  45.  *      system created net numbers if /N is present).
  46.  */
  47.  
  48. int sw_L;
  49. int sw_N;
  50. int sw_I;
  51.  
  52. int type;
  53. int new_type;
  54. int first;
  55. int ok;
  56. int legal;
  57. int len;
  58. int net;
  59. int unet;
  60. int pos;
  61. int ch;
  62. int num;
  63.  
  64. /*-----------------------*/
  65.  
  66. Initialize()
  67. {
  68.     WriteString(0, "Creating Netlist...");
  69.     WriteCrLf(0);
  70.  
  71.     SetTraversal("ROOT");
  72.  
  73.     AddSymbol("SignalNameStr");
  74.     AddSymbol("TempStr");
  75.     AddSymbol("Str");
  76.  
  77.     AddSymbol("GND");
  78.     SetSymbol(GND, "GND");
  79.  
  80.     unet = 32767;
  81.  
  82.     sw_L = SwitchIsSet("L");
  83.     sw_N = SwitchIsSet("N");
  84.     sw_I = SwitchIsSet("I");
  85.  
  86.     SetCharSet("_$0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
  87.     SetNumberWidth(1);
  88.     first = 1;
  89.     net = 0;
  90. }
  91.  
  92. /*-----------------------*/
  93.  
  94. PreFile()
  95. {
  96. }
  97.  
  98. /*-----------------------*/
  99.  
  100. PostFile()
  101. {
  102.     if (first == 1)
  103.     {
  104.         WriteString(1, "* ");
  105.         CopySymbol(TitleString, Str);
  106.         PadSpaces(Str, 46);
  107.         WriteSymbol(1, Str);
  108.         WriteString(1, "Revised: ");
  109.         WriteSymbol(1, DateString);
  110.         WriteCrLf(1);
  111.         WriteString(1, "* ");
  112.         CopySymbol(DocumentNumber, Str);
  113.         PadSpaces(Str, 46);
  114.         WriteSymbol(1, Str);
  115.         WriteString(1, "Revision: ");
  116.         WriteSymbol(1, Revision);
  117.         WriteCrLf(1);
  118.         WriteString(1, "* ");
  119.         WriteSymbol(1, Organization);
  120.         WriteCrLf(1);
  121.         WriteString(1, "* ");
  122.         WriteSymbol(1, AddressLine1);
  123.         WriteCrLf(1);
  124.         WriteString(1, "* ");
  125.         WriteSymbol(1, AddressLine2);
  126.         WriteCrLf(1);
  127.         WriteString(1, "* ");
  128.         WriteSymbol(1, AddressLine3);
  129.         WriteCrLf(1);
  130.         WriteString(1, "* ");
  131.         WriteSymbol(1, AddressLine4);
  132.         WriteCrLf(1);
  133.     }
  134.     else
  135.     {
  136.         WriteParms();
  137.     }
  138.  
  139.     /* output the power sources and .MAP file */
  140.     ok = FirstNet();
  141.     if (ok == 1) {
  142.         do {
  143.             WritePower();
  144.             WriteMAPFile();
  145.         } while (NextNet());
  146.     }
  147.  
  148.     /* write out the parts */
  149.     ok = FirstPart();
  150.     if (ok == 1) {
  151.         do {
  152.             WriteSymbol(3, ReferenceString);
  153.  
  154.             FirstPin();    
  155.             do {
  156.                 SetSignal();
  157.  
  158.                 WriteString(3, " ");
  159.                 WriteNodeInfo();
  160.             } while (NextPin());
  161.  
  162.             WriteString(3, " ");
  163.             WriteSymbol(3, PartName);
  164.             WriteCrLf(3);
  165.         } while (NextPart());
  166.     }
  167.  
  168.     /* write out the subcircuit calls */
  169.     ok = FirstChild();
  170.     if (ok == 1)
  171.     {
  172.         CopySymbol(FileName, Str);
  173.         StripExt();
  174.         CopySymbol(Str, TempStr);
  175.         
  176.         CopySymbol(PartName, Str);
  177.         StripExt();
  178.  
  179.         /* skip if this is the module ports for the current sheet */
  180.         ok = CompareSymbol(Str, TempStr);
  181.         if (ok == 0)
  182.             { ok = NextChild(); }
  183.         else
  184.             { ok = 1; }
  185.  
  186.         while (ok == 1)
  187.         {
  188.             WriteString(3, "X");
  189.  
  190.             CopySymbol(ReferenceString, Str);
  191.             ToUpper(Str);
  192.             StripExt();
  193.             WriteSymbol(3, Str);
  194.  
  195.             FirstChildPin();
  196.             do {
  197.                 SetSignal();
  198.  
  199.                 WriteString(3, " ");
  200.                 WriteNodeInfo();
  201.             } while (NextChildPin());
  202.  
  203.             WriteString(3, " ");
  204.             CopySymbol(PartName, Str);
  205.             ToUpper(Str);
  206.             StripPath(Str);
  207.             StripExt();
  208.             WriteSymbol(3, Str);
  209.  
  210.             WriteCrLf(3);
  211.             ok = NextChild();
  212.         }
  213.     }
  214.  
  215.     if (first != 1)
  216.     {
  217.         WriteString(3, ".ENDS");
  218.         WriteCrLf(3);
  219.     }
  220.     first = 0;
  221. }
  222.  
  223. /*-----------------------*/
  224.  
  225. WriteParms()
  226. {
  227.     int i;
  228.  
  229.     ok = FirstChild();
  230.     if (ok == 0) { return; }
  231.  
  232.     WriteString(3, ".SUBCKT ");
  233.     CopySymbol(FileName, Str);
  234.     ToUpper(Str);
  235.     StripPath(Str);
  236.     StripExt();
  237.     WriteSymbol(3, Str);
  238.  
  239.     FirstChildPin();
  240.     do {
  241.         WriteString(3, " ");
  242.  
  243.         CopySymbol(PinNameString, Str);
  244.         legal = SymbolInCharSet(Str);
  245.  
  246.         if ((legal + sw_N) == 2)
  247.         {
  248.             WriteSymbol(3, PinNameString);
  249.         }
  250.         else
  251.         {
  252.             ok = FirstNet();
  253.             if (ok == 1) {
  254.                 do {
  255.                     type = GetStandardSymbol(NetCode);
  256.                     if (type == 'P')
  257.                     {
  258.                         ok = CompareSymbol(SignalNameString, Str);
  259.                         if (ok == 0) { WriteSysNet(); }
  260.                     }
  261.                 } while (NextNet());
  262.             }
  263.         }
  264.     } while (NextChildPin());
  265.     WriteCrLf(3);
  266. }
  267.  
  268. /*-----------------------*/
  269.  
  270. PostProcess()
  271. {
  272.     FirstPipe();
  273.     ok = AccessKeyWord("SPICE");
  274.     while (ok == 1) {
  275.         PipeSPICE();
  276.         ok = AccessKeyWord("SPICE");
  277.     }
  278.  
  279.     WriteString(3, ".END");
  280.     WriteCrLf(3);
  281.  
  282.     ConcatFile(1, 3);
  283.  
  284.     WriteString(0, "Done");
  285.     WriteCrLf(0);
  286. }
  287.  
  288. /*-----------------------*/
  289.  
  290. StripExt()
  291. {
  292.     ch = 46;
  293.     pos = FindSymbolChar(ch, Str);
  294.     if (pos != -1) { ch = 0; PutSymbolChar(pos, ch, Str); }
  295. }
  296.  
  297. /*-----------------------*/
  298.  
  299. PipeSPICE()
  300. {
  301.     ok = NextPipe();
  302.     if (ok == 1)
  303.     {
  304.         ok = IsKeyWord();
  305.         ok = 1 - ok;
  306.     }
  307.  
  308.     while (ok == 1)
  309.     {
  310.         WriteSymbol(1, PipeLine);
  311.         WriteCrLf(1);
  312.  
  313.         ok = NextPipe();
  314.         if (ok == 1)
  315.         {
  316.             ok = IsKeyWord();
  317.             ok = 1 - ok;
  318.         }
  319.     }
  320. }
  321.  
  322. /*-----------------------*/
  323.  
  324. WriteMAPFile()
  325. {
  326.     type = GetStandardSymbol(NetCode);
  327.     if (type == 'L')
  328.     {
  329.         num = GetStandardSymbol(NetNumber);
  330.         num = num + 10000;
  331.         WriteInteger(2, num);
  332.  
  333.         WriteString(2, " ");
  334.         if (sw_N == 0)
  335.         {
  336.             WriteSymbol(2, SignalNameString);
  337.         }
  338.         else
  339.         {
  340.             if (sw_L == 0)
  341.             {
  342.                 MakeLocalSignal("_");
  343.                 WriteSymbol(2, LocalSignal);
  344.             }
  345.             else
  346.             {
  347.                 WriteSymbol(2, SignalNameString);
  348.             }
  349.         }
  350.         WriteString(2, " (sheet ");
  351.         CopySymbol(FileName, Str);
  352.         ToUpper(Str);
  353.         StripExt();
  354.         WriteSymbol(2, Str);
  355.         WriteString(2, ")");
  356.         WriteCrLf(2);
  357.     }
  358.  
  359.     if (type == 'P')
  360.     {
  361.         num = GetStandardSymbol(NetNumber);
  362.         num = num + 10000;
  363.         WriteInteger(2, num);
  364.  
  365.         WriteString(2, " ");
  366.         WriteSymbol(2, SignalNameString);
  367.         WriteString(2, " (sheet ");
  368.         CopySymbol(FileName, Str);
  369.         StripExt();
  370.         WriteSymbol(2, Str);
  371.         WriteString(2, ")");
  372.         WriteCrLf(2);
  373.     }
  374.  
  375.     if (type == 'S')
  376.     {
  377.         ok = CompareSymbol(GND, SignalNameString);
  378.         if (ok == 0)
  379.             { WriteString(2, "    0 "); }
  380.         else
  381.         {
  382.             num = GetStandardSymbol(NetNumber);
  383.             num = num + 10000;
  384.             WriteInteger(2, num);
  385.             WriteString(2, " ");
  386.         }
  387.  
  388.         WriteSymbol(2, SignalNameString);
  389.         WriteString(2, " (sheet ");
  390.         CopySymbol(FileName, Str);
  391.         StripExt();
  392.         WriteSymbol(2, Str);
  393.         WriteString(2, ")");
  394.         WriteCrLf(2);
  395.     }
  396. }
  397.  
  398. /*-----------------------*/
  399.  
  400. WritePower()
  401. {
  402.     int ch;
  403.     int pos;
  404.  
  405.     type = GetStandardSymbol(NetCode);
  406.     if (type == 'S')
  407.     {
  408.         ok = CompareSymbol(GND, SignalNameString);
  409.         if (ok != 0)
  410.         {
  411.             /* separate the name from trailing characters */
  412.             CopySymbol(SignalNameString, SignalNameStr);
  413.  
  414.             ch = ' ';
  415.             pos = FindSymbolChar(ch, SignalNameStr);
  416.             if (pos != -1)
  417.             {
  418.                 len = SymbolLength(SignalNameStr);
  419.                 len = len - 1;
  420.                 pos = pos + 1;
  421.                 PackString(pos, len, SignalNameStr, Str);
  422.  
  423.                 pos = pos - 1;
  424.                 ch = 0;
  425.                 /* kill the trailing space */
  426.                 PutSymbolChar(pos, ch, SignalNameStr);
  427.             }
  428.             else
  429.             {
  430.                 SetSymbol(Str, "");
  431.             }
  432.  
  433.             ValidateNetInfo();
  434.             if (legal != 1)
  435.             {
  436.                 net = GetStandardSymbol(NetNumber);
  437.                 net = net + 10000;
  438.  
  439.                 /* illegal character in the node name */
  440.                 WriteString(0, "WARNING: Name contains illegal characters '");
  441.                 WriteSymbol(0, SignalNameStr);
  442.                 WriteString(0, "', changed to ");
  443.                 WriteInteger(0, net);
  444.                 WriteCrLf(0);
  445.  
  446.                 SetSymbol(ExitType, "W");
  447.             }
  448.  
  449.             WriteSymbol(3, SignalNameStr);
  450.  
  451.             WriteString(3, " ");
  452.             if (new_type == 'S')
  453.                 { WriteSymbol(3, SignalNameStr); }
  454.             else
  455.                 { WriteSysNet(); }
  456.  
  457.             WriteString(3, " 0");
  458.  
  459.             len = SymbolLength(Str);
  460.             if (len > 0)
  461.             {
  462.                 WriteString(3, " ");
  463.                 WriteSymbol(3, Str);
  464.             }
  465.             WriteCrLf(3);
  466.         }
  467.     }
  468. }
  469.  
  470. /*-----------------------*/
  471.  
  472. WriteSysNet()
  473. {
  474.     net = GetStandardSymbol(NetNumber);
  475.     net = net + 10000;
  476.     WriteInteger(3, net);
  477. }
  478.  
  479. /*-----------------------*/
  480.  
  481. ValidateNetInfo()
  482. {
  483.     legal = 1;
  484.  
  485.     type = GetStandardSymbol(NetCode);
  486.     new_type = type;
  487.     if (sw_N == 1)
  488.     {
  489.         legal = SymbolInCharSet(SignalNameStr);
  490.  
  491.         if (legal != 1) { new_type = 'N'; }
  492.     }
  493.     else
  494.     {
  495.         if (type != 'U') { new_type = 'N'; }
  496.     }
  497. }
  498.  
  499. /*-----------------------*/
  500.  
  501. ValidateNodeInfo()
  502. {
  503.     legal = 1;
  504.  
  505.     type = GetStandardSymbol(TypeCode);
  506.     new_type = type;
  507.     if (sw_N == 1)
  508.     {
  509.         legal = SymbolInCharSet(SignalNameStr);
  510.  
  511.         if (legal != 1) { new_type = 'N'; }
  512.     }
  513.     else
  514.     {
  515.         if (type != 'U') { new_type = 'N'; }
  516.     }
  517. }
  518.  
  519. /*-----------------------*/
  520.  
  521. WriteNodeInfo()
  522. {
  523.     CopySymbol(SignalNameString, SignalNameStr);
  524.     ValidateNodeInfo();
  525.  
  526.     /* this one is special since GND is always 0 */
  527.     if (type == 'S')
  528.     {
  529.         ok = CompareSymbol(GND, SignalNameString);
  530.         if (ok == 0)
  531.             { WriteString(3, "0"); }
  532.         else
  533.         {
  534.             if (sw_N == 0)
  535.             {
  536.                 WriteSysNet();
  537.             }
  538.             else
  539.             {
  540.                 ch = ' ';
  541.                 pos = FindSymbolChar(ch, SignalNameStr);
  542.                 if (pos != -1)
  543.                 {
  544.                     ch = 0;
  545.                     /* kill the trailing space */
  546.                     PutSymbolChar(pos, ch, SignalNameStr);
  547.                 }
  548.                 WriteSymbol(3, SignalNameStr);
  549.             }
  550.         }
  551.     }
  552.     if (new_type == 'L')
  553.     {
  554.         if (sw_L == 0)
  555.         {
  556.             MakeLocalSignal("_");
  557.             WriteSymbol(3, LocalSignal);
  558.         }
  559.         else
  560.         {
  561.             WriteSymbol(3, SignalNameStr);
  562.         }
  563.     }
  564.     if (new_type == 'P')
  565.     {
  566.         WriteSymbol(3, SignalNameStr);
  567.     }
  568.     if (new_type == 'N')
  569.     {
  570.         if (type != 'S')
  571.         {
  572.             WriteSysNet();
  573.  
  574.             if (legal != 1)
  575.             {
  576.                 /* illegal character in the node name */
  577.                 WriteString(0, "WARNING: Name contains illegal characters '");
  578.                 WriteSymbol(0, SignalNameStr);
  579.                 WriteString(0, "', changed to ");
  580.                 WriteInteger(0, net);
  581.                 WriteCrLf(0);
  582.             }
  583.         }
  584.     }
  585.     if (new_type == 'U')
  586.     {
  587.         if (sw_I == 1)
  588.         {
  589.             WriteInteger(1, unet);
  590.             unet = unet - 1;
  591.         }
  592.         else
  593.         {
  594.             WriteString(0, "WARNING: Pin '");
  595.             WriteSymbol(0, PinNameString);
  596.             WriteString(0, "' on Reference '");
  597.             WriteSymbol(0, ReferenceString);
  598.             WriteString(0, "' is unconnected");
  599.             WriteCrLf(0);
  600.  
  601.             SetSymbol(ExitType, "W");
  602.         
  603.             WriteString(1, " ");
  604.         }
  605.     }
  606. }
  607.  
  608.