a2b.c
984 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
46
47
48
49
/*
* Simple program to convert 64-bit words in ASCII to binary.
* Allows bit-blasting of RDP display lists.
*/
#include <stdio.h>
#include <stdlib.h>
main(int argc, char **argv)
{
FILE *fp, *ofp;
int ret;
unsigned int word0, word1;
char line[512], word[50], w0[30], w1[30];
if(argc != 3)
{
printf("Usage: %s <in_file> <out_file>\n", argv[0]);
exit(0);
}
if((fp = fopen(argv[1],"r")) == NULL)
{
printf("Error opening %s for read\n", argv[1]);
exit(1);
}
if((ofp = fopen(argv[2],"wb")) == NULL)
{
printf("Error opening %s for write\n", argv[2]);
exit(1);
}
while(fgets(line, 512, fp))
{
sscanf(line,"%*s %s", word);
sprintf(w0,"0x%.8s\0", &word[2]);
sprintf(w1,"0x%.8s\0", &word[10]);
word0 = strtoul(w0,0,16);
word1 = strtoul(w1,0,16);
ret = fwrite(&word0, sizeof(unsigned int), 1, ofp);
ret = fwrite(&word1, sizeof(unsigned int), 1, ofp);
}
fclose(fp);
fclose(ofp);
exit(0);
}