1 /* Converts bin file to mem file */
6 void print_help(char * name)
8 fprintf(stderr, "%s converts a binary file into a mem-file\n", name);
9 fprintf(stderr, "Usage: %s INFILE OUTFILE\n", name);
12 int main(int argc, char *argv[])
14 FILE *infile, *outfile;
15 int whi, wlo, bhi, blo;
24 infile = fopen(argv[1], "rb");
27 printf("Cannot open file %s\n", argv[1]);
31 outfile = fopen(argv[2], "w");
34 printf("Cannot open file %s\n", argv[2]);
38 fprintf(outfile,"// memory data file (do not edit the following line - required for mem load use)\n"
39 "// format=hex addressradix=h dataradix=h version=1.0 wordsperline=1\n");
42 while ((whi = fgetc(infile)) != EOF)
44 fprintf(outfile,"@%x ", addr);
46 if ((wlo = fgetc(infile)) == EOF)
48 if ((bhi = fgetc(infile)) == EOF)
50 if ((blo = fgetc(infile)) == EOF)
53 fprintf(outfile, "%.2x%.2x%.2x%.2x\n", whi,wlo,bhi,blo);