Initial commit of project with working versions of scripts.

This commit is contained in:
A.M. Rowsell 2023-12-26 21:08:11 -05:00
commit 4b8673fe27
Signed by: amr
GPG key ID: 0B6E2D8375CF79A9
2 changed files with 56 additions and 0 deletions

28
petscii.py Executable file
View file

@ -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()

28
wordwriter.py Executable file
View file

@ -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()