Introduction To Channels On The 2068

Authors

Publication

Pub Details

Date

Pages

Did you know that your 2068 has a feature built-in to it which allows you to link new peripherals into Basic? It is possible to interface your computer to modems, keyboards, printers, other computers, or just about anything else you can think of and then use Basic commands like PRINT, INPUT, LIST, INKEY, LPRINT, or LLIST to send data out or receive data from these devices.

It is the manipulation of STREAMS and CHANNELS which makes all of this possible. You probably have seen these terms mentioned before, but what they are and how to use them are topics which, until now, have been virtually ignored.

So what are streams and channels and how do they relate to external peripheral devices? Imagine opening a valve to let water pass through a garden hose. Now imagine issuing a command to send a string of characters to a modem. In the garden hose you have the water itself which is the STREAM, and you have the hose which is the CHANNEL or pathway the stream is directed through. In the modem analogy, you have the string of characters (the STREAM) which is directed through a program (CHANNEL) which outputs the stream to the modem. A STREAM is the data which is to be sent in or out. A CHANNEL is the program which directs the flow to/from the peripheral. I should emphasize, the channel is NOT the peripheral itself, but the program which handles the peripheral.

When you print characters such as the word “hello” to the TV screen you are sending a stream of data (the letters h-e-!-l-o) to a program which puts those characters on your video display. Channels are given numbers to distinguish one from the other. The channel which prints to the TV screen is channel #2. The channel which prints to your printer is channel #3. Channel #1 is the routine which prints messages at the bottom of your TV screen. When you use the basic channel commands (PRINT, LPRINT, INPUT, INKEYS, LIST, and LLIST) the computer will automatically associate the proper channel number with the command if you do not specify some different channel. Thus the command, PRINT “hello”, will put the word “hello” on your TV screen.

However, you can override the default channels by specifying a different channel number. Try entering these unusual commands:

LPRINT #2;"HELLO"
LIST #3 (make sure your printer is on)
INPUT #2,"NAME?";#1;A$

You can also create your own channels in machine code and send streams of data to them. The article that follows this one shows how to connect an IBM keyboard to your computer. By creating a new keyboard channel, the commands INPUT and INKEYS can be made to take data from this big keyboard. How is this done?

It is a two step procedure creating the channel and linking it to Basic. In the case of interfacing the IBM keyboard to the 2068, the first step is writing the software which determines which key you’re pressing. Then you must link it to Basic.

The link is made by building what is called a “channel table” which tells the computer where to find the channel program. Because a stream can travel in two directions (in or out of the computer), the channel table must provide addresses for a device INPUT routine and a device OUTPUT routine. The table should also include an optional “channel identifier” which tells the computer what kind of channel it is dealing with. This identifier is simply a letter of the alphabet which signifies a device: K for Keyboard, S for screen, P for Printer, etc. You must also tell the computer where to find the channel table. This is not difficult, but it does need some explanation.

Earlier, | mentioned that there are already several channels present in the computer which handle streams from the 2068 keyboard, to the TV and to the 2040 printer. These channels also have a table which show where they are located. The 2068 system variable called CHANS (address 23631/2) points to the start of this table. You can look at this table by entering and running the short program below:

10 LET START=PEEK 23631+256*PEEK 23632
20 FOR X=START TO START+19
30° PRINT X;"=";PEEK X;TAB 12;
40 IF PEEK X<100 AND PEEK X>32 THEN PRINT CHR$ PEEK X:NEXT X
50 PRINT:NEXT X

Each channel requires 5 bytes for its table. The first 5 addresses printed on the screen represent the 2068 keyboard channel. The first 2 addresses of every channel table contain the address of the device OUTPUT routine. The second two addresses contain. the address of the device INPUT routine. The fifth and last byte is used for the channel identifier. The built-in channels all have their tables together in an area of memory which begins at the address pointed to by the CHANS system variable.

