Path: utzoo!attcan!uunet!samsung!brutus.cs.uiuc.edu!wuarchive!decwrl!sgi!koontz@oregon.sgi.com From: koontz@oregon.sgi.com (David Koontz) Newsgroups: sci.electronics Subject: Re: I-records, 8031 Message-ID: <49481@sgi.sgi.com> Date: 1 Feb 90 20:40:03 GMT References: <2454@cs-spool.calgary.UUCP> Sender: koontz@oregon.sgi.com Organization: Silicon Graphics, Inc., Mountain View, CA Lines: 94 In article <2454@cs-spool.calgary.UUCP>, deraadt@cpsc.UCalgary.CA (Theo de Raadt) writes: > I need information on how an intel record (like an srecord) is > formatted. > This was intended to take 68020 code in a unix environ, strip the header off, and convert to ihex for making EPROMs. (easy to undo). I checked the source and could find no copyright notice. ================ /* ihex.c */ /* Intel hex code generating program, taken from prom.c - promdef.c written by A. Bechtolsheim in SAIL on SU-AI. C version by Andy Schneider. Takes input file specified as argv[1] and produces a file named '.hex'. */ #include #include #define STRING "0123456789ABCDEF" #define OUTHEX(fp,v) {putc(STRING[(v&0xf0)>>4],fp);putc(STRING[v&0x0f],fp);} #define OUTFRAME(fp,x) {chksum+=x;OUTHEX(fp,x);} #define BIGSTRING 100 #define DEFAULTSIZE 16384 main (argc,argv) int argc; char **argv; { char infile[BIGSTRING]; char name[BIGSTRING]; char *suffix = ".hex"; char x; int i,adrs,chksum; long size = DEFAULTSIZE; FILE *input, *chan, *fopen(); if (argc < 2) { fprintf (stderr,"No source file named\n"); exit (0); } else{ fprintf (stderr,"Source file %s\n",argv[1]); } if (argc > 2){ size = atol(argv[2]); fprintf(stderr,"Specified Size: %x\n",size); } strncpy (infile,argv[1],10); strcpy (name,infile); strncat (name,suffix,4); /* add dothex */ printf ("Input filename: %s\n",infile); printf ("Output filename: %s\n",name); input = fopen(infile,"r"); if (input == NULL) { fprintf (stderr,"Can't open %s for read\n",infile); exit (0); } chan = fopen(name,"w"); if (chan == NULL) { fprintf(stderr,"Open failure on %s\n",name); exit (0); } for (i=0;i<32;i++) x = fgetc(input); /* lets remove 32 byte unix header */ for (adrs=0;adrs<= (size -1);adrs+=16) { putc(':',chan); /* record mark field */ chksum=0; /* init checksum */ OUTFRAME(chan,16); /* record length = 16 */ OUTFRAME(chan,(0xff&(adrs>>8))); /* load address field high order digit */ OUTFRAME(chan,(adrs & 0xff)); /* load address field low-order digit */ OUTHEX(chan, 0); /* record type = data */ for (i=0;i<=15;i++) { x = fgetc(input); OUTFRAME(chan,x); } OUTHEX(chan,((-(chksum&0xff))&0xff)); /* two's complement of the 8 bit sum of frames */ putc('\n',chan); } fprintf(chan,":0000000000\n"); /* final record: length=0, adrs=0, type=0, chk=0 */ fclose(input); fclose(chan); }