Skip to content

Instantly share code, notes, and snippets.

@thierer
Created July 12, 2020 08:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thierer/2595e8e28a01111d785f282eac2ac8c5 to your computer and use it in GitHub Desktop.
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
#!/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)
@thierer
Copy link
Author

thierer commented Jul 12, 2020

Invocation

d64errors.py <list of .d64 files>
  • Filenames of multiple images can be given as command line arguments.
  • Wildcards are accepted.
  • Without arguments, all .d64 files in the current directory are processed.
  • If no error information is present, that could both indicate that there were no errors or that it just wasn't included when creating the disk image.

Example output

   000000000011111111112
   012345678901234567890
01 ---------------------
02 ---------------------
03 --M------------------
04 --------------------M
05 ---------------------
06 ---------------------
07 ---------------------
08 ---------------------
09 ---------------------
10 ---------------------
11 ---------------------
12 ---------------------
13 ---------------------
14 ---------------------
15 ----M----------------
16 ---------------------
17 ---------------------
18 -------------------
19 -------------------
20 -------------------
21 -------------------
22 -M-----------------
23 ---------------M---
24 ---------HH--------
25 ------------------
26 ------------------
27 ------------------
28 ------------------
29 -----------------M
30 -----------M------
31 -----------------
32 -----------------
33 -----------------
34 ------M----------
35 -----------------

Significance of status markers

cbm
- no error 00
M block header not found 20
X no sync 21
D data block not found 22
C checksum error in data block 23
G invalid gcr code in either header or data block 24
H checksum error in header 27
I disc id mismatch 29

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment