commit 4b8673fe27179dd55ea94975b6906f6b5645afb8 Author: A.M. Rowsell Date: Tue Dec 26 21:08:11 2023 -0500 Initial commit of project with working versions of scripts. diff --git a/petscii.py b/petscii.py new file mode 100755 index 0000000..b54262f --- /dev/null +++ b/petscii.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python3 + +import sys + +def convert(byte): + if byte == 13: # fix line endings + return 10 + if byte == 63: # don't change question marks + return byte + if byte >= 97 and byte <= 122: + return byte - 32 + if byte >= 65 and byte <= 90: + return byte + 32 + if byte >= 192 and byte <= 223: + byte -= 96 + if byte >= 97 and byte <= 122: + byte -= 32 + return byte + +def main(): + filename = sys.argv[1] + with open(filename, "rb") as f: + while (byte := f.read(1)): + byte = convert(int.from_bytes(byte)) + print(byte.to_bytes(1).decode('ascii'), end="") + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/wordwriter.py b/wordwriter.py new file mode 100755 index 0000000..af61ad9 --- /dev/null +++ b/wordwriter.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python3 + +import sys + +def convert(byte): + if byte < 0x20: # lowercase + byte = byte | 0x60 + if byte == 0x60: + byte = 0x40 + if byte == 0xFE or byte == 0xFF: # line feed + byte = 0x0A + if byte > 0x7F: # control codes + byte = 0x20 + return byte + +def main(): + filename = sys.argv[1] + with open(filename, "rb") as f: + while (byte := f.read(1)): + if int.from_bytes(byte) == 0x00: # skip all the bytes before the first 0 + break + while (byte := f.read(1)): + byte = convert(int.from_bytes(byte)) + + print(byte.to_bytes(1).decode('ascii'), end="") + +if __name__ == "__main__": + main() \ No newline at end of file