COMMODORE TI LtTI DISK El D '" DRIVE users guide
COMMODORE 1541-II DISK DRIVE USER'S GUIDE This manual contains copyrighted and proprietary information. No part of this publication may be reproduced , stored in a retrieval system, or transmitted in any form or by any means, electronic , mechanical, photocopying, recording or otherwise, without the prior written permission of Commodore Electronics Limited.
TABLE OF CONTENTS Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The advantages of a disk drive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Features of the 1541 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . How to use this book . . • . . . . • . . . . . . . . . . . . . . . . . . . . . . . • . . . . . . . . . . • Basic Operating Steps. . . . . . . . . • . . . .
PART TWO: GUIDE TO ADVANCED OPERATION AND PROGRAMMING Chapter 4: Commands •.•••••••••.•..•..••••••••••••••.•••.••••••••••••• 25 Command Channel ••.......••.••••••••••.•••••.•..•••••••••••.. 25 Reading the Error Channel •.•..••.••••••••.•••••••••..••••.•.••• 26 Housekeeping hints ••.•••.••••••.••.•.....••.•••.....••••••..... 28 Saving programs •..•.....••.......•..••••••..•.....•••.....•... 29 Save with replace •••••..••...•••• ,. ....••..•.•..•...•..•....•.•. 30 Verifying programs .....•..••....•..•...•..•.
INTRODUCTION The 1541 disk drive greatly increases the speed , storage capacity, flexibility and reliability of your Commodore computer. As you use the 1541 disk drive , you will appreciate its superiority to the cassette recorder you may have useq before and to disk drives offered for other brands of computers . The 1541-D disk drive ia fully compattl>le with the commodore 1541 disk drive, therefore we may often omit the "-II" auftlx throughout the remainder of thia manual.
Another key advantage of the Commodore 1541 over disk drives for other computers is its dynamic allocation of disk space. Many other disk drives make you think about every program you save . Where can I store it on this diskette, and should I pack the disk first? (Packing is the process of moving all the leftover work areas to the end of the diskette's storage space.) All this is handled automatically on Commodore disk drives.
PART 1: GUIDE TO OPERATION SPECIFICATIONS OF THE 1541 DISK DRIVE CHAPTER 1 DISK DRIVE STORAGE Total formatted capacity Maximum Sequential file size Maximum Relative file size Records per file Fil~s per diskette Tracks per diskette Sectors per track Sectors per diskette Bytes per sector 174848 bytes per diskette 168656 bytes per diskette 167132 bytes per diskette 65535 144 35 17-21 683 total 664 free for data 256 INTEGRATED CIRCUIT CHIPS USED 1 6502 Used for overall control 2 6522 VIA Used for input an
EMPTY THE DRIVE First, it is very important to be sure nothing is inside the disk drive . If you tum the power off or oil with a diskette_in the drive, you could lose its contents and have to rerecord it . Since you wouldn't like having to do that, always check to be sure nothing is inside the drive before turning it off or on . When you first unpack the disk drive, you will find a cardboard shipping spacer inside.
TROUBLESHOOTING GUIDE Symptom Cause Remedy Red indicator light on the 1541 not on Disk drive not turned on Make sure power switch is in the "on" position Power supply not plugged in Check both cords of power cable to be sure they are fully inserted Power off to wall outlet Replace fuse or reset circuit breaker in house The disk drive is failing its power-on self-test Tum the system·off for a minute and try again . lf it repeats, try again with the serial bus disconnected .
SIMPLE MAINTENANCE TIPS TROUBLESHOOTING GUIDE Symptom Cause Remedy Prograrlls won't load, and computer says "Dl;lVICE NOT PRESENT ERROR ." Serial bus cable not well connected, or disk not turned on. Be sure serial bus cable is correctly inserted and disk drive is turned on Programs won't load, but computer and disk drive give no error message. Anolher device on the serial bus may be interfering. Unplug all other devices on the serial bus. If that cures it, plug them in one at a time.
SAFETY RULES FOR DISKETTE CARE CHAYfER2 DISKETIES WHAT IS A DISKETTE? Before we actually begin using the drive, let' s take a moment to look at the Test/Demo diskette packed with the disk drive. Tc;> do this, grasp it by the label, which should be sticking out of the paper jacket. Then pull it out of the jacket which keeps it free of dust and other contaminants. (Save the jacket; the diskette should always be kept in its jacket except when actually in use in the disk drive.
SAFJ;TY RULES FOR REMOVING DISKETIES Always remove diskettes before turning a drive off or. on. If a diskette were in place and the door closed at power on or off, you could lose part or all of the data on that diskette. Similarly, do not remove a diskette from its drive when the green drive activity light is on! That light only glows when the drive is actually in use. Removing the diskette with it on may result in your losing information currently being written to the diskette .
number of the 1541, normally 8; the drive number, always 0 on the 1541; any desired name for the diskette, up to 16 characters in length, followed by a 2 character diskette ID number. The Close command is often optional; just don't Open that same file again without Closing it the first time. EXAMPLE: OPEN 15,8, 15, "NO:MY FIRST DISK,01": CLOSE 15 Note: the chattering or thumping noise you hear just after the disk New command begins is entirely normal.
CHAPTER3 DIRECTORIES READY. e •HOW TO USE" •How PART 2• 12 PART 3• •How 12 •v1c-20 WEDGE" 4 •c-64 WEOGE• •oos ~. 1 • •PRINTER TEST• 9 •DISK ADDR CHANGE" 4 •VIEW BAM• 6 •cHECK DISK• 4 •o ISPL.A'lf T&S • 14 •PERFORMAl'CE TEST• 9 •SEQ.FIL.E.DEMO• ~ •so.BACKUP.C16• 7 •so.BACKUP.PL.US4• 7 ·sD.BACKUP.C64• 10 •PRINT.64.UTIL.• 7 •PRINT.C16.UTIL." 7 •pRINT.+4.UTIL.• 7 •cs4 BASIC DEMO· 30 •+4 BASIC DEMO• 3S •L.OAD ADDRESS• 8 •uNSCRATCH• 7 •HEADER CHAJIGE• ~ •REL.FILE.OEMO• 10 426 BLOCKS FREE.
The rest of the directory contains one line per program or file, each line supplying three pieces of information about its subject. At the left end of each line is the size of that line's file in blocks (or sectors) of 256 characters. Four blocks are equivalent to I K (I 024 characters) of RAM (read/write) memory inside the computer. The middle of each directory line contains the name of the file, enclosed in quotation marks.
LOAD"$0:* = S" ,8 EXAMPLES : FORMAT FOR PATTERN MATCHING: will load a directory of all sequential files, while the Basic 3.5 command: DIRECTORY," A*= R'' "C-64*" "expression*" or will display a directaF¥ consisting only of relative files beginning with the letter ''A''.
PART TWO: GUIDE TO ADVANCED OPERATION AND PROGRAMMING CHAPTER4 COMMANDS COMMAND CHANNEL Commodore disk drives expect to receive many of their instructions over what is known as a command channel. Although we will not explain the concepts behind it until Chapter 6, we will learn it to use it now, so you can give your 1541 disk the commands it needs to do some essential chores. To instruct the command channel, we use a Basic Open statement to the disk, with a secondary address of 15.
FORMAT FOR SENDING DISK COMMANDS PRINT DS$ or abbreviate it to OPEN 15,device #,15,commandS ?DS$ or either in immediate mode or within a program, and the current error status message of the disk will be displayed on the screen. A message will be displayed whether there is an error or not, but if there was an error, printing its message will also clear it from the disk memory and turn off the error light on the disk drive.
HOUSEKEEPING HINTS Hint #1: It is best to open file IS once at the very start of a program, and only close it a1 the end of the program, after all other files have already been closed. Do this because closing the command channel automatically closes all other disk files . By opening once a1 the start, the file is open whenever needed for disk commands elsewhere in the program Closing it at the end makes sure all disk files are properly closed without interrupting ani other file commands .
SAVE WITH" REPLACE OPTION If a file already exists, it can't be saved again because the disk only allows one copy of any given file name per diskette. It is possible to get around this problem using the Rename and Scratch commands described later. However, if all you wish to do is replace a program or data file with a revised version, another command is n;iore convenien~ .
FORMAT FOR THE SCRATCH COMMAND: "pattern" can be any file name or combination of characters and wild card characters. _As "D" stands for drive number, which may only be 0 on the 1541 . If the dnve number is omitted, 0 is assumed . Likewise , "U" stands for unit (device) number, normally 8. If "U" is omitted, 8 is assumed .
More about Splats One other warning-never scratch a splat file. These are files that show up in a directory listing with an asterisk (*)just before the file type for an entry . The asterisk (or splat) means that file was never properly closed, and thus there is no valid chain of sector links for the Scratch command to follow in erasing the file.
RENAMING AND SCRATCIDNG TROUBLESOME FILES (ADVANCED USERS) Eventually, you may run across a file which has a crazy filename, such as a comma by itself( "," ) or one that includes a SHIFfed SPACE. Or perhaps you will find one that includes nonprinting characters . Any of these can be troublesome. Comma files , for instance, are an exception to the rule that no two files can have the same name.
NOTE: Dual drives make fuller use of this command, copying programs from one diskette to another in a single disk unit. To do that on the 1541, refer to Appendix E to find the programs that you need. COPYING PROGRAMS: BASIC 3.5 The Copy command allows you to make a spare copy of any program or file on a diskette . However, on a single drive like the 1541, the copy must be on the same diskette , which means it must be given a different name from the file copied.
One use for Initialize is to keep a cleaning diskette spinning , if you choos_e _to use files , with loss of all their contents when other files are added . Unless specifically (There is no need to use such kits on any regular basis und~r normal con~1t1ons of instructed otherwise, never collect a diskette containing direct access files. (Note: these o~~liness and care.) Nonetheless, if you are using such a kit, the followmg short are not the same as the relative files described in Chapter 6.
CHAPTERS SEQUENTIAL DATA FILES Before we study the format of the Open statement, let's review some of the possible devices in a Commodore computer system: pevlce #: Name: THE CONCEPT OF FILES A file on a diskette is just like a file cabinet in your office-an organized place to put things . Nearly everything you put on a diskette goes in one kind of file or another. So far all we've used are program files, but there are others , as we have mentioned.
"channel #" is a secondary address, giving further instructions to the selected device about how further commands are to be obeyed . In disk files, the channel number selects a particular channel along which communications for this file can take place. The possible range of disk chan!'el numbers is 0-15, but 0 is reserved for program Loads , I for program Saves, and 15 for the disk command channel.
EXAMPLE: "°here "file#" is the same file number given in the desired file's current Open statement. If you are writing a grading program, it wou.ld be convenient to simply tack on each student's new grades to the end o( their existing grade files . To add data to the "JOHN PAUL JONES" file, we could type OPEN 1,8,3, "O:JOHN PAUL JONES.A" In this case, DOS will allocate at least one more sector (block) to the file the first time you append to it, even if you only add one character of information.
However, if you need to combine them , here is a safe way to do it: 400 PRINT#5,NAME$;CHR$(13) ;STREET$;CHR$(13);CITY$ 0 with 9950 9960 9970 9980 CHR$(13) is the carriage return character, and has the same effect as putting the print items in separate lines . lf you do this often , some space and time may be saved by previously defining a variable as equal to CHR$(13): 10 CR$=CHR$(13) . ..
but many programs cheat on safety a bit anel UM; 800 INPUT#5,NAME$,STREET$,CITY$ 810 GOSUB 59990:REM CHECK FOR DISK ERRORS This is done primarily when top speed in the program is essential, and there is little or no risk of reading improper data from the file . quotation mark, in either an Input or Input# statement, all other characters except a carriage return or another quotation mark are accepted as part of the current data element.
READING FlLE DATA: USING GET# The Get# statement retrieves data from the disk drive , one character at a time . Like the similar keyboard Get statement in Basic, it only accepts a single character into a specified variable . However, unlike the Get statement, it doesn 't just fall through to the next statement if there is no data to be gotten .
CHAPTER6 DEMONSTRATION OF SEQUENTIAL FILES Use the following program for your first experiments with sequential files . Comments have been added to help you better understand it.
desired person out of a thousand in under 15 seconds, a feat no sequential file prograrn could match. Notes: FILE LIMITS . One of the nicest aspects of relative files is that all this is done for you without you r havmg to worry at all about exactly where on the diskette's surface a given record will be stored, or whether it will fit properly within the ;current disk sector, or need to be extended onto. the next available sector. DOS takes care of all that for you .
FORMAT FOR THE RECORD# COMMAND: PRINT#l5, "P" +CHR$ (channel #+96) + CHR$ (record #) + CHR$ (offset) where "channel #" is the channel number specified in the current Open statement for the specified file, "record #" is the high byte of the desired record number, and an optional "offset" vaiue, if present, is the byte within the record at which a followin g Read or Write should begin.
WRITING RELATIVE FILE DAT A 1410 OPEN 1,8,2, "O:"+FI$+" ,L,"+CHR$(RL) 1420 GOSUB 59990 1430 RH= INT(NR/256) 1440 RL = NR-256*RH 1450 PRINT#l5, "P" +CHR$(96+ 2) + CHR$(RL) + CHR$(RH) 1460 GOSUB 59990 1470 PRINT#l,CHR$(255); 1480 GOSUB 59990 1490 PRINT#l5 , "P" + CHR$(96+ 2) + CHR$(RL) + CHR$(RH) 1500 GOSUB 59990 1510 CLOSE 1 Begin to create desired file Check for disk errors Calculate length values Position to last record number Send default character to it Re-position for safety Now the file can be safel
between maximum field length and average field length . A program that uses variable record lengths must calculate the total length of each record as it is entered, to be sure the total of all fields doesn't exceed the space available. WRITING THE RECORD Here is an example of program lines to enter variable length fields for the above file design, build them into a single string, and send thc;m to record number RE in file number 3 (assumed to be a relative file that uses channel number 3).
3030 GOSUB 59990 3040 INPUT# l ,NA$,SA$,CS$,ZP$ 3050 GOSUB 59990 3060PRINT#15 , "P" + CHR$(96 + 3) + CHR$(RL) + CHR$(RH) Check for disk errors Read in fields Re-position for safety Here are the lines needed to read back the version with fixed length fields : 3000 RH= INT(RE/256) 3010 RL=RE-256*RH 3020 PRINT#l5 , "P" +CHR$(96+ 3) +CHR$ ( RL) + CHR$(RH) 3030 GOSUB 59990 3040 INPUT# 1,DA$ 3050 GOSUB 59990 3060 PRINT#l5 ,"P" +CHR$(96+3)+ CHR$(RL) + CHR$(RH) 3070 NA$= LEFf$(DA$,27) 3080 SA$= MID$(DA$,28 ,27)
channel is opened much like other files, except that the pound sign (#), optionaJiy followed by a memory buffer number, is used as a file name. 8'{AMPLE: FORMAT FOR DIRECT ACCESS FILE OPEN STATEMENTS: dJefC into computer memory via Get#. (If a carriage return will appear at least once in Here is a complete program to read a sector into disk memory using U I , and from every 88 characters of data, Input# may be used in place of Get#) .
EXAMPLES: abbreviated as: PRINT#l5 , " B-W";channel # ;drive # ;track # ;sector# To restore track 18, sector I of the directory from the disk buffer filled by the Block Read example on page 82, we can use where "channel # " is the channel number specified when the file into which the block will be read was opened , "drive# " is the drive number (always 0 on the 1541 ), and ·•track#" and " sector# " are respectively the track and sector numbers containing the desired block of data to be partially read int
pointer to the first file type byte (see Appendix C for details of directory organization), locking it by setting bit 6 and rewriting it. the next available track and block number. Therefore , before selecting a block to write, ll'Y to allocate that block . If the block isn't available, read the next available block from the error channel and allocate it instead. However, do not allocate data blocks in the directory track . If the track number returned is 0, the diskette is full .
CHAPTERS INTERNAL DISK COMMANDS EXAMPLE: To free the sector in which we wrote our name in the Block Write example, and allocated in the first Block-Allocate example, we could use the following command: PRINT#l5 ,"B-F" ;O;l;I USING RANDOM FILES (ADVANCED USERS ONLY) By combining the commands in this chapter, it is possible to develop a file. handing program that uses random files. What you need to know now is how to keep track of which blocks on the disk such a file has used.
E)(AMPLES: Other Resources: More detailed information about Commodore disk drives can be found in these books: Inside Commodore DOS, by lmmers & Neufeld (Datamost, cl984) The Anatomy of the 1541 Disk Drive, by Englisch & Szczepanowski (Abacus, c1984) Programming the PET/CBM, by West (Level Limited, cl982) The PET Personal Computer Guide, by Osborne & Strasmas (Osborne/McGraw-Hill, c 1982) MEMORY -READ To see how many tries the disk will make to read a particular sector, and whether ••seeks" one-half trac
FORMAT FOR THE MEMORY-WRITE COMMAND: PRINT# 15 ,' 'M-W' 'CHR$(
address)CHR$ (# of bytes)CHR$(data byte(s)) where " < address" is the low order part, and " >address" is the high order part of the address in disk memory to begin writing, "# of bytes" is the number of memory locations that will be written (from 1-34), and "data byte " is I or more byte values to be written into disk memory, each as a CHR$() value . If desired, a colon (:) may follow MW within the quotation marks.fORMA T FOR USER COMMANDS: ALTERNATE FORMATS: PRINT#l5,"B-E:";channel #;drive #;track #;sector# PRINT#l5,"B-E:channel #,drive #,track #,sector#" PRINT#l5, ' ' Ucharacter" where "character" defines one of the preset user commands listed above.
CHAPTER9 MACHINE LANGUAGE PROGRAMS Here is a list of disk-related Kemal ROM subroutines and a practical example of their use in a program which reads a sequential file into memory from disk. Note that most require advance setup of one or more processor registers or memory locations, and all are called with the assembly language JSR command .
STEPS TO CHANGE THE DEVICE NUMBER USING THE SWITCH 1. Tum off the disk drive. 2. Refer to the following chart to set the DIP SW at the back of the disk drive for device number setting. Device# 8 9 10 11 3. swl sw2 ON OFF ON OFF ON ON OFF OFF APPENDIX B: DOS ERROR MESSAGES AND LIKELY CAUSES Note: Many commercial program diskettes are intentionally created with one or more of the following errors , to keep programs from being improperly duplicated .
24: READ ERROR (byte decoding error) The data or header has been read into disk memory, but a hardware error has been created by an invalid bit pattern in the data byte. May indicate grounding problems. 25: WRITE ERROR (write-verify error) The controller has detected a mismatch between the data written to diskette and the same data in disk memory . May mean the diskette is faulty . If so, try another. Use only high quality diskettes from reputable makers .
66: ILLEGAL TRACK AND SECTOR The DOS has attempted to access a track or sector which does not exist. May indicate a faulty link pointer in a data block . 67 : ILLEGAL SYSTEM T OR S This special error message indicates an illegal system track or block . 70: NO CHANNEL (available) The requested channel is not available, or all channels are in use . A maximum of three sequential files or one relati•1 e file plus one sequential file may be opened at one time, plus the command channel.
, ,_ 1541 BLOCK DISTRIBUTION BY TRACK Track number Range of Sectors I to 17 18 to 24 25 to 30 31to35 0 to 0 to 0 to 0 to PROGRAM FILE FORMAT Total # of Sectors 20 18 17 16 21 19 18 17 . DEFINITION BYTE FIRST SECTOR 0,1 2,3 4-255 Track and sector of next block in program file . Load address of the program Next 252 bytes of program information stored as in computer memory (with key words tokenized) . REMAINING FULL SECTORS 1541 BAM FORMAT Track 18, Sector 0.
1541 RELATIVE FILE FORMAT BYTE 1541 DIRECTORY FILE FORMAT Track 18, Sector 1. DEFINITION DATA BLOCK BYTE 0, 1 2-255 0, 1 2-31 34-63 66-95 98-127 130-159 162-191 194-223 226-255 Track and sector of next data block . 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) .
APPENDIX D: DISK COMMAND QUICK REFERENCE CHART APPENDIX E: TEST /DEMO DISKETTE General Format: OPEN 15,8,15:PRINT#15,command:CLOSE 15 (Basic 2) HOW TO USE The "HOW TO USE" programs provide brief descriptions of the other programs on the Test/Demo diskette. HOUSEKEEPING COMMANDS BASIC2 BASIC 3.
SEQ.FILE.DEMO AND REL.FILE.DEMO These two files are included as programming examples or guidelines when writing your own programs. They also illustrate the important technique of checking the error channel after each access to the disk drive. SD.BACKUP .xx These three programs are entitled SD.BACKUP.C64, SD.BACKUP.Cl6, and SD.BACKUP.PLUS4.
Commodore Business Machines, Inc. 1200 Wilson Drive • West Chester, PA 19380 Commodore Business Machines, Ltd . 3470 Pharmacy Avenue• Agincourt , Ontario, Ml W 3G3 Commodore 1s a registered trademark of Commodore Electronics L1m1ted Commodore 1541C1s a trademark of Commodore Electronics Limited .