Skip to content
Snippets Groups Projects
Select Git revision
  • 134b60fef52f8ae2538857e32ae7a57ddc4747a7
  • master default
2 results

convert.py

Blame
  • convert.py 769 B
    import sys
    
    # Input binary file and output header file
    input_file = "dragon.bin"
    output_file = "dragon_data.h"
    
    try:
        with open(input_file, "rb") as f:
            binary_content = f.read()
    except FileNotFoundError:
        print(f"Error: {input_file} not found.", file=sys.stderr)
        sys.exit(1)
    
    # Convert binary content into a C array
    hex_data = ', '.join(f'0x{byte:02x}' for byte in binary_content)
    
    # Write the header file
    with open(output_file, "w", encoding="utf-8") as f:
        f.write(f'#ifndef DRAGON_DATA_H\n#define DRAGON_DATA_H\n\n')
        f.write(f'const unsigned char DRAGON_BIN[] = {{ {hex_data} }};\n')
        f.write(f'const unsigned int DRAGON_BIN_SIZE = {len(binary_content)};\n\n')
        f.write(f'#endif // DRAGON_DATA_H\n')
    
    print(f"Generated {output_file}")