SummerCart64/fw/cpu/controller/bin2rom.py

26 lines
555 B
Python
Raw Normal View History

2021-08-23 22:30:47 +02:00
#!/usr/bin/env python3
import os
import sys
binary = None
rom = None
binary_name = sys.argv[1] or 'binary.bin'
rom_name = sys.argv[2] or 'rom.bin'
try:
binary = open(binary_name, mode='rb')
rom = open(rom_name, mode='wb')
length = os.path.getsize(binary_name)
rom.write(length.to_bytes(4, byteorder='little'))
rom.write(binary.read())
except Exception as e:
print(f'Unable to convert the rom: {e}', file=sys.stderr)
sys.exit(-1)
finally:
if (binary): binary.close()
if (rom): rom.close()