mirror of
https://github.com/forth-ev/VolksForth.git
synced 2024-11-22 05:32:28 +00:00
Makefile and python3 script to turn .fb block sources into .fth text files
This commit is contained in:
parent
b139071e41
commit
ae1f4d9dff
11
6502/gen6502/vFORTH38/Makefile
Normal file
11
6502/gen6502/vFORTH38/Makefile
Normal 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
28
6502/gen6502/vFORTH38/fb2fth.py
Executable 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))
|
Loading…
Reference in New Issue
Block a user