IECHost track nibbling with a 1571 drive: NIB file support

As I thought when I created a non-standard G64 file (track data length = 8192 bytes), a NIB file holds pretty much the same information I was trying to hold in my custom G64 file.

I could not find information on the NIB format readily, so I ended up checking the implementation of the write_nib() function within the fileio.c source file in the nibtools repo on GitHub. Consequently, I wrote a script to create NIB files out of the data returned by the IECHost hardware when nibbling a DOS disk with a 1571, as per below:

#!/bin/bash

NIB_TRACK_LENGTH=8192

function int2byte() {
  local i=$1
  local f
  printf -v f '\\x%02x' ${i}
  printf "$f"
}

function int2word() {
  local i=$1
  local f
  printf -v f '\\x%02x\\x%02x' $(( i & 255 )) $(( (i >> 8) & 255 ))
  printf "$f"
}

# File signature
echo -n "MNIB-1541-RAW" > output.nib

# Format version (3), no half-tracks (0)
echo -n -e "\\x03\\x00\\x00" >> output.nib

# Half-track index and density
for track in {1..120}; do
  if (( ${track} <= 35 ))
  then
    int2byte $(( ${track} * 2)) >> output.nib
    density=$(( 3 - (${track} >= 18) - (${track} >= 25) - (${track} >= 31) ))
    int2byte ${density} >> output.nib
  else
    int2word 0 >> output.nib
  fi
done

# Track data
for ofs in $(grep -obUaP "\x3E\x20\x6E\x72\x0D" track_1_35.log | awk -F":" {'print $1'}); do
  skp=$(( ${ofs} + 10 ))
  dd bs=1 skip=${skp} count=${NIB_TRACK_LENGTH} if=track_1_35.log >> output.nib
done

I then converted my NIB file to D64 with nibconv:

nibconv - converts a CBM disk image from one format to another.
(C) Peter Rittwage
http://c64preservation.com
Built Jun  1 2020 20:51:42

Converting output.nib -> output.d64

Loading "output.nib"…
Successfully loaded 286976 bytes.
Parsing NIB data…
NIB file version 3
Successfully parsed NIB data for 35 tracks
Aligning tracks…
Searching for fat tracks…

Writing D64 file…
Converted 683 blocks into D64 file

WARNING!
Converting to D64 is a lossy conversion.
All individual sector header and gap information is lost.
It is suggested you use the G64 format for most disks.

I then calculated the checksum of the resulting D64:

59046   171

So, again, the process produces an identical D64 to the one I initially used to write data to the disk I then nibbled.

I like the idea of nibbling disks to NIB files as these hold slightly more data than G64 files, while also providing some redundant data for the sectors that are nibbled at the start of each track, which seems to be paramount to correctly decode such sectors.

Of course I shall run the GCR decoder on-the-fly for DOS disks in the IECHost GUI client in the long run.

Stay tuned for more!

About Luigi Di Fraia

I am a Senior DevOps Engineer so I get to work with the latest technologies and open-source software. However, in my private time I enjoy retro-computing.
This entry was posted in Retrocomputing, Technical and tagged , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s