The Buft'er Pointer - Commodore 1541 User Manual

Hide thumbs Also See for 1541:
Table of Contents

Advertisement

EXAMPLES:
To restore track 18, sector 1 of the directory from the disk buffer filled by the
Black
Read example on page 82, we can use
PRINT#l5,"U2";5;0;18;1
We'll return to this example on the next page, after we learn to alter the directory
in
a
useful way.
We can also use a Block Write to write a name in Track l, Sector 1, a
rarely-used
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 OPEN
4,8,4, "#"
140 PRINT#4,NA$
150 PRINT#l5,"U2"
;4;0;1;1
160 CLOSE 4
170 CLOSE 15
!RO END
Enter a
name
Open
command channel
Open direct
access channel
Write name to buffer
Write buffer to Track 1,
Sector 1
of
diskette
Tidy up
after
THE ORIGINAL BLOCK-READ AND BLOCK-WRITE COMMANDS
(EXPERT
USERS ONLY)
Although the Block Read and Block Write
commands are
nearly
~I
ways
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 rea.
d
or write less than
a
full
sector.
In the case
of
B-R, the first byte
of
the
selected sector
15
used to set the buffer pointer
(see
next
section),
and determines how many
bytes
of
th~t
sector
are read
into
a disk memory buffer. A program may check to be
sure it doesn
1
h
.
f
the
attempt to read past the end of data actually loaded into the buffer, by watc mg
or
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
coM·
MANOS:
PRINT#l5,"BLOCK-READ";channel #;drive #;track #;sector#
abbreviated as: PRINT#l5,"B-R";channel #;drive #;track #;sector#
and
PRlNT#15,"BLOCK-WRITE";channel #;drive #;track#;
ector
#
68
llJl>reviated as: PRINT#l5,"B-W";channel #;drive #;track #;sector#
wtiere
"channel
#" is the channel number
specified
when the file
into
which the block
\\'ill be
read was opened,
"drive#"
is the drive number
(always
0 on the 1541), and
··uack #" and
"sector
#" are respectively the track and
sector
numbers containing the
11e5ired
block
of data to be partially read into or written from the file buffer.
IMPORT ANT NOTES:
I
.
In a true Block-Read, the first byte of the selected sector is used to
determine
how many bytes of that
sector
to read into the disk memory buffer. It
thus
cannot be used to read an entire
sector
into the buffer, as the first data byte is
always
interpreted as being the number of
characters
to read, rather than part of the
data.
2. Similarly, in a true Block-Write
,
when the buffer is written back to diskette,
the first
byte written is the current value of the buffer pointer, and only that many
bytes
are written into the
specified sector.
It cannot be used to rewrite an entire
sector
onto diskette unchanged, because the first data byte is overwritten by the
buffer
pointer.
THE BUFFER POINTER
The buffer
pointer points to where the next Read or Write will begin within a disk
memory buffer.
By moving the buffer pointer, you can access individual bytes within a
block in
any order. This allows you to edit any portion of a sector, or organize it into
fields, like
a relative record
.
FORMAT
FOR THE BUFFER-POINTER
COMMAND:
PRINT#
15,
"BUFFER-POINTER" ;channel
#;byte
USually
abbreviated
as:
PRINT# 15,
"B-P" ;channel
#;byte
""here
"channel #" is the channel number specified when the file reserving the buffer
'N&s
opened,
and "byte" is the character number within the buffer at which to point.
ALTERNATE
FORMATS:
PRINT#l5
,"B-P:"channel
#;byte
PRINT#l5, "B-P:channel
#;byte"
EXAMPLE:
Here
is a program that locks the first program or file on a 1541 diskette. It works by
!tading the
start of the directory
(Track
18, Sector I) into disk memory,
setting
the buffer
69

Advertisement

Table of Contents
loading

Table of Contents