hello-dosdl/embed-textfile.py
2022-02-25 02:05:00 +02:00

18 lines
434 B
Python

#!/usr/bin/env python
import sys
srcpath = sys.argv[1]
name = sys.argv[2]
targetpath = sys.argv[3]
with open(srcpath, 'r') as f:
lines = [line.rstrip() for line in f]
with open(targetpath, 'w') as f:
f.write(f'{name}:\n')
for line in lines:
encoded = line.encode('cp437')
if len(encoded) > 0:
f.write(f'\tdb {", ".join(str(char) for char in encoded)}, 13, 10\n')
else:
f.write('\tdb 13, 10\n')
f.write("\tdb '$'\n")