romcvt.c
1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* convert a rom binary file into a .c text file, with a struct named
* RomImage
*/
#include <stdio.h>
#include <stdlib.h>
main()
{
FILE *input,*output;
int blen,flen,rv,i,c;
unsigned char *dataIn;
input = fopen("rom", "r");
if (!input)
{
printf("couldn't open file rom\n");
exit(1);
}
output = fopen("rom.c", "w");
if (!output)
{
printf("couldn't open file rom.c \n");
exit(1);
}
fseek(input, 0, SEEK_END);
flen = ftell(input);
rewind(input);
blen = flen;
blen = (blen+4) & ~4;
dataIn = malloc(blen);
if(!dataIn)
{
printf("Unable to alloc memory for buffer\n");
exit(1);
}
fprintf(output,"int gRomImageSize = %d;\n\n",blen);
rv= fread(dataIn, 1, flen, input);
if(rv!=flen)
printf("ERROR!!, didn't read correct number of bytes, read %d\n",rv);
fprintf(output,"unsigned char gRomImage[] ={\n ");
blen--;
for(i=0,c=0;i<blen;i++,c++)
{
if(c >= 16)
{
fprintf(output,"0x%x,\n ",dataIn[i]);
c = 0;
}
else
fprintf(output,"0x%x,",dataIn[i]);
}
fprintf(output,"0x%x};\n",dataIn[blen+1]);
fclose(input);
fclose(output);
}