[comp.sys.cbm] Need 1541 info

byron@pyr.gatech.EDU (Byron A Jeff) (04/04/88)

I'm homebrewing a 68010 based system and I've decided I need some
form of mass storage. I want to use a 1541 for the following reasons:

1) I have two in my apartment.
2) The interface is simple and inexpensive.
3) The drive is intelligent (well kinda) so I don't have to write
   drivers from scratch to use it initially.

Unfortuantely the only info I have is the disk user's guide and
half remembered items from a C64 programmers reference manual that
I no longer have.

So I have a few questions about the drives. Please email all responses
to me. Thanks.

First the hardware:
1) What is the pinout for the DIN connector?
2) I remember that the interface is syncronous serial with handshaking.
   What are the signals (clock, data, handshaking etc.) that have to
   be sent to and received from the drive?
3) What is the maximum clock rate?

And software:
4) How does the software that speeds the data transfer rate work?
5) What is the format of the data transferred? All commands have a
   drive and channel number along with commands and data. How is
   this info packaged? How does the drive send back a block of
   data?
6) Is it possible to get a particular sector without having it in a file
   (random access) short of rewriting the DOS in the drive?

I'm sure there are also several books on the subject. Any references to
any that can answer any/all of my questions?

Thank you.

-- 
Byron A. Jeff
ICS Programming Lab, Georgia Tech, Atlanta GA 30332
Internet:	byron@pyr.gatech.edu
uucp:	...!{decvax,hplabs,ihnp4,linus,rutgers,seismo}!gatech!pyr!byron

elg@nuchat.UUCP (Eric Green) (04/10/88)

From article <5314@pyr.gatech.EDU>, by byron@pyr.gatech.EDU (Byron A Jeff):
> I'm homebrewing a 68010 based system and I've decided I need some
> form of mass storage. I want to use a 1541 for the following reasons:
> 
> 1) I have two in my apartment.
> 2) The interface is simple and inexpensive.
> 3) The drive is intelligent (well kinda) so I don't have to write
>    drivers from scratch to use it initially.

One reason you DON'T want to use a 1541: It's slow  as molasses.
> 
> First the hardware:
> 1) What is the pinout for the DIN connector?
Get the Programmer's Reference Guide. $14.95 at any bookstore. It has
that, plus, a waveform diagram of the synchronous bus protocol.
Get the Abacus book "Anatomy of the 1541" for more information about
that bus protocol. It is NOT a simple protocol, it takes a bit
of work to get it going right, and timing is extremely critical --
especially for output, where the C-64 has four "nop" instructions
providing a delay between one signal going low and waiting for
another to come high. Since input is synchronous, no problem
with timing there. The C64 Programmer's Reference Guide has a
listing of the timing parameters, and you can read the disassembly
in "Anatomy of the 1541" or "Anatomy of the Commodore 64" to get
the nitty-gritty of what those waveform diagrams stand for.

The basic complexity is that there are no handshaking lines. Thus,
the clock line and data line must be pressed into service for
handshaking purposes.
> 3) What is the maximum clock rate?

The 1541 can go faster only if you use a "fastloader"-type program
(which basically discards all the complicated handshaking of the
regular DOS, doing handshaking on a 256-byte basis instead of a 1-byte
basis, and using two bus lines to transfer data).
> 
> And software:
> 5) What is the format of the data transferred? All commands have a
>    drive and channel number along with commands and data. How is
>    this info packaged? How does the drive send back a block of
>    data?

To open a file, C64 DOS sets the ATN line, sends an "OPEN" code with
the device number, then a secondary address (ATN is still set right
now), then the filename (ATN still set). Then raises ATN back to
low level (ATN signals that the C-64 is sending a command). To
close a file, it sets the ATN, sends a "CLOSE" code. To read from
disk drive, sends a "TALK" code, then a secondary address, and
raises ATN back up. All input handshaking from the computer then
fetches bytes from the already-opened file with that secondary
address. A "CLRCHN" code unsets the "TALK" (this is sent with
ATN, of course). A "CLOSE" code, then a secondary address,
closes a file. Various wobblings of the handshaking, on input,
tells the computer it's hit EOF on the current input file.
I'm not up on actual byte-by-byte handshaking, at the moment....
I have a description somewhere around here, that I wrote up from
reading the disassemblies and the Abacus books, I'll type it in and
post it when I find it (includes the "fast" mode for 1571, too --
which isn't so fast, because it uses the exact same handshaking
method as the 1541, only speeding up actual transferance of the
byte itself).
> 6) Is it possible to get a particular sector without having it in a file
>    (random access) short of rewriting the DOS in the drive?
Oh certainly. Block-reads and block-writes have always been part of the
DOS, as far back as most can remember (that was the ONLY way that
the old Pet people could do random-access files).
> Byron A. Jeff
> uucp:	...!{decvax,hplabs,ihnp4,linus,rutgers,seismo}!gatech!pyr!byron

-- 
Eric Lee Green   P.O. Box 92191  Lafayette, LA 70509
uunet!nuchat!elg  "I survived the Flood of '88"

