#!/usr/bin/python3 """Convert F83 block files into Unix text files, with shadow screens. This seems to work okay on *.blk except expand86.blk, which doesn’t actually have shadow screens. """ import sys, os def read64at(file, offset): file.seek(offset) return file.read(64) def blk2unix(file): size = os.fstat(file.fileno()).st_size halfsize = (size - size % 1024) // 2 for n in range((size + 127)//128): shadowline = read64at(file, halfsize + n*64).rstrip() # The \ divider avoids screwing up syntax highlighting. yield (read64at(file, n*64) + (b' \ ' + shadowline if shadowline else b'') ).decode('latin-1').rstrip() + '\n' if 15 == n % 16: # emit form feed between triads of three screens # otherwise just a blank line yield '\f\n' if 2 == n // 16 % 3 else '\n' if __name__ == '__main__': sys.stdout.writelines(blk2unix(open(sys.argv[1], 'rb')))