[comp.sys.nsc.32k] intelhex

ian@sibyl.eleceng.ua.oz.au (05/31/90)

Someone (Dave Rand?) Posted a little program "intelhex.c". I don't know what
this generates, but it certainly isn't what our prom burner calls intel-hex
format. Here is a program which does generate a format acceptable to our prom
burner. The "unsigned" mightn't be necessary but this program is firmly in the
"quick hack" category so I haven't bothered to check.

----------------------------cut here--------------------------------------
#include <stdio.h>

main()
{
  int i, nbytes = 0;
  unsigned char bytes[32];
  int offset = 0;
  do
    {
      int ret;
      int checksum;
      unsigned char type;
      ret = fread(bytes, 1, 32, stdin);
      if (ret == 0)
	{
	  type = 1;
	  offset -= nbytes;
	}
      else
	type = 0;
      nbytes = ret;
      checksum = nbytes;
      checksum += (offset & 0xff);
      checksum += ((offset >> 8) & 0xff);
      checksum += type;
      printf(":%2.2X%4.4X%2.2X", nbytes, offset, type);
      offset += nbytes;
      for (i = 0; i < nbytes; i++)
	{
	  printf("%2.2X", bytes[i]);
	  checksum += bytes[i];
	}
      printf("%2.2X\n", ((-checksum) & 0xff));
    }
  while (nbytes != 0);
  exit (0);
}
------------------------------------end-----------------------------------

Ian Dall