John_-_DeBert@cup.portal.com (04/18/88)

In answer to your questions about using the 1541 with your homebrew machine 
that you put out on USENET:

1. The transfer rate is listed by a couple of sources as 400 bits/seconds. But
a file of 254 bytes or less loads in less than one second. I suspect that they
mean bytes/second.

2. I am mailing data on the serial bus connector. Of the five available signals
one is not used - bus SRQ - by the 1541.
3. Books about the 1541:
  1. The New Anatomy of the 1541 Disk Drive
     By Lothar Englishce & Norbert Szczepanowski
     ISBN 0-916439-01-1
     Published by Abacus Software
                  P.O. Box 7211
                  Grand Rapids, MI 49510
Contaians assembly listings of 1541 operating system ROM routines & info on
using the 1541 with Commodore Computers.The assembly listings can be used to calculate the serial bus timing based on
the 1541's  1 MHz clock.

  2. InsIde Commodore DOS
     by Drs. Richard Immers, Ph.D. & Gerald G. Neufeld, Ph.D.
     ISBN 0-8359-3091-2
     Published by: Datamost
                   20660 Nordhoff St.
                   Chatsworth, CA 91311-6152
                   (818) 709-1202

Contains a very detailed description of the 1540/1541 operating system ROM
routines, including technical information on the operation of the drive. There
are no assembly listings.

The above books should give you plenty of information on the 1541, enough to
let you use the drive with your machine.
4. For info on the 1541 hardware:

  Commodore 1541 Troubleshooting & Repair Guide
  by Michael G. Peltier
  ISBN 0-672-22470-4
  published by: Howard W. Sams & Co.
                4300 West 62nd St
                Indianapolis, IN 46268

5. The bus interface uses open collector outputs with a 1.0K-ohm pullup.

6. Suggest checking the schematic in the back of the C-64 Programmers Reference
Guide for details on the bus interface.

Following is some other interesting & pertinent details:

 file: txt.filatr03   871129
 
 Commodore DOS file attributes
 
 Detail of the file attribute byte:
 
    7 6 5 4 3 2 1 0-> BIT                 NOTES:
    X X X X X X X X
    : : : : : : : :  (0 = low or clear)   1. A scratched file's attribute byte
    : : : : : : : :  (1 = high or set )       is: 00000XXX
    : : : : : : : :  (X = "don't care")   2. For some DOS versions, if a
    : : : : : : : :                           scratched file has it's lock
    : : : : : ------> FILE TYPE               set, it will appear in the
    : : : : :                                 directory as 'DEL<'. While it
    : : : : :    000 DEL Deleted file         may appear in the directory,
    : : : : :    001 SEQ Sequential file      the sectors assigned to the
    : : : : :    010 PRG Program file         file have been freed for use
    : : : : :    011 USR User file            by subsequent file writes.
    : : : : :    100 REL Relative file        Attempting to read such a file
    : : : : :    1XX --- Invalid              may cause the drive to hang, or
    : : : : :                                 cause some other problem that
    : : : ----------> Reserved                will require the drive to be
    : : :                                     reset or turned off.
    : : ------------> @ flag              3. DOS does not support the locking
    : :            1 replacement file         and unlocking of files. To lock
    : :                                       or unlock a file, the file
    : --------------> Lock flag               attribute byte must be directly
    :              1 Locked file              edited, using a utility such as
    :                                         DISK DOCTOR or by using direct
    ----------------> Valid flag              access commands. (For more
                   1 Valid file               information on direct access,
                                              see 'Inside Commodore DOS,'
                                              ISBN 0-8359-3091-2, by Datamost.
 


*nb CBM serial bus commands
*nb orig 5 Feb 1988


*cn1
Commodore Serial Bus Command Byte Structure
By J. DeBert
*cn0


Commodore's serial bus protocol attempts to follow the IEEE-488
 convention as closely as possible. The command byte convention
 necesarily differs somwhat, however, due to the bus structure.


 Command Byte:

          X X X X X X X X
          : : : : : : : :
          : : : - - - - - -> Device Address:
          : : :
          : : :               0 - 31 expressed in binary.
          : : :
          : : :
          - - - - - - - - -> Command:

                             000
                             001 Listen (except...
                                 00111111, the command to device 31
                                 to listen is used as general
                                 unlisten.)
                             010 Talk (with same exception as
                                 Listen command.)
                             011 secondary address (0-31)
                             100
                             101
                             110
                             111 close (secondary address)


The Commodore BASIC does not support the use of devices with an 
address from 0 to 3, however, the serial bus KERNAL routines may
be used to select such devices. KERNAL routines OPEN cannot be used
to access any device with an address less than 4 on the serial bus.

It is possible to expand on the serial bus system here using your
own KERNAL routines. 
*fp0



Hope this helps. Have fun,

John_-_DeBert@cup.portal.com
CIS: 75530,347
Telex: 6502636614
slug-express: P.O. Box 51754, Pacific Grove, CA, 93950-6754, USA, Terra