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.
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.
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.
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
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.
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
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:
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).
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