Makefile and python3 script to turn .fb block sources into .fth text files

This commit is contained in:
Philip Zembrod 2020-06-27 23:40:25 +02:00
parent b139071e41
commit ae1f4d9dff
2 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,11 @@
blk_files = $(wildcard *.fb)
fth_files = $(patsubst %.fb, %.fth, $(blk_files))
# Target to convert all .fb blk sources into .fth files.
fth: $(fth_files)
# Generic rule for converting .fb blk sources into .fth files.
%.fth: %.fb
./fb2fth.py $< $@

28
6502/gen6502/vFORTH38/fb2fth.py Executable file
View File

@ -0,0 +1,28 @@
#!/usr/bin/python3
import sys
def readToString(inFile):
blockNo = 0
result = []
while(True):
block = inFile.read(1024)
if len(block) == 0:
break
result.append("\n\\ *** Block No. %d, Hexblock %x\n"
% (blockNo, blockNo));
offset = 0
while(offset < len(block)):
# sys.stderr.write("block %d offset %d\n" % (blockNo, offset))
line = block[offset:offset+64].decode(encoding="latin_1")
result.append(line.rstrip())
offset += 64
blockNo += 1
return result
inFileName, outFileName = sys.argv[1], sys.argv[2]
inFile = open(inFileName, "rb")
result = readToString(inFile)
result.append('')
outFile = open(outFileName, "w")
outFile.write("\n".join(result))