User`s guide

EXAMPLES:
To
restore track 18, sector I
of
the directory from the disk buffer filled by the
Bl
ock
Read example on page 82, we can use
PRINT#
15,
"U2";5;0;18;1
We'll
return to this example on the next page, after we learn to alter the directory
in
a
useful way.
We can also use a Block Write to write a name
in
Track
l,
Sector 1, a rarely-u
se
d
sector. This can be used as a way
of
marking a diskette as belonging to you . Here is a
program to do it, using the alternate form
of
the Block Write command:
110
INPUT"
YOUR
NAME"
;NA$
120 OPEN 15,8,15
130
')PEN
4,8
,4,
"#"
140
PRINT#4,NA$
150
PRINT#l5
,
"U2";4;0
; 1 ;l
160
CLOSE4
170CLOSE
15
180 END
Enter a name
Open command channel
Open direct access channel
Write name
to
buffer
Write buffer to Track
1,
Sector 1
of
diskette
Tidy up after
THE
ORIGINAL
BLOCK-READ
AND
BLOCK-WRITE
COMMANDS
(EXPE
RT
USERS
ONLY)
Although. the Block Read and Block Write commands are nearly always replaced
by
the U 1 and U2 commands respectively, the original commands can still be used, as
long
as you fully understand their effects. Unlike U 1 and U2 , B-R and B-W allow you to
read
or write less than a full sector.
In
the case
of
B-R, the first byte
of
the selected sector
is
used to set the buffer pointer (see next section), and determines how many bytes of
that
sector are read into a disk memory buffer. A program may check
to
be sure
it
doesn't
attempt
to
read past the end
of
data actually loaded into the buffer, by watching
fo
r
the
value
of
the file status variable
ST
to change from 0 to 64. When the buffer
is
written
back
to
diskette by B-W, the first byte written is the current value
of
the buffer pointer,
and
only that many bytes are written into the specified sector. B-R and B-W may thus
be
useful
in
working with custom-designed file structures.
FORMAT FOR
THE
ORIGINAL
BLOCK-READ AND BLOCK-WRITE C
OM
·
MANDS:
PRINT#l5,
" BLOCK-READ" ;channel # ;drive # ;track # ;
sector#
abbreviated as:
PRINT#
15,
"B-R"
;channel # ;drive # ;track
#;sector
#
and
PRINT#l5
,"
BLOCK
~
WRITE";channel
# ;drive
#;track
# ;
sector#
68
abbreviated as:
PRINT#l5
, " B-W
";
channel # ;drive # ;track # ;
sector#
where
"channel # " is the channel number specified when the file into which the block
will
be read was opened,
"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 partially read into or written from the file buffer.
IMPORTANT
NOTES:
1. In a true Block-Read, the first byte
of
the selected sector is used to
determine how many bytes
of
that sector to read into the disk memory buffer.
It
thus cannot be used to read an entire sector into the buffer, as the first data byte
is
always interpreted as being the number
of
characters
to
read, rather than part
of
the
data.
2. Similarly,
in
a true Block-Write, when the buffer is written back to diskette,
the first byte written is the current value
of
the buffer pointer, and only that many
bytes are written into the specified sector. It cannot be used to rewrite an entire
sector onto diskette unchanged, because the first data byte is overwritten by the
buffer pointer.
·
THE
BUFFER
POINTER
The
buffer pointer points to where the next Read or Write will begin within a disk
memory buffer. By moving the buffer pointer, you can access individual bytes within a
block
in
any order. This allows you to edit any portion
of
a sector,
or
organize it into
fields,
like a relative record.
FORMAT
FOR
THE
BUFFER-POINTER COMMAND:
PR1NT#l5,"BUFFER-POINTER"
;channel
#;byte
USually
abbreviated as:
PRINT#l5
,
"B-P"
;channel # ;byte
Where
"channel
#"
is the channel number specified when the
file
reserving the buffer
was
opened, and "
byte"
is the character number within the buffer at which to point.
ALTERNATE FORMATS:
PRINT#l5,"B-P:
" channel
#;byte
PRINT#l5,
"B-P
:channel
#;byte"
£XAMJ>LE
:
Here is a program that locks the first program or
file
on a
1541
diskette. It works by
ltading the start
of
the directory (Track I 8, Sector I) into disk memory, setting the buffer
69