Allocating Blocks; Freeing Blocks - Commodore 1541 User Manual

Hide thumbs Also See for 1541:
Table of Contents

Advertisement

pointer to the first file type byte
(see
Appendix C for details of directory
organization)
locking
it
by
setting
bit 6 and rewriting
it.
'
110 OPEN
15,8,
15
120 OPEN 5,8,5
, "
#"
130 PRINT#l5,
"Ul
"
;5;0;18 ;1
140 PRINT#l5,"B-P"
;5;2
150 GET#5 ,A$:IF A$=
""
THEN A$=CHR$(0)
160 A= ASC(A$) OR
64
170 PRINT#l5
\"
B-P" ;5;2
180 PRINT#5,CHR$(A);
190 PRINT#l5 ,"U2" ;5;0;18;1
200CLOSE
5
210 CLOSE 15
220 END
Open
command
channel
Open direct access
channel
Read Track 18, Sector
I
Point to Byte 2 of the
buffer
Read it into memory
Tum on bit 6 to lock
Point to Byte 2 again
Overwrite it in buffer
Rewrite buffer to
diskette
Tidy up after
After the above program
is
run
,
the first file on that diskette can no longer be
erased
.
If
you later need to erase that file, re-run the
same
program, but substitute the
revised line
160 below to unlock the file again:
160 A=ASC(A$) AND 191
Tum off bit 6 to unlock
ALLOCATING BLOCKS
Once you have written
something in a
particular
sector
on a diskette with the
help
of
direct
access commands,
you may wish to mark that
sector
as
"already
used,
"
to
keep
other files from being written there. Blocks thus
''allocated''
will be
safe
until the
diskette
is validated.
FORMAT FOR BLOCK-ALLOCATE
COMMAND:
PRINT#l5
,"
BLOCK-ALLOCATE";drive #
;
track #;sector#
usually abbreviated
as:
PRINT#l5,"B-A";drive #
;
track #;sector#
where
"
drive#
"
is
the drive number, always 0 on the 1541, and
"
track#" and
"sector
#" are the track and
sector
containing the block of data to be read into the file
buffer.
ALTERNATE
FORMAT:
PRINT#l5,"B-A:";drive #;track # ;sector#
EXAMPLE:
If
you
try
to allocate a block that isn
'
t available, the DOS will
set
the error
message
to number 65, NO BLOCK
,
and
set
the track and block numbers
in
the
error
message
10
70
the next
available
track
and
block number. Therefore
,
before
selecting
a
block to
write,
lf'f
to allocate that block
.
If
the block isn
'
t
available; read
the next
available block from
the
error
channel
and allocate it
instead.
However,
do not
allocate
data
blocks in
the
directory track
.
If
the track number returned is
0,
the diskette
is full.
Here
is a
program that
allocates
a
place to store
a message on a
diskette
.
100
OPEN15
,8,
15
110 OPEN5
,8,5
,
"#"
120 PRINT#5
,
"I
THINK
THEREFORE I AM
"
1JOT=
l :S= I
140
PRINT#l5
,"B-A";O;T;S
150 INPUT#l5 ,EN,EM$ ,ET,ES
160 IF
EN
=0
THEN
210
170 lF EN <>65 THEN PRINT
EN ,EM$ ,ET
,ES:STOP
180
IF
ET
=
0 THEN PRINT
"DISK FULL":STOP
190
IF
ET
=
18 THEN ET
=
19:ES
=0
200T=ET:S =ES:GOTO 140
210
PRINT#l5
,"
U2 ";5;0;T;S
220
PRINT
"STORED
AT:"
,T,S
230
CLOSE 5:CLOSE 15
240
END
FREEING
BLOCKS
Open
command
channel
"
direct
access
"
Write a message to buffer
Start at first track &
sector
Try allocating it
See if
it
worked
If
so,
we're almost done
"
NO
BLOCK"
means already
allocated
If next track is
0,
we 're out of room
Don 't allocate the directory!
Try
suggested
track &
sector
next
Write buffer to allocated
sector
Say where message went
and tidy up
The
Block-Free command is the opposite
of
Block-Allocate.
It frees a block that
you
don't need
any more, for re-use by the DOS. Block-Free updates the BAM to show
a
panicular
sector
is not in use
,
rather than actually
erasing
any data
.
FORMAT
FOR BLOCK-FREE
COMMAND:
PRINT#l5
,"BLOCK-FREE";drive
# ;track # ;sector#
abbreviated
as:
PRINT#l5,"B-F";drive #;track # ;sector#
where "drive#" is the drive number
(always
0 on the 1541), and
"track#"
and
"sector
#"
are respectively the track and sector numbers
containing
the desired block of data
to
be
read into the file buffer.
ALTERNATE
FORMAT:
PRINT#l5,
"B-F:";drive
#;track # ;sectoi" #
71

Advertisement

Table of Contents
loading

Table of Contents