Commodore 1541 User Manual
विज्ञापन
विज्ञापन
USER'S GUIDE STATEMENT
This equipment genera t es and uses rad i o frequency energy . If it is not . prop er ! installed and used in strict accordance with the manufacturer ' s instructions , thi equipment may interfere with radio and television reception . This m~chine h a been tested and found to comply with the limits for a Class B computing de v ic e peripheral in accordance with the specifications in Subpart 1 5 . of FCC Ru l .
e s which are designed to provide reasonable protection against such interference 1n res i dential installation . If you suspect interference , you can test this equipmen t by turning it off and on. If you determine that there is interference with .
radio or te l e vi sion reception , try one or more of the following measures to correct 1t:
• reorient the receiving antenna e move the computer away from the receiver . .
• change the relative positions of the computer equipment and the receiver .
• plug the computer into a different outlet so that the computer and the rec e iv e · are on different branch circuits I
If necessary , consult your Commodore dealer or an e .
xperienced radio / telev is ~o technician for additional suggestions . You may also wish to consult the follo w ing booklet , which was prepared by the Federal Communications Commission :
" How to identify and Resolve Radio-TV Interference Problems " This bookl e t i available from the U .
S . Government Printing Office, Washington, D .
C . 204 02 ,
Stock No . 004 000-00345 4 ."
IMPORTANT : Shield interface cable must be used according to FCC 14 .
8380 .
FOR USERS IN UK
WARNING : THIS APPARATUS MUST BE EARTHED!
IMPORTANT . The wires in this mains lead are coloured in accordance with the fo l lowing code :
Green and yellow
Blue
Brown
Earth
Neutral
Live
As the colours of the wires in the mains lead of this apparatus may not corresp o nc with the coloured marking identifying the terminals in your plug , proceed as follo ws .
The wire which is coloured green and yellow must be connected to the termin a l in the plug which is marked by the letter E or by the safety earth symbol-or colou re d green or green and yellow .
I
The wire which is coloured blue must be connected to the terminal whic h is marked with the letter N or coloured black .
The wire which is coloured brown must be connected to the terminal whic h is marked with the letter Lor coloured red .
I l
[ _
COMMODORE
.,541
DISK DRIVE
USER'S GUIDE
A Friendly Introduction to Your 1541 Diak Drive
Second Edition by Jim & Ellen Btraama
(::commodore
COMPUTER
S
The information in this manual has been reviewed and is believed to be entirely reliable .
No responsibility, however , is assumed for inaccuracies . The material in this manual is for information purposes only, and may be changed without notice .
© Commodore Electronics Ltd ., September 1984
"All rights reserved ."
TABLE OF CONTENTS
Introduction .............................•............................
The advantages of a disk drive .................................. .
Features of the 1541 . . . . . . . . . . . • . . • . • . • . . . . • . . . • . . • . • . • . • . . . • . . . 1
How to use this book . . • . . . . . . . . . . . . . • . . . • • . . . . • • • . . . • . . . . . . . . . . 2
Basic Operating Steps. . • . . . . • . . . . . . . . . . . . . . . . . . . • . • • . • . . • . • . . . . . 2
Specifications of the 1541 Disk Drive ..•...•...............•...•.. ., 4
PART ONE: GUIDE TO OPERATION
Chapter 1: Disk Drive ...•.....•..............................•...•...... s
Unpacking . . • . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Empty the drive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Connecting the cables ........................................... 6
Turning on the power . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Troubleshooting guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Simple maintenance tips ........................................ 11
Chapter 2: Diskettes .................................................... 12
What is a diskette? ............................................. 12
Safety rules for diskette care ..................................... 1J
Inserting a diskette ............................................. 13
Safety rules for removing diskettes ............................... 14
Loading a packaged program .................................... 14
How to prepare a new diskette ................................... 15
Reusing an old diskette ......................................... 16
Organizing a diskette library .................................... 17
Backups ...................................................... 17
Chapter 3: Directories .............•.................................... 18
~ha~ is a di.rectory? ...........................................
. 18
V1ew1ng a directory ............................................ 18
What a directory shows ......................................... 18
Watch out for splat files ......................................... 20
Printing a directory ............................................
Reading a directory as a file .....................................
Another way to be selective ...................................... 21
Pattern matching and wild cards ............•.................... 22
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 .....••..•..•..••....•..................•... 30
Erasing programs ..•...•......•.....•.••••••..•...•.•...•.•.•.• 31
Scratch for advanced users ...•........•.........•.•.......••.... 33
Renaming programs •.....•.•..•..•.••......•.....••.....•...... 34
Renaming and scratching troublesome programs ....••..•.•........ 36
Copying programs .•••••...•.••.................•..••••.••..... 37
Validating the diskette .....•••.•....•.....•..•.....•...••....... 38
Initializing ..••.........•........••......•...•.........•...••.. 40
Chapter 5: Sequential Data Files .......•....•....••...•.••...•.....•..... 42
The concept of files .............................................. 42
Opening a sequential file .....••••........•.......•••.........•.• 42
Adding to a sequential file •..••..•......•....•...••....••..••...• 45
Writing file data: Print# ...•.••.•..•..•..•..•...•..•.•..••..•... 46
Closing a file ••..•.•..••..••.....••..•.••..•..•...•....••...••. 48
Reading file data using INPUT# •..•....••..•.•....•...•.•..••... 49
More about INPUT (advanced) ..•......•...•..•......••.••...•.. 50
Numeric Data Storage on Diskette •.•••..•...••.•..••....••.....•. 51
Reading File Data: Using GET# .••.•..•.••......•.••..•.......... 52
Demonstration of Sequential Files ...•...•••••......•..••.•....••. 54
Chapter 6: Relative Data Files •.......••.•.....•............•.....•...... 55
The value of relative access .......•...........•••.....•...•...... 55
Files, Records, and Fields .•...•..........•....••..•....•..••...• 55
File limits •..•.........••....•.•........•..•........•....•..... 56
Creating a relative file ...•...........•..•..•..•...•....••.....•. 56
Using relative files: Record# •..•...•••..•..•..•.••....•....•..... 57
Completing relative file creation ••.....•...........•.....••....•.• 59
Expanding a relative file ••..........•...•••.•........•.•...•.... 60
Writing relative file data ...•.........•...•...••..•••..•...•..•.. 61
Designing a relative record •......••...•..•.••....•...•...•...•.. 61
Writing the record •....•...••......••.•...••.•............•.... 62
Reading a relative record ...........•..•.•....•.•......•..•...•• 63
The value of index files ....•........•..•..•..•...•............... 64
Chapter 7: Direct Access Commands •.•••••..•..•..•.••••.••..•..•..•....• 65
A tool for advanced users .•...•••••.....•......••.......•.•..•.. 65
Diskette organization ...•.•...•....•...........•.••••••.•...•... 65
Opening a data channel .•••••......•.•.•....•.......••••••.••..• 65
Block-Read ..•••...........•.••...•...•••••.••.•.•.•......•..• 66
Block-Write ......•••••••.......••.•••...•....••..•..•...••..•. 67
The original commands .•••......•.•••.•.•...........•....•.•••• 68
The buft'er pointer ......••.•••••..•..•..••.•.•.•......•..•..•.. 69
Allocating blocks ...•..•....•...•••.••.•...........••••••••••••• 70
Freeing blocks •..........•..•..•.•....................•..•.••.. 71
Using random files (advanced) •.....•...•..•........•••.•••..••.. 72
Chapter 8: Internal Disk Commands •••.........•.•••••••••..•..•......... 73
1541 Memory Map .••.......•...•...••.••........•...••.••••••. 73
Memory Read •......•......••..•••....•....................... 74
Memory Write •••.•.........•...........•...............•...•. 75
Memory Execute ......•.•...•...•.••.•......................... 77
Block Execute ..•...•..•...•.•••..•...........•...........•••.• 77
User commands .....•.......•.........•.•.............••...•... 78
Chapter 9: Machine Language Programs .................................. 80
Disk-related kemal subroutines .••••............•....•.....•.•.•. 80
Appendices
A. Changing the Device Number ....•.•.•....•................... 81
B. Error Messages ....••••••.................•••••.••••.•••••.. 83
C. Diskette Formats ......•.........••....•.................... 87
D. Disk Command Quick Reference Chart .•..•••••.••.•...•••.... 92
E. Test/Demo Diskette ••....••..•....•.••.....•••••.•......•.•. 93
List of Figures
1. Front Panel. . • . . • . . • . . • • • . . • . • . • . . • . . • . . • . . • . . • • . . . . • . . • • . • . 5
2. Back Panel • . • • • • . . • • • • • . • • • • • • • • . . • • • • • • • • • • . • • . • . . • . . • . . . . 6
3. Floppy Disk Hookup . . . • • • . . • . . • . . . . . . • . • . . • . . • • . • . • • • • . • • . • 8
4. Position for Diskette Insertion .••••••.•.••••.••..•.......••..•. 12
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 used before and to disk drives offered for other brands of computers .
THE ADVANTAGES OF A DISK DRIVE
• Speed
If you have used a cassette recorder for data storage, you probably know it can take up to an hour just to search one long cassette tape looking for a specific program . With the
1541 disk drive, a list of all the programs on a diskette appears on your screen in seconds. The speed of program loading is also greatly improved . It takes the 1541 only a minute to load a large program that would take a half-hour to load from tape .
• Reliability
Reliability is another reason for choosing a disk drive . It is all too common for a cassette user to accidentally erase a valuable program by saving a new program on top of the old one, without realizing it. The 1541 disk drive automatically verifies everything it records.
• Direct File Access
A third advantage of a disk drive is the ability to use relative files (discussed in Chapter
6). On a diskette, any part of a relative file can be accessed and altered separately, without affecting the rest of the file .
Overall, using a disk drive makes for easier and more powerful computing .
FEATURES OF THE 1541
The 1541 is one of the most affordable disk drives on the market. Compared to competitors, the 1541 has high capacity, and even higher intelligence. It is one of the most cost-effective disk drives available . Most home and personal computers that use a disk take at least I OK of RAM memory from the computer to hold a disk operating system
(known as a DOS .
) This large program must be in memory the whole time the disk is being used, and much of it must also be kept on every diskette .
The Commodore 1541 works differently and more effectively. It contains its own built-in microcomputer to control its various operations, along with enough ROM and
RAM memory to operate without any help from the computer. Commodore's DOS
"lives" entirely inside the disk drive , and does not require any internal memory in the computer to do its work, nor does it have to be loaded before use like DOS on other computers . It is so independent that once it begins working on a command, it will complete it while the computer goes on to some other task, effectively allowing you to do two things at once .
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 di k
first? (Packing is the process of moving all the leftover work areas to the end of th e diskette's storage space .
) All this is handled automatically on Commodore disk drive s . I.
Unpack, hook-up, and turn
~n the disk drive.
The 1541 disk drive always knows where the next program will go, and automatically fi ts There's no shortcut through this part. You'll have to read this section to find out it into the best available spot. what connects to what, when to turn everything on, and how to empty the drive.
Diskettes created on the 1541 may be read by several other Commodore di sk If you run into any problems at this point, refer to the Troubleshooting Guide. drives, including the former 1540, 2040, and 4040, and the 2031. It is usually poss i. ble, though not recommended, to write data to any one of these drives from any of the others.
. .
Gently insert a pre-programm.ed diskette.
for the purpose of demonstration, use the Test/Demo diskette that was included
The 1541 communicates with the computer and other devices over a cable an d with the disk dri~e. interface known as the Commodore serial bus. It is patterned after the IEEE-4 88 If you run mto any problems at this point, refer to Chapter 2, "Inserting a bus used on Commodore's PET and CBM models, except that the serial versio n Diskette." only uses one wire for data. The two serial ports on the 1541 allow several devi ces to be connected together at once, each plugged into the next in "daisy chain" fas h. 3. ion. Up to 4 disk drives and 2 printers can be connected this way.
Type: LOAD "HOW TO USE",8 (for Basic 2)
DLOAD "HOW TO USE"(for Basic 3.5)
Press: RETURN
HOW TO USE THIS BOOK
HOW TO USE is the name of a particular program on the Text/Demo diskette. To load a different BASIC program, substitute the name of that program inside the
This book is divided into two main parts. The first part gives you the information y ou quotation marks. . , . . need to use the 1541 effectively , even if you know little or nothing about programmin g . If you .
want to load a program that isn t written m BASIC language, you must
This part of the book tells you how to set up the system, how to prepare diskettes for u se , use the Basic 2
~ommand
and add the
f~llo"'.ing
after the 8 in that command : , 1 how to read a directory, and how to load programs . Part two of the book is for advanc ed ,I,f you .run mto any problems at this pomt, refer to Chapter 2, the section enti users and those who would like to become advanced users . This part provides mo re tied Loadmg a Packaged Program." advanced commands , tells about the different files the 1541 uses , and how to mana ge them, as well as giving a few hints for machine language programmers .
4·
. .
After you perform step 3, the following will appear on the screen:
Both beginning and advanced users will find valuable information in the appen di · ces--a quick reference list of disk commands , a list of disk error messages and what th e} mean, a glossary of words used in this manual, how to use two or more disk drives a 1
SEARCHING FOR HOW TO USE
LOADING
READY
once, and explanations of some programs on the Test/Demo diskette packed with yo m
1541.
Since owners of four different Commodore computers use the 1541 we ha ve At this point, type RUN and press the RETURN key and follow , ilie directions separa ted seve raI l
· · ·
, d d. . . ' rn · for the program
· puter uses. If you have a VIC 20 or Commodore 64 , please read the pages marked B asic
2 . Those with the Commodore 16 or the Plus/4 should read pages marked Basic 3 .
5 . F or many commands , there will be an added page or two of further comments and advanc e d techniques . Feel free to skip anything you don't understand on those pages now , and co me back later .
BASIC OPERA TING STEPS
If you're like most people, you're anxious to start using your new disk dr iv1 right away. In view of that , we have outlined the basic steps you need to know ir order to get started.
Once you've mastered the basic steps however, YO\! will need to refer to the rest o f this manual in order to make full use of the 1541 ' s features . In fact , before you begin , y oL should take a look at the following short sections , which offer precautions on handling the equipment: "Simple maintenance tips ," " Safety rules for diskette care ," and "Saf et ) rules for removing diskettes .
"
2
3
SPECIFICATIONS OF THE 1541 DISK DRIVE
STORAGE
Total formatted capacity
Maximum Sequential file size
Maximum Relative file size
Records per file
Files per diskette
Tracks per diskette
Sectors per track
Sectors per diskette
174848 bytes per diskette
168656 bytes per diskette
167132 bytes per diskette
65535
144
35
17-21
683 total
664 free for data
256 Bytes per sector
INTEGRATED CIRCUIT CHIPS USED
1 6502 microprocessor
Used for overall control
Versatile Interface Adapters 2 6522 VIA
Used for input and output, and as internal timers
6116 RAM
Used as 2K of buffers
Random Access Memory
16K ROM Read-Only Memory
Contains a 16K Disk Operating System (DOS)
INTERFACE USED
Commodore serial bus with two 6 pin DIN connectors
Device number selectable from 8 1 I
Secondary addresses 0 15
PHYSICAL DIMENSIONS
Height
Width
Depth
97mm
200mm
374 mm
ELECTRICAL REQUIREMENTS
Three wire-grounded detachable power cable .
Voltage U .
S . 100-120 VAC
Frequency
Export
U .
S .
220-240 VAC
60HZ
Export 50 HZ
Power used 25 Watts
MEDIA
Any good quality 5 1/ . inch diskette may be used (Commodore diskettes are rec or mended) .
UNPACKING
PART 1: GUIDE TO OPERATION
CHAPTER 1
DISK DRIVE
The first thing you will need to do with your disk drive is unpack it. Inside the carton in which you found this manual, there should also be : a 1541 disk drive, a gray power cord, a black cable to connect the disk drive to the computer, a demonstration diskette, and a warranty card to be filled out and returned to Commodore .
Please don't connect anything until you've read the next three pages! It could save you a lot of trouble . i.--~~~~~~~~~~~~~~~~~~~~~~..._,
DOOR LATCl;-I
DRIVE INDICATER (RED LED)
LIGHT : ACTIVE
FLASH : ERROR
POWER INDICATER
Fig
I.
Front Panel
(GREEN LED) LIGHT : POWER ON i.--~~~~~~~~~~~~~~~~~~~~~~ · -.J l
(E commodore
Fig. I.A
Door
Door
----~
~s~ _ J
\DRIVE INDICATER ( RED LED) LIGHT : ACTIVE
FLASH : ERROR
POWER INDICATER
(GREEN LED) LIGHT : POWER ON
5
4
EMPTY THE DRIVE
First , it is very important to be sure nothing is inside the disk drive . If you turn th e power off or on with a diskette in the drive, you could lose its contents and have to r e record 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 spac er inside . Following the instructions below , pull it out as though it were a diskette, but don ' t throw it away. You will want to put it back inside the slot any time you move or ship th e disk drive later.
To check whether a spin-door drive is empty (Fig 1 .
8), simply rotate the lever on th e front of the disk drive counter-clockwise until it stops , one-quarter turn at most. The n reach inside the long slot the lever covers when it points down, and pull out any diskett e you find there.
To check whether a pop door drive is empty (Fig I .A) , simply press lightly on th e door latch, as though it were a pushbutton . The door will pop open upwards, exposing th e long slot in which your diskettes will rest . Once the door is open, a small spring insid e will usually eject any diskette inside .
CONNECTING THE CABLES
marked "off' is pushed inward. Leave your whole system off until everything is connected. We will tell you when it is safe to turn it on .
After plugging the power cord into the disk drive and a suitable outlet, find the black cable that goes from the disk drive to the computer. It is called a serial bus cable to describe the way the computer, and other accessories communicate with each other through its wires. It has an identical 6-pin DlN connector at each end , which like the power connector can only go in one way-with the dimple in the side of the plug facing up.
To plug in the serial bus cable, find the dimple on the side of the metal part of the plug and tum that side up . Then push it straight into one of the two serial bus connectors on the back of the disk drive. The other end goes into the similar connector on the back of your computer, marked "serial bus." If another accessory, such as a printer , is already connected there, unplug the other device's cable from the computer, and attach it to the spare serial bus connector on the back of the 1541 . Then install the serial cable from the
1541 in the serial bus connector on the back of the computer (Fig 3 .
A.)
If you have more than one disk drive, each added disk drive's serial bus cable is plugged into the second serial bus connector on the back of the previous disk drive, like a daisy chain (Fig 3.8). However , don't connect the other(s) until you've learned how to change their device numbers, as no two disk drives can have the same device number.
We'll cover ways of changing disk device numbers in Appendix A . Until you are ready to read that section, you may find it easier to leave your extra drive(s) unconnected .
The power cable plugs into the back of the disk drive at one end, and into a ground ed
(3-prong) outlet at the other end . It will only go in one way . Before you plug it in though . make sure that your entire computer system is turned off . The disk drive ' s on/off switch i in the back, on the left side (when viewed from the back) . It is off when the porti on
Fig 2. Back Panel
POWER SWITCH SERIAL BUS
TURNING ON THE POWER
With everything hooked up , and the disk drive empty , it is time to turn on the power.
You can turn on the power to the disk and other devices on the serial bus (connected via serial cables) in any order you like . Just be sure to either turn on the power to the computer itself last, or to use a multiple outlet power box with a master switch to tum everything off and on at once. When everything is on, including the computer, the disk drive will go through a self check for a second or so , to be sure it is working correctly. After the drive is satisfied with its own health , it will flash the red light below the drive door once, and the green power-on light to the left of the drive door will glow continuously . At the same time, the computer will be going through a similar self test, and displaying its hello message on your TV or video monitor. Once the red light on the disk drive has flashed and gone out, it is safe to begin working with the drive . If the light doesn't go out, but continues to flash, you may have a problem . Refer to the troubleshooting guide for help .
6 7
Commodore
Penon.al Computer
Single
Fig 3.A Floppy Disc Hookup
Commodore
Penonal Computer
Twin
Fig 3.b Floppy Disc Hookup
8
TROUBLESHOOTING GUIDE
s;;;.Olll
Q;;;; indicator light on the 1541 not on
Cause
Di s k drive not turned on
Power cable not plugged in
Power off to wall outlet
Bad fu di s s e in k drive
Remedy
Make s ure power s witch i s in the " on " position
Check both ends of power cable to be s ure they are fully inserted
Replace fuse or reset circuit breaker in hou s e
Replace fuse (located on back panel , as shown in Figure 2) with one of same size and rating
(If any fuse fails twice, added help is needed . If the house fuse failed , you may need an electrician . If the drive fuse failed , call your dealer.)
Red error light on drive flashes continously on power-up, before any disk commands have been given
The disk drive i failing its power self test s
on
Tum the system off for a minute and try again .
If it repeats , try again with the serial bus discoMected . If it still repeats , call your dealer . If unplugging the serial cable made a difference , check the cable for proper connection at both ends .
This can also be caused by some cartridges on the C 64 and always by a 16K cartridge on the
VIC 20 . Remove the cartridge and power-up the disk drive again to determine where the problem is.
(The principle behind unplugging the serial cable is " divide and conquer.
" The drive can do its power-on test even when not connected to a computer. If it succeeds that way , then the problem is probably in the cable or the rest of the system , not the 1541.
)
9
TROUBLESHOOTING GUIDE sJMPLE MAINTENANCE TIPS
Symptom Cause Remedy Your 1541 should serve you w e ll for year s to c ome , but there are a few thing s you
Progran'\s won't load , and computer says " DEVICE
NOT PRESENT ERROR .
' '
Serial bus c able not well connected, or di s k not turned on .
Be sure serial bus cable is correctly inserted and disk drive is turned on c an do to avoid costly maintenance.
I
. Keep the drive well-ventilated . Like a refrigerator , it need s a few inche s of air c ir;.:tlation on all sides to work proper! y . If heat can ' t be avoided any other way , you may
Program s won't load , but computer and disk drive give no error message .
Anolher device on the serial bu s interfering may be
.
Unplug all other devices on the serial bus . If that cures it , plug them in one at a time . The one just added when the trouble repeats is most likely the problem . c s ool lots the drive
. by placing a small filtered fan on the drive
(An inexpen s ive air fre s hener is quite suitable for this will result in more dirt getting in the drive . s o it
.
s air blow
) However , s into the cooling the added air flow z.
Use only good quality diskette s. Badly-made diskette s could cau s e increased wear on the drive's read/write head . If a particular diskette i s unusually noisy in u s e , it is probably
Also , trying to load a machine language program into BASIC space will cause this problem . c ausing added wear , and should be replaced.
3 . Avoid using programs that " thump " the drive as they load . Many commercial programs, and diskettes that are failing , cause the di s k drive to make a bumping or chattering noise as it attempts to read a bad sector. If the diskette can be copied to a fresh diskette, do so immediately . If it i s protected by its maker against copying , the thumping
(Such devices may not be turned on properly , or may have conflicting device numbers . Only one is intentional and will have to be endured . Be aware , however , that excessive ihumping ,
_de_v_ic_e_o_n_th e_b_u_s_can i .) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ especially when the drive is hot , caused some older 1541 's to go out of alignment and led
Programs won't load and disk error light flashes .
A disk error has oc c urred .
Check the disk error channel to
see
why the error occurred . Follow the advice in Appendix B to correct it . to costly repairs . Current 1541 'shave been redesigned to prevent the problem .
Note:
the "Memory Write" example in Chapter
8
temporarily turns off the bumps .
4. It would be a good idea to have your 1541 checked over about once a year in normal use. Several items are likely to need attention : the felt load pad on the read/write head may be dirty enough to need replacement, the head itself may need a bit of cleaning (with 91 %
(Be sure to spell program names exactly right , as the disk drive is very particular , even about spa ces and punctuation marks, and will not load a program unles s you call it exactly the same thing it w a s isopropyl alcohol on a cotton swab), the rails along which the head moves may need called when it was saved on the diskette .
) lubrication (with a special Molybdenum lubricant, NOT oil), and the write protect sensor may need to be dusted to be sure its optical sensor has a clear view . Since most of these
Your own programs Load fine, but commercial programs and those from other 1541 owners fail to load .
Either the diskette you are loading is faulty ,
( some mass-produced diskette s are) or your disk drive is misaligned .
Try another copy of the troublesome programs . If several programs from several sources always fail to load , have your dealer align your chores require special materials or parts
Commodore service center the of
1541 the maintenance
1541 will void
. If your warranty .
, it is best you wish to do the to leave the work to an authorized work yourself, ask your dealer to order guide for you (part number 990445), but be aware that home repair disk drive .
Your own programs tha! used to Load won't any more, but programs saved on newly-formatted diskettes still work .
Older diskettes have been damaged.
The disk drive has gone out of alignment.
See the section on safety rules for diskette care .
Recopy from backups .
Have your dealer align your disk drive .
The disk drive powers up with the activity light blinking .
Hardware failure (RAM ,
ROM , PCB) .
Have your dealer send it out for repair .
10 11
sAfETY RULES FOR DISKETTE CARE
CHAYl'ER2
WHAT IS A DISKETTE?
DISKETIES
I.
Keep the disk drive and its diskettes a~ay from all moi s ture ,' dust , s moke , food. and
:! temperatures either too hot or loo cold for you _ w _ or~ s ) . Also keep them away in for _ d periods .
When not in the drive , di s kette s s hould be stored upright in s ide their paper Jacket s . Do
Before we actually begin using the drive, let's take a moment to look. at t.ht 2 . not allow them to become bent or folded . Since the working part of the di s kette. i s o n
Test/Demo diskette packed with the disk drive . T<;> do this , grasp it by ~ hic t the bottom, never set it down on a table top _ or other place where dust or mo1 s _ should be sticking out of the paper jacket. Then pull it out of the jacket which keeps 1~ ~ might affect it , and be especially careful to keep your finger s away from the opening ~ of dust and other contaminants . (Save the jacket ; the diskette should always be ke~t m 1 ~ in the diskette cover . jacket except when actually in use in the disk drive .
) It is often called a floppy disk ette
Although some people sell kit s intended lo " double your di s kette's capacity _ " by because it is flexible even though it is not safe to bend diskettes .
A diskette is m~ch like a cassette tape , but in the form of a circle and enclosed with i 1
3 . tting an extra write protect notch into a diskette, it i s be s t not to u s e the other s ide of
~e diskette on the 1541 drive , even if your diskette is labeled '' double -s ided .' '' Doing a protective square plastic cover. As on ~ cassette tape, only a small exposed _ n o the magnetic recording surface is sensitive. You may touch the rest of the diskette an i
50 will cause added wear to your diskette s and drive, and may cost you an important time you like, but avoid touching the few small portion _ no~ covered by ~ protective cover . Also, never try to remove this cover. Unlike the paper Jacket , the pl astt 1
4 diskette cover is intended to remain on permanently .
5
_ program some day. .
When buying diskettes, you may use any good quality
. .
5
1/
.
mch diskette .
_
Make sure the diskette cenler hole i s more or less centered in it s opening before inserting the diskette into the drive . Although the hub assembly will correctly center
Next, notice the notch on one side of the diskette (it may be covered by a piec e o most any diskette, it would be very difficult to rescue data from a diskette recorded tape) . This notch is called the write protect notch. When it is covered with the opaq _ tap with its hub off-center . One way to help center diskettes is to " tickle " the drive door packed with blank diskettes, the disk drive cannot change the contents of that disk ette shut instead of slamming it down. By gently closing it part way , and then opening a bit
Never remove the tape on the Test/Demo diskette . and then closing the rest of the way, you give the spindle more chances to center the
The label on the top of the diskette says "1541 Test/Demo " on it, and tells YO! diskette properly . Another way to ease diskette centering is to buy diskettes that come which diskette you are using. Blank diskettes come with extra labels in addition to
011< with reinforced hubs. These hard plastic rings around the hub opening make the applied by the maker of the diskette . Use them to describe your own diskettes. diskette hub more rigid , and easier to center properly.
At least two other parts of the diskette are worth mentioning : The h~b and the ac c~s slot . The hole in the center is called the hub . A cone-shaped spindle fills it when the dri '1 door is closed, and its edges are clamped. This' keeps them from slipping, when th
INSERTING A DISKETTE
diskette spins at 300 RPM in use. . Spin Door
Drives
The oval opening in the diskette opposite the label is called the
access
_
sl~t.
It
expo
~
To insert a diskette in a spin door 1541 (Fig l .
B), first open the drive door by rotating just enough of the diskette ' s surface for the read/write head and _
~ad msi~e
the dri .., the door lever counter-clockwise one quarter tum until it stops to touch a one inch long line from the center to the edge of the diskette s working su~ ac c the slot in the front of the drive.
, with the lever level with
The bottom side of that slot is where all the information is written as the diskette spm s .
1
Grasp the diskette by the side opposite the large oval access slot, and hold it with the is one place your fingers should never touch . label up and the write protect notch to the left. Now insert the diskette by pushing it
. . . . - - - - - - - - - - - - - - - - - = - = - - - - - - - - - - - - s traight into the slot, the access slot going in first and the label last. Be sure the diskette
ACCESS SLOT goes in until it stops naturally, with no part showing outside the drive , but you shouldn ' t have to force or bend it to get it there .
z
(/) m
:D
-t
With the diskette in position , seat it properly for use by twisting the door lever clockwise one-quarter tum , vertically over the slot until it stops . If it does not move easily, stop! You may have put the diskette in the wrong way, or incompletely . If that
WRITE
PROTECT
NOTCH
z
-t
0
0
:D
< m happens, reposition the diskette until the door lever closes easily .
Pop
Doo~
Drives
. To insert a diskette in a pop door 1541 (Fig I.a) , first open the drive door by pressing in and slightly up on the door latch . A spring inside will then pop the latch up into the
WHEN COVE RE D . DISKETTE ~~~~~~'65
CANNOT BE LABEL open position, exposing a long slot for the diskette in the front of the drive .
Grasp the diskette by the side opposite the large oval access s lot , and hold it with the
L - - - - - - - - - - - - - - - - - - - - - - - - - - - !abet up and the write-protect notch to the left.
Fig.4. Position for I>Mkette Insertion
13
12
. Now insert the diskette by pushin~ it straight ~nto ~e ~lot , with the access slot g oiQ (..aSI is the relocate flag . It can have one of two values , O and I . If the relocate flag i s m first and the label last. Be sure the diskette goes m unttl 11 stops naturally and no lo ng
1 springs back out if you release it. No part of the diskette should be showing outside th O or drive when the diskette is fully inserted
· 1
.
, k h but you shouldn't have to force or bend it to
· h f 11
· ·
d th · 1 · get
0 mitted, all Commodore computers that use the 1541 automatically relocate the s they toad to live in the part of computer memory reserved for BASIC programs .
pro~ocate
· If the re flag value is I , auto-relocation is turned off, and the program is loaded into there. You may nouce a sm all c 1c w en 11 reac es u msert1on an e eJec ton sp nn the exact part of memory from which it wa s originally s aved . Thi s feature allow s catches : . . . . . . . machine-language and other special purpose programs to come into the computer
W1~ ~e ~1ske~e m
~s~tlon , sea~
11 for use by pres~mg straight down on the dO( at the correct location for them to operate properly. At this point in your learning, latch unttl 11 chcks mto pos11ton, and its handle moves shghtly toward you . If the l ate does not move easily, stop! incompletely . If that .
happe~s
,
Y
re~sition
h
_ h d . k · h
. y,
1
Noi
1
•
1
Jy thing you need to know about the relocate flag is how to use it. Simply de the
~~~rly
1 at the end of the LOAD command if a particular program doesn't run when loaded the usual way. . . you are ready to begm workmg with the diskette . p After you type in the command and press the RETURN key , the following will appear on the screen :
SAFETY RULES FOR REMOVING DISKETTES
SEARCHING FOR " HOW TO USE "
LOADING Always remove diskettes before turning a drive off or on . If a diskette were in p lac and the door closed at power on or off , you could lose part or all of the data on thi diskette .
Similarly , do not remove a diskette from its drive when the red drive activity li ght on! That light only glows when the drive is actually in use . Removing the diskette w ith on may result in your losing information currently being written to the diskette .
LOADING A PACKAGED PROGRAM
READY .
•
When the word READY and the flashing cursor reappear on the screen and the red light goes off on the drive , the program named "HOW TO USE " on the Test/Demo diskette has been loaded into the computer. To use it, just type the word RUN and pres s the RETURN key .
To use prepackaged BASIC programs available on diskette here is the procedu re : The same Load command will also allow you to load other prepackaged programs
After turning on your computer system carefully insert the, preprogrammed di sket from the Test/Demo or other diskettes . Merely substitute the exact program name that you
disk=tt~
included with
~e
disk
driv~
.
pu~se
of demonstration use the Test/ Den want to use between the quotation marks in the above example , and that will be the
The following commands will.load a program fro program the computer will load (a list of Test/Demo programs is shown in Chapter 3 , in the diskette into the computer : the section entitled " What a Directory Shows " ) . . . .
Note: here and in the remainder of the book , we will assume you are m graphic
BASIC 2 :
LOAD '' program name'' , device number ,relocate flag
Exll.P1ple: LOAD "HOW TO USE" , 8 mode, seeing upper case letters and graphic characters when you type. This is the normal condition of all Commodore computers covered by this manual when they are first turned on . If you now see lower case letters when you type without using the SHIFf key , you are in text mode instead . Press the COMMODORE key ( (lr ), at the lower left comer of your keyboard, together with a SHIFf key to switch to graphic mode .
BASIC 3 .
5 :
HOW TO PREPARE A NEW DISKETTE: BASIC 2
DLOAD "program name " ,Ddrive #,Udevice number,relocate flag
A diskette needs a pattern of magnetic grooves in order for the drive 's read/write head to find things on it. This pattern is not on your diskettes when you buy them , but adding it to a diskette is simple once you know to do it. Here is the procedure : Example : DLOAD " HOW TO USE "
After each command press the RETURN key
In both cases the exact name of the program wanted is placed between quo tatir
FORMAT FOR THE DISK NEW COMMAND marks . Drive #is optional.
Next is the device number of your disk drive which, unless you change it, is alw ays on the 1541 . If you have more than one drive however, you will need to change the d evi l
OPEN 15,device # , 15 , "Ndrive # : diskette name , id "
CLOSEJ5 number on any additional drive (see Appendix A for instructions on setting a dri ve device number ).
This Open command will be described more fully in Chapters 4 and 5 . For now , just c opy it as is, replacing only the parts given in lower case . The s e include : the devi c e
14
15
number of the.1541, normally 8; the drive number, always 0 on the 1541; any desi ~ your fonnat command . By leaving off the ID number, the format command will fini s h in a name for the diskette, up to 16 characters in length, followed by a 2 character diskette I n number. The Close command is often optional; just don't Open that same file ag ai
1 few seconds instead of the usual 90 seconds . without Closing it the first time . .
ORGANIZING A DISKETTE LIBRARY
EXAMPLE:
Though you may not believe it now , you will eventually have dozens, if not hundreds
OPEN 15,8,15,"NO:MY FIRST DISK,Ol" : CLOSE 15 of diskettes . You can ease life then by planning now . Assign each diskette a unique ID number when you format it. There are diskette cataloging programs you can buy, that
Note : the chattering or thumping noise you hear just after the disk New comm Clll! store and alphabetize a list of all your file names , but are of limited value unless your begin .
s is entirely no~al. The disk must be sure it is at track 1, which it assure s b ) stepping outward 45 times (on a 35 track diskette .
) The noise you hear is the h ea1 diskette ID numbers are unique .
At least two valid approaches are used in assigning ID numbers . One starts at 00 with assembly hitting the track I bumper after its inevitable anival . the first diskette, and continues upward with each new diskette, through 99, and then onward from AA through ZZ . Another organizes diskettes within small categories, and
HOW TO PREPARE A NEW DISKETTE: BASIC 3.5 starts the ID number for each diskette in that category with the same first character, going from Oto 9 and A to Z with the second character as before . Thus, all "Tax " di s keues
A diskette needs a pattern of magnetic grooves in order for the drive's read/wri ~ could have ID numbers that begin with "T." Either approach works well when followed head to find things on it. This pattern is not on your diskettes when you buy them , b u diligently. adding it to a diskette is simple once you know to do it. Here is the procedure :
While on this subject , may we suggest you choose names for diskettes on the same basis , so they too will be unique , and descriptive of the files on them .
FORMAT FOR THE HEADER COMMAND
BACKUPS
HEADER "diskette name" ,lid,Ddrive #,Udevice #
($),not the contents of the variable A$. If you need a variable ID number, use the Bas ic :
When to do a Backup
Where "diskette name" is any desired name for the diskette, up to 16 characters i r length; omitted
"id"
(as is a 2 character diskette it must be on the 1541); and to be 8 if omitted .
ID number;
"device#"
"drive #" is the drive number, 0 is the disk's device number, assum
As described in the next page, "id" is optional if (and only iO diskette has been previously formatted on a 1541 . Also, the ID must be a string literal , u el tlK no
Although the 1541 is far more reliable than a cassette drive under most circum stances, its diskettes are still relatively fragile, and have a useful life of only a few years in steady use . Therefore , it is important to make regular backups of important programs and files. Make a backup whenever you wouldn't want to redo your current work . Just as you should save your work every half hour or so when writing a new program, so you should a variable or expression, and may not include Basic reserved words . Thus, ",IFI" cann a also back up the diskette you 're using at least daily while you are changing it frequently . be used because If is a Basic keyword, and ",l(A$)" is not allowed because A$ is
1
In a business, you would make an archival backup every time important information was variable . " , IA$" is allowed, but the ID number will be the letter "A" plus a dollar sig r due to be era ed , such as when a new accounting period begin s .
How to do a Backup form of the format command .
We have included programs on the Te t / Demo diskette that can be used for similar purposes . These programs are described further in Appendix E .
EXAMPLE :
HEADER "MY FIRST DISK,lOl,DO"
How to Rotate Backups
Once you begin to accumulate backups , you'll want to recycle older one s . One good
Note : the chattering or thumping noise you hear just after the Header comm ~ method is to date each backup . Then retain all backups until the current project is fini s hed .
When you are sure the last backup is correct , make another backup of it to file. and move begins is entirely normal. The disk must be sure it is at track 1, which it assures b ) all older backups to a box of diskette s that may be reused . stepping outward 45 times (on a 35 track diskette). The noise you hear is the h ea c assembly hitting the track 1 bumper after its inevitable.anival
. a eh
One other popular approach, s uited to project s that never e nd, i s to rotate backup s in am, wherein there are s on backups , father backups . and grandfather backups . Then . when another backup is needed , the grandfather
di~kette
is reu s ed, the father become s the
REUSING AN OLD DISKETTE grandfather, and the son becomes the father. ·
After you have once formatted a particular diskette, you can re-format it as thopgh
1 were brand new at any time , using the above procedures. However, you can also chan 8 ' its name and erase its programs more quickly and easily by omitting the
•
ID numbe r i t
16 h Whichever approach i s used , it i s recommended that the newly made backup be c ome
~t
diskette that is immediately u s ed , and the di s kette that i kn o wn to be good s h o uld be th ed away as the backup . That way , if the backup fail s, you 'II know it immediatel y, rather an after all the other backup s have failed s ome dark day .
17
CHAPTER3
DIRECTORIES
WHAT IS A DIRECTORY?
On e o f the primary advantage s of a disk drive i s that it can , with nearly equa l ea ~ and s peed , ac c es s any part of a di s kette 's surface , and jump quickly from one s pot ~ ano~he~ . A DATASSE~E ™, on the other hand , u s ually reads a cassette file fro m t~ begmnmg _ to the _ , without skipping around . To see what 's on a cassette , it i s nece ssari to look at it s entire length , which could take a s long a s an hour . On a disk drive , by w ay
0 contrast, it is a quick and simple matter to view a li s t of the programs and data file s on . diskette. Thi s list is called the directory . '
VIEWING THE DIRECTORY: BASIC 2
To view the directory in Basic 2 , it is usually necessary to load it , like a program . Ai when you load other program s, thi s era s e s anything l!lready in Basic memory , so be sun to save any work you don ' t want to lose before loading the directory in Basic 2. (Chap ter< de s cribe s how to Save a program .)
For e x ample , to load the entire dire c tory from disk device 8 , type :
LOAD " $ " , 8
Then , to display the directory on your screen after it load s into computer mem ory type LIST . You may slow the listing by pressing the CONTROL key on the VIC 20 anc
Commodore 64 , and halt it entirely by pressing the STOP key .
You can also use this command to limit the directory to desired files by using patt em matching characters described later in this chapter.
VIEWING THE DIRECTORY: BASIC 3.5
•HOW TO USE•
12
12
4
•HOW PfllRT 2•
•HOW PART 3•
•v1c-2e WEDGE·
• C -6"4 WEDGE •
4
•oos !5. 1 •
•PRINTER TEST•
9
4
•DISK ADDR CHANGE•
6
•VIEW BAM•
4
•CHECK DISK•
14
•olSPLAV. T&s·
9
•PERFORMAl'CE TEST•
!5
•SEO.FILE.DEMO•
7
•so.BACKUP.CIS·
7
•so.BACKUP.PLUS4·
UI
•so.BACKUP.C64•
7
•PRINT.64.UTIL•
7
7
•PRINT.Cl6.UTIL•
•PRINT.+4.UTIL•
311
7
•cs4 BASIC DEMO·
3!5 •+"4 BASIC OEMIP
8
·LOAD ADDREss•
•UNSCRATCH•
!5
•HEADER CHAI-GE•
1e •REL.FILE.DEMO•
426
BLOCKS FREE.
PRG
PRG
PRG
PRG
PRG
PRG
PRG
PRG
PRG f>'RG
PRG
PRG
PRG
PRG
PRG
PRG
PRG
IMPORTANT NOTE:
PRG Your Test/Demo
dis
kette
PRG may contain additional
PRG programs. Commodore
PRG may update the diskette
PRG from time to time.
PRG
PRG
PRG
To view the directory in Basic 3 .
5 , simply type the word DIRECTORY on a bl anl line, and press the RETURN key . Unlike Basic 2's method of loading a directory , thi s does not erase anything already in Basic memory, s o you can safely ask for a directo ry a1 Starting with the top line, here is what it tells us : almost any time , even from within another program .
Again , you may slow a directory listing on the Commodore 16 and Plus/4 by hold ing .
~
. If we had gotten down the COMMODORE key ((II) , or halt it entirely by pressing the STOP key. y
0 u this dlJ'CCtory from a dual disk drive, it might have said " I" instead . may also pause it with CONTROL S (by holding down the CONTROL key while pre ssing
~ the " S " key), and resume by pressing any other key. diskette, enclosed in quotation marks , and printed in reverse field . Just as each program
h'.18
a name, so does the diskette itself, assigned when the diskette was formatted . The diskette name may be up to 16 characters long, and serves mainly to help you organize
WHAT A DIRECTORY SHOWS your diskette library. By keeping related files together on the same diskette, you ' ll ease task of finding the program you want later , when you have dozens or hundreds of
Now let's look at a typical directory on your 1541 Test/Demo Diskette. diskettes. The two character code to the right of the name is the diskette ID , also created
When the diskette was formatted, and equally useful for individualizing diskettes .
C The 2A at the right end of the top line tells us that the 1541 uses version 2 of
0 11Unodore's DOS (disk operating system) , and that it , like most Commodore drive s,
uses
fonnat "A. "
19
18
The rest of the directory contains one line per program or file, each line supply" three pieces of information about its subject. 'Q I RINTING A DIRECTORY
At the left end of each line is the size of that line's file in blocks (or sectors) of 2Si p characters . Four blocks are equivalent to IK (1024 characters) of RAM (read/w .
·
.
' d h
compu~er.
ntc
To make a permanent copy of a directory , perhaps to fasten to the di kette's outer
(paper) envelope. you w1 · 11 ne~ d to send t e directory to a printer. such as Commodore's
The middle of each directory line contains the name of the file, enclosed in quota ti MPS SOI, 1520 and 1 .
526 se rial bus model . To do this , you may need to refer to your marks . All characters between the quote marks are part of the name, and must be ind uct°' rinter manual, but briefly the procedure for listing a directory to device 4 is as follows : when loading or opening that file . et p
The right portion of each directory line is a three character abbreviation for the fil
~ype of .that entry.' As we will see in later chapters, there
are
many ways to sto~ mformauon on a diskette, most of which are associated with a distinctive file type.
LOAD"$0",8
OPEN 4,4 : CMD 4:LIST
PRINT#4:CLOSE 4
TYPES OF FILES AV Al LAB LE
Currently used file types include :
PRG = Program files
Also note that all of the statements that can be combined on one line already have been. Type them in immediate mode to avoid disturbing the directory .
All other options , such as differing device numbers , and elective directories (see next section) can also be s pecified a~ usual in the Load command .
SEQ = Sequential data files
REL = Relative data files
USR = User (nearly identical to sequential)
DEL
=
Deleted (you may never see one of these .
)
(Not~: Direct Access files , also called Random files, do not automatically appear in the directory . They are discussed in Chapter 7 .
)
WARNING: Be sure to include the PRINT# command after every printer listing . Otherwise, the printer will remain as an unwanted listener on the serial bus, and may disrupt other work . Also, do not abbreviate PRINT# as ?#. Although it will look proper when listed out, it will cause a SYNTAX ERROR in use . The proper abbreviation for PRINT# is pR .
".1-fter all the directory entries have listed, the directory finishes with a me ssagi showing how many blocks of the diskette
are
still available for use . This number can van
~-
-----------------------------_J
from 664 on a new diskette to 0 on one that is already completely full. .
READING A DIRECTORY AS A FILE
WATCH OUT FOR SPLAT FILES!
One indicator you may occasionally notice on a directory line, after you begin savi nj programs and files, is an asterisk appearing just before the file type of a file that is I
3
I~
you w .o
uld like to read a directory from within a program, you may do so. In Basic
.
s. simply include the DIRECTORY command in your Basic program . In Basic 2 , blocks long . This indicates the file was not properly closed after it was created, and tha ll however, and optionally in the others, you will have to Open the directory as though it should not be relied upon . These "splat" files (as they are called in England) wi l were a data file and read it character by character . See the discussion of Get# in Chapter 5 normally need to be erased from the diskette and rewritten. However, do not u e t ll for more information .
Scratch command to get rid of them . They can only be safely erased by the Validate all'
Collect commands . One of these should normally be used whenever a splat file is not icei ANOTHER WAY TO BE SELECTIVE on a diskette . (All these commands are described in the next chapter .
)
There are two exceptions to the above warning: one is that Validate and Coll eC cannot be used on some diskettes that include direct access (random) files, and the oth en
. .
Before d1scu sing the pattern-matching options available for use in seve ral disk
c~mmands,
let's cover one more that is only usable in a directory . Several different type s that if the information in the splat file was crucial and can't be replaced there is a wa y
1 1 rescue whatever part of the file was properly written . (This option is also described in
1
11 . n • we can create a directory from the files of a single selected type . Thu s, we next chapter) .
'
°
files can
~mmad coexist peacefully on
· the same diskette . By
. altering our directory load
~~~ht
request a list of all se quential data files (see Chapter 5), one of all the relative data
(see Chapter 6) , or one of only program files . To do this , imply add to the end of
Your sele c t' d' .
=) followed by the first letter of the file
Ype you want in your directory . For example , the Basic 2 command:
20
21
LOAD"$0:* = S " ,8 will load a directory of all sequential files, while the Basic 3.5 command :
DIRECTORY, "A* =R" will display a direct~ consisting only of relative files beginning with the letter ''A '•. fORMAT FOR PATIERN MATCHING :
.
*"
EXAMPLES:
"C-64*" or
·•expression?expression
''
"C?64 WEDGE"
The possible file types , and their abbreviations for this use are:
P = Program
S = Sequential
R =Relative
U =User
D = Deleted
A= Append
M =Modify or
• 'expression?expression*''
"C-64?WED*"
Use any of the above patterns in any of the disk commands whose format includes . a attem. This applies to Load, Dload, Directory , Open, Scratch , and to the source file m
~e
Copy and Rename commands. More than one"?
" can appear in the same pattern ..
As you might expect , their use in pattern matching means you can't use the asterisk or question mark in a file name when saving or writing a file (see next chapter.)
PATTERN MATCHING AND WILD CARDS
Just as cassette users can load programs without giving a full name, disk user s c i use special pattern matching characters to load a program from a partial name . The sa n characters can also be used to provide selective directories. The two special char act r used in pattern matching are the asterisk (*) and the question mark (?). The y a something like a wild card in a game of cards. The difference between the two is th at tl asterisk makes all characters in and beyond its position wild, while the question mark on makes its own character position wild. Here are some examples , and their results :
LOAD " A* ", 8 loads the first file on disk that begins with an "A", regardl e s s 1 what follows . "ARTIST", "ARTERY", and "AZURE" would all qualify , b
"BARRY" wouldn't, even though it has an "A" elsewhere in its name .
DLOAD "SMITH" (Basic 3 .
5) loads the first program that starts with "SM" , em with "TH", and has one other character between. This would load " SMITH " 1
"SMYTH", but not "SMYTHE".
OPEN 8,8 ,2,'' R?C* , S,R" We'll study Open in Chapter 5, but the pattern used h e means that the selected file will begin with an "R" and have a "C" in the third char ac1 1 of its name.
DIRECTORY,"Q*" (Basic 3.5) will load a directory of files whose names beg • with "Q".
LOAD"*" ,8 and DLOAD "*"are special cases. When an asterisk is used alon e ' a name, it matches the last file used . If none have been used yet on the current di ske V since turning on the drive, using the asterisk alone loads the first program on the disk et1
1
10 INPUT A$ : LOAD A$ + " * ", 8 loads any file whose name starts with 1 b characters entered in A$ .
22
23
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
Chapte r 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 seco ndary address of 15 . The usual form of this stateme11t is :
OPEN 15,8 , 15
The first 15 is a file number, and could be any number from 1 to 255 . It is used to match the secondary address (the last number on the line) , which is also 15 . The middle number is the primary address, better known as the device number, and is normally 8 when talking with the 1541. A second disk drive would usually be 9, a third, 10 and so on .
Once the command channel has been opened, use the Basic Print# command to send infonnation to the disk drive , and Basic's Input# command to receive information back from the disk drive . These two commands are like Basic's Print and Input statements, exce pt that they use the device number specified in the preceding Open statement instead of defaulting to the screen and keyboard respectively .
In Basic 2, you'll use both Print#l5 ahd Input#l5 extensively, to send hou sekeeping commands to the disk and to check its error status. Basic 3 .
5 has built-in commands for most of these chores. Even so, it will be good for those of yo\! with Basic 3 .
5 to see how such commands are sent.
Sending a Command via the Command Channel
Here is the way we send the Initialize command to the disk via the command chan nel.
PRINT# 15, "IO"
This command assumes we have already opened the file 15 to the command ch annel. "10" can be replaced with any string expression that is a valid disk comn_iand. If file 15 isn't already open, we can combine the Open and the Print# in a sm gle statement:
OPEN 15,8, 15, "IO"
However , this only works for the first disk command given . After that , file 15 is alre ady open, and Opening it again would cause a " FILE OPEN" error . Added comrnands are sent via Print# instead .
25
FORMAT FOR SENDING DISK COMMANDS
OPEN 15,device #,15,commandS or
Print# 15,command$
Examples :
OPEN 15,8,15,"VO" or
PRINT#l5, "VO"
OS$
..... reviate it to or a.,.,
?DSS ither in immediate mode or within a program, an~ the c~rrent error status mess~ge of the e. k will be displayed on the screen. A message will be displayed whether there 1s an error dis ot but if there was an error, printing its message will also clear it from the disk or
~o~ and tum off the error light on the disk drive. rne Once the message is on the screen, you can look it up in Appendix B to see what it
11 eans, and what to do about it.
gRROR CHECK SUBROUTINE
where
. the dis k
· dr '
.
1ve .
#"
Th
·
1s
· h d
If
· d
·
'
"
·
1s m 1ca t k'
1t 1s no e d d b ev1ce num a so a v y a al"d ftashi ' ber normally 8 and ng disk command error
. .
"command$" is it will result in
, an
. an error em
. x: h are
Since those of the error of you who are writing disk command , you may want to channel. Here 1 s programs include one we use .
. . a small subroutine in each program to take message such as "3 1,SYNTAX ERROR" when the error channel is read as descnbe d o
Jasic the next two pages .
.
2
vemon: Basic 3.5 version: i9980 REM READ ERROR CHANNEL
READING THE ERROR CHANNEL: BASIC 2
i 9990 INPUT#l5, EN,EM$,ET,ES
In Basic 2, there is no simple way to learn what is causing the error light to flas h ex
0000
IF EN> 1 THEN PRINT
EN,EM$,ET ,ES:STOP the disk drive without writing a small program. This, in tum, causes you to lose an 1 RETURN program variables already in memory. The reason for this is that the INPUT# comm a!I'
59990 REM READ ERROR CHANNEL
60000 IF OS> 1 THEN PRINT DS$:STOP
60010 RETURN cannot easily be used in immediate mode (that is, without a line number) . . 'he Basic 2 version assumes file 15 has already been opened earlier in the program, and
You will often need to be able to read the disk error channel, to see why the disk emi,a t it will be closed somewhere else at the end of the program. light is Hashing, and thereby tum the error light off again .
Here is a brief program to check for disk errors:
1
This subroutine reads the error cha nnel and puts the result s into the named variables. the Basic 2 version , they are EN, EM$, ET, and ES, which stand for Error Number,
10 OPEN 15,8,15
20 INPUT#l5,EN,EM$,ET,ES
30 PRINT EN,EM$,ET,ES
.rror Message, Error Track and Error Sector respectively. Of the four, only EM$ ha s to r. a string, and you could choose other variable names, although these have become adi tional for this use .
40 CLOSE 15
The Basic 3 .
5 version subrouti ne u ses the reserved variables OS and OS$ already set
;ide for this purpose . They are updated automatically by Basic whenever they are used.
. tb herwise, the two versions of the subroutine are equivalent.
This little program reads the error channel into 4 Basic variables, and pnn ts results on the screen. A message will be displayed whether there is an error or not, but
Two error numbers are harmless : O means everything is OK, and 1 tells how many l~s were erased by a Scratch command. If the error status is anything else, line 60000 there was an error, this program will also clear it from disk memory and tum off the errtlints the error message and halts the program . After you have repaired the damage, you light on the disk drive. · . . . , ay then continue the program with Basic's Cont command.
Once the message is on the screen, you can look it up m Appendix B to see what Because this is a subroutine, you access it with the Basic Gosub command, either in means, and what to do about it.
READING THE ERROR CHANNEL: BASIC 3.5
lrnediate mode or from a program. (For example, "200 GOSUB 59990" .) The Return uernent in line 60010 will jump back to immediate mode or the next statement in your ograrn, Whichever is appropriate.
In Basic 3. 5, it is very easy to. learn what is causing the error light to ft ash on the
di
drive, and no need to write a program . Simply type:
26
27
HOUSEKEEPING HINTS
Hint #I: It is best to open file J 5 once at the very start of a program , and only . clo se i the end of the program, after all other files have already tx:en closed . Do ~1s bee closing the command channel automatically closes all other disk files . By ?penmg on the start, the file is open whenever needed for disk commands else:-vhere .m the p r~g
Closing it at the end makes sure all disk files are properly closed without mterrupt mg other file commands .
Note: the "O :" at the start of file name s i s a holdover from the days when all
Commodore disks had two drives in the s ame cabinet. Although the 1541 will normally default to drive 0 (not having a drive I , ) it i s best to s pecify the drive number whenever saving or writing a file . This avoids potential confusion in DOS
(the Disk Operating System .
)
Hint #2: If Basic halts with an error when you have files open,
Bas~c aborts them Wi t h A VING PROGRAMS: BASIC 3.5 closing them properly on the disk . To close them properly on the disk, you must t ype
OPEN 15,8,15 : CLOSE 15
Before you can s ave a program to diskette , the diskette must be formatted , as jescribed earlier. Saving to diskette is just like s aving to ca s sette , except that the device
This opens the command channel and immediately closes 11, al~ng with all o~ er 1 umber of the disk drive is not optional. files . Failure to close a disk file properly both in Basic and on the disk may result m 1 ORMAT FOR THE DSA VE COMMAND the entire file!
HINT #3: One disk error message is not always an error.
Err~r
73
, " C .
BM DO S DSAVE "file name ", Ddrive # , Udevice #
1541 " will appear if you read the disk error channel before send1 .
ng any ~1sk co mm a when you turn on your computer. This is a handy way to check are using. However , if this message appears later , after
oth~r w~ich
version of £?
OS here "file name ' ' is any string expression of up to 16 characters , optionally followed by disk
comman~~
t
·
11\e drive number (the " D " parameter , always 0 on the 1541 ), and the device number of there is a mismatch between the drive .
DOS used to format your diskette and the m · he disk drive (the " U " parameter) . If omitted, the drive number defaults to O , and the levice number to 8 .
HINT
.
#4: To reset dnve , type :
OPEN 15 8 15 "UJ
, • '
"
.
. .
. ac l uc h as
"DOS
5 . 1 or t e ommodore 64 . To copy
.
11
. . .
, and s1m1Jar machme language
LED is off and motor goes off, then type: CLOSE 15 . This also apphes to sendm g a
1 rograms, you will need the .
S command of the machine language monitor built into the or a UI - .
SAVING PROGRAMS: BASIC 2
: ommodore 16 and Plus / 4 . To access a built in monitor, type MONITOR . To exit nonitor, type X alone on a line . a
Before you can save a program to diskette , the diskette must be forma tte d , ORMAT FOR A MONITOR SAVE described earlier. Saving to diskette is just like saving to cassette , except that th e d t number of the disk drive is not optional. S"drive # : file name' ' , device #, s tarting address.ending address+ J
FORMAT FOR THE SA VE COMMAND
SAVE "drive # : file name" ,device# i here "drive# : " is the drive number , 0 on the 1541 ; " file name" is any valid file name
~ ~o
14 characters long (leaving 2 for the drive number and colon) ; "device# " is a two
~gu device number , normally 08 on the 1541 (the leading 0 is required) ; and the dresses to be saved are given in Hexadecimal (base 16 , ) but without a leading dollar where " file name " i s any s . , pre~e e b Y t he gn ($). Note that the ending address listed must be I location beyond the last location to number (alway s o on the 1541) and a colon , and followed by the device num ber 0
Xft.M
disk , normally 8. . . xt PLE:
However it will not work in copying programs that are not m the Basic t e s ue a s
" • 5
. l" for th e Commodore 64 . To copy 11 an s1m1 ar mac m e Jan
P rograms you will n e ed a machine language monitor program . for thi s
. • o the monitor s ave de s
. h ge
Jt •
'
ffere
S"o
·
is the required s yntax to save a copy of " DOS 5 .
1 "
Do
S 5 . J " , 08 , CCOO , C FSA
Ba s i c 3 .
5 .
2 8
29
SA VE WITH REPLACE OPTION If
the disk cop .
~ 0 ~ the pr~gram differ s even a tiny bit from the copy in memory ,
• VERIFY
ER~OR wil! be d1 s pla ~ ed , to tell you that the copie s differ. Thi s in it s elf oesn'I mean either copy 1 s bad , but 1f they were s upposed to be identical , one or the other
If
a file already exists , it can ' t be saved again because the disk
~nly allows o~ e c ~ as a problem . , . . . of any given file name per diskette . It is possible to get around this problem us ing q Naturally ' there
~ no point in trying to v erify a di s k c opy of a program after the
Rename and Scratch commands described later. However, if all you wish to do is rep J · ginal is no longer in memory . With nothing to compare to , a program or data file with a revised version , another command is more conv enieq ways be
an
apparent error will announ~ed , even though the di s k copy i s alway s and automatically verified a s it
Known as Save-with replace , or @ Save , this option tells the disk to replace an y fil e , Wfitten to the disk . finds in the directofy with the same name , substituting the new file for it. oRMAT FOR THE VERIFY COMMAND :
FORMAT FOR SA VE WITH REPLACE : FORMAT FOR SA VE
WITH
REP LA Q
BASIC
2
BASIC
3
.
5
VERIFY "drive # : pattern " , device# , re!ocate flag
SAVE "@ Drive # : file name ", device# DSAVE " @ file name " , Ddri ve 1
Udevice # here '_'drive # :" i s an optional drive number ( 0 on the 1541,) " pattern " i s any string
1 press1on that evaluate s to a file name, with or without pattern-matching characters and where all the parameters are as usual except for adding _ _ " at' _' sign_ (@.
) 7 device #" is the disk
devi~e
number , normally
8
. If the relocate flag is presen; and
" O :" in the Basic 2 version , though a holdover from earlier dual drives is require d h uals l, the file will be venfied where originally saved , rather than relocated into the a ic text area .
EXAMPLES : useful alternate form of the command is :
SAVE" @ O : REVISED PROGRAM"
,8
DSAVE "@ REVISED PROGRAM "
VERIFY "* '',device#
The actual procedure is that the new version is saved completely , then the old ve ru is scratched , and it s directory entry altered to point to the new version . Because it w verifies the last file used without having to type its name or drive number . However it this way , there is little , if any , danger that a disaster such as having the power g oing on't work properly after save with replace , because the last file used was the dne midway through the process would destroy both the old and new copies of the leted, _ drive will try to compare the deleted file to the program in memory . No
Nothing happens to the old copy until after the new copy is saved properly· .
~will ~suit
, but ' ' VERIFY ERROR ' ' will always be announced. To use verify after
However , we do offer one caution-<lo not use @ Save on an almost full d i s k AVE, include at least part of the file name that is to be verified in the pattern .
Only use it when you have enough room on the diskette to hold a second complet e c o p , One other note about Verify-when you Verify a relocated file , an error will nearly the program being replaced . Due to the way @ Save works , both the old and new v ern ways_ be announced, due to changes in the link pointers of Ba s ic programs made during of the file
are
on disk simultaneously at one point , as a way of safeguarding again st the program . If there is not enough room left on diskette to hold that second copy , much of the new version will be saved on the 1541 as there is still room for.
I Ol
loc~tion.
It is best to only verify files saved from the same type of machine and onJt
~tical m~mory
size. For example , a Basic program s aved from a VIC 20 can ' t easlly be
A f te i
nfi~
using a Commodore 64, even when the program would work fine on both command completes , a look at a directory will
~
how
the new version is
pre
sent ,
~~~s
_
(unless
the
progr~
is re saved ). This shouldn't matter , as the only time you'll doesn't occupy enough blocks to match the copy in memory . Unfortunately • th e V _ on machines other than the one which wrote them is when you are command ( see next section) will not detect this problem , because however mu c h saved will have been s aved properly . di l
".1f~ng
two disk files to s ee if they n Ymg a · h
are
the same . Thi s is done by loading one and
: rno . gamst t e other , and as suggested , can only be done on the same machine and ry size as the one on which the files were first created .
VERIFYING PROGRAMS
L
<\SING OLD PROGRAMS: BASIC 2
Although not a s nece s sary with a disk drive as with a cassette , Basic 's Vf
Sc
command can be used to make doubly certain that a program file was properly s av Upi:tch command allows you to era se unwanted file s, and free the s pa ce the y disk .• It works much like the . Load
com~and,
except
tha~
it only compai; esJC Via for use by oth _ s . It can be u s ed to era s e either a s ingle file , or s everal fil es a t character in the program agamst the equivalent character m the computer s pattern-matching . ory, instead of actually being copied into memory.
30 31
FORMAT FOR TIIE SCRATCH ffiMMAND :
PRINT# 15,' 'SCRATCHO:pattern''
.
rtern"
can be any file name or combination of characters and wild card characters . As
~.
"D"
s~ds for _ , which may only be
0
on the 1541. If the drive tier is omitted,
~ly
If
0
is assumed . Likewise, "U" stands for unit (device) number
"U" is omitted,
8
is assumed. '
111anks to the defaults , the usual form of the Scratch command becomes : or abbreviate it as :
PRINT# 15, ''SO:pattern"
"pattern" can be any file name or combination of characters and wild card chara cte11 scRA
TCH "pattern" usual it is assumed that the command channel has already been opened as file
Alth;ugh not absolutely necessary , it is best to include the drive number in Sc i As
a
precaution, you will be asked: commands .
If you check the error channel after a Scratch command, as tlescribed in the ~ section the value for ET (error track) will tell you how many files were scratch ed .
ARE YOU SURE? • exam pie , if your diskette contains program files named '' TEST' '• ''TRA Jore Basic obeys a Scratch command. If you are s ure , simply press y and RETURN . If
"TRUCK", and " TAIL ", you may scratch all four, along with any other files begi t, press RETURN alone or type any other answer , and the co mmand will be cancelled . with the letter "T", by using the command:
PRINT#l5,"SO:T*"
The number of files that were scratched will be automatically displayed . For exame, if your diskette contains program files named " TEST' ', " TRAIN ", " TRUCK", and fAIL", you may scratch all four , along with any other files beginning with the letter f ", by using the command:
Then, to prove they are gone, you can type :
SCRATCH "T* "
GOSUB 59990 to call the error checking subroutine given earlier in this chapter, and
.
1~ the four d if the four listed were the only files beginning with • 'T '', you will see: were the only files beginning with "T", you will see:
OJ
,FILES SCRA TCHED , 04 , 00
0 I
,FILES SCRATCHED , 04,00
READY.• e "04" tells you 4 files were scratched.
READY .
•
The "04" tells you 4 files were scratched .
:
RATCH (FOR ADVANCED USERS)
ERASING OLD PROGRAMS: BASIC 3.S
Scratch is a powerful command, and should be used with caution, to be sure you only
1
.ete the files you really want erased . When using it with a pattern , we suggest you first
The Scratch command allows you to erase unwanted programs and files from
·
the
~ed.
same pattern in a Directory command, to be sure exactly which files will be
That way you'll have no unpleasant diskettes, and free up the space they occupied for use by other files and pr~gram s .
Cratch command. surprises when you u · se the same pattern in be used to erase either a single file or several files at once via pattern-matching (des
' at the end of Chapter 3) .
cove..i--
Ii
If·-. rom
Lik:ou a Scratch
~c~identally
Scratch a file you shouldn ' t have , there is s till a chance of saving
FORMAT FOR TIIE SCRATCH COMMAND: lrs th:asi .
c s New_ c?mman~ , Scrat~h doesn't really wipe out a file itself; it merely
SCRATCH " pattern " ,Ddrive # ,Uunit #
I
Pro
P<_>mters to it
m
the diskette directory . If you immediately set the diskette aside led
I hel
), tect
·r
It
. w·th a wnte-protect notch, to be near Y
. od sure no one adds omm ore user group may be able any file to recover s to the diskette your file for you.
' a
It si~~ you
~an reme'.11ber what kind_offile it wa s you sc ratched ( program, sequential, that mformahon cannot be directly recovered from what is left of the file .
32 33
More about Splats h g)(
,.MPLES:
One other warning-never scratch a splat file. These are files that s ow u~ ~ directory listing with an asterisk (*)just before the file type for an entry: The ~stenskJusl before saving a new copy of a "calendar" program, you might type: splat) means that file was never properly closed, and thus there is no vahd chain of links for the Scratch command to follow in erasing the file.
PRJNT#l5 ,"RO:CALENDAR/BACKUP=CALENDAR"
If you Scratch such a file, odds are you will improperly free up sectors that are needed by other programs, and cause permanent damage to thos~ other _program s when you add more files to the diskette. If you find a splat file, ~r if you ~1scover t0o
10 move a program called "BOOT", currently the first program on a diskette to rneplace else in the directory, you might type: that you have scratched such a file, immediately validate the diskette usmg
~e
Yalj PRINT#l5 ,"RO:TEMP=BOOT" command described later in this chapter. If you have added any _files _ scratching the splat file, it is best to immediately copy the fresh diskette, but do this with a copy program rather
entJr~ t~an
diskette onto an with a backup prog i
Otherwise, the same problem will be recreated on the new diskette. When the new c~ done, compare the number of blocks free in its directory to the number fr~ on the on
P .
f
nowed
by a Copy command (described later), which turns "TEMP" into a new copy of
8 8
ooT",
and finishing with a Scratch command to get rid of the original copy of
ooT",
since renamed to "TEMP" by the command above. diskette. If the numbers match, no damage has been done. If not, very likely at leas t NAMING PROGRAMS: BASIC 3.5 file on the diskette has been conupted, and all should be immediately checked.
Locked Files . . can
The Rename command allows you to alter the name of a program or other file in the
Jiske tte directory . Since only the directory is affected, Rename works very quickly. erased with the Scratch command. Such files may be recognized by the":<" eh . RMAT FOR RENAME COMMAND: which immediately follows the file type in their directory entry. If you wish to e rt locked file, you will have to use a disk monitor to clear bit 6 of the
file-t~pe
byte directory entry on the diskette . Conversely, to lock a file, you would set bit 6 of the
RENAME ''old name'' TO ''new name'' ,Ddrive #, Udevice # byte . For more information on how such tricks are done, see Chapter
9 and Appendi vhere "new name " is the name you want the file to have, and "old name" is the name it and E.
1as now. "new name " may be any stri ng expression that evaluates to a valid file name,
RENAMING PROGRAMS: BASIC 2
I p to 16 characters in length. If "D" is left out, drive 0 is assumed . If "U" is absent, vic e 8 is assumed . One caution-be
The Rename command allows you to alter the name of a program or other . file · losed before you rename it. sure the file you are renaming has been properly diskette directory. Since only the directory is affected, Rename works very qui cklY:XA MPLES :
FORMAT FOR RENAME COMMAND : ust before aving a new copy of a "cale ndar " program, you might type:
PRINT# 15,' 'RENAMEO : new name= old name''
RENAME ''CALENDAR'' TO ''CALENDAR/BACKUP'' or it may be abbreviated as:
)r to move a program called "BOOT", currently the first program on a diskette to rne place else in the directory, you might type :
PRINT#l5,"RO:new name =o ld name"
RENAME "BOOT" TO "TEMP" where "new name" is the name you want the file to have, an d " Id "·s the ~ has now . "new name" may be any valid file name, up to 16 characters m Ien g assumed you have already opened file 15 to the
c~mmand
channel.
~
?~
One caution-be sure the file you are renaming has been properly closed be rename it.
0 W ed.~y a Copy command (described later), which turns "TEMP" into a new copy of
8
~T
• and finishing with a Scratch command to get rid of the original copy of
T" · since renamed to "TEMP" by the command above .
35
34
RENAMING AND SCRATCHING TROUBLESOME FILES
(ADVANCED USERS)
co P y1NG
PROGRAMS: BASIC 2
'J'he Copy comm a nd allow s you to make a spare copy of any program or file on a
Eventually, you may run across a file which has a crazy filename, such as a coll\ . te. However , on a single drive like the 1541 , the copy must be on the same diskette, by itself( " , " ) or one that includes a SHIFfed SPACE. Or perhaps you will find one dis~e~ means it must be given a different name from the file copied . It's also used to iqcludes nonprinting characters . Any of these can be troublesome. Comma fil es , whlC tenate up to four sequential data files (combining them by linking one to another , instance, are an exception to the rule that no two files can have the same name .
Si n ~ '~c~ shouldn ' t be possible to make a file whose name is only a comma , the disk never ex e you to do it again .
Files with a SHIFT-SPACE in their name can also be troublesome , because the4
be
;
0
1
50 urce files and other files on the diskette are not changed . Files must be closed re end in a chain) . Files are linked in the order in which they appear in the command . they are copied or concatenated . interprets the shifted SPACE as signalling the end of the file name, and prints w hate oRMAT FOR THE COPY COMMAND follows after the quotation mark that marks the end of a name in the directo ry . technique can also be useful, allowing you to have a long file name , but also m ake l
. # . fil d . # Id fil ,,
P
RI NT#15
'
0
·
· new e= nve ·
· o e disk recognize a small part of it as being the same as the whole thing withou t u pattern-matching characters . EXAMPLES:
In any case, if you have a troublesome filename , you can use the Chr$() fun ctiot specify troublesome characters without typing them directly . This may allow you to b ,
BASIC 2 FORMAT :
PRINT# 15, "COPYO : BACKUP =ORIGINAL" them into a Rename command . If this fails , you may also use the pattern-m ate r abbreviated as characters in a Scratch command. This give s you a way to specify the name withou t u the troublesome characters at all , but al s o means loss of your file .
For example , if you have managed to create a file named " " MOVIES ", with
PRINT#l5,"Cdrive # : new file=drive # : old file" extra quotation mark at tlie front of the file name, you can rename it to "MOVI ES " u s ing the Chr$ () equivalent of a quotation mark in the Rename command :
PRINT#l5 , ''CO:BACKUP=ORIGINAL ' ' where "drive#" is the drive number (0 on the 1541,) "new file" is the copy, and " old file" is the original.
PRINT# 15 ," RO : MOVIES = "+ CHR$ ( 34)+ " MOVIES " FORMAT FOR THE CONCATENATE OPTION
BASIC 3 .
5 FORMAT :
RENAME ( CHR$ ( 34)
+
" MOVIES ") TO " MOVIES "
PRINT# 15, "Cdrive # : new file= drive # : file J , drive#:file 2,drive # : file 3,drive
# : file 4"
Th CHR$ ( 34 )
The pro c
, s
· k
.
· h d t · ' th
1
. . . s tt ' g edure for a file name that includes a SHIFT-SPACE 1s similar, bu
8 t
",
~ where "drive
. . ve number 1s often omitted. number for each file. Since it is always 0 on the 1541 , the
CHR$(160 ) .
In cases wh e re even this doe s n ' t work , for example if your di s kette contains a corn:
EXAMPLE .
S. file , ( one named "," ) you can g et rid of it thi s way :
BASIC 2 FORMAT : BASIC 3 .
5 FORMAT:
After renaming a file named "BOOT" to "TEMP" in the last section's example, we c an use the Copy command to make a spare copy of the program elsewhere on the diskette, under the original name:
PRINT# 15 , " SO :?" SCRATCH "?
1
'
PRINT#l5,"CO : BOOT=TEMP"
Depending on the exact problem , you may have to be very creative in choosing patt ( fit t h . h fi t t k e p
1 th s th f
1
· 11 be
. f' t I th d h d t mg scra c e oo .
· d fil e , d h t m e
0 a p
• . .
· . . fi rogl'am we are using, we can use the concatenate option to combme them m a master le
' ev 'f is too big to fit in memory .
· ·11 fi · · ·
. u After creating several small sequential files that each fit easily m memory along with on the diskette-it will be as big as the sum of the sizes of the files in it.)
PRINT# 15, "CO:A-Z = A-G,H-M,N-Z"
36 37
NOTE:
Du~I dri".'es mai:e full~r use of this command, copying programs from one di s ~ c to another in a single disk unit. To do that on the 1541, refer to Appendix E to find programs that you need. oscd file (splat file), indicated by an asterisk(*) next to its file type in the directory, that
'~sk
tte needs to be validated. In fact, but for the one exception below, it is a good idea to
di
·
~te diskettes whenever you are the least bit concerned about their integrity.
\'all The exception is diskette s containing Direct Access files, as described in Chapter 7 .
COPYING PROGRAMS: BASIC 3.5
. The Copy command allows you to make a spare copy of any program or file ot diskette. However, on a single drive like the 1541, the copy must be on the same di s k which means it must be given a different name from the file copied. The source fil e other files on the diskette are not changed. Files must be clo ed before they are c o p ic
Although the 1541 supports a Concatenate option, Basic 3.5 doesn't have a s pe ~ command for it. The Basic 2 syntax from the previous page may be used instead. ·
1 direct access ( random) files do not allocate their sectors in a way the Validate
M:mand can recognize . Thus, using Validate on such a diskette may result in un-
c~ocating
all direct .access files,
wit~
loss of all their c?ntents
wh~n
other files _
~e ad~ed
.
~
Jess specifically instructed otherwise, never use Vahdate on a diskette containing direct n files . (Note: these are
~idate
may not the same as the relative files described in Chapter 6 . be used on relative files without difficulty.)
FORMAT FOR THE VALIDATE COMMAND
FORMAT FOR THE COPY COMMAND PRINT#\5 , "VALIDATEO"
COPY Ddrive #,"old file" to Ddrive #,"new file",Udevice # or abbreviated as where "D" is the drive number (always
0
on the 1541,) " new file" is the copy , " o file" is the original, and "U" is the device number. If omitted, the drive number defa ~ to 0 and the device number (unit) to 8.
PRINT#15 ,"VU'' where "O" is the drive number (always 0 on the 1541.) As usual, it is assumed file 15 has been opened to the command channel on the 1541 .
EXAMPLES:
After renaming a file named "BOOT" to "TEMP" in the last section's exampl e,
1 can use the Copy command to make a spare copy of the program elsewhere o n u diskette, under the original name:
EXAMPLE:
PRINT#l5, "VO'
VALIDATING THE DISKETTE: BASIC 3.5
COPY "TEMP" TO "BOOT"
To copy a file on a second disk drive, we would use:
COPY "ORIGrNAL" TO "BACKUP'',U9
The Collect command in Basic 3.5 is the same as the Validate command in Basic 2.
It recalculates the Block Availability Map (BAM) of the current diskette , allocating only those sector still being used by valid, properly closed files and programs . All other sec tors (blocks) are left unallocated and free for re use, and all improperly closed files are auto matically Scratched . However, this bare description of its workings doesn't indicate
NOTE: Dual drives make fuller use of this command, copying programs from one d is k e 1 either the power or the danger of the Collect command . Its power is in restoring to good to another in a single disk unit. To do that on the 1541, refer to Appendix E to find rl programs that you need . health many diskettes whose directories or block availability maps have become muddled.
Any time the blocks used by the files on a diskette plu s the blocks shown as free don ' t add up to the 664 available on a fresh diskette , Collect is needed (with one exception below .)
VALIDATING THE DISKETTE: BASIC 2
Similarly, any time a diskette contains an improperly-closed file (splat file) , indicated by
The Validate command recalculates the Block Availability Map (BAM) of d current diskette, allocating only those sectors still being used by valid, properly -clo an asterisk (*) next to its file type in the directory , that diskette needs to be collected . In fact, but for the one exception below, it is a good idea to collect diskettes whenever you are the least bit concerned about their integrity . Just note the number of blocks free in the files and programs . All other sectors (blocks) are left unallocated and free for re-u se , a r all improperly-closed files are automatically Scratched. However, this bare descript ion its workings doesn't indicate either the power or the danger of the Validate comman d . I diskette's directory before and after using Collect , and if the totals differ , there was indeed
a
problem, and the diskette s hould probably be copied onto a fresh diskette file by file ,
Using the Copy command described in the previous section , rather than using a backup cornrnand or program. power is in restoring to good health many diskettes whose directories or block avail a bi li ' maps have become muddled . Any time the blocks used by the files on a diskette plu s ~ blocks shown as free don't add up to the 664 available on a fresh diskette , Valid a t e needed, with one exception below . Similarly, any time a diskette contains an impro per!
'
M The exception i s diskettes containing Direct Access file s, as described in Chapter 7 .
OSt direct acces s (random) files do not allocate their sectors in a way Collect can recognize . Thus , collecting such a diskette may result in un allocating all direct access
38 39
· · · . . files , with loss of all their contents when other file~ are added . Unless spe c i tic~
. are
~ot d the erw1se, sa~e as never t~e co ect a
·
relative files descnbed m Chapter relative files without difficulty .
) d
1s ette contammg
· ·
d
1rect
6 . access fil es .
(N ote
Collect may be u
. se th d
1 e
~ o
!IC· on r
1ne progran1 e use for Initialize is to keep a cleaning diskette spinning, if you choos · e · to use ss and care
.
wil
.
P d
. such kits on any regular basis under normal conditions of one e es s
, if you are using such
.
1 kee the diskette spinning long enough for your need :
. s h
FORMAT FOR THE COLLECT COMMAND 100PEN l5,S,l 5
2 o
FOR I= I TO 99
30: PRINT#l5 ," IO"
COLLECT Ddrive # , Udevice #
40NEXT
50CLOSE 15 where " D" is the drive number (always 0 on the 1541,) and "U" the device number .
~ usual, if omitted they default to drive 0 and device 8 respectively .
It uses an
Initialize loop to keep the drive motor on for about 20 seconds.
EXAMPLE :
COLLECT DO
INITIALIZING
One command that should not often be needed on the 1541, but is still of occa sio111 value is Initialize . On the 1541, and nearly all other Commodore drives, this funct io n
1 performed automatically , whenever a new diskette is inserted . (The optical write-p ro t ec switch is used to sense when a diskette is changed .
)'
The result of an Initialize , whether forced by a command, or done automaticall y~ the disk, is a re-reading of the current diskette's BAM (Block Availability Map ) i nt o 1 disk buffer. This information must, of course, always be correct in order for the d is k
1 store new files properly. However, since the chore is handled automatically, the onl y t i m you'd need to use the command is if something happened to ma.Ke the information i n th drive buffers unreliable . Even so, you may use the command for reassurance, as oft e n t you like, so Jong as you close all your files except for the command channel first.
FORMAT FOR THE INITIALIZE COMMAND
PRINT# 15, "INITIALIZEdri ve #"
EXAMPLE:
PRINT#l5, ''INITIALIZ E O or it may be abbreviated to
PRINT#l5,"Idrive #" PRINT#l5, "IO" where the command channel is assumed to be opened by file 15, and "drive#" i s O ~ the 1541.
41
40
CHAPTERS
SEQUENTIAL DATA FILES
Be fore we study the format of the Open statement , let ' s review some of the possible
Je\fices i n a Commodore computer system :
THE CONCEPT OF FILES
Used for:
A file on a diskette is just like a file cabinet in your office an o rganized plac e to llo things . Nearly everything you put on a diskette goes in one kind of file or another. So
1
. all we've used are program files, but there are others, as we have mentioned . I n th
1 chapter we will learn about sequential data files .
As we just suggested, the primary purpose of a data file is to store the cont ents
Q program variables, so they won ' t be lost when the program ends . A sequential dat a fi l e one in which the contents of the variables are stored "in sequence," one righ t af1t another, just as each link in a chain follows the previous link . You may already be famili i with sequential files from using a DATASSETIE ™ , because sequential files on di ske11i are just like the data file s used on cassettes . Whether on cassette or diskette, sequ enii a files must be read from beginning to end , without skipping around in the middle .
When sequential file s are created, information (data) is transferred byte by byte through a buffer , onto the magnetic media . Once in the disk drive , program filei sequential data files, and user files all work sequentially . Even the directory act s like
1 sequential file .
To use sequential files properly , we will learn some more Basic words in th e n e~ few pages . Then we'll put them together in a simple but useful program .
3 Screen
4 Printer
8 Disk drive
Receiving input from the computer operator
Sending and receiving information from cassette
Sending and receiving information from a Modem
Sending output to a video display
Sending output to a hard copy printer
Sending and receiving information from diskette eeca u se of the flexibility of the Open statement, it is possible for a single program state m e n t to contact any one of these devices, or even others , depending on the value of a sing l e c h aracter in the command . Often an Open statement is the only difference between
8
program
that uses a DAT ASSETIE ™ and one using the 1541. If the character is kept in
8 vari abl e, the device used can even change each time that part of the program is used , sendi n g data alternately and with equal ease to diskette, cassette, printer and screen .
Note: Besides sequential data files , two other file types are recorded sequenti a ll y on a diskette, and may be considered varying forms of sequential files. They are program files , and user files. When you save a program on a diskette, it is saved in order from beginning to end , just like the information in a sequential data file . Th e main difference is in the commands you use to access it. User files are even m ore similar to sequential data files---differing , for most purposes, in name only . U ser files are almost never used, but like program files, they could be treated as thou gh they were sequential data files and are accessed with the same commands .
For the advanced user, the similarity of the various file types offers t he possibility of such advanced tricks as reading a program file into the compute r a byte (character) at a time and rewriting it to the diskette in a modified form . Th e idea of using one program to write another is powerful , and available on th e
Commodore disk drives .
pe
vlce #: Name: o
Keyboard t DATASSETTE™
2 RS232
REM EMBER TO CHECK FOR DISK ERRORS! ln the last chapter we learned how to check for disk errofS after disk comman ds in a program . It is equally important to dheck for disk errors after using filehandli ng statements . Failure to detect a disk error before using another filehandlin g statement could cause loss of data, and failure of the Basic program.
T h e easiest way to check the disk is to follow all file-handling statements with a Go sub statement to an error check subroutine.
EXA M PLE :
840 OPEN 4 , 8 , 4, "O : DEGREE DAY DATA , S , W"
850 GOSUB 59990 : REM CHECK FOR DISK ERRORS
FO RMA T FOR THE DISK OPEN STATEMENT :
OP EN file#, device# , channel #,"drive #:file name .
file type.direction
"
Where:
OPENING A FILE
One of the most powerful tools in Commodore Basic is the Open statement. W it h ii · you may send almost any data almo E t anywhere, much like a telephone switchboard th ~ can connect any caller to any destination . As you might expect , a command that ca n d o this much is fairly complex . You have already used Open statements regularly in so me ~ your diskette housekeeping commands .
" file # " is an integer (whole number) between 1 and 255 . If the file number is
&reate r th an 127 , a line-feed character is inserted after each carriage return in the file
0
J>e ned. T h ough this may be helpful in printer files , it will cause severe problems in di s k files, and i s to be avoided at all costs . Do not open a disk file with a file number greater
~an
1 2 7 . After the file is open, all other file commands will refer to it by the number give n h e r e . Only one file can use any given file number at a time .
"de vice #" is the number , or primary address, of the device to be used . This nurn be r i s an integer in the range 0-31, and is normally 8 on the 1541 .
42
43
"channel #" is a secondary address, giving further instructions to the selecteii device about how further commands are to be obeyed . ln disk files, the channel num ber selects a particular channel along which communications for this file c an take place . possible range of disk chanrel numbers is 0-15, but 0 is reserved for program
Loa~s
The
• I for program Saves, and 15 for the disk command channel. Also be sure that n~ two disk file s have the same channel number unless they will never be open at the same ume . (One wa~ to do this is to make the channel number for each .file the same as its file number .)
"drive#" is the drive number , always 0 on the 1541. Do no t omit it, or you WilJ only be able to use two channels at the same time instead of the norm a l
m~imum thr~e
If any pre-existing file of the same name is to be replaced, precede the drive number w1t1i the "at" sign(@) to request Open-with-replace . .
"file name" is the file name, maximum length 16 characters. Pattern mat ching characters are allowed in the name when accessing existing files, but not when creatin g of course, this ~rases al .
I our old phone numb~rs , so make sure that any information that rnaY be deleted 1s of no importance . After wnllng our phone file, we remove our diskeue and tum off the system. Later , to recall the data in the file , we would reopen it with s0inething like
OPEN 8 , 8 ,8, "O: PHONES,S , R "
It doesn't matter whether the file and channel numbers match the ones we used before, but the file name does h ave to match . However, it is possible to use an abbreviation form of the file name , if there are no other files that would have the same abbreviation :
OPEN 10,8 ,6, "O:PH* ,S,R" new ones .
"file type" is the file type desired : S=sequential , P=program, U=user , and
If we have too many phone numbers, they might not fit in one file . In that case, we might use several similar file names , and let a program choose the correct file.
L =length of a relative file. . ...
"direction" is the type of access desired . There are three poss1b1h11es : R =read , w
=write and M =modify . When creating a file, use '' W' ' to write the data to di skette
When
vie~ing
a completed file, use " R" to read the data from
disk~tte.
Only u se th e
"M" (modify) option as a last ditch way of reading back data from an 1mpro .
perlt clos .
ed
(Splat) file. (If you try this, check every byte as it is read to be sure the data 1s sttll vahd , as such files always include some erroneous data, and have no proper end .
)
"file type" and
"dir~ction" don't have to be abbreviated. They can be spelled ou t
100 INPUT " WHICH PHONE FILE ( l-3) "; PH
110 IF PH <> I AND PH <>2 AND PH <>3 THEN 100
120 OPEN 4,8 ,2, "PHONE"+ STR$(PH) + ",S,R"
You can omit the drive number on an Open command to read a file . Doing so allows those with dual drives to search both diskettes for the file. in full for clarity in printed listings . or
.
"file#" "device#" and "channel#" must be valid numeric constants, var1able 1
expression~.
The rest of the command mus! be a valid string literal, variab le or expression .
Note: Basic 2 and Basic 3.5 use the same file handling commands and the same direct access commands (chapters 7-8) . Unless otherwise noted , you may use the same commands for both throughout the remainder of this book .
The maximum number of files that may be open sim ultaneously is 10 , includi ng a ll files to all devices . The maximum number of sequential disk files that can be open at onc e is 3 (or 2 if you neglect to include the drive number in your Open statement), plu s tht command channel . ADDING TO
A SEQUENTIAL FILE
EXAMPLES OF OPENING SEQUENTIAL FILES :
To create a seq uential file of phone numbers , you could use :
On Commodore's PET and CBM models, an Append command allows you to reopen an existing sequential file and add more information to the end of it. The same thing can
be
done another way on the 1541. In place of the "type" and "direction" parameters in
Your Open statement, substitute ",A" for Append . This will reopen your file, and
Position the disk head at the end of the existing data in your file, ready to add to it.
OPEN 2,8,2, "O:PHONES,SE QUENTIAL,WRITE"
FoRMA T FOR THE APPEND OPTION or save yourself some typing with:
OPEN file #,device #,channel #,"drive # : file name,A"
OPEN 2,8,2, "O:P HONES ,S,W"
On the off-chance we've already got a "PHONES" file on our diskette , we can av oid '
1
~here.
everything is as on the previous page except for the ending "A" replacing the
'type" and "direction" parameters .
"F ILE EXISTS" error mes sage by doing an @ OPEN
OPEN 2,8,2, "(U,O: PHONES ,S,W"
44 45
EXAMPLE:
If you are writing a grading p~ogram, it would be convenient to simply tack on eac ~ student's new grades to the end of their existing grade files . To add data to the
"JOH
N
~"file# " is the same file number given in the desired file's current Open statement. poring any given access of a particular file, the file number must remain constant because it serves as a shorthand way of relating all other file-handling commands back to the carrect Open statement. Given a file number, the computer can look up everything else
PAUL JONES" file. we could type ab<JUl a file that matters.
The "data list" is the same as for a Print statement a list of constants, variables
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 fi rsi time you append to it, even if you only add one character of information. You may al SQ notice that using the Collect or Validate command didn't correct the file size . On the othe
1 hand, your data is quite safe, and if the wasted space becomes a problem, you can ea s il j
. correct it by copying the file to the same diskette or a different one, and scratching th e original file. Here's a sequence of commands that will copy such files to the ori gi n al diskette under the original name, for ease of continued use: artJJor expressions, including numbers, strings or both . However, it is strongly recommended that each Print# statement to disk include only one data item. If you wish to iJIClude more items, they must be separated by a carriage return character, not a comma. semicolons are permitted, but not recorded in the file, and do not result in any added spaces in the file. Use them to separate items in the list that might otherwise be confused, such as a string variable immediately following a numeric variable .
Note: Do not leave a space between PRINT and #, and do not abbreviate the command as ?# . The correct abbreviation for Print# is pR.
BASIC 2:
PRINT#l5,"RO:TEMP=JOHN PAUL JONES"
PRINT#l5,"CO : JOHN PAUL JONES=TEMP"
PRINT#l5,"SO : TEMP"
EXAMPLES :
BASIC 3.5:
RENAME "JOHN PAUL JONES" TO "TEMP"
COPY "TEMP" TO "JOHN PAUL JONES"
SCRATCH "TEMP"
To record a few grades for John Paul Jones, using a sequential disk file #I previously opened for writing, we could use:
If you are using Basic 2, be sure to open file 15 to the command channel beforehand ( i .
e with OPEN 15,8,15) and close it afterwards (i.e
.
, with CLOSE 15).
200 FOR CLASS= 1 TO COURSES
210 : PRINT#l,GRADE$(CLASS)
220 NEXT CLASS
320 GOSUB 59990:REM CHECK FOR DISK ERRORS
WRITING FILE DATA: USING PRINT#
After a sequential file has been opened to write (with a type and directi o n cl
",S, W"), we use the Print# command to send data to it for storage on diskette . If you art familiar with Basic's Print statement, you will find Print# works exactly the same wa y . except that the list of items following the command word is sent to a particular fi le instead of automatically appearing on the screen. Even the formatting options (pun ctu a tion and such) work in much the same way as in Print statements. This means you h ave tr be sure the items sent make sense to the particular file and device used.
For instance , a comma between variables in a Print statement acts as a separat o r screen
displays
~ making each successive item appear in the next preset displa y fi e\ I
(typically at the next column whose
num~er
is evenly divisible by 10). If the same c ornJ111 is included between variables going lo a disk file, it will again act as a separator , agail inserting extra spaces into the data . This time, however, it is inappropriate, as th e ex trl spaces are simply wasted on the diskette , and may create more problems when readi ng file b~ck t ~ into the computer. Therefore, you are urged to follow the following fofll1
1 precisely when sending data to a disk file.
(assuming your program includes an error check subroutine like the one in the last chapter).
In using Print# there is an exception to the requirement to check for disk errors after every file-handling statement. When using Print#, a single check after entire set of data has been written will still detect the error, so long as the check
IS made before any other file-handling statement or disk command is used. You
may
be
familiar
with Print statements in which several items follow each other:
400 PRINT NAME$,STREET$,CITY$
~get those same variables onto sequential disk file number 5 instead of the screen , the t approach would be to use three separate Print# statements , as follows :
400 PRINT#5,NAME$
410 PRINT#5,STREET$
420 PRINT#5,CITY$
FORMAT FOR THE PRINT# STATEMENT
PRlNT#file #,data list
46
47
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$
CHR$(13) is the carriage return character, and has the same effect
as
putting the Print items in separate lines . If you do this often , some space and tim e may be sav ed b y previously defining a variable as equal to CHR$( 13) : apen. close every file you even think might be open before ending a program. If for eitarnple, we always gave our files numbers between 1 and 10 , we could close them all
~th
9950 FOR I = 1TO10
9960 CLOSE I
9970 GOSUB 59990 : REM CHECK FOR DISK ERRORS
9980 NEXT I
LO CR$=CHR$(13) ... 400 PRINT#5 , NAME$ ; CR$ ; STREET$ ; CR$ ; CITY$ (assuming your program includes an error check subroutine like the one in Chapter 4)
The basic idea is that a proper sequential disk file write, if redirected to the sc reen , will display only one data item per line , with each succeeding item on the next line .
READING FILE DATA: USING INPUT#
CLOSING A FILE WHEN YOU ARE DONE USING IT
After you finish using a data file, it is extremely important that you Close it. D uring the proce s s of writing a file , data is accumulated in a memory buffer , and only writt en out to the physical cassette or diskette when the buffer fills .
Working this way, there is almost always a small amount of data in the buff er thai has not been written to diskette or cassette yet , and which would simply be lost if the computer system were turned off . Similarly , there are diskette housekeeping matters , such as updating the BAM (Block Availability Map) of sectors used by the current file , which are not performed during the ordinary course of writing a file . This is the reaso n for having a Close statement. When we know we are done with a file, the Close stat emem will write the rest of the data buffer out to cassette or diskette , update the BAM , and complete the file ' s entry in the directory . Always Close a data file when you are done using it! Failure to do so may cause loss of the entire file!
However , do not close the disk command channel until all other files have been
Closed . The command channel (described in the last chapter) , when used, should be the first file Opened, and the last file Closed in any program . Otherwise , reruaining file s ma ) be closed automatically . As also described there, this may be used to advantag e if
1 program halts on an error while disk files are open .
Once information has been written properly to a diskette file , it may be read back into the computer with an Input# statement. Just
as
the Print# statement is much like the Print statement, Input# is nearly identical to Input , except that the list of items following the command word comes from a particular file instead of the keyboard . Both statements are subject to the same limitations-halting input after a comma or colon , not accepting data items too large to fit in Basic ' s Input buffer , and not accepting non-numeric data into a numeric variable .
FORMAT FOR THE INPUT# STATEMENT
PRINT#file # , variable list where "file#" is the same file number given in the desired file's current Open statement , and "variable list " is one or more valid Basic variable name s. If more than one data element is to be input by a particular Input# statement , each variable name must be separated from others by a comma .
EXAMPLES :
To read back in the grades written with the Print# example , use :
FORMAT FOR THE CLOSE STATEMENT
CLOSE file#
300 FOR CLASS = I TO COURSES
310 INPUT# l ,GRADE$(CLASS)
320 GOSUB 59990 : REM CHECK FOR DISK ERRORS
330 NEXT CLASS where " file# " is the same file number given in the desired file's current Open stat ement
EXAMPLES :
To clo~e the data file #5 u s ed as an example on the previous page , we would use
CLOSE 5
In Commodore 's CBM and PET computers, there i s a Dclose statement, that , u s ed alone, closes all disk files at once . With a bit of planning, the same can be w n e r
d
one ~
Ba s i c 2 and 3 .
5 via a program loop . Since there is no harm in closing a file that wasn
<assuming your program includes an error check subroutine like the one on page 27 ) .
Use:
To read back in the address data written by another Print# example , it is safe s t to
800 INPUT#5 , NAME$
810 GOSUB 59990 : REM CHECK FOR DISK ERRORS
820 lNPUT#5 , STREET$
830 GOSUB 59990 : REM CHECK FOR DISK ERRORS
840 INPUT#5,CITY$
850 GOSUB 59990 : REM CHECK FOR DISK ERRORS
49
48
but many programs cheat on safety a bit and use quotation mark , in either an Input or Input# statement , all other character s except a carriage return or another quotation mark are accepted as part of the current data element.
800 INPUT#5,NAME$ , STREET$ , CITY$
810 GOSUB 59990 : REM CHECK FOR DISK ERRORS eXAMPLES :
This is done primarily when top speed in the program is essential, and there is little or n risk of reading improper data from the file .
To force a quotation mark into a data element going to a file , append a CHR$ ( 34) to the
start
of tbe..fiata element. For example :
MORE ABOUT INPUT# (FOR ADVANCED USERS)
PRINT#2 , CHR$(34 ) + " STRASMA, JIM"
Troublesome Characters
After you begin using data files regularly , you may encounter two Basic error message s more or les s frequently . They are " STRING TOO LONG ERROR " and "FILE
DATA ERROR ". Both are likely to halt your program at an Input# statement , bu t may also have been caused by errors in a Print# statement when the file was written . or
PRINT#2 , CHR$(34) ;" STRASMA , JIM"
If
you do this often, s ome space and time may be saved by previously defining a variable
as
equal to CHR$(34) as we did earlier with CHR$(13):
"STRING TOO LONG " ERRORS
A Basic string may be up to 255 characters long , although the longest string you can enter via a single Input statement is just under 2 lines of text (4 on the VIC 20) . Thi s lower limitation is due to the 88 character size of the Input buffer in Commodore's seri al bus computers . The same limit applie s to Input# statements . If a single data element (stri ng or number) being read from a disk file into an Input# statement contains more th an 87 characters, Basic will halt with a " STRING TOO LONG ERROR ". To prevent this error, be sure to limit each string to under 88 characters , and separate all file data items with carriage returns (See the next section for a cure once the error has occurred .)
20 QT$= CHR$(34)
400 PRINT#5,QT$ +NAME$
In each case, the added quotation mark will be stripped out of the data by the Input or
Input# statement, but the comma or colon will remain safely part of the data .
NUMERIC DATA STORAGE ON DISKETTE
"FILE DATA " ERRORS
The other error message " FILE DATA ERROR" is caused by attempting to r ead a non-numeric character into a numeric variable. To a computer , a number is the char acters
0 through 9, the
"
+
"
ana " - " signs, the decimal point( .
), the SPACE character , and the letter " E" used in scientifi c notation. If any other character appears in an Input # to a numeric variable , " FILE DATA ERROR" will be displayed and the program will ha l l.
The usual causes of this error are a mismatch between the order in which variabl es are written to and read from a file, a missing carriage return within a Print# statemen t t h at writes more than one data item , or a data item that includes either a comma or a colon without a preceding quotation mark . Once a file data error has occurred , you s h ould correct it by reading the data item into a string variable, and then converting it bac k to a number with the Basic Val() statement after removing non-numeric characters wi th the string functions described in your computer users manual.
COMMAS (.) AND COLONS ( : )
As suggested before, commas and colons can cause trouble in a file, becau se theY delimit (end) the data element in which they appear and cause any remaining charact ers in the data element to be read into the next Input# variable . (They have the same effect in an
Input statement , causing the common " EXTRA IGNORED" error message.) How ever. sometimes we really need a comma or colon within a data element, such as a name w ritten as " Last , First" . The cure is to precede such data elements with a quotation mark . A fter a
Inside the computer, the space occupied by a numeric variable depends only on its type. Simple numeric variables use 7 bytes (character locations) of memory . Real array variables use 5 byte§ per array element, and integer array elements use 2 bytes each . In contrast, when a numeric variable or any type is written to a file , the space it occupies depends entirely on its length, not its type .
Numeric data is written to a file in the form of a string, as if the Str$ () function had been performed on it . The first character will be a blank space if the number is positive , and a minus sign ( ) if the number is negative. Then comes the number , digit by digit.
The last character is a cursor right character .
This format allows the disk data to be read back into a string or numeric variable later. It is, however , somewhat wasteful of disk space, and it can be difficult to anticipat e the space required by numbers of unknown length . For this reason, some programs convert all numeric variables into strings before writing them to diskette, and use string functions to remove any unneeded chara c ters in advance . Doing so still allow s tho s e data elements to be read back into a numeric variable by Input# later , although file data error s be avoided by reading all data in a s s trings , and converting to numbers after the tnforrnation is inside the computer .
For example, "N$ = MID$(STR$(N),2) " will convert a positive number N into a
5
1ring N$ without the usual leading s pace for its numeric sign . Then instead of writing i>RINT#5 , N , you would use PRINT#5 , N$ .
50
51
READING FILE DATA: USING GET#
:111~ 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 int o specified variable. However, unlike the Get statement, it doesn ' t just fall through t o th a n~xt statement if there is no data to be gotten. The primary use of Get# is to retrieve fr o ; diskette any data that cannot be read into an Input# statement, either because it is too I o n to fit in the input buffer or because it includes troublesome characters . g
Get# may be especially useful in recovering damaged files , or files with unknown
'°"te
nts
. The Basic reserved variable ST (the file STatus variable) can be used to indicate all of a
properly-closed file has been read .
500 GET#2,S$
510 SU=ST : REM REMEMBER FILE STATUS
520 PRINT S$; .
530 IF SU =0 THEN 500 : REM IF THERE'S MORE TO BE READ
540 IF SU< > 64 THEN PRINT " STATUS ERROR : ST= "; SU
FORMAT FOR THE GET# STATEMENT:
GET#file#, variable list eopying ST into SU is often an unneccessary prec~ution, but must be done if any other file-handling statement appears between the one which
r
~
ad fro~
the file and the one that toops back to read again . For example, it would be required 1f lane 520 was changed to where "file#" is the same file number given in the desired file's current Open statem e nt and "variable list" is one or more valid Basic variable names . If more than one dat ~ element is to be input by a particular Get# statement, each variable name must be separated from others by a comma.
In practice, you will almost never see a Get or Get# statement containing more than one variable name. If more than one character is needed, a loop is used rather th a n additional variables . Also as in the Input# statement, it is safer to use string variabl es when the file to be read might contain a non-numeric character.
Data in a Get# statement comes in byte by byte, including such normally invisible characters as the Carriage Return, and the various cursor controls . All but one will be r e ad properly . The exception is CHR$(0), the ASCII Null character. It is different from a n empty string(oneofthe form A$= '"'),even though empty strings are often referred t o a s null strings. Unfortunately, in a Get# statement, CHR$(0) is converted into an em p t y string . The cure is to test for an empty string after a Get#, and replace any that are fo u nd with CHR$(0) instead. The first example below illustrates the method.
EXAMPLES :
To read a file that may contain a CHR$(0), such as a machine language program fi le, we could correct any CHR$(0) bytes with
520 PRINT# I ,S$ ;
()dterwise, the file status checked in line 530 would be that of the write file, not the read
file.
IFST=
0
I
2
4
8
16
32
64
128
POSSIBLE VALUES OF THE FILE STATUS VARIABLE "ST" ,
AND l'HEIR MEANINGS
THEN
All is OK
Receiving device wa not available (time out on talker)
Tran milling device was not available (time out on listener)
Cassette data file block was too short
Cassette data file block was too long
Unrecoverable read error from cas ette , verify error
Cassette checksum error--0ne or more faulty characters were read
End of file reached (EOI detected)
Device not present, or end of tape mark found on cassette
1100 GET#3,G$ : 1F G$= ""THEN G$=CHR$(0)
If an overlong string has managed to be recorded in a file, it may be safely read b ac k into the computer with Get# , using a loop such as this
3300 B$ = ""
3310GET#l , A$
3320 IF A$< >CHR$( 13) THEN B$ = B$ + A$:GOTO 3310
The limit for such a technique is 255 characters. It will ignore CHR$(0), but that may be: an advantage in building a text string .
53
52
DEMONSTRATION OF SEQUENTIAL FILES
Use the following program for your first experiments with sequential fil es.
Comments have been added to help you better understand it.
150 CR$ = CHR$ , (13)
160 OPEN 15,8,15
170 PRINT CHR$(147):REM CLEAR
SCREEN
190 PRINT"** WRITE A FILE** "
210 PRINT
220 OPEN 2,8,2, " @O : SEQ FILE,S,W"
230 GOSUB 500
240 PRINT " ENTER A WORD,
THEN A NUMBER' '
250 PRINT"OR 'END,O' TO STOP"
260 PRINT
270 INPUT A$,B
Make a carriage return variable
Open demo file with replace
Check for disk errors
Accept a string & number from keyboard
Write them to the disk file
280 PRINT#2,A$ ; CR$;B
290 GOSUB 500
300 IF A$ <>" END " THEN 270
310 PRINT
320 CLOSE 2
340 PRINT"** READ SAME FILE
BACK**"
360 PRINT
370 OPEN 2 , 8,2 , "O : SEQ FILE,S,R"
380 GOSUB 500
390 INPUT#2 , A$ , B
400 RS=ST
410 GOSUB 500
420 PRINT A$ , B
430 IF RS = 0 THEN 390
440 IF RS <> 64 THEN
PRINT' ' STATUS = ''; RS
450 CLOSE 2
460 END
480 REM ** ERROR CHECK S I R * *
500 INPUT#l5 , EN,EM$ , ET,ES
510 IF EN>O THEN PRINT
EN ,EM$,ET , ES : STOP
Until finished
Tidy up
Reopen same file for reading
Read next string
Remember
& number from fil file status
Display file contents until done , unless there's an error
Then quit
A Basic 3 replace line 500 with
'500 IF
.
5-only version could
DS>O THEN PRINT e
520 RETURN
DS$:STOP and delete line 510
CHAPTER6
RELATIVE DATA FILES
fJ1E
VALUE OF RELATIVE ACCESS
Sequential files are very useful when you 're just working with a continuous stream of
data-
i.e., information that can be read or written all at once . However, sequential files are not useful or desirable in some situations . For example , after writing a large list of mail labels, you wouldn ' t want to have to re read the entire list each time you need a person's record . Instead, you need some kind of random access, a way to get to a particular label in your file without having to read through all those preceding it first.
As an example, compare a record turntable with a cassette recorder. You have to listen to a cassette from beginning to end, but a turntable needle can be picked up at any
time.
and instantly moved to any spot on the record . Your disk drive works like a turntable in that respect. In this chapter we will learn about a type of file that reflects this flexibility .
Actually , two different types of random access files may be used on Commodore disk drives : relative files and random files . Relative files are much more convenient for most data handling operations, but true random access file commands are also available to advanced users, and will be discussed in the next chapter.
FILES, RECORDS, AND FIELDS
When learning about sequential files, we did not worry about the organization of data within a file, so long as the variables used to write the file matched up properly with those which read it back into the computer. But in order for relative access to work, we need a more structured and predictable environment for our data .
The structure we will use is similar to that used in the traditional filing cabinet . In a traditional office , all customer records might be kept in a single file cabinet. Within this file, each customer has a personal record in a file folder with their name on it , that contains everything the office knows about that person . Likewise, within each file folder , there may be many small slips of paper , each containing one bit of information about that customer, such as a home phone number, or the date of the most recent purchase .
In a computerized office, the file cabinet is gone, but the concept of a file containing all the information about a group or topic remains . The fiie folders are g1 ,; me too , but the notion of subdividing the file into individual records remains. The slips of paper within the personal records are gone too, replaced by subdivisions within the records, called fields. Each field is large enough to hold one piece of information about one record in the file. Thus, within each file there are many records, and within each record there are typically many fields .
A relative file takes care of organizing the records for you , numbering them from I to
Whatever, by ones, but the fields are up to you to organize . Each record will be of the same size, but the 1541 won't insist that they all be divided the same way . On the other hand, they normally will all be subdivided the same way , and if it can be known in advance exactly where each field starts within each record, there are even fast way s to ilCcess a desired field within a record without reading through the other fields . A s all of lhis implies, access speed is a primary reason for putting information into a relative di s k file. Some well-written relative file programs are able to find and read the record of on e
54 55
desired person out of a thousand in under 15 seconds , a feat no sequential file could match . pr og r alli
FILE LIMITS
. One of the nicest aspects of relative files is that all this is done for you without havmg to worry at .
all
~bout
0 exactly where on the diskette's surface a given record wiii Ur stored, or whether 1t will fit properly within the current disk sector or need to be e x t d he onto . the next available sector. DOS takes care of all that for you '. All you need t o specify how long do the rest'. e
~ eac~
reco .
rd is: in bytes, and how many records you will need . DO S
a~d ~rgan~ze
thmgs m such a way that it can quickly find any record as soon as It is
~1~en
Its re~ord number (ordinal position within the file) . in th e o ~d
1
, / fii
11 e ,
The only hm1t that will concern you, is that each record must be the same si z the record length you choose must be between 2 and 254 characters Naturally th eee , a n d file I h fi a so as to t on your diskette too, which means that the more records you ne ed th shorter each must be .
· . · n t 1re
· e
Notes:
I . Do not precede the drive number with the "at" sign( @ ); there is no reason to replace a relative file .
2. ,L , "+ CHR$(record length) is only required when a relative file is first created, though it may used later, so long as the "record length" is the same as when the file was first created . Since relative files may be read from or written to alternately and with equal ease, there is no need to specify Read or Write mode when opening a relative file.
3. "file#", "device#" and "channel#" must be valid numeric constants, variables or expressions . The rest of the command must be a valid string literal, variable or expression .
4. Only I relative file can be open at a time on the 1541, although a sequential file and the command channel may also be open at the same time .
CREATING A RELATIVE FILE
EXAMPLES
:
. When a relative file is to be used for the first time, its Open statement will cre a t e t h e file,
af~e~
that, the and wntmg . same Open statement will be used to re-open the file for both r ead · in g
To create or re open a relative file named "GRADES" , of record length 100 , use
OPEN 2,8,2,"GRADES,L," +CHR$(100)
FORMAT STATEMENT TO OPEN A RELATIVE FILE :
OPEN file # , device# , channel # , "drive # : file name, L" + CHR$ ( r eco r d length) '
To re -open an unknown relative file of the user's choice that has already been created, we could use
200 INPUT''WHICH ALE'';A$
210 OPEN 5,8,5,A$ where ' .
'file#" is the file number, normally an integer between I and 127; "device# " is the device numbe.r to be used'.
no~ally
8 on the 1541; "channel #" selects a part ic ul ar
ch~~~el
.
along.~~1ch co~municatJOns
for this file can take place, normally between 2 a n d
14, dn:e # is .
the dnve number, always 0 on the 1541 ; and "file name" is th e file
?ame, with a maximum length of 16 characters . Pattern matching characters are all owed
'.~
the name
~~~n acc~ssing
an existing file , but not when creating a new on e . T h e record length . is the size of each record within the file in bytes used, including carriage returns , quotation marks and other special characters .
USING RELATIVE FILES: RECORD#
When a relative file is opened for the first time, it is not quite ready for use . Both to save time when using the file later, and to assure that the file will work reliably, it is necessary to create several records before closing the file for the first time. At a minimum, enough records to fill more than 2 disk sectors (512 bytes) should be written . In practice, most program s go ahead and create as many records as the program is eventually expected
to
use. That approach has the additional benefit of avoiding such problems as running out
of
room on the diskette before the entire file is completed.
If you simply begin writing data to a just-opened relative file, it will act much like a lequential file, putting the data elements written by the first Print# statement in Record
II, those written by the second Print# statement in record #2 and so on . (As this implies, each relative record must be written by a single Print# statement, using embedded carriage returns within the data to separate fields that will be read in via one or more
Input# statements later.) However, it is far better to explicitly specify which record
~Urnber is desired via a Record# command to the disk . This allows you to access records
Ill any desired order, hopping anywhere in a file with equal ease . Properly used, it also avoids a subtle error (bug) common to all Commodore disk drives .
56
57
FORMAT FOR THE RECORD# COMMAND :
PRINT# 15, " P" +CHR$ (channel#+ 96) + CHR$ (<record#)+ CHR$
(>record #) + CHR$ (offset) tNPUT "RECORD # DESJRED";RE
::IF RE< I OR RE>65535 THEN 450
10
(lH = INT(RE/256)
' RL==RE -256*RH
: : 15, "P" + CHR$ (98) + CHR$ (RL) + CHR$ (RH) where "channel #" is the channel number pecified in the current Open statement for t he specified file, "<record#" is the low byte of the desired record number, expre ss e d as a two byte integer, " =:::record #" is the high byte of the desired record number, a n d an optional "offset" value, if present, is the byte within the record at which a foll owing
Read or Write should begin.
To fully understand this command, we must understand how most integers are sto r ed in computers based on the 6502 and related microprocessors . In the binary arithmeti c used by the microprocessor , it is possible to ex pre s any unsigned integer from 0-25 5 in a single byte . It is also possible to store any unsigned integer from 0-65535 in 2 byte s, with
I byte holding the part of the number that is evenly divisible by 256 , and any remain der in the other byte . In machine language , s uch number are written backwards, with th e low. order byte (the remainder) first . followed by the high order byte . In a sembly l a n guage programs written with the Commodore As embler . the low part of a two byte num ber is indicated by preceding its label with the les sthan character (< ) . Similarly. the hi gh pan of the number is indicated by greater than ( > ) .
rniJ'g
RH and RL are calculated as in the
INPUT "CHANNEL. RECORD, & OFFSET DESIRED";CH,RE,OF !:
PRINT#l5, "P"+CHR$(CH +96) +CHR$ CRL) +CHR$ (RH) +CHR$ (OF)
ANOTHER RECORD# COMMAND pr~vious the channel, record, and offset requ1recj: example, program~ may abo u~e
Basic 4.0 on Commodore's PET and CBM models includes a Basic Record#
C(JlllllWld not found in any of the serial bus computers . However, som~ available utility programs for these models include it.
It
_ sei:es the same function as the
Record#
command explained above, but has a s1mphfied syntax:
SAFETY NOTE: GIVE EACH RECORD# COMMAND TWICE!
To avoid the remote possibility of corrupting relative file data . it is necessary t o give Record# commands twice--once before a record is read or written. and ag ain immediately afterwards .
RECORD#file #,record #,offset wm
"file#" is the relative file number being used, not the command channel's file, "record#" is the desired record number, and "offset" is as above.
If you see a Record# command written in Basic 4 form in a program yo _ w~t to use, simply convert it into the usual form for both Basic 2 and 3.5 descnbed
m this
section.
EXAMPLES :
0MPLETING RELATIVE FILE CREATION
To position the record pointer for file number 2 to record number 3, we could t ype :
PRINT #15, "P" +CHR$ (98) +CHR$ (3) +CHR$ (0)
The CHR$(98) comes from adding the constant (96) to the desired channel number
(2) .
(96 + 2 = 98) Although the command appears to work even when 96 is not added t o the channel number, the constant is normally added to maintain compatibility with th e waY
Record# works on Commodore's CBM and PET computers .
Since 3 is less than 256, the high byte of its binary representation is 0, and the ent i re value fits into the low byte . Since we want to read or write from the beginning o f th ~ record, no offset value is needed.
Since these calculations quickly become tedious, most programs arc written to d o them for you . Here is an example of a program which inputs a record number and con ve rt s it into the required low byte/high byte form:
Now that we have learned how to use both the Open and Record# commands, we
are
ready to properly create a relative file. The only additional fact we need to know is
CllRS(255) is a special character in a relative file. It is the character used by _
fill
relative records as they
are
created, before a program fills them with other
~ill
not interfere with our later work, CHR$(255) is the obvious choice .
. ia how it works in an actual program whi~h you may copy for use in your own
Ve file programs.
J200pEN
15 ,8,15
1%QINJ>UT"ENTER RELATIVE FILE NAME";FI$
~INPUT''ENTER
MAX .
# OF RECORDS";NR
INPUT" ENTER RECORD LENGTH";RL
Open command channel
Select file parameters
59
58
1410 OPEN 1 , 8 , 2, " O : "+ FI$+ " ,L ," +CHR$(RL)
1420 GOSUB 59990
1430 RH= lNT(NR/256)
1440 RL=NR 256*RH
1450 PRINT#l5, "P" + CHR$(96 + 2) +
CHR$(RL) + CHR$(RH)
Begin to create d es ireQ
Check for disk e rro r s
Calculate length VaJ
u
Cs
G RELATIVE FILE DATA
1be
commands used to read and write relative file data are the same Print# , Input# ,
(jtl.# commands used in the preceding chapter on Sequential files. Each command i s
,J
15 described there . However , some aspects of relative file access do differ from file programming , and we will cover those differences here . Position to last r eco r d number
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 I
Send default char ac t er to
Re-position for safe t y
Now the file can be sai closed
AS seated earlier in this chapter, each relative record has a fixed length , including all
·ial
characters . Within that fixed length, there are two popular ways to organize
~ oUS individual fields of information . One is free-format, with individual fields varyin g
i0gth
from record to record , and each field separated from the next by a carriage return
(each of which does take up 1 character space in the record) . The other approach
~ use fixed-length fields, that may or may not be separated by carriage returns . If fixed
1520 GOSUB 59990
9980 CLOSE 15
9990 END
59980 REM CHECK DISK SUBROUTINE
59990 INPUT#l5,EN , EM$,ET,ES
60000 IF EN > 1 AND EN<>50 THEN PRINT
EN ,EM$,ET ,ES : STOP
60010 RETURN
And the comman d e h closed
Before we end th e pro. gram fields are not all separated by carriage returns, you will either need to be s ure a return is included within each 88 character portion of the record . If this is not
'OC .
you
will have to use the Get# command to read the record , at a significant cost in
Relative records of 88 or fewer characters, or final portions of records that are 88 or
0 ercharacters in length, need not end in a carriage return . :fhe 1541 is smart enough to
· ognize the end of a relative record even without a final• carriage return . Though the
1
1ng of
a single character isn't much, when multiplied by the number of record s on a
Ignore "RECOR D NOT ette, the savings could be significant.
PRESENT" Since each relative record must be written by a s ingle Print# statement , the recom ndcd approach is to build a copy of the current record in memory before writing it to it It can be collected into a single string variable with the help of Basic ' s many s tring -
Two lines require additional explanation . When line 1470 executes, the disk drive
( operate for up to ten or more minutes , creating all the records in the file , up t o maximum record number you selected in line 1390 . This is normal , and only n eeds t o done once . During the process you may hear the drive motor turning and an occasi
. g function s, and then all written out at once from that variable .
Here is an example . If we are writing a 4-line mail label , con s isting of 4 fields n a m e d
AME",
"STREET" , "CITY & STATE ", and " ZIP CODE ", and have a total record of87 characters, we can organize it i n either of two w a y s: slight click as the head steps from track to track , everything is probably just fin e . Sec line 60000 above is different from the equivalent line in the error check subrout ine gi
1 earlier. Here disk error number 50 is specifically ignored , because it will be ge n e . Id N when the error channel is chec;ked in line 1460 . We ignore it because not havtn! requested record would only be ail error if that record had previously been crea ted . \
ME
ame
Length
2 7 chara c ter s
WITH VARIABLE LENGTH FIELDS
Field Nam e
NAME
L e ngth
3 1 c hara c t e r s
EXPANDING A RELATIVE FILE
27 character s
23 char a cter s
STREET
CITY & STATE
3 1 c hara c t e r
2 6 chara c ter s
1 I c har ac t e r s I 0 c hara c ter s ZIP CODE
What if you underestimate your needs and need to expand a relative fil e later ? problem . Simply request the record number you need, even if it doesn't curr e n tly e~ 1 the file . If there is no such record yet,
oos·
will create it as soon as you t ry to
~ information in it , and also automatically create any other missing records beloW
11 number. The only penalty will be a s light time delay while the record s are cr eated .
87 charact e r s P o t e nt ia l l e n g th
Edit e d l e n g th
99 c hara c t e r
87 c har ac t e r
·
1
With fixed length re co rd s. th e fi e ld l e ngth s a dd up t o ex a c tly th e r ec ord l e n g th . Si n ce otal length is ju s t within th e Input buffer s i ze limit a ti o n , n o ca rri age r e turn c h arac t e r s
: ileeded. With variabl e l e n g th r ec ord s, w e ca n tak e a d v ant age of th e va t ia b i l i t y of
<Ja! address length s . Whil e on e n a m e c ontain s 2 7 l e tt e r s. a n o th e r m ay h ave o nl y 1 5,
.
the same variability e xi s t s in Str ee t a nd City l e n g th s. Al t h o u g h va ri a bl e le n gt h record
1 character per fi e ld for ca rri age r e turn s, th ey ca n t ake a d va nt age of th e differe n ce
60 61
between maximum field length and average field length. A program that use s v . record lengths must calculate the total length of each record as it is entered , to be total of all fields doesn't exceed the space available.
8
Ure
WRITING THE RECORD
Here is an example of program lines to enter variable length fields for the abov design , build them into a single string, and send them to record number RE in file nuc
3 (assumed to be a relative file that uses channel number 3) .
'Jf1J_ IF LEN(SA$)>27 THEN 2020
SA$+ LEFT$(BL$ ,2 7 LN)
fl'IJ
(NPUT "CITY & STATE "; CS$
LN = LEN(CS$)
;,so
IF LEN(CS$) >23 THEN 2040 j,sS
CS$ = CS$+ LEFT$(BL$ ,2 3 LN)
INPUT"ZIP CODE" ; ZP$
'flJS
LN = LEN(ZP$) f10IFLEN(ZP$)>10 THEN 2060
150 CR$=CHR$(13) Carriage Return
Enter fields
And check length of each
= ZP$ + LEFT$(BL$ , 10-LN)
DA$ =NA$+ SA$+ CS$+ ZP$
:120 RH= lNT(RE/256)
'.1J0 RL = RE 256*RH
;,40 PRINT#15, "P" +CHR$(96 + 3) +
2000 INPUT"NAME";NA$
2010 IF LEN(NA$)>30 THEN 2000
2020 lNPUT"STREET" ; SA$
2030 IF LEN(SA$)>30 THEN 2020
2040 INPUT"CITY & STATE";CS$
2050 lF LEN(CS$)>25 THEN 2040
2060 lNPUT"ZIP CODE" ; ZP$
2070 lF LEN(ZP$)> 10 THEN 2060
2080 DA$ = NA$+ CR$+ SA$+ CR$+
CS$+ CR$ + ZP$
2090 lF LEN(DA$)<87 THEN 2120
2100 PRINT"RECORD TOO LONG"
2110 GOTO 2000
2120 RH= INT(RE/256)
2130 RL=RE-256*RH
2140 PRINT#l5,"P" +CHR$(96+3)+
CHR$(RL) + CHR$(RH)
2150 GOSUB 59990
2160 PRINT#3,DA$
2170 GOSUB 59990
2180 PRlNT#l5,"P" +CHR$(96+3)+
CHR$(RL) + CHR$(RH)
2190 GOSUB 59990
Build output data strin g
Check its length
If too long overall
Calculate record numbe r
Position to record number RE
Check for disk errors
Send data to it
Re -position for safety
. CHR$(RL) + CHR$(RHl + CHR$ (I)
!ISO GOSUB 59990
!160 PRINT# 3 , DA$ ;
:170 GOSUB 59990
!i80
PRINT#l5 ,"P" +CHR$(96+3) +
CHR$(RL ) + CHR$(RH) + CHR$ (I)
:190 GOSUB 59990
Note lack of separators
Note added semicolon
If
field contents vary in length , variable field lengths are often preferable . On the
'Cher hand , if the field lengths are stable, fixed field lengths are preferable . Fixed length ields
are
also required if you want to use the optional offset parameter of the Record#
;oounand to point at a particular byte within a record . However , one warning must be
13dc about using the offset this way . When any part of a record is written , DOS vcrwrites any remaining spaces in the record . Thus, if you must use the offset option,
:ever update any field in a record other than the last one unless all succeeding fields will
ilsobe
updated from memory later.
. The above programs are careful to match record lengths exactly to the space
•11ilab le. Programs that don't do so will discover that DOS pads short records out to full
1
1.e with fill characters, and tri.mcates overlong records to fill only their allotted space.
Yihen
a record is truncated, DOS will indicate error 51, "RECORD OVERFLOW", but
~records will be accepted without a DOS error message .
To use the above program lines for the version with fixed length field s, we
YI
•~·alter a few lines as follows :
""'WING A RELATIVE RECORD
150
160 BL$="
Not needed this time
27 shifted space char acters
Once a relative record has been written properly to diskette, reading it back into
-lllputer memory is fairly simple, but the procedure again varies , depending on whether
illes
fixed or variable length fields . Here are the program lines needed to read back the lllable fields created above from record number RE in file and channel 3 : 2000 INPUT"NAME "; NA$
2005 LN = LEN(NA$)
2010 IF LEN(NA$) > 27 THEN 2000
2015 NA$ = NA$+LEFT$(BL$ , 27 LN)
2020 JNPUT " STREET "; SA$
2025 LN = LEN(SA$)
Checking for differen t tengthl
And padding to pres et sizes llO
120
RL = RE-256*RH
PiUNT#l5, "P" + CHR$(96 + 3)+
CJ.iRS(RL) + CHR$(RH) + CHR$ ( 1)
Calculate record number
Position to record number R E
62 63
3030 GOSUB 59990
3040 INPUT# l ,NA$,SA$,CS$,ZP$
3050 GOSUB 59990
3060 PRINT#l5, "P" +CHR$(96+ 3) +
CHR$(RL) + CHR$(RH)
Check for disk errors
Read in fields
Re-position for safety
CHAPTER 7
DIRECT ACCESS COMMANDS
~ fOOL FOR ADVANCED USERS
Here are the Jines needed to read back the version with fixed length fields :
3000 RH= INT(RFJ256)
3010 RL=RE-256*RH
3020 PRINT#l5,"P" +CHR$(96+3) +CHR$
Direct access commands specify individual sectors on the diskette, reading and
..nung information entirely under your direction . This gives them almost complete
~bility in data-handling proerams, but also imposes tremendous responsibilities on the to be sure nothing goes awry. As a result, they are normally used only in tdl!Plex commercial programs able to properly organize data without help from the disk
( RL) + CHR$(RH)
3030 GOSUB 59990
3040 INPUT# l ,DA$
3050 GOSUB 59990
3060 PRINT#l5, "P" + CHR$(96+ 3) +
CHR$(RL) + CHR$(RH)
Read in entire record
,JIVC itself .
A far more common use of direct access commands is in utility programs used to fl(9I and alter parts of the diskette that are not normally seen directly . For instance . such
,1Jflll1lllnds can be used to change the name of a diskette without erasing all of its to lock a program so it can't be erased , or hide your name in a location where it
'°"'t be expected .
3070 NA$= LEFf$(DA$,27)
3080 SA$= MID$(DA$ , 28 , 27)
Split data into fields
DISKETTE ORGANIZATION
3090 CS$= MID$(DA$,55,23)
3100 ZP$ = RIGHT$(DA$, 10)
There are a total of 683 blocks on a 1541 diskene , of which 664 are available for use, itb the rest reserved for the BAM (Block Availability Map) and the Directory .
The diske!!e's surface is divided into tracks, which are laid out as concentric circles
This ends our discussion of n ·l .
111ve files . A complete "RELA
TIY~
FILE" similar to the examples in this ch.ipt~r. is included on the Test/Demo diskette . progra m
111
lhe
surface of the diskette . There are 35 different tracks , starting with track I at the ldlide of the diske!!e to track 35 at the center . Track 18 is used for the directory, and the
DOS
fills up the diskette from the center outward , alternately in both direction s.
THE VALUE OF INDEX FILES (ADVANCED USERS) Each track is subdivided into sectors (also called blocks) . Because there is more separately. ft d th · th the sequential
. d
In the last two chapters we have learned how to use sequential an re file used to
1
. v e eep fi b l
.Cl
ne records of which name in the relative file 1s stored m each record number. al . Y contents of the
. d · array and sorted alphabeti c al Y an room on the outer tracks, there are more sectors per track there. The
Table 6.1: Track and Sector Format outermost track s
1
.mn 21 sectors each , while the innermost ones only have 17 sectors each . The table the
!Jclow
shows the number of sectors per track .
After sorting, a technique known as a binary search can be used to
v~ry quic~y·
entered name in the array' and read in or write the associated record m. the . re n
~u ve file TRACK NUMBER SECTOR NUMBERS TOTAL SECTORS
21
Advanced programs can maintain two or more such index files, sorted m d1ffenn g ways simultaneously.
I to 17
18 to 24
25 to 30
0 through 20
0 through 18
O through 17
19
18
31 to 35 0 through 16 17
In this chapter we will describe the DOS commands for directly reading and writing
:nylrac k and block on the diskette, as well as the commands used to mark blocks as used llllused. Unless otherwise notes, all direct access commands are the same in both Basic
·and Basic 3.5
.
OitNiNG A DATA CHANNEL FOR DIRECT ACCESS
When working with direct access data, you need two channels open to the disk : the
' d we've used throughout the book, and another for data . The command illne1 is opened with the usual OPEN 15,8,15 or equivalent. A direct access data
64
65
channel is opened much like other files, except that the pound sign (#), optionau 61(AMPLE : fo llowed by a memory buffer number, is used as a file name .
~
FORMAT FOR DIRECT ACCESS FILE OPEN STATEMENTS :
Here is a complete program to read a sector into disk memory using U I , and from ibtre into computer memory via Get# . (If a carriage return will appear at least once in every 88 characters of data , Input# may be used in place of Get#) .
OPEN file #,device#, channel#, "#buffer#" where "file#" is the file number , " device# " is the disk's device number, norm ally
8
"c hannel# " is the channel number, a number between 2 and 14 that is not used by othe;
. files open at the same time; and " buffer# " , if present, is a 0, 1, 2 , or 3, specifying the memory buffer within the 1541 to use for this file 's data .
EXAMPLES: lf we don't specify which disk buffer to use, the 1541 will select one:
OPEN 5,8,5, " # "
Or we can make the choice ourselves :
110 MB = 7936 : REM $I FOO
120 lNPUT " TRACK TO READ" ; T
130 INPUT " SECTOR TO READ" ; S
140 OPEN 15,8 , 15
ISO OPEN 5,8,5 , "#"
160 PRINT#IS, "U I ";S;O;T;S
170 FOR l=MB TO MB+255
180 GET#5 ,A$:IF A$= " "
THEN A$= CHR$(0)
190 POKE l,ASC(A$)
200 NEXT
210 CLOSE S : CLOSE 15
220 END
Define a memory buffer
Select a track and sector
Open command channel
Open direct access channel
Read sector into disk buffer
Use a loop to copy disk buffer into computer memory
Tidy up after
OPEN 4,8 ,4," #2 "
BLOCK-READ
As the loop progresses, the contents of the specified track and sector are copied into computer memory , beginning at the address set by variable MB in line 160, and may be examined and altered there . This is the basis for programs like " DISPLAY T & S " on the
Test/Demo diskette.
BLOCK-WRITE
The purpose of a Block Read is to load the contents of a specified sector into a file buffer . Although the Block Read command (B-R) is still part of the DOS command set, it is nearly always replaced by the U 1 command .
The purpose of a Block Write is to save the contents of a file buffer into a specified sector. It is thus the reverse of the Block Read command. Although the Block Write command (B-W) is still part of the DOS command set, it is nearly always replaced by the
U2command .
FORMAT FOR THE BLOCK-WRITE COMMAND:
FORMAT FOR THE BLOCK READ COMMAND:
PR1NT#l5 , "U2";channel #;drive #;track #;sector#
PRINT#l5 , "UI ";c hannel# ; drive# ; track# ; sector# where "c hannel # " is the channel number specified when the file into which th e bloc k will be read was opened, " drive# " is the drive number, always 0 on the 1 541 . an d
"tr ack #" and "sector #" are respectively the track and sector numbers contai ning thl desired block of data to be read into the file buffer.
~"channel#"
is the channel number specified when the file into which the block
~II
be read was opened ; "drive#" is the drive number (always O on the 1541 ); and track #" and "sector #" are respectively the track and sector numbers that should l'CCeive the block of data being saved from the file buffer.
ALTERNATE FORMATS :
ALTERNATE FORMATS :
PRINT#IS , " U I :"c hannel # ; drive #;track #;sector#
PRINT#IS ," UA :" channel # ; drive # ; track #;sector#
PRINT#IS ," Ul :c hannel #,drive #,track #,sector#"
PRINT# 15 , " U2 :" channel # ; drive # ; track # ;sec tor#
PRINT#IS ,"UB:"channel # ; drive # ; track #;sector#
PRINT#IS ,"U2 : channel #,drive #,track # ,se ctor# "
66 67
llJl>reviated as: PRINT#l5,"B-W";channel #;drive #;track #;sector#
EXAMPLES:
To restore track 18, sector 1 of the directory from the disk buffer filled by the Bl ack
Read example on page 82, we can use wtiere "channel #" is the channel number specified when the file into which the block
\\'ill be read was opened, "drive#" is the drive number (always 0 on the 1541), and
··uack #" and "sector #" are respectively the track and sector numbers containing the
11e5ired block of data to be partially read into or written from the file buffer.
PRINT#l5,"U2";5;0;18;1
We'll return to this example on the next page, after we learn to alter the directory in a useful way.
We can also use a Block Write to write a name in Track l, Sector 1, a rarely u sed sector. This can be used as a way of marking a diskette as belonging to you . Her e i s a program to do it, using the alternate form of the Block Write command :
110 INPUT" YOUR NAME" ;NA$
120 OPEN 15,8, 15
130 OPEN 4,8,4, "#"
140 PRINT#4,NA$
150 PRINT#l5,"U2" ; 4;0;1;1
160 CLOSE 4
170 CLOSE 15
!RO END
Enter a name
Open command channel
Open direct access channel
Write name to buffer
Write buffer to Track 1,
Sector 1 of diskette
Tidy up after
IMPORT ANT NOTES:
I . In a true Block-Read, the first byte of the selected sector is used to determine how many bytes of that sector to read into the disk memory buffer. It thus cannot be used to read an entire sector into the buffer, as the first data byte is always interpreted as being the number of characters to read, rather than part of the data .
2. Similarly, in a true Block-Write , when the buffer is written back to diskette, the first byte written is the current value of the buffer pointer, and only that many bytes are written into the specified sector. It cannot be used to rewrite an entire sector onto diskette unchanged, because the first data byte is overwritten by the buffer pointer.
THE BUFFER POINTER
THE ORIGINAL BLOCK-READ AND BLOCK-WRITE COMMANDS (EXPERT
USERS ONLY)
Although the Block Read and Block Write commands are nearly
~ I ways repla ce d b y the U 1 and U2 commands respectively. the original commands can still be used , as l o n g as you fully understand their effects . Unlike U 1 and U2, B-R and B-W allow you t o re a.
d or write less than a full sector. In the case of B-R, the first byte of the selected s e ct o r
15 used to set the buffer pointer (see next section), and determines how many byte s o f th ~t sector are read into a disk memory buffer. A program may check to be sure it d oes n
1 h
. f o r t he value of the file status variable ST to change from 0 to 64 . When the buffer is writt e n b ack to diskette by B-W, the first byte written is the current value of the buffer point e r . a n d only that many bytes are written into the specified sector. B-R and B-W may thu s be useful in working with custom-designed file structures .
The buffer pointer points to where the next Read or Write will begin within a disk memory buffer. By moving the buffer pointer, you can access individual bytes within a block in any order. This allows you to edit any portion of a sector, or organize it into fields, like a relative record .
FORMAT FOR THE BUFFER-POINTER COMMAND :
PRINT# 15, "BUFFER-POINTER" ;channel #;byte
USually abbreviated as: PRINT# 15, "B-P" ;channel #;byte
""here
"channel #" is the channel number specified when the file reserving the buffer
'N&s opened, and "byte" is the character number within the buffer at which to point.
FORMAT FOR THE ORIGINAL BLOCK-READ AND BLOCK-WRITE coM
·
MANOS:
ALTERNATE FORMATS:
PRINT#l5,"BLOCK-READ";channel #;drive #;track #;sector#
PRINT#l5 ,"B-P:"channel #;byte
PRINT#l5, "B-P:c hannel #;byte" abbreviated as: PRINT#l5,"B-R";channel #;drive #;track #;sector# EXAMPLE : and Here is a program that locks the first program or file on a 1541 diskette. It works by
!tading the start of the directory (Track 18, Sector I) into disk memory, setting the buffer
PRlNT#15,"BLOCK-WRITE";channel #;drive #;track#; ector #
69
68
pointer to the first file type byte (see Appendix C for details of directory organi zation) locking it by setting bit 6 and rewriting it. '
110 OPEN 15 , 8 , 15
120 OPEN 5,8,5 , " #"
130 PRINT#l5, "Ul " ;5 ; 0;18 ; 1
140 PRINT#l5,"B P" ; 5 ;2
150 GET#5 , A$ : IF A$= "" THEN A$=CHR$(0)
160 A= ASC(A$) OR 64
170 PRINT#l5 \" B-P" ; 5 ; 2
180 PRINT#5,CHR$(A);
190 PRINT#l5 ," U2" ; 5 ; 0;18;1
200CLOSE 5
210 CLOSE 15
220 END
Open command channe l
Open direct access chann el
Read Track 18, Sector I
Point to Byte 2 of the buffer
Read it into memory
Tum on bit 6 to lock
Point to Byte 2 again
Overwrite it in buffer
Rewrite buffer to diskett e
Tidy up after
After the above program is run , the first file on that diskette can no longer be erased . If you later need to erase that file, re-run the same program, but substitute the revi sed line
160 below to unlock the file again:
160 A=ASC(A$) AND 191 Tum off bit 6 to unlock
ALLOCATING BLOCKS
Once you have written something in a particular sector on a diskette with the help of direct access commands, you may wish to mark that sector as "already used, " to keep other files from being written there. Blocks thus ''allocated'' will be safe until the diskette is validated.
FORMAT FOR BLOCK ALLOCATE COMMAND :
PRINT#l5 ," BLOCK-ALLOCATE "; drive # ; track #;sector# usually abbreviated as : PRINT#l5,"B A "; drive # ; track #;sector# where " drive# " is the drive number, always 0 on the 1541, and " track#" and "sector
#" are the track and sector containing the block of data to be read into the file bu ffer .
ALTERNATE FORMAT :
PRINT#l5,"B-A :"; drive #;track # ; sector#
EXAMPLE:
If you try to allocate a block that isn ' t available, the DOS will set the error me ssage to number 65, NO BLOCK , and set the track and block numbers in the error me ssage
1 0 the next available track and block number. Therefore , before se le cting a block to write , lf'f 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 th e directory track . If the track number returned is 0 , the di ske tte is full.
Here is a program that allocate s a place to s tore a message on a diskette .
Open command c hannel
" direct access "
100 OPEN15 ,8, 15
110 OPEN5 , 8,5 , "#"
120 PRINT#5 , "I THINK
THEREFORE I AM "
1JOT= l : S= I
140 PRINT#l5 ,"B-A";O;T;S
150 INPUT#l5 , EN,EM$ , ET,ES
160 IF EN =0 THEN 210
170 lF EN <> 65 THEN PRINT
EN , EM$ ,E T ,ES:STOP
180 IF ET = 0 THEN PRINT
"DISK FULL ": STOP
190 IF ET = 18 THEN ET = 19 :E S =0
200T=ET : S =E S : GOTO 140
210 PRINT#l5 ," U2 "; 5 ; 0 ; T ; S
220 PRINT "STORED AT :" ,T,S
230 CLOSE 5 : CLOSE 15
240 END
Write a message to buffer
Start at first track & sector
Try allocating it
See if it worked
If so, we're almost done
" NO BLOCK " means already allocated
If next track is 0 , we ' re out of room
Don ' t allocate the directory!
Try suggested track & sector next
Write buffer to allocated sector
Say where message went and tidy up
FREEING BLOCKS
The Block Free command is the opposite of Block Allocate . It frees a block that you don't need any more, for re-use by the DOS. Block-Free updates the BAM to s how a panicular sector is not in use , rather than actually erasing any data .
FORMAT FOR BLOCK FREE COMMAND :
PRINT#l5 ,"BLOCK-FREE";drive # ; track # ; sector# abbreviated as : PRINT#l5,"B-F "; drive #;track # ;s ector# where "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 read into the file buffer.
ALTERNATE FORMAT :
PRINT#l5, "B-F:";drive #;track # ; sectoi" #
70
71
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 ;l
USING RANDOM FILES (ADVANCED U~ERS
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. (Even though you know a sector has not been allocated by your random file, you must also be sure it wasn't allocated by another unrelated file on the diskette.)
The most common way of recording which sectors have been used by a random file is in a sequential file. The sequential file stores a list of record numbers, with the track, sector, and byte location of each record . This means three channels are needed by a random file: one for the command channel, one for the random data, and the last for the sequential data.
CHAPTERS
INTERNAL DISK COMMANDS
Expert programmers can give commands that directly alter the workings of the
15~
I, h as skilled programmers can alter the workings of Ba sic inside the computer with mucks Pokes and Sys calls. It is also possible to write machine language prograivs that
~ entirely within the _ , either
~y writ~ng
them
in~o dis~
memory from the com Pu
In u ter or by londing them directly from diskette into the de s ired disk memory buffer.
•
•
Se this is similar to loading and
. . · your computer. . . .
As when learning to use Peek() , Poke and Sy s in your computer, extreme caution is advised in using the commands in this chapter. They ~e essentially machine language command s, and lack all of Basic 's safeguards . If anyth1~g goes wrong .. you may have to the disk drive off and on again (after removing the diskette) to regain control. Do not
WC:tice these commands on any important diskette . Rather , make a s pare copy and work
~th that. Knowing how to program a 6502 in machine language will help greatly, and you will also need a good memory map of the 1541 . A brief 1541 map appears below .
Location
0000-00FF
0100-0IFF
0200-02FF
0300-07FF
1800-ISOF lCOO-ICOF
Cl00-F258
F259-FE66
FE67 -FE84
FE85-FEE6
FEE7 -FFOF
FFE6-FFFF
1541 MEMORY MAP
Purpose
2K of RAM memory
Zero page work area : job queue , important variables & pointers
Stack work area
Command buffers & tables : channels, parser, output, variables
Data buffers 0 4, I per page of memory . lnput/Output chips
6522 VIA: I / O to computer
65f2 VIA : I / O to disk controller
Two SK Disk Operating System ROMs
Interface Processor : receive & interpret commands from computer
Floppy Disk Controller: executes IP 's commands, controls mechanism
IRQ handler : switches from IP to FDC & back every 10 ms .
ROM tables & constants
Patch area
JMP table : User command vectors
73
72
Other Resources:
More detailed information about Commodore disk drives can be found in the se books:
Inside Commodore DOS, by Imrners & Neufeld (Datamost, cl984)
The Anatomy of the 1541 Disk Drive, by Englisch & Szczepanowski
(Abacus, cl984)
Programming the PET/CBM, by West (Level Limited, c 1982)
The PET Personal Computer Guide, by Osborne & Strasmas
(Osborne/McGraw-Hill, c 1982)
MEMORY-READ
The disk contains l 6K of ROM (Read-Only Memory), as well as 2K of RAM (Re a d -
Write Memory) . You can get direct access to any location within these, or to the buff ers that the DOS has set up in RAM, by using memory commands. Memory-Read allow s y ou to select which byte or bytes to read from disk memory into the computer. The Memory -
Read command is the equivalent of the Ba ic Peek() function, but reads the di sk's memory instead of the computer's memory.
Note: Unlike other disk commands , those in this chapter cannot be spelled out in full. Thus, M-R is correct, but MEMORY-READ is not a permitted alternat e wording .
FORMAT FOR THE MEMORY-READ COMMAND:
PRINT# 15, "M-R "CHR$( <address)CHR$(>address)CHR$( # of bytes) where "<address" is the low order par\, and ">address" is the high order part of the address in disk memory to be read . If the optional "#of bytes" is specified, it sel e ct s
'how many memory locations will be read in, from 1-255 . Otherwise, I character will be read . If desired, a colon ( : ) may follow M-R inside the quotation marks .
AMPLES :
To see how many tries the disk will make to read a particular sector, and whether
.. see k s
" one-half
"bUmP
. s" to track one and back will be attempted before declanng the sector unreadable , can-use the track following to each side will be attempted if a read fails lines. They
. read a special .
· · the
, and whether zer? page o f d i
' s k
:mory, called REYCNT . It is located at $6A hexadecimal ($6A hexadecimal = 6 x 16
+JO= 106) .
110 OPEN 15,8, 15 ilO PRINT#l5 , "M-R"CHR$(106)CHR$(0)
130 GET#l5 ,G$ : LF G$= ''''THEN G$=CHR$(0)
Open command channel
Same as G = PEEK( I 06)
140 G = ASC(G$)
!So B =G AND 128:B$= "ON" : IF B THEN B$= "OFF" Check bit 7
!60 S = G AND 64 : S$ = "ON":IF S THEN S$ = "OFF" Check bit 6 t70 T = G AND 31 : PRINT "#OF TRIES IS";T
!80 PRINT "BUMPS ARE" ;B$
Check bits 0-5 and give results t90 PRINT "SEEKS ARE" ; S$
ZQOCLOSE 15
210END
Tidy up after
Here's a more general purpose program that reads one or more locations anywhere in disk memory:
110OPENI5 ,8,15
120 INPUT "# OF BYTES TO READ (O= END)";NL
130 IF NL<I THEN CLOSE 15:END
140 IF NL>255 THEN 120
150 INPUT "STARTING AT ADDRESS";AD
160 AH = INT(AD/256) : AL = AD-AH*256
170 PRINT#15 ,"M-R"CHR$(AL)CHR$(AH)
CHR$(NL )
180 FOR I= I TO NL
190: GET# 15,A$:1F A$="" THEN A$= CHR$(0)
200 : PRINT ASC(A$);
210 NEXT I
220 PRINT
230GOTO 120
Open command channel
Enter number of bytes wanted unless done or way out of line
Enter starting address
Convert it into disk form
Actual Memory-Read
Loop til have all the data printing it as we go
Forever
ALTERNATE FORMAT:
PRINT# I 5, "M-R: "CHR$( <address)CHR$(>address)CHR$( # of bytes)
'The next byte read using the Get# statement through channel #15 (the error channel), will be from that address in the disk controller's memory, and success~ve byte s will be from successive memory locatjons .
Any
lnput#
from the error channel will give peculiar results when you're uiing thi s command . This can be cleared up by sending any other command to the disk, ex c ept another memory command.
74
MEMORY-WRITE
The Memory-Write command is the equivalent of the Basic Poke command'. but has its effect in disk memory instead of within the computer. M-W allows you to wnte up to l4 bytes at a time into disk memory. The Memory-Execute and some User commands can be Used to run any programs written this way.
75
FORMAT FOR THE MEMORY-WRITE COMMAND:
~MORY-EXECUTE
PRINT# 15,' ' M-W' ' CHR$( <address)CHR$(>address)CHR$
(#of bytes)CHR$(data byte(s)) where "<address" is the low order part, and ">address" is the high order part f address in disk memory to begin writing, "# of bytes" is the number of m o the
I . h · 11 . emory oc.allon
.
s t at .
w1 be wntten (from 1-34), and "data byte" is I or more byte values to wntt~n
.mto disk memory, each as a CHR$() value . If desired, a colon( : ) may follow be
M
W wl!hm the quotation marks . ·
Any routine in disk memory, either in RAM or ROM, can be executed with the
\fclllory-Execute command. It is the equivalent of the Basic Sys call to a machine
IJll8uage program or subroutine, but works in disk memory instead of within the com p0ter. f()RMAT FOR THE MEMORY-EXECUTE COMMAND :
PRINT#15 , ''M-E''CHR$(<address)CHR$(>address)
ALTERNATE FORMAT :
PRINT# 15 ,' 'MW :' ' CHR$( <address )CHR$( >address )CHR$
(#of bytes)CHR$(data byte(s))
*'1Cre "<address" is the low order part, and ">address" is the high order part of the address in disk memory at which execution is to begin .
ALTERNATE FORMAT:
EXAMPLES :
PRINT# 15 , "M-E:' ' CHR$( <address)CHRS(>address)
We can use this line to tum off the
"bum~s" w~en
loading DOS-protected
program
~
(i.e., prog:ams . that have been protected agamst bemg copied by creating and checkin g for specific disk errors) .
EXAMPLE :
PRINT# 15 , " M-W"CHR$( 106)CHR$(0)CHR$( I )CHR$( 133)
Here is a Memory-Execute command that does absolutely nothing. The first instruction it executes is an RTS, which ends the command:
The following line can be used to recover bad sectors, such as when an important file has been damaged and cannot be read normally .
PRINT# 15,' 1 M-W " CHR$( I 06)CHR$(0)CHR$( I )CHR$(3 I)
. The above two examples may be very useful under some circumstances . They are the
~q~1valent
ms1de the of POKE I 06 ,
13~ and '.0KE I 06,31 respectively, but in disk memory , not
c?mput~r
.
As mentioned m the previous section's first example, location 106 in the 1541 d1 .s
k dnve signifies three separate activities to the drive, all related to error recov .
ery ·.
BI! 7 (the high bit), if set means no bumps (don't thump the drive back to track
I). Bit 6, if set, means no seeks . In that case, the drive won ' t attempt to read the half -track a?<>ve and below the assigned track to see if it can read the data that way . The bottom 6 bi!~ are the count of how many times the disk will try to read each sector before and after trymg see~s an~ bumps before giving up. Since 31 is the largest number that can be expressed m 6 bits, that is the maximum number of tries allowed .
Fro~ this example, you can see the value of knowing something about Peeks , Pokes,
~nd machme-language before using direct-access disk commands, as well as their poten llal power.
PRINT# 15, "M-E"CHR$(88)CHR$(242)
A more plausible use for this command would be to artificially trigger an error message .
Don't forget to check the error channel, or you'll miss the message:
PRINT#15 ,'' M -E'' CHR$(201)CHR$(239)
However , most uses require intimate knowledge of the inner workings of the DOS, and preliminary setup with other commands, such as Memory-Write.
BLOCK-EXECUTE
This rarely-used command will load a sector containing a machine language routine into a memory buffer from diskette, and execute it from the first location within the buffer, until a ReTum from Subroutine (RTS) instruction ends the command .
FORMAT FOR THE BLOCK-EXECUTE COMMAND:
PRINT#l5 , "B-E";channel # ; drive #;track #;sector#
~re
" is the channel number specified when the file into which the block
\\ill be loaded was opened, " drive#" is the drive number (always 0
"track #" and "sec tor# " are respectively the track and sector numbers containing the desired block of data to be loaded into the file buffer and executed there .
76
77
ALTERNATE FORMATS : fORMAT FOR USER COMMANDS :
PRINT#l5
PRINT#15,
,"
"
B-E:
B-E
";c
:c hannel # hannel # ,
; drive # ;track # ;s ector# drive #,track #,sector#"
PRINT#l5 , " Ucharacter"
\Where " character" defines one of the preset user commands listed above .
EXAMPLES :
As s uming you 've written a machine language program onto Track 1, Sector 8 of a diskette , and would like to run it in buffer number 1 in disk memory (starting at $0400 hexadecimal , you could do so as follows :
E)(AMPLES :
PRINT#l5, " U:"
PRINT#15 ," U3"
Preferred form of DOS RESET
Execute program at command start of buffer 2
110 OPEN 15,8,15
120 OPEN 2 , 8,2 , "# "
130 PRINT#l5, " B E ";2; 0 ; 1 ; 8
140 CLOSE 2
150 CLOSE 15
160END
Open command channel
Open direct access channel to buffer I
Load Track 1 , Sector 8 in it & execute
Tidy up after
USER COMMANDS
Most User commands are intended to be used as machine language JMP or Basic
SYS commands to machine language programs that reside inside the disk m emory.
However, some of them have other uses a s well . The Userl and User2 commands are used to replace the Block-Read and Block-Write commands, UI re-starts the 1541 without changing its variables , UJ cold-starts the 1541 almost as if it had been turned off and on again, and UIspeeds up the 1541 when used with the VIC 20 only . (Note : VIC 20 owners don ' t have to use UI-; the 1541 works with the VIC 20, with or without this comm and .)
User Command
Ul or UA
U2 orUB
U3 or UC
U4 or UD
US or UE
U6 or UF
U7 orUG
U8 or UH
U9 or UI
U: or UJ
Ul+
UI-
Function replaces Block-Read replaces Block-Write
JMP $0500 (same as SYS 5*256 , but within the 1541 itsel f.)
JMP $0503 (SYS 5*256 + 3)
JMP $0506 ( " 5*256 + 6)
JMP $0509 ( " 5 * 256 + 9)
JMP $050C (" 5*256+ 12)
JMP $050F ( "5*256+ 15)
1541 NM! (non-maskable intelTUpt-warm start)
1541 reset (cold start, allow 2 seconds before next comman d .) restore 1541 to usual speed speed 1541 up by 25% when used with VIC 20 only .
By loading these memory locations with another machine language JMP com mand. such as JMP $0520 , you can create longer routines th~t operate in the disk's m emorY along with an easy to-use jump table.
78
79
CHAYI'ER 9
MACHINE LANGUAGE PROGRAMS
.
Here is a list of disk-related Kemal ROM subroutines and a practical example of the ' h ' h
. Note that mos t require advance setup of one or more processor registers or memory locations , and all are called with the assembly language JSR command .
For a more complete description as to what each routine does and how paramet ers ar set for each routine, see the Programmer's Reference Guide for your specific compu ter . e
Label
SETLFS
SETNAM
OPEN
CLOSE
CHKIN
CHKOUT
CLRCHN
CHRIN
CHROUT
START
NEXT
END
FNADR
DISK-RELATED KERNAL SUBROUTINES
Address
SFFBA
SFFBD
SFFCO
SFFC3
$FFC6
$FFC9
SFFCC
SFFCF
$FFD2
Function
; SET LOGICAL , FIRST & SECOND ADDRE SSES
; SET LENGTH & ADDRESS OF FILENAME
; OPEN LOGICAL FILE
; CLOSE LOGICAL FILE
; SELECT CHANNEL FOR INPUT
; SELECT CHANNEL FOR OUTPUT
; CLEAR ALL CHANNELS & RESTORE
DEFAULT UO
;GET BYTE FROM CURRENT INPUT DEVI CE
;OUTPUT BYTE TO CURRENT OUTPUT
DEVICE
JSR
LOX
JSR
JSR
BEQ
JSR
JMP
LDA
LOX
LOY
JSR
LOA
LOX
LOY
JSR
#4 ; SET LENGTH & ADDRESS
#<FNADR ;OF FILE NAME , LOW
#>FNADR ;& HIGH BYTES
SETNAM ;FOR NAME SETTER
#3
#8
#0
;
;SET FILE NUMBER,
DISK DEVICE NUMBER,
SETLFS
OPEN
#3
CHKIN
;AND SECONDARY ADDRESS
;AND SET THEM
;OPEN 3,8 , 0 , "TEST"
;SELECT FILE 3 FOR INPUT
CHRIN
END
; GET NEXT BYTE FROM FILE
; UNTIL FINISH OR FAIL
CH ROUT ; OUTPUT BYTE TO SCREEN
NEXT ; AND LOOP BACK FOR MORE
LOA
JSR
JSR
RTS
#3
CLOSE
;WHEN DONE
; CLOSE FILE
CLRCHN ; RESTORE DEFAULT UO
;BACK TO BASIC
.
BYT ' 'TEST' ' ; STORE FILE NAME HERE
APPENDIX A: CHANGING THE DEVICE NUMBER
oFTWARE METHOD
The preferred way to temporarily c hange th e device number o f a di s k driv e i s vi a a program . When power is first turned on , the drive reads an UO location whose value i s controlled by a jumper on it s circuit board, and writes the de v ic e number it read s there int
0 rnemory location s 119 and 120 . Any time thereafter , you may write over that devi ce number with a n e w o ne, which will be effective until it is changed again , or the 1541 is reset .
FORMAT FOR TEMPORARlL Y CHANGING THE DISK DEVICE NUMBER :
PRINT# 15, ' 'M-W ' 'CHRS( I I 9)CHR$(0 ) CHR$(2)CHR$
(device# + 32)CHR$(device # + 64 )
EXAMPLE :
Here is a program that set s any device number from 8 11 :
10 INPUT' NEW DEVICE NUMBER' ; DY
20 IF DY < 8 OR DY > 11 THEN 10
3()0PEN 15 , 8 , 15
40PRINT#15,' 'M W ' ' CHR$ ( l l 9)CHR$(0)CHR$ ( 2 ) CHR$(DY + 32)CHRS ( DY + 64 )
50CLOSE 15
Note: If you will be using two disk drives, and want to temporarily change the devi ce numb e r of one, you will need to run the above program with the disk drive who ~e d ev i ce number i s not to be changed turned off . After the program ha s been run , y ou m ay turn that drive back on . If you need to connect more than two drive s at on ce. y o u wi ll need to u s e the hardware method of changing device number s, althou g h yo u m ay be a ble to get by in an emergency by unplugging the s erial bu s cabl e fr o m dri v e s who s e device number has already been set while changing other s.
Thi s i s n o t re co mm e nded , however , as there is always danger of damaging el ec troni c d ev i c e s wh e n plu gg ing in cable s with the power on . llARDW ARE METHOD
-
IMPORT ANT: Using the following method to change the device number will void
._ the 1541 Disk Drive warranty!
81
80
If you have more than one drive, either you or preferably your dealer may penna. nently change the address of all after the first , to avoid having to run the program on the previous page before each use of multiple drives . The only tools needed to mak e the change are a Phillips-head screwdriver and a sharp knife .
PENDIX B: DOS ERROR MESSAGES AND LIKELY CAUSES
I '
STEPS TO CHANGE THE DEVICE NUMBER ON HARDWARE l. Disconnect all cables from drive, including power.
2 . Tum drive upside down on a Hat, steady surface .
3. Remove 4 screws on bottom that hold drive cover together.
4 . Carefully tum drive right side up, and remove case top .
5 . Remove 2 screws on side of metal housing covering the main circuit board .
6. Remove housing.
7 . Locate the two device number jumpers. They will be small round silvery spots
(solder pads) on the main circuit board , located close .
together, each cut ne arly in half, and will be the only such jumpers on the board . On current 1541 's, th ey are located near the front of the drive, in the middle, by resistors R32 and R36 , capacitor
C46, and transistor Q3, all of which are named on the board . On older 1541 's with white cases , they were located in the left rear of the board, to the left of UA B 1 , a
6522 VIA chip. In each case, Jumper 1 is toward the rear, and Jumper 2 tow ard the front of the drive .
8 . Following the chart below , decide which jumper(s) to cut.
Note: Many commercial program diskettes are intentionally created with one or more of the following errors, to keep programs from being improperly duplicated .
If a disk error occurs while you are ma.king a security copy of a commercial progr am diskette , check the program 's manual. If its copyright statement does not permit purchasers to copy the program for their own use , you may not be able to duplicate the diskette. In some such cases, a safety spare copy of the program diskette is available from your dealer or directly from the company for a rea so nable fee.
00: OK (not an error)
This is the message that usually appears when the error channel is checked . It means there is no current error in the disk unit.
01: FILES SCRATCHED (not an error)
This is the message that appears when the error channel is checked after using the
Scratch command . The track number tells how many files were erased.
Device#
9
JO
11
Jumper I cut cut
Jumper 2 cut cut
NOTE: If any other error message numbers less than 20 ever appear, they may be ignored . All true errors have numbers of 20 or more .
9 . Make the cut by completing the cut already nearly separating the two halves of the selected jumper(s).
JO. Replace the metal housing and its 2 screws .
11 . Replace case top, carefully tum drive upside down, and tighten 4 case screw s .
12. Re-connect cables and power up .
20: READ ERROR (block header not found)
The disk controller is unable to locate the header of the requested data block .
Cau sed by an illegal block , or a header that has been destroyed . Usually unrecoverable.
21: READ ERROR (no sync character)
The disk controller is unable to detect a sync mark on the desired track .
Caused by misalignment, or a diskette . that' is absent, unformatted or improperly seated. Can also indicate hardware failure. Unless caused by one of the above simple causes, this error is usually unrecoverable.
Note: If you make a mistake , perhaps cutting the wrong jumper , or your n eeds change later, a cut jumper can be restored with a small dot of electrical sold er.
However, do not attempt this yourself unless you are already skilled at electro nic soldering.
22: READ ERROR (data block not present)
The disk controller has been requested to read or verify a data block that wa s not properly written . Occurs in conjunction with Block commands and indicates an illegal track and/or sector request .
23·
READ ERROR (checksum error in data block)
There is an error in the data. The sector has been read into disk memory , but its checksum is wrong . May indicate grountling problems . This faU:ty minor error is often repairable by simply reading and rewriting the sector with direct access commands.
82 83
24:
25 :
26 :
29:
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 probl e rn s.
SYNTAX ERROR (invalid command)
The DOS does not recognize a command sent to the command channel (secondary address 15). Check your typing and try again.
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 . lJse only high quality diskettes from reputable makers .
,o: RECORD NOT PRESENT
The requested record number has not been created yet. This is not an error in a new relative file or one that is being intentionally expanded . It results from reading past the last existing record, or positioning to a non-existent record number with the
Record# command.
WRITE PROTECT ON
The controller has been requested to write a data block while the write pr o t ec i sensor is covered. Usually caused by writing to a diskette whose write prote c t n o t c h is covered over with tape to prevent changing the diskette's contents .
51:
OVERFLOW IN RECORD
The data to be written in the current record exceeds the record size. The excess has been truncated (cut off). Be sure to include all special characters (such as carriage returns) in calculating record sizes .
27 : READ ERROR (checksum error in header)
The controller detected an error in the header bytes of the requested data block . Th e block was not read into disk memory. May indicate grounding problems . U s u a ll y unrecoverable.
52:
28 : WRITE ERROR (long data block)
The controller attempts to detect the sync mark of the next header after writ i ng a data block. If the sync mark does not appear on time, this error mes s a g e is generated . It is caused by a bad diskette format (the data extends into the next block) or by a hardware failure.
60:
FILE TOO LARGE
There isn't room left on the diskette to create the requested relative record.
To avoid this error, create the last record number that will be ~eeded as . you first create the file. If the file is unavoidably too large for the diskette, either split it into two files on two diskettes, or use abbreviations in the data to allow shorter records.
WRITE FILE OPEN
A write file that has not been closed is being re-opened for reading. This file must be immediately rescued, as described in Housekeeping Hint #2 in Chapter 4 , or it will become a splat (improperly closed) file and probably be lost.
30:
DISK ID MISMATCH
The disk controller has been requested to access a diskette which has not been initialized . Can also occur if a diskette has a bad header.
61:
SYNTAX ERROR (general syntax)
The DOS cannot interpret the command sent to the command channel. Typi ca ll y. this is caused by an illegal number of file names, or an illegal pattern. Check y our typing and try again .
62:
FILE NOT OPEN
A file is being accessed that has not been opened by the DOS. In some such cases no error message is generated. Rather the request is simply ignored .
FILE NOT FOUND
The requested file does not exist on the indicated drive . Check your spelling and try again .
31 : SYNTAX ERROR (invalid command)
The DOS does not recognize the command. It must begin with the first ch a ra c t e r s ent. Check your typing and try again.
6
3:
FILE EXISTS
A file with the same name as has been requested for a new file already exists on the diskette. Duplicate file names are not allowed . Select another name .
32: SYNTAX ERROR (invalid command)
The command sent is longer than 58 characters. Use abbreviated disk comm a nd s. 64:
33: SYNTAX ERROR (invalid file name) .
Pattern matching characters cannot be used in the Save command or when O pe nin g files for the purpose of Writing new data. Spell out the file name. 6S:
FILE TYPE MISMATCH
The requested file access is not possible using files of the type named . Reread the chapter covering that file type .
34 : SYNTAX ERROR (no file given) h
The file name was left out of a command or the DOS does not recognize it a s s u e ·
Typically, a colon(:) has been omitted . Try again.
NO BLOCK .
Occurs in conjunction with B-A. The sector you tried to allocate is already allocated . The track and sector numbers returned are the next hi~her track and sector available. If the track number returned is zero (0) , all remaining s ectors are full. If the diskette is not full yet , try a lower track and s ector.
84
85
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 .
pENDIX C: DISKETTE FORMATS
67 : ILLEGAL SYSTEM TOR 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 max imum of three sequential files or one relative file plus one sequential file may be open ed at one time, plus the command channel. Do not omit the drive number in a sequ en ti al
Open command, or only two sequential files can be used . Close all files as soon as you no longer need them .
71: DIRECTORY ERROR
The BAM (Block Availability Map) on the diskette does not match the copy in disk memory. To correct , Initialize the diskette .
72: DISK FULL
Either the diskette or its directory is full. DISK FULL is sent when 2 block s are still available, allowing the current file to be closed. If you get this message and th e directory shows any blocks left, you have too many separate files in your dire ctory, and will need to combine some, delete any that are no longer needed, or cop y some to another diskette .
0
73 : DOS MISMATCH (CBM DOS V2 .
6 1541)
If the disk error status is checked when the drive is first turned on , be fore a directory or other command has been given, this message will appear . In that use, it is not an error, but rather an easy way to see which version of DOS is in u se . If the message appears at other times, an attempt has been made to write to a disk ette wi th an incompatible format , such as the former DOS I on the Commodore 2040 disk drive . Use one of the copy programs on the Test/Demo diskette to copy the d esi red file(s) to a 1541 diskette .
74 : DRIVE NOT READY
An attempt ha s been made to access the 1541 single disk without a form atted diskette in place. Blank diskettes cannot be used until they have been form atted .
I
I
I
I
I
~
I
HUU
M.KI
1 1 llUll
UKI
CIUUU tlt 1 0
UIUI
T
......
I t It Uf t UUUll UIUC1ll ltll
1111111 . . . . . . .
..
'"'
IUIU lllC
UI U.U tlll
UKl
"
IH
Nitllnll
Ull t l Kl
IOI lnl
NOTE
\
\
\
\
Not
to ,cak
\
~
1 01
'"'
1 111 ..
1541 Format: Expanded View of a Single Sector
87
86
1541 BAM FORMAT
Track 18, Sector 0.
BYTE CONTENTS DEFINITION
0,1
2
3
4-143
18,01
65
0
Track and sector of first directory block.
ASCII character A indicating 1541/4040 format.
Null flag for future DOS use .
Bit map of the available blocks in tracks 1-35.
I - available block
0 = block not available (each bit represents one block)
-
-
PROGRAM FILE FORMAT 1541 BLOCK DISTRIBUTION BY TRACK
Track number
I to 17
18 to 24
25 to 30
31 to 35
Range of Sectors
0 to 20
0 to 18
0 to 17
0 to 16
Total# of Sectors
----
21
----
19
18
17 ---
DEFINITION pYTE f!RST SECTOR
O, I z.3
4-255
_ \rack and sector of next block in program file .
Load address of the program
Next 252 bytes of program information s tored as in computer memory (with key words tokenized) .
REMAINING FULL SECTORS
O, l
2-255
Track and ector of next block in program file .
Next 254 bytes of program info stored as in computer memory
(with key words tokenized) .
FINAL SECTOR
0,1
2-?
??
Null ($00), followed by number of valid data byte s in sec tor.
La s t bytes of the program information , stored as in computer memory (with key words tokenized) . The end of a Ba ic file is marked by 3 zero bytes in a row . Any remaining bytes in the sec tor are garbage, and may be ignored .
BYTE
144-159
160-161
162-163
164
165-166
167-170
170-255
1541 DIRECTORY HEADER
Track 18, Sector 0.
CONTENTS
160
160
50,65
160
0
DEFINITION
Diskette name padded with shifted spaces .
Shifted spaces.
Diskette ID.
Shifted space
ASCII representation of 2A, which are, respectively , the DOS version (2) and format type (1541/4040).
Shifted spaces .
Nulls ($00), not used .
SEQUENTIAL FILE FORMAT
BY TE
DEFINITION
ALL BUT FINAL SECTOR
0-1
2-255
Track and sector of next sequential data block .
254 byte s of data .
FINAL SECTOR
0,1
2-??
?
Null ($00), followed by number of valid data byte in sec tor.
Last bytes of data . Any remaining byte s are garbage and may be ignored .
89 88
1541 RELATIVE FILE FORMAT
BYTE
DATA BLOCK
DEFINITION
0
2 -
, 1
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) .
SIDE SECTOR BLOCK
0 1
2
3
4-5
6-7
8 9
10-11
12 13
14-15
16-255
Track and sector of next side sector block .
Side sector number (0-5)
Record length
Track and sector of first side sector (number O)
Track and sector of second side sector (number 1)
Track and sector of third side sector (number 2)
Track and sector of fourth side sector (number 3)
Track and sector of fifth side sector (number 4)
Track and sector of sixth side sector (number 5)
Track and sector pointers to 120 data blocks .
-
1541 DIRECTORY FILE FORMAT
Track 18, Sector 1.
DEFINITION
BYTE
0,1
2-31
34-63
66-95
98-127
130-159
162-191
194-223
226-255
Tra c k and sector of next directory block
File entry I *
File entry 2 *
File entry 3 *
File entry 4*
File entry 5 *
File entry 6 *
File entry 7*
File entry 8*
.
*STRUCTURE OF EACH INDIVIDUAL DIRECTORY ENTRY
DEFINITION
BYTE CONTENTS
0
1 2
3-18
19-20
21
22 25
26-27
28-29
128
+ type
File type OR ' ed with $80 to indicate properly c lo se d fil e.
( ifOR ' ed with $CO inst e ad , fil e is locked .)
TYPES : 0 = DELet e d
1 = SEQuential
2 = PROGram
3 = USER
4 = RELative
Track and sector of fir s t data blo c k .
File name padded with shifted space s.
Relativ e file only : track and se ctor of fir s t s id e s e c tor block.
Relative file only : Re c ord length .
Unu s ed .
Track and sector of repla c em e nt file
~uring an
@ SA VE or @ OPEN .
Number of blocks in file : st o r e d as a tw o byt e int ege r , in low byte, high byt e order.
91
90
~
APPENDIX D: DISK COMMAND QUICK REFERENCE CHAR
l
General Form a t: OPEN 15 , 8 , 15 : PRINT#l5,command : CLOSE 15 ( Ba s ic 2 )
HOUSEKEEPING COMMANDS
BASIC 2 NEW
C OPY
RENAME
SCRATCH
INITIALIZE
VALIDATE
" NO : di s kette name , id "
" CO : new file = O : old file "
" RO : new name = old name "
" SO : fil e name "
" IO "
'' VO "
BASIC 3.
5 NEW
COPY
RENAME
SCRATCH
VALIDATE
HEADER
COPY "o l
" d di s file kette name
" TO " n e
, " lid w file
, DO
"
RENAME " old name " TO " new name "
SCRATCH " file name"
COLLECT
BOTH INITIALIZE " IO "
FILE COMMANDS
BASIC 2 LOAD
SAVE
LOAD ' ' file name " , 8
SA YE " O : fil e n a me " ,8
BASIC 3 .
5 LOAD
SAVE
DLOAD " file name "
DSA YE "file name "
BOTH CLOSE
GET#
INPUT#
OPEN
PRINT#
RECORD#
CLOSE file#
GET#file # , variable list
INPUT#file # .
variable li s t
OPEN file # , 8 , channel # , "O : file name .
file type.direction
''
PRINT#file # , data list
" P " +CHR$ ( channel #)+CHR$ (< record # )
+ CHR$ (> record # ) + CHR$(offset )
DIRECT ACCESS COMMANDS
BLOCK ALLOCATE
BLOCK EXECUTE
BLOCK FREE
BUFFER POINTER
BLOCK READ
BLOCK WRITE
MEMORY EXECUTE
MEMORY READ
MEMORY WRITE
USER
"B A" ; O ; track # ;s ector#
" B E "; channel # ; O ; track # ;s ector #
" B-F " ;O;track # ; sector#
" B-P "; channel # ; byt e
" UI "; channel # ; O ; track # ;se ctor#
" U2 "; channel # ; O ; track # ;s ector#
'' M-E' 'CHR$(
< add~s s )CHR$( > address)
'' M R' 'CHR$( <address ) CHR$( > address)CHR$( # of byt es)
''M W " CHR$( <address)CHR$( > address)CHR$ ( # of by tes)
CHR$ (data byte)
" Ucharacter "
9 2
APPENDIX E: TEST /DEMO DISKETTE
HOW TO USE
The " HOW TO USE" programs provide brief descriptions of the other programs on the Test/Demo diskette .
THE VIC-20 & C-64 WEDGES
Additional commands are available which allow you to type short instructions to the disk drive. Load and run the VIC-20 WEDGE if you have a VIC; use the C-64
WEDGE if you have a Commodore 64. Using either, you will be able to press backslash
(/) followed by the program name and the RETURN key to load a program; the " /" means load from di s k drive . For example , type " / how to use" to load that program.
Type
">"
or " @ " and then press RETURN to display the current disk error status .
Type
">
$" or "@$" and RETURN to display the directory without erasing the current program.
DOSS.1
The DOS 5. l program is not intended to be loaded directly, but is loaded instead from the program C 64 WEDGE . Its load address is $CC00 hexadecimal .
PRINTER TEST
The PRINTER TEST prints a listing of characters in a form that makes it easy to check the mechanical and electronic capabilities of the printer.
DISK ADDR CHANGE
Use this program to change the device number of the disk drive. It is a soft change-when the system is turned off, the disk drive is reset to its original device number.
VIEW BAM
The VIEW BAM program allows a programmer to examine the contents of the sectors that make up the block availability map (BAM)-the table that DOS uses to identify blocks that ha v e been allocated to the files on that diskette.
CHECK DISK
The CHECK DISK program can be used to make sure a new diskette that has been headered is in fact a good diskette. The program writes to every block to verify its ability to store information and identifies any diskette that contains a bad block . Don ' t use such diskettes .
DISPLAYT&S
The DISPLAY T&S program allows a programmer to examine the c ontent s of a block by specifying the particular track number and sector number that identifie s that block .
PERFORMANCE TEST
The PERFORMANCE TEST program tests the electronic and me c hanical capabilities of the disk drive whenever necessary . Use this program whenever you s uspect there may be damage to the drive .
93
SEQ.FILE.DEMO AND REL.FILE.DEMO
These two files are included as programming examples or guidelines when wr iting your own programs . They also illustrate the important technique of checking the er ror channel after each access to the disk drive.
SO.BACKUP .xx
These three programs are entitled SD.BACKUP
.
C64, SD.BACKUP.Cl6, an d
SD .
BACKUP .
PLUS4 . Each , when lo~ded into its respective computer, allows you to crea te an exact duplicate of a diskette by switching a blank diskette and the diskette to be copied in and out of the drive at the appropriate times . Loading and running th em incorrectly may damage a diskette.
PRINT .xx. UTIL
These three programs are actually entitled PRINT.64
.
UTIL, PRINT.+4 , a nd
PRINT .
Cl6 .
UTIL. They provide two functions : a printout of any Text-Mode scre en display, and a listing of the contents of all scaler (non-array ) v ariables in a Basic p rogram to screen or printer. Any CBM printer may be used for either fun c tion . Printing of reverse-video and graphics characters depends on the specific printer model used . Th ese programs can run from tape.
C64 BASIC DEMO +4 BAS I C DEMO
These programs offer a set of demo routines which can perform minimal sy stem testing on the computers . Routines are provided for testing the video and sound outpu t, keyboard and joy stick input, and . disk unit 1/0 .
LOAD ADDRESS
LOAD ADDRESS is a simple program that tells you where a program was or iginally located in memory. Some programs can only run in the same locations from wh ich they were saved. Load such programs with LOAD"filename" ,8, 1 .
UNSCRATCH
Allows you to restore a file that's been deleted (scratched) from a diskett e as lo ng as the diskette hasn't been written to since the scratch was performed .
HEADER CHANGE
Allows you to rename a diskette without losing the data currently stored in the diskette.
IMPORT ANT NOTE:
Your Test/Demo diskelle may contain additional programs. Commodore may update the diskette from time to time.
ALL ADDITIONS, DELETIONS, OR MODIFICATIONS TO THE PR O-
GRAMS LISTED IN THIS APPENDIX WILL BE NOTED IN THE "HOW TO
USE" PROGRAMS ON YOUR TEST/DEMO DISKETTE.
94
. ' i i I ~ i f ..
~
1 !\'.!
Commodore offers a complete line of peripherals and accessories for other new and exciting applications.
Dot Matrix Printers
Commodore manufactures printers designed to fit almost any type of application
.
These include a variety of high-speed
,
dot matrix printers for business applications and graphics printers for general and highresolution printing for graphics packages such as LOGO. Enhance your system today with the addition of a quality printer from Commodore
.
Color Monitors
Commodore monitors
,
designed specifically for Commodore computers
,
provide superior resolution compared to most television sets or other video monitors. They come complete with video adjustment controls and a speaker with volume control.
Accessories
Modems
A Commodore modem allows your computer to communicate with other computers via standard telephone lines
.
Information may be instantly obtained including timely financial information
,
news and reference libraries
.
Turn your ordinary phone into a telecomputing information network.
Joysticks and Game Paddles
Increase your video game skills with the addition of a Commodore joystick or game paddle
.
Commodore Diskettes
To ensure maximum performance from your 1541 disk drive
,
use quality
Commodore diskettes.
Software
Get more from your computer with Commodore Software. Whether it's productivity
,
educational or recreational, Commodore offers a complete line of software at affordable prices.
Commodore has a variety of other products available for your particular system. See your dealer for more details
.
(::commodore
CO
MPUTERS
Commodore Business Machines, Inc.
Computer Systems Division
1200 Wilson Drive
,
West Chester
,
PA 19380
Printed in Japan P
/
N 1540031-03
डाउनलोड
विज्ञापन