Chapter 7.
K A N A L Li
S P O T O C AND
Moving information between the program
and peripheral devices is controlled
through canals and streams. Desirable
represent the channel as a physical device that receives
information (TV, printer), or give her (keyboard), and
stream as a path along which data should be moved to the
channel or from him.
In the ZX-SPECTRUM without ZX-INTERFACE-1 differ 4 channels.
They are denoted by single letters:
S - output channel, the data sent
to the channel are displayed at the top
of the screen;
K - channel I / O services
keyboard and bottom of the screen;
P - output channel, the data is sent
a printer;
R - output channel to be used only
editor to enter a buffer Editor
data read from the keyboard.
These channels are sent in connection to his threads. We
have them at the disposal of 16 (0 ... 15). After
initialization system should be connected streams 0 and 1
to the channel K, the flow 2 to S, the flow 34 to P.
R channel is not available from the ZX-BASIC.
Instructions BASIC PRINT, LPRINT,
INPUT, LIST, LLIST make it possible to access
all these channels, completely hiding them
existence. In fact, requires only 2 of them and INPUT LIST, as
well as the existing system of canals and streams.
Each of these statements can be used to send information to any
flow. For this purpose, it is only necessary
symbol # K signal which channels
We would like to take.
User LLIST tantamount LIST # 3
LIST is the same as that LLIST # 2. Can
also write LIST # 0 or LLIST # 0, directing print at the bottom
of the screen, but it not very practical, because the system
does not allows you to display there over a 22-screen
operators, and often she cleans it area. Also, the command:
PRINT # 1, "The bottom of the screen"
will print the text at the bottom
screen, as well as INPUT, but
PRINT # 3, "Oh, you do not even have a printer"
will forward the text to the printer. Himself
PRINT equivalent PRINT # 2. Sometimes it can
be advantageous to use
INPUT # 2, "give your name", # 0; A $,
that will cause the output directives are not in the lower
of the screen and at the top. # 0 to A $
needed because the channel is only S
outlet and from the impossible to read.
The user can remain
flows with the numbers from 4 to 15. Before using them
appropriate streams connected to the channels that should serve
them. For this purpose the instruction OPEN # K; "L", where # K
is an expression, giving as a result of a number between 4 and
15, and L - an alphanumeric expression, giving as a result of a
letter ', which identifies the channel (in "naked" SPECTRUM to
be K, S or P). For example, after the team OPEN # 6; "P"
instruction LIST # 6 will be act as LLIST. Also PRINT # 6
can be used instead LPRINT.
After using this stream before connecting it to another
channel, be sure to disable it. For this is team CLOSE # K. A
good rule recommends closing channels (disable them flow)
immediately after use. This can be important for peripheral
devices (allowing them, for example, to switch off their
control devices). Flows from 0 to 3 are automatically connected
to your channels and their closure is impractical so
since the system will connect them again. Attempts
connecting them to other channels may
have uncertain consequences, including
system crash. You also can not close the streams that are not
connected to any channel (see "system error").
"Naked" ZX-SPECTRUM does not allow
evaluate the merits of such a system to transfer information
(especially when there is no necessity to work with Level
ZX-BASIC with atypical peripheral devices). They are identified
only After connecting ZX-INTERFACE-1, while working with
mikrodrayvom or computer network.
The major advantage brought by the system
canals and streams is its flexibility, ease of operation is
determined new channels. In practice, this allows
greatly simplify the design of interfaces by placing in the
computer memory needed programs, serving these devices (which
also reduces cost). Inclusion of your own channels in BASIC
system requires then only 2, usually very short and simple
additional procedures in machine code. True theoretically for
this purpose would be enough instructions IN and OUT, but in
the case of devices requiring signaling from several
microseconds to several tens of microseconds, it will remain a
theory.
For users of the device
importance is also the convenience of writing programs. Much
easier to use PRINT # K or INPUT # K, than each just append to
the ZX-BASIC procedures, preparing the data and then send them
to one sign.
Before we will explain how
organize their own channels, we must
know how SPECTRUM stores the necessary information about them
and about the streams, as well as he use them.
In the area of memory starting at address
Stored system variable CHANS (# 5C4F
(23631)) to the PROG-1 placed the basic data about the
channels. They have a standard format. Description of each
channel is 5 bytes and has the form:
____________________________________
| | | |
| ADDRESS | SIZE | VALUE |
|-------|---------|------------------|
| X | 2 bytes | Address pin |
| | | Procedures Channel |
| X + 2 | 2 bytes | Address pin |
| | | Procedures Channel |
| X + 4 | 1 byte | Code letters Channel |
|_______|_________|__________________|
The procedure for withdrawal will be called with a code the
next symbol in register A. The procedure entry to freely
interact with the ZX-BASIC, should deliver regular codes of
characters that are recognized by the system and signal the
availability of data the pointer C. Lack of input data shall be
indicated zeroing pointer C (CARRY-port) and Z (ZERO-zero).
It often happens that the device
one-sided. Then, as the address
procedures for handling of incorrect operation
gives the position (usually in ROM) procedure:
RST 0008
DEFB CODE
code appropriate error message (the contents of the cell
following the RST 8) chosen as a parameter.
After system initialization domain channel information is 20
bytes +1 contains a pointer to the end of
(# 80 (128)). They include:
________________________________________
| | |
| ADDRESS | |
|----------|----------------------------| CHANS | Address
procedures, writing in | | | Bottom |
| +2 | Address procedures, reading |
| | Data from the keyboard |
| +4 | "K" channel ID |
|----------|-----------------------------|
| +5 | Address procedures, writing in |
| | Top of the screen |
| +7 | Address procedures, signaling-|
| | The classifying error |
| +9 | "S" Channel ID |
|----------|-----------------------------|
| +10 | Address procedures deceptive |
| | Read data in the buffer |
| | Editor |
| +12 | Address procedures, signaling-|
| | The classifying error |
| +14 | "R" channel ID |
|----------|-----------------------------|
| +15 | Address procedures, servicing-|
| | Yuschey Printer |
| +17 | Address procedures, signaling-|
| | The classifying error |
| +19 | "P" channel ID |
|----------|-----------------------------|
| +20 | # 80 (128) Index end |
| | Region |
|----------|-----------------------------|
| +21 | Start of PROG |
|__________|_____________________________|
As seen in this area is no place for
placement of data on new channels. To modify the existing
approach can only P, because the rest automatically
open system. This is not the best way to determine, since only
one extra channel, and also makes it impossible to
simultaneously the printer. Advantageous to move
the entire block of PROG-1 to STEND the appropriate number of
bytes, along with a modification of the system variables.
The easiest way to do this systemic procedure MAKE_ROM. Less
elegant, but equally effective, posting information
new channels anywhere in the system variables at 38 bytes,
starting with SIRMS # 5C10 (23568). For each flow
meant 2 bytes. Address 5 bytes
describing the channel has the form
CHANS + X-1, where X is the content of 2 bytes related to the
data stream. Description of flow number K is located at address
SIRMS +6 +2 + K.
At the time of connection to the stream channel
these cells are assigned to appropriate
values. How many times a program will
Download INPUT # K, or PRINT # K, so
times based on data from the table, STRMS
assigned address of the procedure and placed in the system
variable CURCHL 5C51 (23633). Further, in the case of writing
instruction, the next character is loaded into the drive and
called this procedure. In the case of reading from the drive
selected by the regular characters, if they are available (put
pointer C). Inactive flows are marked by zero in the
appropriate location table STRMS.
As can be seen, this system is really
very flexible and adding new channels netrudoemko. The only
problem is, that the OPEN and CLOSE operate only
standard identifiers of channels
K, S, P. Connection and disconnection of flow
of new channels (a modification of data
STRMS, as well as variable CURCHL) should
be executed program. This requires sending additional signals
that initialize the device or informing him of the completion
of session.
At the end of disappointing news for owners of
ZX-INTERFACE-1: After connecting this device to change SPECTRUM
storage formats of data about the channels and flows, and the
above considerations do not can apply.