home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 148_01 / a99.c < prev    next >
Text File  |  1987-09-28  |  5KB  |  224 lines

  1. /*
  2.     9900 Cross-Assembler  v. 1.0
  3.  
  4.     January, 1985
  5.  
  6.     Original 6800 version Copyright (c) 1980 William C. Colley, III.
  7.     Modified for the TMS9900/99105  Series by Alexander Cameron.
  8.  
  9. File:    a99.c
  10.  
  11. It all begins here.
  12. */
  13.  
  14. /*  Get globals:  */
  15.  
  16. #include "a99.gbl"
  17.  
  18. /*  The assembler starts here.  */
  19.  
  20. main(argc,argv)
  21. int argc;
  22. char *argv[];
  23. {
  24.     int n, m;
  25.     unsigned u;
  26.     puts("\n----------------------------------------------------\n");
  27.     puts("TMS9900 / TMS99105 Cross-Assembler  v. 1.0\n");
  28.     puts("Modified from William C. Colley, III's M6800 version\n");
  29.     puts("by Alexander Cameron January, 1985\n");
  30.     puts("----------------------------------------------------\n\n");
  31.     setfiles(argc,argv);
  32.     sympoint = &symtbl;        /*  Initialize symbol table.    */
  33.     symend = symtbl[SYMBOLS].symname;
  34.     setmem(sympoint,(SYMBOLS * (SYMLEN + 2)),'\0');
  35.     ifsp = 0;            /*  Initialize if stack.    */
  36.     ifstack[ifsp] = 0xffff;
  37.     hxbytes = 0;            /*  Initialize hex generator.    */
  38.     flshhbf(0);
  39.     pc = errcount = 0;
  40.     pass = 1;
  41.     puts("Pass 1\n");
  42.     while (pass != 3)    /*  The actual assembly starts here.    */
  43.     {
  44.         errcode = ' ';
  45.         if (!getlin())
  46.         {
  47.             strcpy(linbuf,"\tEND\t\t;You forgot this!\n");
  48.             linptr = linbuf;
  49.             markerr('*');
  50.             ifstack[ifsp] = 0xffff;
  51.         }
  52.         asmline();        /*  Get binary from line.    */
  53.         if (pass > 1)
  54.         {
  55.             lineout();    /*  In pass 2, list line.    */
  56.             hexout();    /*  In pass 2, build hex file.    */
  57.         }
  58.         pc += nbytes;
  59.         if (pass == 0)    /*  This indicates end of pass 1.    */
  60.         {
  61.             pass = 2;
  62.             puts("Pass 2\n");
  63.             rewind();
  64.             ifsp = pc = errcount = 0;
  65.         }
  66.     }
  67.  
  68.         /*  print symbol table statistics  */
  69.  
  70.     u = (SYMBOLS - sortsym(NOSORT))*100;
  71.     u /= SYMBOLS;
  72.     printf("\nSymbol table use factor = %d%s\n",100-u,"%");
  73.  
  74.         /*  List number of errors.    */
  75.  
  76.     linptr = linbuf;
  77.     *linptr++ = '\n';
  78.     if (errcount == 0) strcpy(linptr,"No");
  79.     else
  80.     {
  81.         putdec(errcount,&linptr);
  82.         *linptr = '\0';
  83.     }
  84.     strcat(linbuf," error(s).\n");
  85.     puts(linbuf);
  86.     if (lstbuf.fd != CONO && lstbuf.fd != NOFILE)
  87.     {
  88.         putlin(linbuf,&lstbuf);
  89.         putchr('\f',&lstbuf);
  90.     }
  91.     if (lstbuf.fd != NOFILE)        /*  If needed, sort and list
  92.                         symbol table.        */
  93.     {
  94.         n = sortsym(SORT);
  95.         sympoint = symtbl;
  96.         while (n > 0)
  97.         {
  98.             linptr = linbuf;
  99.             for (m = 0; m < 4; m++)
  100.             {
  101.                 movmem(sympoint->symname,linptr,SYMLEN);
  102.                 linptr += 8;
  103.                 *linptr++ = ' ';
  104.                 *linptr++ = ' ';
  105.                 puthex4(sympoint->symvalu,&linptr);
  106.                 *linptr++ = ' ';
  107.                 *linptr++ = ' ';
  108.                 *linptr++ = ' ';
  109.                 *linptr++ = ' ';
  110.                 sympoint++;
  111.                 if (--n <= 0) break;
  112.             }
  113.             linptr -= 4;
  114.             *linptr++ = '\n';
  115.             *linptr = '\0';
  116.             putlin(linbuf,&lstbuf);
  117.         }
  118.         putchr(CPMEOF,&lstbuf);
  119.     }
  120.     flush(&lstbuf);
  121.     close(sorbuf.fd);
  122.     wipeout("\r");
  123. }
  124.  
  125. /*
  126. Function to set up the file structure.  Routine is called with
  127. the original argc and argv from main().
  128. */
  129.  
  130. setfiles(argc,argv)
  131. int argc;
  132. char *argv[];
  133. {
  134.     char sorfname[16],lstfname[16],hexfname[16], *tptr;
  135.     if (--argc == 0) wipeout("\nNo file info supplied.\n");
  136.     argv++;
  137.     sorbuf.fd = lstbuf.fd = hexbuf.fd = NOFILE;
  138.     lstbuf.pointr = lstbuf.space;
  139.     hexbuf.pointr = hexbuf.space;
  140.     sorfname[0] = curdrive + 'A';
  141.     sorfname[1] = ':';
  142.     sorfname[2] = '\0';
  143.     strcat(sorfname,*argv++);
  144.     for (tptr = sorfname; *tptr != '\0'; tptr++) if (*tptr == '.') *tptr = '\0';
  145.     strcpy(lstfname,sorfname);
  146.     strcpy(hexfname,lstfname);
  147.     strcat(sorfname,".A99");
  148.     strcat(lstfname,".L99");
  149.     strcat(hexfname,".H99");
  150.     if (--argc == 0) goto defsorf;
  151.     while (**argv != '\0')
  152.     {
  153.         switch (*(*argv)++)
  154.         {
  155.             case 'S':    switch (*(*argv)++)
  156.                     {
  157.                         case 'A':
  158.                         case 'B':
  159.                         case 'C':
  160.                         case 'D':    sorfname[0] = *(*argv - 1);
  161.  
  162.                         case '-':    if((sorbuf.fd = open(sorfname,0)) == -1)
  163.                                     wipeout("\nCan't open source.\n");
  164.                                 rewind();
  165.                                 break;
  166.  
  167.                         default:    goto badcomnd;
  168.                     }
  169.                     break;
  170.  
  171.             case 'L':    switch (*(*argv)++)
  172.                     {
  173.                         case 'A':
  174.                         case 'B':
  175.                         case 'C':
  176.                         case 'D':    lstfname[0] = *(*argv - 1);
  177.                         case '-':    if ((lstbuf.fd = creat(lstfname)) == -1)
  178.                                     wipeout("\nCan't open list.\n");
  179.                                 break;
  180.  
  181.                         case 'X':    lstbuf.fd = CONO;
  182.                                 break;
  183.  
  184.                         case 'Y':    lstbuf.fd = LST;
  185.                                 break;
  186.  
  187.                         default:    goto badcomnd;
  188.                     }
  189.                     break;
  190.  
  191.                     case 'H':    switch(*(*argv)++)
  192.                             {
  193.                                 case 'A':
  194.                                 case 'B':
  195.                                 case 'C':
  196.                                 case 'D': hexfname[0] = *(*argv - 1);
  197.                                 case '-': if (( hexbuf.fd = creat(hexfname)) == -1)
  198.                                         wipeout("\n Can't open hex.\n");
  199.                                       break;
  200.  
  201.                                 case 'X':    hexbuf.fd = CONO;
  202.                                 break;
  203.  
  204.                         case 'Y':    hexbuf.fd = LST;
  205.                                 break;
  206.  
  207.                         default:    goto badcomnd;
  208.                     }
  209.                     break;
  210.  
  211.             badcomnd:
  212.             default:    wipeout("\nIllegal command line.\n");
  213.         }
  214.     }
  215.     if (sorbuf.fd != NOFILE) return;
  216.  
  217.     defsorf:
  218.  
  219.     if ((sorbuf.fd = open(sorfname,0)) == -1) wipeout("\nCan't open source.\n");
  220.     rewind();
  221.     return;
  222. }
  223.  
  224.