--- title: "Streaming Along" type: "article" slug: "streaming-along" url: "http://localhost/article/streaming-along/" markdown_url: "http://localhost/article/streaming-along.md" published_at: "2022-10-07T12:22:37+00:00" modified_at: "2026-08-02T09:10:48+00:00" featured_image: url: "http://localhost/wp-content/uploads/2022/04/20230809-041332.jpg" excerpt: "I'm sure that you all know by now how to drive your printers from a program; you simply replace your customary PRINT statement with a LPRINT statement. Simple, right? But what if you have a program which will print to the printer or to the screen at the user's option? How do you program this…" category: - name: "CATS Newsletter" slug: "cats-newsletter" taxonomy: "category" url: "http://localhost/category/periodicals/cats-newsletter/" post_tag: - name: "1984" slug: "year-1984" taxonomy: "post_tag" url: "http://localhost/tag/year-1984/" - name: "Best of Timex/Sinclair 2068 Articles and Documents" slug: "ts2068best" taxonomy: "post_tag" url: "http://localhost/tag/ts2068best/" - name: "Reference" slug: "reference" taxonomy: "post_tag" url: "http://localhost/tag/reference/" - name: "TS 2068" slug: "ts2068" taxonomy: "post_tag" url: "http://localhost/tag/ts2068/" model: - name: "Timex/Sinclair 2068" slug: "ts-2068" taxonomy: "model" url: "http://localhost/model/ts-2068/" indiv: - name: "Jim Hayes" slug: "jim-hayes" taxonomy: "indiv" url: "http://localhost/indiv/jim-hayes/" publication_r: id: 35941 title: "CATS Newsletter" type: "periodical" url: "http://localhost/periodical/cats-newsletter/" authors: "Jim Hayes" authors_r: - name: "Jim Hayes" slug: "jim-hayes" taxonomy: "indiv" url: "http://localhost/indiv/jim-hayes/" volume: "2" issue: "4" issues_articles: - id: 39595 title: "CATS v2 n4" type: "issue" url: "http://localhost/issue/cats-v2-n4/" pages: "15" pubdate: "July 1984" archive_link: false --- # Streaming Along I’m sure that you all know by now how to drive your printers from a program; you simply replace your customary `PRINT` statement with a `LPRINT` statement. Simple, right? But what if you have a program which will print to the printer or to the screen at the user’s option? How do you program this ability into the computer? You might try something like this: ``` 10 INPUT"Print to S-creen, or P-rinter";a$ 20 IF a$="P" THEN LPRINT "Message" 30 IF a$="S" THEN PRINT "Message" ``` This method works well, but takes two sets of print statements at every output point. Thus taking up valuable memory and slowing your computerized masterpiece down. Fortunately, Uncle Clive provided an alternate way of sending output to the screen and/or printer. This alternate way has to do with the way that your TS 2068/ZX Spectrum looks at outputted data. Upon power-up, the computer sets up channels for your output to travel along. These channels are to the printer, screen, edit lines, and other areas beyond the scope of this article. It then assigns these channels to certain output statements: screen for `PRINT` and `LIST`; printer for `LPRINT` and `LLIST`; and edit lines for ROM output. This channeling of data is known as STREAMING. Each of the three primary output areas mentioned are given a number all their own. Stream 1 goes to the edit lines, stream 2 goes to the screen, and stream 3 goes to the printer. Thus; by changing the default area of each stream, we can redirect outputed data. This redirecting is accomplished by assigning the stream to a new area: “K” for the edit lines, “S” for the screen, and “P” for the printer. Thus, by changing the output area of stream 2, we can cause `PRINT` and `LIST` statements to go somewhere other than on the screen. This is done by using the `OPEN#` statement in the form of `OPEN#,""`. Consider the new version of our program: ``` 10 INPUT"Print to the S-creen, or P-rinter";a$:OPEN#2,a$ 20 PRINT"Message" ``` This new version does the same as the first but shorter. In a longer program this can add up to a savings of several kilobytes. Of course, once you have re-routed the data, you can return it to its normal area by using the `CLOSE#` command in the format of `CLOSE#`. Another unique trick of streaming is the ability to print on the edit lines by opening stream 2 to the “K” device. See if you can figure this out from the previous examples we’ve used.