Created
July 12, 2020 08:09
-
-
Save thierer/2595e8e28a01111d785f282eac2ac8c5 to your computer and use it in GitHub Desktop.
display the (optional) error information in commodore 1541 disk images in .d64 format
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
#!/usr/bin/env python | |
from __future__ import division, print_function | |
import sys | |
import io | |
import glob | |
from os.path import getsize | |
def display_errors(filename, print_filename): | |
size = getsize(filename) | |
if print_filename: | |
print("* %s: " % filename, end="") | |
if size == 0: | |
print("File is empty.") | |
if size % 257 != 0: | |
if size % 256 != 0: | |
print("Not a valid D64 image.") | |
else: | |
print("No errors or error information not present.") | |
return | |
if print_filename: | |
print("\n") | |
sectors = size // 257 | |
with io.open(filename, "rb") as infile: | |
infile.seek(256 * sectors, io.SEEK_SET) | |
codes = bytearray(infile.read()) | |
track = 1 | |
sectors = 21 | |
pos = 0 | |
# Print header | |
print(" %s" % "".join([str(x // 10) for x in range(21)])) | |
print(" %s" % "".join([str(x % 10) for x in range(21)])) | |
codemap = ["?"] * 256 | |
codemap[1] = "-" # 00 no error | |
codemap[2] = "M" # 20 block header not found | |
codemap[3] = "X" # 21 no sync | |
codemap[4] = "D" # 22 data block not found | |
codemap[5] = "C" # 23 checksum error in data block | |
codemap[6] = "G" # 24 invalid gcr code in either header or data block | |
codemap[9] = "H" # 27 checksum error in header | |
codemap[11] = "I" # 29 disc id mismatch | |
while pos < len(codes): | |
if track == 18: | |
sectors = 19 | |
elif track == 25: | |
sectors = 18 | |
elif track == 31: | |
sectors = 17 | |
errstr = "".join([codemap[x] for x in codes[pos:pos+sectors]]) | |
print("%02d %s" % (track, errstr)) | |
pos += sectors | |
track += 1 | |
print() | |
if len(sys.argv) >= 2: | |
args = sys.argv[1:] | |
else: | |
args = ["*.d64"] | |
filenames = [] | |
for i in args: | |
filenames.extend(glob.glob(i)) | |
if len(filenames) == 0: | |
print("No files found.") | |
exit(1) | |
# Print the filename if more than one argument or argument constains a wildcard | |
print_filename = len(args) > 1 or any([c in args[0] for c in "*?[]"]) | |
for filename in filenames: | |
display_errors(filename, print_filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Invocation
Example output
Significance of status markers