When the computer needs to find an input or output routine address given in the channel tables, it does so by checking another group of 2068 system variables named “STRMS”. These are 38 bytes which are described on page 262 of the TS2068 operators manual. Unfortunately, the description given in the manual is horrendously incorrect. First of all, the name, STRMS, is misleading because the 38 bytes are not “streams”; they are offsets to channels. Secondly, the book states that these bytes are “addresses of channels attached to streams.” Again, they are not addresses, they are offsets.

Specifically, each two byte “STRM” tells the computer how far the channel information (the table for the specific channel) is located away from the address specified in the system variable CHANS. The value stored in a STRM will always be | greater than the actual distance.

Internally, the computer recognizes 7 built in channels. Their numbers are -3, -2, -1, 0, 1, 2, and 3. For all practical purposes, you can ignore these channels. Their workings are invisible to you as you run your computer. You can, however peek the first few bytes starting at address 23568 to see the offsets. Use the listing below to print them on the TV screen:

10 FOR X=23568 TO 23588
20 PRINT X;"=";PEEK X
30 NEXT X

Here is a chart showing which STRM addresses represent which channels.

STRM
Address
Offset
Value
Distance from
CHANS
Channel
Number
23568/6910-3
23570/7165-2
23572/731110-1
23574/75100
23576/77101
23578/79652
23580/8116153
23582/83Not definedNot defined4
23584/85Not definedNot defined5
23586/87Not definedNot defined6
23588/89Not definedNot defined7
23590/91Not definedNot defined8
23592/93Not definedNot defined9
23594/95Not definedNot defined10
23596/97Not definedNot defined11
23598/99Not definedNot defined12
23600/01Not definedNot defined13
23602/03Not definedNot defined14
23604/05Not definedNot defined15

As you can see, channels 4-15 are not used internally by the computer. They are left for you to use with your add-ons. What must be done to create a new channel is to place a new channel table somewhere in memory and poke a new STRM with an offset which shows where this table is located.

You can place your 5 byte channel table just about anywhere you want as long as it is at an address higher than that specified in CHANS. I have grown fond of the practice of placing channel tables in REM lines of basic programs. This fulfills the requirement that the table be higher than the existing channel information, and if the REM holding your new channel data is the first line of a program, its location is easy to determine. The first byte of such a table will always be 5 bytes more than the address stored in the system variable, PROG (23635 and 23636).

So using the Keyboard article as an example, you locate your channel program in memory. The entry point of the keyboard software is address FD02 hex. Then you build a channel table in a REM line. This is done by entering a program line like:

1 REM xxxxK

The address of the keyboard OUTPUT routine will be the same as the output routine for the 2068 keyboard (shown in the built-in channel table to be address 0500 hex). The first two x’s must be poked with the output address (0500) and the second 2 x’s must be poked with the input address (FD02).

To find the address of the first “x” in the REM line, enter the command:

PRINT 5+PEEK 23635+256*PEEK 23636

Normally, this will give 26715 as a result. So the following pokes are then entered:

POKE 26715,     OUTPUT ROUTINE Equals: 
POKE 26716,50 500 HEX
POKE 26717,2 INPUT ROUTINE Equals:
POKE 26718,253 FD02 HEX

That takes care of the channel information.

All that’s left to do now is poke the first unused STRM with the proper offset. This address will depend on how many channels have already been set up. The STRM for channel 4 is at address 23582 and 23583. To determine the value to poke these addresses, enter these commands:

LET CHAN=PEEK 23631+256*PEEK 23632
LET TABLE=5+PEEK 23635+256*PEEK 23636
LET OFFSET=TABLE-CHAN+1
RANDOMIZE OFFSET
POKE 23582,PEEK 23670
POKE 23583,PEEK 23671

Now a new channel 4 is fully linked to your Basic. Using the Basic commands PRINT #4, INPUT #4, etc. will direct your stream of data to your channel software.

Describing how to make use of channels is much more difficult than actually doing it. What follows is an actual example which hopefully, you’ll find far less abstract.

Products

 

Downloadable Media

 
Scroll to Top