Adding Toa Sequential File - Commodore 1541 User Manual

Hide thumbs Also See for 1541:
Table of Contents

Advertisement

"channel #"
is a secondary address, giving
further
instructions
to the
selecteii
device
about
how
further commands
are
to
be obeyed
.
ln disk files, the channel
number
selects
a particular
channel
along which
communications
for this file can take place
.
The
possible range of disk
chanrel
numbers is 0-15, but 0 is reserved for program
Loa~s
• I for
program Saves, and 15 for the disk
command channel.
Also be
sure that
n~ two disk
files
have the
same channel
number unless they will never be
open
at the
same
ume
.
(One
wa~
to do this is to make the
channel
number for
each
.file the
same
as its file
number.)
"drive#" is the drive
number,
always 0 on the 1541. Do
not
omit it, or
you
WilJ
only
be able to use two
channels
at the
same
time
instead of
the normal
m~imum
of
thr~e
If any pre-existing file of the
same
name is to be replaced, precede the drive number
w1t1i
the
"at"
sign(@) to request
Open-with-replace.
.
"file name"
is
the file name, maximum length 16
characters.
Pattern
matching
characters
are allowed
in
the name when
accessing existing
files,
but
not when
creating
new ones
.
"file type" is the file type
desired:
S=sequential
,
P=program,
U=user, and
L
=length
of
a
relative
file.
.
...
"direction" is
the type of access desired
.
There are three
poss1b1h11es:
R
=read,
w
=write
and M
=modify
.
When
creating a
file, use ''W'
'
to write the data to
diskette
When
vie~ing
a
completed
file, use
"
R" to read the data from
disk~tte.
Only
use
the
"M" (modify) option as a
last ditch way
of
reading back data from an
1mpro.
p
erltclos.
e d
(Splat) file. (If you try this, check every
byte
as it is
read to be
sure
the data
1s sttll
vahd,
as
such
files always
include some erroneous
data, and have no proper end
.)
"file
type"
and
"dir~ction" don't have to be
abbreviated.
They
can
be
spelled
out
in
full
for
clarity in printed listings
.
.
"file#"
"device#"
and
"channel#"
must
be valid
numeric
constants,
var1able1
or
expression~.
The rest of the
command
mus! be a
valid string
literal,
variable
or
expression
.
The maximum number
of files
that may be
open
simultaneously
is
10, including
a
ll
files
to all devices
.
The maximum number
of sequential disk files
that
can
be
open at
once
is 3 (or 2 if you
neglect to
include the
drive number
in your Open statement),
plus
tht
command channel
.
EXAMPLES OF
OPENING
SEQUENTIAL
FILES:
To
create a
sequential
file of
phone numbers
,
you could
use
:
OPEN 2,8,2,
"O:PHONES,SEQUENTIAL,WRITE"
or
save
yourself
some
typing
with:
OPEN 2,8,2,
"O:PHONES
,S,W"
of
course, this
~rases
al.
I
our old
phone
numb~rs
,
so make sure
that
any information that
rnaY
be deleted
1s of
no importance
.
After
wnllng our
phone
file, we remove our diskeue
and
tum off the
system.
Later,
to
recall
the data
in
the file
,
we
would reopen
it
with
s0inething like
OPEN
8,8,8, "O:
PHONES,S
,R"
It doesn't matter
whether
the file
and channel
numbers match the
ones we
used
before, but
the file name does
have
to match
.
However, it is
possible
to use
an abbreviation form of
the file name
,
if there
are
no
other
files that
would
have the
same abbreviation
:
OPEN 10,8
,6,
"O:PH* ,S,R"
If we have too many phone numbers, they might not
fit
in
one file
.
In that
case, we
might use
several similar
file names
,
and
let
a
program
choose
the
correct
file.
100 INPUT
"
WHICH PHONE FILE
(
l-3) ";PH
110 IF PH
<>
I AND PH
<>2
AND PH
<>3
THEN 100
120 OPEN 4,8
,2,
"PHONE"+
STR$(PH)
+
",S,R"
You can omit the drive number
on an
Open
command
to read
a file
.
Doing
so allows
those
with dual drives to
search
both diskettes for the file.
Note: Basic
2
and Basic
3.5
use the
same
file handling
commands
and the
same
direct access
commands (chapters
7-8)
.
Unless otherwise noted
,
you
may use the
same commands for both throughout the remainder of this book
.
ADDING TO
A SEQUENTIAL FILE
On Commodore's PET and CBM models, an Append command allows you to reopen
an
existing sequential file and add more information to the end of it. The
same
thing
can
be
done another way on the 1541. In place of the
"type"
and
"direction"
parameters
in
Your
Open statement,
substitute ",A"
for Append
.
This will reopen your file,
and
Position the disk head at the end of the existing data in your file, ready to add to it.
FoRMA T FOR THE APPEND OPTION
OPEN file #,device #,channel #,"drive # :file name,A"
oid
'
1
~here.
everything is as on the previous page except for the ending
"A" replacing the
On the
off-chance we've already got a "PHONES" file on our
diskette
,
we can av
'type"
and
"direction"
parameters
.
"FILE
EXISTS" error
message
by
doing an
@OPEN
OPEN
2,8,2,
"(U,O:
PHONES
,S,W"
44
45

Advertisement

Table of Contents
loading

Table of Contents