Commodore 2040, 3040, 4040, 8050 User Manual
Commodore 3040 is a dual-drive floppy disk storage device designed for Commodore computers. With its IEEE-488 interface, it seamlessly integrates with your system and offers intelligent peripheral capabilities, meaning it doesn't take up computer memory. The front panel features LED indicators, diskette slots, and doors for secure diskette loading. On the back panel, you'll find the power switch, fuse, and an interface connector for connecting to your computer.
Advertisement
Advertisement
User's Manual
for
CBM 5Y4-inch
Dual
Floppy
Drives
Disk
ell
commodore
User's Manual for
CBM Dual Drive
Floppys
Model 2040-Model 4040
Model 3040-Model 8050
Appropriate for use with:
Commodore Computers
• Series 2001 (CBM-PET)
• Series 3000
CBM)
• Series 4000 PET)
• Series 8000
CBM)
Part Number 320899
October 1980
(I[
commodore
© 1980 Commodore Business Machines, Inc.
Table of Contents
Chapter 1
Chapter 2
Chapter 3
Page
Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1
General Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3
Front Panel 3
Back Panel
Interior Configuration
The Diskette . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5
Specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5
3
4
Care Of The 2040, 3040, 4040 and 8050 . . . . . . . . . . . . . . . . . . . .
9
Care Of The Diskettes
Unpacking The Disk Drive
9
9
Preparing To Use Your Disk Drive 11
Connecting The Disk Drive To The Computer
Performing The Power-On Test
11
12
Inserting The Diskette Into The 8050 13
Inserting The Diskette Into The 2040, 3040 and 4040 ..
13
The 4040 and 8050 Performance Test 14
The 2040 and 3040 Performance Test 17
Learning How To Use Your Floppy Disk Drive
The Block Availability Map (BAM)
21
22
The Disk Operating System (DOS) , 22
Disk Maintenance Commands. . . . . . . . . . . . . . . . . . . . . . . . . . . ..
23
NEW 24
HEADER (BASIC 4.0 Direct Command) . . ..
25
Initialization (2040 and 3040) . . . . . . . . . . . . . . . . . . ..
25
Initialization (4040) . . . . . . . . . . . . . . . . . . . . . . . . . . ..
26
Initialization (8050) . . . . . . . . . . . . . . . . . . . . . . . . . . ..
26
The Directory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ..
26
LOAD$ 26
DIRECTORY (BASIC 4.0 Direct Command).
27
Printing The Directory. . . . . . . . . . . . . . . . ..
27 iii
IV
Chapter 4
Chapter 5
Chapter 6
VALIDATE..................................
28
COLLECT (BASIC 4.0 Direct Command). . ..
28
DUPLICATE 28
BACKUP (BASIC 4.0 Direct Command). . . ..
29
COpy 29
COpy (BASIC 4.0 Direct Command) . . . . . ..
31
RENAME
CONCAT (BASIC 4.0 Direct Command). . . ..
31
31
SCRATCH
RENAME (BASIC 4.0 Direct Command) . . ..
32
32
SCRATCH (BASIC 4.0 Direct Command). . ..
33
BASIC Commands For Data Handling 35
BASIC Commands Associated with Floppy Disk Drives . . . . . . . ..
35
SAVE and DSAVE (Writing a Program to a Diskette) . ..
36
LOAD and DLOAD (Reading a Program from a
Diskette) 36
VERIFy.....................................
37
OPEN
DOPEN
38
39
CLOSE......................................
39
DCLOSE 40
Closing The Command Channel
Closing The Data Channel
40
41
. ..
PRINT# . . . . .. .. .. . . .. . . . . . . .. .. ..
INPUT#
GET#
41
42
43
RECORD# 43
Quickload Feature (BASIC 4.0) .. . . . . . . . . . . . . . . . . . . . . . . . ..
44
Moving a Tape Program to Disk 45
Advanced Disk Programming
Commodore Disk Operating System (DOS)
47
47
Disk Utility Command Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ..
48
BLOCK-READ................................
49
BLOCK-WRITE. . . . . . . . .. .. .. . . .. . . .. .. .. . . . ..
50
BLOCK-EXECUTE 50
BUFFER-POINTER . . . . . . . . . . . . . . . . . . . . . . . . . . ..
50
BLOCK-ALLOCATE
MEMORy
" .. . . . . . . . . . . . . .. . ..
51
51
MEMORY-WRITE 51
MEMORY-READ. . . . . . . . . . . . . . . . . . . . ..
52
MEMORY-EXECUTE 52
USER.......................................
52
8050 Disk Zones 59
Advanced File Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ..
65
Special Open and Close Statements For Direct Access . . . . . . . . ..
65
Random Access Example . . . . . . . . . . . . . . . . . . . . . . ..
66
To Create A File . . . . . . . . . . . . . . . . . . . . . ..
66
To Add A Record. . . . . . . . . . . . . . . . . . . . ..
67
To See A Record 68
To Change A Record 68
Getting The Directory of Listings . . . . . . . . ..
69
Table
10
11
12
8
9
6
7
4
5
1
2
3
Chapter 7
Chapter 8
Chapter 9
Chapter 10
Ending The Program . . . . . . . . . . . . . . . . . . ..
69
Relative Files 4040, 8050 . . . . . . . . . . . . . . . . . . . . . . ..
69
Creating A Relative File .. . . . . . . . . . . . . . . . . . . . . . ..
72
Expanding A Relative File 72
Accessing A Relative File . . . . . . . . . . . . . . . . . . . . . . ..
73
Simplifying The Use of Commodore Disk-Related Commands. . . . . . ..
77
Loading The DOS Support Program . . . . . . . . . . . . . . . . . . . . . . ..
77
Using The DOS Support Symbols:
> and
@ . . • • . • • . • . • . • • . • .•
78
Loading A Program With The 1 . . . . . . . . . . . . . . . . . . . . . . . . . . ..
78
Loading And Running A Program With Up Arrow .. . . . . . . . . . ..
79
Special DOS Support Information 79
Error Messages - Pattern Matching File Names - Disk Commands. . . ..
81
Requesting Error Messages: Commodore Disk Drives. . . . . . . . . ..
81
Summary Of CBM Floppy Error Messages
Description of DOS Error Messages
82
82
Pattern Matching 85
User's Quick Reference: Disk Commands. . . . . . . . . . . . . . . . . . ..
86
Random 1.00 Program Listing
Index , . . . . . . . . . . . . . . . ..
89
95
Figure
3
4
5
1
2
List of Illustrations
Title
Models 2040, 3040, 4040, 8050: Rear View
Floppy Disk Hookup
Position For Diskette Insertion
2040,3040,4040 Format: Expanded View of A Single Sector
8050 Format: Expanded View of A Single Sector
Page
5
12
13
62
63
List of Tables
Title Page
Suggested Reading List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4
Specifications: Model 8050 Dual Drive Floppy Disk
Specifications: Models 2040/3040 Dual Drive Floppy Disk. . . . . . . . . .
6
7
Specifications: Model 4040 Dual Drive Floppy Disk 8
Standard Jump Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ..
53
Block Distribution By Track 54
2040,3040 BAM Format. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ..
55
2040,3040 Directory Header. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ..
55
4040 BAM Format. . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . ..
56
4040 Directory Header. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ..
56
8050 Directory Header Block. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ..
57
8050 BAM Format. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ..
58 v
vi
13
14
15
16
17
Directory Format. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ..
60
Sequential Format
Program File Format
61
61
Relative File Format
User's Quick Reference - Disk Commands
70
87
Chapter
1
INTRODUCTION
The disk-oriented Commodore Computer System was designed around the central concept of providing you, the user, with large file-handling capabilities supported by BASIC programming commands and further simplified by DOS Support command abbreviations.
Read the Table of Contents and become acquainted with the broad scope of material covered in this manual.
It has been designed to assist you in pursuing an educational program by utilizing the computer as an adjunct to the learning process. That is, once the disk drive is properly interfaced to a Commodore Computer, YOU become as important an element of the system as the hardware. Your importance, however, is measured in direct relationship to how well you understand how to effectively utilize the hardware and software.
That's why it is best to think of your computer and disk drive as only part of a system.
Grasping and understanding the concept that each individual component acts and reacts to signals and commands from other devices in the system will greatly accelerate your fundamental grasp of how to operate, control, and master the system. This basic concept forms the basis of this manual: teaching you how to gain mastery of the system so that it will perform as desired. That is the primary reason this manual is laid out in a building block fashion: it permits you to advance as fast as you desire.
The first chapters discuss basic hardware features and permit you, right from the start, to become familiar with the disk drive by doing the performance tests which comprise the first essential "hands on" experience. Then, by actually using your particular disk drive and learning to carefully follow instructions, you can gain confidence in order to proceed to more comprehensive subjects.
By the time you begin Chapter 3-Learning How To Use Your Floppy Disk Drive-you will have already used some portions of the DOS Support system which is not fully described until Chapter 7. The reason for this procedure lies within the purpose of DOS Support: simplifying commands.
It is actually easier to instruct a new user by using the simplified command structure of DOS Support than attempting to explain the entire command hierarchy at an early stage. This concept of providing you with enough essential information to complete a task, a step-by-step description of the task, and meaningful examples is a feature of this manual which will provide you with sufficient incentive to actually complete the task.
1
2
The manner in which this manual is laid out encourages the concept of learning by doing.
Difficult concepts and procedures have been broken down into steps that walk the user through examples which provide ample opportunity to experiment later by returning to each command description. When possible, the command format has been included with the command description and, as an additional aid, a User's Quick Reference has been placed in
Chapter 8 for easy access if problems persist.
Error messages are also presented in Chapter 8 where they can be quickly referenced, if needed. The Error Message discussions have been expanded to include:
• How to request error messages.
• Error message summary.
• Detailed error message descriptions.
For those users who have been reluctant to attempt disk programming because of the presumed degree of difficulty, note that the entire disk command hierarchy is structured in this manual from least difficult to more complex:
• Commands for file manipulation and maintenance
• Commands for data handling
• Advanced programming
• Advanced file handling
• Simplified commands
Users who have attained some degree of programming skills may desire to begin with the advanced subjects such as random access or relative files while others may be content with just following the manual's format. In either case, this manual has been laid out to provide the user with essential information in a logical sequence. Follow the examples, attempt the step-by-step procedures, and learn by doing.
GENERAL INFORMATION
With the purchase of your Commodore Dual Drive Floppy Disk you have greatly enhanced the computing power of your Commodore system. To get the most out of your system you should study your computer's user guide, and if necessary the BASIC manuals listed in
Table 1.
You will benefit most if you first read through this entire manual, taking note of those features that relate to your particular floppy as well as those which are common to all
CBM Floppys.
The information presented in this manual is extensive and may, in some cases, present information that is currently beyond your particular level of expertise. However, by carefully and thoughtfully studying its contents you will gain the confidence necessary to progressively upgrade your programming skills and expertise.
This manual presents discussions, descriptions, practices and procedures relating to the use and operation of all Commodore 5-1I4-inch Dual Floppy Disk Drives.
Four models are discussed:
Model 2040 (DOS 1)
Model 3040 (DOS 1)
Model 4040 (DOS2)
Model 8050 (DOS 2.5)
The floppys are operationally compatible with the following Commodore Computers.
1.
Series 2001 -16K and 32K - Operating With BASIC Version 3.0
2. Series 2001 - PET 8K - Upgraded to BASIC Version 3.0
3. Series 3000 - 16K and 32K - Operating With BASIC Version 3.0
4. Series 4000 - PET 8K, 16K, and 32K - Operating With BASIC Version 4.0
5. Series 8000 - 32K - Operating With BASIC Version 4.0
For ease of reference, the Models 2040, 3040,4040, and 8050 Dual Drive Floppy
Disks will be referred to in this manual as "the 2040", "the 3040", "the 4040", and "the 8050", respectively. All descriptions and discussions are common unless noted otherwise.
DESCRIPTION
All CBM Floppys described in this manual are dual-drive diskette storage devices. Their individual primary components consist of read/write controls, drive motor electronics, two drive mechanisms, two read/write heads, and track positioning mechanisms. All disk drives discussed in this manual conform to IEEE-488 interface requirements. Because each device is an "intelligent" peripheral, their operation requires no space in the computer's memory.
This means you have just as much computer memory available to you as when you do not have the disks attached.
Front Panel
The front panel of the respective disk drive consists of an identification panel across the top; slots in which to insert two diskettes; and doors to close after inserting the diskettes. When the door is closed, the diskette is clamped onto the diskette spindle hub. Also on the front panel are three LED indicator lights. The one on the right is called the Drive 0 Active Indicator, and lights when drive 0 is active. The LED on the left does the same for drive 1.
On the 8050, the LED in the middle is a two-color power/error indicator.
It is normally green, indicating power ON but flashes red whenever a disk error occurs. On the 2040, 3040, and
4040 the middle LED is activated if power is applied or removed, and whenever an error occurs.
Back Panel
The back of each disk drive contains an IEEE-488 interface connector. Near the panel's lower edge is the power ON/OFF switch. There is also a "slow blow" fuse, and the AC power cord.
3
4
Table 1. Suggested Reading List
PetICBM Personal Computer Guide.
C. S. Donahue and J. K. Enger, Osborne/McGraw-Hill, 630 Bancroft Way,
Berkeley, CA 94710
Hands-On Basic with a Pet.
H. D. Peckham, McGraw-Hill, 1979
Entering BASIC.
J. Sack and J. Meadows, Science Research Associates, 1973
BASIC: A Computer Programming Language.
C. Pegels, Holden-Day, Inc., 1973
BASIC Programming.
J. Kemeny and T. Kurtz, Peoples Computer Co., 1010 Doyle (P.O. Box
3100), Menlo Park, CA 94025, 1967
BASIC FOR HOME COMPUTERS.
Albrecht, Finkle and Brown, Peoples Computer Co., 1010 Doyle (P.O. Box
3100), Menlo Park, CA 94025, 1973
A Guided Tour of Computer Programming in BASIC.
T. Dwyer, Houghton Mifflin Co., 1973
Programing Time Shared Computer in BASIC.
Eugene H. Barnett, Wiley-Interscience, LIC 72-175789
Programming Language #2.
Digital Equipment Corp., Maynard, MA 01754
101 BASIC Computer Games.
Software Distribution Center, Digital Equipment Corp., Maynard, MA 01754
What do To After You Hit Return.
Peoples Computer Co., 1010 Doyle (P.O. Box 3100), Menlo Park, CA 94025
Basic BASIC.
James S. Coan, Hayden Book Co., Rochelle Park, NJ
WORKBOOKS 1-5.
T.I.S., P.O. Box 921, Los Alamos, NM 87544
Programming the 6502.
R. Zaks, Sybex, 1978
24 Tested, Ready-to-Run Game Programs in Basic.
K.
Tracton, Tab Books, 1978
Some Basic Programs.
M. Borchers and R. Poole, Osborne & Assoc. Inc., 1978
Basic Programming for Business.
I.
H. Forkner, Prentice-Hall, 1977
The Channel Data Book.
B.
Lewis, 5960 Mandarin Ave., Goleta, CA 93017,1978
PET and the IEEE 488 Bus (GPIP).
Osborne/McGraw-Hill, 630 Bancroft Way, Berkeley, CA 94710
Interior Configuration
The interior of your floppy contains two disk drives. All the logic for the disk drive is contained within the unit. The mechanical devices are, for the most part, located beneath the disk spindles.
The Diskette
The diskette (also known as a minifloppy, floppy diskette, minidiskette, etc.) is similar to the standard flexible disk. There are several reputable manufacturers of the 5 1/4-inch diskettes. You should make sure that you buy diskettes for SOFT SECTORED FORMAT.
Your Commodore dealer can supply your needs.
Specifications
Table 2 presents the specifications for the 8050, Table 3 the specifications for the 2040 and
3040, and Table 4 the 4040.
Figure 1 - Models 2040, 3040, 4040, 8050: Rear View
5
6
Directory entries
Sectors per track
Bytes per sector
Tracks
Blocks
IC's:
Table 2. Specifications: Model 8050 Dual Drive Floppy Disk
STORAGE:
Total capacity
Sequential
Relative
533248 bytes per diskette
521208 bytes per diskette
464312 to 517398 bytes per diskette depending upon file size.
182880 bytes per file
65535 records per file
224 per diskette
23 to 29
256
77
2083
Controller
6502
6530
6522
Interface
6502
6532 (2)
6564 (2)
Shared
6114 (8) microprocessor
I/O, RAM, ROM
I/O, interval timers microprocessor
I/O, RAM, interval timers
RO~v1
4x1K RAM
PHYSICAL:
Material
Dimensions
Height
Width
Depth
ELECTRICAL:
Power requirements
Voltage
Frequency
Power
MEDIA:
Diskettes
18 gao steel
6.5/1
15.0/1
14.35/1
100,117,220, or 240 VAC
50 or 60 Hertz
50 watts
Standard mini 5 single density
1/4", single sided,
Table 3. Specifications: Models 2040/3040 Dual Drive Floppy Disk
STORAGE:
Total capacity
Sequential
Random
Directory entries
Sectors per track
Bytes per sector
Tracks
Blocks
176640 bytes per diskette
170180 bytes per diskette
170850 bytes per diskette
152 per diskette
17
256
35 to 21
690
IC's:
Controller
6504
6530
6522 microprocessor
I/O, RAM, ROM
I/O, interval timers
Interface
6502
6532 (2)
6332 (2) microprocessor
I/O, RAM, interval timers
ROM
Shared
6114 (8) 4xlK RAM
PHYSICAL:
18 gao steel Material
Dimensions
Height
Width
Depth
ELECTRICAL:
6.5"
15.0"
14.35"
Power requirements (2040)
Voltage
Frequency
Power
Power requirements (3040)
Voltage
Frequency
Power
MEDIA:
Diskettes
120
60 Hertz
50
VAC
Watts
100, 220,
60 Hertz
50 Watts or 240 VAC
Standard mini 5 1/4", single sided, single density
7
8
Table 4. Specifications: Model 4040 Dual Drive Floppy Disk
STORAGE:
Total capacity
Sequential
Relative
Directory entries
Sectors per track
Bytes per sector
Tracks
Blocks
IC's:
Controller
6504
6530
6522
Interface
6502
6532 (2)
6332 (2)
174848 bytes per diskette
168656 bytes per diskette
167132 bytes per diskette
65535 records per file
144 per diskette
17 to 21
256
35
683 microprocessor
I/O, RAM, ROM
I/O, interval timers microprocessor
I/O, RAM, interval timers
ROM
Shared
6114 (8)
PHYSICAL:
Material
Dimensions
Height
Width
Depth
ELECTRICAL:
4x1K RAM
18 gao steel
6.5"
15.0"
14.35"
Power requirements (4040) USA (domestic)
Voltage
Frequency
Power
120 VAC
60 Hertz
50 Watts
Power requirements (4040) (international)
Voltage 100,220, or 240 VAC
Frequency
Power
60 Hertz
50 Watts
MEDIA:
Diskettes Standard mini 5 1/4", single sided, single density
CARE OF THE 2040, 3040, 4040 AND 8050
The disk drive should be placed on a flat surface free of vibration.
It is important that dust particles be kept at a minimum since a particle buildup will interfere with optimum operation.
If you should experience a hardware failure contact your Commodore dealer. Any attempt to correct the problem yourself could result in voiding the warranty.
CARE OF THE DISKETTES
Handle diskettes with care. Follow these instructions to maintain the quality of the diskette and to protect the integrity of the data:
1.
Return the diskette to its storage envelope whenever it is removed from the drive.
2. Keep the diskettes away from magnetic fields. Exposure to a magnetic field can distort the data.
3. Never leave a diskette on top of your computer or disk drive.
4. Do not write on the plastic jacket with a lead pencil or ball-point pen. Use a felt tip pen or fill out the label before attaching it to the jacket.
5. Do not expose diskettes to heat or sunlight.
6. Do not touch or attempt to clean the diskette surface. Abrasions will cause loss of stored data.
7. Before applying power to the 2040, 3040, or 4040 open the drive doors and remove diskettes.
UNPACKING THE DISK DRIVE
Before unpacking the disk drive, inspect the shipping carton for signs of external damage.
If the carton is damaged, be especially careful when inspecting its contents. Carefully remove all packing material and the contents of the carton. DO NOT discard any packing material until you have made sure you have located all the contents of the carton! The carton should contain:
1. Commodore Dual Floppy Disk Drive
2. User Manual, Number 320899
3. One of the following TEST/DEMO diskettes: a. 2040/3040/4040 TEST/DEMO diskette, PIN 4040037 b. 8050 TEST/DEMO diskette, PIN 8050050
If any items are missing, please contact your Commodore dealer immediately.
9
Chapter
2
PREPARING TO USE
YOUR DISK DRIVE
Before starting to use your disk drive, make sure it is in good working condition. This includes properly connecting it to your computer, giving it a power-on and initial checkout test, and finally the performance test using the appropriate TEST/DEMO diskette.
CONNECTING THE DISK DRIVE TO THE COMPUTER
One of two connector cables are required to interface the floppy to the computer. These cables can be supplied by your Commodore dealer.
1.
PET-to-IEEE cable, PIN 320101
Use this cable if the disk drive is to be the only (or first) IEEE device connected to your computer.
2. IEEE-to-IEEE cable, PIN 905080
Use this cable if your disk drive is to be connected ("daisy-chained") to another peripheral device such as the Commodore Model 2022, or any other suitable interfaced printer.
NOTE: The disk drive should be the first peripheral attached to the computer if other devices are to be "daisy-chained".
Follow these steps to connect the disk drive to your computer:
STEP 1: Turn power OFF to the computer.
STEP 2: Place the disk drive in a convenient location as close as possible to the computer.
DO NOT connect the disk drive to a power outlet at this time.
STEP 3: Connect the PET-to-IEEE cable between the IEEE-488 interface connector on the computer and the connector on the disk drive.
If additional IEEE devices are to be connected, the IEEE-to-IEEE cable(s) must be used.
STEP 4: Connect the disk drive power cable to an AC outlet. DO NOT turn on power at this time.
11
Floppy Disk
IEEE-la-IEEE Cable
(PIN 905080)
Prinler
12
Figure 2 - Floppy Disk Hookup
PERFORMING THE POWER-ON TEST
You are now ready to proceed with the power-on part of the checkout:
STEP 1: Open both disk drive doors. Ensure that no diskettes are present in either drive.
STEP 2: Turn power ON to the COMPUTER and verify that it is working properly.
STEP 3: Apply power to the disk drive. All three indicator lights (LEDS) on the front panel will flash twice. On the 8050, the two drive LEDs will go out and the center two-color power/error LED will stay green indicating power ON.
If the drive lights remain on, all lights flash continuously, or if the power/error LED is red for more than five seconds, turn the power OFF. Wait one minute and try again.
If any light remains lit, or all lights flash continuously, contact your Commodore dealer immediately.
NOTE: If the problem persists, try disconnecting the other devices attached to the IEEE bus. This should assure that a problem related to another device does not affect the disk drive.
INSERTING THE DISKETTE INTO THE 8050
STEP 1: Insert the diskette into the slot designated "Drive 0" and with the write protect tab oriented to the left.
STEP 2: Once the diskette is in the slot, push gently on the diskette until you hear a distinct "clock". The diskette is now properly positioned in the drive.
STEP 3: Press DOWN firmly on the spring-loaded door of the drive to lower the diskette into the correct position. It is important to press firmly on the door in a smooth motion to avoid damaging the diskette.
STEP 4: To remove the diskette, press DOWN firmly on the spring-loaded door. This will release the spring and raise the diskette. When the diskette is level with the opening, press UP on the door. This will release the diskette and push it out toward the front of the drive. The diskette is now free to be removed from the drive.
STEP 5: DO NOT ATTEMPT TO CLOSE THE DOOR WITHOUT A DISKETTE IN
PLACE. The door is locked open by a mechanical interlock mechanism associated with the diskette ejector that prevents the door from closing if no diskette has been loaded.
WRITE
PROTECT
NOTCH
WHEN COVERED, DISKETTE
CONTENTS CANNOT
BE ALTERED
I
••
•
Figure 3 - Position for Diskette Insertion
IeI:
W z
INSERTING THE DISKETTE INTO THE 2040, 3040 AND 4040
CAUTION: NEVER APPLY POWER TO THE DISK DRIVE IF DISKETTES ARE
PRESENT (LOCKED AND SEATED) IN EITHER DRIVE 0 OR DRIVE 1.
STEP 1: Ensure that the power to the disk drive is OFF and DO NOT apply power until you complete this step. Open both disk drive doors and make sure that no diskettes are present in either drive.
STEP 2: If the preceding conditions have been met, you may apply power to the disk drive.
13
14
STEP 3: Insert the diskette into the slot marked "Drive 0" and with the write protect tab oriented to the left.
STEP 4: Once the diskette is in the slot, gently push on it until it is fully seated.
STEP 5: Press DOWN firmly on the spring-loaded door of the drive until you hear a distinct "click". The diskette is now locked and seated in drive 0, ready for processing by the computer.
STEP 6: To remove the diskette, insert your index finger under the lip of the spring-loaded door and gently PULL. This will release the door and permit access to the diskette. The diskette is now free to be removed from the drive.
THE 4040 AND 8050 PERFORMANCE TEST
When you have successfully completed the Power-On test, proceed with the Performance
Test. Don't worry if you don't fully understand exactly what is happening in this test. At this point, enter the commands just to get a feel for what you can do with your disk.
If UN-
EXPECTED results are obtained during any step of the test, stop and start over again. The most likely cause of a problem is an improperly entered command. This is to be expected until you become familiar with your disk unit.
All commands are entered via the keyboard and must be followed by a carriage return: press the RETURN key on your keyboard.
NOTE: Commands must be entered exactly as shown. DO NOT insert any spaces unless shown in the example.
If the error indicator lights, you may be able to continue the example anyway. Re-enter your last command. If the light goes out, your correction was successful and you may continue.
NOTE FOR BUSINESS KEYBOARD USERS ONLY: You can set your computer for upper case character entry. Do this by typing:
POKE 59468,12 and pressing the RETURN key.
Although it is not absolutely necessary to give this command, it does permit easy entry.
In addition, the examples in this manual can be duplicated exactly when you use only upper case.
If this step is omitted the display will be in lower case letters. DO NOT use the shift key when entering commands. (POKE 59468,14 will return the user to lower case letters.)
STEP 1: Insert the DEMO diskette into drive 0 as previously instructed.
STEP 2: Type: LOAD "*",8 and press RETURN. The computer will load the first file from the diskette in drive 0 and display the following:
STEP 3: Type: RUN and press RETURN. This will cause the DOS Support Program to be
executed. (This program is not necessary for the disk unit to operate; it just simplifies the direct mode commands.) A brief introductory descrption of DOS
Support is presented in Chapter 3 as it applies to Chapter 3 operations. A detailed description of DOS Support is presented in Chapter 7.
STEP 4: Insert a blank diskette into drive 1 and type:
>N1:DEMO,99
>C1=0
This procedure formats the diskette and copys all files from drive 0 to drive 1, thus creating a backup of the DEMO diskette. Remove the DEMO diskette from drive 0 and return it to its protective envelope. Remove the diskette from drive 1 and place it in drive O. Close the door to drive O.
STEP 5: Type: LOAD "PERFORMANCE TEST",8
The screen will display:
<:,EAF'CHmCT FOF' F'EF'FOFr'1AtJCE E':,T
LORD I ~JCT
•
PERD'T' •
STEP 6: Type: RUN and press RETURN.
The program instructs you to place a blank diskette into each drive. The Performance Test Program executes a shortened version of the test used by Commodore in final inspection of the 4040 or 8050. The purpose of this test is to ensure that the unit is functioning correctly and will take approximately seven minutes to complete.
NOTE: Do not use diskettes containing any valuable information since the Performance Test Program will re-format them and any data will be lost. The test program will label these diskettes "Test Disk 1" and "Test Disk 2". These diskettes are ready for further use when the test program is completed and the performance test has been satisfied.
STEP 7: Press RETURN, the following will display:
STEP 8: Enter the appropriate response to the question and press RETURN.
The computer will calculate the maximum number of tracks for the particular disk drive and begin the performance test. The screen displays:
15
The computer will first format the diskette in drive 0 then the diskette in drive 1.
This procedure takes up to three minutes per disk. At the end of the operation the screen displays:
16
The computer conducts the remainder of the Performance Test and displays:
OPEt·~ ~.JF.:
OF'Et·~ ~.JP
~.J
F.: I TI
~4Ci
I TE FILE
ot·~ 0
I TE FILE
DATA TO
Ot·~
0
1
CLO::;E
~'JF.:
ITE DATA TO
0
L·JP ITI
~~Ci
DATA TO
1
CLO~:;E
L·JP I TE DATA TO
1
OPEN PEAD FILE
ot·~ 0
OF'Et·~
READ FILE
Ot·~ 1
PEADItKi DATA FF:Ot'1
0
~:;CRATCH
FILE
Ot·~ (1
FILES
~:;CF.:ATCHED 1
SCRATCH FILE
Ot·~ 1
FILE::; :::;CPATCHED
1
L·JF.: I TE Tf;;:ACK
>::::< Ot~ 0
L·JP I TE TPACK
::<::< Ot·~ 1
~.JF.:
I TE TF:ACK
1 m~ 0
L·JP I TE TF.:ACK
1 O~~ 1
PEAD TF.:ACI<
::<>:: ot·~ 0
PEAD TF.:ACK
::<>:: Ot·~ 1
F.:EAD TF.:ACI<
1 Ot~ (1
READ TF.:ACK
1 O~~ 1
O!:::
OK
OK.
OK
OK
OK
OK
OK
OK
0
1
0
0
1
1
0
1
0
01.00
01.~X1
00.00
00. (10
00.00
OCI.OO
00.00
00.00
O~].
00
0(1.00
0(1.
~X1
OK
0 {:m.O(1
OK
1 0(1.00
OK
0 (H]. (H)
OK
1 O~:1.
00
OK
~:1 00.
~)O
OK
1 O~). ~]O
01< (1 00. (10
OK
1 00.00
UNIT HAS PASSED PEPFORMANCE TEST!
PULL DISKETTES FROM DF.:IVES BEFOF.:E
TURNING POWEP OFF.
•
F.:ERD'T' •
STEP 9: Remove the diskettes and return them to their protective jackets. The floppy has
passed the Performance Test.
STEP 10:
If any problems have been encountered during this phase of the test, return to
Step 1 and repeat the entire procedure.
If problems persist and you do not reach a satisfactory conclusion to the Performance Test, contact your Commodore dealer.
THE 2040 AND 3040 PERFORMANCE TEST
When you have successfully completed the Power-On test, proceed with the Performance
Test. Don't worry if you don't fully understand exactly what is happening in this test. At this point, enter the commands just to get a feel for what you can do with your disk.
If UN·
EXPECTED results are obtained during any step of the test, stop and start over again. The most likely cause of a problem is an improperly entered command. This is to be expected until you become familiar with the procedure.
All commands entered via the keyboard must be followed b a carriage return: press the
RETURN key.
NOTE: Enter the commands exactly as shown. DO NOT insert any spaces unless shown in th& example.
If the error indicator lights, you may be able to continue the example anyway.
Re-enter your last command.
If the light goes out, your c.orrection was successful and you may continue.
STEP 1: Insert the DEMO diskette into drive 0 as previously instructed. Insert a blank diskette into drive 1. Close both drive doors.
STEP 2: Type: OPEN 1,8,15
This command opens logical file 1 on device 8. The secondary address of 15 opens the command channel to the device. The screen displays your entry followed by
READY.
NOTE FOR BUSINESS KEYBOARD USERS ONLY: To set the computer for upper case character entry type:
POKE 59468,12 and press RETURN
Although it is not absolutely necessary to give this command prior to communicating with the disk drive, it does permit easy entry. In addition, the examples in this manual can be duplicated exactly. (POKE 59468,14 will return the user to lower case letters.)
STEP 3: Type: PRINT#1,"IO"
This command initializes drive O.
The initialization procedure places the magnetic head of the drive in the proper position above the diskette. This process is necessary each time the diskette is removed and inserted into the drive. The computer displays your entry, then the word READY.
STEP 4: Type: LOAD"*",8 and press RETURN.
The screen displays:
17
18
STEP 5: Type: RUN.
This causes the DOS support program to be executed. (This program is not necessary for the disk unit to operate, it just simplifies the direct mode commands.) A brief introductory discussion of DOS Support is presented in Chapter 3 as it applies to Chapter 3 operations. A detailed description of DOS Support is presented in Chapter 7.
STEP 6: Type: >D1=O
This commands the disk drive to make a backup copy of the DEMO diskette.
Remove the original DEMO disk from drive envelope. Insert the backup disk into drive O.
0 and return it to its protective
STEP 7: Type: >10
This command initializes the backup diskette.
STEP 8: Type: LOAD"O:DIAGNOSTIC BOOT",8
This command loads the Diagnostic Boot program from the diskette in drive 0 into memory. The screen displays your entry and:
':,ERPCHItJC, FOP
[1
IiIRC,tJO':,TIC BOOT
LORIIItlCi
•
PERII'T' •
Concurrent with the display, the drive 0 indicator lights and the drive 0 motor runs.
STEP 9: REMOVE THE BACKUP DISKE'ITE BEFORE PROCEEDING TO THE NEXT
STEP.
STEP 10: Type: RUN and press RETURN
Follow the directions on the screen.
If all three indicators flicker continuously, the test is passed.
If all indicators remain lit in a steady pattern, the directions on the screen can be used to find the problem area. Mter 30 seconds of operation, reset the disk drive by turning the computer's power switch OFF, then ON.
STEP 11: Simultaneously press SHIFT and CLR/HOME to clear the screen. Use the POKE command described earlier to set the computer for upper case character entry.
STEP 12: RETURN THE BACKUP DISKE'ITE TO DRIVE 0
STEP 13: Type: >10
This command initializes the diskette in drive O.
STEP 14: Type: /O:PET DISK
This loads the PET DISK program from the diskette in drive 0 into memory.
The screen displays your entry and:
':,EAF'C HUK, FOP (1 F'ET D 1':,[
LOAD IHC,
•
F'EAD'T' •
STEP 15: Type: RUN
The PET DISK program is displayed until terminated. Note that you can hear the drive 0 motor running intermittently as each program loads the next.
STEP 16: Press the RUN/STOP key.
Simultaneously press SHIFT and CLR/HOME. This completes the 2040 and
3040 performance test.
NOTES
19
Chapter
3
LEARNING HOW TO USE
YOUR FLOPPY DISK DRIVE
Your CBM Floppy Disk Drive adds and enhances your computing power with added storage and file handling capability and is controlled directly with:
• BASIC commands entered via the keyboard,
• BASIC statements within programs, and
• special disk commands.
In this chapter you will learn how to apply those commands and statements. This chapter is organized in such a way that the functions and format of disk commands are described in a manner which permits the user to perform disk-related tasks. For BASIC 4.0 users, those
BASIC commands which correspond to each disk maintenance command are also discussed.
Before using your floppy disk make sure you know how to:
1.
operate your Commodore Computer,
2. do elementary programming in BASIC, and
3. open and close files.
NOTE: The BASIC statements described in this chapter apply specifically to the 2040,
3040,4040, and 8050. Certain of the commands and statements may follow a slightly different format or produce different results from those described herein when they are used with the computer or with other peripherals. Consult the appropriate manual for the exact usage of these commands and statements in other applications.
This chapter will first acquaint the user with those fundamental disk commands that perform disk maintenance and file manipulation and will then progressively advance toward an understanding of those BASIC commands used for data handling. Approached in this manner, the user will then have developed the necessary confidence and programming skills to proceed to advanced disk programming techniques. Practice the disk commands, read the examples, and follow the step-by-step illustrations of their usage. The understanding of the more advanced disk programming techniques will depend to a large degree upon how well the fundamentals have been mastered.
21
22
To facilitate your understanding and mastery of Commodore BASIC, two computer terms are stressed in this Chapter: Block Availability Map (BAM) and Disk Operating System
(DOS). Although these are conventional terms, they will be briefly discussed as they relate to Commodore Floppy Disk Usage.
THE BLOCK AVAILABILITY MAP (BAM)
The BAM is a disk memory representation of available and allocated space on a disk. When the system stores information on a disk, the BAM will be automatically referenced by the
DOS to determine what space is available and how many blocks can be allocated.
If sufficient space is available to store a given file, it will be stored on the disk and the BAM updated to account for the space allocated. However, if the DOS detects that a file will occupy more space than available, an error message will be generated.
Formatting a disk creates the BAM which is then loaded into DOS memory upon initialization. The BAM is stored on diskette in varying locations depending upon the drive used:
BAM Location and Memory Required Model
2040,3040,4040 Track 18, Sector 0
128 bytes
8050 Track 38, Sector 0 and 1
2 Blocks
As changes occur to the BAM in DOS memory, the BAM on disk will be updated to reflect these changes. Updates to the BAM occur when a program is saved or a CLOSE or DCLOSE is performed on a new RELative or SEQuential data file. Since the 8050 has two blocks available for the BAM, only one block of the BAM is loaded into memory at a time. When updated, this block is written to the disk and the other block loaded into memory. This interchange of information between the two BAMs, one in DOS memory and the other on disk, enables the system to maintain a record of free and allocated space on the disk.
This description of the BAM can only stress the importance of initialization when using either the 2040 or 3040. Strict attention to this basic rule will enable the user to benefit from the advantages of developing good programming techniques as well as to develop a better understanding of the relationship of one element of the system to another.
THE DISK OPERATING SYSTEM (DOS)
The DOS is responsible for managing information exchange between the disk controller and the computer.
The DOS performs many functions which are transparent to the user but which are vital to the operation of the system. For example, the DOS monitors the input/output (I/O) of the disk so that channels are properly assigned and that no lengthy waits for an open channel occur. In addition to monitoring of disk 110, the DOS also uses the channel structure to search the directory and to delete and copy files.
There is another function of DOS called DOS Support which was used during hardware checkout in Chapter 2. Review the Performance Test procedure and observe the special symbols of DOS Support which were used to duplicate and initialize the disks before these procedures were fully explained to the user. Because of its ease of use, DOS Support symbols
were easier to implement at that point than attempting to explain the programming procedures they replace.
It is now appropriate to briefly discuss how DOS Support can enhance and simplify your knowledge of operating your Commodore computer.
The first file on the TEST/DEMO diskette that comes with your disk drive is the Universal
Wedge program, often referred to as DOS SUPPORT. This program, when loaded into computer memory, permits the user to enter abbreviations for many disk commands.
For example, disk commands which would normally be transmitted to the disk using the
PRINT#1fn "commandstring" format may be transmitted via DOS SUPPORT by preceding the command with> or
@.
Typing slash (I) followed by a program name and RETURN will cause DOS SUPPORT to load that program into memory. Replacing certain disk commands with DOS Support special symbols can simplify learning about your Commodore computer by providing a faster method to communicate with the disk. Chapter 7 contains detailed instructions concerning the use of these special symbols and their limitations.
DISK MAINTENANCE COMMANDS
The following disk commands permit the user to perform file manipulation and disk maintenance.
Diskette
Level
BASIC
COMMAND
NEW
INITIALIZE
LOAD"$O"
VALIDATE
DUPLICATE
FUNCTION
Formats a disk
Prepare diskette for use
Read disk directory
Reconstruct Block Availability
Map (BAM)
Duplicates a diskette
BASIC 4.0
DIRECT COMMAND
HEADER
DIRECTORY
COLLECT
BACKUP
File
Level
COPY
RENAME
SCRATCH
Copies files (optional concatenation)
Renames a file
Erases a file
COpy
CONCAT
RENAME
SCRATCH
NOTE: Diskette commands can be transmitted to the disk by PRINT# commands or through the abbreviated commands of DOS support. The examples in this chapter assume that a file has been opened with the OPEN 15,8,15 command.
If the error message ?FILE
OPEN ERROR appears upon typing the OPEN command, it means that the logical file was opened but had not been properly closed. This error condition will automatically close the file. To recover, retype the OPEN command.
23
24
NEW
Each time a diskette is placed in one of the drives, both the diskette and the drive must be prepared for use. A previously unused diskette must first be formatted in the soft-sector format recognized by your particular disk drive. This may be accomplished by use of the
NEW disk command.
To use the NEW command, to format the diskette and initialize the disk drive, enter the command:
PRINT#15,"commandstring" where 15 is the logical file number of a file which has been opened to the disk command channel (primary address 8, secondary address 15).
The format of NEW is:
"NEWdr:fn,xx" or
"Ndr:fn,xx"
Where dr=the drive number, 0 or 1 fn=the file name you wish to assign to the disk.
It may be up to 16 characters long.
xx=a unique two-character, alphanumeric identifier supplied by the user.
The NEW command (with ID specified) is used on an unformatted diskette or one which the user wishes to reformat. NEW creates the block headers, writing the sync characters, disk
ID, and track and sector numbers at the beginning of each block. The directory header and the BAM are created and the diskette is made ready to accept data. The command may be used on an already formatted diskette (with no ID specified) to clear the disk directory and reinitialize the BAM, deallocating all blocks on the diskette. The time involved in reformatting without an ID is much less than formatting with an ID.
Example 1: OPEN15,8,15
PRINT#15,"NO:TESTDISK,88"
These commands will open the command and error channel to the disk drive and format a disk in drive 0, giving it a disk identifer of 88.
Here's an example of reformatting a diskette using the NEW command and no disk ID.
Example 2: OPEN1,8,15
PRINT#l,"NO: NEWNAME"
The diskette will be assigned the name "NEWNAME" and the directory and BAM will be cleared. This procedure will work only if the diskette has been formatted.
The NEW disk command SHOULD NOT be confused with the NEW command in BASIC.
The latter will delete the program currently in memory and clear all variables before entering a new program.
HEADER (BASIC 4.0 Direct Command)
The HEADER command has the same effect as NEW command but is reserved for those computers using BASIC 4.0. Since formatting destroys all data previously stored, the
HEADER command has a built-in safety feature that queries the user: ARE YOU SURE? A positive response to this question permits formatting to take place while a negative response aborts the operation.
The format of HEADER command is:
HEADER"fn",Ddr,Ixx
Where: fn=file name supplied by user but limited to 16 characters.
dr=drive number, 0 or 1 xx=a unique two character alphanumeric identifier (ID) supplied by user.
(same parameters as used by NEW command)
Initialization (2040 and 3040)
Whenever a diskette is inserted into either drive, for any reason, it MUST be initialized to ensure that the information on the BAM (in the disk memory) is the proper information for the diskette currently in the drive. Failure to properly initialize a diskette each time it is inserted or reinserted into the drive will result in a DISK ID MISMATCH ERROR and/or loss of data.
Insert the diskette into drive 1 and initialize as follows:
OPEN 1,8,15
PRINT#l,"Il"
NOTE: FILE OPEN ERROR could occur if a previously opened file was addressed with a second OPEN command. If the file is still open, the second OPEN command would close the file. If this error is displayed, retype the OPEN command and proceed.
The diskette in drive 1 is now initialized. Do not confuse formatting and initialization.
Remember that formatting is usually a one-time operation and that re-formatting a disk will destroy previously stored data.
The INITIALIZE command on the 2040 and 3040 aligns the read/write head with track 1 on the specified diskette. It then moves to track 18, reads the disk label and ID, and loads this information into the Disk Operating System (DOS) memory.
Since the 2040 and 3040 initialization function depends upon a change of ID to detect a change of diskette, inserting a diskette with an ID identical to one previously used may lead to a loss of data. This happens because the computer will reference the BAM left over from the previous diskette. Since the IDs are identical the DOS assumes there has been no change of diskette. A SAVE or DSAVE command may now cause new data to be written over good data already present on the disk because the DOS will use the old map of available storage area, instead of the current one. The results are unpredictable, and the diskette may become totally useless. For this reason, unique disk IDs must be used whenever possible for each diskette.
25
Initialization (4040)
The 4040 utilizes a DOS 2 software routine each time the disk is addressed to determine if initialization is required. If a different ID is detected, the 4040 will automatically initialize the new disk. Operator initialization is not required if unique IDs are assigned each diskette.
Initialization (8050)
The 8050 utilizes a hardware feature to detect the removal or insertion of a diskette, so it is not necessary to initialize since this is an automatic function.
THE DIRECTORY
Confirm that the newly formatted disk has the correct ID and disk name by using one of the following methods to list the directory. The directory display includes the following information:
• Disk name
• Disk ID
• DOS version number
• File name
• File type
• Number of blocks used
• Pointer to first block of file
• Number of available (free) blocks
There are two methods available to all users for listing the directory. The first method illustrates the listing procedure using LOAD and the second, the listing procedure in BASIC 4.0
using the DIRECTORY command. If using a 2040 or 3040, and have removed the disks from the drives for any reason, the disks must be INITIALIZED before attempting to display the directory. If using a 4040 or 8050, initialization is not required-insert the diskette and continue.
26
LOADS
This procedure will destroy any program currently in computer memory when the directory is LOADed. (Refer to the description of the >$ DOS Support command in Chapter 7 which is a non-destructive directory display procedure.)
STEP 1: Place a formatted disk in drive ette and continue.
1. If using a 2040 or 3040, INITIALIZE the diskthen press RETURN.
STEP 2: Type: LOAD"$1",8
The screen displays:
LOADI$l" .' :::
':,EAPC HI HC, FOJ::' $1
LOAIiItH:'
•
PEAD'T' •
STEP 3: Type: LIST
.
The directory for drive 1 will be displayed. SUbstituting $0 for $1 in the format will display the directory for drive O.
DIRECTORY (BASIC 4.0 Direct Command)
This command will display the directory without disturbing the content of the memory.
You may type: DIRECTORY DO using the full word spelling but the preferred short format is illustrated which uses the first two unshifted characters followed by a shifted R.
To display the directory, type: diRdO
If using upper case display, type: DI_DO and press RETURN.
and press RETURN.
The _ in this example represents the upper case display for a shifted R. Typing DI _ D1 will display the directory for drive 1.
Typing DI _ or DIRECTORY will display the directory for both drives if there is a formatted diskette present in each drive. See your BASIC 4.0
reference manual for a complete description of this BASIC command.
Printing The Directory
Quite often, it becomes convenient to affix a diskette directory listing directly on the protective jacket. This permits the user to scan the printed directory listing without having to insert the diskette into the drive to obtain this information. Should you desire to print the directory, place the diskette in drive 0 and enter the following commands:
LOAD "$0",8
OPEN 4,4:CMD4
Loads the directory.
Opens device 4 (printer) and changes the primary output device to 4.
LIST
PRINT#4:CLOSE4
Prints the directory.
Returns output to the screen and closes the file.
VALIDATE
The VALIDATE command traces through each block of data contain'ed in all files on the diskette.
If this trace is successful, a new BAM is generated in the disk memory and written to the diskette. Any blocks which have been allocated but are not associated with a file name, as in the case of direct access files will be freed for use. This will not affect relative files created using the BASIC 4.0 DOPEN command.
In addition to reconstructing the BAM, VALIDATE deletes files from the directory that were never properly closed.
If a READ error is encountered during a VALIDATE, the operation aborts and leaves the diskette in its previous state. If a VALIDATE error does occur, you must re-initialize before proceeding.
The format of VALIDATE is:
PRINT#15,"VALIDATEdr"
Where: dr=drive number (0 or 1)
27
NOTE: You may abbreviate VALIDATE to V.1f a drive number is not specified, the diskette in the last drive used during the current session is verified.
Example: OPEN1,8,15
PRINT#l,"VO" or
PRINT#l,"VALIDATE 0"
COLLECT (BASIC 4.0 Direct Command)
The COLLECT command in BASIC 4.0 performs the same function as VALIDATE. Either command will accomplish the following:
• Recreate a Block Availability Map according to valid data on disk
• Delete files from the directory which were never properly closed.
(OPENed but never CLOSEed)
The format of COLLECT is:
COLLECTDx
Where: x=drive number (lor 0)
Example 1: COLLECT D1
Verifies drive 1
Example 2: COLLECT
Verifies drive 0
(drive defaults to 0)
DUPLICATE
28
The DUPLICATE command formats the destination diskette and transfers each block of information from the source diskette to the destination diskette, thus creating an exact duplicate of the source diskette. Use this procedure for one method of creating a backup copy of a diskette.
Due to the various formatting protocols used by DOS 1, DOS 2, and DOS 2.5, this command may NOT be used interchangeably when using diskettes prepared on different disk drives. Use the following guide to avoid confusion:
DUPLICATE command may be used on-
• a 2040 or 3040 using diskettes formatted on a 2040 or 3040.
• a 4040 using diskettes formatted on a 4040.
DUPLICATE command may NOT be used on-
• a 2040 or 3040 using diskettes formatted on a 4040.
• a 4040 using diskettes formatted on a 2040 or 3040.
To reproduce a diskette under these conditions, use the COpy ALL DISK program found on the TEST/DEMO diskette which came with your disk drive.
The format of DUPLICATE is:
PRINT#lfn, "DUPLICATEddr=sdr"
Where: ddr=is the destination diskette (either 0 or 1) sdr=is the source diskette (either 0 or 1)
Do not reverse the order of the drive numbers. If you do, you will lose all data and there is no way to recover it. Observe good practice and place a write protect tab on the diskette containing the valuable information. This procedure will prevent overlaying good information.
Example: OPEN1,8,15
PRINT#l,"DUPLICATEO=l" or
PRINT#l,"DO=l"
NOTE: The letter D is a legal abbreviation for DUPLICATE command.
BACKUP (BASIC 4.0 Direct Command)
The BACKUP command in BASIC 4.0 performs the same function as DUPLICATE.
The format of BACKUP is:
BACKUP Dsdr TO Dddr.
Where: ddr=is the destination drive sdr=is the source drive
(either 0 or 1)
(either 0 or 1)
Note that the format of BACKUP differs from DUPLICATE in that the order of the drives is reversed.
Example: BACKUP D1 TO DO
This has exactly the same effect as the previous example given when discussing DUPLICATE command. For a complete explanation of the BACKUP command, refer to the Commodore
BASIC 4.0 Reference Manual.
COpy
The COpy command allows you to copy files from one diskette to another, to create mul· tiple copies (under different names) of files on the same diskette. This command can also be used to concatenate data files on the 4040 or 8050. Up to four source files can be concatenated into the destination file. On the 4040 or 8050 all files from one drive may be copied to a formatted diskette in the other drive. The COPY command may be abbreviated with a C.
COpy disk command can be formatted three ways depending upon application:
To copy a single file: PRINT#1fn,"COpyddr :dfn=sdr :sfn"
29
or
PRINT#1fn,"Cddr :dfn=sdr:sfn"
To concatenate and copy: PRINT#1fn,"COPYddr:dfn=sdr:sfn,sdr:sfn ...
or
PRINT#1fn,"Cddr:dfn=sdr :sfn,sdr :sfn ...
PRINT#1fn, "COpyddr=sdr" To copy all files on a diskette: or
PRINT#1fn,"Cddr=sdr"
Where: ddr=is the destination drive. The file is to be copied onto the diskette in this drive. This may be the same or different from the source drive.
dfn=is the destination file name. This name may be either a new name or the same as the old file name unless the ddr is the same as the sdr.
If both files are to exist on the same diskette, they must have different names.
In example 1, a file is copied from the diskette in drive 1 to the diskette in drive O. In example 2, files from both drives are concatenated into a file on drive 1.
In example 3, all files from drive 0 are copied to drive 1. An error message FILE EXISTS will be generated in the disk unit if a file to be copied already exists on the destination drive (drive 1 in this example).
Example 1: PRINT#I,"Cl :ACCTI=0 :ACCT"
A file is copied from the diskette in drive 1 to drive O.
Example 2: PRINT#I,"Cl:JDATA=I:ACCTl,O:ADATA,O:BDATA"
Files from both drives are concatenated into a file on drive 1.
Note that file names should be short, as the maximum length of a disk command string is 40 characters.
30
Example 3: PRINT#I,"Cl=0"
All files from drive 0 are copied to drive 1.
Example 3 illustrates one way to upgrade from a 2040 or 3040 formatted diskette to a 4040 format: place a formatted diskette in drive 1 and the diskette to be upgraded in drive 0 and copy all files from 0 onto 1.
COPY (BASIC 4.0 Direct Command)
The COpy direct command in BASIC 4.0 performs the same function as COPY disk command and its format is also dependent upon application.
Use this format to copy the contents of the entire disk:
COpy Dsdr TO Dddr
Use this format to copy a single file:
COpy Dsdr,"sfn" to Dddr,"dfn"
Where: sdr=the source diskette ddr=destination diskette fn=file name
CONCAT (BASIC 4.0 Direct Command)
The CONCAT direct command in BASIC 4.0 permits the user to concatenate files.
The format of CONCAT is
CONCAT Dsdr,"sfn" TO Dddr,"dfn" where the file named dfn on drive ddr will contain the contents of both dfn and sfn after the concatenation. For example:
CONCAT DO,"YOURFILE" TO D1,"MYFILE" will result in MYFILE on drive 1 containing the data from the old MYFILE and from
YOURFILE. YOURFILE will remain unchanged.
NOTE: The concatenation feature of COPY disk command and CONCAT direct command are valid only for DOS 2.
For further information regarding use of BASIC COPY and CONCAT commands, refer to the Commodore BASIC 4.0 Reference Manual.
RENAME
The RENAME command renames an existing file. A file can not already exist with the file name specified in the command or the FILE EXISTS error message will be generated.
The format of RENAME is:
PRINT#1fn, "RENAMEdr :nfn=ofn"
Where: dr=the disk drive on which the diskette is located.
nfn=the new name of the file.
31
32 ofn=the old name of the file.
lfn=a logical file number. You assign this number arbitrarily and it may be any whole number between 1 and 255.
NOTE: The letter R is a legal abbreviation for RENAME.
RENAME (BASIC 4.0 Direct Command)
The RENAME direct command in BASIC 4.0 performs the same function as RENAME disk command.
The format is:
RENAME Ddr,"ofn" TO "nfn"
NOTE: Close any open files before using the RENAME command since the disk will not execute this command on any active files.
For further information on the RENAME command, please refer to the Commodore BASIC
4.0 Reference Manual.
SCRATCH
The SCRATCH command erases unwanted files from the specified diskette and its directory.
You can erase one file, several files, or all the files on a diskette.
The format of SCRATCH is:
PRINT#lfn, "Sdr :fn,dr :fn ... dr :fn"
Where: dr is the disk drive to be searched.
alone means "last drive accessed", with dr refers to the specified drive, where not used means "both drives".
fn is the name of the file to be erased.
To erase one file, enter the entire name of the file:
Example: PRINT#l,"SO:ACCT"
To erase several files with unrelated names, enter the entire name of each file to be deleted:
Example: PRINT#l,"SO:ACCT,O:CUSTOMER,O:INV"
To erase several files at one time where names have something in common, refer to the rules in APPENDIX B concerning pattern matching.
You may erase all files on a diskette using pattern matching as in the following example:
Example: PRINT#l "~O:*"
SCRATCH (BASIC 4.0 Direct Command)
SCRATCH direct command in BASIC 4.0 performs the same function as SCRATCH disk command.
The format is: SCRATCH Ddr,"fn"
Where: dr=drive number fn=filename of file to be scratched
Pattern matching rules may be used with this command.
As with the HEADER command, there is a built-in safety feature that queries the user: ARE YOU SURE? A positive response permits the file to be SCRATCHed while a negative response aborts the operation.
For a complete description of the SCRATCH direct command, please refer to your BASIC
4.0 reference manual.
NOTES
33
Chapter
4
BASIC COMMANDS
FOR DATA HANDLING
BASIC COMMANDS ASSOCIATED WITH FLOPPY DISK DRIVES
The BASIC commands described in this chapter, allow the user to communicate with and transfer data to and from the disk drive.
These commands are available for ALL versions of Commodore BASIC:
OPENlfn,8,sa,"dr :fn,t,r/w"
CLOSElfn
LOAD"dr:fn",8
SAVE"dr :fn",8
VERIFY"dr :fn",8
PRINT#lf
GET#lfn
INPUT#
These commands are available ONLY in BASIC 4.0:
DOPEN#lfn,"fn"
DCLOSE#lfn
DLOAD"fn"
DSAVE"fn"
RECORD#lfn,R,B
Where: lfn=logical file number (any number between 1 and 255) fn=file name supplied by user x=dr=disk drive number (lor 0): both Dx and dr default to 0
8=device number (8 for disk, 2 for second cassette, 4 for printer) sa=secondary address
U=logical file
All upper-case characters shown in format are essential for the proper execution of a command and must be typed by user. These commands are entered via the keyboard using unshifted characters only. On the CBM Business Model they will appear in lower case.
BASIC 3.0 commands are upward compatible with BASIC 4.0 commands. Each command will be defined along with a brief example to illustrate their use.
As soon as your dual drive floppy disk is attached to your computer and has passed the performance test, we encourage you to try the examples and procedures.
35
36
SAVE and DSAVE (Writing a Program to a Diskette)
If a program is in computer memory, it can be moved to a diskette for storage. This is accomplished with the SAVE (any Commodore BASIC) or DSAVE (BASIC 4.0) commands.
Any data transferred with the SAVE or DSAVE commands are automaticaly designated by the DOS as a program (PRG) file. Both commands transfer PRG files from the computer's memory to the specified diskette. You must specify the drive number, the program name, and the device number. The device number will default to device 1 which is the tape unit if it is not specified.
The format of SAVE is:
SAVE"dr:fn",dn
Where: dr=is the disk drive number.
It must be 0 or 1.
fn=is any file name of 16 characters or less you wish to assign to the file to be transferred to the diskette. Blanks are counted as characters.
dn=is the device number and it must be 8.
This following example illustrates creating a one line program, SAVEing it on the diskette in drive 0 under the name TESTPROG, and VERIFYing that it is resident on disk.
Example: 10?"THIS IS A TEST"
SAVE"O :TESTPROG",8
VERIFY"0:TESTPROG",8
The DSAVE command performs the same function as SAVE, but is valid only with a Commodore disk system and BASIC 4.0.
The format is:
DSAVE"fn "Ddr
This command will save a file named "fn" on the floppy disk in drive 0 or
"fn", may be any name of 16 characters or less.
1.
The file name,
LOAD and DLOAD (Reading a Program from a Diskette)
A program stored on diskette may be loaded into memory using the LOAD (any Commodore BASIC) or DLOAD (BASIC 4.0) commands.
The LOAD and DLOAD commands transfer PRG files from the specified diskette to the computer's memory. You must specify the drive number, the program name, and the device number. The device number will default to unit 1 which is the cassette unit. The format of
LOAD is:
LOAD' 'dr :fn",dn
Where: dr=is the drive number from which you are loading data. It must be 0 or 1.
fn=is the file name previously specified in the SAVE command and/or stored in the disk directory.
dn=is the device number and it must be 8.
The following example illustrates how a program is loaded from the diskette into the computer memory, then executed. To do this example, first type NEW and depress RETURN key to clear your computer's memory so that you can see that it really works. Don't confuse the NEW command in BASIC with the NEW disk command used to format your disk.
Example 1: LOAD' '0 :TESTPROG",8
READY.
RUN
THIS IS A TEST
The DLOAD command transfers performs the same function as LOAD, but is specifically designed for a Commodore disk unit using BASIC 4.0. The device number will default to 8 if not specified. The drive number will default to 0 is not specified.
DLOAD"fn",Ddr
A successful LOAD or DLOAD closes all open files. Therefore you must give a new OPEN command in order tocontinue communicating with the disk drive command and error channel.
VERIFY
The format of VERIFY command is:
VERIFY' 'dr :fn",8
This command verifies that a file named "fn" stored on a floppy disk contains the same information which is stored in the computer's memory. This command is the same as the
VERIFY command used with the tape cassette. Once again, dr refers to the drive number, either zero or one. Note that the format of this command specifies that the drive number be placed before the filename. The 8 at the end of this command is the device number (8 for disk, 2 for second tape cassette).
STEP 1: Write a short program and save it on a diskette in drive 1 under the name "test" using the procedure described under the section on SAVE.
NOTE: It is important that the program in memory is not changed in any way between the save and verify operations.
STEP 2: Type: VERIFY "1:TEST",8
Once verified, the screen displays:
37
38
If a verify error occurs, reSAVE the program and verify it again.
VERIFY may also be used in the format:
VERIFY' '*",8 in order to perform verification of the last file saved without re-typing the filename. Confirm by following these steps:
STEP 1: Write a short program and save it.
STEP 2: Clear the screen.
STEP 3: Type: VERIFY "*",8
The VERIFY function will be performed comparing the last file saved to the content of memory.
OPEN
This command sets up a correspondence between a logical file number and a file which exists on disk.
It also reserves the buffer space within the disk unit for operations on the file being opened.
The format of the complete OPEN command is:
OPENlfn,dn,sa,"dr:fn,ft,mode"
Where: lfn=the logical file number dn=the device number; in this case 8 sa=the secondary address. It may be any number from 2 to 14 and may be used either for input or output as specified in mode. See note below dr=the drive number: 0 or 1 fn=the name of the file.
ft=the file type. It may be SEQ (for sequential), USR (for user), REL (for relative) or PRO (for program).
mode describes how the channel is to be used. It may be either READ (R) or
WRITE (W).
NOTE: Secondary address 15 is the command and error channel and has special uses which are discussed in subsequent chapters. Secondary addresses 0 and 1 are reserved by the operating systems (BASIC and DOS) for LOADing and SAVEing programs.
Examples: OPEN2,8,2,"O:FILE1,SEQ,WRITE"
OPEN3,8,9,"1:TESTDATA,PRO,WRITE"
OPEN8,8,8,"O:NUM,USR,READ"
The contents of an existing file (on 4040 and 8050 only) may be replaced by preceding the drive number with an at sign (@) in the OPEN command.
OPEN3,8,5,"@0:JDATA,USR,WRITE"
If the specified file does not exist, then normal OPENing procedures are executed.
You can also assign some of the OPEN parameters to a variable name as illustrated in these examples:
Example 1:
Example 2:
FL$="O:FILEA,SEQ,READ"
OPEN1,8,14,FL$
FL$="O :FILEA"
OPEN1,8,14,FL$+",SEQ,WRITE"
The preceding methods are convenient when it is necessary to open several channels to the same file name.
DOPEN
The DOPEN command is available only to BASIC 4.0 users. When used with either a 4040 or 8050, DOPEN may be used to create relative files or sequential files of fixed length.
The format of DOPEN is:
DOPEN#lfn,"fn",Ddr,Lrl (,ONUdn) (,W)
Where: lfn, fn, and dr are the same as defined for OPEN.
Lrl defines the record length as equal to rl
ONUdn specifies the device number equal to dn (with default device being 8)
W may be specified to mean write mode.
If W is not specified for sequential files, the file will be opened to read.
DOPEN is not available for the standard 2040 or 3040.
CLOSE
The CLOSE command closes a file opened by the OPEN command. Its format is:
CLOSE lfn
Where: lfn=the logical file number of a file opened by the OPEN command.
Always close a file after working with it. You are not allowed to have more than ten open files in the computer and five in the disk drives, so it is prudent to make a habit of closing files as soon as possible. This way you will always have the maximum number of files avail· able for use.
39
DC lOSE
The DCLOSE command is available only to BASIC 4.0 users. This command closes files opened with the DOPEN command.
The format of DCLOSE is:
DCLOSE#lfn
Where: lfn=the logical file number of the file to be closed.
The DCLOSE command may also be used in this format:
DCLOSE ONUdn
Where: dn=the device number of the disk unit (defaults to 8).
When used in this form, DCLOSE command closes all active disk files on the specified unit.
The following examples illustrate some applications of DCLOSE command:
Example 1: DCLOSE
Example 2:
Close all files currently OPEN.
DCLOSE#5
Close only logical file 5.
CLOSING THE COMMAND CHANNEL
Closing the command channel closes all channels associated with the disk drive. No other part of the logical file environment is affected. That is, the computer does not recognize that the files have been closed.
The following example illustrates a situation in which several channels are closed down by a single CLOSE command.
Example: The command channel is opened.
Data Channels are opened for writing.
A channel is opened to the printer by mistake.
An error message is displayed on the screen.
40
Since there was an error, all logical files in the computer are closed, but the channels in the disk drive are still open. To close the disk channels, type:
OPEN1,8,15
CLOSE1
Now all data channels in the disk drive are properly closed.
CLOSING THE DATA CHANNEL
The CLOSE command closes a file and the data or command channel associated with it.
Whenever you close a file opened with a write channel, the closing of that file writes the final block of data to the disk and updates the disk directory. When you close a file opened with a read channel, that channel is simply closed down.
NOTE: When a drive is initialized with INITIALIZE, NEW, DUPLICATE, or VALIDATE, all channels associated with that drive are deleted. These commands should not be executed when there are any files open since the files will be disrupted.
#
The PRINT# command transmits a disk command string to the drive.
The format of PRINT# is:
PRINT#fn,"commandstring"
Where: lfn=a file previously opened using secondary address 15
"commandstring"=disk handling or disk file handling commands. These disk commands are discussed in detail in Chapter 3 of this manual.
PRINT# may also be used to transmit data to a previously-opened sequential or relative file.
A semicolon must be used as a terminator for each PRINT# statement when using BASIC
3.0 to avoid sending extraneous line feeds to the diskette. These characters are written to the diskette by the BASIC PRINT# routine as part of the data terminator.
It is important to be aware of this face because the carriage return alone is seen as a terminator by the DOS.
The line feed is then stored in the file as the first character in the next record. To avoid this, use the following format:
Example: PRINT#2,"JONESABC";CHR$(13);
The CHR$(13) is the carriage return necessary for the proper termination of the record on the disk. When this record is input, the result will be JONESABC which is the desired result.
BASIC 4.0 users do not need to follow this procedure (though no harmful effects will result from it). In BASIC 4.0, any file opened with lfn less than 128 will automatically suppress the line feed.
The following format may then be used:
PRINT#1fn,A$
This will produce the desired value of A$ for the record, and will not interfere with the next record.
41
42
Several variables may be written to the disk at the same time.
The format:
PRINT#lfn,A$,B$,C$ will result in a single variable (A$+B$+C$) being retrieved by the input command.
The format:
PRINT#lfn,A$CHR$(13)B$CHR$(13)C$ will result in the variables A$, B$, and C$ being separated by carriage returns, and they may then be input as separate variables.
INPUT
#
The INPUT# command is used to transfer information from an IEEE device such as the disk drive into computer memory. INPUT# is valid only when used in a program and only when referencing a logical file that has been OPENed for input.
The format for INPUT# is:
INPUT#lfn,A$ or INPUT#lfn,A
Where: lfn=a file previously opened using secondary address 15
A$=a string variable which will contain the data transferred.
A=a numeric variable which will contain the data transferred.
INPUT# may also be used to transfer several strings of data at one time:
INPUT#1fn,A$,B$,C$
Where: A$, B$, C$ will contain the data transferred from the disk.
In this format, the data strings must have been separated by carriage returns ( CHR$(13) ) at the time they were written to the disk in order to be retrieved separately. No single string may contain more than 80 characters if it is to be INPUT.
Example 1:
20 INPUT#2,A
Input the next data item which must be in numeric form and assign the value to variable A.
Example 2:
10 INPUT#8,A$
Input the next data item as a string and assign it to variable A$.
Example 3:
60 INPUT#7,B,C$
Input the next two data items and assign the first to numeric variable Band the second to string variable C$.
For strings longer than 80 characters, the GET# command must be used.
GET#
The GET# command is used to transfer individual bytes of information from an IEEE device such as the disk drive into computer memory. GET# is valid only when used in a program and only when referencing a file that has been OPENed.
The format of GET# is:
GET#lfn,A$
Where: lfn=a file previously opened using secondary address 15
A$=a string variable which will contain the data transferred.
GET# may also be used to transfer several bytes of information, which is useful for retrieving strings which have been written to the disk in a format which is unacceptable for the
INPUT command (strings longer than 80 characters).
For example: 10 AA$=""
20 FOR 1=1 TO 254
30 GET#lfn,A$
40 AA$=AA$+A$
50 NEXT is a program segment which would result in a string of length 254 being transferred from the disk (logical file number lfn) to the computer memory and stored in the variable AA$.
RECORD#
The RECORD# command is used prior to a PRINT#, INPUT#, or GET# in order to position the file pointer to the desired record (and byte) of a relative file. For example, if record pointer is set beyond the last record and PRINT# is used, the appropriate number of records are generated to expand the file to the desired record.
RECORD# is available only to users equipped with BASIC 4.0. The format is:
RECORD#lfn,r,b
Where: lfn=a logical file number of a file previously opened with the DOPEN command r=the desired record number. 4 may be either a variable name or value, however if r is a variable name, it must appear enclosed in parentheses.
0<=r<=65535 b=the byte position desired within the record. Byte positioning is optional.
1<=b<=254
43
The following example illustrates how RECORD command is used with INPUT#:
Example: 10 RECORD#1,120
Using the RECORD command to select the record.
20 INPUT#1,A$
Input the next data item as a string and assign it to variable A$.
A detailed example of the usage of the RECORD command for relative file manipulation is found in Chapter 6.
aUICKLOAD FEATURE (BASIC 4.0)
This command feature is valid with DOS 2 and BASIC 4.0, and either a 4040 or 8050. (This command will also function properly with a retrofitted 2040.)
This command loads the first file on the disk in drive 0 into memory. To ensure that the first program on the diskette is accessed, the command must be the first disk command given after a cold start.
STEP 1: Turn the computer OFF, then ON.
STEP 2: Make sure the disk containing a program as the first file is in drive 0 and that the drive door is closed.
STEP 3: Simultaneously press the SHIFT and RUN/STOP keys.
The computer will initialize the disk in drive 0, search for the first program on that disk, and load it.
44
When using this feature the computer will automatically execute the DLOAD and RUN commands and it is not necessary to enter either command.
MOVING A TAPE PROGRAM TO DISK
This example illustrates a session with the computer, a tape cassette and a disk drive. The purpose is to copy a cassette program to a diskette. The program is then read from the diskette to the computer's memory and printed.
It is assumed that the BASIC program was previously stored on the cassette.
Example:
Load the file from the cassette tape to the computer's memory.
Create a program file containing the program on diskette.
Erase everything from memory. (The NEW command in BASIC will clear memory; the
NEW disk command will format a disk.)
Load the program back into the computer's memory.
Run the program to verify it has been loaded.
45
Chapter
5
ADVANCED
DISK PROGRAMMING
This chapter provides detailed information about DOS structure and disk utility commands.
The utility commands provide the programmer with low-level functions that may be used for special applications such as special disk handling routines and random access techniques.
COMMODORE DISK OPERATING SYSTEM (DOS)
The DOS file interface controller is responsible for managing all information between the disk controller and the IEEE488 bus. Most disk I/O is performed on a pipelined basis, resulting in a faster response to a requested operation.
The file system is organized by channels which are opened with the BASIC OPEN statement. When executed with the OPEN statement, the DOS assigns a workspace to each channel and allocates either one or two disk I/O buffer areas. If either the workspace or the buffer is not available, a NO CHANNEL error is generated. The DOS also uses the channel structure to search the directory, and to delete and copy files.
The common memory between the disk controller and the file interface controller is used as
256-byte buffer areas. Three of the sixteen buffers are used by the DOS for the Block
Availability Maps (BAM), variable space, command channel I/O, and disk controller's job queue.
The job queue is the vital link between the two controllers. Jobs are initiated on the file side by providing the disk controller with sector header and type of operation information.
The disk controller seeks the optimum job and attempts execution.
An error condition is then returned in place of the job command.
If the job is unsuccessful, the file side re-enters the job a given number of times, depending upon the operation, before generating an error message.
The secondary address given in the OPEN statement is used by DOS as the channel number.
The number the user assigns to a channel is only a reference number that is used to access the work areas, and is not related to the DOS ordering of channels. The LOAD snd SAVE statements transmit secondary addresses of 0 and 1, respectively. The DOS automatically
47
48 interprets these secondary addresses as LOAD and SAVE functions. Unless these functions are desired when opening files, avoid secondary addresses of 0 and 1.
The remaining numbers,2 through 14, may be used as secondary addresses to open up to five channels for data.
DISK UTILITY COMMAND SET
The disk utility command set consists of the following commands:
General Format Commands
BLOCK-READ
BLOCK-WRITE
BLOCK-EXECUTE
BUFFER-POINTER
BLOCK-ALLOCATE
BLOCK-FREE memory-write memory-read memory-execute
Abbreviations
B-R
B-W
B-E
B-P
B-A
B-F
M-W
M-R
M-E
"B-R: "ch,dr,t,s
"B-W: "ch,dr,t,s
"B-E: "ch,dr,t,s
"B-P:"ch,p
"B-A: "dr,t,s
"B-F: "dr,t,s
"M-W"adl/adh/nc/data
"M-R"adlladh
"M-E"adlladh
USER
Where:
U "Ui:parms" ch=the channel number in DOS: identical to the secondary address in the associated OPEN statement.
dr=the drive number: 0 or 1 t=the track number: 0 thru 77. For each track number, the sector ranges for the 2040, 3040, 4040, and 8050 are shown in Appendix C.
p=the pointer position for the buffer pointer.
adl=the low byte of the address*.
adh=the high byte of the address*.
nc=the number of characters: 1 through 34*.
data=the actual data in hexidecimaI. This is transmitted by using the CHR$ function, i.e. CHR$(1) would send the binary equivalent of hexidecimal
01, (decimal 1).
i=the index to the User Table.
parms=the parameters associated with the U command (optional).
The values used in conjunction with the memory commands exist in the 2040, 3040, and
4040 as hexidecimal values and must be transmitted as CHR$(n), where n is the decimal equivalent of the desired hexidecimal value.
NOTE: If using variables the format must have only the command in quotes. For example:
"B-R: "ch,dr,t,s
"B-R:ch,dr,t,s" correct incorrect
To avoid confusion, it is good practice to use this format when using variables or constants.
As implied in the preceding format, these commands may be abbreviated to the first character of each of the key words. Abbreviations only are accepted for those commands shown in lower case. The parameters associated with each command are searched for starting at a colon (:), or in the fourth character position if a colon is not present. The example following shows four ways that the same block-read command may be given.
NOTE: If using a 4040 initialize the disk before the buffer read or write.
Examples: "BLOCK-READ: "2,1,4,0
"B-R"2,1,4,0
"B-R"2;1;4;0
"B-READ: "2;1;4;0
Parameters following the key words within quotation marks may be separated by any combination of the following characters:
Character Name
Skip
Space
Comma
Keyboard Representation
<cursor right>
Space bar
The use of these characters permits sending both ASCII strings and integers.
Parameters not within the confines of quotation marks should be separated by semicolons (;).
In the following discussions, a PRINT# is assumed in all examples.
BLOCK-READ
This diskette utility command provides direct access to any block on a diskette in either disk drive. Used in conjunction with other block commands, a random access file system may be created through BASIC. This command finds the character pointer in the O-position of the block. When a character in this position is accessed with GET# or INPUT#, an Endor-Identify (EOI) is sent. This terminates an INPUT# and sets the Status Word (ST) to 64 in the computer.
49
The format "B-R:"ch;dr;t;s is illustrated in the following example.
Example: "B-R: "5;1;18;0
Reads the block from drive 1, track 18, sector 0 into channel 5 buffer area.
Mter using BLOCK READ to transfer the data to the buffer, the data may be transferred to memory by INPUT# or GET# from the logical file opened to that disk channel (Le., using that secondary address).
The U1 command described under USER is similar to the BLOCK-READ command.
BLOCK-WRITE
When this command is initiated, the current buffer pointer is used as the last character pointer and is placed in the 0 position of the new buffer. The buffer is then written to the indicated block on the diskette and the buffer pointer is left in position 1.
The format "B-W: "ch;dr;t;s is illustrated in the following example.
Example: "B-W: "7;0;35;10
Writes channel 7 buffer to the block on drive 0, track 35, sector 10:
BLOCK-WRITE is not available with DOS 2. This includes the 4040 and all 2040/3040 retrofits. The BLOCK-WRITE command is replaced by the U2 command for the 4040.
BLOCK-EXECUTE
This command allows part of the DOS or user designed routines to reside on disk and be loaded into disk drive memory and executed. B-E is really a B-R with an addition. The File
Interface Controller begins execution of the contents after the block is read into a buffer.
Execution must be terminated with a return from the subroutine (RTS) instruction. Future system extensions or user-created functions may implement this command.
The format "B-E:"ch;dr;t;s is illustrated in the following example.
Example: "B-E:"6;1;1;10
Reads a block from drive 1, track 1, sector 10 into channel 6 buffer and executes its contents beginning at position 0 in the buffer:
50
BUFFER-POINTER
This command changes the pointer assocIated with the given channel to a new value. This is useful when accessing particular fields of a record in a block or, if the block is divided into records, individual records may be set for transmitting or receiving data.
The format "B-P: "ch,p is illustrated in the following example.
Example: "B-P:"2;1
Sets channel 2 pointer to the beginning of the data area in the direct access buffer:
BLOCK-ALLOCATE
The appropriate BAM is updated in the DOS memory to reflect the indicated block as allocated (used). In future operations, the DOS skips over the allocated block when saving programs or writing sequential files. The updated BAM is written to diskette upon the closure of a write file or the closure of a direct access channel.
If the block requested has been previously allocated, the error channel indicates the next available block (increasing track and sector numbers) with a NO BLOCK error.
If there are no blocks available that are greater in number than the one requested, zeroes are displayed as track and sector parameters.
The format "B-A: "dr;t;s is illustrated in the following example.
Example: "B-A: "1;10;0
Requests that block (sector) 0 of track 10 be flagged as allocated on the diskette in drive 1.
NOTE: The error channel should always be check when using BLOCK ALLOCATE, so that if the block is already allocated, it will not be overwritten.
If the block is allocated, the error message will also indicate the next available block.
Example: INPUT#15,EN,EM$,ET,ES
Reads the next track and sector, respectively, into ET and ES, assuming that lfn=15 has been previously OPENed to the disk error channel.
MEMORY
All three MEMORY commands are byte-oriented so that the user may utilize machine language programs. BASIC statements may be used to access information through the
MEMORY commands by using the CHR$ function. The system accepts only M-R, M-W, and
M-E: neither verbose spelling or the use of the colon (:) is permitted.
Memory-Write
This command provides direct access to the DOS memory. Special routines may be downloaded to the disk drive through this command and then executed using the MEMORY-
EXECUTE command or one of the USER (U) commands. Up to 34 bytes may be deposited with each use of the command. The low byte of the address must precede the high byte of the address.
The format "M-W: "adl/adh/nc/data is illustrated in the following example.
Example: "M-W: "CHR$(00)CHR$(18)CHR$(4)CHR$(32)CHR$(0)CHR$(17)CHR$(96)
Writes four bytes to buffer 2 ($1200 or decimal 4608):
51
52
Memory-Read
The byte pointed to by the address in the command string may be accessed with this command. Variables from the DOS or the contents of the buffers may also be read with this command. The M-R command changes the contents of the error channel since it is used for transmitting information to the computer. The next GET# from the error channel
(secondary address 15) transmits the byte.
An INPUT# should not be executed from the error channel after a MEMORY-READ command until a DOS command other than one of the MEMORY commands is executed.
The format "M-R: "adlladh is illustrated in the following example.
Example: "M-R"CHR$(128);CHR$(O)
Accesses the byte located at ($0080 or decimal 128):
Memory-Execute
Subroutines in the DOS memory may be executed with this command. To return to the
DOS, terminate the subroutine with RTS ($60).
The format "M-E: "adlladh is illustrated in the following example.
Example: "M-E"CHR$(128);CHR$(49)
Requests the execution of code beginning at $3180.
USER
This command provides a link to 6502 machine code according to a jump table pointed to by the special VSER pointer. Refer to Table 5. The second character in this command is used as an index to the table. The ASCII character 0 through 9 or A through 0 may be used.
Zero sets the VSER pointer to a standard jump table that contains links to special routines.
The special VSER commands VI (or VA) and V2 (or VB) can be used to replace the
BLOCK-READ and the BLOCK-WRITE commands.
The format of VI is:
"VI: "ch;dr;t;s
VI forces the character count (buffer pointer) to 255 and reads an entire block into memory. This allows complete access to all bytes in the block.
The format of V2 is:
"V2 :"ch;dr;t;s
V2 writes a buffer to a block on the disk without changing the contents of position 0 as
B-W does. This is useful when a block is to be read in (with B-R) and updated (B-P to the field and PRINT#), then written back to diskette with V2.
Refer to the random access example in Chapter 6 for an application of the commands.
VI and V2
USER
DESIGNATION
Ul
U2
U3
U4
U8
U9
U:
U5
U6
U7
UC
UD
UE
UF
UG
UH
VI
UJ
Table 5. Standard Jump Table
ALTERNATE
USER
DESIGNATION
UA
UB
FUNCTION
BLOCK-READ replacement
BLOCK-WRITE replacement jump to jump to jump to jump to jump to jump to jump to
2040/3040
$1300
$1303
$1306
$D008
$DOOB
$DOOE
4040
$1300
$1303
$1306
$1309
$130C
$DOD5
$130F
$10FO power up vector
8050
$1300
$1303
$1306
$1309
$130C
$130F
$10FO
U3 thru U9 commands are user-defined. The locations jumped to are located in the buffer areas of RAM and routines may be written to reside there and downloaded using the M-W command. Locations D008, DOOB, DOOE, and DOD5 are located in the expansion ROM slot in the 2040/3040 and USER commands may be used to access a ROM or EPROM located in that position. Location IOFO is the location of the NMI vector in the 4040 and 8050.
53
54
2040,3040
Track number
1 to 17
18 to 24
25 to 30
31 to 35
4040
Track number
1 to 17
18 to 24
25 to 30
31 to 35
8050
Track number
1 to 39
40 to 53
54 to 64
65 to 77
Table 6. Block Distribution By Track
Block or
Sector Range o to 20 o to 19 o to 17 o to 16
Block or
Sector Range o to 20 o to 18 o to 17 o to 16
Block or
Sector Range o to 28 o to 26 o to 24 o to 22
Total
21
20
18
17
Total
21
19
18
17
Total
29
27
25
23
Any block on a diskette may be examined by using the program DISPLAY T&S, provided on the TEST/DEMO diskette.
Tables 7 through 12
PLAY T&S program.
will assist the user in interpreting information obtained using the DIS-
Table 7. 2040, 3040 BAM FORMAT
Track 18, Sector O.
BYTE CONTENTS
0,1 18,01
2
3
1
0
DEFINITION
Track and sector of first directory block.
Indicates version 1 format.
Null flag for future DOS use.
4-143 *Bit map of available blocks for tracks 1-35.
*l=available block
O=block not available
(each bit represents one block)
144"-161
Table 8. 2040, 3040 DIRECTORY HEADER
Track 18, Sector O.
BYTE CONTENTS DEFINITION
Disk name padded with shifted spaces.
162-163
164-170 160
Disk ID.
Shifted spaces.
171-255 0 Nulls, not used.
Note: ASCII characters may appear in locations 180 thru 191 on some diskettes.
55
56
Table 9. 4040 BAM FORMAT
Track 18, Sector O.
0,1
2
3
BYTE
4-143
CONTENTS
18,01
65
0
DEFINITION
Track and sector of first directory block.
ASCII character A indicating 4040 format.
Null flag for future DOS use.
Bit map of available blocks for tracks 1-35.
*1=available block
O=block not available
(each bit represents one block)
Table 10. 4040 DIRECTORY HEADER
Track 18, Sector O.
BYTE CONTENTS
144-161
DEFINITION
Disk name padded with shifted spaces.
162-163
164
165,166
160
50,65
Disk ID.
Shifted space.
ASCII representation for 2A which is DOS version and format type.
166-167
171-255
160
0
Shifted spaces.
Nulls, not used.
Note: ASCII characters may appear in locations 180 thru 191 on some diskettes.
Table 11. 8050 DIRECTORY HEADER BLOCK
Track 39, Sector O.
2
3
BYTE
0,1
CONTENTS
38,0
67
0
0 4,5
6-21
22,23
24,25
26
27,28
29-32
33-255
160
160
50,67
160
0
DEFINITION
Track and sector of first BAM block.
ASCII character C indicating 8050 format.
Null flag for future DOS use.
Unused.
Disk name padded with shifted spaces.
Shifted spaces.
Disk ID.
Shifted space.
ASCII representation for 2C which is DOS version and format type.
Shifted spaces.
Nulls, not used.
57
58
0,1
2
5
6
3
4
7-10
11-140
141-255
Table 12. 8050 BAM FORMAT
First BAM block: Track 38, Sector O.
BYTE CONTENTS
0,1 38,3
DEFINITION
Track and sector of second BAM block.
2 67 ASCII character C indicating 8050 format.
5
6
3
4
0
1
51
Null flag for future DOS use.
Lowest track number represented in this BAM block.
Highest track number +1 in this BAM block.
Number of blocks unused on track l.
7-10
11-255
Bit map representation of available blocks on track l.
*BAM for tracks 2-50, 5 bytes per track.
Second BAM block: Track 38, Sector 3.
BYTE CONTENTS DEFINITION
39,1
67
0
1
51
Track and sector of first directory block.
ASCII character C indicating 8050 format.
Null flag for future DOS use.
Lowest track number represented this BAM block.
Highest track number +1 in this BAM block.
Number of blocks unused on track 5l.
Bit map representation of available blocks on track 51.
*BAM for tracks 52-77, 5 bytes per track.
Unused.
*STRUCTURE OF BAM ENTRY FOR A TRACK
BYTE DEFINITION
0
1
2
3
4 number of available sectors for track bit map sectors 0-7 bit map sectors 8-15 1=available bit map sectors 16-23 bit map sectors 24-31
O=not available
Note: "BLOCKS FREE" may appear in locations 180 thru 191 on some diskettes.
8050 DISK ZONES
The 8050 disk format uses a variable number of sectors per track according to four density zones. The BAM is made up of two blocks (see BAM structure information). The first block represents tracks 1 thru 50 and the second, tracks 51 thru 77.
TRACK NUMBER OF
RANGE SECTORS/TRACK TOTAL SECTORS ZONE BAM AREA
1-39
40-50
.......... . . . . . . .
51-53
54-64
65-77
29 1131 1 1
27 297 2 1
.
.
. . . .. . . . . . .
.
.
.
. .
.
. . . .
..
.
,
..
. . .. . . .
.
. . . .
.
. .
.
. .
.
. .
27 81 2 2
25
23
275
299
................
2083
- 29 DIRECTORY
3
4
2 BAM
2
2
2052 BLOCKS AVAILABLE
When the DOS requires access to a BAM block not currently in memory, it must be read from the diskette. Before reading in the other block, the DOS checks to see if changes have occurred to the current block.
If changes have been made, the current block is written to the diskette. The other BAM block is then read into the DOS memory.
59
60
Table 13. DIRECTORY FORMAT
BYTE
0,1
2-31
34-63
66-95
98-127
Track 18, Sector 1 for 4040
Track 39, Sector 1 for 8050
DEFINITION
Track and sector of next directory block.
*File entry 1
*File entry 2
*File entry 3
*File entry 4
*File entry 5 130-159
162-191
194-223
226-255 *File entry 8
*STRUCTURE OF SINGLE DIRECTORY ENTRY
BYTE
0
CONTENTS
128+type
*File entry 6
*File entry 7
DEFINITION
File type OR'ed with $80 to indicate properly closed file.
TYPES: 0= DELeted
1 = SEQential
2 = PROGram
3 = USER
4 = RELative
1,2
3-18
19,20
21
22-25
26,27
Track and sector of 1st data block.
File name padded with shifted spaces.
Relative file only: track and sector for first side sector block.
Relative file only: Record size.
Unused.
Track and sector of replacement file when OPEN@ is in effect.
28,29 Number of blocks in file: low byte, high byte.
BYTE
0,1
2-256
Table 14. SEQUENTIAL FORMAT
DEFINITION
Track and sector of next sequential data block.
254 bytes of data with carriage returns as record terminators.
BYTE
0,1
2-256
Table 15. PROGRAM FILE FORMAT
DEFINITION
Track and sector of next block in program file.
254 bytes of program info stored in CBM memory format (with key words tokenized). End of file is marked by three zero bytes.
61
/
/
/
/
/
POINTERS TO LINK
TOGETHER ALL BLOCKS
WITHIN A FILE
• t
SYNC 08 IDl ID2 TRACK SECTOR
CHECK-
SUM
,...; 0 r..:I r..:I
GAP 1 SYNC 07 E-< E-<
>< ><
P=I P=I
254 BYTES
OF DATA
CHECK-
SUM
NOTE:
Not to scale
~
GAP
2
Figure 4 - 2040,3040,4040 Format: Expanded View of a Single Sector
62
Figure 4 illustrates an expanded view of a single sector on a diskette formatted for the 2040.
In addition to other information, each sector contains a data block consisting of 256 stored characters. Blocks within the same file are linked together by means of a two character block pointer. By pointing to the location of the next data block, block pointers enable the system to retrieve data from non-contiguous blocks. Retrieving the first data block within a file triggers a search for the next data block which, in turn, utilizes block pointers to locate related blocks until the entire file is assembled and made available for display. All PRG,
SEQ, and USR files utilize this format.
A data block is addressed by track and sector. A 2040 diskette contains 35 tracks (or rings) numbered 1 to 35 while an 8050 diskette contains 77 tracks numbered 1 to 77. The number of sectors per track will vary (as illustrated in Table 6) due to differences in track circumference and recording frequency.
The 2040 maintains a system file on track 18 which contains the BAM, diskette name, ID, and file directory. The BAM, resident in the first 128 bytes of sector 0, monitors available and occupied storage locations on diskette. The last 128 bytes of sector 0 are used to store the diskette name and ID. The file directory begins on the next sector, sector 1.
NOTE:
Not to scale
/
/
/
/
/
SYNC 08 IDI ID2 TRACK SECTOR
CHECK-
SUM
GAP I SYNC 07
POINTERS TO LINK
TOGETHER ALL BLOCKS
WITHIN A FILE
0
+ +
,...,
~ t-< t-<
>< ><
I:Q
"" ""
I:Q
254 BYTES
OF DATA
CHECK-
SUM
GAP
2
Figure 5 - 8050 Format: Expanded View of a Single Sector
Figure 5 illustrates an expanded view of a single sector on a diskette formatted for the 8050.
In addition to other information, each sector contains a data block consisting of 256 stored characters. Blocks within the same file are linked together by means of a two character block pointer. By pointing to the location of the next data block, block pointers enable the system to retrieve data from non-contiguous blocks. Retrieving the first data block within a file triggers a search for the next data block which, in turn, utilizes block pointers to locate related blocks until the entire file is assembled and made available for display. All PRG,
SEQ, and USR files utilize this format.
A data block is addressed by track and sector. A numbered 1 to
2040 diskette contains 35 tracks (or rings)
35 while an 8050 diskette contains 77 tracks numbered 1 to 77. The number of sectors per track will vary (as illustrated in Table 6) due to differences in track circumference and recording frequency.
The 8050 maintains system files on tracks 38 and 39 which contain the BAM, diskette name, ID, and file directory. The BAM, resident in the first track
255 bytes of sectors 0 and 3 of
38, monitors available and occupied storage locations on diskette. The file directory header block, beginning on sector 0 of track the first 30 bytes.
39, contains the diskette name and ID within
63
Chapter
6
ADVANCED
FILE HANDLING
In the preceding chapters, you learned how to manipulate files on the disk, and were shown the format of commands used to create and update files. In this chapter, you will utilize these skills in a file handling application using random or relative access.
SPECIAL OPEN AND CLOSE
STATEMENTS FOR DIRECT ACCESS
The BASIC statements (after initializing the disk):
OPEN2,8,4, "#" or
OPEN2,8,4,"#12" open a channel to one buffer, to be used with the block commands. In the first example, the first available buffer is allocated to channel 4. The second example is an attempt to allocate buffer 12 to the channel. If the buffers are not available, a NO CHANNELS error condition is generated. The explicit buffer allocation can be used to reserve a buffer for position dependent code as in the case of an EXECUTE command.
Execute a GET# statement to find the number of the allocated buffer. The byte transmitted is the buffer number. A buffer number may only be obtained PRIOR TO any write or read operations to that buffer.
The CLOSE statement clears the OPENed channel and writes the BAM to the diskette that was last used by that channel. To avoid confusion, limit yourself to accessing one drive with any direct access channel.
65
66
RANDOM ACCESS EXAMPLE
Since the BLOCK-ALLOCATE command returns the next available diskette block through the error channel, it can be used in the allocation of records. This feature allows creating a random file without being concerned with the actual physical structure of the diskette.
However, the allocated blocks must first be recorded in a sequential or user file in order to be referenced by the BASIC program.
The following random file example demonstrates the use of block access commands. Notice that the Ul and U2 commands are used. These commands are used since more than one record is stored in a block, and it is necessary to manage end-of-record pointers in BASIC.
A smaller application might take advantage of the B-R and B-W commands.
Chapter 9 contains a complete listing of the random access program entitled "Random
1.00". The example program is built upon a relative record scheme and provides single record access through BASIC programming. Most of the programming below line 2000 is relative record access. The field accessing routines left-justify binary and alpha fields, and right-justify numeric fields.
In an actual situation, the program should generate error messages to the operator, or automatically take corrective action such as rounding numbers to fit a field.
It would also be possible to add data sorts and searches as well as key fields to the program. Record size, including field markers, must be less than 254 characters. Field size is restricted to 80 characters because of the restrictions of the BASIC INPUT# statement. Longer fields could be used if the BASIC program were modified to use GET# for retrieval but that procedure would be much slower.
Two sequential files are used to support the random access file in this example. Each file bears the name of the file name given in the CREATE file code (lines 1100 to 1180) plus a six-character extension. Since primary file names are ten or less characters, the file names are padded with spaces. The two files are named FILENAME .DESCR and FILENAME
.KEY01.
The descriptor ( .DESC) contains information about record structure and location. The primary key file ( .KEY01) contains the first field of each record and the relative record number. This example allows the random records to reside on a separate diskette from the sequential support files, thereby providing added room for random data. The OPEN code
(lines 1200 to 1275) requires the disk ID of the random file disk for comparison.
Note that since no file name is assigned to the random blocks, a VALIDATE should never be performed on the disk containing the random data. In order to backup the disk, a
BACKUP or DUPLICATE must be performed, since the DOS is unable to COpy without a filename.
To Create A File
STEP 1: Insert the TEST/DEMO disk in drive O.
STEP 2: Type: OPEN15,8,15 and press RETURN
Opens the command channel and initializes the diskette.
STEP 3: Type: LOAD"O:RANDOM 1.00",8 and press RETURN
This command loads the random access program.
STEP 4: Insert a blank diskette into drive 1.
STEP 5: Type: PRINT#15,"N1:MAILING LIST" and press RETURN
STEP 6: Type: RUN and press RETURN
The screen displays: "DO YOU WISH TO CREATE A FILE"?
STEP 7: Type: Y and press RETURN
The screen displays: "RANDOM FILE NAME"?
STEP 8: Type the file name: PHONE LIST
The screen displays: and press RETURN
"KEY FILE DRIVE NUMBER"?
STEP 9: Type: 1 and press RETURN
The screen displays: "RANDOM FILE NUMBER"?
STEP 10: Type: 1 and press RETURN
The screen displays: "ENTER ID OF RANDOM DISK"?
STEP 11: Type: CS and press RETURN
The screen displays: "NUMBER OF RECORDS"?
STEP 12: Type: 10 and press RETURN
For this example, ten was entered since this is the MAXIMUM number of records the file can contain.
If less records are needed, specify a number less than ten.
The screen displays:
STEP 13: Type: 4
"NUMBER OF FIELDS PER RECORD"?
and press RETURN
This is the number of 'items' each field contains.
The screen displays: "INPUT FIELD NAME, FIELD SIZE, FIELD TYPE".
TYPES: O=BINARY, l=NUMERIC, 2=ALPHA
FIELD 1?" enter: NAME,20,2 and press RETURN
FIELD 2?" enter: PHONE,15,2
FIELD 3?" enter: ADDRESS,40,2
FIELD 4?" enter: COMMENTS,40,2 and press RETURN and press RETURN and press RETURN
STEP 1: The screen displays:
Press RETURN.
The screen displays:
STEP 2: Type: COMMODORE
The screen displays:
To Add A Record
"WHOSE RECORD DO YOU WISH TO SEE?
"****ADD RECORD****"
NAME"?
and press RETURN
"PHONE"?
67
68
STEP
3: Type: 727-1130
The screen displays: and press RETURN
"ADDRESS"?
STEP
4: Type: 3330 SCOTT BLVD SANTA CLARA CA. 95051
The screen displays: "COMMENTS"?
and press RETURN
STEP
5: Type: MANUFACTURES MICROCOMPUTERS
The screen displays:
Press RETURN and press RETURN
"WHOSE RECORD DO YOU WISH TO SEE"?
The screen displays:
NAME"?
RETURN
"****ADD RECORD****"
Enter the desired name. For example: SMITH
PHONE"?
Enter the phone number: 999-356-1012 and press and press RETURN
ADDRESS"?
Enter the address: 247 MASSOL DR LOS GATOS CA. 95030 and press RETURN
COMMENTS"?
PERIPHERALS
STEP 6: The screen displays:
Press RETURN
Enter a comment. For example: MANUFACTURES and press RETURN
"WHOSE RECORD DO YOU WISH TO SEE"?
The screen displays:
NAME"?
RETURN
"****ADD RECORD****"
Enter the desired name. For example: JONES
PHONE"?
Enter the phone number: 999-268-1795 and press and press RETURN
ADDRESS"?
Enter the address: 4086 AMBER WAY SAN JOSE CA. 95117 and press RETURN
COMMENTS"?
COMPUTERS
Enter a comment. For example: and press RETURN
MANUFACTURES
The computer displays:
Enter: COMMODORE
To See A Record
"WHOSE RECORD DO YOU WISH TO SEE"?
and press RETURN
To Change A Record
After displaying the record, the screen displays:
STEP
1: Type: YES and press RETURN.
"ANY MODS"?
The screen displays: "WHICH FIELD"?
Enter the number of the field you wish to change.
STEP
2: Type: 4 and press RETURN.
The computer displays that field: US HEADQUARTERS
STEP
3: Press RETURN.
The screen display asks if there are; "ANY MODS".
STEP
4: If the record is correct, type: NO and press RETURN
Getting The Directory of Listings
The screen displays:
Type: IDIR
"WHOSE RECORD DO YOU WISH TO SEE"?
and press RETURN
The computer displays the directory.
The computer displays;
Type: II and press RETURN. The program ends.
Ending The Program
"WHOSE RECORD DO YOU WISH TO SEE"?
RELATIVE FILES 4040, 8050
Direct access of relative files is a method that allows the programmer to position to any record on the disk relative to the beginning of that file. Compare this method to the standard procedure of having to search each track and sector for the desired information and it becomes apparent that such a relative handling method would result in a great reduction in the amount of time required to find a specific record stored on disk. This reduction in the amount of time required to locate and fetch a file through the application of relative file handling techniques frees the user from the major objection to using sequential disk files: excessive "look up" time.
Both DOS 2 and 2.5 (4040 and 8050) are capable of handling relative files and should significantly reduce the amount of time spent retrieving disk files.
The two main components of a relative file are the side sector chain of blocks and the data block chain. Both are linked together through forward pointers similar to those used in a sequential file. Record sizes, while fixed in length, may range from one to 254 bytes. The number of records is limited to the capacity of the disk but for practical purposes should not exceed 65,535.
The side sectors do not contain record information, but do contain locations of the data blocks. The record size dictates where the pointer is placed when a record number is referenced because the record size is used in an algorithm to compute where the pointer is placed when a record number is given through the RECORD command. The side sector also contains a table of pointers to all of the other side sectors within the file. In order to move from one side sector to another, the pointer is referenced through the appropriate DOS command, and the corresponding side track and sector read into memory. By using the information contained in the referenced side sector, the data block pointer can be located and used to read in the actual data block containing the record. The relative file data block
69
pointers in the side sectors allow the DOS to move from one record to another within two disk read commands-a considerable savings in the amount of time required to find a desired data block when compared to sequential methods.
A file may contain up to six side sectors and each side sector may contain pointers to 120 data blocks. Therefore, the largest file on the 204 Dual Drive Floppy Disk contains
182,880 bytes (120 pointers/side sector
*
6 side sectors
*
254 bytes/block) which happens to be greater than the total storage capacity of that particular disk.
Table 16.
RELATIVE FILE FORMAT
DATA BLOCK
BYTE
0,1
2-256
DEFINITION
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
BYTE
0,1
2
3
4,5
6,7
8,9
10,11
12,13
14,15
16-256
DEFINITION
Track and sector of next side sector block.
Side sector number.
(0-5)
Record length.
Track and sector of first side sector (number 0)
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.
70
To expand a relative file, a programmer may reference the last record number generated through the RECORD command and print to that particular record. The intermediate records from the point of the current end of the file to the reference record number will be automatically generated by the DOS. This includes any side sectors and all data blocks necessary to contain a file, regardless of size, but within the capacity limits of the diskette.
For example, if the current size of the relative record is one data block long and the record number referenced would expand it to 125 blocks, then an additional side sector would be generated by the DOS since one side sector can only represent 120 data blocks.
Spanning is a key feature of relative files which aids in reducing the number of disk read/ write operations required to find and retrieve data. Before explaining how this feature of
DOS 2 and 2.5 improves time utilization efficiency, we need to examine how I/O channels are utilized by relative files:
When a channel is opened to a previously existing file, the DOS will position to the first record provided that the given parameters match properly. The record length variable is not necessary on the OPEN if the file is already in existence, but the DOS causes a check to be made against the record size that was originally made in the DO PEN statement creating the file.
If these do not match, then error
50-record not present-will be generated.
The relative channel requires three memory buffers from the system, whereas sequential files only require two. Since there are twelve channels in the system and two of these are used in directory searches and internal functions, only three relative channels can be open at one time. The highest number of buffers that can be used is ten, which limits the total number of channels which can be open at anyone time.
If a record was found to be on the boundary between two data blocks, that is, starting in one data block and finishing in another, then the DOS would read the first segment as well as any following records in the second data block. In practice, the records of most relative data files will span across data blocks. The only exceptions are record size 1, 2, 127, and
254. These divide evenly into the 254 size of the data block and spanning is unnecessary.
This method of spanning has the advantage of requiring no system memory overhead aside from that required for the side sector blocks in the relative files. When a record is written upon through the PRINT# statement, the data block is not immediately written out.
It is only written out when the DOS moves beyond the particular data block in which that record resides. This can occur through successive printing to sequential records, or when positioning to another record outside of that particular block.
Because of the spanning feature, it is recommended that two channels not be open to a relative file at the same time if either channel will be writing to the same file. An update may be made in the channel's particular memory buffer area, but the change may not be made on disk until the DOS moves that particular data block. There is no restriction on this, however, and in certain instances where the file is only read from, it may be advantageous to have more than one channel open to a single relative file.
The DOS terminates printing to a record by detecting the EOI signal which is generated with each PRINT# statement.
If the PRINT statement goes over the maximum record size, error
51-record overflow-will be generated. Any data overflow will be truncated to fit the number of characters specified by the record size and the DOS will position to the next record in sequence.
If the print statement contains less characters than the record size, the remaining positions within that record will be filled with nulls. Consequently, when positioning to a record for input the EOI signal is generated from the DOS to the computer when the last non-zero is transmitted. Should the programmer desire to store binary information, a record terminator such as carriage return will have to be used and the record size increased by one character to accommodate the terminator.
While the DOS is generating new data blocks for relative files, the requested record number is compared to the number of data blocks left on the diskette.
If the resulting number of data blocks is greater than what is left on the diskette, then error 52-file too large-is generated.
71
CREATING A RELATIVE FILE
The following examples apply only to those users equipped with both BASIC 4.0 and DOS
2. In terms of hardware, this means a 4000 or 8000 Series PET or CBM must be used as the computer and a 4040 or 8050 for the disk drive.
When a relative file is opened for the first time, the file should be initialized by the programmer to allow for faster subsequent access, and to assure that the DOS reserves sufficient space on the diskette for the future data. A simple program to perform such initialization is illustrated below:
110 DOPEN#1,"FILE1",DO,L50
120 GOSUB 190
130 RECORD#1,100
140 GOSUB 190
150 PRINT#1,CHR$(255);
160 GOSUB 190
170 DCLOSE#l
180 END
190 IF DS<20 THEN RETURN
200 PRINT DS$
210 IF DS=50 THEN RETURN
220 STOP
72
In the preceding example, line 110 creates a file with the name FILE1 and a record length of 50.
Lines 120, 140, and 160 cause the error handling subroutine to be executed.
It gramming practice to check the error channel after each disk-related operation.
is good pro-
Line 130 positions the file pointer to record number 100 which does not yet exist. The message 50 RECORD NOT PRESENT will occur at this point, but should be interpreted as a warning rather than an error condition. This message is normally expected to occur as a warning when a new record is accessed for the first time and indicates that no INPUT or GET operation should be attempted.
Line 150 causes record number 100 (because of the pointer positioned by line 130) to be written. During this write operation, the DOS detects that records 1 thru 99 do not already exist, and automatically initializes them by placing CHR(255) in the first character.
Line 170 closes the file and causes the space to be allocated in the BAM and file directory.
Lines 190-220 are the error subroutine.
If DS is less than 20, no error condition exists, so line 190 would return control to the main program. Line 200 prints the error message, and lie 210 returns to the main program if the message was 50 RECORD NOT PRESENT.
If some other unexpected error (such as a read error) occurs, line 220 will halt the program so the user can correct the problem.
EXPANDING A RELATIVE FILE
Mter the file has been initialized, data may be written to the file. Initialization of a file in this manner need be performed only once when the file is originally created.
If the user wishes to expand an existing file, the same procedure would be used, with the record number (line 130 in the example) changed to be the new last record.
The following example, when with the disk containing the file FILE1 (with 100 records) in drive 0, will result in the first 100 records remaining unchanged and records containing only CHR$(255) would be generated for records 101-200.
110 DOPEN#1,"FILE1",DO,L50
120 GOSUB 190
130 RECORD#1,200
140 GOSUB 190
150 PRINT#1,CHR$(255)
160 GOSUB 190
170 DCLOSE#l
180 END
190 IF DS<20 THEN RETURN
200 PRINT DS$
210 IF DS=50 THEN RETURN
220 STOP
NOTE: When DOPEN is used on an existing file, specification of the record length is optional.
If specified, it must match the record length set at the time the file was created or an error condition will result.
When a file is expanded in this manner, the required side sectors are also created. Side sectors are transparent to the user since they are automatically generated and accessed by the DOS.
ACCESSING A RELATIVE FILE
In order to make the relative file system practical, the user must be able to access the file for reading and writing of data. Both of these operations are simplified by relative files and both may use the RECORD command for positioning to the desired record before the operation.
To write data to a predetermined record in a file, a constant may be used in the positioning
(line 130) as follows:
110 DOPEN#1,"FILE1",DO
120 GOSUB 190
130 RECORD#1,25
140 GOSUB 190
150 PRINT#l,"RECORD 25"
160 GOSUB 190
170 DCLOSE#l
180 END
190 IF DS<20 THEN RETURN
200 PRINT DS$
210 IF DS=50 THEN RETURN
220 STOP
The resulting record would appear as follows:
1 2 3 4 5
12345678901234567890123456789012345678901234567890
RECORD 25*
Where * represents a carriage return ( CHR$(13) ).
73
The following program illustrates the feature which permits access to individual bytes within a record:
110 DOPEN#1,"FILE1",DO
120 GOSUB 900
130 RECORD#1,25,1
140 GOSUB 900
150 PRINT#l,"FIELD 1"
160 GOSUB 900
170 RECORD#1,25,10
180 GOSUB 900
190 PRINT#l,"FIELD 2"
200 GOSUB 900
210 RECORD#1,25,30
220 GOSUB 900
230 PRINT#l,"FIELD 3"
240 GOSUB 900
250 DCLOSE#l
260 END
900 IF DS<20 THEN RETURN
910 PRINT DS$
920 STOP
Lines 130, 170, and 210 cause the file pointer to be moved to different places within record number 25. The following illustration is a representation of the contents of record number
25 after the above example is executed:
1 2 3 4 5
12345678901234567890123456789012345678901234567890
FIELD 1* FIELD 2* FIELD 3*
Where * represents a carriage return ( CHR$(13) ).
NOTE: It is important that the fields be written in sequence, since writing to a byte at the beginning of the record destroys the rest of the record in memory. For example, this means that while it is possible to position and write first to byte 1 and then to byte 20, it is NOT possible to first write byte 20 and then byte 1.
74
Since the carriage return is recognized as a terminator by the BASIC INPUT statement, the data may be retrieved by the following sequence:
110 DOPEN#1,"FILE1",DO
120 GOSUB 290
130 RECORD#1,25
140 GOSUB 290
150 RECORD#I,25,I:GOSUB 290
160 INPUT#I,A$:GOSUB 290
170 RECORD#1,25,10:GOSUB 290
180 INPUT#l,B$:GOSUB 290
190 RECORD#I,25,30:GOSUB 290
200 INPUT#I,C$:GOSUB 290
210 DCLOSE#1
220 END
290 IF DS<20 THEN RETURN
300 PRINT DS$
320 STOP
Lines 160, 180, and 200 cause the stored values on disk to be read and stored in A$, B$, and C$, respectively.
It is extremely useful to be able to access a record which is determined during program operation. The following routine illustrates a procedure to query the operator for a record number and data and to write the data to the disk file:
100 PRINT "TYPE RECORD NUMBER AND DATA"
105 INPUT R,D$
110 DOPEN#1,"FILE1",DO
120 GOSUB 190
130 RECORD#l,(R)
140 GOSUB 190
150 PRINT#l,D$
160 GOSUB 190
170 DCLOSE#l
180 END
190 IF DS<20 THEN RETURN
200 PRINT DS$
220 STOP
Line 130 positions the file pointer to record number (R), specified by the user. Note that a variable used in the RECORD command must be enclosed in parentheses.
Line 150 causes the data stored in D$ to be stored on the disk.
The RECORD command may be omitted if the file is to be accessed sequentially, which saves time during program execution. An example of this occurs when writing a large data base to the disk file. Assume that the program has already dimensioned D$ as an array which contains 100 elements. These elements are to be written to the disk in records number 1 thru 100 of file FILEl. This could be accomplished with the following program segment:
110 DOPEN#1,"FILE1",DO
120 GOSUB 190
130 FOR 1=1 TO 100
150 PRINT#l,D$(I)
160 GOSUB 190
165 NEXT I
170 DCLOSE#l
180 END
190 IF DS<20 THEN RETURN
200 PRINT DS$
220 STOP
Since the record pointer is automatically set to record 1 when the file is opened, record 1 is the first record written.
If no RECORD command is executed the DOS automatically positions to the next record after each PRINT. Therefore, the contents of D$ will be written to records 1 thru 100 of the file.
For detailed description of related BASIC commands, refer to chapter 4 of this manual and the BASIC 4.0 reference manual.
75
Chapter
7
SIMPLIFYING THE USE OF
COMMODORE DISK-
RELATED COMMANDS
It has been explained that all disk commands must be preceded with the BASIC PRI1'.1'= command and enclosed in quotation marks. This is true, but your computer can be programmed to perform these tasks as well as how to load and run programs stored on diskette.
LOADING THE DOS SUPPORT PROGRAM
The first file on the TEST/DEMO diskette contains a program called UNIVERSAL
WEDGE, often referred to as DOS S'L"PPORT. This program, when loaded into memory, takes care of the tasks mentioned above.
If your computer has Commodore BASIC 4.0 you can use the quick load procedure to load the DOS SL"PPORT program. For those of you not equipped with BASIC 4.0, the following procedure will work:
Start with a cold start condition by resetting both the computer and disk drive and insert the TEST/DEMO disk in drive 0.
STEP 1: Type: LOAD"*",8 and press RETCR~.
The screen displays:
77
STEP 2: Type: RUN and press RETURN.
This will cause the DOS Support program to be executed. This program will relocate itself into the top of the user memory, where it will coexist with programs which are entered later. DOS support will not need to be reloaded until the computer is reset. The following special symbols, once implemented, will simplify the entry of disk commands.
USING THE DOS SUPPORT SYMBOLS:
>
AND
@
Once DOS SUPPORT is implemented, preceding disk commands with PRINT#lfn or enclosing them in quotation marks is no longer required: precede the disk command with either the greater than symbol (» or the at-sign (@).
The examples in this manual use the> symbol.
Examples: >10 is the same as
>SO:FILE1
PRINT#l, "10" is the same as PRINT#15, "SO;FILE1"
The OPEN statement is NOT required before a statement.
The> symbol can also be used to load a diskette directly. Normally the directory is loaded with LOAD"$dr",8 but this command destroys any program you might have in memory.
When you use the> symbol, the directory is printed directly to the screen, thus preserving the data in the computer's memory.
Examples: >$0
>$l:Q* means display the entire directory of drive O.
means to display all the files on drive 1 that begin with a Q.
NOTE: To avoid scrolling the directory, press the space bar to stop the listing. To continue the listing, press any key on the keyboard.
To stop a directory listing and return to BASIC, press RUN/STOP.
The third use of > is the request of error messages.
Example: > is equivalent to:
10 OPEN2,8,15
20 INPUT#2,A$,B$,C$,D$
30 PRINTA$,B$,C$,D$
78
LOADING A PROGRAM WITH THE
I
Use the slash (I) to load a program from diskette. Both diskettes are searched if the drive number is not specified.
Example: /ACCT loads the program ACCT into the computer's memory.
LOADING AND RUNNING A PROGRAM WITH UP ARROW
The up arrow (t) loads a program from a diskette and executes it. Both diskettes are searched if necessary.
Example: tJDATA loads and runs the program JDATA.
SPECIAL DOS SUPPORT INFORMATION
The DOS SUPPORT program has certain limitations. These are:
1.
The program must be reaccessed from the disk whenever resetting the computer.
2. DOS Support may only be used when communicating with the disk in direct mode. That is, they may NOT be used in a program.
3. The disk directory may be printed on the printer by giving these commands:
LOAD "$0",8
OPEN 4,4:CMD4:LIST
PRINT#4:CLOSE 4
NOTES
79
Chapter
8
ERROR MESSAGES-
PATTERN MATCHING
FILE NAMES-
DISK COMMANDS
REQUESTING ERROR MESSAGES: COMMODORE DISK DRIVES
The execution of the following program displays the error on the computer screen and resets the device error indicator:
CBM Series 2001
CBM Series 3000 with
BASIC 3.0
I
U::1 OPEt·~ 1
J
8 .. 15
20 INPUT#l .. A.. B$JC .. D
30 PRINT A.. B$ .. C.. D
CBM Series 8000
CBM Series 4000 with
BASIC 4.0
where A=error message number B$=error message C=track D=sector
81
SUMMARY OF CBM FLOPPY ERROR MESSAGES
o
OK, no error exists.
1 Files scratched response. Not an error condition.
2-19 Unused error messages: should be ignored.
61
62
63
64
65
39
50
51
52
60
66
67
70
71
72
73
74
24
25
26
27
28
20
21
22
23
29
30
31
32
33
34
Block header not found on disk.
Sync character not found.
Data block not present.
Checksum error in data.
Byte decoding error.
Write-verify error.
Attempt to write with write protect on.
Checksum error in header.
Data extends into next block.
Disk id mismatch.
General syntax error.
Invalid command.
Long line.
Invalid filename.
No file given.
Command file not found.
Record not present.
Overflow in record.
File too large.
File open for write.
File not open.
File not found.
File exists.
File type mismatch.
No block.
illegal track or sector.
illegal system track or sector.
No channels available.
Directory error.
Disk full or directory full.
Power up message, or write attempt with DOS mismatch.
Drive not ready. (8050 only)
DESCRIPTION OF DOS ERROR MESSAGES
NOTE: Error message numbers less than 20 should be ignored with the exception of 01 which gives information about the number of files scratched with the SCRATCH command.
82
20: READ ERROR (block header not found)
The disk controller is unable to locate the header of the requested data block. Caused by an illegal sector number, or the header has been destroyed.
21: READ ERROR (no sync character)
The disk controller is unable to detect a sync mark on the desired track. Caused by misalignment of the read/write head, no diskette is present, or unformatted or improperly seated diskette. Can also indicate a hardware failure.
22: READ ERROR (data block not present)
The disk controller has been requested to read or verify a data block that was not properly written. This error message occurs in conjunction with the BLOCK commands and indicates an illegal track and/or sector request.
23: READ ERROR (checksum error in data block)
This error message indicates that there is an error in one or more of the data bytes. The data has been read into the DOS memory, but the checksum over the data is in error.
This message may also indicate grounding problems.
24: READ ERROR (byte decoding error)
The data or header has been read into the DOS memory, but a hardware error has been created due to an invalid bit pattern in the data byte. This message may also indicate grounding problems.
25: WRITE ERROR (write-verify error)
This message is generated if the controller detects a mismatch between the written data and the data in the DOS memory.
26: WRITE PROTECT ON
This message is generated when the controller has been requested to write a data block while the write protect switch is depressed. Typically, this is caused by using a diskette with a write protect tab over the notch.
27: READ ERROR (checksum error in header)
The controller has detected an error in the header of the requested data block. The block has not been read into the DOS memory. This message may also indicate grounding problems.
28: WRITE ERROR (long data block)
The controller attempts to detect the sync mark of the next header after writing a data block.
If the sync mark does not appear within a pre-determined time, the error message is generated. The error is caused by a bad diskette format (the data extends into the next block), or by hardware failure.
29: DISK ID MISMATCH
This message is generated when the controller has been requested to access a diskette which has not been initialized. The message can also occur if a diskette has a bad header.
30: SYNTAX ERROR (general syntax)
The DOS cannot interpret the command sent to the command channel. Typically, this is caused by an illegal number of file names, or patterns are illegally used. For example, two file names may appear on the left side of the COpy command.
31: SYNTAX ERROR (invalid command)
The DOS does not recognize the command. The command must start in the first position.
32: SYNTAX ERROR (long line)
The command sent is longer than 58 characters.
33: SYNTAX ERROR (invalid file name)
Pattern matching is invalidly used in the OPEN or SAVE command.
83
84
34: SYNTAX ERROR (no file given)
The file name was left out of a command or the DOS does not recognize it as such.
Typically, a colon (:) has been left out of the command.
39: SYNTAX ERROR (invalid command)
This error may result if the command sent to command channel (secondary address
15) is unrecognizable by the DOS.
50: RECORD NOT PRESENT
Result of disk reading past the last record through INPUT#, or GET# commands. This message will also occur after positioning to a record beyond end of file in a relative file. If the intent is to expand the file by adding the new record (with a PRINT# command), the error message may be ignored. INPUT or GET should not be attempted after this error is detected without first repositioning.
51: OVERFLOW IN RECORD
PRINT# statement exceeds record boundary. Information is truncated. Since the carriage return which is sent as a record terminator is counted in the record size, this message will occur if the total characters in the record (including the final carriage return) exceeds the defined size.
52: FILE TOO LARGE
Record position within a relative file indicates that disk overflow will result.
60: WRITE FILE OPEN
This message is generated when a write file that has not been closed is being opened for reading.
61: FILE NOT OPEN
This message is generated when a file is being accessed that has not been opened in the
DOS. Sometimes, in this case, a message is not generated; the request is simply ignored.
62: FILE NOT FOUND
The requested file does not exist on the indicated drive.
63: FILE EXISTS
The filename of the file being created already exists on the diskette.
64: FILE TYPE MISMATCH
The file type does not match the file type in the directory entry for the requested file.
65: NO BLOCK
This message occurs in conjunction with the B-A command.
It indicates that the block to be allocated has been previously allocated. The parameters indicate the track and sector available with the next highest number.
If the parameters are zero (0), then all blocks higher in number are in use.
66: ILLEGAL TRACK AND SECTOR
The DOS has attempted to access a track or sector which does not exist in the format being used. This may indicate a problem reading the pointer to the next block.
67: ILLEGAL SYSTEM T OR S
This special error message indicates an illegal system track or sector.
70: NO CHANNEL (available)
The requested channel is not available, or all channels are in use. A maximum of five sequential files may be opened at one time to the DOS. Direct access channels may have six opened files.
71: DIRgectory) ERROR
The BAM does not match the internal count. There is a problem in the BAM allocation or the BAM has been overwritten in DOS memory. To correct this problem, reinitialize the diskette to restore the BAM in memory. Some active files may be terminated by the corrective action. NOTE: BAM = Block Availability Map
72: DISK FULL
Either the blocks on the diskette are used or the directory is at its limit of 152 entries for the 2040, 3040, and 4040 or 243 entries for the 8050. DISK FULL is sent when two blocks are available on the 8050 to allow the current file to be closed.
73: DOS MISMATCH (73, CBM DOS V2.5 8050)
(73, CBM DOS V2 ) for 4040
DOS 1 and 2 are read compatible but not write compatible. Disks may be interchangeably read with either DOS, but a disk formatted on one version cannot be written upon with the other version because the format is different. This error is displayed whenever an attempt is made to write upon a disk which has been formatted in a noncompatible format. (A utility routine is available to assist in converting from one format to another.) This message may also appear after power up.
74: DRIVE NOT READY
An attempt has been made to access the 8050 Dual Drive Floppy Disk without any diskettes present in either drive.
PATTERN MATCHING
Pattern matching of file names is available on all Commodore floppys. Pattern matching uses the question mark (?) and the asterisk (*) to perform operations on several files with similar names.
The asterisk is used at the end of a string of characters to indicate that the rest of the name is insignificant. For example:
FIL*
FIL or FILE1 could refer to files named or FILEDATA or FILLER or any other file name starting with the letters FIL.
The question mark may be used anywhere within the string of characters to indicate that the character in that particular position should be disregarded. For example:
?????.SRC
TSTER.SRC
or DIAGN .SRC
or PROGR.SRC
could refer to files named but not SRC.FILES
85
86
Both the characters and the position of the characters are significant.
The question mark and asterisk may be combined in many ways:
*J??????
does not make sense because the question marks are in an area which is insignificant (because of the asterisk).
P???FIL* will access files with the names
PET FILE or PRG FILE-32 or POKEFILES$$ or any other files starting with P and having FIL in positions 5-7.
SCRATCH with pattern matching should be used carefully~ since multiple files will be scratched. LOAD or DLOAD will load the first file which fits the pattern matching. OPEN or DOPEN with pattern matching may be used to open an existing file~ in which case the first existing file encountered which fits the description will be opened.
However~ OPEN or
DOPEN should not be used with pattern matching when creating a new file. Never use
RENAME~ SAVE~ DSAVE~ result~ if attempted.
or COpy for pattern matching since an error condition will
USER'S QUICK REFERENCE: DISK COMMANDS
The user~s quick reference guide will assist the user in becoming familiar with the various commands used in both BASIC 3.0 and BASIC 4.0~ and with the DOS SUPPORT utility as well as with all Commodore disk units.
In order to make BASIC 4.0 easier to use~ disk commands have been incorporated into the language. For example~ with BASIC 4.0:
• DSAVE and DLOAD commands eliminate the need to specify device number each time you store and retrieve disk files.
• Directory display is now a one-step procedure and no longer interferes with the program in memory.
• It is no longer necessary to write a program to read the error channel. The variable
DS$ contains the error message.
• Formatting is now a one-step procedure through the use of HEADER command.
Commands in BASIC 3.0 are upward compatible with BASIC 4.0. That is~ if you are familiar with BASIC 3.0~ those commands will still work on the Series 8000 Computer furnished with BASIC 4.0. All disk commands available on the 2040 are upward compatible with both the 4040 and 8050.
BASIC 3.0
SAVE "dr:fn",8
Table 17. User's Quick Reference-Disk Commands
UNIVERSAL
DOS SUPPORT
SAVE"dr:fn",8
BASIC 4.0
DSAVE, "fn",Ddr
(drive defaults to 0)
LOAD"dr:fn",8
LOAD"*",8
RUN
/dr:fn
(searches both drives) tdr:fn
DLOAD"fn ",Ddr
(drive defaults to 0)
DLOAD"fn",Ddr
RUN
LOAD"dr:fn",8
LOAD"$0",8
LIST
(destroys memory) t*
>$0
(preserves memory) shifted RUN/STOP
DIRECTORY or
DI<shifted R>
(preserves memory)
100PEN1,8,15
20INPUT#1,A,B$,C,D
30 PRINT A,B$,C,D
> return ?DS$ or ?DS
(DS is number of error only)
NOTE: Assume that OPEN1,8,15 has already been typed for all of the PRINT# commands in the following formats. Commands may be spelled out or abbreviated by the first letter as illustrated.
PRINT#l, "Ix"
PRINT#l, "Vdr"
PRINT#l, "Sdr :fn "
PRINT#l, "Dddr=sdr"
PRINT#l ,"Cddr=sdr"
PRINT#l,"Cdr :dfn= dr:sfn"
INITLIALIZE
>Ix
VALIDATE
>Vdr
SCRATCH
>dr:fn
DUPLICATE
>Dddr=sdr
COpy (all disk)
>Cddr=sdr
COPY (single file)
>Cdr:dfn=dr:sfn
PRINT#l,"Ix"
COLLECT Ddr
SCRATCH' 'fn",Ddr
BACKUP Dsdr TO Dddr
COpy Dsdr TO Dddr
COPY Ddr,"sfn" TO
Ddr ,"dfn "
PRINT#l,"Cdr:dfn= dr:sfn1,dr:sfn2, ...
PRINT#l,"Rdr :dfn=sfn"
CONCATENATE FILES
>Cdr :dfn=dr :sfl, dr:sfn2, ...
RENAME FILES
>Rdr:dfn=sfn"
CONCAT Ddr,"sfn" TO
Ddr, "dfn "
RENAME Ddr, "sfn" TO
"dfn"
PRINT#l,"Ndr :dname,xx"
FORMAT A DISKETTE
>Ndr :dname,xx HEADER "dname",Ddr,Ixx
87
Chapter
9
RANDOM 1.00
PROGRAM LISTING
This chapter provides a complete listing of the random access program described in Chapter
6 under the heading of Random Access Example.
F.:EAD'T' .
1 REM RANDOM 1.0
2 REM SUBROUTINES TO MANAGE RANDOM ACCESS FILES
3 REM VARIABLES ARE SET FROM DATA OF DESCRIPTOR FILE & KEY LIST FILES ...
4 REM ... DEFINED BY USER PROGRAM
5 REM VARIABLES SHOULD REFLECT DESIRED FILE STRUCTURE
6 REM ALL FUNCTIONS ACT UPON THE VARIABLES DEFINED BELOW
10 F.:EM
11 REM
12 REM
* .
13 POKEI022, 128:REM TURN DOS SUPPORT 3.1 OFF
15 M'=CHR$(13):REM FIELD MARKER
16 :;:;P'="
20 C0=2:
21 Cl=3:
25 CC=15:
30 D=0:
31 T=0:
32 S=0:
REM DIRECT CHANNEL
REM SEQUENTIAL CHANNEL
REM COMMAND CHANNEL
REM CURRENT DRIVE #
REM CURRENT TRACK
#
REM CURRENT SECTOR #
"+"": REt'1 :;:;PACE FOR F'ADDING
35 DD=0: REM DESCRIPTOR DRIVE #
36 F.:D=f1:
40 I D$=" " :
45 NR=0:
46 CR=0:
47 FR=0:
50 NF=0:
51 CF=0:
55 PB=0:
REM F.:At·WOt1 DF.: I '·...E
#
REt'1 PAt~DOt1 DISK ID
PEM # PECOPDS IN R-FILE
REM CURRENT RECOPD #
REM 1ST FREE RECORD UNUSED
REM # FIELDS IN RECORD
REM CURPENT FIELD #
REM # PECOPDS PER BLOCK
56 RS=0:
60 NB=0:
REM PECOPD SIZE IN BYTES
REM # BLOCKS IN P-FILE
65 E=0: REM EPPOP FLAG, OK =0
66 REM EN$,EMS.ET$,ES$,ET,ES EPROR CHANNEL VAPIABLES
70 EP=.5/256: PEM INTEGEP COPPECTI(~
75 AS=0: PEM INDEX ARPAY ADDRESSING STRATEGY
76 PEM AS=0: USE ARRAY INDEX; AS=I: T&S ARE SET, CR= RECORD OFFSET IN BLOCK
9f1 F.:EM "A" ',"'AR I ABLES AF.:E TEt'1PORAR'T'
95 DN=8:0PENCC,DN,CC: REM DN= DEVICE NUMBEP
98 GOT02000: REM START OF USER PROGRAM
99 PEt1
89
90
2*]
245
::::O~:1
:X11
3[12
305
31'.:1
315
:::2~:1
'-"-,E:"
'':''::''-'
501
5f12
5W
515
520
53(1
C='-,C' oJ·:.·;.)
435
44'.:1
45'.:1
451
452
455
46'.:1
465
470
475
4:::0
5(1'.:1
:~:35
340
400
401
402
4~]5
4W
415
42[1
425
43~]
1[10
Wl
1 ~]~:
103
1[15
110
111
115
12[1
125
130
135
14'.:1
145
146
150
151
155
160
165
17[1
175
2~X1
2~:11
202
2'.:15
210
215
220
230
F:Et1
FH1
F:H1
....t.t...t.t.t.t.t.t.t.tt...t.t.t.t.t.t.t.t.t.t.
RANDOM FILE DIMENSION ROUTINE
1ST SET NR, NF
F:Et1
GO:::UB 15'.:1
& NB
IFFP%=-lTHENRETURN
FP;·;=-l
D!t'1 F:::;'; (t'~F)
DI t1 FP;'; (t·jF)
F:H1
D1t'1 FT ;.; (t'~F )
DIt1 FH$O'W)
DH1 F$O·F'
DI~1 F(~W)
RETUF.:t·j
:F:Et1 FIELD ::: I ZE
:REM FIELD POSITION
FP%(I)= SUM [FS%(I-l)]
:REM FIELD TYPE: 0:BINAPY,
:REM FIELD HEADING
REM FIELD ARGS-ALPHA,BINAPY
:REM FIELD ARGS-Nl~ERIC
IFIT%=-lTHENRETURN
IT;';=-l
DIt1 IT ;.; (t·m )
DI t1 I:::;';
(m:)
DI t1 1< 1 $( t~RI
DI ~1 RF.:;·; (t·W)
REM TRACK INDEX ARRAY
REM SECTOR INDEX ARRAY
REM PRIMARY KEY VALUE
:REM PELATIVE RECORD LIST PER KEY
RETURt·~
REM f.t.t.t.t.f.f.tt.tttttttt.tt.tt. .. t.t.t
REM UPDATE RECORD, CR
2 ALPHA
FH1
GC6UB900
PF.:ItH#CC .. "Ul : "C0.: D.: T.: :::
PF.:IHT#CC .. "B-P: "C0.: PP
FORCF= 1 TOt~F
GOSUB5~X1 t'~E::<TCF
PRItH#CC .. "U2: "C[1.: D.: T.: :::
GOSUB1000:IFETHEN1900
RETUF.:t·j
REM t.ttf.tttttttttt.t.ttttt.t.t.tt.t.
REM READ RECORD, CR
REt1
GC6UB9~X1
PF.:ItH#CC, "Ui : "C0.: D.: T.: :::
PF:ItH#CC .. "B-P: "C0; PP
GOSUB1000IFETHEN1900
FOPCF=l TOt'~F
GOSUB6~Xl t'~E::-::TCF
RETUF:tj
REM t.t.t.tt.t.t.tt.t.t.tt.tt.tttttttttt.
PEM UPDATE FIELD(CF) OF PECORD CR, SINGLE FIELD UPDATE
REt1
GOSUB9[10
PRItH#CC .. "Ul : "C0.: D.: T.::3
GOSUB1000:IFETHEN1900
PI': It-H#CC .. "B-P: "C[1.: FP;·;(CF)+F.:P
GOSUB500 :REM UPDATE FIELD
PPINT#CC, "U2: "C0;D;T;S
GOSUB1000:IFETHEN1900
F:ETUF.:t·~
REM .... ttf.tf.tttttttttttttttttt
REM READ FIELD(CF) OF RECORD CR .. SINGLE FIELD READ
PEM
GO:::UB9[1[1
PPIt-H#CC, "Ul : "C0.: D.: T.: :::
GC6UB 100[1 : I FETHEt·~ 19[10 pF.:nH#CC .. "E:-P: "C0.:FP;·;(I::F)+f':P
GOSUB600 :REM READ FIELD
RETURt·~
PEM ttttttttttttttttttttttttt
REM UPDATE FIELD(CF), B-P IS SET
REM
IFFT%(CF)()lTHEN520
A$=RIGHT$(SP$+STR$(F(CF»,FS%(CF»:GOT0530
AS=LEFT$(FS(CF)+SP$,FS%(CF»
PRItH#C[1 .. AS.: ~1$:
RETUf':tj
6013 REM .
601 REM READ FIELD(CF), B-P IS SET
6132 REM
610 IF FT%CCF) THEN645
615 Al$=""
620 FORJ=lTOFS%CCF)
625 GET#CO, A$: IFA$=""THENA$=CHI":$O~1)
6:30 Al$=Al$+A$
6:35 NEXT:F$(CF)=Al$
640 GET#C0,A$:RETURN
645 INPUT#C0,F$(CF)
650 IFFT%CCF)(>lTHEN RETURN
655 FCCF)=VALCF$CCF»:RETURN
700 REM •••••••••••••••••••••••••
& S =REQUESTED TRACK & SECTOR 701 REM ALLOCATE ONE BLOCK, T
7(12 REM RETUR~~ED T 8: :::; AF.:E ALLOCATED VALUES o::T=18 IS SKIPPED)
70:::: F.:EM
710 GOSUB800:IFETHEN1900: REM CHECK T
71~ PRINT#CC, "B-A: "D;T;S
720 INPUT#CC,EN,EM$,ET,ES
725 IFEN=0THENRETURN
7:30 IFEN()65THEN1900
7:35 IFET=18THENT=19:S=0:GOT0715
7::::6 T=ET: S=ES
& S
740 GOT0715
750 REM •••••••••••••••••••••••••
751 F.:Etol FI":EE Ot~E BLOCK., T ~~ :::; = TRACK 8: SECTOR
752 REM
760 GOSUB800:IFETHEN1900: REM CHECK T & S
770 PRINT#CC, "B-F: "D;T;S
780 INPUT#CC,EN,EM$,ET,Es
785 IFEN=0THENRETURN
79(1 GOTO 19(10
800 REM •••••••••••••••••••••••••
801 REM CHECK MAX SECTOR
802 REM
810 IFT>:35THEN1900
820 E=0:IFT=0THEN=40:GOT01900
840 A:3= 16 : I FT):30THEt~880
850 A:3=17:IFT)24THEN880
860 A:3=19: IFT)17THEN880
870 A::::=2(1
880 IFS>A:3THEN1900
89(1 RETURt~
900 REM ••••••••••••••••, ••••" ••
901 REM SET RECORD"S TF.:ACK, SECTOR ~:: RECOl":D POIt-4TER FF.:Ot'l nUiE:x: ARRA'T'S
902 REt1
905 D=RD
9H3 E=0
915 IFAS=-lTHENRP=CRf.RS+l:GOT0950
92(1 I":P= INT C(CR-l ),/RB+EP) : I FF:p>t·m OR RP<)3THEt~EN=41: GOTO 19(u3
9:30 T=IT%CRP):S=IS%CRP)
940 RP=INTCCCCR-l)/RB-RP+EP).RS.RB)+l
950 IFRP)254THEN EN=41:GOT01900
960 RETURt·~
1000 REM •••••,.,." ••,.,•••" ••, .
1001 REM INPUT 2040 ERROR STATUS
1002 REt1
1005 INPUT#CC,EN$,EM$,ET,ES
1010 EN=VALCEN$):E=0
1015 IF EN$= "00" THEt·~ RETURN
1017 ET$=STR$CET):ES$=STR$CES)
1020 IFEN$(>RIGHT$("0"+MID$CSTR$CEN),2),2)THEN1070
10:30 IF H~= 1 THEN Erl$= ET:f+" "+Et'1$: RETUF.:~~
11335 E=E+l
1(14(1 EM$=u ~"+EN$+U!!!
u+Et1$
1050 IF H~{30 01": EN=65 THEN EM$=EM$+u ON u+ET$+"., "+ES$
1060 RETUF:~~
1070 EM$=" ~'r'STEM ~~OT F.:ESPOt·Ui I t·~G PI":OPERL'r'"
1080 EM$=EM$+EN$+EM$+ET$+ES$
1085 E=E+l
1(19(1 RETUl":t~
91
92
1110
1115
1116
1120
1121
1122
1123
1124
1126
1130
1135
114(1
11 ~)(1
IHH
I1f12
1103
11(14
11(15
11 [16
11(19
1145
1150
1152
1155
1160
1165
1166
1167
116:::
1215
1220
1
·-,·-,<::,
0::.'::',_1
1226
1227
123~:1
1235
1240
1245
1250
1255
126(1
1170
1175
11 ::::~:1
1200
1201
1202
1203
1204
12(15
12(19
1210
1402
14(19
1410
1420
143~)
1440
1490
1900
1265
1270
1
·-,-,,,,
.::.. i
._1
12:::0
12:::5
12:::6
129~)
129:::
1299
1400
14(11
REM t.****t.****t.t.*t.*t.*******t.*
REM CREATE DESCRIPTOR FILE
REM INPUT: FS= FILENAME
REM IDS,NR,NF,FS%(),FT%(),FHS()
REM
REM
DD= DESCRIPTOR FILE DRIVE #
RD= RANDOM DISK DRIVE #
REM DRIVES MUST BE INITIALIZED
F.:Et'1
R::::= 1 : D=RD
FORAO=lTONF:FP%(A0)=RS:RS=FS%(AO)+RS+l:NEXT:RS=RS-l
RB=INT(254/RS+EP)
OPEt·jCO., Dt-j., CO, "#" : GO:::;LIB 1(11)(1 : I FETHEt·j 190~:1
CiO:;UB 12:::0
PRItH#CC, "B-P: "C0.: 1
FORA0=lTORB:FORA1=lTONF
PRINT#CO,LEFTS(SPS,FS%(Al»;MS; t·jD<TA 1, A(l
NB=INT(NR/RB+EP):IF(NR/RB-NB)t.RB)=lTHENNB=NB+l
T=1:S=0:GOSUB150
FORAO=0TONB-l:GOSUB710:IFETHEN1900
IT%(AO)=T IS%(A0)=SGOSUB430:NEXT
GO:::UB710
PRItH#CC, "B-P· "CO.: 1
PRINT#CO,NR;MS;I;MS;NB;MS;RS;MS;RB;MS;NF;MS;
PRItH#CC, "B-(,J: "CO.: D.: T.: :::
AS=::::TRHDD)+" : "+LEFTS(FS+:3PS, 1(1)+". DESCR, U., (~"
OPEt·jC 1, Dt-j .. C1, AS
GO::::UB 1(lIXl : I FETHHj 190(1
PRINT#Cl,IDS;MS;T;MS;S;MS;
FORA0=ITONF:PRINT#Cl,CHRS(FS%(A0»;CHRS(FT%(A0»;FHS(A0);MS; : NEXT
FORA0=OTONB-l:PRINT#Cl .. CHRS(IT%(A0»;CHRS(IS%(A0»; :NEXT
CLOSEC1:CLOSECO:RETURN
REM *t.'t.t.t.t.*t.t.t.t.t.t.t.t.ttt.t.tt.tt.t.
REM OPEN RELATIVE FILE
REM INPUT: FS= FILENAME
REM
REM
DD= DESCRIPTOR FILE DRIVE #
RD= RANDOM DISK DRIVE #
REM DRIVES MUST BE INITIALIZED
REt1
AS=:::TRS(DD H" : "+LEFTS(FS+SPS, 10)+". DESCR., U.. F.:"
OPENC1,DN,Cl,A':GOSUBI000:IFETHEN1900
INPUT#Cl,IDS,T,S
OPEtK:O., Dt-L CO, "#" :GO:::UB1(1I)O: I FETHHH 9~)~)
GOSUB12:::0
PRItH#CC., "B-R: ".: C(l.: RD.: T.: S: GO:::UBI0(1tl: IFETHEtH9(1I)
INPUT#C0,NR,FR,NB,RS .. RB,NF
CiOSUB100:FT%(0)=TFS%(0)=S
FORA0=1TONF:GOSUB129::::FS%(A0)=ASC(AS)
GOSUB129::::FT%(A0)=ASC(AS)
INPUT#Cl,FHS(A0):NEXT
FORA0=0TCNB-l :GO::::UBI298: IT;·;(A~:l)=ASC(AS)
GOSUB129::::IS%(A0)=ASC(AS):NEXT
GOSUB1000:IFETHENI900
CLOSECl
F.:ETURt·j
PRItH#CC .. "Ul : ".: C0.: F::D.:"., 1:::.,0": GOSUB1(1I)O: I FETHEt·H 9(1(1
PRItH#CC, "B-P: ".: C(l.: 162
CiET#CO,A',A1S:A'=AS+A1S:IFIDS()ASTHENEN=43:EMS="WRONG RAND DISK":GOT01900
F.:ETUF.:t·j
CiET#C 1., AS : I FAS=" "THEt·jAS=CHRS «(1)
RETURt·j
REM t.t.t.t.tt.*t.t.t.t.t.t.t.*t.t.tt.t.*t.t.t.t.
REM CLOSE RELATIVE FILE
REM INPUT: VARIABLES FROM OPEN SHOULD BE VALID
REt1
PRItH#CC" "B-P: "CO 1
PRINT#C0,NR;MS;FR MS;NB;MS;RS;MS;RB;MS;NF;MS;
PRItH#CC, "B-(·j: "C(l D.: FT;·;(~:1).: F:::;·;«(1)
CLC6EO:l
RETUF.:t·j
E=E+1 : F.:ETUF.:t·j
200(1 mpUT"::m~lDO 'T'OU ~H:::H TO CPEATE A FILE t·~.II'''.:A$: IFLEFT$(A$ .. 1)<>'''T'''THEt·Q1(10
2001 HWUT":~F.:At·mOt'1 FILE t·~At'1E".: F$
2(H~12
2(H~n I
I t·WUT "VE'T' FILE DF.: I '·lE t·Klt'1BEP".: DD t'~PUT" PAtmOt'1 FILE DP I ',,IE t·~Ut·1BEF.:".: F.:D
2005 mpUT"Et-nEP ID OF F.: At·mOt·1 DISf<
2(H36 I t·WUT" t·~Ut'1BEF.: OF PECOF.:DS".: t·~p
III'''; ID$: ID$=LEFT$( ID$ .. 2)
2007 I t'~PUT" t·Wt'lBEP OF FIELDS PEP F.:ECOPD".: t'~F
2010 CiC6UB 11 0
2015 PPINT"~ INPUT FIELD NAME .. FIELD SIZE .. FIELD TYPE"
2(116 PP I NT"
2(119 P:::=O n'PE::: : O=B I t·~AP'T'..
1 =t'~U~1EP I C..
2=ALPHA:~l"
202(1 FOP I = 1 TOt'~F : PP I tH" FIELD" .: I., : I t·WUTFH$ ( I ) ..
2025 A$=" I " : I FDD=PDTHENA$=" I "+:::TP$ (DD)
2030 PPINT#CC,A$
F:::;'~ ( I ) .' FT;'~ ( I ) : PS=FS;'~ ( I ) +F.:S+ 1 : t'~E::<T
2040 CiOSUB1100:IFETHEN3900
205~3 OPEtH .. ::: .. 4 .. :::TF.:$(DD)+": "+LEFT$(F$+SP$., 1(1)+". f<E'T'01 .. U., ~.j"
2055 PRINT#4,0;M$; :CLOSE4
2~390 CiOT02120
2100 PEM OPEN RANDOM FILE FOP ACCESS
2103 I t·iPUT" :~F:At-mot'1 FILE t·~At'1E".: F$
2105 HWUT" KE'T' FILE DP !'olE t·~Ut'lBEF.:".: DD
2110 mpUT"RAt·mOt'1 FILE DF.T·lE t~Um:EP".: r;~D
2120 CiOSUB1200:IFETHEN3900
2140 OPEtH .. :::" 4., :::TP$(DD)+": "+LEFT$(F$+SP$ .. 1(1)+". f<E'T'(11 .. U"
2142 INPUT#4 .. RR:IFRP=OTHEN2147
2145 FORI=1TOPp:INPUT#4 .. f<1$(I) .. PP%(I):NEXT
2147 CLO:::E4
2150 PP I t-n ":1~O t:Ht·1PLE F.: At·mo t'1 ACCE:::::::~l"
2155 PPHH"T'r'PE / TO OUIT)iI"
2156 PF.: It-n" (H IT PETUPt·~ TO ADD F.:ECOPD)"
216~3 PF.:lt-n":~lll.1,jHOSE PECOF.:D DO 'T'OU"
2161 mpUT"~·n:::H TO :::EE
2165 I FPP:i'=" "THa~2:31 0
.'1'''.:
PI':$
2167 IFRP$="//"THEN2400
216::: IFRP$="/DIP"THENCiOSUB4000:GOT02160
2170 FORII=1TOPP:IFf<1$(II)<>PR$THENNEXT:CiOT02300
2175 CR=RR%(II):GOSUB300
218(1 FORI=1 TONF: PRItHI.:") "FH$( I)" :" .. F$( I): t'~E>::T: PF.:HH
21:::5 FF=(1
2190 It~PUT"At'~'T' t'lODS
.11'" .:
2195 mpUT" ~,jH I CH FIELD".: A
A$ : I FLEFT$( A$ .. 1 ) <> '"T''' THEt~222(1
22(10 PRHH" "F$(A): PF.:It-n"~" ,: : HWUTF$(A): F(A)=VAL(F$(A»
2210 FF=1:CiOT02190
2220 IFFF=0THEN2160
2222 IFA=1THENf<1$(II)=F$(A)
2225 GC6UB2~30
2230 GOT02160
2300 PI': I t-n ":~F.:ECORD tKiT PF.:E:::Et-H"
2305 It-lPUT"DO 'T'OU ~H:::H TO ADD".: A$: IFLEFT$(A$ .. 1 )<>'''T'''THEt~2160
231 0 pr;~ I tH" :~lH:H AnD PECOF.:D :H:H:~l~]"
2312 IFFR>NRTHEN2500
2315 CR=Fp:FR=FR+1:RR=RR+1
2320 FORI=1TC~F:PRINTFH$(I); :INPUTF$(I):F(I)=VAL(F$(I»:NEXT
233~3 GOSUB2(1(1
2340 f<1$(RR)=F$(1):PR%(RR)=CR
2::::5(1 GOT02161:1
24(H~1 F.:Et'1 CLOSE RAt·m FILE
24135 CiOSUB 140~~1
241(1 OPEt~4 .. :::., 4 .. "I!"+STF.:$(DII)+" : "+LEFT$(F$+:::P$ .. 1(1)+". f<E'r'01 .. U.,
2420 CiOSUB 1(1(1(1 : I FETHaB9~3(1
2430 PRINT#4,PP;M$;
2440 FOPI=1TORp:PPINT#4 .. f<1$(I);M$;RP%(I);M$; :NEXT
2445 GO:::UB 1 (H~H3 : I FETHEt-j::::9~~10
245~~1 CLOSE4
2455 GOSUB1000:IFETHEN3900
249~) POI<E 1022 .. ::: : am : F.:Et'1 TUF.l~ DOS SUPPOPT 3. 1 Ot·~
W
25(H) PI': ItH" THE FILE I ::: FULL.. t·JO ADD IT IOt~AL RECOF.:D::: t1A'T' BE ADDED"
251 ~3 CiOT0216(1
3900 PRINTE .. EM$:STOP
4000 FORDI=OTONp:PPINTf<1$(DI):NEXT:PETURN
93
Cha
p
ter
10
INDEX
AC power cord, 3
Advanced disk programming, 47
Advanced file handling, 65
At symbol (see DOS Support)
BACKUP (BASIC 4.0 direct command), 29
BAM, 22,47
Format
2040,3040,55
4040,56
8050,58
Memory requirements, 22
BASIC commands
CLOSE command, 39
DCLOSE command, 40
DLOAD command, 36
DOPEN command, 39
DSAVE command, 36
GET# command, 43
INPUT# command, 42
LOAD command, 36
OPEN command, 38
PRINT# command, 41
RECORD# command, 43
SAVE command, 36
VERIFY command, 37
BASIC commands, disk drive, 35
BASIC 4.0 direct commands
BACKUP command, 29
COLLECT command, 28
CONCAT command, 31
COpy command, 31
RENAME command, 32
SCRATCH command, 33
Block availability map, 22
Block distribution, by track, 54
BLOCK-ALLOCATE command, 51
BLOCK-EXECUTE command, 50
BLOCK-READ command, 49
BLOCK-WRITE command, 50
Block pointer, 26
Buffer number, 65
BUFFER-POINTER command, 50
Business keyboard, 14,17
Bus, IEEE, 12
Cables, 11
PET to IEEE, 11
IEEE to IEEE, 11,
CHR$ function, 41, 42, 48, 49, 51, 52
CLOSE command, 39
Closing the command channel, 40
Closing the data channel, 41
COLLECT (BASIC 4.0 direct command), 28
Command channel, 40
Compatability
BASIC versions, 35
Disk drives with computers, 3
Series 2001, 3
Series 3000, 3
Series 8000, 3
DOS versions, 69
CONCAT (BASIC 4.0 direct command), 31
COpy (BASIC 4.0 direct command), 31
COpy command, 31
Data blocks, 69
Data channel
Closing, 41
95
96
Data file
Concatenation, 29, 30
Copying, 29
Renaming, 31
Data handling, 35
BASIC commands for, 35
DCLOSE command, 40
DEMO diskette (see TEST/DEMO diskette)
Description of DOS error messages, 81
Descriptor (.DESC), 66
Device number, 35
Diagnostic boot, 18
Direct access, 65
Special OPEN and CLOSE statements,
65
Directory, 26
Loading, 26
Printing, 27
DIRECTORY (BASIC 4.0 direct command),27
Directory format, 60
Directory header
2040,3040,55
4040,56
Directory header block, 8050, 57
Diskettes
Care of, 9
Inserting diskettes
2040,3040,4040,13
8050,13
Disk maintenance commands, 23
BACKUP (BASIC 4.0 direct command),
29
COLLECT (BASIC 4.0 direct command),
28
COPY (BASIC 4.0 direct command), 31
COPY command, 29
CONCAT (BASIC 4.0 direct command),
31
DIRECTORY (BASIC 4.0 direct command, 27
DUPUCATE command, 28
Limitations due to formats, 28
HEADER (BASIC 4.0 direct command),
25
NEW command, 24
VALIDATE command, 28
RENAME (BASIC 4.0 direct command),
32
RENAME command, 31
SCRATCH (BASIC 4.0 direct command),33
SCRATCH command, 32
Disk maintenance commands
Diskette level, 23
File level, 23
Disk operating system, 15,18,22,25,47,
59,69,70,71,72,77
Disk programming, advanced, 47
Disk utility command set, 48
BLOCK-READ, 48, 50
BLOCK-WRITE, 48, 50
BLOCK-EXECUTE, 48, 50
BUFFER-POINTER, 48, 50
BLOCK-ALLOCATE, 48, 51
MEMORY, 51
Memory-Write, 48, 51
Memory-Read, 48, 52
Memory-Execute, 48, 52
USER, 48, 52
Disk zones, 59
DLOAD command, 36
DOPEN command, 39
DOS,15,18,22,25,47,59,69,70,71,
72,77
DOS support, 22, 77
Loading DOS support, 15, 18, 77
Loading a program, 14,17, 78
Loading and running a program, 15,18, 78
Special DOS support, 79
Using DOS symbols> and
@,
78
Limitations, 79
Disk backup, 15, 18, 66
Disk drive
Care of, 9
Description, 3
Front panel, 3
Back panel, 3
Interior configuration, 4
Connecting to computer, 11
Power-on test, 12
Performance tests, 14, 17
Specifications, disk drives, 5, 6, 7, 8
Unpacking, 9
Disk ID, 24, 25, 26
DSA VE command, 35
EOI signal, 71
Error messages, 81
Description of DOS error messages, 82
Requesting error messages, 81
Summary of error messages, 82
Expanded view, single sector
2040 format, 62
8050 format, 63
Field fitting, 66
File format, program, 61
File handling, advanced, 65
File pointer, 43
Floppy disk hookup, 11
Format
BAM
2040,3040,55
4040,56
8050,57
Directory, 60
2040,3040,55
4040,56
8050,57
Formatting, 24, 25
GET# command, 41
HEADER (BASIC 4.0 direct command), 25
High byte, 48, 51
Hookup, floppy disk, 11
ID, 24, 25, 26
IEEE-488 interface, 4,11,47
Indicator lights (see LED indicator lights)
INPUT# command, 42
I/O channels, 22, 47, 71
Inserting diskettes
2040,3040,4040,13
8050,13
Initialization
2040 and 3040,25
4040,26
8050,26
Job queue, 47
Key file, primary (see primary key file)
LED (light emitting diode; see LED indicator lights)
LED indicator lights, 3, 12, 18, 81
Limitations, DUPLICATE command, 28
Line feed, suppression of, 41
LOAD$ command, 26
Loading
DOS support, 77 a program with a slash (I) symbol, 78 and running a program with up arrow
(t) symbol, 79
Low byte, 48, 51
Magnetic fields, 9
Maintenance commands, disk, 23
MEMORY commands, 51
MEMORY-WRITE command, 51
MEMORY-READ command, 52
MEMORY-EXECUTE command, 52
OPEN command, 38
Operating system, disk, 15, 18, 22, 25,47,
59,69,70,71,72,77
Parameters, 48, 49
Parms,48
Pattern matching, 85
Performance test
4040/8050, 14
2040/3040, 17
POKE command, 14, 17
Pointer, block, 26
PRG file, 36, 61
Primary key file (.KEY01), 66
PRINT# command, 41
Program file, 61
Program file format, 61
Quickload feature, 44
Quick reference: commands, 86
Random access
Add a record, 67
Change a record, 68
Create a file, 66
Ending the program, 69
Example, 66
Field markers, 66
Field size, 66
Restrictions, 66
Getting directory of listings, 69
Primary file names, 66
Primary key file, 66
Record size, 66
See a record, 68
Reading list, 4
RECORD# command, 43
Record pointer, 43
Relative files, 69
4040,8050,69
Accessing, 73
Block pointers, 70
Channel restrictions, 71
Creating, 72
DOS compatability, 69
Expanding a file, 70
Format, 70
Main components, 69
Record size, 69
Side sectors, 69
Side tracks, 69
Storage capacity, 70
RENAME (BASIC 4.0 direct command),
32
RENAME command, 32
Requesting error messages, 81
Safety feature, HEADER command, 25
SAVE command, 36
SCRATCH (BASIC 4.0 direct command),
33
SCRATCH command, 33
Screen displays, actual, 14, 15, 16, 17, 18,
19,26,37,40,44,45,77,81
Secondary address, 35, 38,42,47, 50
Sector, single: expanded view, 70
Sequential format, 61
Side sectors, 69
Side track, 69
Simplifying commands, 77
Single record access, 65
97
98
Single sector, expanded view, 70
Slash (I) symbol (see DOS support)
Spanning, 71
Specifications
8050,6
2040/3040, 7
4040,8
Standard jump table, 53
Summary
BASIC commands, data handling, 35
Disk commands, 86
Disk maintenance commands, 23
Disk utility commands, 48
Error messages, 81
Suppression of line feeds, 41
Symbols, DOS support, 78
Tab, write protect, 13
Tape to disk, 45
TEST/DEMO diskettes, 9,14,17,23
Ul command, 52
U2 command, 52
Universal wedge, 23, 77
Up arrow (t) symbol (see DOS support)
USER command, 52
User's quick reference: disk commands, 86
Utility commands, disk, 48
VALIDATE command, 28
VERIFY command, 37
Wedge (» symbol (see DOS support)
Write protect tab, 13
(:: commodore
Commodore Business Machines, Inc.
3330 Scott Boulevard
Santa Clara, California 95051
Download
Advertisement
Key features
Dual floppy drive
IEEE-488 interface
Intelligent peripheral
LED indicators
Diskette doors
Front panel
Back panel
Power switch
Fuse
Interface connector
Frequently asked questions
The Commodore 3040 has a total capacity of 176640 bytes per diskette, with sequential and random access options. It supports 152 directory entries, 17-21 sectors per track, and 256 bytes per sector.
The Commodore 3040 has a height of 6.5 inches, a width of 15.0 inches, and a depth of 14.35 inches.
The Commodore 3040 requires 100, 220, or 240 VAC at 60 Hertz with a power consumption of 50 Watts.