Block-Free - Commodore 1541 User Manual

Disk drive
Hide thumbs Also See for 1541:
Table of Contents

Advertisement

How do you know which blocks are available to use? If you try a block that isn't
available, the DOS will set the error message to number 65, NO BLOCK, and set the
track and block numbers to the next available track and block number. Therefore, any
time you attempt to write a block to the disk, you must first try to allocate that block.
If that block isn't available, read the next block available from the error channel and
then allocate that block.
EXAMPLE OF PROCEDURE TO ALLOCATE BLOCK:
DRIVE
10
OPEN15,8,15
20
OPEN5,8,5,"#"
30
PRINT#5,"DATA"
40
T=1:B=1
50
PRINT#15,"B-A:"0;T;B
60
INPUT#15,A,B$,C,D
70
IF A=65 THEN T=C:B = D:GOTO50
80
PRINT #15,"B-W:"5;0;l;l
90
CLOSE5:CLOSE15
BLOCK-FREE
The BLOCK-FREE command is the opposite of BLOCK-ALLOCATE, in that it
frees a block that you don't want to use anymore for use by the system. It is vaguely
similar to the SCRATCH command for files, since it doesn't really erase any data from
the disk — just frees the entry, in this case just in the BAM.
FORMAT FOR BLOCK-FREE COMMAND:
PRINT#file#, "BLOCK-FREE:" drive; track; block
or abbreviated as
PRINT#file#, "B-F:" drive; track; block
USING RANDOM FILES
The only problem with what you've learned about random files so far is that you
have no way of keeping track of which blocks on the disk you used. After all, you can't
tell one used block on the BAM from another. You can't tell whether it contains your
random file, just part of a program, or even sequential or relative files.
To keep track, the most common method is to build up a sequential file to go with
each random file. Use this file to keep just a list of record, track, and block locations.
This means that there are 3 channels open to the disk for each random file: one for the
command channel, one for the random data, and the other for the sequential data.
This also means that there are 2 buffers that you're filling up at the same time!
31

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents