Created
February 16, 2021 05:17
-
-
Save prozacchiwawa/be606063d17daae2760014cefa097715 to your computer and use it in GitHub Desktop.
a twitter thread reminiscing about bbses pre-internet got me thinking about this. does a good enough job of converting old .mac
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
def shiftout(fout, bs): | |
for b in bs: | |
bb = b | |
for i in range(8): | |
if (bb >> 7) % 2 == 0: | |
fout.write(bytes([255])) | |
else: | |
fout.write(bytes([0])) | |
bb = bb << 1 | |
if __name__ == '__main__': | |
fdata = open(sys.argv[1],'rb').read() | |
fout = open(sys.argv[2],'wb') | |
fout.write('P5\n'.encode('utf8')) | |
fout.write('576 720 255\n'.encode('utf8')) | |
n = 640 | |
while n < len(fdata): | |
by = fdata[n] | |
if by >= 128: | |
repeat = 257-by | |
rdata = fdata[n+1] | |
n += 2 | |
shiftout(fout, bytes([rdata] * repeat)) | |
else: | |
repeat = by | |
rdata = fdata[n+1:n+repeat+2] | |
n += repeat + 2 | |
shiftout(fout, rdata) | |
fout.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment