Reading File Data: Using Get - Commodore 1541 User Manual

Hide thumbs Also See for 1541:
Table of Contents

Advertisement

READING FILE DATA: USING GET#
:111~
Get#
statement
retrieves data from the disk drive, one
character
at a
time.
Like
the
similar
keyboard Get
statement in
Basic, it only accepts
a single character
into
specified
variable. However, unlike the Get
statement,
it doesn 't just fall through
to
th
a
n~xt
statement if there
is
no data to be gotten. The primary use of Get#
is
to retrieve
fro;
diskette any data that
cannot
be read
into
an Input# statement, either because it is too
Ion
to fit in the input buffer or because
it
includes troublesome characters
.
g
FORMAT FOR THE GET# STATEMENT:
GET#file#, variable list
where
"file#"
is the
same
file number given in the desired file's current Open
statement
and
"variable
list" is one or more valid Basic variable names
.
If more than one
dat~
element is
to be
input
by a particular Get#
statement, each
variable name must
be
separated
from others by
a comma.
In practice, you will almost never
see
a Get or Get#
statement
containing more
than
one
variable
name. If more than one character
is
needed, a loop is used
rather than
additional
variables
.
Also
as
in the Input#
statement,
it is
safer
to use
string
variables
when the file to be read might
contain
a non-numeric
character.
Data
in
a Get#
statement
comes in byte by byte, including
such
normally invisible
characters as
the Carriage Return, and the various cursor controls
.
All but one will
be read
properly
.
The
exception is
CHR$(0), the ASCII Null
character.
It is different from
an
empty
string(oneofthe form
A$=
'"'),even
though empty
strings
are often referred
to as
null
strings.
Unfortunately,
in
a Get#
statement,
CHR$(0) is converted into an
empty
string.
The
cure
is to test for an
empty string
after a Get#, and replace any that are
found
with CHR$(0) instead. The first example below illustrates the method.
EXAMPLES
:
To read
a
file that may
contain
a CHR$(0),
such
as a machine language program
fi
le,
we could correct any CHR$(0) bytes with
1100 GET#3,G$ :1F G$=
""THEN
G$=CHR$(0)
If
an overlong string
has managed to be recorded in a file, it may be
safely
read
back
into the
computer
with Get#
,
using a loop
such
as this
3300 B$
= ""
3310GET#l ,A$
3320 IF A$<
>CHR$(
13)
THEN
B$
=
B$
+
A$:GOTO
3310
The limit for
such a
technique is
255
characters. It will ignore CHR$(0), but that may
be:
an advantage in building a text
string
.
52
Get# may
be especially
useful in recovering damaged
files
,
or files with unknown
nts
The Basic reserved variable ST
(the file
STatus
variable) can be
used to
indicate
' ° "te
.
-
whC"
all of
a
properly-closed file has been read
.
500 GET#2,S$
510 SU=ST:REM REMEMBER FILE
STATUS
520 PRINT S$;
.
530 IF SU
=0 THEN
500:REM IF THERE'S MORE
TO
BE READ
540 IF SU<
>
64
THEN PRINT
"
STATUS
ERROR
:
ST= ";SU
eopying ST into SU
is often
an unneccessary prec~ution, but must
be
done
if any other
file-handling
statement appears between
the
one which
r~ad fro~
the file and
the
one that
toops back to
read again
.
For
example,
it
would be
required 1f
lane 520 was changed
to
520 PRINT# I
,S$;
()dterwise, the file
status checked
in line
530 would be
that
of
the
write
file, not
the
read
file.
POSSIBLE VALUES OF THE
FILE
STATUS VARIABLE
"ST"
,
AND
l'HEIR MEANINGS
IFST=
0
All is OK
THEN
I
Receiving device wa not
available (time out on
talker)
2
Tran milling device
was
not
available (time out on
listener)
4
Cassette data
file
block
was
too
short
8
Cassette data
file
block
was
too long
16
Unrecoverable read error
from cas ette
,
verify
error
32
Cassette
checksum error--0ne or
more
faulty characters
were read
64
End
of file
reached
(EOI
detected)
128
Device not present,
or end of
tape mark
found
on
cassette
53

Advertisement

Table of Contents
loading

Table of Contents