home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1402 < prev    next >
Internet Message Format  |  1990-12-28  |  2KB

  1. From: ian@sibyl.eleceng.ua.oz.au
  2. Newsgroups: alt.sources
  3. Subject: [comp.sys.nsc.32k] intelhex
  4. Message-ID: <1990Jun1.210955.26308@math.lsa.umich.edu>
  5. Date: 1 Jun 90 21:09:55 GMT
  6.  
  7. Archive-name: intelhex/31-May-90
  8. Original-posting-by: ian@sibyl.eleceng.ua.oz.au
  9. Original-subject: intelhex
  10. Reposted-by: emv@math.lsa.umich.edu (Edward Vielmetti)
  11.  
  12. [Reposted from comp.sys.nsc.32k.
  13. Comments on this service to emv@math.lsa.umich.edu (Edward Vielmetti).]
  14.  
  15. Someone (Dave Rand?) Posted a little program "intelhex.c". I don't know what
  16. this generates, but it certainly isn't what our prom burner calls intel-hex
  17. format. Here is a program which does generate a format acceptable to our prom
  18. burner. The "unsigned" mightn't be necessary but this program is firmly in the
  19. "quick hack" category so I haven't bothered to check.
  20.  
  21. ----------------------------cut here--------------------------------------
  22. #include <stdio.h>
  23.  
  24. main()
  25. {
  26.   int i, nbytes = 0;
  27.   unsigned char bytes[32];
  28.   int offset = 0;
  29.   do
  30.     {
  31.       int ret;
  32.       int checksum;
  33.       unsigned char type;
  34.       ret = fread(bytes, 1, 32, stdin);
  35.       if (ret == 0)
  36.     {
  37.       type = 1;
  38.       offset -= nbytes;
  39.     }
  40.       else
  41.     type = 0;
  42.       nbytes = ret;
  43.       checksum = nbytes;
  44.       checksum += (offset & 0xff);
  45.       checksum += ((offset >> 8) & 0xff);
  46.       checksum += type;
  47.       printf(":%2.2X%4.4X%2.2X", nbytes, offset, type);
  48.       offset += nbytes;
  49.       for (i = 0; i < nbytes; i++)
  50.     {
  51.       printf("%2.2X", bytes[i]);
  52.       checksum += bytes[i];
  53.     }
  54.       printf("%2.2X\n", ((-checksum) & 0xff));
  55.     }
  56.   while (nbytes != 0);
  57.   exit (0);
  58. }
  59. ------------------------------------end-----------------------------------
  60.  
  61. Ian Dall
  62.