Skip to content

Instantly share code, notes, and snippets.

@jandelgado
Last active January 28, 2023 15:22
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 jandelgado/88962932896127dcabbe251f996e790e to your computer and use it in GitHub Desktop.
Save jandelgado/88962932896127dcabbe251f996e790e to your computer and use it in GitHub Desktop.
#!/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"
@eberhab
Copy link

eberhab commented Jan 4, 2023

Thanks for putting this together! Did you ever try to write an obtained/ modified image back to floppy? Would this be doable with KF?

@jandelgado
Copy link
Author

jandelgado commented Jan 4, 2023

No, not yet. I just used the KryoFlux to archive old disk. But for my understanding, writing disks is also possible.

FYI: a complete write-up of how I dumped the disks can be found here: https://jandelgado.github.io/blog/posts/olivetti-m20-disk-preservation

@eberhab
Copy link

eberhab commented Jan 4, 2023

Thanks for your quick reply. Indeed I came here via the article and read it with great interest. I am looking for a method to exchange files back and forth between a modern system and the M20, preferably via floppy. The KF sounds like the best option, but I'd still need some clarity on the writing to floppy part.

If you do ever look into writing images back to floppy, I'd be interested to learn if it works. If it doesn't I might have a few ideas to simplify the process.

@jandelgado
Copy link
Author

You probably already know this excellent M20 site: http://z80ne.com/m20/index.php?argument=sections/transfer/transfer.inc

Perhaps a Gotek Floppy Emulator might help (with the flashfloppy firmware. But I'm absolutely not sure if it's compatible with the M20 - needs to be checked first. An open source alternative to the KF could be a the Greaseweazle, check the link.

Also check the KF forums (https://forum.kryoflux.com/) they might answer your questions regarding writing disks.

@eberhab
Copy link

eberhab commented Jan 4, 2023

Thanks for the suggestions. The Greaseweazle does look interesting!

@eberhab
Copy link

eberhab commented Jan 28, 2023

Again, thanks a lot for pointing me towards the Greaseweazle. The timing could not have been better: keirf/greaseweazle#143

@jandelgado
Copy link
Author

Excellent! Good to know that it works

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