User`s guide

PART TWO:
GUIDE TO
ADVANCED OPERATION
AND
PROGRAMMING
COMMAND CHANNEL
CHAPTER4
COMMANDS
Commodore disk drives expect to receive many
of
their instructions over what
is
known as a command channel. Although we will not explain the concepts behind it until
Chapter 6, we will learn it to use it now, so you can give your 1541 disk the commands it
needs to do some essential chores.
To instruct the command channel, we use a Basic
Open statement to the disk, with a
secondary address
of
15. The usual form
of
this statement is:
OPEN 15,8,15
The first
15
is
a file number, and could be any number from 1 to 255.
It
is used to
match the secondary address (the last number on the
line), which is ยทalso
15
. The middle
number is the primary address, better known as the device number, and is normally
8
when talking with the 1541. A second disk drive would usually be
9,
a third,
10
and so on.
Once the command channel has been opened, use the Basic
Print#
command to send
information to the disk drive, and
Basic's
Input#
command to receive information back
from the disk drive. These two commands
are
like Basic's Print and Input statements,
except that they use the device number specified in the preceding Open statement instead
of
defaulting to the screen and keyboard respectively.
In Basic
2,
you'll use both
Print#l5
and
Input#l5
extensively, to send housekeep-
ing commands to the disk and to check its error status. Basic
3.5
has built-in commands
for most
of
these chores. Even so, it will be good for those
of
yo'u
with Basic
3.5
to
see
how such commands are sent.
Sending a
Command
via the
Command
Channel
Here is the way we send the Initialize command to the disk via the command
channel.
PRINT#l5
,
"IO"
This
command
assumes
we
have
already
opened
the
file
15
to
the
command
channel.
"10"
can be
replaced
with
any
string
expression
that
is a
valid
disk
com-
mand.
If
file
15
isn't
already
open,
we
can
combine
the
Open
and
the
Print#
in
a
single
statement:
OPEN 15,8, 15,
"IO"
However, this only works for the first disk command given. After that, file
15
is
already open, and Opening it again would cause a
"ALE
OPEN"
error. Added com-
mands
are
sent via
Print#
instead.
25