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

Subversion Repositories plasma

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

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

powered by: WebSVN 2.1.0

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