error or not, but if there was
an
error, the program clears it from disk memory and turns
off the error light on the disk drive.
Once the message
is
on the screen, you can look it
up
in
Appendix B
to
see what it
means, and what to
do
about it.
For those
of
you who are writing programs, the following
is
a small error-checking
subroutine you can include in your programs:
59980 REM READ ERROR CHANNEL
59990INPUT#15,EN,EM$,ET,ES
60000 IF
EN>1
THEN PRINT EN,EM$,ET,ES:STOP
60010 RETURN
This assumes
file
15
was opened earlier
in
the program, and that
it
will
be
closed at
the end
of
the program.
The subroutine reads the error channel and puts the results into the named varia-
bles-EN
(Error Number), EM$ (Error Message), ET (Error Track), and
ES
(Error
Sector).
Of
the four, only EM$ has
to
be a string. You could choose other variable names,
although these have become traditional for this use.
Two error numbers are harmless---O means everything
is
OK, and 1 tells how many
files were erased by a SCRATCH command (described later
in
this chapter). If
the
error
status
is
anything else, line 60000 prints the error message and halts the program.
Because this
is
a subroutine, you access
it
with the BASIC GOSUB command, either
in immediate mode or from a program. The RETURN statement in line 60010 will jump
back
to
immediate mode or the next statement
in
your program, whichever
is
appropriate.
BASIC
HINTS
Hint
#1:
It
is
best
to
open
file
15
once at the very start
of
a program, and only close it at
the end
ofthe
program, after
all
other files have already been closed. By opening it once at
the start, the file is open whenever needed for disk commands elsewhere
in
the
program.
Hint
#2:
If
BASIC halts with an error when you have files open, BASIC aborts them
without closing them properly on the disk. To close them properly
on
the disk, you must
type:
CLOSE 15:0PEN
15,8,15,"I":CLOSE
15
This opens the command channel and immediately closes it, along with
all
other disk
files. Failure to close a disk
file
properly both
in
BASIC and
on
the
disk may result
in
losing the entire file.
Hint
#3:
One disk error message
is
not always an error. Error 73,
"CBM
DOS 3.0
1571" will appear if you read the disk error channel before sending any disk commands
when you tum on your computer. This
is
a handy way
to
check which version
of
DOS
you
are using. However, if this message appears later, after other disk commands,
it
means
there
is
a mismatch between the DOS used
to
format your diskette and the
DOS
in
your
drive. DOS
is
Disk Operating System.
15