+3e Extended Channels

The streams and channels system of the +3e has been extended, and it is now possible to open streams to channels other than the three standard ones using the OPEN # command.

The syntax of the OPEN # command together with other new streams and channels commands is given in the +3e commands section; here we will examine the channels themselves, and how they may be used.

__________________________________________________________________

File channels

Streams may be opened to any +3DOS file (on floppy or hard disk) in one of three different access modes: input (using the "I>" channel), output (using the "O>" channel) and update (using the "U>" channel). If no channel specifier is given, then a channel name will be assumed to be an input mode file, so the "I>" can be left out (this will not work if the filename is only one character long though).

In input and update modes, the file must already exist, or an error will occur. In output mode, the file is deleted if it already exists, and then a new file is created. Once the file is open, it can be input from (if opened in input or update modes) or output to (if opened in output or update modes). Because of file buffering, it is essential to CLOSE # any file channel before finishing, otherwise data may be lost.

File channels support all the pointer commands (RETURN #, GOTO # and DIM #).

It should be noted that +3DOS files are always stored as a number of 128-byte "records" and so you may read rubbish at the end of a file if it is not an exact multiple of 128 bytes in length. To avoid this problem, you should write some code or "signature" at the end of your file which you can detect when reading it back. Alternatively, you could write the number of bytes or entries in your file at the start.

Examples

OPEN #4, "o>test.txt"
Creates a file named "test.txt" on the default drive for output through stream 4.
OPEN #5, "a:test2.txt">
Opens a file named "test2.txt" on drive A: for input through stream 5.

__________________________________________________________________

Variable channels

The "V>" channel can be used to direct output to or input from a string variable, which can be easily manipulated within a BASIC program. This would allow you to (for example) examine disk catalogs in your BASIC program, or make an auto-running game demo (by inputting from a string containing set keystrokes).

The string specified must be a character array with a single dimension, large enough to hold the maximum amount of data you expect to have to deal with.

Variable channels support all the pointer commands.

Example

Here is an example program that outputs an assignment list to a string.

    10 DIM a$(1000)
    20 OPEN #8, "V>a$"
    30 CAT #8 ASN
    40 RETURN #8, l
    50 PRINT "Assignment length is ";l
    60 PRINT "List is:"
    70 PRINT a$( TO l)
    80 CLOSE #8

__________________________________________________________________

Memory channels

The "M>" channel can be used in a very similar way to the variable channels. However, as it is a fixed memory region, it is more suitable for use by machine-code programs.

Example

Here is an example program that outputs a disk catalogue to memory and then runs a machine-code routine to process it:

    10 CLEAR 29999
    20 OPEN #7, "M>30000,1000"
    30 CAT #7
    40 LET x=USR myroutine
    50 CLOSE #7

__________________________________________________________________

Window channels

The "W>" window channels are the most complex of the extended channels currently available on the +3e. Although they are output-only and do not support any of the pointer commands, they are extremely flexible as they accept a large number of "control codes".

Windows are defined by their top line (0-23), leftmost column (0-31), height (1-24), width (1-32), and optionally character size (3-8) and character set address. If no character size is specified, the default is 8. If a character set address is given, then this is used instead of the built-in fonts; this allows you to use nice fonts such as those provided with art programs and adventure games.

Note that the character size has no bearing on the way the window is defined, but it does affect the number of "actual" columns you have available. For example, the following defines a window the size of the entire screen; but because a character size of 5 is specified, the number of characters that can be printed in the window at any time is 24x51:

OPEN #5,"w>0,0,24,32,5"

When PRINTing to windows, you can use many of the same control functions as you can with the normal screen. For example: ' (apostrophe; start a new line), , (comma; start a new column), TAB, AT, INK , PAPER, FLASH, BRIGHT , INVERSE, OVER. Of these, only AT behaves slightly differently; it takes y to be a pixel line and x to be an actual character column.

When first defined, windows are in non-justified mode, but they can be set to be left-, full- or centre-justified. Note that in justified mode, some features and control codes cannot be accessed, so you may need to switch back to non-justified mode to use them.

A complete list of control codes follows; these codes can be sent to a window by PRINTing them using the CHR$ function. If a code is preceded by (j) then it will be ignored if issued in justified mode (however, their settings will still be taken into account; for example, you can justify double-width text, but you must set it before entering justified mode). If a code is preceded by (e) then it can only be used in justified mode if the "embedded codes" feature has been set; if not, unpredictable results may occur (hopefully this will be fixed in the future).

0
Turn justification off
1
Turn justification on
2
Save current window contents
3
Restore saved window contents
4
Home cursor to top left
5
Home cursor to bottom left
(j) 6
Tab to left or centre of window (PRINT comma)
7
Scroll window
(j) 8
Move cursor left
(j) 9
Move cursor right
10
Move cursor down
11
Move cursor up
(j) 12
Delete character to left of cursor
13
Start new line (PRINT apostrophe)
14
Clear window to current attributes
15
Wash window with current attributes
(e) 16, n
Set INK n (0-7)
(e) 17, n
Set PAPER n (0-7)
(e) 18, n
Set FLASH n (0-1)
(e) 19, n
Set BRIGHT n (0-1)
(e) 20, n
Set INVERSE n (0-1)
(e) 21, n
Set OVER n (0-1)
(j) 22, y, x
Set cursor to pixel line y, character size column x
(j) 23, n
TAB to character size column n
(e) 24, n
Set attributes n (0-255)
(j) 25, n
If n=1, then characters 165-255 will be printed as UDGs, with data located at the end of the standard UDGs. If n=0, then characters 165-255 will be printed as BASIC keyword tokens (the default).
(e) 26, n
Fill window with byte n. Attributes are affected, but not cursor position.
(e) 27, n
Fill window with character n. Attributes and cursor position are affected.
(j) 28, n
Set double width (n=1) or normal width (n=0).
(e) 29, n
Set height n (0=normal, 1=double, 2=reduced, 3=double reduced)
30, n
Set justification mode (0=left, 1=centred, 2=full)
(j) 31, n
Allow embedded codes in justified mode if n=1.

Examples

The following demo program shows some of the features of window channels, and is a good source of examples of their use:

__________________________________________________________________

Back to ZX Spectrum +3e homepage