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

Subversion Repositories plasma

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

powered by: WebSVN 2.1.0

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