mirror of
https://github.com/option8/RetroConnector.git
synced 2025-01-01 10:31:02 +00:00
merged with xandark
This commit is contained in:
commit
0cc11c31ce
5
.gitignore
vendored
5
.gitignore
vendored
@ -1 +1,4 @@
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
|
*/.DS_Store
|
||||||
|
|
||||||
|
.DS_Store
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 57 KiB |
@ -7,14 +7,16 @@
|
|||||||
@RetroConnector
|
@RetroConnector
|
||||||
|
|
||||||
requires ImageMagick: http://www.imagemagick.org/
|
requires ImageMagick: http://www.imagemagick.org/
|
||||||
and python PNG module: https://pypi.python.org/pypi/pypng
|
and python PNG module: https://pypi.python.org/pypi/pypng
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
import os,sys # filesystem functions
|
import os,sys # filesystem functions
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import png # PNG image library
|
import png # PNG image library
|
||||||
except:
|
except:
|
||||||
print("\n\n" + sys.argv[0] + " requires the Python PNG module\n\n Download from https://pypi.python.org/pypi/pypng \n Or type in shell: pip install pypng\n\n")
|
print("\n\n" + sys.argv[0] + " requires the Python PNG module\n\n Download from https://pypi.python.org/pypi/pypng \n Or type in shell: pip install pypng\n\n")
|
||||||
sys.exit(1) # exit on exception - no library installed
|
sys.exit(1) # exit on exception - no library installed
|
||||||
@ -26,12 +28,25 @@ except:
|
|||||||
print("\n\nUsage: python "+ sys.argv[0] +" [filename]\n\n [filename] should be a .DSK file of 143kb.\n")
|
print("\n\nUsage: python "+ sys.argv[0] +" [filename]\n\n [filename] should be a .DSK file of 143kb.\n")
|
||||||
sys.exit(1) # exit on exception - no file chosen
|
sys.exit(1) # exit on exception - no file chosen
|
||||||
|
|
||||||
TEMPFILENAME = "DiskImageTEMP.png"
|
|
||||||
PNG = open(TEMPFILENAME, "wb") # open a PNG for writing
|
print("Checking " + INPUTFILE + "...\n")
|
||||||
|
|
||||||
|
# to do: check for 140k 5.25'' disks vs 400k/800k 3.5'' and adjust accordingly
|
||||||
|
|
||||||
|
if (os.path.getsize(INPUTFILE)) != 143360: # check file size. for 5.25'', it needs to be 143k
|
||||||
|
print("\n\nOops. Is " + INPUTFILE + " a DSK file of 143kb?\n\n")
|
||||||
|
sys.exit(1) # exit on exception - file is empty, etc
|
||||||
|
|
||||||
# The point: Make a PNG image from the data on a floppy disk image.
|
# The point: Make a PNG image from the data on a floppy disk image.
|
||||||
# 35 tracks, each with 16 sectors of 256 bytes each, for a total of 143,360 bytes
|
# 5.15'' disks have 35 tracks, each with 16 sectors of 256 bytes each, for a total of 143,360 bytes
|
||||||
# so 35 lines of 4096 px.
|
# so 35 lines of 4096 px.
|
||||||
|
TRACKS = 35
|
||||||
|
SECTORS = 16
|
||||||
|
BYTESPERSECTOR = 256
|
||||||
|
|
||||||
|
TEMPFILENAME = "DiskImageTEMP.png"
|
||||||
|
PNG = open("DiskImageTEMP.png", "wb") # open a PNG for writing
|
||||||
|
|
||||||
|
|
||||||
# new, empty arrays
|
# new, empty arrays
|
||||||
BYTES = []
|
BYTES = []
|
||||||
@ -40,7 +55,7 @@ PIXELS = []
|
|||||||
try:
|
try:
|
||||||
byte = DSK.read(1) # read a byte
|
byte = DSK.read(1) # read a byte
|
||||||
while byte != "": # while the file still has bytes in it
|
while byte != "": # while the file still has bytes in it
|
||||||
byte = DSK.read(1)
|
byte = DSK.read(1)
|
||||||
if len(byte) > 0: # the last byte, for whatever reason, is length 0. Bah.
|
if len(byte) > 0: # the last byte, for whatever reason, is length 0. Bah.
|
||||||
BYTES.append(ord(byte)) # append the number representing the byte (0-255) to the BYTES array
|
BYTES.append(ord(byte)) # append the number representing the byte (0-255) to the BYTES array
|
||||||
except:
|
except:
|
||||||
@ -50,23 +65,23 @@ except:
|
|||||||
|
|
||||||
print("\n Starting.\n")
|
print("\n Starting.\n")
|
||||||
|
|
||||||
for TRACK in range(0,35,1): # for each of the 35 tracks
|
for TRACK in range(0,TRACKS,1): # for each of the 35 tracks
|
||||||
LINE=[] # start a new line of pixels
|
LINE=[] # start a new line of pixels
|
||||||
for SECTOR in range(0,4096,1): # write the bytes for the sectors in that track to the line array
|
for SECTOR in range(0,SECTORS*BYTESPERSECTOR,1): # write the bytes for the sectors in that track to the line array
|
||||||
offset = (SECTOR * TRACK) + SECTOR
|
offset = (SECTOR * TRACK) + SECTOR
|
||||||
LINE.append(BYTES[(SECTOR * TRACK) + SECTOR])
|
LINE.append(BYTES[(SECTOR * TRACK) + SECTOR])
|
||||||
|
|
||||||
print(" Track: " + str(TRACK))
|
print(" Track: " + str(TRACK))
|
||||||
PIXELS.append(LINE) # add the array of pixels to the array of arrays
|
PIXELS.append(LINE) # add the array of pixels to the array of arrays
|
||||||
|
|
||||||
print("\n Done.\n")
|
print("\n Done.\n")
|
||||||
|
|
||||||
# write to the PNG file
|
# write to the PNG file
|
||||||
w = png.Writer(4096,35, greyscale=True, bitdepth=8)
|
w = png.Writer(SECTORS*BYTESPERSECTOR,TRACKS, greyscale=True, bitdepth=8)
|
||||||
w.write(PNG, PIXELS) # each number in the array becomes a pixel in the image. each array becomes a line.
|
w.write(PNG, PIXELS) # each number in the array becomes a pixel in the image. each array becomes a line.
|
||||||
|
|
||||||
print(" Writing to disk. Chunka-chunk-cka. Whirr...\n")
|
sys.stdout.write("\n\n\r Writing bytes to disk. Chunka-chunka-chunk. Whirr.\n\n")
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
DSK.close() # done with these files. close them.
|
DSK.close() # done with these files. close them.
|
||||||
PNG.close()
|
PNG.close()
|
||||||
@ -75,19 +90,24 @@ PNG.close()
|
|||||||
OUTPUTFILE = os.path.join(INPUTFILE + ".png")
|
OUTPUTFILE = os.path.join(INPUTFILE + ".png")
|
||||||
# set a destination file same as DSK, but with PNG extension
|
# set a destination file same as DSK, but with PNG extension
|
||||||
|
|
||||||
os.system('convert '+TEMPFILENAME+' -matte -virtual-pixel transparent -resize 1024x1024! -rotate 90 -distort Polar "512 110 512,512 -180,180" "'+OUTPUTFILE+'"')
|
|
||||||
# Using ImageMagick, convert the 4096x35px image to a square, rotate, then rotate around an axis.
|
|
||||||
# NOTE: Windows command line needs to have Polar coordinates enquoted with " not '
|
try:
|
||||||
# NOTE: Windows has a native command called convert which does something very different
|
subprocess.call(['convert', 'DiskImageTEMP.png', '-matte', '-virtual-pixel', 'transparent', '-resize', '1024x1024!', '-rotate', '90', '-distort', 'Polar', '512 110 512,512 -180,180', OUTPUTFILE])
|
||||||
# from ImageMagick's convert command, so obviously this will fail if IM is not installed
|
# convert the 4096x35px image to a square, rotate, then rotate around an axis.
|
||||||
|
except OSError:
|
||||||
|
print("\n\nOops. This script requires ImageMagick: http://www.imagemagick.org/")
|
||||||
|
sys.exit(1) # exit on exception - needs imagemagick installed
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if 'win32' in sys.platform:
|
if 'win32' in sys.platform:
|
||||||
# Because the Windows "start" commandline command cannot take an enquoted file or pathname,
|
# Because the Windows "start" commandline command cannot take an enquoted file or pathname,
|
||||||
# which is necessary if the path has spaces, we have to obtain the "short" version of
|
# which is necessary if the path has spaces, we have to obtain the "short" version of
|
||||||
# the file/path in the 8.3 format. There is no Python library to do this for us.
|
# the file/path in the 8.3 format. There is no Python library to do this for us.
|
||||||
# Said another way: Windows is broken in that enquoting a file argument after their start
|
# Said another way: Windows is broken in that enquoting a file argument after their start
|
||||||
# command causes it to open a blank terminal. Boo!
|
# command causes it to open a blank terminal. Boo!
|
||||||
# But we do this *after* the ImageMagick convert process above, because that will take an
|
# But we do this *after* the ImageMagick convert process above, because that will take an
|
||||||
# enquoted file just fine.
|
# enquoted file just fine.
|
||||||
from ctypes import windll, create_unicode_buffer, sizeof
|
from ctypes import windll, create_unicode_buffer, sizeof
|
||||||
buf = create_unicode_buffer( 512 )
|
buf = create_unicode_buffer( 512 )
|
||||||
@ -96,7 +116,7 @@ if 'win32' in sys.platform:
|
|||||||
else:
|
else:
|
||||||
# Otherwise we enquote the output file becuase it may have spaces
|
# Otherwise we enquote the output file becuase it may have spaces
|
||||||
OUTPUTFILE = '"' + OUTPUTFILE + '"'
|
OUTPUTFILE = '"' + OUTPUTFILE + '"'
|
||||||
|
|
||||||
platform_commands = {
|
platform_commands = {
|
||||||
'darwin' : 'open', # opens the resulting image in the default Mac image viewer (Preview.app)
|
'darwin' : 'open', # opens the resulting image in the default Mac image viewer (Preview.app)
|
||||||
'linux' : 'xdg-open', # opens the resulting image in the default Linux image viewer (mime-determined); Python 2: 'linux2', Python 3: 'linux'
|
'linux' : 'xdg-open', # opens the resulting image in the default Linux image viewer (mime-determined); Python 2: 'linux2', Python 3: 'linux'
|
||||||
|
Loading…
Reference in New Issue
Block a user