diff --git a/6502/gen6502/vFORTH38/Makefile b/6502/gen6502/vFORTH38/Makefile new file mode 100644 index 0000000..f2eff8d --- /dev/null +++ b/6502/gen6502/vFORTH38/Makefile @@ -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 $< $@ diff --git a/6502/gen6502/vFORTH38/fb2fth.py b/6502/gen6502/vFORTH38/fb2fth.py new file mode 100755 index 0000000..ec756b0 --- /dev/null +++ b/6502/gen6502/vFORTH38/fb2fth.py @@ -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))