b2mem.c
784 Bytes
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
/*
* Converts binary file into ASCII verilog memory file:
* <64-bit hex word>
* <64-bit hex word>
* . .
* . .
* . .
* <64-bit hex word>
*
* Useful for running display lists through verilog simulation
*/
#include <stdio.h>
main(int argc, char **argv)
{
FILE *fp;
unsigned int dbl_word[2];
int ret, cnt;
if(argc != 2)
{
printf("Usage: %s <filename>\n", argv[0]);
exit(0);
}
if((fp = fopen(argv[1],"rb")) == NULL)
{
printf("Error opening %s\n", argv[1]);
exit(1);
}
cnt = 0;
do
{
ret = fread(dbl_word, sizeof(unsigned int), 2, fp);
if(ret == 2)
printf("%08x%08x\n", dbl_word[0], dbl_word[1]);
++cnt;
} while ( ret == 2 );
fclose(fp);
exit(0);
}