Books Issue 11 Contents Mind Games


Andrew Hewson

Andrew Hewson looks at difficulties concerning the PRINT command

Finding the answer to screen filling

MOST OF the questions this month are concerned with PRINTing problems. The first is from Derek Barry, who asks: It can be very annoying when the screen fills on the ZX-81 and the program grinds to a halt with Report Code 5. Is there a way to scroll the display automatically?

The column and line numbers of the PRINT position are held in the system variables at 16441 and 16442 respectively. For some eccentric reason the line numbers are counted from the bottom of the screen upwards, starting at one, not from the top downwards starting at zero as with the PRINT AT command. The bottom two lines normally are reserved for INPUT and error messages, although a method for PRINTing on these lines is given later in this column; hence if 16442 contains 2 or less the program will fail at the next PRINT command.

To SCROLL the screen automatically include the following line before each relevant PRINT statement:


The Spectrum has a separate system variable at 23692 to keep track of the number of lines which may be PRINTed before the next


query should be issued. To prevent the query appearing, POKE a number larger than 1 - and less than 256 - into 23692 as often as necessary.

Daniel Guillemyn asks: Is it possible to set the colour of a pixel in the Spectrum display independently of all the others?

No. There are 256x192=49,152 pixels in the Spectrum display and 49,152/8=6,144 bytes are used simply to determine which of the pixels are illuminated and which are not. If each pixel could take any one of, say, eight colours, a further 3x6,192=18,576 bytes would be required, to say nothing of the extra hardware required.

All current colour computers make some compromise on the colour detail they support. In the Spectrum each eight by eight group of pixels which form a character position is assigned an INK, or foreground, colour and a PAPER, or background, colour. Colours can be assigned to each character position independently but changing the INK colour, for example, of one pixel in a character position also changes the INK colour of the other 63 pixels. There are 32x24=768 character positions in the display and their current colours are held in the attributes file which is held at locations 22528 to 23295.

Is there a way of printing on the bottom two lines of the display? asks Gordon Charlesworth. On the ZX-81 the DF-SZ system variable at 16418 is used to store the current number of lines, including one blank line, in the lower part of the screen. DF-SZ is normally set to 2 and is increased only when a particularly long line is being INPUT or EDITed.

To PRINT in the lower part of the screen, POKE the value 0 into DF-SZ, as in this example:

10 POKE 16418,0
30 PAUSE 32768

The PAUSE command is not necessary generally but I have included it in this example to prevent the STOP message being PRINTed and thereby obliterating the output from line 20.

The Spectrum stores the value of DF SZ at 23659 and the technique for PRINTing on the bottom of the screen is similar except that the machine will crash if PRINT AT is used on line 23 or if the value in 23659 is not POKEd back to 2 after use. The following routine PRINTs a number on all 241 lines of the display:

10 POKE 23659,0
20 FOR i=0 TO 23
30 PRINT i
40 NEXT i
50 POKE 23659,2
60 PAUSE 0

The machine will crash if the routine is run with line 50 omitted or if line 30 is replaced by:

30 PRINT AT i,i;i
Sinclair printout

Several people have asked about the machine code PRINT AT facility for the Spectrum described by Andrew Pennell in the October issue of Sinclair User. Andrew Beale, for example, writes: I cannot find a reference in Appendix A of the manual to the RST 10 command described. Please tell me the exact decimal codes to, say, PRINT AT 0,0;"A" in machine code.

It is conventional to count in hexadecimal when referring to machine code routines, thus the 10 in RST 10 is in hexadecimal, i.e., 16 in decimal. Appendix A of the Spectrum manual uses the decimal system so that the RST 10 instruction used by Pennell refers to the RST 16 instructions about one-third of the way down column four on page 186 of the manual. The decimal code is 215. The following routine is the machine code equivalent of

  PRINT AT 0,0;"A"

LD A,16         62 22
RST 10          215
LD A,0          62 0
RST 10          215
LD A,0          630
RST 10          215
LD A,41         62 65
RST 10          215
RET             201

The right-hand column lists the decimal codes. The routine can be loaded into the graphics area of the 16K Spectrum as follows:

10 DATA 62,22,215,62,0,215,62,0,215,62,65,215,201
20 FOR T=32600 TO 32612
30 READ a
40 POKE i,a
50 NEXT i

To call the routine, initialise the PRINT position and then use the USR function, for example:

110 RAND USR 32600

To alter the Y and X PRINT AT coordinates, change the fifth and eighth numbers in the DATA statement and to PRINT a different character change the eleventh number to the appropriate character code.

Finally, Philip Pfeil asks a perennial question. He writes: At the risk of admission to the funny farm, can you please tell me how to SAVE and LOAD programs into my ZX-81?

It is a sad fact that many people have difficulty in SAVEing and LOADing. The problem is particularly acute for the newcomer to the ZX-81 who has not had the experience to diagnose a fault. None of the advice I can offer is original; most of it has been published several times but I repeat it because about five percent of the letters I receive are from people who cannot LOAD and/or SAVE.

When SAVEing a program, make sure that the cassette and the player are free of dust, because even a momentary interruption in the recorded information will make reLOADing impossible. Connect one lead only - the SAVE lead in this case - between the computer and the cassette player, otherwise a low frequency hum may be recorded on the tape, smothering the signal from the ZX-81.

A television set generates a strong oscillating electric field and the result can be a high-pitched noise recorded on the cassette. The cure is to keep the cassette player at least three feet from the TV set. Always SAVE at least two copies, thereby increasing the probability of obtaining an adequate copy.

Some people suggest that batteries should be used to power the cassette player so that there is no possibility of picking up interference through the mains supply. I have always found that batteries are more trouble than they are worth; even the high-power versions drain very rapidly, causing the cassette player to run too slowly.

Similar precautions should be taken when LOADing a tape but you must also adjust the volume on the cassette recorder to the required level. If the sound is not loud enough to make you wince when the tape is played with the EAR lead disconnected from the recorder you are unlikely to be able to LOAD the program satisfactorily.

When LOADING, the TV display should show fluctuating broad black and white bands like a zebra crossing. If the volume is low the bands will not appear or the black parts will be interspersed with white. If the volume is too high the screen will appear almost entirely black. Adjust the volume by making a dummy run through the tape.

If you find SAVEing and/or LOADing is impossible, your next step should be to isolate the problem as it could be the tape, the cassette player or the ZX-81. The easiest way to do so is to contact a fellow ZX-81 owner and swap your items with his until you are certain which unit is at fault. Even if the other person is a complete stranger, you will no doubt have an enjoyable time swapping tips with him which may be some consolation if the worst comes to the worst and you have to return your computer for exchange or repair.

Books Issue 11 Contents Mind Games

Sinclair User
February 1983