home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 1 / Meeting Pearls Vol 1 (1994).iso / installed_progs / hard / galer / source / src.lha / Source / GALer / GALasm.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-14  |  48.9 KB  |  2,221 lines

  1. /****************************************************************/
  2. /*                                */
  3. /* GALAsm.c - this file includes the GAL-Assembler        */
  4. /*                                */
  5. /*                                 */
  6. /****************************************************************/
  7.  
  8.  
  9.  
  10. #include <exec/types.h>
  11. #include <exec/memory.h>
  12. #include <intuition/intuition.h>
  13. #include <libraries/locale.h>
  14. #include <ctype.h>
  15. #include <stdio.h>
  16. #include <string.h>
  17.  
  18. #include <proto/locale.h>
  19. #include <proto/intuition.h>
  20. #include <proto/exec.h>
  21.  
  22. #include "GALer.h"
  23. #include "Localize.h"
  24.  
  25.  
  26.  
  27.  
  28.  
  29. #define    SUFFIX_NON        0    /* possible suffixes */
  30. #define SUFFIX_T        1
  31. #define SUFFIX_R        2
  32. #define SUFFIX_E        3
  33. #define SUFFIX_CLK        4
  34. #define SUFFIX_APRST        5
  35. #define SUFFIX_ARST        6
  36.  
  37. #define    DUMMY_OLMC11        24
  38. #define DUMMY_OLMC12        25
  39.  
  40.  
  41.  
  42.  
  43. extern    struct  AppString { LONG   as_ID;
  44.                  STRPTR as_Str;
  45.               };
  46.  
  47. extern    struct  AppString AppStrings[];
  48.  
  49.  
  50. extern    int    linenum, MaxFuseAdr, SigAdr, RowSize, GALType;
  51. extern    UBYTE    *actptr, *buffend;
  52. extern  char    path;
  53.  
  54.  
  55. extern    struct    JedecStruct    Jedec;
  56. extern    struct    Configuration    Config;
  57. extern    struct    Catalog        *catalog;
  58.  
  59. struct    Pin        actPin;
  60. struct    GAL_OLMC    OLMC[12];
  61.  
  62.  
  63.             /*Diese Arrays geben an, in welche Spalte der ent- */
  64.             /*sprechende Pin eingekoppelt (bzw. rückgekoppelt) */
  65.             /*wird. Für die invertierende Einkopplung ist 1 zu */
  66.             /*addieren, um die entsprechende Spalte zu erhalten*/
  67.             /* -1: keine Einkopplung auf Fuse-Matrix vorhanden */
  68.  
  69.             /* GAL16V8 */
  70. int    PinToFuse16Mode1[20]    = {  2,  0,  4,  8, 12, 16, 20, 24, 28, -1,
  71.                     30, 26, 22, 18, -1, -1, 14, 10,  6, -1 };
  72.  
  73. int    PinToFuse16Mode2[20]    = {  2,  0,  4,  8, 12, 16, 20, 24, 28, -1,
  74.                     30, -1, 26, 22, 18, 14, 10,  6, -1, -1 };
  75.  
  76. int    PinToFuse16Mode3[20]    = { -1,  0,  4,  8, 12, 16, 20, 24, 28, -1,
  77.                     -1, 30, 26, 22, 18, 14, 10,  6,  2, -1 };
  78.  
  79.             /* GAL20V8 */
  80. int    PinToFuse20Mode1[24]    = {  2, 0, 4, 8,12,16,20,24,28,32,36,-1,
  81.                     38,34,30,26,22,-1,-1,18,14,10, 6,-1 };
  82.  
  83. int    PinToFuse20Mode2[24]    = {  2, 0, 4, 8,12,16,20,24,28,32,36,-1,
  84.                     38,34,-1,30,26,22,18,14,10,-1, 6,-1 };
  85.  
  86. int    PinToFuse20Mode3[24]    = { -1, 0, 4, 8,12,16,20,24,28,32,36,-1,
  87.                     -1,38,34,30,26,22,18,14,10, 6, 2,-1 };
  88.  
  89.  
  90.             /* GAL22V10 */
  91. int    PinToFuse22V10[24]    = {  0, 4, 8,12,16,20,24,28,32,36,40,-1,
  92.                     42,38,34,30,26,22,18,14,10, 6, 2,-1 };
  93.  
  94.  
  95.             /* GAL20RA10 */
  96. int    PinToFuse20RA10[24]    = { -1, 0, 4, 8,12,16,20,24,28,32,36,-1,
  97.                     -1,38,34,30,26,22,18,14,10, 6, 2,-1 };
  98.  
  99.  
  100.  
  101.  
  102.             /* This arrays show which row is connected to */
  103.             /* which OLMC */
  104.             /*diese Arrays geben an, in welcher Zeile der*/
  105.             /*erste Eingang der OLMC-Zelle liegt*/
  106.  
  107. int    ToOLMC[8]      = { 56, 48, 40, 32, 24, 16, 8, 0 };
  108.  
  109. int    ToOLMC22V10[12]      = { 122, 111, 98, 83, 66, 49, 34, 21, 10, 1, 0, 131 };
  110.  
  111. int    ToOLMC20RA10[10]  = { 72, 64, 56, 48, 40, 32, 24, 16, 8, 0 };
  112.  
  113.  
  114.                     /* this array shows the size of the */
  115.                     /* 22V10-OLMCs ( AR and SP = 1 )    */
  116. int    OLMCSize22V10[12] = { 9, 11, 13, 15, 17, 17, 15, 13, 11, 9, 1, 1 };
  117.  
  118.         /* The last two entries of the 22V10 arrays are for the   */
  119.         /* AR and SP rows of the 22V10 GAL. This rows are not     */
  120.         /* connected to an OLMC. But to keep the assembler as     */
  121.         /* simple as possible, I introduced  two "OLMCs" for the  */
  122.         /* AR and SP. The assembler treads them like real OLMCs.  */
  123.         /* So don't become confused when OLMC number 11 and 12    */
  124.         /* are used as inputs, outputs, pins... by the assembler. */
  125.         /* These two OLMCs are just dummy-OLMCs.          */
  126.  
  127.  
  128. UBYTE    PinNames[24][10], PinNamesOpt[26][10];
  129. UBYTE    PinDecNeg[24];
  130. UBYTE    ModeErrorStr[] = "Mode  x:  Pin xx";
  131. UBYTE    *pinnames;
  132.  
  133.  
  134. LONG    fsize;
  135. UBYTE    *fbuff;
  136.  
  137. int    num_of_pins, num_of_col, modus, gal_type;
  138. int    asmreadyflag;
  139.  
  140.  
  141. /* AssembleInputFile:
  142.    assemble source file (boolean equations)
  143.  
  144.    Call:      AssembleInputFile(OpMode);    (OpMode = OperationMode)
  145.    Parameter: OpMode = ASSEMBLER : assemble source file and generate JEDEC
  146.                    structure
  147.              = OPTIMIZER : assemble source file up to the Boolean
  148.                    equations and return without generating
  149.                    the JEDEC structure
  150.                    Booleschen Gleichung und brich dann ab
  151.    Result:  0: o.k.  else: error or cancel
  152. */
  153. int AssembleInputFile(int OpMode)
  154. {
  155. UBYTE    chr;
  156. UBYTE    *bool_start, *oldptr;
  157. char    prevOp;
  158. char    suffix_strn[MAX_SUFFIX_SIZE];
  159. int    i, j, k, l, n, m;
  160. int    max_chr, pass, pin_num, bool_linenum;
  161. int    actOLMC, row_offset, newline, oldline;
  162. int    suffix, start_row, max_row, num_of_olmcs;
  163.  
  164.  
  165.   m = YES;
  166.  
  167.   if (OpMode == ASSEMBLER)
  168.     m = AsmRequester();
  169.  
  170.   if (m) {                    /* load source file */
  171.  
  172.     if (MyFileReq(AppStrings[MSG_LOAD_SOURCE].as_Str, ".pld", YES, LOAD)) {
  173.  
  174.       fsize = FileSize((UBYTE *)&path);
  175.  
  176.       switch (fsize) {
  177.     case -1L:
  178.       ErrorReq(1);
  179.       return(-1);
  180.       break;
  181.  
  182.     case -2L:
  183.       ErrorReq(2);
  184.       return(-2);
  185.       break;
  186.  
  187.     case 0L:
  188.       ErrorReq(4);
  189.       return(-4);
  190.       break;
  191.       }
  192.  
  193.  
  194.       if ((fbuff = (UBYTE *)AllocMem(fsize,MEMF_PUBLIC))) {
  195.  
  196.         if ((ReadFile((UBYTE *)&path, fsize, fbuff))) {
  197.  
  198.           PrintText(AppStrings[MSG_FILE_LOADED].as_Str, 1);
  199.  
  200.       actptr  = fbuff;
  201.       buffend = fbuff+fsize;
  202.       linenum = 1;
  203.  
  204.       for (n = 0; n < sizeof(Jedec); n++) {    /* init. JEDEC structure */
  205.         if (n < LOGIC22V10_SIZE)
  206.           Jedec.GALLogic[n] = 1;        /* set fuses */
  207.         else
  208.           Jedec.GALLogic[n] = 0;        /* clear ACW... */
  209.       }
  210.  
  211.  
  212.  
  213.       for (n = 0; n < 12; n++) {        /* clear OLMC structure */
  214.         OLMC[n].Active   = 0;
  215.         OLMC[n].PinType  = 0;
  216.         OLMC[n].TriCon   = 0;
  217.         OLMC[n].Clock    = 0;
  218.         OLMC[n].ARST     = 0;
  219.         OLMC[n].APRST    = 0;
  220.         OLMC[n].FeedBack = 0;
  221.       }
  222.  
  223.  
  224.                     /*** get type of GAL ***/
  225.  
  226.       if (!strncmp((char *)actptr, "GAL16V8", (size_t)7)) {
  227.         num_of_olmcs = 8;            /* number of OLMCs */
  228.  
  229.         num_of_pins  = 20;            /* number of pins */
  230.  
  231.         num_of_col   = MAX_FUSE_ADR16 + 1;    /* number of columns */
  232.  
  233.         gal_type     = GAL16V8;
  234.  
  235.         if ((*(actptr+7L) != ' ') && (*(actptr+7L) != 0x0A) && (*(actptr+7L) != 0x09)) {
  236.           AsmError(1, 0);
  237.           return(-1);
  238.         }
  239.        }
  240.       else
  241.         if (!strncmp((char *)actptr, "GAL20V8", (size_t)7)) {
  242.           num_of_olmcs = 8;                /* number of OLMCs */
  243.  
  244.           num_of_pins  = 24;            /* number of pins */
  245.  
  246.           num_of_col   = MAX_FUSE_ADR20 + 1;    /* number of columns */
  247.  
  248.           gal_type     = GAL20V8;
  249.  
  250.           if ((*(actptr+7L) != ' ') && (*(actptr+7L) != 0x0A) && (*(actptr+7L) != 0x09)) {
  251.             AsmError(1, 0);
  252.             return(-1);
  253.           }
  254.           }
  255.         else
  256.           if (!strncmp((char *)actptr, "GAL20RA10", (size_t)9)) {
  257.         num_of_olmcs = 10;            /* number of OLMCs */
  258.  
  259.           num_of_pins  = 24;            /* number of pins */
  260.  
  261.         num_of_col   = MAX_FUSE_ADR20RA10 + 1;    /* number of columns */
  262.  
  263.         gal_type     = GAL20RA10;
  264.  
  265.          if ((*(actptr+9L) != ' ') && (*(actptr+9L) != 0x0A) && (*(actptr+9L) != 0x09) ) {
  266.           AsmError(1, 0);
  267.           return(-1);
  268.             }
  269.             }
  270.           else
  271.             if (!strncmp((char *)actptr, "GAL22V10", (size_t)8)) {
  272.           num_of_olmcs = 10;            /* number of OLMCs */
  273.  
  274.             num_of_pins  = 24;            /* number of pins */
  275.  
  276.           num_of_col   = MAX_FUSE_ADR22V10 + 1;    /* number of columns */
  277.  
  278.           gal_type     = GAL22V10;
  279.  
  280.            if ((*(actptr+8L) != ' ') && (*(actptr+8L) != 0x0A) && (*(actptr+8L) != 0x09) ) {
  281.             AsmError(1, 0);
  282.             return(-1);
  283.               }
  284.               }
  285.         else {
  286.           AsmError(1, 0);
  287.           return(-1);
  288.             }
  289.  
  290.  
  291.                 /*** get the leading 8 bytes of the second ***/
  292.                 /*** line as signature               ***/
  293.  
  294.  
  295.       if (GetNextLine()) {            /* end of file? */
  296.         AsmError(2, 0);            /* yes, then error */
  297.         return(-1);
  298.       }
  299.                         /* store signature in the */
  300.       n = m = 0;                /* JEDEC structure        */
  301.                     /* end of signature: after eight */
  302.                     /* characters, CR or TAB */
  303.       while((*actptr != 0x0A) && (*actptr != 0x09) && (n < 8)) {
  304.         chr = *actptr;
  305.  
  306.         for (m = 0; m < 8; m++)
  307.           Jedec.GALSig[n*8 + m] = (chr >> (7 - m)) & 0x1;
  308.  
  309.         actptr++;                /* increment pointer and */
  310.         n++;                /* character-counter     */
  311.  
  312.         if (actptr>buffend) {        /* end of file ?*/
  313.           AsmError(2, 0);            /* yes, then error */
  314.           return(-1);
  315.         }
  316.       } 
  317.  
  318.  
  319.                 /*** get name of pins ***/
  320.  
  321.                     /* clear flags for negations */
  322.                     /* in the pin declaration */
  323.       for (n = 0; n < 24; PinDecNeg[n++] = 0);
  324.  
  325.  
  326.       pinnames = &PinNames[0][0];    /*assembler: pin names in PinNames*/
  327.  
  328.       if (OpMode == OPTIMIZER)    /*optimizer: pin names in PinNamesOpt*/
  329.         pinnames = &PinNamesOpt[0][0];
  330.  
  331.       asmreadyflag = 0;            /* set flag 'not assembled' */
  332.  
  333.       GetNextLine();
  334.  
  335.       for (n = 0; n < num_of_pins; n++) {
  336.         if (GetNextChar()) {        /*unexpected end of file?*/
  337.           AsmError(2, 0);            /*yes, then error*/
  338.           return(-1);
  339.         }
  340.  
  341.         m = 0;
  342.  
  343.         chr = *actptr;            /* get character */
  344.  
  345.         if (IsNEG(chr)) {            /* is there a negation? */
  346.           max_chr        = 10;
  347.           PinDecNeg[n] = 1;            /* yes, then set flag */
  348.         }
  349.         else
  350.           max_chr = 9;
  351.  
  352.         if (!(isalpha(chr) || isdigit(chr) || IsNEG(chr))) {
  353.           AsmError(5, 0);            /* is character a legal */
  354.           return(-1);            /* one? */
  355.         }
  356.  
  357.         k = 0;
  358.  
  359.         while (isalpha(chr) || isdigit(chr) || IsNEG(chr)) {
  360.           if (IsNEG(chr) && k != 0) {    /* check position of '/' */
  361.             AsmError(10, 0);            /* must be at the beginning */
  362.             return(-1);            /* of the pin name */
  363.           }
  364.  
  365.           k = 1;
  366.  
  367.           actptr++;
  368.  
  369.           if (IsNEG(chr) && (!(isalpha(*actptr) || isdigit(*actptr)))) {
  370.             AsmError(3, 0);
  371.             return(-1);
  372.           }
  373.  
  374.           *(pinnames + n*10 + m) = chr;
  375.  
  376.           m++;
  377.  
  378.           chr = *actptr;
  379.  
  380.           if (m == max_chr) {        /*check number of characters*/
  381.             AsmError(4, 0);            /*in this pinname*/
  382.             return(-1);            /* error: too many char. */
  383.            }
  384.  
  385.         }
  386.  
  387.         *(pinnames+n*10+m) = 0;        /* mark end of string */
  388.  
  389.         for (l = 0; l < n; l++) {        /* pin name twice ? */
  390.           if (strcmp((char *)pinnames+l*10, "NC")) {
  391.             i = j = 0;
  392.  
  393.             if (IsNEG(*(pinnames+l*10)))    /* skip negation sign */
  394.           i = 1;
  395.  
  396.             if (IsNEG(*(pinnames+n*10)))
  397.           j = 1;
  398.  
  399.             if (!strcmp((char *)(pinnames+l*10+i), (char *)(pinnames+n*10+j))) {
  400.             AsmError(9, 0);        /* pin name defined twice */
  401.           return(-1);
  402.             }
  403.           }
  404.         }
  405.                         /* is GND at the GND-pin? */
  406.         if (!strcmp((char *)(pinnames + n*10), "GND")) {
  407.           if (n+1 != num_of_pins/2) {
  408.             AsmError(6, 0);
  409.             return(-1);
  410.           }
  411.         }
  412.         if (n + 1 == num_of_pins/2) {
  413.           if (strcmp((char *)(pinnames + n*10), "GND")) {
  414.             AsmError(8, 0);
  415.             return(-1);
  416.           }
  417.         }
  418.                         /* is VCC at the VCC pin? */
  419.         if (!strcmp((char *)(pinnames + n*10), "VCC")) {
  420.           if (n+1 != num_of_pins) {
  421.            AsmError(6, 0);
  422.            return(-1);
  423.           }
  424.         }
  425.         if (n + 1 == num_of_pins) {
  426.           if (strcmp((char *)(pinnames + n*10), "VCC")) {
  427.             AsmError(7, 0);
  428.             return(-1);
  429.           }
  430.         }
  431.                     /* AR and SP are key words for 22V10 */
  432.                     /* they are not allowed in the pin */
  433.                     /* declaration */
  434.        if (gal_type == GAL22V10) {
  435.          if (!strcmp((char *)(pinnames+n*10), "AR")) {
  436.            AsmError(18, 0);
  437.            return(-1);
  438.          }
  439.  
  440.          if (!strcmp((char *)(pinnames + n*10), "SP")) {
  441.            AsmError(18, 0);
  442.            return(-1);
  443.          }
  444.        }
  445.  
  446.  
  447.      }
  448.  
  449.  
  450.      if (OpMode == OPTIMIZER)    /* if this routine is called from */
  451.        return(0);            /* the optimizer, then finish */
  452.  
  453.  
  454.  
  455. /* Boolean-Equations auswerten:
  456.    Dabei werden die Boolean-Equations zweimal untersucht. Beim ersten
  457.    Durchlauf werden die OLMC-Pins ausgewertet und die OLMC-Struktur ge-
  458.    füllt. Mit Hilfe dieser Struktur läßt sich auf dem notwendigen Modus
  459.    (1, 2 oder 3) schließen. Beim zweiten Durchlauf wird dann die
  460.    Fuse-Matrix erstellt.
  461. */
  462.  
  463.  
  464.   if (GetNextChar()) {            /* end of file? */
  465.     AsmError(2, 0);            /* yes, then error */
  466.     return(-1);
  467.   }
  468.  
  469.                     /* are there any equations? */
  470.   if (!strncmp((char *)actptr, "DESCRIPTION", (size_t)11)) {
  471.     AsmError(33, 0);            /* no, then error */
  472.     return(-1);
  473.   }
  474.  
  475.  
  476.   bool_start   = actptr;        /*set pointer to the beginning of*/
  477.   bool_linenum = linenum;        /*the equations and save line number*/
  478.  
  479.  
  480.   for (pass = 0; pass < 2; pass++) {    /*this is a tow-pass-assembler*/
  481.  
  482.     if (pass) {                /* 2. pass? => make ACW and get */
  483.                     /* the mode for 16V8,20V8 GALs  */
  484.       modus = 0;
  485.                 /*** GAL16V8, GAL20V8 ***/
  486.  
  487.       if (gal_type == GAL16V8 || gal_type == GAL20V8) {
  488.  
  489.     for (n = 0; n < 8; n++) {        /* examine all OLMCs */
  490.        if (OLMC[n].PinType == REGOUT) { /* is there a registered OLMC? */
  491.          modus = MODE3;         /* yes, then GAL's mode is mode 3 */
  492.  
  493.          Jedec.GALSYN = 0;         /* set SYN and AC0 for mode 3 */
  494.  
  495.          Jedec.GALAC0 = 1;
  496.  
  497.          break;
  498.        }
  499.         }
  500.  
  501.         if (!modus) {
  502.       for (n = 0; n < 8; n++) {    /* examine all OLMCs */
  503.         if (OLMC[n].PinType == TRIOUT) { /* is there a tristate OLMC? */
  504.           modus = MODE2;        /* yes then GAL's mode is mode 2 */
  505.  
  506.           Jedec.GALSYN = 1;        /* set SYN und AC0 bit for mode 2 */
  507.  
  508.           Jedec.GALAC0 = 1;
  509.  
  510.           break;
  511.         }
  512.       }
  513.         }
  514.  
  515.  
  516.         if (!modus) {            /*if there is a violation of mode 1,*/
  517.       for (n = 0; n < 8; n++) {    /*then use automatically mode 2*/
  518.         if (OLMC[n].PinType == INPUT) {
  519.           if (gal_type == GAL16V8) {
  520.             pin_num = n + 12;
  521.  
  522.             if ((pin_num == 15) || (pin_num == 16)) {
  523.           modus = MODE2;        /* mode 2 */
  524.  
  525.           Jedec.GALSYN = 1;        /* set SYN and AC0 bit */
  526.  
  527.           Jedec.GALAC0 = 1;
  528.  
  529.           break;
  530.             }
  531.  
  532.           }
  533.  
  534.           if (gal_type == GAL20V8) {
  535.             pin_num = n + 15;
  536.  
  537.             if ((pin_num == 18) || (pin_num == 19)) {
  538.           modus = MODE2;        /* mode 2 */
  539.  
  540.           Jedec.GALSYN = 1;        /* set SYN and AC0 bit */
  541.  
  542.           Jedec.GALAC0 = 1;
  543.  
  544.           break;
  545.             }
  546.           }
  547.         }                /* output and feedback? then mode 2 */
  548.  
  549.         if ((OLMC[n].PinType == COM_TRI_OUT) && (OLMC[n].FeedBack)) {
  550.           modus = MODE2;            /* mode 2 */
  551.  
  552.           Jedec.GALSYN = 1;            /* set SYN and AC0 bit */
  553.  
  554.           Jedec.GALAC0 = 1;
  555.  
  556.           break;
  557.         }
  558.           }
  559.         }
  560.  
  561.  
  562.         if (!modus) {            /* if there is still no mode */
  563.       modus = MODE1;        /* defined, use mode 1 */
  564.  
  565.       Jedec.GALSYN = 1;        /* set SYN and AC0 bit */
  566.  
  567.       Jedec.GALAC0 = 0;
  568.         }
  569.  
  570.  
  571.  
  572.         /* If GAL's mode is mode 1, use all OLMCs which type is   */
  573.         /* not defined explicitly as combinational outputs.       */
  574.         /* If GAL's mode is mode 2 or 3, use all OLMCs which type */
  575.         /* is not defined explicitly as tristate output which is  */
  576.         /* always enabled */
  577.  
  578.     for (n = 0; n < 8; n++) {            /* examine all OLMCs */
  579.       if (OLMC[n].PinType == COM_TRI_OUT) {    /* is OLMC's type defined */
  580.         if (modus == MODE1)            /* explicitly? */
  581.           OLMC[n].PinType = COMOUT;        /* mode 1? then comb. output */
  582.         else {
  583.           OLMC[n].PinType = TRIOUT;        /* mode 2, 3? then tri. output */
  584.  
  585.           OLMC[n].TriCon  = TRI_VCC;    /* tristate control = TRUE */
  586.         }
  587.       }
  588.         }
  589.     
  590.                     /* make ACW; (SYN and AC0 are */
  591.                     /* defined already) */
  592.  
  593.     for (n = 0; n < PT_SIZE; n++)    /* set product term disalbe */
  594.       Jedec.GALPT[n] = 1;
  595.  
  596.                     /* get AC1 bits */
  597.     for (n = 0; n < AC1_SIZE; n++) {
  598.       if ((OLMC[n].PinType == INPUT) || (OLMC[n].PinType == TRIOUT))
  599.         Jedec.GALAC1[AC1_SIZE - 1 - n] = 1;
  600.         }
  601.  
  602.     for (n = 0; n < XOR_SIZE; n++) {    /* get XOR bits */
  603.       if (((OLMC[n].PinType == COMOUT) || (OLMC[n].PinType == TRIOUT) ||
  604.            (OLMC[n].PinType == REGOUT)) && (OLMC[n].Active  == ACTIVE_HIGH))
  605.             Jedec.GALXOR[XOR_SIZE - 1 - n] = 1;
  606.     }
  607.  
  608.       }
  609.                 /*** GAL22V10 ***/
  610.  
  611.       if (gal_type == GAL22V10) {
  612.  
  613.     for (n = 0; n < 10; n++) {
  614.                         /* get XOR bits (S0) */
  615.       if (OLMC[n].PinType == COM_TRI_OUT)    /* output can be */
  616.         OLMC[n].PinType = TRIOUT;        /* tristate or register */
  617.  
  618.       if (((OLMC[n].PinType == COMOUT) || (OLMC[n].PinType == TRIOUT) ||
  619.            (OLMC[n].PinType == REGOUT)) && (OLMC[n].Active  == ACTIVE_HIGH))
  620.             Jedec.GALXOR[9 - n] = 1;
  621.  
  622.                         /* get AC1 bits (S1) */
  623.       if ((OLMC[n].PinType == INPUT) || (OLMC[n].PinType == TRIOUT))
  624.         Jedec.GALS1[9 - n] = 1;
  625.     }
  626.  
  627.       }
  628.  
  629.                 /*** GAL20RA10 ***/
  630.  
  631.       if (gal_type == GAL20RA10) {
  632.                         /* get XOR bits (S0) */
  633.     for (n = 0; n < 10; n++) {
  634.       if (OLMC[n].PinType == COM_TRI_OUT)    /* output can be tristate */
  635.         OLMC[n].PinType = TRIOUT;        /* or register */
  636.  
  637.       if (((OLMC[n].PinType == COMOUT) || (OLMC[n].PinType == TRIOUT) ||
  638.            (OLMC[n].PinType == REGOUT)) && (OLMC[n].Active  == ACTIVE_HIGH))
  639.             Jedec.GALXOR[9 - n] = 1;
  640.     }
  641.       }
  642.  
  643.     }
  644.  
  645.  
  646.     actptr  = bool_start;
  647.  
  648.     linenum = bool_linenum;
  649.  
  650.     newline = linenum;
  651.  
  652.     goto label1;        /* Shit, don't blame me for the gotos.       */
  653.                 /* I know, goto is a very bad command in C   */
  654.                 /* and in the most other languages. But it   */
  655.                 /* is very hard to remove them in this case. */
  656.  
  657. loop1:
  658.  
  659.     if (GetNextChar()) {            /* end of file? */
  660.       AsmError(2, 0);                /* yes then error */
  661.       return(-1);
  662.     }
  663.  
  664.     suffix = SUFFIX_NON;
  665.  
  666.     if (*actptr == '.') {            /* is there a suffix? */
  667.       actptr++;                    /* yes, then get the string */
  668.  
  669.       if (gal_type == GAL22V10 && (actPin.p_Pin == 24 || actPin.p_Pin == 25)) {
  670.     AsmError(39, 0);                /* no suffix allowed at */
  671.     return(-1);                /* AR and SP */
  672.       }
  673.  
  674.  
  675.       n = 0;
  676.       while (isalpha(*actptr)) {        /* copy suffix string into */
  677.     if (n < MAX_SUFFIX_SIZE)         /* suffix array */
  678.       suffix_strn[n++] = *actptr++;
  679.     else {                    /* string too long, then */
  680.       AsmError(13, 0);                /* unknown suffix */
  681.       return(-1);
  682.     }
  683.       }
  684.  
  685.       suffix_strn[n] = 0;            /* mark end of string */
  686.  
  687.       if (!strcmp(&suffix_strn[0], "T"))
  688.     suffix = SUFFIX_T;
  689.       else
  690.     if (!strcmp(&suffix_strn[0], "R"))
  691.       suffix = SUFFIX_R;
  692.     else
  693.       if (!strcmp(&suffix_strn[0], "E"))
  694.         suffix = SUFFIX_E;
  695.       else
  696.         if (!strcmp(&suffix_strn[0], "CLK"))
  697.           suffix = SUFFIX_CLK;
  698.         else
  699.           if (!strcmp(&suffix_strn[0], "ARST"))
  700.         suffix = SUFFIX_ARST;
  701.           else
  702.          if (!strcmp(&suffix_strn[0], "APRST"))
  703.           suffix = SUFFIX_APRST;
  704.         else {
  705.           AsmError(13, 0);
  706.           return(-1);
  707.         }
  708.                     /* check whether suffix is */
  709.                     /* allowed or not */
  710.       if (gal_type != GAL20RA10) {
  711.     switch (suffix) {
  712.       case SUFFIX_CLK:
  713.         AsmError(34, 0);            /* no .CLK allowed */
  714.         return(-1);
  715.         break;
  716.  
  717.       case SUFFIX_ARST:
  718.         AsmError(35, 0);            /* .ARST is not allowed */
  719.         return(-1);
  720.         break;
  721.  
  722.       case SUFFIX_APRST:
  723.         AsmError(36, 0);            /* .APRST is not allowed */
  724.         return(-1);
  725.         break;
  726.     }
  727.       }
  728.  
  729.       if (GetNextChar()) {            /* end of file? */
  730.         AsmError(2, 0);                /* yes, then error */
  731.         return(-1);
  732.       }
  733.     }
  734.  
  735.  
  736.  
  737.     actOLMC = (int)actPin.p_Pin;        /* save offset of OLMC */
  738.  
  739.  
  740.  
  741.     if (gal_type == GAL16V8)
  742.       actOLMC -= 12;
  743.     else
  744.       if (gal_type == GAL20V8)
  745.         actOLMC -= 15;
  746.       else
  747.     actOLMC -= 14;
  748.  
  749.  
  750.     row_offset = 0;            /* offset for OR at OLMC*/
  751.  
  752.     prevOp     = 0;            /* previous operator */
  753.  
  754.  
  755.     if (!pass) {            /* is this pass 1? */
  756.                     /* is pin a OLMC pin? */
  757.       if ( ((gal_type == GAL16V8)
  758.            && (actPin.p_Pin >= 12) && (actPin.p_Pin <= 19)) ||
  759.            ((gal_type == GAL20V8)
  760.            && (actPin.p_Pin >= 15) && (actPin.p_Pin <= 22)) ||
  761.        ((gal_type == GAL22V10) 
  762.            && (actPin.p_Pin >= 14) && (actPin.p_Pin <= DUMMY_OLMC12)) ||
  763.        ((gal_type == GAL20RA10) 
  764.            && (actPin.p_Pin >= 14) && (actPin.p_Pin <= 23)) ) {
  765.  
  766.  
  767.     switch (gal_type) {            /* get OLMC number */
  768.       case GAL16V8:
  769.         n = actPin.p_Pin - 12;
  770.         break;
  771.  
  772.       case GAL20V8:
  773.         n = actPin.p_Pin - 15;
  774.         break;
  775.  
  776.       case GAL22V10:
  777.       case GAL20RA10:
  778.         n = actPin.p_Pin - 14;
  779.         break;
  780.     }
  781.  
  782.  
  783.  
  784.     switch (suffix) {
  785.  
  786.       case SUFFIX_R:        /* output definition */
  787.       case SUFFIX_T:
  788.       case SUFFIX_NON:
  789.  
  790.         if ((!OLMC[n].PinType) || (OLMC[n].PinType == INPUT)) {
  791.  
  792.           if (actPin.p_Neg)            /* get pin's activation */
  793.             OLMC[n].Active = ACTIVE_LOW;
  794.           else
  795.             OLMC[n].Active = ACTIVE_HIGH;
  796.  
  797.           if (suffix == SUFFIX_T)
  798.             OLMC[n].PinType = TRIOUT;    /* tristate output */
  799.  
  800.           if (suffix == SUFFIX_R)
  801.         OLMC[n].PinType = REGOUT;    /* registered output */
  802.  
  803.           if (suffix == SUFFIX_NON)        /* type of output is not */
  804.         OLMC[n].PinType = COM_TRI_OUT;    /* defined explicitly */
  805.  
  806.         }
  807.         else {
  808.           if (gal_type == GAL22V10 && (n == 10 || n == 11)) {
  809.         AsmError(40, 0);        /* AR or SP is defined*/
  810.         return(-1);            /* twice */
  811.           }
  812.           else {
  813.         AsmError(16, 0);        /* pin is defined twice as */
  814.         return(-1);            /* output */
  815.           }
  816.         }
  817.  
  818.         break;
  819.  
  820.  
  821.  
  822.       case SUFFIX_E:
  823.  
  824.         if (actPin.p_Neg) {            /* negation of the trisate */
  825.           AsmError(19, 0);            /* control is not allowed */
  826.           return(-1);
  827.         }
  828.  
  829.         if (OLMC[n].TriCon) {        /* tri. control twice? */
  830.           AsmError(22, 0);            /* yes, then error */
  831.           return(-1);
  832.         }
  833.  
  834.         OLMC[n].TriCon = TRICON;        /* set the flag that there is */
  835.                         /* a tri. control equation */
  836.  
  837.         if ((!OLMC[n].PinType) || (OLMC[n].PinType == INPUT)) {
  838.           AsmError(17, 0);            /* the sequence must be output */
  839.           return(-1);            /* followed by the tri. control  */
  840.         }
  841.  
  842.  
  843.         if (OLMC[n].PinType == REGOUT &&
  844.            (gal_type == GAL16V8 || gal_type == GAL20V8)) {
  845.           AsmError(23, 0);        /* GAL16V8/20V8: tristate control */
  846.           return(-1);        /* for reg. output is not allowed */
  847.         }
  848.  
  849.  
  850.         if (OLMC[n].PinType == COM_TRI_OUT) { /* no tristate .T? */
  851.           AsmError(24, 0);              /* then error */
  852.           return(-1);
  853.         }
  854.  
  855.         break;
  856.  
  857.  
  858.  
  859.         case SUFFIX_CLK:
  860.  
  861.           if (actPin.p_Neg) {        /* negation of the .CLK */
  862.             AsmError(19, 0);        /* control is not allowed */
  863.             return(-1);
  864.           }
  865.  
  866.           if (OLMC[n].PinType == NOTUSED) {
  867.         AsmError(42, 0);        /* sequence must be: output */
  868.         return(-1);            /* def., .CLK definition */
  869.           }
  870.  
  871.           if (OLMC[n].Clock) {        /* is .CLK defined twice? */
  872.         AsmError(45, 0);        /* yes, then error */
  873.         return(-1);
  874.           }
  875.  
  876.           OLMC[n].Clock = 1;        /* set flag that there is */
  877.                         /* a .CLK equation */
  878.           if (OLMC[n].PinType != REGOUT) {
  879.         AsmError(48, 0);        /* no .CLK allowed when */
  880.         return(-1);            /* output is not registered */
  881.           }
  882.  
  883.           break;
  884.     
  885.  
  886.  
  887.         case SUFFIX_ARST:
  888.  
  889.           if (actPin.p_Neg) {        /* negation of the .ARST */
  890.             AsmError(19, 0);        /* control is not allowed */
  891.             return(-1);
  892.           }
  893.  
  894.           if (OLMC[n].PinType == NOTUSED) {
  895.         AsmError(43, 0);        /* sequence must be: output */
  896.         return(-1);            /* def., .ARST definition */
  897.           }
  898.  
  899.           if (OLMC[n].ARST) {        /* is .ARST defined twice? */
  900.         AsmError(46, 0);        /* yes, then error */
  901.         return(-1);
  902.           }
  903.  
  904.           OLMC[n].ARST = 1;            /* set flag that there is */
  905.                         /* a .ARST equation */
  906.           if (OLMC[n].PinType != REGOUT) {
  907.         AsmError(48, 0);        /* no .CLK allowed when */
  908.         return(-1);            /* output is not registered */
  909.           }
  910.  
  911.           break;
  912.  
  913.  
  914.  
  915.         case SUFFIX_APRST:
  916.  
  917.           if (actPin.p_Neg) {        /* negation of the .APRST */
  918.             AsmError(19, 0);        /* control is not allowed */
  919.             return(-1);
  920.           }
  921.  
  922.           if (OLMC[n].PinType == NOTUSED) {
  923.         AsmError(44, 0);        /* sequence must be: output */
  924.         return(-1);            /* def., .APRST definition */
  925.           }
  926.  
  927.           if (OLMC[n].APRST) {        /* is .APRST defined twice? */
  928.         AsmError(47, 0);        /* yes, then error */
  929.         return(-1);
  930.           }
  931.  
  932.           OLMC[n].APRST = 1;        /* set flag that there is */
  933.                         /* a .APRST equation */
  934.           if (OLMC[n].PinType != REGOUT) {
  935.         AsmError(48, 0);        /* no .CLK allowed when */
  936.         return(-1);            /* output is not registered */
  937.           }
  938.  
  939.           break;
  940.     }
  941.  
  942.       }
  943.       else {
  944.     AsmError(15, 0);            /* pin can't be programmed */
  945.     return(-1);                /* as output */
  946.       }
  947.     }
  948.  
  949.  
  950.  
  951.     switch (gal_type) {                /* get first row of the */
  952.       case GAL16V8:                /* OLMC and the number of */
  953.       case GAL20V8:                /* rows which areavailable */
  954.     start_row = ToOLMC[actOLMC];
  955.     max_row   = 8;
  956.     break;
  957.  
  958.       case GAL22V10:
  959.     start_row = ToOLMC22V10[actOLMC];
  960.     max_row   = OLMCSize22V10[actOLMC];
  961.     break;
  962.  
  963.       case GAL20RA10:
  964.     start_row = ToOLMC20RA10[actOLMC];
  965.     max_row   = 8;
  966.     break;
  967.     }
  968.  
  969.  
  970.  
  971.  
  972.     if (*actptr != '=') {            /* '=' ?*/
  973.       AsmError(14, 0);                /*no, then error */
  974.       return(-1);
  975.     }         
  976.  
  977. loop2:
  978.  
  979.     actptr++;
  980.  
  981.     if (GetNextChar()) {            /* end of file? */
  982.       AsmError(2, 0);                /* yes, then error */
  983.       return(-1);
  984.     }
  985.  
  986.     oldptr = actptr;                /* save pointer */
  987.  
  988.     IsPinName(pinnames, num_of_pins);
  989.  
  990.     if (gal_type == GAL22V10 && !actPin.p_Pin) { /* AR and SP is not allowed */
  991.       Is_AR_SP(oldptr);                 /* in terms of an equation */
  992.  
  993.       if (actPin.p_Pin) {             /* when used, then error */
  994.     AsmError(31, 0);
  995.     return(-1);
  996.       }
  997.     }
  998.  
  999.  
  1000.     if (!actPin.p_Pin) {            /* pin name? */
  1001.       AsmError(11, 0);                /* no, then error */
  1002.       return(-1);
  1003.     }
  1004.  
  1005.  
  1006.     if (actPin.p_Pin == NC_PIN) {        /* NC used as pin name? */
  1007.       AsmError(12, 0);                /* yes, then error */
  1008.       return(-1);
  1009.     }
  1010.  
  1011.     if (IsNEG(*(pinnames+(long)((actPin.p_Pin-1)*10))))
  1012.       actPin.p_Neg = !actPin.p_Neg;        /* consider negation in the */
  1013.                         /* pin declartion */
  1014.  
  1015.     oldline = linenum;
  1016.  
  1017.     if (GetNextChar()) {            /* end of file? */
  1018.       AsmError(2, 0);                /* yes, then error */
  1019.       return(-1);
  1020.     }
  1021.  
  1022.     newline = linenum;
  1023.  
  1024.     linenum = oldline;
  1025.  
  1026.  
  1027.     if (!pass) {                /* is this pass 1?*/
  1028.       if ( ((gal_type == GAL16V8)        /* is this pin an OLMC pin? */
  1029.            && (actPin.p_Pin >= 12) && (actPin.p_Pin <= 19)) ||
  1030.            ((gal_type == GAL20V8)
  1031.            && (actPin.p_Pin >= 15) && (actPin.p_Pin <= 22)) ||
  1032.        ((gal_type == GAL22V10) 
  1033.            && (actPin.p_Pin >= 14) && (actPin.p_Pin <= DUMMY_OLMC12)) ||
  1034.        ((gal_type == GAL20RA10) 
  1035.            && (actPin.p_Pin >= 14) && (actPin.p_Pin <= 23)) ) {
  1036.  
  1037.  
  1038.     switch (gal_type) {            /* get OLMC number */
  1039.       case GAL16V8:
  1040.         n = actPin.p_Pin - 12;
  1041.         break;
  1042.  
  1043.       case GAL20V8:
  1044.         n = actPin.p_Pin - 15;
  1045.         break;
  1046.  
  1047.       case GAL22V10:
  1048.       case GAL20RA10:
  1049.         n = actPin.p_Pin - 14;
  1050.         break;
  1051.     }
  1052.  
  1053.  
  1054.     if (!OLMC[n].PinType)            /* is OLMC's type already */
  1055.       OLMC[n].PinType = INPUT;        /* defined? no, then use  */
  1056.                         /* it as input */
  1057.     OLMC[n].FeedBack = YES;        /* if a OLMC pin is used within an */
  1058.       }                    /* equation, a feedback is needed  */
  1059.     }
  1060.  
  1061.                 /* in pass 2 we have to make the fuse matrix */
  1062.     if (pass) {
  1063.    
  1064.       switch (gal_type) {        /* get row offset */
  1065.     case GAL16V8:
  1066.     case GAL20V8:
  1067.  
  1068.       if (suffix == SUFFIX_E)    /* when tristate control use first */
  1069.         row_offset = 0;        /* row (=> offset = 0) */
  1070.       else
  1071.         if (!row_offset)        /* is offset of rows still equal 0?*/
  1072.           if ((modus != MODE1) && (OLMC[actOLMC].PinType != REGOUT))
  1073.             row_offset = 1;        /* then init. row-offset */
  1074.  
  1075.       break;
  1076.  
  1077.     case GAL22V10:
  1078.  
  1079.       if (suffix == SUFFIX_E)    /* enable is the first row */
  1080.         row_offset = 0;        /* of the OLMC */
  1081.       else {
  1082.         if (actOLMC == 10 || actOLMC == 11) 
  1083.           row_offset = 0;        /* AR, SP?, then no offset */
  1084.         else
  1085.           if (!row_offset)        /* output starts at the second row */
  1086.             row_offset = 1;        /* => offset = 1 */
  1087.       }
  1088.  
  1089.       break;
  1090.  
  1091.     case GAL20RA10:
  1092.       switch (suffix) {
  1093.         case SUFFIX_E:        /* enable is the first row */
  1094.           row_offset = 0;        /* of the OLMC */
  1095.           break;
  1096.  
  1097.         case SUFFIX_CLK:        /* Clock is the second row */
  1098.           row_offset = 1;        /* of the OLMC */
  1099.           break;
  1100.  
  1101.         case SUFFIX_ARST:        /* AReset is the third row */
  1102.           row_offset = 2;        /* of the OLMC */
  1103.           break;
  1104.  
  1105.         case SUFFIX_APRST:        /* APreset is the fourth row */
  1106.           row_offset = 3;        /* of the OLMC */
  1107.           break;
  1108.  
  1109.         default:            /* output equation starts at */
  1110.           if (row_offset <= 3)    /* the fifth row */
  1111.         row_offset = 4;
  1112.       }
  1113.       break;
  1114.       }
  1115.  
  1116.       pin_num = actPin.p_Pin;
  1117.  
  1118.                 /* is there a valuation of GAL's mode? */
  1119.  
  1120.       if (gal_type == GAL16V8 || gal_type == GAL20V8) {
  1121.  
  1122.     if (modus == MODE2) {            /* valuation of mode 2? */
  1123.       if ((gal_type == GAL16V8) && ((pin_num == 12) || (pin_num == 19))) {
  1124.         AsmError(20, 0);
  1125.         return(-1);
  1126.       }
  1127.  
  1128.       if ((gal_type == GAL20V8) && ((pin_num == 15) || (pin_num == 22))) {
  1129.         AsmError(21, 0);
  1130.         return(-1);
  1131.       }
  1132.         }
  1133.  
  1134.         if (modus == MODE3) {            /* valuation of mode 3? */
  1135.       if ((gal_type == GAL16V8) && ((pin_num == 1) || (pin_num == 11))) {
  1136.         AsmError(26, 0);
  1137.         return(-1);
  1138.       }
  1139.  
  1140.       if ((gal_type == GAL20V8) && ((pin_num == 1) || (pin_num == 13))) {
  1141.         AsmError(27, 0);
  1142.         return(-1);
  1143.       }
  1144.         }
  1145.       }
  1146.  
  1147.       if (gal_type == GAL20RA10) {    /* valuation of 20RA10? */
  1148.     if (pin_num == 1) {            /* pin 1 is reserved for */
  1149.       AsmError(37, 0);                /* /PL (preload) */
  1150.       return(-1);
  1151.     }
  1152.  
  1153.     if (pin_num == 13) {            /* pin 13 is reserved for */
  1154.       AsmError(38, 0);                /* /OE (output enable) */
  1155.       return(-1);
  1156.     }
  1157.       }
  1158.  
  1159.  
  1160.                     /* if GND, set row equal 0 */
  1161.       if ((pin_num == num_of_pins) || (pin_num == num_of_pins/2)) {
  1162.     if (actPin.p_Neg) {        /* /VCC and /GND are not allowed */
  1163.       AsmError(25, 0);
  1164.       return(-1);
  1165.     }
  1166.  
  1167.         if (!prevOp && !IsAND(*actptr) && !IsOR(*actptr)) {
  1168.  
  1169.       if (pin_num == num_of_pins/2) {
  1170.  
  1171.         m = (start_row + row_offset) * num_of_col;
  1172.                                /* set row equal 0 */
  1173.         for (n = m; n < m+num_of_col; Jedec.GALLogic[n++] = 0);
  1174.  
  1175.       }
  1176.     }
  1177.     else {
  1178.       AsmError(28, 0);
  1179.       return(-1);
  1180.     }
  1181.       }
  1182.       else {
  1183.  
  1184.     if (suffix == SUFFIX_E || suffix == SUFFIX_CLK ||
  1185.         suffix == SUFFIX_ARST || suffix == SUFFIX_APRST ||
  1186.        (gal_type == GAL22V10 && (actOLMC == 10 || actOLMC == 11))) {
  1187.  
  1188.       if (IsOR(prevOp)) {            /* max. one product term */
  1189.         AsmError(29, 0);            /* for CLK, ARST, APRST, E*/
  1190.         return(-1);                /* and 22V10: AR, SP */
  1191.       }
  1192.  
  1193.       SetAND(start_row + row_offset, pin_num, actPin.p_Neg);
  1194.     }
  1195.     else {
  1196.       if (IsOR(prevOp)) {            /* OR operation? yes, then*/
  1197.         row_offset++;            /* take the next row */
  1198.  
  1199.         if (row_offset == max_row) {    /* too many ORs?*/
  1200.           AsmError(30, 0);
  1201.           return(-1);
  1202.         }
  1203.       }
  1204.                         /* set ANDs */
  1205.       SetAND(start_row + row_offset, pin_num, actPin.p_Neg);
  1206.     }
  1207.       }
  1208.  
  1209.  
  1210.                     /* are there any more terms? */
  1211.       if (!IsOR(*actptr) && !IsAND(*actptr) && suffix != SUFFIX_E
  1212.       && suffix != SUFFIX_CLK && suffix != SUFFIX_ARST
  1213.           && suffix != SUFFIX_APRST) {
  1214.                         /* no?, then */
  1215.     row_offset++;                /* set unused rows of the */
  1216.                         /* OLMC equal 0 */
  1217.     if (row_offset != max_row) {
  1218.       m = (start_row + row_offset) * num_of_col;
  1219.  
  1220.       for (n = m; n < m + (max_row - row_offset) * num_of_col; n++)
  1221.         Jedec.GALLogic[n] = 0;
  1222.  
  1223.     }
  1224.       }
  1225.     }
  1226.  
  1227.  
  1228.     linenum = newline;
  1229.  
  1230.     if (IsOR(*actptr) || IsAND(*actptr)) {
  1231.       prevOp = *actptr;
  1232.       goto loop2;
  1233.     }
  1234.  
  1235.     if (strncmp((char *)actptr, "DESCRIPTION", (size_t)11)) {
  1236.  
  1237. label1:
  1238.  
  1239.       linenum = newline;
  1240.  
  1241.       oldptr = actptr;
  1242.  
  1243.       IsPinName(pinnames, num_of_pins);
  1244.  
  1245.       if (gal_type == GAL22V10 && !actPin.p_Pin) { /* no pin name? then  */
  1246.     Is_AR_SP(oldptr);               /* check whether name */
  1247.                            /* is AR or SP */
  1248.     if (actPin.p_Pin && actPin.p_Neg) {    /* but no negation of */
  1249.       AsmError(32, 0);                /* AR or SP */
  1250.       return(-1);
  1251.     }
  1252.       }
  1253.     
  1254.       if (!actPin.p_Pin) {            /* pin name? */
  1255.     AsmError(11, 0);                /* no, then error */
  1256.     return(-1);
  1257.       }
  1258.  
  1259.       if (actPin.p_Pin == NC_PIN) {        /* NC used as pin name? */
  1260.     AsmError(12, 0);                /* yes, then error */
  1261.     return(-1);
  1262.       }
  1263.  
  1264.       if (IsNEG(*(pinnames+(long)((actPin.p_Pin-1)*10))))
  1265.     actPin.p_Neg = !actPin.p_Neg;        /* negation at pin declaration */
  1266.  
  1267.       goto loop1;
  1268.  
  1269.     }
  1270.   }
  1271.  
  1272.  
  1273.             /* set fuse matrix of unused OLMCs and of OLMCs */
  1274.             /* which are programmed as input equal 0 */
  1275.  
  1276.   for (n = 0; n < num_of_olmcs; n++) {
  1277.     if ((OLMC[n].PinType == NOTUSED) || (OLMC[n].PinType == INPUT)) {
  1278.  
  1279.       switch (gal_type) {            /* get first row of the */
  1280.         case GAL16V8:                /* OLMC and the number of */
  1281.         case GAL20V8:                /* rows which are available */
  1282.       l = ToOLMC[n];
  1283.       i = 8;
  1284.       break;
  1285.  
  1286.         case GAL22V10:
  1287.       l = ToOLMC22V10[n];
  1288.       i = OLMCSize22V10[n];
  1289.       break;
  1290.  
  1291.         case GAL20RA10:
  1292.       l = ToOLMC20RA10[n];
  1293.       i = 8;
  1294.       break;
  1295.       }
  1296.  
  1297.       l = l * num_of_col;
  1298.  
  1299.       m = l + i * num_of_col;
  1300.  
  1301.       for (k = l; k < m; k++)
  1302.     Jedec.GALLogic[k] = 0;
  1303.     }
  1304.   }
  1305.  
  1306.  
  1307.   if (gal_type == GAL22V10) {        /* if AR or SP is not defined,   */
  1308.                     /* set corresponding row equal 0 */
  1309.     if (!OLMC[10].PinType)               /* set row of AR equal 0 */
  1310.       for (n = 0; n < num_of_col; Jedec.GALLogic[n++] = 0);
  1311.  
  1312.     if (!OLMC[11].PinType)               /* set row of SP equal 0 */
  1313.       for (n = 5764; n < 5764 + num_of_col; Jedec.GALLogic[n++] = 0);
  1314.   }
  1315.  
  1316.  
  1317.   if (gal_type == GAL20RA10) {            /* set unused CLK, ARST */
  1318.                         /* and APRST equal 0 */
  1319.     for (n = 0; n < num_of_olmcs; n++) {    /* examine all OLMCs */
  1320.  
  1321.       if (OLMC[n].PinType != NOTUSED) {        /* is OLMC used? */
  1322.  
  1323.     if (OLMC[n].PinType == REGOUT && !OLMC[n].Clock) {
  1324.       AsmError(41, n+14);            /* register output */
  1325.       return(-1);                /* needs clock definition */
  1326.     }
  1327.  
  1328.     if (!OLMC[n].Clock) {            /* is clock unused? */
  1329.       l = (ToOLMC20RA10[n] + 1) * num_of_col;   /* yes, then clear */
  1330.                             /* the row */
  1331.       for (k = l; k < l + num_of_col; k++)
  1332.         Jedec.GALLogic[k] = 0;
  1333.     }
  1334.  
  1335.     if (OLMC[n].PinType == REGOUT) {
  1336.       if (!OLMC[n].ARST) {            /* is ARST unused? */
  1337.         l = (ToOLMC20RA10[n] + 2) * num_of_col;
  1338.  
  1339.         for (k = l; k < l + num_of_col; k++)
  1340.           Jedec.GALLogic[k] = 0;
  1341.       }
  1342.  
  1343.       if (!OLMC[n].APRST) {            /* is APRST unused? */
  1344.         l = (ToOLMC20RA10[n] + 3) * num_of_col;
  1345.  
  1346.         for (k = l; k < l + num_of_col; k++)
  1347.           Jedec.GALLogic[k] = 0;
  1348.       }
  1349.     }
  1350.  
  1351.       }
  1352.  
  1353.     }
  1354.  
  1355.   }
  1356.  
  1357.  
  1358.  
  1359.  
  1360.  
  1361. /* now the JEDEC structure is ready */
  1362. /* (be happy, it was a hard task) */
  1363.  
  1364.  
  1365.  
  1366.      asmreadyflag = 1;        /* set flag, so that we can see that  */
  1367.                     /* this file is assembled succesfully */
  1368.  
  1369.      FreeMem(fbuff, fsize);        /* free buffer of the source file */
  1370.  
  1371.  
  1372.  
  1373.      if (Config.AutoGAL == YES) {    /* redraw the symbolic GAL and print */
  1374.        SetGALType(gal_type);    /* the names of the GAL's pins */
  1375.  
  1376.        PrintPinNames();
  1377.      }
  1378.  
  1379.  
  1380.                 /*** now make the selected files ***/
  1381.  
  1382.          if (Config.GenJedec == YES)
  1383.        if (MyFileReq(AppStrings[MSG_WRITE_JED].as_Str, ".jed", !Config.AutoSave, SAVE))
  1384.          WriteJedecFile(gal_type);
  1385.  
  1386.      if (Config.GenFuse == YES)
  1387.        WriteFuseFile();
  1388.  
  1389.      if (Config.GenChip == YES)
  1390.        WriteChipFile();
  1391.  
  1392.      if (Config.GenPin == YES)
  1393.        WritePinFile();
  1394.  
  1395.       PrintText(AppStrings[MSG_FILE_ASM].as_Str, 1);
  1396.           return(0);                /* there was no error */
  1397.  
  1398.         }
  1399.         else {
  1400.       ErrorReq(3);                /* read error */
  1401.       FreeMem(fbuff,fsize);            /* can't load source file */
  1402.       return(-2);
  1403.     }
  1404.       }
  1405.       else {
  1406.     ErrorReq(2);                /* no more free memory */
  1407.     return(-2);
  1408.       }
  1409.     }
  1410.     else
  1411.       return(-1);            /* file requester canceled */
  1412.   }
  1413.   else
  1414.     return(-1);                /* assembler requester canceled */
  1415. }
  1416.  
  1417.  
  1418.  
  1419.  
  1420.  
  1421.  
  1422. /* set an AND (=0) in the fuse matrix
  1423.    row     :  row in which the AND should be set
  1424.    pinnum  :  pin which sould be ANDed
  1425.    negation:  0: pin without negation; 1: pin with negation sign ('/')
  1426. */
  1427. void SetAND(int row, int pinnum, int negation)
  1428. {
  1429. int column;
  1430.  
  1431.   switch (gal_type) {
  1432.     case GAL16V8:
  1433.       if (modus == MODE1)
  1434.     column = PinToFuse16Mode1[pinnum - 1];
  1435.       if (modus == MODE2)
  1436.     column = PinToFuse16Mode2[pinnum - 1];
  1437.       if (modus == MODE3)
  1438.     column = PinToFuse16Mode3[pinnum - 1];
  1439.       break;
  1440.  
  1441.     case GAL20V8:
  1442.       if (modus == MODE1)
  1443.         column  =  PinToFuse20Mode1[pinnum - 1];
  1444.       if (modus == MODE2)
  1445.     column  =  PinToFuse20Mode2[pinnum - 1];
  1446.       if (modus == MODE3)
  1447.     column  =  PinToFuse20Mode3[pinnum - 1];
  1448.       break;
  1449.  
  1450.     case GAL22V10:
  1451.       column  =  PinToFuse22V10[pinnum - 1];
  1452.       break;
  1453.  
  1454.     case GAL20RA10:
  1455.       column  =  PinToFuse20RA10[pinnum - 1];
  1456.       break;
  1457.   }
  1458.  
  1459.   Jedec.GALLogic[row * num_of_col + column + negation] = 0;
  1460.  
  1461. }
  1462.  
  1463.  
  1464.  
  1465.  
  1466. /* check whether actptr points to a pinname or not
  1467.    numofpins: number of the GAL's pins
  1468.    actptr:    pointer to the first character of the pinname
  1469.    actPin.p_Pin: number of pin or NC_PIN; 0: no pin
  1470.    actPin.p_Neg: pinname with '/' = 1;  without '/' = 0
  1471. */
  1472. void IsPinName(UBYTE *pinnames, int numofpins)
  1473. {
  1474. int    i, k, n;
  1475. UBYTE    *oldactptr;
  1476.  
  1477.   actPin.p_Neg = 0;            /* install structure for pin */
  1478.   actPin.p_Pin = 0;
  1479.  
  1480.   if (IsNEG(*actptr)) {            /* negation? */
  1481.     actptr++;
  1482.     actPin.p_Neg = 1;
  1483.   }
  1484.  
  1485.   n = 0;                /* get length of pin name */
  1486.  
  1487.   oldactptr = actptr;
  1488.  
  1489.   while (isalpha(*actptr) || isdigit(*actptr)) {
  1490.     actptr++;
  1491.     n++;
  1492.   }
  1493.  
  1494.   if (n)
  1495.     if ((n == 2 ) && !strncmp((char *)oldactptr, "NC", (size_t)2))  /*NC ?*/
  1496.       actPin.p_Pin = NC_PIN;                /*yes, then NC pin*/
  1497.   else
  1498.     for (k = 0; k < numofpins; k++) {        /* examine list of pin names */
  1499.       i = 0;
  1500.  
  1501.       if (IsNEG(*(pinnames+k*10)))
  1502.         i = 1;
  1503.  
  1504.       if (n == strlen((char *)(pinnames+k*10+i)))    /* string sizes equal?*/       
  1505.         if (!(strncmp((char *)oldactptr, (char *)(pinnames+k*10+i) , (size_t)n))) {
  1506.       actPin.p_Pin = k + 1;             /*yes, then compare*/
  1507.       break;                 /*this strings*/
  1508.         }
  1509.     }
  1510. }
  1511.  
  1512.  
  1513.  
  1514.  
  1515. /* check whether actptr points to a AR or SP
  1516.    ptr:    pointer to the first character of the name
  1517. result:
  1518.    actPin.p_Pin: 23: AR, 24: SP, 0: no AR, SP
  1519.    actPin.p_Neg: pinname with '/' = 1;  without '/' = 0
  1520. */
  1521. void Is_AR_SP(UBYTE *ptr)
  1522. {
  1523. int    n;
  1524. UBYTE    *oldptr;
  1525.  
  1526.   actPin.p_Neg = 0;            /* install structure for pin */
  1527.   actPin.p_Pin = 0;
  1528.  
  1529.   if (IsNEG(*ptr)) {            /* negation? */
  1530.     ptr++;
  1531.     actPin.p_Neg = 1;
  1532.   }
  1533.  
  1534.   n = 0;                /* get length of pin name */
  1535.  
  1536.   oldptr = ptr;
  1537.  
  1538.   while (isalpha(*ptr) || isdigit(*ptr)) {
  1539.     ptr++;
  1540.     n++;
  1541.   }
  1542.             /* assign AR to "OLMC 11" ("pin 24") and */
  1543.   if (n) {        /* assign SP to "OLMC 12" ("pin 25")     */
  1544.     if ((n == 2 ) && !strncmp((char *)oldptr, "AR", (size_t)2))
  1545.       actPin.p_Pin = DUMMY_OLMC11;
  1546.  
  1547.     if ((n == 2 ) && !strncmp((char *)oldptr, "SP", (size_t)2))
  1548.       actPin.p_Pin = DUMMY_OLMC12;
  1549.   }
  1550. }
  1551.  
  1552.  
  1553.  
  1554.  
  1555.  
  1556. /* search the next character which is no comment, space, TAB, LF
  1557.   result 0: character found, actptr points on this
  1558.          1: no character found
  1559. */
  1560. int GetNextChar(void)
  1561. {
  1562.  
  1563.   for(;;) {
  1564.     switch (*actptr) {
  1565.       case 0x0A:                /* LineFeed */
  1566.         actptr++;
  1567.         linenum++;
  1568.         break;
  1569.  
  1570.       case ' ':                    /* space */
  1571.       case 0x09:                /* TAB */
  1572.         actptr++;
  1573.         break;
  1574.  
  1575.       case ';':                    /* comment found? */
  1576.     if (GetNextLine())            /* then skip rest of line */
  1577.       return(0);
  1578.     break;
  1579.  
  1580.      default:
  1581.        if ((*actptr > ' ') && (*actptr <= '~'))    /* was there a character? */
  1582.      return(0);
  1583.        else
  1584.      actptr++;
  1585.     }
  1586.  
  1587.     if (actptr > buffend)            /* end of file? */
  1588.       return(1);
  1589.   }
  1590. }
  1591.  
  1592.  
  1593.  
  1594. /* get pointer to next line
  1595.   result:  0: line found,  actptr points to this line
  1596.        1: end of file reached
  1597. */
  1598. int GetNextLine(void)
  1599. {
  1600.   for(;;) {
  1601.     if (*actptr == 0x0A) {
  1602.       actptr++;
  1603.       linenum++;
  1604.       return(0);
  1605.     }
  1606.  
  1607.     if (actptr > buffend)            /* end of file? */
  1608.       return(1);
  1609.  
  1610.     actptr++;
  1611.   }
  1612. }
  1613.  
  1614.  
  1615.  
  1616.  
  1617. /* print error message of the GAL-assembler and free
  1618.    the memory of the file buffer
  1619.  parameter: errornum: number of error to print
  1620.         pinnum = 0: print "Error in line linenum: of error
  1621.            > 0: print "Pin pinnum:"
  1622. */
  1623. void AsmError(int errornum, int pinnum)
  1624. {
  1625. static char pin[] = "Pin xx:";        /* this string is not localized  */
  1626.                     /* since "pin" is a well known   */
  1627.                     /* word for electronic freaks (or */
  1628.                     /* isn't it?) */
  1629.   FreeMem(fbuff,fsize);
  1630.  
  1631.   MyRequest(ERR_REQ, AppStrings[MSG_ERR_ASM].as_Str);
  1632.  
  1633.   if (!pinnum)
  1634.     PrintErrorLine(linenum);
  1635.   else {
  1636.     sprintf(&pin[4], "%2d", pinnum);
  1637.     pin[6] = ':';
  1638.     PrintText(pin, 1);
  1639.   }
  1640.  
  1641.   switch (errornum) {
  1642.     case  1:
  1643.       PrintText(AppStrings[MSG_ERR_ASM1].as_Str, 1);
  1644.       break;
  1645.  
  1646.     case  2:
  1647.       PrintText(AppStrings[MSG_ERR_ASM2].as_Str, 1);
  1648.       break;
  1649.  
  1650.     case  3:
  1651.       PrintText(AppStrings[MSG_ERR_ASM3].as_Str, 1);
  1652.       break;
  1653.  
  1654.     case  4:
  1655.       PrintText(AppStrings[MSG_ERR_ASM4].as_Str, 1);
  1656.       break;
  1657.  
  1658.     case  5:
  1659.       PrintText(AppStrings[MSG_ERR_ASM5].as_Str, 1);
  1660.       break;
  1661.  
  1662.     case  6:
  1663.       PrintText(AppStrings[MSG_ERR_ASM6].as_Str, 1);
  1664.       break;
  1665.  
  1666.     case  7:
  1667.       PrintText(AppStrings[MSG_ERR_ASM7].as_Str, 1);
  1668.       break;
  1669.  
  1670.     case  8:
  1671.       PrintText(AppStrings[MSG_ERR_ASM8].as_Str, 1);
  1672.       break;
  1673.  
  1674.     case  9:
  1675.       PrintText(AppStrings[MSG_ERR_ASM9].as_Str, 1);
  1676.       break;
  1677.  
  1678.     case 10:
  1679.       PrintText(AppStrings[MSG_ERR_ASM10].as_Str, 1);
  1680.       break;
  1681.  
  1682.     case 11:
  1683.       PrintText(AppStrings[MSG_ERR_ASM11].as_Str, 1);
  1684.       break;
  1685.  
  1686.     case 12:
  1687.       PrintText(AppStrings[MSG_ERR_ASM12].as_Str, 1);
  1688.       break;
  1689.  
  1690.     case 13:
  1691.       PrintText(AppStrings[MSG_ERR_ASM13].as_Str, 1);
  1692.       break;
  1693.  
  1694.     case 14:
  1695.       PrintText(AppStrings[MSG_ERR_ASM14].as_Str, 1);
  1696.       break;
  1697.  
  1698.     case 15:
  1699.       PrintText(AppStrings[MSG_ERR_ASM15].as_Str, 1);
  1700.       break;
  1701.  
  1702.     case 16:
  1703.       PrintText(AppStrings[MSG_ERR_ASM16].as_Str, 1);
  1704.       break;
  1705.  
  1706.     case 17:
  1707.       PrintText(AppStrings[MSG_ERR_ASM17].as_Str, 1);
  1708.       break;
  1709.  
  1710.     case 18:
  1711.       PrintText(AppStrings[MSG_ERR_ASM18].as_Str, 1);
  1712.       break;
  1713.  
  1714.     case 19:
  1715.       PrintText(AppStrings[MSG_ERR_ASM19].as_Str, 1);
  1716.       break;
  1717.  
  1718.     case 20:
  1719.       PrintText(AppStrings[MSG_ERR_ASM20].as_Str, 1);
  1720.       break;
  1721.  
  1722.     case 21:
  1723.       PrintText(AppStrings[MSG_ERR_ASM21].as_Str, 1);
  1724.       break;
  1725.  
  1726.     case 22:
  1727.       PrintText(AppStrings[MSG_ERR_ASM22].as_Str, 1);
  1728.       break;
  1729.  
  1730.     case 23:
  1731.       PrintText(AppStrings[MSG_ERR_ASM23].as_Str, 1);
  1732.       break;
  1733.  
  1734.     case 24:
  1735.       PrintText(AppStrings[MSG_ERR_ASM24].as_Str, 1);
  1736.       break;
  1737.  
  1738.     case 25:
  1739.       PrintText(AppStrings[MSG_ERR_ASM25].as_Str, 1);
  1740.       break;
  1741.  
  1742.     case 26:
  1743.       PrintText(AppStrings[MSG_ERR_ASM26].as_Str, 1);
  1744.       break;
  1745.  
  1746.     case 27:
  1747.       PrintText(AppStrings[MSG_ERR_ASM27].as_Str, 1);
  1748.       break;
  1749.  
  1750.     case 28:
  1751.       PrintText(AppStrings[MSG_ERR_ASM28].as_Str, 1);
  1752.       break;
  1753.  
  1754.     case 29:
  1755.       PrintText(AppStrings[MSG_ERR_ASM29].as_Str, 1);
  1756.       break;
  1757.  
  1758.     case 30:
  1759.       PrintText(AppStrings[MSG_ERR_ASM30].as_Str, 1);
  1760.       break;
  1761.  
  1762.     case 31:
  1763.       PrintText(AppStrings[MSG_ERR_ASM31].as_Str, 1);
  1764.       break;
  1765.  
  1766.     case 32:
  1767.       PrintText(AppStrings[MSG_ERR_ASM32].as_Str, 1);
  1768.       break;
  1769.  
  1770.     case 33:
  1771.       PrintText(AppStrings[MSG_ERR_ASM33].as_Str, 1);
  1772.       break;
  1773.  
  1774.     case 34:
  1775.       PrintText(AppStrings[MSG_ERR_ASM34].as_Str, 1);
  1776.       break;
  1777.  
  1778.     case 35:
  1779.       PrintText(AppStrings[MSG_ERR_ASM35].as_Str, 1);
  1780.       break;
  1781.  
  1782.     case 36:
  1783.       PrintText(AppStrings[MSG_ERR_ASM36].as_Str, 1);
  1784.       break;
  1785.  
  1786.     case 37:
  1787.       PrintText(AppStrings[MSG_ERR_ASM37].as_Str, 1);
  1788.       break;
  1789.  
  1790.     case 38:
  1791.       PrintText(AppStrings[MSG_ERR_ASM38].as_Str, 1);
  1792.       break;
  1793.  
  1794.     case 39:
  1795.       PrintText(AppStrings[MSG_ERR_ASM39].as_Str, 1);
  1796.       break;
  1797.  
  1798.     case 40:
  1799.       PrintText(AppStrings[MSG_ERR_ASM40].as_Str, 1);
  1800.       break;
  1801.  
  1802.     case 41:
  1803.       PrintText(AppStrings[MSG_ERR_ASM41].as_Str, 1);
  1804.       break;
  1805.  
  1806.     case 42:
  1807.       PrintText(AppStrings[MSG_ERR_ASM42].as_Str, 1);
  1808.       break;
  1809.  
  1810.     case 43:
  1811.       PrintText(AppStrings[MSG_ERR_ASM43].as_Str, 1);
  1812.       break;
  1813.  
  1814.     case 44:
  1815.       PrintText(AppStrings[MSG_ERR_ASM44].as_Str, 1);
  1816.       break;
  1817.  
  1818.     case 45:
  1819.       PrintText(AppStrings[MSG_ERR_ASM45].as_Str, 1);
  1820.       break;
  1821.  
  1822.     case 46:
  1823.       PrintText(AppStrings[MSG_ERR_ASM46].as_Str, 1);
  1824.       break;
  1825.  
  1826.     case 47:
  1827.       PrintText(AppStrings[MSG_ERR_ASM47].as_Str, 1);
  1828.       break;
  1829.  
  1830.     case 48:
  1831.       PrintText(AppStrings[MSG_ERR_ASM48].as_Str, 1);
  1832.       break;
  1833.   }
  1834.  
  1835.  
  1836.  
  1837.  
  1838.  
  1839.  
  1840. /********************************************************/
  1841. /* the following routines are for the creation of the     */
  1842. /* documentation files                    */
  1843. /********************************************************/
  1844.  
  1845.  
  1846. /* make chip file */
  1847. void WriteChipFile(void)
  1848. {
  1849. extern    char    path;
  1850. FILE    *fp;
  1851. int    n;
  1852.  
  1853.    if (MyFileReq(AppStrings[MSG_WRITE_CHIP].as_Str, ".chp", !Config.AutoSave, SAVE)) {
  1854.  
  1855.      PrintText(AppStrings[MSG_WRITING_CHIP].as_Str, 1);
  1856.  
  1857.      if (fp = fopen(&path, (char *)"w")) {
  1858.  
  1859.        fprintf(fp, "\n\n");
  1860.  
  1861.        WriteSpaces(fp, 31);
  1862.  
  1863.        if (gal_type == GAL16V8)
  1864.      fprintf(fp, " GAL16V8\n\n");
  1865.  
  1866.        if (gal_type == GAL20V8)
  1867.      fprintf(fp, " GAL20V8\n\n");
  1868.  
  1869.        if (gal_type == GAL22V10)
  1870.      fprintf(fp, " GAL22V10\n\n");
  1871.  
  1872.        if (gal_type == GAL20RA10)
  1873.      fprintf(fp, "GAL20RA10\n\n");
  1874.  
  1875.  
  1876.        WriteSpaces(fp, 26);
  1877.  
  1878.        fprintf(fp,"-------\\___/-------\n");
  1879.  
  1880.        for (n = 0; n < num_of_pins/2; n++) {
  1881.  
  1882.      WriteSpaces(fp, 25 - (int)strlen((char *)(pinnames+n*10)));
  1883.  
  1884.      fprintf(fp,"%s | %2d           %2d | %s\n", pinnames+n*10, n+1, num_of_pins-n, pinnames+(num_of_pins-n-1)*10);
  1885.  
  1886.      if (n < num_of_pins/2 - 1) {
  1887.        WriteSpaces(fp, 26);
  1888.  
  1889.        fprintf(fp, "|                 |\n");
  1890.       }
  1891.     }
  1892.  
  1893.        WriteSpaces(fp, 26);
  1894.  
  1895.        fprintf(fp, "-------------------\n");
  1896.  
  1897.        if (fclose(fp) == EOF) {
  1898.      PrintText(AppStrings[MSG_ERROR].as_Str, 0);
  1899.  
  1900.          ErrorReq(8);            /* can't close file */
  1901.  
  1902.      return;
  1903.     }
  1904.      }
  1905.      else {
  1906.        PrintText(AppStrings[MSG_ERROR].as_Str, 0);
  1907.  
  1908.        ErrorReq(13);
  1909.  
  1910.        return;
  1911.      }
  1912.  
  1913.      PrintText(AppStrings[MSG_LOWER_OK].as_Str, 0);
  1914.    }
  1915. }
  1916.  
  1917.  
  1918.  
  1919.  
  1920.  
  1921. /* generate the pin filee*/
  1922. void WritePinFile(void)
  1923. {
  1924. extern    char    path;
  1925. FILE    *fp;
  1926. int    k, n, flag;
  1927.  
  1928.  
  1929.    if (MyFileReq(AppStrings[MSG_WRITE_PIN].as_Str, ".pin", !Config.AutoSave, SAVE)) {
  1930.  
  1931.      PrintText(AppStrings[MSG_WRITING_PIN].as_Str, 1);
  1932.  
  1933.      if (fp = fopen(&path, (char *)"w")) {
  1934.        fprintf(fp, "\n\n");
  1935.  
  1936.        fprintf(fp, " Pin # | Name     | Pin Type\n");
  1937.  
  1938.        fprintf(fp, "-----------------------------\n");
  1939.  
  1940.        for (n = 1; n <= num_of_pins; n++) {
  1941.      fprintf(fp,"  %2d   | ",n);
  1942.  
  1943.      fprintf(fp,"%s",pinnames+(n-1)*10);
  1944.  
  1945.      WriteSpaces(fp, 9-(int)strlen((char *)(pinnames+(n-1)*10)));
  1946.  
  1947.      flag = 0;
  1948.  
  1949.      if (n == num_of_pins/2) {
  1950.        fprintf(fp,"| GND\n");
  1951.        flag = 1;
  1952.      }
  1953.  
  1954.      if (n == num_of_pins) {
  1955.        fprintf(fp,"| VCC\n\n");
  1956.        flag = 1;
  1957.      }
  1958.  
  1959.  
  1960.      if (gal_type == GAL16V8 || gal_type == GAL20V8) {
  1961.  
  1962.        if (modus == MODE3 && n == 1) {
  1963.          fprintf(fp, "| Clock\n");
  1964.          flag = 1;
  1965.        }
  1966.  
  1967.        if (modus == MODE3) {
  1968.          if (gal_type == GAL16V8 && n == 11) {
  1969.            fprintf(fp, "| /OE\n");
  1970.            flag = 1;
  1971.          }
  1972.  
  1973.          if (gal_type == GAL20V8 && n == 13) {
  1974.            fprintf(fp, "| /OE\n");
  1975.            flag = 1;
  1976.          }
  1977.        }
  1978.      }
  1979.  
  1980.      if (gal_type == GAL22V10 && n == 1) {
  1981.        fprintf(fp, "| Clock/Input\n");
  1982.        flag = 1;
  1983.      }
  1984.  
  1985.                             /* OLMC pin?*/
  1986.  
  1987.      if ( (gal_type == GAL16V8   && n >= 12 && n <= 19) ||
  1988.           (gal_type == GAL20V8   && n >= 15 && n <= 22) ||
  1989.           (gal_type == GAL20RA10 && n >= 14 && n <= 23) ||
  1990.           (gal_type == GAL22V10  && n >= 14 && n <= 23) ) {
  1991.  
  1992.  
  1993.        if (gal_type == GAL16V8)
  1994.          k = n - 12;
  1995.        else
  1996.          if (gal_type == GAL20V8)
  1997.            k = n - 15;
  1998.          else
  1999.            k = n - 14;
  2000.  
  2001.        if (OLMC[k].PinType != INPUT)
  2002.          if (OLMC[k].PinType)
  2003.            fprintf(fp,"| Output\n");
  2004.          else
  2005.            fprintf(fp,"| NC\n");
  2006.        else
  2007.          fprintf(fp,"| Input\n");
  2008.      }
  2009.      else {
  2010.        if (!flag) 
  2011.          fprintf(fp,"| Input\n");
  2012.      }
  2013.        }
  2014.  
  2015.        if (fclose(fp) == EOF) {
  2016.      PrintText(AppStrings[MSG_ERROR].as_Str, 0);
  2017.      ErrorReq(8);                /* can't close file */
  2018.      return;
  2019.     }
  2020.      }
  2021.      else {
  2022.        PrintText(AppStrings[MSG_ERROR].as_Str, 0);
  2023.        ErrorReq(13);
  2024.        return;
  2025.      }
  2026.      PrintText(AppStrings[MSG_LOWER_OK].as_Str, 0);
  2027.    }
  2028. }
  2029.  
  2030.  
  2031.  
  2032. /* WriteRow: write a row of an OLMC to fp
  2033.    Prameter: row: number of row which should be written
  2034.          fp:  pointer to file handle
  2035.    global variable: row_of_col
  2036. */
  2037. void WriteRow(FILE *fp, int row)
  2038. {
  2039. int col;
  2040.  
  2041.  
  2042.   fprintf(fp, "\n%3d ", row);            /* print row number */
  2043.  
  2044.   for (col = 0; col < num_of_col; col++) {    /* print fuses of */
  2045.     if (!( (col) % 4) )                /* a row   */
  2046.       fprintf(fp, " ");
  2047.  
  2048.     if (Jedec.GALLogic[row * num_of_col + col])
  2049.       fprintf(fp, "-");
  2050.     else
  2051.       fprintf(fp, "x");
  2052.   }
  2053.  
  2054. }
  2055.  
  2056.  
  2057.  
  2058.  
  2059. /* generate fuse file */
  2060. void WriteFuseFile(void)
  2061. {
  2062. extern    char    path;
  2063. FILE    *fp;
  2064. int    row, pin, n, numofOLMCs, numofrows, olmc;
  2065.  
  2066.  
  2067.   if (MyFileReq(AppStrings[MSG_WRITE_FUSE].as_Str, ".fus", !Config.AutoSave, SAVE)) {
  2068.     PrintText(AppStrings[MSG_WRITING_FUSE].as_Str, 1);
  2069.  
  2070.     if (fp = fopen(&path,(char *)"w")) {
  2071.       if (gal_type == GAL16V8) {
  2072.         pin = 19;
  2073.     numofOLMCs = 8;
  2074.       }
  2075.       else
  2076.         if (gal_type == GAL20V8) {
  2077.       pin = 22;
  2078.       numofOLMCs = 8;
  2079.     }
  2080.         else {                    /* 22V10, 20RA10 */
  2081.       pin = 23;
  2082.       numofOLMCs = 10;
  2083.     }
  2084.  
  2085.  
  2086.  
  2087.       row = 0;
  2088.  
  2089.       for (olmc = 0; olmc < numofOLMCs; olmc++) {
  2090.  
  2091.     if (gal_type == GAL22V10 && olmc == 0) {  /* AR when 22V10 */
  2092.       fprintf(fp, "\n\nAR");
  2093.       WriteRow(fp, row);
  2094.       row++;
  2095.     }
  2096.  
  2097.     if (gal_type == GAL22V10)        /* get number of rows */
  2098.       numofrows = OLMCSize22V10[olmc];    /* of an OLMC */
  2099.     else
  2100.       numofrows = 8;
  2101.  
  2102.  
  2103.  
  2104.     fprintf(fp, "\n\nPin %2d = ", pin);        /* print pin */
  2105.  
  2106.     fprintf(fp, "%s", pinnames + (pin - 1)*10);
  2107.  
  2108.     WriteSpaces(fp, 13-(int)strlen((char *)(pinnames+(pin-1)*10)));
  2109.  
  2110.  
  2111.     if (gal_type == GAL16V8)
  2112.       fprintf(fp, "XOR = %1d   AC1 = %1d", Jedec.GALXOR[19 - pin],
  2113.                            Jedec.GALAC1[19 - pin]);
  2114.     else
  2115.       if (gal_type == GAL20V8)
  2116.         fprintf(fp, "XOR = %1d   AC1 = %1d", Jedec.GALXOR[22 - pin],
  2117.                              Jedec.GALAC1[22 - pin]);
  2118.       else
  2119.         if (gal_type == GAL22V10)
  2120.           fprintf(fp, "S0 = %1d   S1 = %1d", Jedec.GALXOR[23 - pin],
  2121.                               Jedec.GALAC1[23 - pin]);
  2122.         else
  2123.           if (gal_type == GAL20RA10)
  2124.             fprintf(fp, "S0 = %1d", Jedec.GALXOR[23 - pin]);
  2125.  
  2126.  
  2127.  
  2128.     for (n = 0; n < numofrows; n++) {    /* print all fuses of an OLMC */
  2129.       WriteRow(fp, row);
  2130.       row++;
  2131.     }
  2132.  
  2133.  
  2134.     if (gal_type == GAL22V10 && olmc == 9) {  /* SP when 22V10 */
  2135.       fprintf(fp, "\n\nSP");
  2136.       WriteRow(fp, row);
  2137.     }
  2138.  
  2139.     pin--;
  2140.       }
  2141.  
  2142.  
  2143.       fprintf(fp, "\n\n");
  2144.  
  2145.       if (fclose(fp) == EOF) {
  2146.         PrintText(AppStrings[MSG_ERROR].as_Str, 0);
  2147.         ErrorReq(8);                /* can't close file */
  2148.         return;
  2149.       }
  2150.     }
  2151.     else {
  2152.       PrintText(AppStrings[MSG_ERROR].as_Str, 0);
  2153.       ErrorReq(13);
  2154.       return;
  2155.     }
  2156.  
  2157.     PrintText(AppStrings[MSG_LOWER_OK].as_Str, 0);
  2158.   }
  2159. }
  2160.  
  2161.  
  2162.  
  2163.  
  2164.  
  2165. /* write "numof" spaces
  2166. */
  2167. void WriteSpaces(FILE *fp, int numof)
  2168. {
  2169. int n;
  2170.  
  2171.  for (n = 0; n < numof; n++)
  2172.    fprintf(fp, " ");
  2173.  
  2174. }
  2175.  
  2176.  
  2177.  
  2178.  
  2179. /* checks whether chr is a OR sign or not
  2180. ** result: 1: chr is a OR
  2181. **        0: chr is no OR
  2182. */
  2183. int IsOR(char chr)
  2184. {
  2185.   if (chr == '+' || chr == '#')
  2186.     return(1);
  2187.   else
  2188.     return(0);
  2189. }
  2190.  
  2191.  
  2192.  
  2193. /* checks whether chr is a AND sign or not
  2194. ** result: 1: chr is a AND
  2195. **        0: chr is no AND
  2196. */
  2197. int IsAND(char chr)
  2198. {
  2199.   if (chr == '*' || chr == '&')
  2200.     return(1);
  2201.   else
  2202.     return(0);
  2203. }
  2204.  
  2205.  
  2206. /* checks whether chr is a negation sign or not
  2207. ** result: 1: chr is a negation
  2208. **        0: chr is no negation
  2209. */
  2210. int IsNEG(char chr)
  2211. {
  2212.   if (chr == '/' || chr == '!')
  2213.     return(1);
  2214.   else
  2215.     return(0);
  2216. }
  2217.  
  2218.  
  2219.  
  2220.