mirror of
https://github.com/paulhagstrom/dsk2po.git
synced 2024-12-22 16:30:08 +00:00
Merge pull request #3 from chris-torrence/master
Add po2dsk.py to go other direction
This commit is contained in:
commit
2f199f601c
12
README.md
12
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
|
but certain utilities (with which I wanted to use existing .dsk images) assume
|
||||||
ProDOS-ordered files.
|
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.
|
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.
|
It just goes through 35 tracks and converts them, then ends.
|
||||||
|
|
||||||
This can be used as an action for find, like so:
|
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.
|
...which was mostly the point.
|
||||||
|
|
||||||
|
You can also go the opposite direction:
|
||||||
|
|
||||||
|
./po2dsk.py image.po
|
||||||
|
35
po2dsk.py
Executable file
35
po2dsk.py
Executable file
@ -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())
|
Loading…
Reference in New Issue
Block a user