commodore vic 1541 floppy drive users manual

Upload: cid-hayes

Post on 09-Apr-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    1/65

    II 11II IIIIII III 11IIII a II

    ..III'" n" II

    "

    III n: :j

    ~ commodoreCOMPUTER

    . II Un.

    : VIC-154'1 I[ill [)]11II gII

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    2/65

    VIC-1541SINGLE DRIVE FLOPPY DISKUSER'SMANUAL

    P/N 1540031-02

    ~ commodoreCOMPUTER

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    3/65

    WARNING: This equipment has been certified to comply with the limits for I!,Class B computing device, pursuant to Subpart J of Part 15 of FCC Rules. Onlycomputers certified to comply with the Class B limits may be attached to thisprinter. Operation with noncertified computers is likely to result in interferenceto radio and TV reception,"This warning is valid for the equipment which has the following FCC labelon its rear.

    CERTIFIED TO COMPLY WITH CLASS B LIMITS.PART 15 OF FCC RULES SEE INSTRUCTIONS IFINTERFERENCE TO RADIO RECEPTION IS SUS-PECTED.

    The information in this manual has been reviewed and is believed to be entirelyreliable. No responsibility, however, is assumed for inaccuracies. The material inthis manual is for information purposes only, and is subject to change withoutlIotice.@Commodore BusinessMachines, Inc., September 1981

    "All rights reserved."

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    4/65

    Table of Contents1. General Description ..............2. Unpacking and Connecting .Contents of Box . . . .Connection of Cables

    PoweringOn ........Insertion of I)jskette . . . . .Usingwith VlC 20 or Commodore 64 . .

    3. UsingPrograms.............Loading Pre-packaged SoftwareLOAD .Directoryof Disk . . . . . . . . .Pattern Matching & Wild CardsSAVE .SAVE and replace. . .VERIFY. .. . .. ..DOS Support Program

    4. DiskCommands . . . . . . . .OPEN ANDPRINT #NEW ...COpy.. ..RENAME.SCRATCHINITIALIZEVAUDATE.DUPUCATEReading the Error ChannelCLOSE .. .. . .. . .. .. .

    S. SequentialFiles . . . . . . . . .OPEN .PRINT # and INPUT #GET# ..Reading the Directory

    6. RandomFiles ..........Opening a channel for random access dataBLOCK-READ. . . . .BLOCK-WRITE . . . .BLOCK-ALLOCATE.BLOCK-FREE . . . .BUFFER-POINTERUSER 1 and USER2

    .

    Page3667788999911121313141414IS161617171718181819192022232627272829293132

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    5/65

    7. Relativeiles. . . . . . . . . . . . . . . . . ., . 33Creating arelative fde .. .. .. . .. .. . 34Usingelativedes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 3S

    8. Programming the Disk Controller. 37BLOCK-EXECUTE 37MEMORY-READ. . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 37MEMORY-WRITE 38MEMORY-EXECUTE . . . . . . . . . . . . . . . . . . . . . . . . . . .. 38USERCommands 399. Changingthe Disk DeviceNumber . . . . . . . . . . . . . . . . . . . . . . .. 39

    Software Method .. . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 39HardwareMethod 40AppendicesA. DiskCommandSummary. 41B. ErrorMessages. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 42

    C. Demonstration Disk Programs . . . . . . . . . . . . . . . . . . . . . .. 47D. DiskFormatsTables . . . . . . . . . . . . . . . . . . . . . . . . . . . .. S4

    2

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    6/65

    1. GENERAL DESCRIPTIONIntroduction

    Welcome to .the fastest, easiest, and most efficient filing system availablefor your Commodore 64 or VIC 20 computer, your 1541 DISK DRIVE. Thismanual has been designed to show you how to get the most from your drive,whether you're a beginner or an advanced professional.If you are a beginner, the first few chapters will help you through thebasics of disk drive installation and operation. As your skill and programmingknowledge improves. you will find more uses for your disk drive and the moreadvanced chapters of this manual willbecome much more valuable.If you're a professional, this reference guide will show you how to put the1541 through its paces to perform just about all the disk drive jobs you canth ink of.No matter what level of expertise you have, your 1541 disk drive willdramatically improve the overall capabilities of your computer system.Before you get to the details of 1541 operation, you should be aware of afew important points. This manual is a REFERENCE GUIDE, which means thatunless the information you seek directly pertains to the disk or disk drive youwill have to useyour Commander 64 or VIC 20 User's Guides and Programmer'sReference Guides to find programming information. In addition, even though wegive you step-by-step instructions for each operation, you should becomefamiliar with BASIC and the instructions (called commands) that help youoperate your disks and drives. However. if you just want to use your disk driveunit to load and save prepackaged software, we've included an easy and briefsection on doingjust that.Now. . . let's get on with the general information.The commands for the disk drive come in several levels of sophisication.Starting in chapter three. you can learn how the commands that allow you tosave and load programs with the disk work. Chapter four teaches you howcommands are sent to the disk, and introduces the disk maintenance commands.Chapter five tells you how to work with sequential data files. These arl

    very similar to their counterparts on tape (but much faster). Chapter sifintroduces the commands that allow you to work with random files, accessanypiece of data on the' disk, and how you organize the diskette into tracks andblocks. Chapter seven describes the special relative files. Relative files are thebest method of storing data bases, especially when they are used along withsequential files.Chapter eight describes methods for programming the disk controllercircuits at the machine language level. And the final chapter shows you how to

    3

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    7/65

    change the disk device number. by "cutting" a line inside the drive unit orthrough software.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 coupleare enough for most operations. Getting to know your disk drive will reward youin many ways-speed of operation, reliability, and much more flexibility in yourdata processing capabilities.Specifications

    This disk drive allows you to store up to 144 different programs and/ordata files on a singlemini-floppy diskette, for a maximum of over 174,000 bytesworth of information storage.Included in the drive is circuitry for both the disk controller and acomplete 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 awayfrom your Commodore 64 or VIC 20 computer. The disk uses a "pipeline"software system. The "pipeline" makes the disk abot to process commands whilethe computer is performing other jobs. This dramatically improves the overallthroughput (input and output) of the system.Diskettes that you create in this disk drive are read and write compatiblewith Commodore 4040 and 2031 disk drives. Therefore, diskettes can be usedinterchangeably on any of these systems. In addition, this drive can readprograms 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 parallelIEEE-488 interface used on Commodore PET computers, except that only onewire is used to communicate data instead of eight. The two ports at the rear ofthe 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 intothe next. Up to five disk drives and one printer can share the bus simultaneously.

    4

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    8/65

    Figure 1.1 Specifications VIC 1540/1541 SingleDrive Floppy DiskSTORAGE

    Directory entriesSectors per trackBytes per sectorTracksBlocks

    174848 bytes per diskette168656 bytes per diskette167132 bytes per diskette65535 records per file144 per diskette17 to 2125635683 (664 blocks free)

    Total capacitySequentialRelative

    lC's:65026522 (2) microprocessorI/O. internal timersBuffer

    2114 (4)PHYSCIAL:

    2K RAM

    DimensionsHeightWidthDepth

    97mm200 mm374 mmElectrical:

    Power requirementsVoltageFrequencyPower

    I~O, 120,220, or 240 VAC5 or 60 Herts

    2 WattsMEDIA:

    Diskettes Standard mini 5\4", single sided,singledensity

    5

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    9/65

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    10/65

    Connection of CablesYour first step is to take the power cable and insert it into the back of thedisk drive (see figure 2.2). It won't go in if you try to put in in upside down.

    Once it's in the drive, plug the other end into the electrical outlet. if the diskdrive makes any sound at this time, please turn it off using the switch on theback! 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 endof the cable into the back of the computer. That's all there is to it!If you have a printer, or any additional disk drives, attach the cables intothe second serial bus port (see figure 2.3). For directions on using multiple drivesat one time, read chapter 8. If you are a first-time user with more than one drive,start working with only one drive until you're comfortable with the unit.

    r u --- ..---.--.I

    ---_.--_.-.---._-_.. lIiCommodore 64 or VIC20Personal Computer VIC 1541Single DriveFloppy Disk

    VIC Graphic Printer

    Fig 3. Floppy Disk HookupPowering On

    When you have all the devices hooked together, it's time to start turningon 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 thelast one to be turned on, everything will be OK.7.

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    11/65

    First, make sure that you've removed all diskettes from the disk drivesbefore powering on.After all the other deviceshave been turned on, only then is it safe to turnon the computer. All the other devices will go through their starting sequences.The printer's motor goes on, with the print head movinghalfway across the lineand back again. The 1541 disk drive will have its red error light on, and then thegreen drive light will blink, while your TV screen forms the starting picture.Once all the lights have stopped flashing on the drive, it is safe to beginworking with it.

    WRITEPROTECTNOTCH

    ZInm:c'-Iz-Ioo:c

    ~

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    12/65

    computers. However, each computer has different requirements for speed ofincoming data. Therefore, there is a software seitch for selecting whichcomputer's speed to use. The drive starts out ready for a Commodore 64. Toswitch to VIC 20 speed, the foIlowing command must be sent after the drive isstarted (power-on or through software):OPEN 15,8,15, "UI-": CLOSE 15To return the disk drive to Commodore 64 speed, use this command:OPEN 15,8, 15, "UI+": CLOSE 15More about using this type of command is in chapter 4, with a detailedexplanation of the U (user) commands in chapter 7.

    3. USING PROGRAMSLOADINGPREPACKAGED PROGRAMS

    For those of you interested in using only prepackaged programs availableon cartridges, cassette, or disk, here's all you have to do:Using your disk drive, carefully insert the preprogrammed disk so that thelabel on the disk is facing up and is closest to you. Look for a little notch on thedisk (it might be covered with a little piece of tape). If you're inserting the diskproperly, the notch will be on the left side. Once the disk is inside, close theprotective gate by pushing in on the lever. Now type LOAD "PROGRAMNAME", 8 and hit the .~U"IU~~. key. The disk will make noise and yourscreen will say:

    When the READY comes on and the:~:is on, just type RUN, and yourprepackaged software is ready to use.LOAD

    The BASICcommands used with programs on the disk drive are the sameas the commands used on the Commodore DatassetteTM recorder. There are afew extra commands available for use with disks, however. First of all, theprogram name must be given with each command. On a Datassette, you couldomit the program name in order to just LOAD the firs program there. On disk,since there are many different programs that are equally accessible, theprogram

    9

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    13/65

    name must be used to tell the disk drive what to do. In addition, the disk drive'sdevice number must be specified. If no device number is listed, the computerassumes the program ison tape.FORMAT FOR THE LOAD COMMAND:

    LOAD name$ , device# , command#The program name is a string, that is, either a name in quotes or thecontents 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 thanone drive, see chapter 8 on how to change the device number. This book assumesthat you're using device number 8 for the disk drive.The command# is optional. If not given, or zero, the program is LOADednormally, that is, beginning at the start of your available memory for BASICprograms. If the number is I, the program will be LOADed at exactly the samememory locations from which it came. In the case of computers with differentmemory configurations, like VICs with 5K, 8K, or more memory, the start ofBASIC memory is in different places. The command# 0 permits BASICprograms to LOAD normally. Command# I is used mainly for machinelanguage, character sets, and other memory dependent functions.

    EXAMPLESLOAD "TEST", 8

    LOAD"Mach Lang", 8, INOTE: You can use variables to represent device numbers, commands, andstrings, as long as you've previously defined them in your program.Directory of Diskette

    Your Datassette tape deck is a sequential device. It can only read fromthe beginning of the tape to the end, without skipping around the tape andwithout the capability of going backward or recording over old data.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 upto 256 bytes of information. There are a total of 683 blocks on a single diskette.. Fortunately, you don't really have to worry about individual blocks ofdata. There is a program in the disk drive called the Disk Operating System, orthe DOS. This program keeps track of the blocks for you. It organizes them intoa Block Availability Map,or BAM,and a directory.

    10

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    14/65

    The Block Availability Map is simply a checklist of all 683 blocks on thedisk. It is stored in the middle of the diskette, halfway between the center huband the outer rim. Every time a program is SAVEd or a data file is CLOSEd, theBAMis updated with the list of blocks used up.The directory is a list of all programs and other files stored on the disk. Itis physically located right next to the BAM.There are 144 entries available inthe directory, consisting of information like file name and type, a list of blocksused, and the starting block. The directory is automatically updated every time aprogram is SAVEd or a file is OPENed for writing. Beware: the BAM isn'tupdated until the file is CLOSEd, even though the directory changes right away.If a file isn't CLOSEd properly, all data in that me will probably be lost.The directory can be LOADed into your memory just like a BASICprogram. Place the diskette in the drive, and type the following command:LOAD"$",8The computer responds with:

    Now the directory is in your computer's memory. Type LIST, and you'llsee 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 asdevice# 4):OPEN4, 8,4: CMD4: LIST

    NOTE: When using CMD, the file must be closed using the commandPRINT# 4: CLOSE 4. See the VIC 1525/1515 printer manual for detailedexplanation.

    To read the directory without LOADing it into your memory, see thesection later in this chapter on the DOS Support Program. In addition, toexamine the directory from inside a BASICprogram. see the section in chapter 5that deals with the GET# statement.Pattern Matching and Wild Cards

    When using the tape deck, you can LOAD any program starting withcertain letters just by leaving off any following letters. Thus, the command11

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    15/65

    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 lettersHELLO, like "HELLO THERE."When using the disk, this option is called pattern matching, and there is aspecial character in the file name used to designate this. The asterisk (*)character following any program name tells the drive you want to find anyprogram starting with that name.

    LOADname$ + "*", 8Can Be A StringVariable Or TheName Inside Quotes

    FORMAT FOR PATTERN MATCHING:

    In other words, if you want to LOAD the first program on the diskstarting with the letter T, use the command LOAD "T*", 8.If only the "* is used for the name, the last program accessed on the diskis the one LOADed. If no program has yet been LOADed, the first one listed inthe directory is the one used.You are probably familiar with the concept of wild cards in poker whereone 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 iscompared to the name in the LOAD command, but any characters where there isa questionmarkin the namearen't checked. 'For instance, when the command LOAD "T?NT", 8 is given, programsthat match include TINT, TENT, etc.When LOADing the directory of the disk, pattern matching and wild cardscan be used to check for a list of specific programs. If you gave the commandLOAD "$O:TEST", only the program TEST would appear in the directory (ifpresent on the disk). The command LOAD "$O:t*" would give you a directoryof aU programs beginning with the letter T. And LOAD "$O:T?ST" would giveyou all the programs with 4-letter names having the first letter of T and the thirdand fourth letters ST. LOAD "$O:T?ST*" would give names of any length with

    the correct first, third, and fourth letters.SAVE

    To SAVE a program to the diskette, all that is needed is to add the devicenumber after the program name. Just like the SAVE command for the tapedeck, the device number can be folJowed by a command number, to prevent theautomatic re-Iocation on LOADing (see the section on the LOAD 'command,above).FORMAT FOR THE SAVE COMMAND:

    SAVE name$, device#, command#12

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    16/65

    See the LOAD ~ommal1d (pagesparameters device# and command#.& ) for an explanation of the ____

    When you tell the disk drive to SAVE a program, the DOS must takeseveral steps. First, it looks at the directory to see if a program with that namealready exists. Next it ~he~ks to see that there is a directory entry available forthe name. Then it che~ks the BAMto see if there are enough blocks in which tostore the program. If everything is OK up to this point, the program is stored. Ifnot, the error light will flash.SAVE and Replace

    If a program already exists on the disk, it is often necessary to make a~hange and re-SAVE it onto the disk. In this case, it would be inconvenient tohave to erase the old version of the program and then SAVE it.If the first characters of the program name are the "(aP'sign followed by ao and a colon (:), the DOS knows to replace any old program that has that namewith the program that is now in the computer's memory. The drive checks thedirectory to find the old program, then it marks that entry as deleted, and itnext creates a new entry with' the same name. Finally, the program is storednormally.FORMATFOR SAVEWITHREPLACE:

    SAVE "=0:" + nameS, device#, command#For example, if a file was called TEST, the SAVE and replace commandwould be SAVE"(u,O:TESr,8.The reason for the 0: is to keep compatibility with other Commodore diskdrive units which have more than one drive built in. In that case, the number 0or 1 is used to specify which drive is being used.

    VERIFYThe VERIFY command works to check the program currently in memoryagainst the program on disk. You must include a device# with the VERIFYcommand. The computer does a byte-by-byte comparison of the program,including line links-which may be different for different memory configura-tions. For instance, if a program was SAVEd to disk from a 5K VIC 20, andre-LOADed on an 8K machine, it wouldn"t VERIFY properly because the linkspoint to different memory locations.

    FORMAT FOR VERIFY COMMAND:VERIFY name$, device#

    I3

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    17/65

    DOS Support ProgramOn your demonstration disk, there may be a program called DOSSUPPORT.This program, also called a wedge,allowsyou to use many diskcommands more easily (different wedges are used for the VIC 20 and the

    Commodore 64). Just LOAD the program and RUN it. It automatically setsitself up and erases itself when it's finished. You'll have a few hundred less bytesto work with when this program is running, but you'll also have a handy way tosend the disk commands.As a result of the DOS Support, the "/" key now takes the place of theLOAD command. Just hit the slash followed by the program name, and theprogram is LOADed. When you use this method, you don't need to use theLOADcommand or the comma 8.Thc"(Q)"and ">" keys are used to send commands to the disk drive. If youtype (a$ (or >$), the directory of the disk is displayed on the screen, withoutLOADinginto your memory!Thesekeysalsotaketheplaceof the PRINT#(seechapter 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 (a'or the> and hit RETURN. The complete error messageisdisplayed to you: messagenumber, text, and track and block numbers.

    4: DISK COMMANDSOPEN and PRlNT#

    Up 'til now, you have explored the simple ways of dealing with the diskdrive. In order to communicate with the disk drive more fully, you have totouch on the OPEN and PRINT# statements in BASIC(more details of thesecommands are available in your VIC 20 or Commodore 64 User's Guide orProgrammer's Reference Guide). You may be familiar with their use with datafiles on cassette tape, where the OPEN statement creates the file and thePRINT# statement fills the file with data. They can be used the same way withthe disk, as you will see in the next chapter. But they can also be used to set upa command channel. The command channel lets you exchange informationbetween the computer and the disk drive.FORMAT FOR THE OPEN STATEMENT:

    OPENfile#, device#, (command) channel#, text $The file# can be any number from I to 255. This number is used

    throughout the program to identify which file is being accessed. But numbersgreater than 127 should be avoided, because they cause the PRINT# statementto generate a linefeed after the return character. These numbers are really meantto be used with non-standard printers.14

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    18/65

    The device# of the disk is usually 8.The channel# can be any number from 2 to 15. These refer to a channelused to communicate with the disk, and channels numbered a and I are reserved

    for the operating system to use for LOADing and SAVEing. Channels::: through14 can be used for data to files, and 15 is the command channel.The text$ is a string that is PRINTed to the file, as if with a PRINT#statement. This is handy for sending a single command to the channel.

    EXAMPLES OF OPEN STATEMENTS:~ ~OPEN 15,8, IS DEViCE-#~\OPEN2, 8. 2 C-- ~~OPENA;B,C,ZL ~The PRINT# command works exactly like a PRINT statement, exceptthat 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 inthe disk drive, which LOADs it onto the diskette. When PRINT# is used withthe command channel, it sends commands to the disk drive.FORMAT FOR SENDING DISK COMMANDS:

    OPEN 15, 8, IS. command$orPRINT# IS, command$

    NEWThis command is necessary when using a diskette for the first time. TheNEW command erases the entire diskette, it puts timing and block markers onthe diskette and creates the directory and BAM.The NEWcommand can also beused to clear out the directory of an already.formatted diskette. This is fasterthan re-formatting the whole disk.

    FORMAT FOR THE NEWCOMMANDTO FORMATDISK:PRINT#15, "NEW~~'r abbreviated asPRINT#15, "N~:name,id"

    FORMAT FOR THE NEW COMMAND TO CLEAR DIRECTORY:

    PRINT# 15, "N~:name"The name goes in the directory as the name of the entire disk. This onlyappears when the directory is listed. The ID code is any 2 characters, and theyare placed not only on the directory but on every block throughout the diskette.

    15

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    19/65

    That way, if you carelessly replace diskettes while writing data, the drive willknow by checking the ID that something is wrong.COpy

    This command allows you to make a copy of any program or file on thedisk drive. It won't copy from one drive to a different one (except in the case ofdual drives like the 4040), but it can duplicate a program under another name onthe drive.FORMAT FOR THE COPYCOMMAND:

    ~ "'"PRINT# 15, "COPY~:newfile=~:oldfile"or abbreviated asPRINT# 15, "c~:newfile=~:oldfile"The COpy command can also be used to combine two through four flleson the disk.

    FORMAT FOR COpy TO COMBINE FILES:PRINT#15, "CO:newfile=O: old file I ,0:0Idfile2,0:0Idfile3 ,0:0Idfile4"

    EXAMPLES OF COPY COMMAND:PRINT# 15, "CO:BACKUP=O:ORIGINAL"PRINT#15, "CO:MASTERFILE=O:NAME,O:ADDRESS,O:PHONES"

    RENAMEThis command allows you to change the name of a file once it is in thedisk directory. This is a fast operation, since only the name in the directory mustbe changed.

    FORMAT FOR RENAME COMMAND:~-~

    PRINT# IS, "RENAME~:newname=oldname" ~r abbreviated asPRINT# IS, "R~:newname=oldname"

    EXAMPLEOF RENAME COMMAND:PRINT# 15, "RO:MYRA=MYRON"The RENAME command will not work on any files that are currentlyOPEN.

    16

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    20/65

    SCRATCHThis command allows you to erase unwanted files and programs from thedisk, which then makes the blocks available for new information. You can erase

    programs one at a time or in groups by using pattern matching and/or wild cards.FORMATFOR SCRATCHCOMMAND

    PRINT# 15, "SCRATCH~:~or abbreviated asPRINT# 15, "S~:name"If you check the error channel after a scratch operation (see below), thenumber usually reserved for the track number now tells you how many files

    were scratched. For example, if your directory contains the programs KNOWand GNAW, and you use the command PRINT# 15, "SO:?N?W", you willscratch both programs. If the directory contains TEST, TRAIN, TRUCK, andTAIL, and you command the disk to PRINT# 15, "SO:T*", you will erase allfour of these programs.INITIALIZE

    At times, an error condition on the disk will prevent you from performingsome operation yo~ want to do. The INITIALIZE command returns the diskdrive to the same state as when powered up. You must be careful to re-matchthe drive to the computer (see chapter 2).FORMATFOR INITIALIZE COMMAND:PRINT# 15, "INITIALIZE"or abbreviated asPRINT# 15, ''!''

    VALIDATEAfter a diskette has been in use for some time, the directory can becomedisorganized. When programs have been repeatedly SAVEd and SCRATCHed,they may leave numerous small gaps on the disk, a block here and a few blocksthere. These blocks never get used because they are too small to be useful. TheVALIDATE command will go in and re-organize your diskette so that you canget the most from the availablespace.Also, there may be data files that were OPENed but never properlyCLOSEd. This command will collect all blocks taken by such files and makethem available to the drive, since the files are unusable at that point.There is a danger in using this command. When using random files (seechapter 6), blocks allocated will be de-allocated by this command. Therefore,this command should never be used with a diskette that uses random files.

    17

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    21/65

    FORMAT FOR VALIDATE COMMAND:PRINT# 15, "VALIDATE"or abbreviated asPRINT# 15, "V"

    DUPLICATEThis command is a hangover from the operating systems that werecontained on the dual drives like the 4040. It was used to copy entire diskettesfrom one drive to another, but has no function on a singledisk drive.

    Reading the Error ChannelWithout the DOS Support Program, there is no way to read the disk errorchannel without a program, since you need to use the INPUT# command whichwon't work outside a program. Here is a simple BASIC routine to read the errorchannel:

    IOOPENI5,8,15 /' ~E20 INPUT# 15,A$, B$,C~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, andfourth variables come in as numbers, and can be INPUT into numeric variables ifyou like. The first variable describes the error #, where 0 is no error. The secondvariable is the error description. The third variable is the track number on whichthe error occurred, and the fourth and final is the block number inside thattrack. (A block is also known as a sector)Errors on track 18have to do with the BAMand directory. For example, aREAD ERROR on track 18 block 0 may indicate that the disk was never

    formatted.CLOSE

    It is extremely important that you properly CLOSE files once you arefinished using them. Closing the file causes the DOS to properly allocate blocksin the BAMand to finish the entry in the directory. If you don't CLOSE the fde,aDyour data will be lost!FORMAT FOR CLOSE STATEMENT:

    CLOSE file#You should also be careful not to CLOSE the error channel (channel# 15)18

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    22/65

    before CLOSEingyour data channels. The error channel should be OPENed iustand 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 drivewill CLOSE them for you, but BASICwill still think they are open (unless youCLOSE them properly), and let you to try to write to them.

    NOTE: If your BASIC program leads you into an error condition, all filesare CLOSEd in BASIC,without CLOSEing them on your disk drive! Thisis a very dangerous condition. You should immediately type the statementCLOSE 15: OPEN 15, 8, 15: CLOSE 15. This will re-initialize your driveand make all your files safe.

    5. SEQUENTIAL FILESOPEN

    Sequential files on the disk drive work exactly like they do on cassettetape, only much faster. They are limited by their sequential nature, which meansthey must be read from beginning to end. Data is transferred byte by byte,through a buffer, onto the magnetic media. To the disk drive all files are createdequal. That is, sequential files, program files, and user files all work the same onthe disk. Only program files can be LOADed, but that's really the onlydifference. Even the directory works like this, except that it is read-only. Theonly difference is with relative files.FORMAT FOR OPENING A SEQUENTIAL FILE:

    OPEN file#, device#, channel#, "O:name,type,direction"The file number is the same as in all your other applications of the OPENstatement, 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 matchingif you're creating a write file). The type can be any of the ones from the chartbelow, at least the first letter of each type. The direction must be READ orWRITE, or at least the first letter of each.FILE TYPE MEANINGPRGSEQUSRREL

    ProgramSequentialUserRelative (not implemented in BASIC2.0)

    19

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    23/65

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    24/65

    statement PRINT# 5, A$; B$;C$:

    char

    CR stands for the CRR$ code of 13, the carriage return, which is PRINTedat the end of every PRINT or PRINT# statement unless there is a comma orsemicolon at the end of the line.NOTE: Do not leave a space between PRINT and #, and do not try toabbreviate the command as ?#. See the appendixes in the user manual forthe correct abbreviation.FORMAT FOR INPUT#STATEMENT:

    INPUT# file#, variable listWhen using the INPUT# to read this data in, there is no way to tell thatit's not supposed to be one long string. You need something in the file to act as aseparator. Characters to use as separators include the CR, a comma or asemicolon. The CR can be added easily by just uSingone variable per line on thePRINT# statement, and the system pUts one there automatically. The statementPRINT# 5, A$: PRINT# 5, B$: PRINT# 5, C$ puts a CR after every variablebeing written, providing the proper separation for a statement like INPUT#5,

    AS, B$, C$. Or else a line like Z$= .. ,": PRINT# 5, A$ Z$ B$Z$ C$ will do thejob as well, and in less space. The file after that line looks like this:

    charPutting commas between variables results in lots of extra space on the diskbeing used. A statement like PRINT# 5, A$, B$makes a file that looks like:

    charYou 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 bein 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 willbe a blank space if the number is positive, and a minus sign (-) if the number isnegative. Then comes the number,and the last character is the cursor rightcharacter. This format provides enough information for the INPUT# statementto read them in as separate numbers if several are written with no other specialseparators. It is somewhat wasteful of space, since there can be two unused

    21

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    25/65

    characters if the numbers are positive.Here is a picture of the file after the statement PRlNT# 5, I; 3; 5; 7 isperformed:

    char IS

    fIle. Appendix B contains a program demonstrating the use of a sequential diskGET#

    The GET# retrieves data from the disk, one character at a time.FORMAT FOR THE GET# STATEMENT:

    GET# f1le#, variable listData comes in byte by byte, including the CR, comma, and otherseparating characters. It is much safer to use string variables when using theGET# statement. You will get a BASICerror message if string data is receivedwhere a number was requested, but not vice-versa.

    EXAMPLES OF GET#STATEMENT:GET# 5, A$

    You can get more than I character at a timeGETS 5, AThe GET# statement is extremely useful when examining files withunknown contents, like a file that may have been damaged by an experimental

    program. It is safer than INPUT# because there is a limit to the number ofcharacters allowed between separators of INPUT variable.s.With GET#, youreceive every character, and you can examine separators as well as other data.Here is a sample program that will allow you to examine any file on thedisk:

    10 INPUT "FILE NAME"; F$20 INPUT "FILE TYPE";T$30 T$=LEFTS(TS,1)40 IF TS < > "s" THEN IF T$ < > "P" THEN IF T$ < > "u" THEN 2045 OPEN 15,8,1550 OPEN5,8,5, "0:" + F$+ ","+ T$+ ",R"60 GOSUB20022

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    26/65

    70 GET# 5, A$80 IF ST< > 0 THENPRINT ST: STOP90 PRINT ASC(A$+CHR$.l0) );100 GOTO 70200 INPUT# 15, A$, B$, C$, 0$210 IF VAL (A$) > 0 THEN PRINT A$,B$,C$;O$:STOP220 RETURN

    In CaseOf NullCharacter BeingRead In - CausesError With ASCFunction Otherwise!

    Reading the DirectoryThe directory of the diskette may be read just like a sequential file. lustuse $ for the file name, and OPEN 5, 8, 5, "$". Now the GET# statement worksto examine the directory. The format here is identical to the format of aprogram file: the file sizes are the line numbers, and names are stored ascharacters within quote marks.Here's a program that lets you read the directory of the diskette:

    100PENl,8,2,"S20 GET#I,A$,A$,A$,A$30 T$(O) ="Del":T$(1) ="SEQ":T$(2) = "PRG":T$(3) = "USR":T$(4) ="REL"401=17:GOSUBSOO ~~50N$=B$ @) ~01=2 ( ID70GOSUB500801$=B$901=2 ( ( OPERATINGSYSTEM100 GOSUB5001100$=B$120FORL=IT073( (GET RESTOFBLOCK130GET#I,A$,A$,A$140NEXT150GET#I,A$,A$,A$,A$,A$160PRINTCHR$(147)"Diskname:"N$,"ID: "I$,"OS: "0$161 PRINT" Length" ,"Type" ,"Name"165 FORP=IT08170 GET#l ,T$,A$,A$175IFSTTHENCLOSEl:END180IFT$=""THENT$=CHR$(128)1901=15 ( ~200 GOSUB500 ~210N$=B$ ~20GET#1,A$,A$,A$,A$,A$,A$,A$,A$,A$,A$,U,H$225 L=ASC(U+CHR$(0))+25 6*ASC(H$+CHR$(0):IFL=OTHEN250230 PRINTL,T$(ASC(T$)-128),N$250 IFP < 8THENGET#1 ,A$,A$260NEXTP:GOTOI65

    23

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    27/65

    500 B$=""510 FORL=OTOJ

    j520 GET#I,A$ BUILDA530 IFA$ < > CHR$(96)THENIFA$ < > CHR$(160)THENB$=B$+A$f STRING540 NEXT ~SUBROUTINE550 RETURN

    Table 5.1: 1540{1541 BAM FORMAT

    Table 5.2: 1540/1541 DIRECTORYHEADER

    24

    Track 18, Sector O.BYTE CONTENTS DEFINITION0,1 18,01 Track and sectOrof first directory block2 65 ASCII character A indicating 4040 format.3 0 Null flag for future OOSuse.4-143 Bitmap of available blocks for trac so1-35.

    ... 1=availableblocko = block not available(each bit represents one block)

    Track 18, Sector O.BYTE CONTENTS DEFINITION

    144-161 Disk name padded with shifted spaces.162-163 Disk lD.164 160 Shifted space.165,166 50,65 ASCII representation for 2Awhich is DOS versionand format type.166-167 160 Shifted spaces.171-255 0 Nulls, not used.Note: ASCIIcharacters may appear in locations 180 thru 191 on some diskettes.

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    28/65

    Table 5.3: DIRECTORY FORMAT

    *STRUCTURE OF SINGLE DIRECTORY ENTRY

    25

    Track 18,Sector1for4040Track 39, Sector 1 for 8050BYTE DEFINITION

    0,1 Track and sector of next directory block.2-31 *File entry 134-63 *File entry 266-95 *File entry 398-127 *File entry 4130-159 *File entry 5162-191 *File entry 6194-223 *File entry 7226-255 *File entry 8

    BYTE CONTENTS DEFINITION0 128+type File type OR'ed with $80 to indicate properly closed

    file.TYPES: 0= DELetedI = SEQential2 = PROGram3=USER4 = RELative

    1,2 Track and sector of 1st data block.3-18 File name padded with shifted spaces.19,20 Relative file only: track and sector for first side sectorblock.21 Relative file only: Record size.22-25 Unused.26,27 Track and sector of replacement file when OPEN(a)s ineffect.28,29 Number of blocks in file: low byte, high byte.

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    29/65

    Table 5.4: SEQUENTIAL FORMAT

    Table 5.5: PROGRAMFILE FORMAT

    6. RANDOMFILESSequential files are fine when you're just working with a continuousstream of data, but some jobs require more than that. For example, with a largemailing 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, someway to get to any record inside a file without having to read through the entirefIle first.There are actually two different types of random access files on theCommodore disk drive. The relative files discussed in the next chapter are moreconvenient for data handling operations, although the random files in thischapter have uses of their own, especiallywhen working with machine language.Random files on the Commodore disk drive reach the individual 256.byteblocks 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 blankdiskette. Each block of data really means I Track and sector of the same name.The diskette is divided into tracks, which are laid out as concentric circleson the surface of the diskette. There are 35 different tracks, starting with track Iat 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 sectors. Because there is more room on theouter tracks, there are more sectors there. The outer tracks contain 21 sectors

    each, while the inner ones only have 17 blocks each. The table below shows thenumber of sectors per track.

    26

    BYTE DEFINITION0,1 Track and sector of next sequential data block.2-256 254 bytes of data with carriage returns as record terminators.

    BYTE DEFINITION0,1 Track and sector of next block in program me.2-256 254 bytes of program info stored in CBMmemory format (withkey words tokenized). End of file is marked by three zero bytes.

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    30/65

    The DOS contains commands for reading and writing directly to any trackand sector on the diskette. There are also commands for checking to see whichblocks (tracks & sectors) are available, and for marking off used blocks.These commands are transmitted through the command channel(channe[# 15), and tell the disk what to do with the data. The data must be read

    later through one of the open data channels.Opening a Data Channel for Random Access

    When working with random access files,you need to have 2 channels opento the disk: one for the commands, and the other for the data. The commandchannel is OPENed to channel 15, just like other disk commands you'veencountered so far. The data channel for random access files is OPENed byselecting the pound sign (#) as the file name.FORMAT FOR OPENSTATEMENTFORRANDOMACCESSDATA:

    OPEN file#, device#, channel#, "#"or optionally

    OPEN file#, device#, channel#, "# buffer#"EXAMPLES OF OPENING RANDOM ACCESSDATA CHANNEL:

    OPEN 5, 8, 5, "#" DON'T CARE WHICH BUFFER

    OPENA.B.C,"#~BLOCK-READFORMAT FOR BLOCK-READ COMMAND:

    PRINT# file#, "BLOCK-READ:" channel, drive, track, blockor abbreviatedas .PRINT# file#, "B-R:" channel, drive, track, block

    This command will move one block of data from the diskette into theselected channel. Once this operation has been performed, the INPUT# andGET# statements can read the information.

    27

    TRACK NUMBER SECTORRANGE TOTAL SECTORSI to [7 o to 20 2118 to 24 o to 18 1925 to 30 o to 17 1831 to 35 o to 16 17

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    31/65

    SAMPLE PROGRAM TO READ BLOCK 2 FROM TRACK 18: (stores contentsin B$)10OPEN 15,8,1520 OPEN 5, 8,5,"#" ~30PRINT# 15, "B.R:" 5,0, 18,2 ~ } -BB$"" ~ ~ - LOCK40= ~50 FOR L=OTO 25560 GET# 5, A$70 IF ST=OTHEN B$=B$+A$: NEXT L80 PRINT "FINISHED"90 CLOSE 5: CLOSE 15 COLLECT ENTIRE BLOCK,BYTE BY BYTE

    BLOCK-WRITE

    The BLOCK-WRITEcommand is the exact opposite of the BLOCK-READcommand. First you must fill up a data buffer with your information, then youwrite that buffer to the correct location on the disk.FORMAT FOR BLOCK-WRITE COMMAND:

    PRINT# file#, "BLOCK-WRITE:" drive, channel, track, blockor abbreviated asPRINT# file, "B-W:" drive, channel, track, blockWhen the data is being put into the buffer, a pointer in the DOS keepstrack of how many characters there are. Whenyou perform the BLOCK-WRITEoperation, that pointer is recorded on the disk. That is the reason for the STcheck in line 70 of the program above: the ST will become non-zero when youtry to read past the end-of-file marker within thr record.

    SAMPLE PROGRAM TO WRITE DATA ON TRACK 1, SECTOR I:10 OPEN 15,8, IS20 OPEN 5, 8, 5, "#"30FOR L=I to 5040 PRINT#5, "TEST"50 NEXT60 PRINT# 15, "B-W:" 5,0, I, I70 CLOSE 5: CLOSE 15

    28

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    32/65

    BLOCK.ALLOCAIEIn order to safely use random files along with regular files, your programsmust 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 tiles will besafe-at least unless you perform the VALIDATE command (see chapter 3).FORMAT FOR THE BLOCK-ALLOCATE COMMAND:

    PRINT# file#, "BLOCK.ALLOCATE:" drive, track, blockHow do you know which blocks are available to use? If you try a blockthat isn't available, the DOS will set the error message to number 65, NOBLOCK, 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 thenext block available from the error channel and then allocate that block.EXAMPLE OF PROCEDURE TO ALLOCATE BLOCK:

    10OPEN15.8,1520 OPEN5,8,5, "# DRIVE30PRINT#5,"DATA" / ~40T=I:S=1 ~ ~50 PRINT#15, "B-A:"0,T, S~60 INPUT#15, A, B$, C, D70 IF A=65 THEN T=C: S=D: GOTO 5080 PRINT# 15, "B.W:" 5,0, T, S

    BLOCK-FREE

    The BLOCK.FREE command is the opposite of BLOCK.ALLOCATE, inthat it frees a block that you don't want to use anymore for use by the system.It is vaguely similar to the SCRATCH command for files, since it doesn't reallyerase any data from the disk-just frees the entry, in this casejust in the BAM.FORMAT FOR BLOCK.FREE COMMAND:

    PRINT# f1le#, "BLOCK-FREE:" drive, track, blockor abbreviated asPRINT# file#, "B.F:" drive, track, block

    Using Random FilesThe only problem with what you've learned about random fIles so far is

    29

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    33/65

    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 BAMfrom another. You can't tellwhether it contains your random file, just part of a program, or even sequentialor relative mesoTo keep track, the most common method is to build up a sequential file togo with each random file. Use this file to keep just a list of record, track, andblock locations. This means that there are 3 channels open to the disk for eachrandom me: one for the command channel, one for the random data, and theother for the sequential data. This also means that there are 2 buffers that you'refilling up at the same time!

    SAMPLE PROGRAM WRITING 10 RANDOM-ACCESS BLOCKS WITHSEQUENTIALFILE: .10 OPEN 15,8,15

    20 OPEN 5, 8, 5, "#30 OPEN4,8,4, "@O:KEYS,S,W"40 A$= "Record Contents #"50 FOR R=l TO 1070 PRINT# 5, A$ "," R90 T=I: S=1100 PRINT# 15, "B-A:" 0, T, S110 INPUT# 15, A, B$, C, D120 IF A=65 THEN T=C: S=D: GOTO 100130 PRINT# 15, "B-W:" 5, 0, T, S140 PRINT# 4, T "," S150 NEXT R160 CLOSE4: CLOSE 5: CLOSE 15

    SAMPLE PROGRAM READING BACK 10 RANDOM-ACCESS BLOCKS WITHSEQUENTIAL FILE:

    10 OPEN 15,8,1520 OPEN 5, 8, 5, "#"30 OPEN4, 8, 4, "KEYS,S,R"40 FOR R=1 TO 10~50 INPUT# 4, T, S60 PRINT# 15, "B-R:" 5, 0, T, S

    Finds Next Track&Sector Used

    30

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    34/65

    80 INPUT# 5, A$, X90 IF A$ < > "Record Contents #" OR X < > R THEN STOP110 PRINT# 15, "B-F:" 0, T, S "'"120 NEXT R Checks To MakeSure Data Is OK130 CLOSE4: CLOSE5140 PRINT# IS, "S0:KEYS"150 CLOSE 15

    BUFFER-POINTER

    The buffer pointer keeps track of where the last piece of data waswritten.It also is the pointer for where the next piece of data is to be read. By changingthe buffer pointer's location within the buffer, you can get random access to theindividual bytes within a block. This way, you can subdivide each block intorecords.For example, let's take a hypothetical mailing list. The information such asname, address, etc., will take up a total of 64 characters maximum. We coulddivide each block of the random access file into 4 separate records, and byknowing the track, sector, and record numbers, we can access that individualrecord.

    FORMAT FOR BUFFER-POINTER COMMAND:PRINT# file#, "BUFFER-POINTER:" channel, locationor abbreviated asPRINT# file#, "B-P:" channel, location

    EXAMPLE OF SETTING POINTER TO 64THCHARACTER OF BUFFER:PRINT# 15, "B-P:" 5, 64Here are versions of the random access wwiting and reading programsshown above, modified to work with records within blocks:

    SAMPLE PROGRAM WRITING 10 RANDOM-ACCESSBLOCKS WITH 4RECORDSEACH:10OPEN15,8,1520 OPEN 5, 8, 5, "#30 OPEN4, 8,4, "KEYS,S,W"40 A$= "Record Contents #"50 FORR=1TO 1060 FORL=1 TO4

    31

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    35/65

    70 PRINT# IS, "B-P:" 5: (L-I)'" 64 \. P~sition to 0, 64, 128, or 19280 PRINT# 5, AS "," L90 NEXT L100T=I: S=I110 PR]NT# IS, "B-A:" 0; T; S120 ]NPUT# IS, A, BS, C, D

    s.]30 IF A=65 THEN T=C: S=D: GOTO ] 10140 PR]NT# IS, "B-W:" 5; 0; T; S150 PRINT# 4, T "," S160 NEXT R170 CLOSE 4: CLOSE 5: CLOSE 15

    SAMPLE PROGRAM READING BACK 10 RANDOM-ACCESS BLOCKS W]TH4 RECORDS EACH:

    10 OPEN IS, 8, 1520 OPEN 5, 8, 5, "#30 OPEN4, 8,4, "KEYS,S,R"40 FOR R=I TO 1050 ]NPUT#4, T, S60 PRINT# ]5, "B-R:" 5; 0; T; S70 FOR L=1 TO 480 PR]NT# ]5, "B-P:" 5; (L-l)* 6485 ]NPUT# 5, AS, X90 IF AS< > "Record Contents #" OR X=L THEN STOP100 NEXT L110 PRINT# IS, "B-F:" 0; T; S120 NEXT R130 CLOSE4: CLOSE 5140PRINT# 15, "SO:KEYS"150 CLOSE 15

    USERl and USER2The user commands are generally designed to work with machine language(see the next chapter for more on this). The USERI and USER2 commands arespecial versions of the BLOCK-READand BLOCK-WRITEcommands, but. . .

    32

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    36/65

    with an important difference: the way USERl and USER2 work with thebuffer-pointer.The BLOCK-READ command reads up to 256 characters, but stopsreading when the buffer-pointer stored with the block says that block is finished.The USERI command performs the BLOCK-READoperation, but first forcesthe pointer to 255 in order to read the entire block of data from the disk.

    FORMAT FOR USERl COMMAND:PRINT# file#, "VI :,. channel, drive, track, blockorPRINT# file#, "VA;" channel, drive, track, block

    There is no difference between the VI and VA designations for this. command.The BLOCK-WRITEcommand writes the contents of the buffer to the

    block on the disk along with the value of the buffer-pointer. The USER2command writes the buffer without disturbing the buffer-pointer value alreadystored on that block of the diskette. This is useful when a block is to be read inwith BLOCK.READ, updated through the BUFFER-POINTER and PRINT#statements, and then written back to the diskette with USER2.FORMAT FOR VSER2 COMMAND:

    PRINT# file#, "V2;" channel, drive, track, blockorPRINT# file#, "VB:" channel, drive, track, blockFor a more complex sample program, see appendix B.

    7. RELATIVEFILESRelative files allow you to easily zero in on exactly the piece of data thatyou want from the file. It is more convenient for data handling because it allowsyou to structure your files into records, and into fields within those records.The DOS keeps track of the tracks and sectors used, and even allowsrecords 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 sectorsin a file. There can be up to 720 records in a file, and each record can be up to254 characters, so the file could be as large as the entire diskette.

    33

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    37/65

    Creating a Relative FileWhen a relative file is first to be used, the OPEN statement will create thatfile; after that, that samefilewillbe used.The replaceoption (withthe@)sign)

    does not erase and re-create the file. The file can be expanded, read, and writteninto.FORMAT FORTHE OPENSTATEMENTTOCREATERELATIVE FILE:

    OPENfile#, device#, channel#, "name,L," + CHR$(record length)EXAMPLES OF OPEN STATEMENT CREATING RELATIVE FILES:

    OPEN2, 8, 2, "FILE,L,"+CHR$(lOO)OPEN F, 8, F, A$+ ",L,"+ CHR$(Q)OPENA, B,C, "TEST,L,"+ CHR$(33)

    Record Length

    Table 7.1 RELATIVE FILE FORMAT

    34

    DATA BLOCKBYTE DEFINITION0,1 Trackandsectorof next datablock.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 ofthe record. Partially filled records are padded with nulls (00).

    SIDE SECTORBLOCKBYTE DEFINITION0,1 Trackand sector of next side sector block.2 Side sector number. (0-5)3 Record length.4,5 Track and sector of first side sector (number 0)6,7 Track and sector of second side sector (number 1)8,9 Track and sector of third side sector (number 2)10,11 Track and sector of fourth side sector (number 3)12,13 Track and sector of fifth side sector (number 4)14,15 Trackandsector of sicth side sector (number 5)16-256 Trackandsectorpointersto 120data blocks.

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    38/65

    Upon execution, the DOSfirst checksto see if the fileexists. If it does,then nothing happens. The only way to erase an old relative file is by using theSCRATCHcommand (see chapter 4), but not by using the replace option.UsingRelative Files

    In order to OPENa relative file once it exists, the format is simpler.FORMAT FOR OPENING AN EXISTING RELATIVE FILE:

    OPEN file#, device#, channel#, "name"In this case, the DOS automatically knows that it is a relative file. Thissyntax, and the one shown in the above section, both allow either reading orwriting to the file.In order to read or write, you must, before any operation, position the filepointer to the correct record position.

    FORMAT FOR POSITION COMMAND:PRINT# file#, "P" CHRS(channel#) CHR$(rec# 10) CHR$(rec# hi)or optionally asPRlNT#file#, "P" CHR$(channel#) CHR$(rec#lo) CHR$(rec#hi) CHR$(position)

    PRINT# IS, "P" CHR$(2~CHR$(I) CHR$(O)~PRINT# 15, "P" CHR$(CH) CHR$(Rl) CHR$(R2)PRINT# 15, "P" CHR$(4) CHR$(R{fCHR$(R2) ~R$(P)EXAMPLES OF POSITION COMMAND:

    The 2.byte format for the record number is needed because one byte canonly hold 256 different numbers, and we can have over 700 records in the file.The rec# 10contains the least significant part of the address, and the rec# hi isthe most significant part. This could be translated to the actual record numberby the"formula REC#= RECHI * 256 + REC LO.

    Let's assume we have a mailing list. The list consists of 8 pieces of data,according to this chart:Field Name Lengthfirst namelast nameaddress line 1address line 2city

    1215202012

    state 2zip code 9phone number 10----------TOTAL 100

    35

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    39/65

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    40/65

    This program asks for record numbers when retrieving records. It won't letyou retrieve from beyond the end of the file, and if you try to write beyond theend it forces you to write on the next higher record.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 searchfor a record by name, or print out labels by zip code. For this you would need aseparate 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 willsave much time to create a record at the projected end of the file. In otherwords, if you expect the file to be 1000 records long, create a record# 1000 assoon as the file is created. This will force the DOS to create all intermediate

    records, making later use of those records much faster.EXAMPLEOF CREATING LARGE FILE:

    OPEN 1,8, IS: OPEN 2, 8, 2, "REL,L,"+ CHR$(60)PRINT# I, "P" CHR$(2) CHR$(O)CHR$(4) CHR$(I)PRINT# 2, "END"CLOSE 2: CLOSE I8. PROGRAMMING THE DISK CONTROLLER

    The expert programmer can actually design routines that reside andoperate on the disk controller. DOS routines can be added that come from thediskette. Routines can be added much the same way as the DOS SupportProgram is "wedged" into your memory.BLOCK.EXECUTE

    This command will load a block from the diskette containing a machinelanguage routine, and begin executing it at location 0 in the buffer until aRTS(ReTurn from Subroutine) command is encountered.FORMAT FOR BLOCK-EXECUTE:

    PRINT# file#, "BLOCK-EXECUTE:" channel, drive, track, blockor abbreviated asPRINT# file#, "BLOCK-EXECUTE:" channel, drive, track, blockMEMORY.READ

    There is 16K of ROM in the disk drive as well as 2K of RAM.You can getdirect access to these, or to the buffers that the DOS has set up in the RAM,byusing the MEMORY commands. MEMORY-READ allows you to select whichbyte to read, through the error channel.

    37

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    41/65

    FORMATFORMEMORY-READ:PRINT# file#, "M-R:" CHR$(low byte of address) CHR$(high byte)(no abbreviation!)The next byte read using the GET# statement through channel# IS, theerror channel, will be from that address in the disk controller's memory, andsuccessivebytes will be from successivememory locations.Any INPUT# to the error channel will give peculiar results when you'reusing this command. This can be cleared up by any other command to the disk(besides a memory command).

    PROGRAM TO READ THE DISK CONTROLLER'S MEMORY:10OPEN15,8,1520 INPUT "LOCATION PLEASE"; A30 AI= INT(A/2S6): A2=A-Al *25640 PRINT# IS, "M-R:" CHR$(A2) CHR$(AI)SOFOR L=I TO 560 GET# IS, A$70 PRINT ASC(A$+CHR$(O));80 NEXT90 INPUT "CONTINUE";A$100 IF LEFT$(A$,I) ="Y" THEN SO110 GOTO 20

    MEMORY-WRITE

    The MEMORY-WRITEcommandallowsyou to write up to 34 bytesat atime into the disk controller's memory. The MEMORY-EXECUTEand USERcommands can be used to run this code.FORMAT FOR MEMORY-WRITE:

    PRINT# file#, "M-W:" CHR$(low address byte) CHR$(high address byte)#-of-characters; byte dataPROGRAM TO WRITE A "RTS" TO DISK:

    I 0 OPENIS, 8, IS. "M-W:" CHR$(O)CHR$(S); I; CHR$(96)20 PRINT# IS, "M-E:" CHR$(O)CHR$(I 9): REM JUMPSTOBYTE,RETURNS30 CLOSE IS -MEMORY-EXECUTE

    Any routine in the DOSmemory, RAMor ROM, can be executed with theMEMORY-EXECUTEcommand.38

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    42/65

    FORMAT FOR MEMORY-EXECUTE:PRINT# file#, "M-E:" CHR$(1ow address byte) CHR$(high byte)

    USER CommandsSee line 20 above for an example.

    Aside from the USERI and USER2 commands discussed in chapter 6, andthe UI+ and UI- commands in chapter 2, the USER commands are jumps to atable of locations in the disk drive's RAMmemory.USER COMMANDUI or UAU2 or UB03 or UCU4 or UDUS or UEU6 or UFU7 or UCU8 or UHU9 or VIU; or UJVI+VI-

    FUNCTIONBLOCK-READwithout changing buffer-pointerBLOCK-WRITEwithout changingbuffer-pointerjump to $0500jump to $0503jump to $0506jump to $0509jump to $050Cjump to $050Fjump to $FFF Apower-up vectorset Commodore 64 speedset VIC 20 speed

    By loading these locationswith anotherjump command,likeJMP$0520,you can create longer routines that operate in the disk's memory along with aneasy-to-usejump table-even from BASIC!EXAMPLES OF USER COMMAMDS:

    PRINT# 15,"03"PRINT# 15, "U"+ CHR$(50+Q)PRINT# 15, "VI"

    Software Method9. CHANGING THE DISK DRIVE DEVICE NUMBER

    The devicenumber is selectedby the drive by looking at a hardwarejumper on the board and writing the number based on that jumper in a sectionof its RAM. Once operation is underway, it is easy to write over the previousdevice number with a new one.FORMAT FOR CHANGING DEVICE NUMBER:

    39

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    43/65

    PRlNT# file#, "M-W:" CHR$(119) CHR$(O)CHR$(2) CHR$(address+32)CHR$(address+64)EXAMPLE OF CHANGING DEVICE NUMBER:

    PRINT# 15, "M-W:" CHR$(l19) CHR$(O)CHR$(2) CHR$(9+32) CHR$(9+64)PRlNT# Q, "M-W:" CHR$(119) CHR$(O)CHR$(2) CHR$(R+32) CHR$(R+64)

    If you have more than one drive, it's sensible to change the addressthrough hardware (see below). If you must, the procedure is easy. Just plug inthe drives one at a time, and change their numbers to the desired new values.That way you won't have any conflicts.Hardware Method

    It's an easy job to permanently change the device number of your drive foruse in multiple drive systems. The tools needed is a phillips-head screwdriver anda knife.STEPS TO CHANGING DEVICE NUMBER ON HARDWARE:

    1. Disconnect all cables from drive, including power.2. Turn drive upside down on a flat, steady surface.3. Remove 4 screws holding drive box together.4. Carefully tum drive right side up, and remove case top.S. Remove 2 screws on side of metal housing.6. Remove housing.7. Locate device number jumpers. If facing the front of the drive, it'son the left edge in the middle of the board.8. Cut either or both of jumpers 1 and 2.9. Replace housing and 2 screws, and case top and 4 screws.10. Re-connect cables and power up.The jumper number is added to the old device number (8) when cut. Inother words, jumper 1 adds 1, and jumper 2 adds 2, to the device number. Ifnone are cut, the number is 8, if 1 is cut it goes up to 9, and if only 2 is cut thenumber is 10. If both I and 2 are cut, the number is 11.

    40

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    44/65

    Appendix A: Disk Command Summary

    COMMANDGeneral Format: PRINT# file#, command

    COMMAND FORMATNEWCOpyNAMESCRATCHINITIALIZEVALIDA TEDUPLICATEBLOCK-READBLOCK-WRITEBLOCK-ALLOCATEBLOCK-FREEBUFFER-POINTERUSERl. and USER2POSITIONBLOCK.EXECUTEMEMORY-READMEMORY-WRITEMEMORY-EXECUTEUSER Commands

    "N"CO:new file=O:originalfile"RO:new name=O:old name"SO:file name"I"Vnot for singledrives"B-R:" channel; drive; track; block"B-W:" channel; drive; track; block"B-A:" drive; track; block"B-F:" drive; track; block"B.P:" channel; position"Un:" channel; drive; track; block"P" CHR$(channel#) CHR$(rec# 10)CHR$(rec# hi)CHR$(position)"B-E:" channel; drive; track; block"M-R:" CHR$(address 10)CHR$(address hi)"M-W:" CHR$(address 10)CHR$(address hi) CHR$(# chars) "data""M-E:" CHR$(address 10)CHR$(address hi)"Un:"

    41

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    45/65

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    46/65

    DESCRIPTIONOF DOSERRORMESSAGESNOTE: Error message numbers less than 20 ~hould be ignored with theexception of 01 which gives information about the number of files scratchedwith the SCRATCHcommand.20: READ ERROR (block header not found)The disk controller is unable to locate the header of the requested datablock. Caused by an illegal sector number, or the header has beendestroyed.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/write head, no diskette is present, or

    unformatted or improperly seated diskette. Can also indicate a hardwarefailure.22: READ ERROR (data block not present)The disk controller has been requested to read or verify a data block thatwas not properly written. This error message occurs in conjunction withthe BLOCKcommands and indicates an illegal track and/or sector 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 thechecksum over the data is in error. This message may also indicategrounding problems.24: READ ERROR (byte decoding error)The data or header has been read into the DOS memory, but a hardwareerror has been created due to an invalid bit pattern in the data byte. Thismessagemay also indicate grounding problems.25: WRITE ERROR (write-verify error)This message is generated if the controller detects a mismatch between the

    written data and the data in the DOSmemory.26: WRITE PROTECTON

    This message is generated when the controller has been requested to writea data block while the write protect switch is depressed. Typically, this iscaused by using a diskette with a write protect tab over the notch.27: READ ERROR (checksum error in header)The controller has detected an error in the header of the requested datablock. The block has not been read into the DOS memory. This message

    may also indicate grounding problems.

    43

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    47/65

    28: WRITE ERROR (long data block)The controller attempts to detect the sync mark of the next header afterwriting a data block. If the sync mark does not appear within apre-determined time, the error message is generated. The error is caused bya bad diskette format (the data extends into the next block), or byhardware failure.

    29: DISK IDMISMATCHThis message is generated when the controller has been requested to accessa diskette which has not been initialized. The message can also occur if adiskette has a bad header.

    30: SYNTAX ERROR (general syntax)The DOS cannot interpret the command sent to the command channel.Typically, this is caused by an illegalnumber of file names, or patterns areillegally used. For example, two file names may appear on the left side ofthe COPYcommand.

    31 : SYNTAXERROR (invalid command)The DOS does not recognize the command. The command must start inthe first position.32: SYNTAXERROR (long line)The command sent is longer than 58 characters.33: SYNTAX ERROR (invalid file name)Pattern matching is invalidly used in the OPENor SAVEcommand.34: SYNTAX ERROR (no file given)

    The file name was left out of a command or the DOS does not recognize itas such. Typically, a colon (:) has been left out of the command.39: SYNTAXERROR (invalid command)This error may result if the command sent to command channel

    (secondary address IS) is unrecognizable by the DOS.50: RECORDNOT PRESENT

    Result of disk reading past the last record through INPUT#, or GET#commands. This message will also occur after positioning to a recordbeyond end of file in a relative file. If the intent is to expand the file byadding the new record (with a PRlNT# command), the error messagemaybe ignored. INPUT or GET should not be attempted after this error isdetected without first repositioning.51: OVERFLOWIN RECORD

    PRINT# statement exceeds record boundary. hiformation is truncated.Since the carriage return which is sent as a record terminator is counted inthe record size, this messagewill occur if the total characters in the record(including the final carriage return) exceeds the defined size.

    44

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    48/65

    52: FILE TOO LARGERecord position within a relative file indicates that disk overflow willresult.

    60: WRITE FILE OPENThis message is generated when a write file that has not been closed isbeing opened for reading.61: FILE NOT OPEN

    This message is generated when a file is being accessed that has not beenopened in the DOS. Sometimes, in this case, a message is not generated;the request is simply ignored.6 '")... 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 therequested file.65: NO BLOCK I

    This message occurs in conjuction with the B-Acommand. It indicatesthat the block to be allocated has been previously allocated. Theparameters indicate the track and sector available with the next highestnumber. If the parameters are zero (0), then all blocks higher in numberare in use.66: ILLEGAL TRACK AND SECTOR

    The DOS has attempted to access a track or sector which does not exist inthe format being used. This may indicate a problem reading the pointer tothe next block.67: ILLEGAL SYSTEM T OR SThis special error message indicates an illegal system track or sector.70: NO CHANNEL(available)The requested channel is not available, or all channels are in use. Amaximum of five sequential files may be opened at one time to the DOS.Direct accesschannels may have six opened files.71: DIRECTORY ERROR

    The BAM does not match the internal count. There is a problem in theBAM allocation or the BAMhas been overwritten in DOS memory. Tocorrect this problem, reinitialize the diskette to restore the BAM inmemory. Some active files may be terminated by the corrective action.NOTE: BAM =Block Availability Map

    45

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    49/65

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    50/65

    APPENDIX C: Demonstration Disk Programs1. D/R4 OPEN2.. 8,155 PRINT":1":GOTO 11211211211211101OPENL8..e, "$101"2121 GETlll,A$,B$313 GETIIL A$, B$413 GETIIL A$, B$5101 C=!!I60 IF A$()"" THEN C=ASC(A$)713 IF B$()"" THEN C=C+ASC(B$)i!!2568101 PRINT" ~"MID$(STR$(C), 2); TAB(3); "~";913 GETlll,B$:IF ST(>e THEN 11211313lee IF B$(>CHR$(34) THEN 912111121 GETlll,B$:IF B$(>CHR$(34)THEN PRINTB$; : GOT01112112121 GETlll,B$:IF B$=CHR$(32) THEN 1212113121 PRINT TAB"" THEN 1412115121 PRINT"~"LEFT$(C$,3)16121 GET T$: IF T$O"" THEN GOSUB 2121012117121 IF ST~12I THEN 31211121121121RINT" BLOCKS FREE"11211121 CLOSE1:GOTO 1121121121121213121121F T$="Q" THEN.CLOSE1:END21211121GET T$: IF T$="" THEN 2121131212132121 RETURN413121121EM DISK COMMAND4131121 C$="":PRINT")";412111 GETB$: I FB$="" THEN412111412112 PRINTB$; :IF B$=CHR$(13) THEN 41212121412113 C$=C$+B$:OOTO 41211141212121PRHITII2, C$5121121121RINT"~".:51211121GETII2,A$:PRINTA$; :IF A$(>CHR$(13)GOT05121112151212121PRINT"~"11211210121RINT "D-DIRECTOR'T"11211211121RINT ")-DISK COMMAND"10020 PRINT "Q-QUIT PROGRAM"101213121PRINT "S-DISK STATUS "11211121121ETA$:IFA$=""THENl1211121121102121121IF A$="D" THEN 1121112131210IF A$="." OR A$=")" OR A$=">" THEN 4121121121112131121IF A$="Q" THEN END112132121IF A$="S" THEN 51211211211121999 GOTO 11211121121

    2. VIEW SAM1121121EM ************.*.*.*..*.*...10.1 REM. VI~W BAM FOR VIC & 64 DISK *102 REM ,..........................1121:5OPEN15,S,1511121 PRINTII15,"II2I":NU$="N/A N/A N/A N/A N/A":Z4=112121 OPEN2,S,2,"II"13121 'T$~" j:!)roll)lnal!lwt~tljl)jll~l)q'a.aIQ)'OO)II~J"14121 X$=" "15121 DEF FNS(Z) = 2f(S-INT(S/S)i!!S) AND (SB(INT(S/S)

    47

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    51/65

    1613 PRINTiI5."Ul:";2;0;18;a17121 PRINTiI5."B-P";2;118121PRINT":'1";19121 =22:X=I:GOSUB43a2130 FORI=0T020:PRINT:PRINT":T1"RIGHT$(STR$(I>+" ".3); :NEXT21121GET#2,A$220 GEHI2. A$23121GET#2., A$240 TS=025121FORT=lTOI7:GOSUB45026121Y=22:X=T+4:GOSUB43e:GOSUB54a:NEXT270 FORI=lT02a0a:NEXT:PRINT":'1"28121Y=22:X=I:GOSUB43029121FORI"0T02a: PRUIT: PRINT":T1"RIGHT$(STR$( I)+" ".3);: NEXT31210FORT=18T03531121 GOSUB45032121Y=22:X=T-13:GOSUB43a:GOSUB~4a:NEXT330 FORI=lT0100a:NEXT34121PRINT"~"350 PRIt~T#15. "B-P"; 2; 14436121N$="":FORI=IT020:GET#2,A$:N$=N$+A$:NEXT37121PRINT" "N$" "TS-17;"BLOCKS FREE"38121FORI=IT04aaa:NEXT3913 PRUIT":,]"400 INPUT" J.MdIJFI~IOTHER DISKETTE t~I..I".: A$410 IFA$="Y"THENRUN42121IFA$O""THENEND43121PRINTLEFT$(Y$. Y)LEFT$(X$. >0 "II";44121RETURH45121GET#2.SC$:SC=ASC(RIGHT$(CHR$(0)+SC$.1460 TS=TS+SC47121GET#2.A$:IFA$=""THENA$=CHR$(0)480 SB(0)=ASC(A$)4913 GET#2,A$:IFA$=""THENA$=CHR$(a)51210SB(I)=ASC(A$)51121GET#2., A$: I FA$= '''' THEHA$=CHR$ (.,)52121SB(2)=ASC(A$)530 RETUR~I54121PRIHT"QI"RIGHT$(STR$(T). 1); "1m";55121REM PRUITT" "SC" "SB(a)" "SB( 1)" "SB(2)=CHR$(e)56121IFT>24AHDS=18THEH:PRINTMID$(NU$.Z4,1); :GOT0661215713 FORS=0T02058121IFT30AHDS=17THEN:PRINTMID$(NU$.Z4.1); :GOT066e6121121FT)24AHDS=18THEN:PRINTMID$(NU$.Z4.1); :GOT066e61121IFT)24AHDS=19THENPRINTMID$(NU$,Z4.1); :GOT066a6213 IFT>17AHDS=2aTHENPRINTMID$(NU$,Z4.1); :24=24+1:GOT066a6313 PRIt~T" ::I".:64121 IF F~IS(S) =121THEN PR HIT" +".: :GOT066a6513 PRIt~T"!!!+".: :REt1RIGHT$(STR$(S). 1); 24.1).: :GOT0726613 PRU~T""I!!!";6713 NEXT6813 RETUR~I

    48

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    52/65

    3. DISPLAYT&Slee REM"'''' '..'*' ' *-.lIe REt1'" DISPLA'T' A~JY TRACK $ SECTOR '"1213 REM. ON THE DISK TO THE SCREEN .1313 REM. OR THE PRINTER *-1413 REM"'''''''''''''''''''''''''''''''''''''''''''*'''''''''*'''**'''''''''''''''..1513 PRHH":'IIIiIIl1613 PRHIT"DISPLA'T' BLOCK COtnENTS"165 PRINT" ":1713REM * "''''.'''.'''.........1813 REM'" SET PROORAMCONSTANT ...1913REM..".'."".." "'......_._.21313SP$=" ": NL$=CHR$(e) :H7~$="eI23456789ABCDEF"2113 FS$="":FORI=64 TO 95:FS$=FS$+"~"+CHR$(I)+"!!":NEXT I2213 SS$=" ":FOR 1=192 TO 223:SS$=SS$+"~"+CHR$(I)+"!!":NEXT2413 DIM A$(15),NB(2)251 D$="0"253 PRINT" ~!!!J;REENQ.DI..II.8)R QI:P!!RINTER"254 GETJJ$: IF JJ$="" THEN254255 IF JJ$="S"THE~IPRHIT"256 IF JJ$="P"THENPRINT"2613 OPEN15.8.15."I"+D$:GOSUB265 OPEN4.42713 OPEN 2,8,2, "#":OOSUB 6502813 REM."' ",,,,...*...,,, *,,,,,,.,,,***,,,2913 REM'" LOAD TRACK AND SECTOR *31313REM... INTO DISK BUFFER .3113 REt1"'.************"'** *............3213 INPUT" :ODITRACK, SECTOR".: T.'S3313 IF T=e OR T>35 THEN PRINT#15."I"D$:CLOSE2:CLOSE4:CLOSE15:PRINT"END":E~1D3413 IF JJ$="S" THEN PRINT":ODITRACK"T" SECTOR"S")1"341 IF JJ$="P" THEN PRINT#4:PRINT#4."TRACK"T" SECTOR"S:PRINT#43513 PRINT#15."Ul:2,"D$;T;S:GOSUB6503613 REM *** ** "' * *............3713 REM. READ BYTE 13 OF DISK BUFFER ...3913 REM................................................4013 PRINT#15,"B-P:2,1"4113 PRINT#15, "M-R"CHR$(e)CHR$(5)4213 GET#15,A$(e):IFA$(e)=""THENA$(e)=NL$428 IF JJ$="S"THEN43e4313 IF JJ$="P"THE~146e431 REM "'...** "'''''''*******''' * '''432 REM* READ & CRT DISPLAY ...433 REM'"REST OF THE DISK BUFFER ...434 REM................................................................436 K=l:NB(l)=ASC(A$(13438 FOR J=e TO 63: IF J=32 THEN GOSUB 7H): IF Z$="N"THEN J=80:00TO 4584413 FOR I=K TO 3442 GET#2, A$( 1) : IF A$( 1)='''' THEN A$( 1)=t.jL$444 IF K=l AND 1(2 THEN NB(2)=ASC(A$(I446 NEXT I: K=0448 A$="":B$=":":N-J.4:00SUB 7ge:A$=A$+":"4~e FOR 1=0 TO 3:N=ASC(A$(I:GOSUB 790452 C$=A$(I):GOSUB 8513:B$=B$+C$454 NEXT I:IF JJ$="S" THEN PRINTA$B$458 NEXT J:GOT0571

    )1~CREEN!!")1:PRINTER!!"6513

    49

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    53/65

    4613 REM******************************462 REM* READ & PRINTER DISPLAY *464 REM********************_**_******466 K~l:NB(l)=A$C(A$(e468 FOR J=0 TO 154713 FOR I=K TO 15472 GETII2,A$

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    54/65

    4. CHECK DISK1 REM CHECK DISK -- VER 1.42 DN=8:REM FLOPP~ DEVICE NUMBER5 DIMT(laa):DIMS(laa):REM BAD TRACK, SECTOR ARRA~51 PRINT":'MWOO "113 PRINT" CHECK DISK PROGRAM"12 PRINT"213 D$="a"313 OPEN15,DN,1535 PRHITII15,"V"D$45 N~=RND(TI)*255513 A$= ''"':FOR I= 1 T0255 :A$=A$+CHR$ (255AND (1 +Nr. :NEXT6a GOSUBSlaa713 OPEN2,DN,2, "II"813 PRINT:PRINT#2,A$;85 T=l: 5=13913 PRINTII15, "B-A: "D$; T.:$11313INPUTII15,EN,EM$,ET,ES1113 IFEN=aTHEN13a115 IFET=aTHEN2aa:REM END1213 PRINTII15, "B-A: "D$.:ET; ES: T=ET: S=ES1313 PRINTII15."U2:2,"D$;T;$134 NB=NB+l:PRINT" CHECKED BLOCKS"NB135 PRINT" TRACK IIIII"T;" SECTOR 11111"S ":11"1413 INPUT#15.EN,EM$.ES,ET150 IF EN=0THEN851613 T(J)=T:S(J)=S:J=J+l165 PRINT"~AD BLOCK: III",T; 5''"'1713 GOT08521313PRINTII15,"I"D$2113 G05UBSla13212 CLOSE2215 IFJ=aTHENPRINT"mlD..tlO BAD BLOCKS!":END2170PEN2.DN,2."#"218 PRINT"~AD BLOCKS","TRACK","SECTOR"2213FORI=aTOJ-l2313PRINTII15,"B-A:";D$,T(I);S(I)2413PRINT"T(I>.S(I) .2513NEXT2613 PRINT":.I"J"BAD BLOCKS HAVE BEEN ALLOCATED"2713CLOSE2:END511313NPUT#15.EN,EM$,ET,ES9113 IF EN=a THEN RETURN$1213PRINT":.lERROR !!"EN,EI1$;ET; E5''"'9313 PRINTII15,"I"D$

    5. PERFORMANCE TEST1131313REM PERFORMANCE TEST 2.13113113113213REM VIC-2a AND COMMODORE 64113313REM SINGLE FLOPP~ DISK DRIVE113413113513OPEN 1,S,15:0PEN15,S,15113613LT=35113713LT$=STR$(LT>

    51

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    55/65

    1"'81:1 NT=30\1390 !>!>.IN,'':N~~1%~~i~~':, ?ERFQR\~~HCE ,I::S,"1121:1 PRINT1131:1 PRINT" INSERT SCRATCH"1.1413 PRINT1150 PRINT" DISKETTE IN DRIVE"11613PRINT11713 PRHIT"~ PRESS ~ETURN!!!"1180 PRINT1Ige PRINT" WHEN READ'r'JII"1200 FOR 1=0 TO 50:GET A$:NEXT12110 GET A$:IF A$()CHR$(13) THEN 1210'22012301240 TI $=" 000000"1250 TT=181260 PRINT#I, "N0:TEST DISK,e0"12713 Cl$=" DISK NEW COMMAND "+CHR$( 13)1280 C2$="JII WAIT ABOUT 80 SECONDS"1290 CC$=Cl$+C2$:GOSUB 1840131313IF TI(NTTHENI37e13113 PRINT"~'r'STEM IS"1320 PRINT"~ NOT RESPONDING"13313 PRH~T" CORRECTL'r' TO COMMANDS"13410 GOSUB 1881313581361313713 PRINT":.IDRIVE PASS"13813 PRINT" MECHANICAL TESTJII"13913 TT=21141313OPEN 2.8,2, "0:TEST FILE,S,W"1410 CC$="OPEN WRITE FILE" :GOSUB 184131.420 CH=2:CC$="WRITE DATA" :GOSUB 193131430 CC$="CLOSE "+CC$ : GOSUB 1841314413 OPEN 2.8,2, "13:TEST FILE,S,R"14513 CC$="OPEN READ FILE" :GOSUB 18401460 CH=2:GOSUB 19901470 PRINT#l, "S0: TEST FILE"1488 CC$="SCRATCH FILEJII":TT=1 :GOSUB 1848149131501315113 TT=2115213 OPEN 4.8,4,"#"15313 N~I~=( 1+RND(T I ) .254+NN~) AND255 :PR INTIT1 , "B-P" ; 4; NN~15413 NN$="":FOR 1=1 TO 255:NN$=NN$+CHR$(I):NEXT1550 PRINT# 4,NN$;15613 PRINT# 1,"U2:";4;8;LT;1315713 CC$="WRITE TRACK"+LTS:GOSUB 1841315813 PRINT#I,"U2:";4;13;I;e15913 CC$="WRITE TRACK 1" :GOSUB 1840161313 PRINT#I,"Ul:";4;e;LT;e16113 CC$="READ TRACK"+LTS :GOSUB 1841316213 PRINT#I,"Ul:";4;e;I;1316313 CC$=" READ TRACK 1" :GOSUB 1841316413 CLOSE 416513 : !16613 :

    52

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    56/65

    167121PRINT"J.1 UNIT HAS PASSED"168121PRINT" PERFORMANCE TEST!"16913 PRINT")) PULL DISKETTE FROM"171313PRINT")) DRIVE BEFORE TURNING"1713 PRINT" POI~ER OFF."172121END173017413 :175121PRINT" J.1CONTINUE (.../N)?";17613 FOR 1=13 TO 50:GET A$:NEXT17713 GET A$: IF A$="" THEt~ 177121178121PRINT A$"JII"17913 IF Af="N" THEN END181313 IF A$=""''' THEN RETURN18110 GOTO 17613182101831211841318513186131871211881318913191313191131921319313194019513196131971319813199102130020113213202031320402050212160

    PRIm CC$INPUT# 1,EN,EM$,ET,ESPRUITTAB( 12)" "EN; Et1$; ET; ES; ""IF EN

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    57/65

    APPENDIX D: DISK FORMATS

    NOTENot to scale

    1540/1541 Format: Expanded View of a Single Sector

    54

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    58/65

    Block Distribution by Track

    1540/1541 BAM FORMAT

    55

    2040,3040 Block orTrack number Sector Range TotalI to 17 o to 20 2118 to 24 o to 19 2025 to 30 o to 17 1831 to 25 o to 16 17

    4040 Block orTrack number Sector Range Total1 to 17 o to 20 21

    18 to 24 o to 18 1925 to 30 o to 17 1831 to 35 o to 16 178050 Block orTrack number Sector Range Total1 to 39 o to 28 2940 to 53 o to 26 2754 to 64 o to 24 25

    65 to 77 o to 22 23

    Track 18, Sector O.BYTE CONTENTS DEFINITION0,1 18,01 Track and sector of first directory block.2 65 ASCII character A indicating 4040 format.3 0 Null flag for future DOS use.4-143 Bit map of available blocks for tracks 1.35.*1=available blockO=blocknot available

    (each bit represents one block)

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    59/65

    * STRUCTURE OF SINGLE DIRECTORY ENTRY

    SEQUENTIAL FORMAT

    PROGRAM FILE FORMAT

    56

    BYTE CONTENTS DEFINITION0 128+type File type OR'ed with $80 to indicate properlyclosed file.TYPES: 0= DEleted

    I = SEQential2 = PROGram3 = USER4 = RELative1-2 Track and sector of Ist data block.3-18 File name padded with shifted spaces.19-20 Relative file only: track and sector for first sidesector block.21 Relative file only: Record size.22-25 Unused.26-27 Track and sector of replacement file when OPEN@is in effect.28-29 Number of blocks in file: low byte, high byte.

    BYTE DEFINITION0.1 Track and sector of next sequential data block.2-256 254 bytes of data with carriage return as record terminators.

    BYTE DEFINITION0,1 Track and sector of next block in program me.2-256 254 bytes of program info stored in CBMmemory format (withkey words tokenized). End of file is marked by three zero bytes.

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    60/65

    1540/1541 DIRECTORYHEADER

    DIRECTORY FORMAT

    57

    Track 18, Sector O.BYTE CONTENTS DEFINITION144-161 Diskname padded with shifted spaces.162-163 Disk 10.164 160 Shifted space.165-166 50,65 ASCII representation for 2Awhich is DOSversion and format type.166-167 160 Shifted spaces.177-255 0 Nulls, not used.Note: ASCIIcharacters may appear in locations 180 thru 191 on some diskettes.

    Track 18, Sector 1BYTE DEFINITION0-1 Track and sector of next directory block.2-31 *File entry 134-63 *File entry 266-95 *File entry 398-127 *File entry 4130-159 *File entry 5162-191 *File entry 6194-123 *File entry 7226-255 *File entry 8

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    61/65

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    62/65

    VIC-1541 User's Manual Errata Sheet.

    INTRODUCTIONCommodore is constantly trying to bripg you the most efficient and reliablecomputer in the world today. Alongwit~ the hardware improvements that comefrom practical applications of the 154i disk drive in the marketplace, the docu-mentation should also reflect any changes and/or improvements that occur.This is the most up-to-date information available for your 1541 disk drive. Thechanges listed here s~ould be used to replace the comparable information inyour User's Manual..~Future updates will normally be available through theCommodore User's Magazines(COMMODOREand POWERPLAY) as well asthe COMMODOREINFORMAT~ONN~TWORKon CompuServe.The format ofthis update is as follows:A. 1. Pageand Paragraphor Section ofthe VIC-1541User's Guide.

    2. Old information.3. Newinformation.

    Example:A. 1. P.3, INTRODUCTION,paragraph 5

    2. ... use your Commander 64 or VIC20 User's Guides. . .3. ... use your Commodore 64 or VIC 20 User's Guides. . .

    The following listing is performed in numerical order by page.A. 1. P. 3, INTRODUCTION,paragraph 5

    2. ... use your Commander 64 or VIC20 User's Guides. . .3. ... use your Commodore 64 or VIC 20 User's Guides. . .

    B. 1. P. 4, SPECIFICATIONS,paragraph 2, line 62. The "pipeline" makes the disk abot to process commands. . .3. The "pipeline" makes the disk able to process commands. . .

    C. 1. P. 7, CONNECTIONOF CABLES,paragraph 3, line 32. ... at one time, read chapter 8 . . .3. ... at one time, read chapter 9 . . .

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    63/65

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    64/65

    M. 1. P. 23, READINGTHEDIRECTORY,sample program, line 102. 10 OPEN1, 8, 2, "s3. 10 OPEN1,8,2, "$

    N. 1. P.24,TABLE5.1,line4-1432. 4-143 Bit map of availableblocks for trace 1-353. 4-143 * Bit map of availableblocks for trace 1-35

    O. 1. P. 27, TABLETOPOF PAGE272.3. Table 6.1 TRACKANDBLOCKFORMAT

    P. 1. P. 30, SAMPLEPROGRAMWRITING10 RANDOM-ACCESS.. . ,lines 40, 90, 100, 120, 130, 1402. 40 A$="Record Contents #"90 T=l : S=1100 PRINT# 15, "B-A:" 0, T, S120 IF A=65THENT=C: S=D: GOTO 100

    130PRINT#15, "B-W:" 5,0, T,S140 PRINT#4, T "," S3. 40 A$="RECORDCONTENTS#"90 T=1: B=1100 PRINT# 15, "B-A:" 0, T, B120 IFA=65THENT=C: B=D:GOTO100130 PRINT# 15, "B-W:" 5,0, T, B140 PRINT#4, T;B

    Q. 1. P. 31-32 SAMPLE PROGRAM WRITING 10 RANDOM-ACCESS..., lines 40, 100, 110, 130, 140, 1502. 40 A$="Record Contents #"100 T=1 : S=1110 PRINT# 15, "B-A:" 0 ;T;S130 IF A=65 THENT=C : S=D: GOTO110140 PRINT# 15, "B-W:" 5,0, T; S150 PRINT# 4, T " ," S

    3. 40 A$="RECORDCONTENTS#"100 T=1 : B=1110 PRINT# 15, "B-A:" 0; T; B130 IFA=65THENT=C: B=D: GOTO 110140 PRINT# 15, "B-W:" 5; 0; T; B150PRINT#4, T; B

  • 8/8/2019 Commodore Vic 1541 Floppy Drive Users Manual

    65/65

    R. 1. P. 41, APPENDIXA: DISKCOMMANDUMMARY,ine32. NAME "RO:new name. . .3. RENAME "RO:newname. . .

    S. 1. P.46, 72: DISKFULL,lines2-32. . . . 152entriesfor the 2040,3040,and4040or 243entriesfor the8050 . . . . whentwoblocksareavailableonthe 8050to . . .3. . . . 144 entries for the 1541 . . . . when two blocks are availableonthe 1541to . . .

    T. 1. P.46, 73:DOSMISMATCH,itle line2. DOSMISMATCH73, CBMDOSV2.58050)(73, CBMDOSV2)for40403. DOSMISMATCH73,CBMDOSV2.61541)

    U. 1. P.46, 74:DRIVENOTREADY,ine12. Anattempthasbeenmadeto accessthe 8050DualDriveFloppyDisk.3. Anattempthasbeenmadeaccessthe 1541SingleDrive. . .