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