type a variable name not previously defined then the computer will stop with the report 2 Variable not found, 20:1.

Using control codes with PRINT

In the beginning of this chapter, we saw the effect that control codes 29 and 30 had in adjusting the size of the font that's currently printed on screen. There are more control codes that we can use with PRINT. CHR$ 22 and CHR$ 23 affect printing in the same manner as AT and TAB. They are rather odd as control codes, because whenever one is sent to the screen to be printed, it must be followed by two more characters that do not have their usual effect: they are treated as numbers (their codes) to specify the y and x positions (for AT) or the tab position (for TAB). You will almost always find it easier to use AT and TAB in the usual way rather than the control codes, but they might be useful in some circumstances. The AT control character is CHR$ 22. The first character after it specifies the y-position (be it a line number or y-pixel value according to the layer we're currently in) and the second the column number, so that:

PRINT CHR$ 22+CHR$ 1 +CHR$ c;

has exactly the same effect as:

PRINT AT 1,c;

This is so even if CHR$ 1 or CHR$ c would normally have a different meaning (for instance if c=13); the CHR$ 22 before them overrides that.

The TAB control character is CHR$ 23 and the two characters after it are used to give a number between 0 and 65535 specifying the number you would have in a TAB modifier:

PRINT CHR$ 23+CHR$ a+CHR$ b;

has the same effect as:

PRINT TAB a+256*b;

As with the character size control codes, there are further control codes that only apply to layers other than 0 and further modify their behaviour. One of those, is CHR$ 26 or the Scroll-prompt inhibitor control code. Set by CHR$ 26; CHR$ n; where n is the number of lines that can be scrolled off before the scroll prompt cursor appears (as discussed in the Scrolling section above) but after the first full screen length has been printed. If n=0, the scroll prompt function is inhibited for that layer/window. Note that the n number of lines is calculated based on an 8 pixel character height. That can lead to some very confusing results if your chosen character height is different. Some are easy to calculate like the standard or double height characters, with the latter in essence halving the amount of lines but others not so easy as with the reduced height and double reduced height characters. In the two last cases you have to calculate how many pixels your program outputs vertically by getting the amount of actual lines times the height of the characters and then divide the product by 8 (standard character height) in order to arrive to how many lines you need to instruct the system via the Scroll-prompt inhibitor control code to allow.

If this sounds unnecessarily complicated that's because it is! In most cases, the average user will either need to disable scroll-prompting by setting n to 0 or just set it to a full screen of data by setting n to 24 (for all screen modes except LAYER 1,0 which requires n set to 12).

On Layer 0 you can duplicate that behaviour albeit in a less confusing way since the characters are always 8 pixels high, by employing a bit of POKE trickery to inhibit the scroll? prompt by doing:


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.