a2b.c 984 Bytes
/*
 *  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);
}