The Commodore 1541 Disk Drive User's Guide
The Commodore 1541 Disk Drive User's Guide
The Commodore 1541 Disk Drive User's Guide
*********
The Project 64 etext of the Commodore 1541 Disk Drive User's Guide,
first edition. Converted to etext by the Basic Bombardier. Some
errors in the original document were corrected in this etext.
*********
Note: To extract the ascii text basic programs all at once from this
etext use "tok64" by Cris Berneburg <[email protected]>. Or to
extract the uuencoded basic programs all at once use "uud" by Edwin
Kremer <edwin@zlotty>.
*********
INFORMATION TO USER
"WARNING: THIS EQUIPMENT HAS BEEN CERTIFIED TO COMPLY WITH THE LIMITS
FOR A CLASS B COMPUTING DEVICE, PURSUANT TO SUBPART J OF PART 15 OF
FCC RULES. ONLY PERIPHERALS (COMPUTER INPUT/OUTPUT DEVICES, TERMINALS,
PRINTERS, ETC.) CERTIFIED TO COMPLY WITH THE CLASS B LIMITS MAY BE
ATTACHED TO THIS COMPUTER. OPERATION WITH NON-CERTIFIED PERIPHERALS
IS LIKELY TO RESULT IN INTERFERENCE TO RADIO AND TV RECEPTION."
"THIS EQUIPMENT GENERATES AND USES RADIO FREQUENCY ENERGY AND IF NOT
INSTALLED PROPERLY, THAT IS, IN STRICT ACCORDANCE WITH THE
MANUFACTURER'S INSTRUCTIONS, MAY CAUSE INTERFERENCE TO RADIO AND
TELEVISION RECEPTION. IT HAS BEEN TYPE TESTED AND FOUND TO COMPLY
WITH THE LIMITS FOR A CLASS B COMPUTING DEVICE IN ACCORDANCE WITH THE
SPECIFICATIONS IN SUBPART J OF PART 15 OF FCC RULES, WHICH ARE
DESIGNED TO PROVIDE REASONABLE PROTECTION AGAINST SUCH INTERFERENCE IN
A RESIDENTIAL INSTALLATION. HOWEVER, THERE IS NO GUARANTEE THAT
INTERFERENCE WILL NOT OCCUR IN A PARTICULAR INSTALLATION. IF THIS
EQUIPMENT DOES CAUSE INTERFERENCE TO RADIO OR TELEVISION RECEPTION,
WHICH CAN BE DETERMINED BY TURNING THE EQUIPMENT OFF AND ON, THE USER
IS ENCOURAGED TO TRY TO CORRECT THE INTERFERENCE BY ONE OR MORE OF THE
FOLLOWING MEASURES:
1. GENERAL DESCRIPTION
[ Introduction........................................ 1 ]
[ Specifications...................................... 2 ]
3. USING PROGRAMS
Loading Pre-packaged Software....................... 1
LOAD................................................ 2
Directory of Disk................................... 3
Pattern Matching & Wild Cards....................... 4
SAVE................................................ 5
SAVE and replace.................................... 6
VERIFY.............................................. 7
DOS Support Program................................. 8
4. DISK COMMANDS
OPEN AND PRINT #.................................... 1
NEW................................................. 2
COPY................................................ 3
RENAME.............................................. 4
SCRATCH............................................. 5
INITIALIZE.......................................... 6
VALIDATE............................................ 7
DUPLICATE........................................... 8
Reading the Error Channel........................... 9
CLOSE...............................................10
5. SEQUENTIAL FILES
OPEN................................................ 1
PRINT# and INPUT#................................... 2
GET#................................................ 3
Reading the Directory............................... 4
6. RANDOM FILES
[ Explanation......................................... 1 ]
Opening a channel for random access data............ 2
BLOCK-READ.......................................... 3
BLOCK-WRITE......................................... 4
BLOCK-ALLOCATE...................................... 5
BLOCK-FREE.......................................... 6
[ Using Random Files.................................. 7 ]
BUFFER-POINTER...................................... 8
USER1 and USER2..................................... 9
7. RELATIVE FILES
[ Introduction........................................ 1 ]
Creating a relative file............................ 2
Using relative files................................ 3
Create a relative file.............................. 4
Summary............................................. 5
Modifying the program............................... 6
Appendices
A. Disk Command Summary
B. Error Messages
C. Demonstration Disk Programs
D. Disk Formats Tables
[ Index ]
[ Back Page ]
1. GENERAL DESCRIPTION
1.1 INTRODUCTION
If you are a beginner, the first few chapters will help you through
the basics of disk drive installation and operation. As your skill
and programming knowledge improves, you will find more uses for your
disk drive and the more advanced chapters of this manual will become
much more valuable.
No matter what level of expertise you have, your 1541 disk drive will
dramatically improve the overall capabilities of your computer system.
Before you get to the details of 1541 operation, you should be aware
of a few important points. This manual is a REFERENCE GUIDE, which
means that unless the information you seek directly pertains to the
disk or disk drive you will have to use your Commodore 64 or VIC 20
User's Guides and Programmer's Reference Guides to find programming
information. In addition, even though we give you step-by-step
instructions for each operation, you should become familiar with BASIC
and the instructions (called commands) that help you operate your
disks and drives. However, if you just want to use your disk drive
unit to load and save prepackaged software, we've included an easy and
brief section on doing just that.
Chapter five tells you how to work with SEQuential data files. These
are very similar to their counterparts on tape (but much faster).
Chapter six introduces the commands that allow you to work with random
files, to access any piece of data on the disk, and how you organize
the diskette into tracks and blocks. Chapter seven describes the
special relative files. RELative files are the best method of storing
data bases, especially when they are used along with sequential files.
Remember, you don't really need to learn everything in this book all
at once. The first four chapters are enough to get you going, and the
next couple are enough for most operations. Getting to know your disk
drive will reward you in many ways -- speed of operation, reliability,
and much more flexibility in your data processing capabilities.
1.2 SPECIFICATIONS
Included in the drive is circuitry for both the disk controller and a
complete disk operating system, a total of 16K of ROM and 2K of RAM
memory. This circuitry makes your Commodore 1541 disk drive an
"intelligent" device. This means it does its own processing without
taking any memory away from your Commodore 64 or VIC 20 computer. The
disk uses a "pipeline" software system. The "pipeline" makes the disk
able to process commands while the computer is performing other jobs.
This dramatically improves the overall throughput (input and output)
of the system.
Diskettes that you create in this disk drive are read and write
compatible with Commodore 4040 and 2031 disk drives. Therefore,
diskettes can be used interchangeably on any of these systems. In
addition, this drive can read programs created on the older Commodore
2040 drives.
The 1541 disk drive contains a dual "serial bus" interface. This bus
was specially created by Commodore. The signals of this bus resemble
the parallel IEEE-488 interface used on Commodore PET computers,
except that only one wire is used to communicate data instead of eight.
The two ports at the rear of the drive allows more than one device to
share the serial bus at the same time. This is accomplished by
"daisy-chaining" the devices together, each plugged into the next. Up
to five disk drives and one printer can share the bus simultaneously.
IC's:
6502 microprocessor
6522 (2) I/O, internal timers
Buffer
2114 (4) 2K RAM
PHYSICAL:
Dimensions
Height 97 mm
Width 200 mm
Depth 374 mm
Electrical:
Power Requirements
Voltage 100, 120, 220, or 240 VAC
Frequency 50 or 60 Hertz
Power 25 Watts
MEDIA:
Included with the 1541 disk drive unit, you should find a gray power
cable, black serial bus cable, this manual, and a demonstration
diskette. The power cable has a connection for the back of the disk
drive on one end, and for a grounded (three-prong) electrical outlet
on the other. The serial bus cable is exactly the same on both ends.
It has a 6-pin DIN plug which attaches to the VIC 20, Commodore 64 or
another disk drive.
Fig 1.A
+------------------------------------------+
| |
| +------------------------------------+ |
| | C= commodore ======== 1541 | |
| +------------------------------------+ |
| +----------------------------+ |
| | | |
+------| ========================== |------+
| | | | | |
| O | O +------+ | |
| | +-----|----------------------+ |
+--|---------|-----------------------------+
| |
| +-- DRIVE INDICATOR (RED LED)
| LIGHT: ACTIVE
| FLASH: ERROR
+-- POWER INDICATOR
(GREEN LED) LIGHT: POWER ON
Fig 1.B
+------------------------------------------+
| |
| +------------------------------------+ |
| | C= commodore ======== 1541 | |
| +------------------------------------+ |
| +----------------------------+ |
| | O----+------+ | |
+------| ====|===================== |------+
| | | | | | |
| O | ==| | | | |
| | +---|--\---+------+----------+ |
+--|-------|---|---------------------------+
| | |
| | +-- DOOR LEVER
| |
| +---- DRIVE INDICATOR (RED LED)
| LIGHT: ACTIVE
| FLASH: ERROR
+-- POWER INDICATOR
(GREEN LED) LIGHT: POWER ON
Your first step is to take the power cable and insert it into the back
of the disk drive (see figure 2). It won't go in if you try to put it
in upside down. Once it's in the drive, plug the other end into the
electrical outlet. If the disk drive makes any sound at this time,
please turn it off using the switch on the back! Don't plug any other
cables into the disk drive if the power is on.
Next, take the serial bus cable and attach it to either one of the
serial bus sockets in the rear of the drive. Turn off the computer,
and plug the other end of the cable into the back of the computer.
That's all there is to it!
+--------+
+---------------------------+ | +-----|---+
| ============= O O | | | O O----+
| | == === | | | #[]o | |
+------------------|--------+ | +---------+ |
Commodore 64 or | | VIC 1541 |
VIC20 Personal | Serial cable | Single Drive |
Computer +--------------+ Floppy Disk |
|
|
Serial cable |
+-----------------------+
|
| +---------------+
Fig 3. Floppy Disk | | |
Hookup | +-+-------------+
| | Printer
+---------+
2.3 POWERING ON
When you have all the devices hooked together, it's time to start
turning on the power. It is important that you turn on the devices in
the correct order. The computer should always be turned on last. As
long as the computer is the last one to be turned on, everything will
be OK.
First, make sure that you've removed all diskettes from the disk
drives before powering on.
After all the other devices have been turned on, only then is it safe
to turn on the computer. All the other devices will go through their
starting sequences. The printer's motor goes on, with the print head
moving halfway across the line and back again. The 1541 disk drive
will have its green light on, and then the red drive/error light will
blink, while your TV screen forms the starting picture.
Once the red drive/error light has stopped flashing on the drive, it
is safe to begin working with it.
+-------U-===-U-------+ /\
| | | | / \
| |_| | /_ _\ INSERT
| ___ | | | INTO
| O / \ | | | DRIVE
WRITE | | | | | |
PROTECT | \___/ | | |
NOTCH ------] | |____|
| |
+---------------------+
WHEN COVERED, DISKETTE
CONTENTS CANNOT BE ALTERED
There is different way to open and close the drive door, and
insertion/removal the diskette.
TYPE 1: figure 1.A -- To open the door on the drive, simply press the
door catch lightly, and the door will pop open. If there is a diskette
in the drive, it is ejected by a small spring. Take the diskette to
be inserted, and place it in the drive face-up with the large opening
going in first and write-protect notch to the left (covered with tape
in the demonstration disk) (see figure 4).
Press it in gently, and when the diskette is in all the way, you will
feel a click and the diskette will not spring out. Close the drive
door by pulling downward until the latch clicks into place. Now you
are ready to begin working with the diskette.
TYPE 2: figure 1.B -- To open the door on the drive, simply turn the
door lever counter-clockwise. Take the diskette to be inserted, and
place it in the drive face-up with the large opening going in first
and write-protect notch to the left (covered with tape in the
demonstration disk) (see figure 4).
Close the drive door by turning clockwise direction until the latch
clicks into place. Now you are ready to begin working with the disk.
Remember to always remove the diskette before the drive is turned off
or on. Never remove the diskette when the red drive light in on! Data
can be destroyed by the drive at this time!
2.5 USING WITH A VIC 20 OR COMMODORE 64
The 1541 Disk Drive can work with either the VIC 20 or Commodore 64
computers. However, each computer has different requirements for
speed of incoming data. Therefore, there is a software switch for
selecting which computer's speed to use. The drive starts out ready
for a Commodore 64. To switch to VIC 20 speed, the following command
must be sent after the drive is started (power-on or through
software):
3. USING PROGRAMS
Using your disk drive, carefully insert the preprogrammed disk so that
the label on the disk is facing up and is closest to you. Look for a
little notch on the disk (it might be covered with a little piece of
tape). If you're inserting the disk properly, the notch will be on
the left side. Once the disk is inside, close the protective gate by
pushing in on the level. Now type LOAD "PROGRAM NAME", 8 and hit the
RETURN key. The disk will make noise and your screen will say:
READY
When the word READY appears, just type RUN, and your prepackaged
software is ready to use.
3.2 LOAD
The BASIC commands used with Programs on the disk drive are the same
as the commands used on the Commodore DATASSETTE-tm recorder. There
are a few extra commands available for use with disks, however.
First of all, the program name must be given with each command. On a
DATASSETTE-tm, you could omit the program name in order to just LOAD
the first program there. On disk, since there are many different
programs that are equally accessible, the program name must be used to
tell the disk drive what to do. In addition, the disk drive's device
number must be specified. If no device number is listed, the computer
assumes the program is on tape.
The program name is a string, that is, either a name in quotes or the
contents of a given string variable. Some valid names are: "HELLO",
"PROGRAM #1", A$, NAME$.
The device# is preset on the circuit board to be #8. If you have more
than one drive, see chapter 9 on how to change the device number. This
book assumes that you're using device number 8 for the disk drive.
EXAMPLES
LOAD "TEST", 8
LOAD "Program # 1", 8
LOAD A$, J, K
LOAD "Mach Lang", 8, 1
NOTE: You can use variables to represent device numbers, commands, and
strings, as long as you've previously defined them in your program.
Your disk drive is a random access device. The read/write head of the
disk can go to any spot on the disk and access a single block of data
which holds up to 256 bytes of information. There are a total of 683
blocks on a single diskette.
The directory is a list of all programs and other files stored on the
disk. It is physically located right next to the BAM. There are 144
entries available in the directory, consisting of information like
file name and type, a list of blocks used, and the starting block.
The directory is automatically updated every time a program is SAVEd
or a file is OPENed for writing. BEWARE: the BAM isn't updated until
the file is CLOSED, even though the directory changes right away. If
a file isn't CLOSED properly, all data in that file will probably be
lost.
The directory can be LOADed into your memory just like a BASIC program.
Place the diskette in the drive, and type the following command:
LOAD "$", 8
SEARCHING FOR $
FOUND $
LOADING
READY.
Now the directory is in your computer's memory. Type LIST, and you'll
see the directory displayed on the screen. To print the directory on
your printer, type the following command line (in this example your
printer is plugged in as device# 4):
NOTE: When using CMD, the file must be closed using the command
PRINT#4: CLOSE 4. See the VIC 1525/1515 printer manual for detailed
explanation.
To read the directory without LOADing it into your memory, see the
section later in this chapter on the DOS Support Program. In addition,
to examine the directory from inside a BASIC program, see the section
in chapter 5 that deals with the GET# statement.
When using the tape deck, you can LOAD any program starting with
certain letters just by leaving off any following letters. Thus, the
command LOAD "T" will find the first program on the tape beginning
with the letter T. And LOAD "HELLO" will find the first program
beginning with the letters HELLO, like "HELLO THERE."
When using the disk, this option is called pattern matching, and there
is a special character in the file name used to designate this. The
asterisk (*) character following any program name tells the drive you
want to find any program starting with that name.
FORMAT FOR PATTERN MATCHING:
+-------------------+
LOAD name$ + "*", 8 | Can Be a String |
| | Variable Or The |
+--------------------+ Name Inside Quotes|
+-------------------+
In other words, if you want to LOAD the first program on the disk
starting with the letter T, use the command LOAD "T*", 8.
If only the "*" is used for the name, the last program accessed on the
disk is the one LOADed. If no program has yet been LOADed, the first
one listed in the directory is the one used.
You are probably familiar with the concept of wild cards in poker
where one card can replace any other card needed. On your 1541, the
question mark (?) can be used as a wild card on the disk. The program
name on the disk is compared to the name in the LOAD command, but any
characters where there is a question mark in the name aren't checked.
For instance, when the command LOAD "T?NT", 8 is given, programs that
match include TINT, TENT, etc.
When LOADing the directory of the disk, pattern matching and wild
cards can be used to check for a list of specific programs. If you
gave the command LOAD "$0:TEST", only the program TEST would appear in
the directory (if present on the disk). The command LOAD "$0:T*"
would give you a directory of all programs beginning with the letter T.
And LOAD "$0:T?ST" would give you all the programs with 4-letter names
having the first letter of T and the third and fourth letters ST. LOAD
"$0:T?ST*" would give names of any length with the correct first,
third, and fourth letters.
3.5 SAVE
When you tell the disk drive to SAVE a program, the DOS must take
several steps. First, it looks at the directory to see if a program
with that name already exists. Next it checks to see that there is a
directory entry available for the name. Then it checks the BAM to see
if there are enough blocks in which to store the program. If
everything is OK up to this point, the program is stored. If not, the
error light will flash.
3.6 SAVE AND REPLACE
If the first characters of the program name are the "@" sign followed
by a 0 and a colon (:), the DOS knows to replace any old program that
has that name with the program that is now in the computer's memory.
The drive checks the directory to find the old program, then it marks
that entry as deleted, and it next creates a new entry with the same
name. Finally, the program is stored normally.
For example, if a file was called TEST, the SAVE and replace command
would be SAVE "@0:TEST",8. If the name is in A$, the command is SAVE
"@0:" + A$, 8.
3.7 VERIFY
As a result of the DOS Support, the "/" key now takes the place of the
LOAD command. Just hit the slash followed by the progrwn name, and
the program is LOADed. When you use this method, you don't need to
use the LOAD command or the comma 8.
The "@" and ">" keys are used to send commands to the disk drive. If
you type @$ (or > $), the directory of the disk is displayed on the
screen, without LOADing into your memory! These keys also take the
place of the PRINT# (see chapter 4) to send commands listed in the
next chapter.
To read the error channel of the disk (when the red error light is
blinking), just hit either the @ or the > and hit RETURN Key. The
complete error message is displayed to you: message number, text, and
track and block numbers.
4. DISK COMMANDS
Up 'til now, you have explored the simple ways of dealing with the
disk drive. In order to communicate with the disk drive more fully,
you have to touch on the OPEN and PRINT# statements in BASIC (more
details of these commands are available in your VIC 20 or Commodore 64
User's Guide or Programmer's Reference Guide). You may be familiar
with their use with data files on cassette tape, where the OPEN
statement creates the file and the PRINT# statement fills the file
with data. They can be used the same way with the disk, as you will
see in the next chapter. But they can also be used to set up a
command channel. The command channel lets you exchange information
between the computer and the disk drive.
The file# can be any number from 1 to 255. This number is used
throughout the program to identify which file is being accessed. But
numbers greater than 127 should be avoided, because they cause the
PRINT# statement to generate a linefeed after the return character.
These numbers are really meant to be used with non-standard printers.
The channel# can be any number from 2 to 15. These refer to a channel
used to communicate with the disk, and channels numbered 0 and 1 are
reserved for the operating system to use for LOADing and SAVEing.
Channels 2 through 14 can be used for data to files, and 15 is the
command channel.
OPEN 15, 8, 15
OPEN 2, 8, 2
+-------------- FILE#
| +----------- DEVICE#
| | +-------- COMMAND CHANNEL#
| | |
OPEN A, B, C, Z$
|
+----- COMMAND$(text$)
The PRINT# command works exactly like a PRINT statement, except that
the data goes to a device other than the screen, in this case to the
disk drive. When used with a data channel, the PRINT# sends
information into a buffer in the disk drive, which LOADs it onto the
diskette. When PRINT# is used with the command channel, it sends
commands to the disk drive.
or
4.2 NEW
This command is necessary when using a diskette for the first time.
The NEW command erases the entire diskette, it puts timing and block
markers on the diskette and creates the directory and BAM. The NEW
command can also be used to clear out the directory of an already-
formatted diskette. This is faster than re-formatting the whole disk.
PRINT#15, "NEW:name,id"
or abbreviated as
PRINT#15, "N:name,id"
PRINT#15, "N:name"
The name goes in the directory as the name of the entire disk. This
only appears when the directory is listed. The ID code is any 2
characters, and they are placed not only on the directory but on every
block throughout the diskette. That way, if you carelessly replace
diskettes while writing data, the drive will know by checking the ID
that something is wrong.
4.3 COPY
This command allows you to make a copy of any program or file on the
disk drive. It won't copy from one drive to a different one (except
in the case of dual drives like the 4040), but it can duplicate a
program under another name on the drive.
or abbreviated as
The COPY command can also be used to combine two through four files on
the disk.
4.4 RENAME
This command allows you to change the name of a file once it is in the
disk directory. This is a fast operation, since only the name in the
directory must be changed.
or abbreviated as
PRINT#15, "R:MYRA=MYRON"
The RENAME command will not work on any files that are currently OPEN.
4.5 SCRATCH
This command allows you to erase unwanted files and programs from the
disk, which then makes the blocks available for new information. You
can erase programs one at a time or in groups by using pattem matching
and or wild cards.
If you check the error channel after a scratch operation (see below),
the number usually reserved for the track number now tells you how
many files were scratched. For example, if your directory contains
the programs KNOW and GNAW, and you use the command PRINT# 15,
"S:?N?W", you will scratch both programs. If the directory contains
TEST, TRAIN, TRUCK, and TAIL, and you command the disk to PRINT# 15,
"S:T*", you will erase all four of these programs.
4.6 INITIALIZE
or abbreviated as
4.7 VALIDATE
After a diskette has been in use for some time, the directory can
become disorganized. When programs have been repeatedly SAVED and
SCRATCHed, they may leave numerous small gaps on the disk, a block
here and a few blocks there. These blocks never get used because they
are too small to be useful. The VALIDATE command will go in and re-
organize your diskette so that you can get the most from the available
space.
Also, there may be data files that were OPENed but never properly
CLOSED. This command will collect all blocks taken by such files and
make them available to the drive, since the files are unusable at that
point.
There is a danger in using this command. When using random files (see
chapter 6), blocks allocated will be de-allocated by this command.
Therefore, this command should never be used with a diskette that uses
random files.
PRINT#15, "VALIDATE"
or abbreviated as
PRINT#15, "V"
4.8 DUPLICATE
Without the DOS Support Program, there is no way to read the disk
error channel without a program, since you need to use the INPUT#
command which won't work outside a program. Here is a simple BASIC
routine to read the error channel:
10 OPEN 15, 8, 15
20 INPUT# 15, A$, B$, C$, D$
30 PRINT A$, B$, C$, D$
Whenever you perform an INPUT# operation from the command channel, you
read up to 4 variables that describe the error condition. The first,
third, and fourth variables come in as numbers, and can be INPUT into
numeric variables if you like. The first variable describes the
error#$, where 0 is no error. The second variable is the error
description. The third variable is the track number on which the error
occurred, and the fourth and final is the block number inside that
track. (A block is also known as a sector)
Errors on track 18 have to do with the BAM and directory. For example,
a READ ERROR on track 18 block 0 may indicate that the disk was never
formatted.
4.10 CLOSE
It is extremely important that you properly CLOSE files once you are
finished using them. Closing the file causes DOS to properly allocate
blocks in the BAM and to finish the entry in the directory. If you
don't CLOSE the file, all your data will be lost!
CLOSE file#
You should also be careful not to CLOSE the error channel (channel#
15) before CLOSEing your data channels. The error channel should be
OPENed first and CLOSEd last of all your files! That will keep your
programs out of trouble.
If you close the error channel while other files are OPEN, the disk
drive will close them for you, but BASIC will still think they are
open (unless you CLOSE them properly), let you to try to write to them.
NOTE: If your BASIC program leads you into an effor condition, all
files are CLOSEd in BASIC, without CLOSEing them on your disk drive!
This is a very dangerous condition. You should immediately type the
statement OPEN 15, 8, 15, "I". This will re-initialize your drive and
make all your files safe.
5. SEQUENTIAL FILES
5.1 OPEN
The file number is the same as in all your other applications of the
OPEN statement, and it is used throughout the program to refer to this
particular file. The device# is usually 8. The channel# is a data
channel, number 2 through 14. It is convenient to use the same number
for both the channel# and file#, to keep them straight. The name is
the file name (no wild cards or pattern matching if you're creating a
write file). The type can be any of the ones from the chart below, at
least the first letter of each type. The direction must be READ or
WRITE, or at least the first letter of each.
PRG Program
SEQ Sequential
USR User
REL Relative
If the file already exists, you can use the replace option in the OPEN
statement, similar to the SAVE-and-replace described in chapter 3.
Simply add the @0: before the file's name in the OPEN statement.
OPEN 2, 8, 2, "@0:DATA,S,W"
The 0: should always precede the name of the file or the drive will
only allow you to use 2 of the available buffers.
The PRINT# command works exactly like the PRINT statement, except that
output is re-directed to the disk drive. The reason for the special
emphasis on the word exactly is that all the formatting capabilities
of the PRINT statement, as applies to punctuation and data types,
applies here too. It just means that you have to be careful when
putting data into your files.
The file# is the one from the OPEN statement when the file was created.
The data list is the same as the regular PRINT statement -- a list of
variables and/or text inside quote marks. However, you must be
especially careful when writing data so that it is as easy as possible
to read the data back again.
When using the PRINT# statement, if you use commas (,) to separate
items on the fine, the items will be separated by some blank spaces,
as if it were being formatted for the screen. Semicolons (;) don't
result in any extra spaces.
|eof| | | | | | | | | | | | | | |
-----+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---
char | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10| 11| 12| 13| 14| 15|...
The eof stands for the end-of-file marker. String data entering the
file goes in byte by byte, including spaces.
For instance, let's set up some variables with the statement A$=
"HELLO"; B$ = "ALL": C$ = "BYE". Here is a picture of a file after the
statement PRINT# 5, A$; B$; C$:
| H | E | L | L | O | A | L | L | B | Y | E | CR|eof|
-----+---+---+---+---+---+---+---+---+---+---+---+---+---+
char | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10| 11| 12| 13|
CR stands for the CHR$ code of 13, the carriage return, which is
PRINTed at the end of every PRINT or PRINT# statement unless there is
a comma or semicolon at the end of the line.
NOTE: Do not leave a space between PRINT and #, and do not try to
abbreviate the command as ?#. See the appendixes in the user manual
for the correct abbreviation.
FORMAT FOR INPUT# STATEMENT:
When using the INPUT# to read in data, the disk drive can't tell that
it's not supposed to be one long string. You need something in the
file to act as a separator. Characters to use as separators include
the CR, a comma or a semicolon. The CR can be added easily by just
using one variable per line on the PRINT# statement, and the system
puts one there automatically. The statement PRINT# 5, A$: PRINT# 5,
B$: PRINT# 5, C$ puts a CR after every variable being written,
providing the proper separation for a statement like INPUT#5, A$, B$,
C$. Or else a line like Z$ = ",":PRINT# 5, A$ Z$ B$ Z$ C$ will do the
job as well, and in less space. The file after that line looks like
this:
| H | E | L | L | O | , | A | L | L | , | B | Y | E | CR|eof|
-----+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
char | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10| 11| 12| 13| 14| 15|
| H | E | L | L | O | | | | A | L | L | | CR|eof|
-----+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
char | 1 | 2 | 3 | 4 | 5 | 6 |...| 11| 12| 13| 14|...| 23| 24|
You can see that much of the space in the file is wasted.
The moral of all this is: take care when using PRINT# so your data
will be in order for reading back in.
Numeric data written in the file takes the form of a string, as if the
STR$ function had been performed on it before writing it out. The
first character will be a blank space if the number is positive, and a
minus sign (-) if the number is negative. Then comes the number, and
the last character is the cursor right character. This format
provides enough information for the INPUT# statement to read them in
as separate numbers if several are written with no other special
separators. It is somewhat wasteful of space, since there can be two
unused characters if the numbers are positive.
5.3 GET#
The GET# retrieves data from the disk, one character at a time.
Data comes in byte by byte, including the CR, comma, and other
separating characters. It is much safer to use string variables when
using the GET# statement. You will get a BASIC error message if
string data is received where a number was requested, but not vice-
versa.
GET# 5, A$
GET# A, B$, C$, D$
| | |
+---+---+--- You can get more than 1 character at a time
GET# 5, A
Here is a sample program that will allow you to examine any file on
the disk:
The directory of the diskette may be read just fike a sequential file.
Just use $ for the file name, and OPEN 5, 8, 5, "$". Now the GET#
statement works to examine the directory. The format here is
identical to the format of a program file: the file sizes are the line
numbers, and names are stored as characters within quote marks.
Here's a program that lets you read the directory of the diskette:
+---------+----------+--------------------------------------------+
| BYTE | CONTENTS | DEFINITION |
+---------+----------+--------------------------------------------+
| 0 | 128+type | File type OR'ed with $80 (hexadecimal) to |
| | | indicate properly closed file. |
| | | TYPES: 0 = DELeted |
| | | 1 = SEQential |
| | | 2 = PROGram |
| | | 3 = USER |
| | | 4 = RELative |
+---------+----------+--------------------------------------------+
| 1,2 | | Track and sector of 1st data block. |
+---------+----------+--------------------------------------------+
| | | File name padded with shifted spaces. |
+---------+----------+--------------------------------------------+
| | | Relative file only: track and sector for |
| | | first side sector block. |
+---------+----------+--------------------------------------------+
| | | Relative file only: Record size. |
+---------+----------+--------------------------------------------+
| | | Unused. |
+---------+----------+--------------------------------------------+
| | | Track and sector of replacement file when |
| | | OPEN@ is in effect. |
+---------+----------+--------------------------------------------+
| | | Number of blocks in file: low byte, high |
| | | byte. |
+---------+----------+--------------------------------------------+
6. RANDOM FILES
[ 6.1 Explanation ]
Sequential files are fine when you're just working with a continuous
stream of data, but some jobs require more than that. For example,
with a large mailing list, you would not want to have to scan through
the entire list to find a person's record. For this you need some
kind of random access method, some way to get to any record inside a
file without having to read through the entire file first.
There are actually two different types of random access files on the
Commodore disk drive. The relative files discussed in the next
chapter are more convenient for data handling operations, although the
random files in this chapter have uses of their own, especially when
working with machine language.
Random files on the Commodore disk drive reach the individual 256-byte
blocks of data stored on the disk. As was mentioned in the first
chapter, there are a total of 683 blocks on the diskette, of which 664
are free on a blank diskette.
The diskette is divided into tracks, which are laid out as concentric
circles on the surface of the diskette. There are 35 different tracks,
starting with track 1 at the outside of the diskette to track 35 at
the center. Track 18 is used for the directory, and the DOS fills up
the diskette from the center outward.
Each track is subdivided into blocks. Because there is more room on
the outer tracks, there are more blocks there. The outer tracks
contain 21 blocks each, while the inner ones only have 17 blocks each.
The table below shows the number of blocks per track.
The DOS contains commands for reading and writing directly to any
track and block on the diskette. There are also commands for checking
to see which blocks are available, and for marking off used blocks.
When working with random access files, you need to have 2 channels
open to the disk: one for the commands, and the other for the data.
The command channel is OPENed to channel 15, just like other disk
commands you've encountered so far. The data channel for random
access files is OPENed by selecting the pound sign (#) as the file
name.
or optionally
+-------------------------+
OPEN 5,8,5,"#" <------+ DON'T CARE WHICH BUFFER |
+----------------+--------+
OPEN A,B,C,"#2" <-----+ PICK BUFFER #2 |
+----------------+
6.3 BLOCK-READ
or abbreviated as
PRINT#file#, "B-R:" channel; drive; track; block
This command will move one block of data from the diskette into the
selected channel. Once this operation has been performed, the INPUT#
and GET# statements can read the information.
SAMPLE PROGRAM TO READ BLOCK 2 FROM TRACK 18: (stores contents in B$)
6.4 BLOCK-WRITE
or abbreviated as
When the data is being put into the buffer, a pointer in the DOS keeps
track of how many characters there are. When you perform the BLOCK-
WRITE operation, that pointer is recorded on the disk. That is the
reason for the ST check in line 70 of the program above: the ST will
become non-zero when you try to read past the end-of-file marker
within the record.
10 OPEN 15,8,15
20 OPEN 5,8,5,"#":REM OPEN A RANDOM ACCESS CHANNEL
30 FOR L=1 TO 50
40 PRINT#5,"TEST"
50 NEXT
60 PRINT#15,"B-W:"5;0;1;1
70 CLOSE 5:CLOSE 15
6.5 BLOCK-ALLOCATE
In order to safely use random files along with regular files, your
programs must check the BAM to find available blocks, and change the
BAM to reflect that you've used them. Once you update the BAM, your
random files will be safe -- at least unless you perform the VALIDATE
command (see chapter 3).
How do you know which blocks are available to use? If you try a block
that isn't available the DOS will set the error message to number 65,
NO BLOCK, and set the track and block numbers to the next available
track and block number. Therefore, any time you attempt to write a
block to the disk, you must first try to allocate that block. If that
block isn't available, read the next block available from the error
channel and then allocate that block.
+-------+
| DRIVE |
10 OPEN 15,8,15 +--------+-------+
20 OPEN 5,8,5,"#" | | TRACK |
30 PRINT#5,"DATA" | +------+-------+
40 T=1:B=1 | | | BLOCK |
50 PRINT#15,"B-A:"0;T;B <--+-------+
60 INPUT#15,A,B$,C,D
70 IF A=65 THEN T=C:B=D:GOTO 50
80 PRINT#15,"B-W:"5;0;1;1
90 CLOSE 5:CLOSE 15
6.6 BLOCK-FREE
or abbreviated as
The only problem with what you've learned about random files so far is
that you have no way of keeping track of which blocks on the disk you
used. After all, you can't tell one used block on the BAM from
another. You can't tell whether it contains your random file, just
part of a program, or even sequential or relative files.
10 OPEN 15,8,15
20 OPEN 5,8,5,"#"
30 OPEN 4,8,4,"@0:KEYS,S,W"
40 A$="RECORD CONTENTS #"
50 FOR R=1 TO 10
70 PRINT#5,A$","R
90 T=1:B=1 <-------------------------+---------------------+
100 PRINT#15,"B-A:"0;T;B <-----------+ FIND NEXT AVAILABLE |
110 INPUT#15,A,B$,C,D <--------------+ TRACK & BLOCK |
120 IF A=65 THEN T=C:B=D:GOTO 100 <--+---------------------+
130 PRINT#15,"B-W:"5;0;T;B
140 PRINT#4,T","B
150 NEXT R
160 CLOSE 4:CLOSE 5:CLOSE 15
6.8 BUFFER-POINTER
The buffer pointer keeps track of where the last piece of data was
written. It also is the pointer for where the next piece of data is
to be read. By changing the buffer pointer's location within the
buffer, you can get random access to the individual bytes within a
block. This way, you can subdivide each block into records.
For example, let's take a hypothetical mailing list. The information
such as name, address, etc., will take up a total of 64 characters
maximum. We could divide each block of the random access file into 4
separate records, and by knowing the track, sector, and record numbers,
we can access that individual record.
or abbreviated as
PRINT#15, "B-P:" 5; 64
Here are versions of the random access writing and reading programs
shown above, modified to work with records within blocks:
10 OPEN 15,8,15
20 OPEN 5,8,5,"#"
30 OPEN 4,8,4,"@0:KEYS,S,W"
40 A$="RECORD CONTENTS #" +--------------------+
50 FOR R=1 TO 10 | SET POSITION |
60 FOR L=1 TO 4 | TO 1, 65, 129, 193 |
70 PRINT#15,"B-P:"5;(L-1)*64+1 <-----+--------------------+
80 PRINT#5,A$","L
90 NEXT L
100 T=1:B=1 +---------------------+
110 PRINT#15,"B-A:"0;T;B <-----------+ FIND NEXT AVAILABLE |
120 INPUT#15,A,B$,C,D <--------------+ TRACK & BLOCK |
130 IF A=65 THEN T=C:B=D:GOTO 110 <--+---------------------+
140 PRINT#15,"B-W:"5;0;T;B
150 PRINT#4,T","B
160 NEXT R
170 CLOSE 4:CLOSE 5:CLOSE 15
10 OPEN 15,8,15
20 OPEN 5,8,5,"#"
30 OPEN 4,8,4,"KEYS,S,R"
40 FOR R=1 TO 10
50 INPUT#4,T,B
60 PRINT#15,"B-R:"5;0;T;B
70 FOR L=1 TO 4
80 PRINT#15,"B-P:"5;(L-1)*64+1
85 INPUT#5,A$,X
90 IF A$<>"RECORD CONTENTS #" OR X<>L THEN STOP
95 PRINT R;A$;L
100 NEXT L
110 PRINT#15,"B-F:"0;T;B
120 NEXT R
130 CLOSE 4:CLOSE 5
140 PRINT#15,"S0:KEYS"
150 CLOSE 15
The USER commands are generally designed to work with machine language
(see chapter 8 for more on this). The USER1 and USER2 commands are
special versions of the BLOCK-READ and BLOCK-WRITE commands, but...
with an important difference: the way USER1 and USER2 work with the
buffer-pointer.
or
The BLOCK-WRITE command writes the contents of the buffer to the block
on the disk along with the value of the buffer-pointer. The USER2
command writes the buffer without disturbing the buffer-pointer value
already stored on that block of the diskette. This is useful when a
block is to be read in with BLOCK-READ, updated through the BUFFER-
POINTER and PRINT# statements, and then written back to the diskette
with USER2.
or
7. RELATIVE FILES
[ 7.1 INTRODUCTION ]
The DOS keeps track of the tracks and blocks used, and even allows
records to overlap from one block to the next. It is able to do this
because it establishes side sectors, a series of pointers for the
beginning of each record. Each side sector can point to up to 120
records, and there may be 6 side sectors in a file. There can be up
to 720 records in a file, and each record can be up to 254 characters,
so the file could be as large as the entire diskette.
+---------------------------------------------------------------+
| DATA BLOCK |
+---------------------------------------------------------------+
| BYTE | DEFINITION |
+--------+------------------------------------------------------+
| 0,1 | Track and block of next data block. |
+--------+------------------------------------------------------+
| 2-256 | 254 bytes of data. Empty records contain FF (all |
| | binary ones) in the first byte followed by 00 |
| | (binary all zeros) to the end of the record. |
| | Partially filled records are padded with nulls (00). |
+---------------------------------------------------------------+
| SIDE SECTOR BLOCK |
+--------+------------------------------------------------------+
| BYTE | DEFINITION |
+--------+------------------------------------------------------+
| 0,1 | Track and block of next side sector block. |
+--------+------------------------------------------------------+
| 2 | Side sector number. (0-5) |
+--------+------------------------------------------------------+
| 3 | Record length. |
+--------+------------------------------------------------------+
| 4,5 | Track and block of first side sector (number 0) |
+--------+------------------------------------------------------+
| 6,7 | Track and block of second side sector (number 1) |
+--------+------------------------------------------------------+
| 8,9 | Track and block of third side sector (number 2) |
+--------+------------------------------------------------------+
| 10,11 | Track and block of fourth side sector (number 3) |
+--------+------------------------------------------------------+
| 12,13 | Track and block of fifth side sector (number 4) |
+--------+------------------------------------------------------+
| 14,15 | Track and block of sixth side sector (number 5) |
+--------+------------------------------------------------------+
| 16-256 | Track and block pointers to 120 data blocks. |
+--------+------------------------------------------------------+
Upon execution, the DOS first checks to see if the file exists. If it
does, then nothing happens. The only way to erase an old relative
file is by using the SCRATCH command (see chapter 4), but not by using
the replace option.
The 2-byte format for the record number is needed because one byte can
only hold 256 different numbers, and we can have over 700 records in
the file. The rec# lo contains the least significant part of the
address, and the rec# hi is the most significant part. This could be
translated to the actual record number by the formula REC# = REC HI *
256 + REC LO.
If the record number is known, the high and low bytes can be
determined as follows:
EXAMPLE:
first name 12
last name 15
address line 1 20
address line 2 20
city 12
state 2
zip code 9
phone number 10
----------------------------
TOTAL 100
5 X=0
10 OPEN 1,8,15
20 OPEN 2,8,3,"0:MAILING LIST,L," + CHR$(108)
30 GOSUB 900
40 PRINT#1 "P" CHR$(3+96) CHR$(1) CHR$(0) CHR$(1)
50 GOSUB 900
60 IF E=50 THEN PRINT#2,1:GOTO 40
70 INPUT#2,X
75 PRINT X
300 STOP:CLOSE 1:CLOSE 2:END
900 INPUT#1,E,B$,C,D: REM ERROR SUBROUTINE
910 IF (E=50) OR (E<20) THEN RETURN
920 PRINT E;B$;C;D:STOP:RETURN
Error #50 which is checked in line 60 of the program is the RECORD NOT
PRESENT error, which means that the record hadn't been created yet.
Writing into the record will solve the problem. This error condition
must be watched carefully within your programs.
So far, all it does is create the file and the first record, but
doesn't actually put any data in it. Below is a greatly expanded
version of the program, to actually allow you to work with a mailing
list where the records are coded by numbers.
A more advanced version than this would keep track of the items by
"keys", to index the records. For example, you would probably want to
search for a record by name, or print out labels by zip code. For
this you would need a separate list of keys and record numbers,
probably stored in sequential files.
When working with a new relative file that will soon be very large, it
will save much time to create a record at the projected end of the
file. In other words, if you expect the file to be 1000 records long,
create a record# 1000 as soon as the file is created. This will force
the DOS to create all intermediate records, making later use of those
records much faster.
The program below, creates a relative file with 2 fields. The first
field starts in position 1 of the record and the second field starts
in position 25.
LINE 8: Create the file. Make room for records of 50 characters with
the CHR$(50). Use the Z$ as a file, input variable in LINE 6, you can
then press the f1 function key to create a file.
LINE 30: Point to the first character position of a file. P tells the
disk drive to point to the position in the record that corresponds to
the optional, CHR$(1).
NOTE: The POSITION command does NOT write anything to, or read
anything from the file. It just points to the position specified in
the record.
LINE 60: Use the PRINT# statement after the POSITION command to move
to character position 1, as specified in LINE 30 -- CHR$(1).
LINE 130: Specify the character position using the POSITION command.
Then follow it with LINE 160, the INPUT# statement.
7.5 SUMMARY
In this program, you press the f1 key and a RELative file is created
on disk. You can type RUN and press the f3 key to READ the previous
RELative file. If an error condition exists (flashing red light on
the disk drive) you can hit the RUN/STOP key, type RUN and press the
f5 key. This reads the ERROR CHANNEL from the drive, shows the error
number and message, as well as the track and sector of the error. It
then resets the drive for use. Later on the program asks if the file
should be printed. To Print the file, press the f7 key when prompted,
or press C to continue.
REMEMBER:
1) Before a file can be written to, or read from, a POSITION command
must be executed.
2) You must always use PRINT#1 with the POSITION command. This puts
your data under command channel control.
4) For convenience, use the FOR ... NEXT loop variable in the SECOND
character string, CHR$(I), of the POSITION command where I equals the
record number (see lines 20 and 30 of above program).
1) You can add more POSITION commands to make more fields within each
record. Remember to include the character position number as the last
CHR$, when adding fields.
The expert programmer can actually design routines that reside and
operate on the disk controller. DOS routines can be added that come
from the diskette. Routines can be added much the same way as the DOS
Support Program is "wedged" into your memory.
8.1 BLOCK-EXECUTE
This command will load a block from the diskette containing a machine
language routine, and begin executing it at location 0 in the buffer
until a RTS (ReTurn from Subroutine) command is encountered.
8.2 MEMORY-READ
There is 16K of ROM in the disk drive as well as 2K of RAM. You can
get direct access to these, or to the buffers that the DOS has set up
in the RAM, by using the MEMORY commands. MEMORY-READ allows you to
select which byte to read, through the error channel.
FORMAT FOR MEMORY-READ:
The next byte read using the GET# statement through channel# 15, the
error channel, will be from that address in the disk controller's
memory, and successive bytes will be from successive memory locations.
Any INPUT# to the error channel will give peculiar results when you're
using this command. This can be cleared up by any other command to
the disk (aside from a memory command).
8.3 MEMORY-WRITE
8.4 MEMORY-EXECUTE
Any routine in the DOS memory, RAM or ROM, can be executed with the
MEMORY-EXECUTE command.
Aside from the USER1 and USER2 commands discussed in chapter 6, and
the UI+ and UI- commands in chapter 2, the USER commands are jumps to
a table of locations in the disk drive's RAM memory.
By loading these locations with another jump command, like JMP $0520,
you can create longer routines that operate in the disk's memory along
with an easy-to-use jump table -- even from BASIC!
10 OPEN 15, 8, 15
20 PRINT# 15, "M-W" CHR$(119) CHR$(0) CHR$(2) CHR$(9+32)
CHR$(9+64)
If you have more than one drive, it's sensible to change the address
through hardware (see below). If you must, the procedure is easy. Just
plug in the drives one at a time, and change their number to the
desired new values. That way you won't have any conflicts.
It's an easy job to permanently change the device number of your drive
for use in multiple drive systems. The tools needed are a phillips-
head screwdriver and a knife.
If you want to use your 1541 disk drive to manipulate data directly
from assembly language you can use the information presented below.
SUBROUTINE
SETLFS = $FFBA ; set logical, physical & secondary addresses
SETNAM = $FFBD ; save length & address of filename
OPEN = SFFC0 ; open a logical file
CLOSE = $FFC3 ; close a logical file
CHKIN = $FFC6 ; open a channel for input
CLRCH = $FFCC ; clear all channels
BASIN = $FFCF ; get a byte from a file
BSOUT = $FFD2 ; output a character to the screen
For a more complete description as to what each routine does and what
parameters are passed to and from each routine, see your Commodore 64
or VIC-20 Programmer's Reference Guide.
INIT ; initialize:
LDA #$04 ; filename length
LDX #$00 ; low byte of filename address
LDY #$C0 ; high byte of filename address
JSR SETNAM ; save length & address of filename
LDA #$03 ; logical address
LDX #$08 ; device number
LDY #$00 ; secondary address (0 = read seq. file)
JSR SETLFS ; set logical, physical & secondary addresses
JSR OPEN ; open logical file
LDX #$03 ; set x-register to logical address
JSR CHKIN ; open input channel
your program info ; get data and print it one byte at a time
JSR BASIN ; get one byte
BEQ END ; if 0 then end of file or error
JSR BSOUT ; output character to the screen
JMP your prog. info ; loop
END
LDA #$03 ; set accumulator to logical address
JSR CLOSE ; close file
JSR CLRCH ; clear channels and reset defaults
RTS ; end of assembly language program
COMMAND
NEW "N
COPY "C:new file=:orginal file
RENAME "R:new name=old name
SCRATCH "S:file name
INITIALIZE "I
VALIDATE "V
DUPLICATE not for single drives
BLOCK-READ "B-R:" channel; drive; track; block
BLOCK-WRITE "B-W:" channel; drive; track; block
BLOCK-ALLOCATE "B-A:" drive; track; block
BLOCK-FREE "B-F:" drive; track; block
BUFFER-POINTER "B-P:" channel; position
USER1 and USER2 "Un:" channel; drive; track; block
POSITION "P" CHR$(channel#) CHR$(rec#lo) CHR$(rec#hi)
CHR$(position)
BLOCK-EXECUTE "B-E:" channel; drive; track; block
MEMORY-READ "M-R" CHR$(address lo) CHR$(address hi)
MEMORY-WRITE "M-W" CHR$(address lo) CHR$(address hi)
CHR$(#chars) "data"
MEMORY-EXECUTE "M-E" CHR$(address lo) CHR$(address hi)
USER Commands "Un"
20: READ ERROR (block header not found) -- The disk controller is
unable to locate the header of the requested data block. Caused by an
illegal block number, or the header has been destroyed.
21: READ ERROR (no sync character) -- The disk controller is unable to
detect a sync mark on the desired track. Caused by misalignment of the
read/writer head, no diskette is present, or unformatted or improperly
seated diskette. Can also indicate a hardware failure.
22: READ ERROR (data block not present) -- The disk controller has
been requested to read or verify a data block that was not properly
written. This error message occurs in conjunction with the BLOCK
commands and indicates an illegal track and/or block request.
23: READ ERROR (checksum error in data block) -- This error message
indicates that there is an error in one or more of the data bytes. The
data has been read into the DOS memory, but the checksum over the data
is in error. This message may also indicate grounding problems.
24: READ ERROR (byte decoding error) -- The data or header as been
read into the DOS memory, but a hardware error has been created due to
an invalid bit pattern in the data byte. This message may also
indicate grounding problems.
28: WRITE ERROR (long data block) -- The controller attempts to detect
the sync mark of the next header after writing a data block. If the
sync mark does not appear within a predetermined time, the error
message is generated. The error is caused by a bad diskette format
(the data extends into the next block), or by hardware failure.
30: SYNTAX ERROR (general syntax) -- The DOS cannot interpret the
command sent to the command channel. Typically, this is caused by an
illegal number of file names, or pattems are illegally used. For
example, two file names may appear on the left side of the COPY
command.
31: SYNTAX ERROR (invalid command) -- The DOS does not recognize the
command. The command must start in the first position.
32: SYNTAX ERROR (invalid command) -- The command sent is longer than
58 characters.
34: SYNTAX ERROR (no file given) -- the file name was left out of a
command or the DOS does not recognize it as such. Typically, a colon
(:) has been left out of the command,
39: SYNTAX ERROR (invalid command) -- This error may result if the
command sent to command channel (secondary address 15) is unrecognized
by the DOS.
50: RECORD NOT PRESENT -- Result of disk reading past the last record
through INPUT#, or GET# commands. This message will also occur after
positioning to a record beyond end of file in a relative file. If the
intent is to expand the file by adding the new record (with a PRINT#
command), the error message may be ignored. INPUT or GET should not
be attempted after this error is detected without first repositioning.
52: FILE TOO LARGE -- Record position within a relative file indicates
that disk overflow will result.
60: WRITE FILE OPEN -- This message is generated when a write file
that has not been closed is being opened for reading.
61: FILE NOT OPEN -- This message is generated when a file is being
accessed that has not been opened in the DOS. Sometimes, in this case,
a message is not generated; the request is simply ignored.
62: FILE NOT FOUND -- The requested file does not exist on the
indicated drive.
63: FILE EXISTS -- The file name of the file being created already
exists on the diskette.
64: FILE TYPE MISMATCH -- The file type does not match the file type
in the directory entry for the requested file.
66: ILLEGAL TRACK AND SECTOR -- The DOS has attempted to access a
track or block which does not exist in the format being used. This
may indicate a problem reading the pointer to the next block.
71: DIRECTORY ERROR -- The BAM does not match the internal count.
There is a problem in the BAM allocation or the BAM has been
overwritten in DOS memory. To correct this problem, reinitialize the
diskette to restore the BAM in memory. Some active files may be
terminated by the corrective action. NOTE: BAM = Block Availability
Map
72: DISK FULL -- Either the blocks on the diskette are used or the
directory is at its entry limit. DISK FULL is sent when two blocks are
available on the 1541 to allow the current file to be closed.
73: DOS MISMATCH (73, CBM DOS V2.6 1541) -- DOS 1 and 2 are read
compatible but not write compatible. Disks may be interchangeably
read with either DOS, but a disk formatted on one version cannot be
written upon with the other version because the format is different.
This error is displayed whenever an attempt is made to write upon a
disk which has been formatted in a non-compatible format. (A utility
routine is available to assist in converting from one format to
another.) This message may also appear after power up.
74: DRIVE NOT READY -- An attempt has been made to access the 1541
Single Drive Floppy Disk without any diskettes present in either drive.
1. DIR
2. VIEW BAM
3. DISPLAY T & S
4. CHECK DISK
5. PERFORMANCE TEST
[ Outer Rim ]
------------------------------------
Track 1
----------------------------------
--------------------------------
Track 18 (Directory)
------------------------------
----------------------------
Track 35 O Index Hole
--------------------------
[ Center Hub ]
+------+----+------+------+----+----+-------+-------+------+-
| SYNC | 08 | ID 1 | ID 2 | TK | BL | CHECK | GAP 1 | SYNC |
| | | | | | | SUM | | | <-+
+------+----+------+------+----+----+-------+-------+------+- |
|
+----------------------- (CONTINUED) --------------------------+
|
| -+----+------+------+-----------+-------+-----+
| | 07 | BYTE | BYTE | 254 BYTES | CHECK | GAP |
+-> | | 0 | 1 | OF DATA | SUM | |
-+----+------+------+-----------+-------+-----+
SEQUENTIAL FORMAT
+---------+-------------------------------------------------------+
| BYTE | DEFINITION |
+---------+-------------------------------------------------------+
| 0,1 | Track and sector of next sequential data block. |
+---------+-------------------------------------------------------+
| 2-256 | 254 bytes of data with carriage returns as record |
| | terminators. |
+---------+-------------------------------------------------------+
DIRECTORY FORMAT
+---------------------------------------------------------+
| Track 18, Sector 1 for 1540/1541 |
+---------+-----------------------------------------------+
| BYTE | DEFINITION |
+---------+-----------------------------------------------+
| 0,1 | Track and sector of next directory block. |
+---------+-----------------------------------------------+
| 2-31 | *File entry 1 |
+---------+-----------------------------------------------+
| 34-63 | *File entry 2 |
+---------+-----------------------------------------------+
| 66-95 | *File entry 3 |
+---------+-----------------------------------------------+
| 98-127 | *File entry 4 |
+---------+-----------------------------------------------+
| 130-159 | *File entry 5 |
+---------+-----------------------------------------------+
| 162-191 | *File entry 6 |
+---------+-----------------------------------------------+
| 194-223 | *File entry 7 |
+---------+-----------------------------------------------+
| 226-255 | *File entry 8 |
+---------+-----------------------------------------------+
+---------+----------+--------------------------------------------+
| BYTE | CONTENTS | DEFINITION |
+---------+----------+--------------------------------------------+
| 0 | 128+type | File type OR'ed with $80 (hexadecimal) to |
| | | indicate properly closed file. |
| | | TYPES: 0 = DELeted |
| | | 1 = SEQential |
| | | 2 = PROGram |
| | | 3 = USER |
| | | 4 = RELative |
+---------+----------+--------------------------------------------+
| 1,2 | | Track and sector of 1st data block. |
+---------+----------+--------------------------------------------+
| | | File name padded with shifted spaces. |
+---------+----------+--------------------------------------------+
| | | Relative file only: track and sector for |
| | | first side sector block. |
+---------+----------+--------------------------------------------+
| | | Relative file only: Record size. |
+---------+----------+--------------------------------------------+
| | | Unused. |
+---------+----------+--------------------------------------------+
| | | Track and sector of replacement file when |
| | | OPEN@ is in effect. |
+---------+----------+--------------------------------------------+
| | | Number of blocks in file: low byte, high |
| | | byte. |
+---------+----------+--------------------------------------------+
A
Assembly Language, 10
B
BLOCK-ALLOCATE, 6.5, A
Block Availability Map (BAM), 3.3, 5.4, 6.1, 6.5, D
BLOCK-EXECUTE, 8.1, A
BLOCK-FREE, 6.6, A
BLOCK-READ, 6.1, 6.3, 6.7, 6.8, 6.9, A
Blocks, 1.2, 6.9, D
BLOCK-WRITE, 6.4, 6.7, 6.9, A
Buffer, 1.2, 6.8
BUFFER-POINTER, 6.8, A
C
CLOSE, 4.10
COPY, 4.3, A
D
Data Channel, 6.2
Demonstration Disk Programs, C
Device Number, 5.1, 9.1-9.2
Directory, 3.3, 5.4, D
Disk Controller, 8.1-8.5
Disk Operating System (DOS), 3.3-3.4, 3.8, 5.4, 6.1, 6.5, 6.8, B
DOS Support Program, 3.8, 4.9
Drive Speeds, 2.5
DUPLICATE, 4.8, A
E
End-of-file (EOF), 5.2
Error Channel, 4.9, 7.5, 8.2
Error Messages, B
F
FORMAT (see NEW)
G
GET#, 5.3
I
INITIALIZE, 4.6, 8.3, A
INPUT#, 4.9, 5.2, 7.4
L
LOAD, 1.1 3.2-3.5, 3.7-3.8, 4.1, 4.10
M
Mailing List Program, 7.3
MEMORY-EXECUTE, 8.4, A
MEMORY-READ, 8.2, A
MEMORY-WRITE, 8.3, A
N
NEW, 4.2, A
O
Open, 4.1, 5.1
P
Pattem Matching, 3.4
POSITION, 7.3-7.4, A
PRINT#, 4.1, 5.2
Program Files (PRG), 5.1, 5.4, C
R
Random Files, 1.2, 6.1-6.8
Relative Files (REL), 1.1-1.2, 5.1, 6.8-6.9, 7.1-7.6, D
RENAME, 4.4, A
S
SAVE, 1.1, 3.5-3.6, 4.7
SCRATCH, 4.5, 4.7, A
Sectors, 1.2, D
Sequential Files (SEQ), 1.1-1.2, 5.1-5.3, 5.4, 6.7, D
Serial Bus Interface, 1.2, 2.3, 2.5
Side Sector, 7.1-7.2
Specifications, 1.2
T
Tracks, 6.1, 6.8, D
U
USER, 8.5, A
User Files (USR), 5.1, 5.4, 6.9
V
VALIDATE, 4.7, A
VERIFY, 3.7, A
W
Wedge, 3.8, 8
Wild Cards, 3.4
Commodore AG (Schweiz)
Aeschenvorstadt 57
4010 Basel, Switzerland
[ BACK PAGE ]
DISK DRIVES
MODEL SFD 1001 -- 1 Megabyte double sided, floppy disk drive. Uses
double density, double sided diskettes. IEEE interface.
MODEL 2031LP -- Media compatible with 1541 and 4040 diskettes. 170 K
of memory per single side disk. Rugged and stylish housing. IEEE
interface.
PRINTERS
PRINTER/PLOTTER
MODEL 1520 -- Four color, printer/plotter for all graphic needs. Print
bar graphs...create pie charts...plot time graphs. High quality
printing in a variety of styles and sizes. Great for graphic artists.
MODEMS
_____
/ ___|___
| / |__/ c o m m o d o r e
| \___|__\ C O M P U T E R
\_____|
Printed in Japan
*********
End of the Project 64 etext of the Commodore 1541 Disk Drive User's
Guide, first edition.
*********