                                  FDCDEMO.ASM
                              By John M. B. Wilson
                                  06-Sep-1995


FDCDEMO is a program demonstrating how to program the floppy disk controller
found in the IBM PCs and clones (based on the NEC 765 chip and its successors).
FDCDEMO.ASM contains the assembly language source code (MASM or TASM) of both
the public-domain FDC driver code, and a simple command line interpreter which
demonstrates how to call the FDC driver, and allows the user to set all disk
parameters and read, write, and format disks using keyboard commands.  This may
in itself be useful for making image files of disks for emulators etc., or
writing boot images to disks for Linux etc.  (replacing RAWRITE.EXE).

Note that most PC floppy controllers have broken single density modes.  They
may still be able to read single density disks with a few retries, but they
can't write or format them.  However, FDCs based on the 37C65 series of chips
appear to work OK;  this chip is normally in a 40-pin DIP or 44-pin PLCC
package and has one 9.6 MHz crystal and one 16 or 32 MHz crystal (as opposed to
the more common chips that use a single 24 MHz crystal).  The bottom-
of-the-line ISA IDE/FDC controller from JDR Micro Devices was based on this
chip when I ordered mine, you might want to try them but of course nothing is
guaranteed, they might have changed the circuit since then.

The syntax of each command is given below.  More than one command may be on a
line if the commands are separated by blanks or tabs.  Commands may be
abbreviated to any unique abbreviation, except for FORMAT, PUT, and WRITE,
which must be spelled out in full (for safety, such as it is).  There are
commands to set each parameter individually, and then there are "macro"
commands to set all parameters for the standard DOS disk types, as well as a
few DEC and BBC types.  This program is not intended to be a sector editor, it
is only able to read and write either one sector at a time or one disk at a
time, and there is no way provided to edit the sector buffer contents.  If
necessary you can use SAVE and LOAD to move data between the sector buffer and
files (one sector at a time), and then use DEBUG.COM to edit the disk files,
but that would be hellish for a big job.  The SHOW command is a little
cumbersome, since all it can do is dump out the whole sector, which is more
than a screenful for 512- and 1024-byte sectors, so you need to be ready with
the Pause key.  I'm a little proud of the logic used by READ and WRITE to
figure out sector interleave (using the SECZER/SECINI/SECNXT routines), if
you're in a position where you need to read or write large sections of a disk
quickly using only a one-sector buffer you may want to take a look at that
code.  Otherwise the command-line front-end is basically throwaway fluff
intended simply to demonstrate the FDC code and help with testing disk
parameters.

John Wilson
11 Bank Street
Troy, NY  12180-4303
+1 (518) 271-1982
<wilsonj@alumni.rpi.edu>


COMMAND SUMMARY
======= =======

1.2MB

Set up all disk parameters for 1.2MB 80-track 15-sector DS HD floppies.

1.44MB

Set up all disk parameters for 1.44MB 80-track 18-sector DS HD floppies.

180KB

Set up all disk parameters for 180KB 40-track 9-sector SS DD floppies.
This command sets DOUBLESTEP on the assumption that you are using a 1.2MB
(i.e. 80-track) drive, if you're really using a 180KB or 360KB (i.e.
40-track) drive you must issue a SINGLESTEP command afterwards.

2.88MB

Set up all disk parameters for 2.88MB 80-track 36-sector DS ED floppies.

360KB

Set up all disk parameters for 360KB 40-track 9-sector DS DD floppies.
This command sets DOUBLESTEP on the assumption that you are using a 1.2MB
(i.e. 80-track) drive, if you're really using a 180KB or 360KB (i.e.
40-track) drive you must issue a SINGLESTEP command afterwards.

720KB

Set up all disk parameters for 720KB 80-track 9-sector DS DD floppies.

A:  B:  C:  D:

Select which floppy drive to use.  Default is B:.  Most systems support
only two drives so C: and D: may not do anything useful (they do not
select hard drive(s)).

BBC

Set up all disk parameters for BBC SSSD 40-track 10-sector floppies.

BYTES n

Set number of bytes per sector.  "n" is 128, 256, 512, or 1024.

CYLINDERS n

Set number of cylinders per disk.  Usually 40 or 80, but anything up to 256
is allowed.

DD

Set recording method to MFM (modified frequency modulation) for double
density (or HD or ED) disks.

DDINDD

Set data rate for double density (e.g. 360KB) disk in a double density
(i.e. 360KB) drive.  Note that if you are using a generic 360KB 40-track
drive, you will probably want to set SINGLESTEP too.

DDINHD

Set data rate for double density (e.g. 360KB) disk in a high density
(i.e. 1.2MB) drive.  Note that if the disk comes from a machine that uses
normal (e.g. 360KB) 40-track drives, you will probably want to set
DOUBLESTEP too.

DOUBLESTEP

Set the seek code to double head stepping, for using 40-track disks in
80-track drives.

DS

Set up for double-sided disks.  Equivalent to HEADS 2.

ED

Set data rate for extended density vertical format disk (i.e. 2.88MB).

FILL hh

Set the hex value of the fill byte to be used to blank out sectors during
a subsequent format operation.

FORMAT

Format and verify the disk using the currently set parameters.

GAP3 n

Set the size of gap 3 in the disk format (see any FDC chip's data sheets
if you don't understand what this means).

GAP3FORMAT n

Set the size of gap 3 written during a subsequent format operation (see
any FDC chip's data sheets if you don't understand what this means).

GET cyl [head] sec

Get a single sector into the sector buffer, from the specified decimal
cylinder, head, and sector location on the disk.  The head number is (must
be) omitted when using a single-sided disk (i.e. "SS" or "HEADS 1").

HD

Set data rate for high density disk (i.e. 1.2MB or 2.88MB).

HEADS n

Set number of heads, 1 or 2.  "SS" and "DS" commands are equivalent.

LOAD filename

Load the sector buffer from a file (containing data for a single sector).
Size is determined by the BYTES command.

MINSECTOR n

Sets the minimum sector number on each track.  Normally 1, but 0 on some
variants.

PUT cyl [head] sec

Put a single sector from the sector buffer, onto the specified decimal
cylinder, head, and sector location on the disk.  The head number is (must
be) omitted when using a single-sided disk (i.e. "SS" or "HEADS 1").

QUIT

Quit to DOS.

READ filename

Read entire contents of disk into an image file.  All sectors appear in
the file in the same order as on the disk.

RX01

Set up all disk parameters for DEC RX01 SSSD 77-track 26-sector floppies
(8", or 5.25" workalike disks).

RX02

Set up all disk parameters for DEC RX02 SSDD 77-track 26-sector workalike
floppies.

RX50

Set up all disk parameters for DEC RX50 SSDD 80-track 10-sector floppies.

SAVE filename

Save the sector buffer to a file (which receives data for a single sector).
Size is determined by the BYTES command.

SD

Set recording method to FM (frequency modulation) for single density disks.
N.B. most PC FDC chips can't write SD disks properly, but many can read
them given a few retries.

SECTORS n

Set number of sectors per track.

SHOW

Show contents of sector buffer in hex and ASCII.  Sorry, the program
doesn't let you edit it, you'll have to SAVE it to a file and edit it
there.

SINGLESTEP

Set the seek code to use normal head stepping, for anything other than
using 40-track disks in 80-track drives.

SS

Set up for single-sided disks.  Equivalent to HEADS 1.

STATUS

Display all disk settings.

WRITE filename

Write entire contents of disk from an image file.  All sectors appear in
the same order on the disk as in the file.
