#!/bin/bash # 2011-06-02 Johann E. Klasek johann AT klasek at # # cpmread - read a CP/M image from floppy # # usage: ./cpmread # # Parameters: asked interactively # # Commands: # fdrawcmd (from fdutils package) # # Files: # image file (will be overwritten!) # /dev/fdX floppy device # log Error transcript in case of uncomplete tracks. # # array holding names of devices corresponding to drive 0..3 dev=("/dev/fd0" "/dev/fd1" "/dev/fd2" "/dev/fd3") clear cat < 3 )) ; do read -p "Floppy drive (0,1,2,3): " drive [ -z "$drive" ] && drive=-1 done echo Prepare the floppy in ${dev[$drive]} and enter the name of an read -p "image file. If the file exists it will be overwritten: " image # clear the image file. You may want to test here # and prompt to make sure it's okay.... cat /dev/null >$image # This will (??) reset the controller in case a previous command # left things in a bad/unknown state. floppycontrol --resetnow 0 ${dev[$drive]} # set a fd path for fdrawcmd. Unfortunately, this delays for about 15 (??) # seconds. If we don't do this the fdrawcmd will seek to track 0 each loop # which adds up to lots more time than the delay. echo Opening device ${dev[$drive]} ... could take up to 60 seconds exec 4<${dev[$drive]} # initialize error log cp /dev/null log # cleanup at termination trap "rm -f out.err" 0 echo "Now reading data with fdrawcmd" # the while loop counts the tracks (( tr = track1 - 1 )) while (( ( tr += 1 ) < tracks )); do # Do each side. The variable $sd loops between side 0/1. # Note that this value is shifted left2 and ored with the drive # number as the first parm. sd=-1 while (( (sd += 1) < sides )); do cmd="fdrawcmd read $((sd<<2 | drive )) $tr $sd $sect1 \ $sectcode $numsect 0x1b 0xff need_seek \ rate=$rate drive=4 length=$trlength track=$((tr * stepsize)) " echo $cmd $cmd >>$image 2>out.err cat out.err grep "remaining= 0" out.err >/dev/null if [ $? -ne 0 ]; then echo "#### ERROR" >>log echo $cmd >>log cat out.err >>log fi # This moves the cursor back 10 lines so that the output of # fdrawcmd overwrites itself. tput cuu 11 done done exec 4