OpenCores
URL https://opencores.org/ocsvn/plasma/plasma/trunk

Subversion Repositories plasma

[/] [plasma/] [tags/] [V3_0/] [tools/] [bintohex.c] - Blame information for rev 53

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 47 rhoads
/*bintohex by Steve Rhoads 5/29/02*/
2
#include <stdio.h>
3
#include <string.h>
4
 
5
#define BUF_SIZE (1024*1024)
6
 
7
int main(int argc,char *argv[])
8
{
9
   FILE *file;
10
   unsigned char *buf;
11 53 rhoads
   unsigned long size,mem_size=1024*4,i,j,k,sum;
12 47 rhoads
   char filename[80];
13
 
14 53 rhoads
   if(argc<2) {
15
      printf("usage: bintohex infile\n");
16
      return -1;
17 47 rhoads
   }
18
   file=fopen(argv[1],"rb");
19
   if(file==NULL) {
20
      printf("Can't open %s\n",argv[1]);
21
      return -1;
22
   }
23
   buf=(unsigned char*)malloc(BUF_SIZE);
24
   memset(buf,0,BUF_SIZE);
25 53 rhoads
   size=fread(buf,1,BUF_SIZE,file);
26
   mem_size=size;
27 47 rhoads
   if(size>mem_size) {
28
      printf("FILE TOO LARGE!!!!!!!!!!!\n");
29
      return -1;
30
   }
31
   fclose(file);
32
   strcpy(filename,"codeX.hex");
33
   for(i=0;i<4;++i) {
34
      filename[4]='0'+i;
35
      file=fopen(filename,"wb");
36
      for(j=0;i+j*4*16<mem_size;++j) {
37
         k=j*16;
38
         fprintf(file,":10%4.4x00",k);
39
         sum=0x10+(k>>8)+(k&0xff);
40
         for(k=0;k<16;++k) {
41
            fprintf(file,"%2.2x",buf[i+j*4*16+k*4]);
42
            sum+=buf[i+j*4*16+k*4];
43
         }
44
         sum&=0xff;
45
         sum=0x100-sum;
46
         sum&=0xff;
47
         fprintf(file,"%2.2x\n",sum);
48
      }
49
      fprintf(file,":00000001ff\n");
50
      fclose(file);
51
   }
52
   free(buf);
53
   return 0;
54
}
55
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.