1571-9.TXT rev 1a 96-11-06
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
     THIS DOCUMENT IS COPYRIGHT (C) 1988, 1996 BY HERNE DATA
     SYSTEMS LTD.  THE MATERIAL CONTAINED HEREIN MAY BE FREELY
     USED FOR PERSONAL INFORMATION ONLY.  IF YOU REPRODUCE IT,
     THIS COPYRIGHT NOTICE MUST NOT BE REMOVED.  THIS MATERIAL
     MAY NOT BE EXPLOITED FOR COMMERCIAL PURPOSES.
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Herne Data Systems Ltd., 
PO Box 250, Tiverton, ON N0G 2T0 CANADA.  
Voice/fax 519-366-2732, 
e-mail herne@herne.com, 
internet: http://www.herne.com

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


                      Burst Mode and BASIC 
 
 
 
This document deals with accessing MFM disks and interfacing
burst mode with BASIC and/or standard machine language KERNAL
input/output routines.  This is done by reading or writing
directly from or to the memory of the 1571 drive.  A number of
important 1571 memory locations are summarized in Table 12-1.  Of
course, this method will not be as fast as full burst mode. 
 
For example, to read the burst mode status byte, the following
statement can be used in a short BASIC program (remember INPUT#
and GET# can not be used in direct mode): 
 
OPEN 15,8,15,"M-R"+CHR$(94)+CHR$(0)+CHR$(1):GET#15,A$ 
     The ASCII value of A$ represents the burst mode status byte.

Bit 7 of the first byte of the burst mode command string (after
the "u0") controls the transfer of data between the computer and
the 1571.  If this bit is set, then data transfer occurs via
direct memory reads and writes to the 1571 RAM buffers.  One
sector worth of data for the burst mode READ/WRITE SECTOR
commands can be transferred using conventional BASIC or machine
language through the disk drive command channel.  When in burst
mode, buffers 0 to 3 (address $300 to $6FF) in the 1571 are used
for data storage.  Four buffers are allocated for transfer
because MFM sectors can be up to 1024 bytes long.  The buffer is
filled starting at address $300.  To read an MFM sector in BASIC,
the following command sequence can be used: 
 
1)  OPEN the command channel:   OPEN 15,8,15 
2)  Read sector into 1571 buffer: 
           PRINT#15,"U0"+CHR$(A)+CHR$(track#) 
                        +CHR$(sector#)+CHR$(1) 
 
    where "A" has a value of 192 to read a sector on side 0 
                          or 208 to read a sector on side 1 
                          of an MFM disk. 
 
3) Extract data from 1571 buffer with a memory-read: 
   PRINT#15,"M-R"+CHR$(BL)+CHR$(BH)+CHR$(0) 
 
   where BL is the low byte of the 1571 buffer address (0) and 
         BH is the high byte (starts at 3) of the address. 
 
The data can then be read with a GET#15,A$ in an indexed loop and
stored in C-128 memory with a command similar to POKE
nnn,ASC(A$).  Because only 256 bytes can be read this way at one
time, the M-R must be repeated at 1571 buffer addresses of $400,
$500, and $600, if the MFM sector size is 512 or 1024 bytes. 
 
4)  CLOSE the command channel:  CLOSE 15 
 
The reverse procedure is used to write data to an MFM disk: 
 
1) OPEN the command channel:  OPEN 15,8,15 
2) Transfer data from the C-128 to the 1571 with a memory-write: 
    PRINT#15,"M-W"+CHR$(BL)+CHR$(BH)+CHR$(32); 
Then PRINT#15 the data in an indexed loop.  Because the M-W
command is limited to a maximum of only 34 bytes at a time
(restricted by the length of the 1571 command input buffer), the
M-W must be repeated, incrementing the buffer pointers, BL and
BH, each time (as shown above it is easiest to work in increments
of 32 rather than 34 because 256=8 x 32) until one sector has
been transferred. 
3)  Write sector from buffer to disk: 
   PRINT#15,"U0"+CHR$(B)+CHR$(track#)+CHR$(sector#)+CHR$(1) 
   where "B" has a value of 194 to write to side 0 
                         or 210 to write to side 1 of an MFM
                         disk. 
4)  CLOSE command channel:  CLOSE 15 
 
 
Although the above examples have been given in BASIC for clarity,
the same procedure can be followed using equivalent machine
language KERNAL calls.  By using simple memory read and memory
write commands to access the RAM of the 1571 disk drive, even a
novice programmer can unlock the secrets of MFM disks with ease!  
The techniques outlined above can be used with any Commodore
computer, a C-64, Plus/4, even a VIC-20, to access the burst mode
commands on the 1571. 
 
 
 

TABLE 12-1:  Useful  1571 Memory Locations 
............................................................... 
   Address                 Function 
.............
Hex      Dec 
............................................................... 
24-29    36-41            ID field of last MFM sector accessed 
 24       36              track# 
 25       37              0=side 0, 1=side 1 
 26       38              sector# 
 27       39              sector size: 0=128 bytes, 1=256, 
                                       2=256, 3=512, 4=1024 
 28-29    40-41           CRC (checksum) 
 
37       55               Bus status byte: 
                          bit 0   1="file has only one sector" 
                              3   inverse status of clock line 
                              6   1=1571 bus mode, 0=1541 bus mode 
                              7   1=1571 operating mode (2 MHz) 
                                  0=1541 operating mode (1 MHz) 
 
3B       59               Last burst mode command number 
 
3C       60               MFM disk sector interleave 
 
5E       94               Burst status byte: 
                          bit 0-3 current error message number 
                                  returned by job loop 
                              7   1=MFM, 0=GCR 
 
5F       95               Current job code 
 
60       96               Smallest sector number on track 
 
61       97               Largest sector number on track 
 
67       103              Current track number 
 
97       151              Number of MFM sectors per track 
 
200-     512-             Input buffer for command strings  
 229      553             from computer 
 
274      628              Length of command string in input buffer 
 
300-     768-             RAM buffers: $300 is the start of 
 7FF      2047                         buffer for MFM sector 
                                       reads/writes 
 
1800-    6144-            6522 VIA# 1: Controls 1541 bus and 
 180F     6159                         electronics 
  
1C00-    7168-            6522 VIA# 2: Controls GCR recording 
 1C0F     7177                         electronics, motor, etc. 
 
2000-    8192-            WD 1770    : Controls MFM recording 
 2003     8195                         electronics 
 
4000-    16384-           6526 CIA# 1: Controls 1571 fast bus mode 
 400F     16399 
 
8000-    32768-           ROM 32K disk operating system 
 FFFF     65535 
 
 
