From 57658950f7d75ec2f09d903b6514d1026e2d0e6d Mon Sep 17 00:00:00 2001 From: Chris Torrence Date: Sun, 11 Oct 2020 16:00:29 -0600 Subject: [PATCH 1/2] Add code to do other direction (same algorithm) --- po2dsk.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 po2dsk.py diff --git a/po2dsk.py b/po2dsk.py new file mode 100755 index 0000000..fe49b59 --- /dev/null +++ b/po2dsk.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# scramble po back into dsk +# Chris Torrence, Oct 2020 +import sys, getopt, re +from dsk2po import dsk2po +def main(argv=None): + print("po2dsk - convert po files to dsk files") + + try: + opts, args = getopt.getopt(sys.argv[1:], '') + except getopt.GetoptError as err: + print(str(err)) + usage() + return 1 + try: + filenameIn = args[0] + except: + print('You need to provide the name of a PO file to begin.') + return 1 + + tracks = [] + # Note that the same algorithm can be used to convert in either direction + with open(filenameIn, mode="rb") as fileIn: + for track in range(35): + trackbuffer = fileIn.read(4096) + tracks.append(dsk2po(trackbuffer)) + dskfilename = re.sub('\.po$', '', filenameIn, flags=re.IGNORECASE) + ".dsk" + print('Writing dsk image to {}'.format(dskfilename)) + with open(dskfilename, mode="wb") as file: + for track in tracks: + file.write(track) + return 1 + +if __name__ == "__main__": + sys.exit(main()) From 742aa4b90137373f9cae3fae73570ec91c88cec5 Mon Sep 17 00:00:00 2001 From: Chris Torrence Date: Sun, 11 Oct 2020 16:03:50 -0600 Subject: [PATCH 2/2] Add po2dsk --- README.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 790e1fd..90541f3 100644 --- a/README.md +++ b/README.md @@ -6,15 +6,19 @@ into those of a .po (ProDOS-order) file. Most Apple II emulators can handle bot but certain utilities (with which I wanted to use existing .dsk images) assume ProDOS-ordered files. -Usage is just (assuming you've done chmod 755 dsk2po.py, else precede with python command): +Usage is just (assuming you've done `chmod 755 dsk2po.py`, else precede with python command): -./dsk2po.py image.dsk + ./dsk2po.py image.dsk This will create image.dsk.po alongside it. Pretty much no checking is done. It just goes through 35 tracks and converts them, then ends. This can be used as an action for find, like so: -find imagefolders/\*/\*.dsk -exec ./dsk2po.py {} \; + find imagefolders/\*/\*.dsk -exec ./dsk2po.py {} \; -...which was mostly the point. \ No newline at end of file +...which was mostly the point. + +You can also go the opposite direction: + + ./po2dsk.py image.po