retroforth/tools/retro-embedimage.py
crc aff0fb3c6e run black to reformat Python files
FossilOrigin-Name: 3b06a15e14d8f808dbefdde1d129a4f768f803fbb3ce7fe39a82e60ff7ed88e7
2021-01-20 17:41:34 +00:00

31 lines
698 B
Python
Executable file

#!/usr/bin/env python3
# retro-embedimage
#
# This takes an ngaImage and generates a version that provides the
# image as a Python list. Output is written to stdout.
#
# Copyright (c) 2020, Charles Childers
#
# Usage:
#
# retro-embedimage.py [image]
import os, sys, struct
from struct import pack, unpack
if __name__ == "__main__":
cells = int(os.path.getsize(sys.argv[1]) / 4)
f = open(sys.argv[1], "rb")
memory = list(struct.unpack(cells * "i", f.read()))
f.close()
count = 0
print("InitialImage = [")
for cell in memory:
print(cell, end=", ")
count = count + 1
if count > 10:
print("")
count = 0
print("]")