home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / dev / cross / tms32010 / l320.c < prev    next >
C/C++ Source or Header  |  1992-09-02  |  3KB  |  127 lines

  1. /* TMS320 Intel hex linker release 1.0 */
  2.  
  3. #include <libraries/dosextens.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7.  
  8. void Copyright(void);
  9.  
  10. /* constants declaration */
  11.  
  12. #define MAXBUF 128
  13. #define MAXINBUF 6
  14. #define MAXOUTBUF 128
  15.  
  16. /* variables declaration */
  17.  
  18. char filein[MAXBUF], filelow[MAXBUF], filehigh[MAXBUF], addbuf[MAXINBUF];
  19. char databuf[MAXINBUF], lowbuf[MAXOUTBUF], highbuf[MAXOUTBUF], count[2];
  20. char *pointer, *low, *high, auxbuf[10];
  21. FILE *fi, *fl, *fh;
  22. unsigned long PC;
  23.  
  24. main(argc, argv)
  25.  
  26. int argc;
  27. char *argv[];
  28.  
  29. {
  30.  
  31. int i=1, lcheck, hcheck;
  32. BOOL start=TRUE;
  33. long data;
  34.  
  35.     Copyright();
  36.     if(argc==1) {
  37. badusage:    printf("Usage: %s filename [filename]\n",argv[0]);
  38.         exit(1);
  39.     }
  40.  
  41. /* insert options handling here */
  42.  
  43.     if(!(--argc))
  44.         goto badusage;
  45.     strcpy(filein,argv[i]);
  46.     strcpy(filelow,filein);
  47.     strtok(filelow,".obj");
  48.     strcpy(filehigh,filelow);
  49.     if(--argc)
  50.         strcpy(filelow,argv[++i]);
  51.     strcpy(filehigh,filelow);
  52.     strcat(filelow,".low");
  53.         strcat(filehigh,".high");
  54.         if(!strstr(filein,".obj"))
  55.             strcat(filein,".obj");
  56.     if(!(fi=fopen(filein,"r"))) {
  57.         printf("Can't open file %s for input\n",filein);
  58.         exit(1);
  59.     }
  60.     if(!(fl=fopen(filelow,"w"))) {
  61.         printf("Can't open file %s for output\n",filelow);
  62.         fclose(fi);
  63.         exit(1);
  64.     }
  65.     if(!(fh=fopen(filehigh,"w"))) {
  66.         printf("Can't open file %s for output\n",filehigh);
  67.         fclose(fi);
  68.         fclose(fl);
  69.         exit(1);
  70.     }
  71.     
  72.     i=0;
  73.     
  74.     while(1) {
  75.         if(!fgets(addbuf,sizeof(addbuf),fi)) 
  76.             break;
  77.         if(!fgets(databuf,sizeof(databuf),fi))
  78.             goto error;
  79. restart:    pointer=databuf;
  80.         data=strtol(addbuf,NULL,16);
  81.         if(start) {
  82.             PC=data;
  83.             hcheck=lcheck=PC/256+PC%256;
  84.             sprintf(lowbuf,":10%04X00",PC);
  85.             strcpy(highbuf,lowbuf);
  86.             low=lowbuf+9;
  87.             high=highbuf+9;
  88.             start=FALSE;
  89.         }
  90.         else if((PC!=data)||(i==16)) {
  91.             lcheck+=i;
  92.                 hcheck+=i;
  93.                 sprintf(count,"%02X",i);
  94.                 lowbuf[1]=highbuf[1]=count[0];
  95.                 lowbuf[2]=highbuf[2]=count[1];
  96.                 pointer=auxbuf;
  97.                 sprintf(pointer,"%08X\n\0",-hcheck);
  98.                 sprintf(high,pointer+6);
  99.                 sprintf(pointer,"%08X\n\0",-lcheck);
  100.                 sprintf(low,pointer+6);
  101.                 i=lcheck=hcheck=0;
  102.                 start=TRUE;
  103.                 if((fputs(lowbuf,fl)==-1)||(fputs(highbuf,fh)==-1))
  104.                     goto error;
  105.                 goto restart;
  106.             }
  107.         data=strtol(databuf,NULL,16);
  108.         hcheck+=data/256;
  109.         lcheck+=data%256;
  110.         *high++=*pointer++;
  111.         *high++=*pointer++;
  112.         *low++=*pointer++;
  113.         *low++=*pointer++;
  114.         i++;
  115.         PC++;
  116.     }
  117.     fputs(":00000001FF\n",fl);
  118.     fputs(":00000001FF\n",fh);
  119. error:    fclose(fi);
  120.     fclose(fl);
  121.     fclose(fh);
  122. }
  123.  
  124. void Copyright(void)
  125. {
  126.     puts("TMS32010 Intel Hex linker (C)1994 by SRC");
  127. }