From ae1f4d9dffe8c0a11d67c9bb2f17895cff43a3f2 Mon Sep 17 00:00:00 2001 From: Philip Zembrod Date: Sat, 27 Jun 2020 23:40:25 +0200 Subject: [PATCH] Makefile and python3 script to turn .fb block sources into .fth text files --- 6502/gen6502/vFORTH38/Makefile | 11 +++++++++++ 6502/gen6502/vFORTH38/fb2fth.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 6502/gen6502/vFORTH38/Makefile create mode 100755 6502/gen6502/vFORTH38/fb2fth.py 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))