home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / c / mot2intel.c < prev    next >
Internet Message Format  |  1994-03-04  |  1KB

  1. From: rochester!pt.cs.cmu.edu!cadre!pitt!hoffman (Bob Hoffman)
  2. Newsgroups: comp.sys.intel,misc.wanted,comp.misc,comp.sources.wanted
  3. Subject: Re: Motorola S19 Format
  4. Date: 23 Mar 89 16:53:13 GMT
  5. Reply-To: hoffman@vax.cs.pittsburgh.edu (Bob Hoffman)
  6.  
  7. wfp5p@euclid.acc.Virginia.EDU (William F. Pemberton) writes:
  8. >I am looking for a program to convert from Motorola S19 Hex format to Intel
  9. >Hex format.
  10.  
  11. Here it is, enjoy!
  12.  
  13.     ---Bob.
  14.  
  15. /*
  16.  * Convert Motorola S1/S9 hex files to Intel hex.
  17.  *
  18.  * R. B. Hoffman, July 1985.
  19.  *
  20.  * usage:   hexcvt < motorola-file > intel-file
  21.  */
  22.  
  23. #include <stdio.h>
  24.  
  25. char line[256];
  26.  
  27. main() {
  28.     int bc, val, cksm, fcksm, i;
  29.     long laddr;
  30.  
  31.     while (fgets(line, 256, stdin) != NULL) {
  32.         if (line[0] != 'S')
  33.             continue;
  34.         if (line[1] == '9')
  35.             break;
  36.         if (line[1] != '1')
  37.             continue;
  38.         sscanf(&line[2],"%2x",&bc);
  39.         sscanf(&line[4],"%4x",&laddr);
  40.         printf(":%02X%04X00", bc-3, laddr);
  41.         cksm = bc + (laddr & 0xFF) + ((laddr >> 8) & 0xFF);
  42.         for (i=0; i<(bc-3); i++) {
  43.             sscanf(&line[i*2 + 8], "%2x", &val);
  44.             cksm += val;
  45.             printf("%02X", val);
  46.         }
  47.         sscanf(&line[(bc-3)*2 + 8], "%2x", &fcksm);
  48.         cksm = ~cksm & 0xFF;
  49.         if (cksm != fcksm)
  50.             fprintf(stderr,"cksm=%02x, fcksm=%02x\n", cksm, fcksm);
  51.         printf("%02X\n", (cksm+4) & 0xFF);
  52.     }
  53.     printf(":0000000000\n");
  54. }
  55. -- 
  56. Bob Hoffman, N3CVL       {allegra, bellcore, cadre, idis, psuvax1}!pitt!hoffman
  57. Pitt Computer Science    hoffman@vax.cs.pittsburgh.edu
  58.