Chapter 20 – Channels, Streams, Drivers and Windows

As we have seen thus far, NextBASIC can read data from the keyboard and controllers using INPUT and INKEY$ and it can write data onto the display or a printer by using PRINT and LPRINT. However, these commands are really a form of shorthand designed to protect the user from some of the computer's more complex features.

To the PRINT command, for example, there is no difference between the screen and the printer. PRINT "Mikayla" really means: take the characters which make up the word Mikayla and send them somewhere else. It's just convenient to use the screen most of the time. Likewise, LPRINT usually sends data to the printer. In fact, what these commands really do is to send data to one of a number of channels.

Channels

A channel is the pathway to the computer's input and output devices and on the ZX Spectrum Next, they are designated by a letter. These are:

Designator Direction Description Default Streams Default Status
k Input/Output1 Keyboard 0,1 Open
s Output Screen 2 Open
p Output Printer 3 Open
i Input File (input) Closed
o Output File (output) Closed
u Input/Output File (Update) Closed
v Input/Output Variable Closed
m Input/Output Memory Closed
d Depends Driver Closed
w Input/Output Windows Closed
r Internal Internal Use only N/A Open

Table 19 – NextBASIC channels

To access a channel, it must be open. Opening a channel makes it ready to receive or produce data. A channel is opened by connecting it to a stream. From NextBASIC, you would use a command like:

OPEN #4,"k"

which means connect stream 4 to the keyboard channel. As evidenced by the table above, if we go by the direction of data flow there are three types of channels: Input, Output and Input/Output (or Update).

However, we can better classify channels by device type: We have Screen, Keyboard, Printer, File, Memory, Variable, Windows and Driver channels. Let's examine them according to the device type however, as this affects what types of commands we can use with them and how.

The Screen Channel deals with everything that goes to the screen. It is the simplest of all channels and most of its characteristics have been covered in Chapter 15 already. It is already opened and connected to stream #2. In fact you can substitute any PRINT command with PRINT #2 and it will work in the exact same way as a regular PRINT command.

1 Outputting data to the keyboard might seem a bit peculiar, but once you consider that the computer uses the lower screen (like INPUT does) to display the characters, it becomes clear why.


ZX Spectrum Next User Manual, 3rd Edition (ISBN 978-1-5272-5496-1), written and illustrated by Phoebus R. Dokos. Copyright © 2020-2024 Phoebus Dokos / SpecNext Ltd. Licensed under CC BY-NC-SA 4.0. This is a transcription and can contain errors; check any doubt against the printed page.