Skip to content

Instantly share code, notes, and snippets.

@jandelgado
Last active Apr 20, 2022
Embed
What would you like to do?
#!/bin/bash
#
# convert a Kryoflux stream of an Olivetti M20 disk to a raw disk image that
# can be used in MAME.
#
# usage:
# conv_m20.sh <dir> [<output-file>]
# where <dir> is the directory where the stream files are stored as
# dump.xx.y.raw files. <output-file> is dir to write the raw image to
# It defaults to <dir>.raw
#
# example:
# $ ./conv_m20.sh M20_Assembler asm.raw
#
# 04-2022 by Jan Delgado
#
# Disk format information:
#
# M20 Disks are 320 KB and MFM formatted, expcept for track 00.0
# track 00.0 - FM formatted, 128 Bytes x 16 Sectors
# track 00.1 - MFM formatted, 256 Bytes x 16 Sectors
# track 01-34 - MFM formatted, 256 Bytes x 16 Sectors
#
# Dependencies:
# Kryoflux dtc tool, dd
#
set -eou pipefail
dir="$1"
[ ! -d "$dir" ] && { echo "$1: no such directory"; exit 1; }
target=${2:-${dir}.raw}
target_file=${target}
# temporary files to store raw tracks
tmpdir=$(mktemp -d)
tmp_tracks="$tmpdir/tracks"
trap 'rm -rf "$tmpdir"' EXIT
# track 0.0 FM formatted, 128 bytes * 16 sectors -> ${tmp_tracks}_s0.raw
dtc -m1 -f$dir/dump -i0 \
-f${tmp_tracks}.raw \
-g0 -s0 -e0 -oe0 -z0 -i3 \
-l8
# track 0.1 MFM formatted, 256 bytes * 16 sectors -> ${tmp_tracks}_s1.raw
dtc -m1 -f$dir/dump -i0 \
-f${tmp_tracks}.raw \
-g1 -s0 -e0 -oe0 -z1 -i4 \
-l8
# remaining tracks MFM formatted, 256 bytes * 16 sectors -> ${tmp_tracks}.raw
dtc -m1 -f$dir/dump -i0 \
-f${tmp_tracks}.raw \
-s1 -e34 -os1 -oe34 -z1 -i4 \
-l8
dd if=${tmp_tracks}_s0.raw of=${target_file}
dd if=${tmp_tracks}_s1.raw of=${target_file} oflag=seek_bytes seek=4096
dd if=${tmp_tracks}.raw of=${target_file} oflag=seek_bytes seek=8192
echo "Wrote image $target_file"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment