ZX 81 - BASIC Programming

Sinclair ZX Spectrum
Chapter 23 - When the computer gets full
The ZX81 has a limited amount of internal storage, and it is not hard to fill it up. The best sign of this happening is usually an error report 4, but other things can happen and some of them are rather strange. The exact behaviour depends on whether you have a memory expansion board attached, so first let us assume that you have not. If you have, take it off (after first switching off the computer).

The display file, that is to say the area inside the computer where it stores the television picture, is cunningly designed so that it only takes up space for what has been printed so far: a line in the display consists of up to 32 characters and then a NEWLINE character. This means that you can run out of memory by printing something, and the most obvious place is while making a listing. Type

NEW

DIM A(150)

10 FOR N=1 TO 15

20 PRINT N

Here comes the first surprise: line 10 disappears from the listing. The listing is bound to include the current line, 20, and there is not room for both lines. Now type

30 NEXT N

Again, there is only room for line 30 in the listing. Now type

40 REM X    (without NEWLINE)

and you will see line 30 disappear and line 40 jump to the top of the screen. It has not been entered in the program - you still have the cursor and can move it about. All you have seen is some obscure mechanism that gives the bottom half of the screen 24 lines to give it priority over the top half. Now type

XXXXXX    (still without NEWLINE)

and the cursor will disappear - there is no room to display it. Type another X, without NEWLINE, and one of the Xs will disappear. Now type NEWLINE. Everything will disappear, but the program is still in the computer, as you can prove by deleting line 10 and using & . Now type

10 FOR N=1 TO 15

again - it will move up to the top of the screen as line 40 did. But when you press NEWLINE, it will not be entered, although there is no error message or marker to say that anything is wrong. This is the result of there being no room to check the syntax of a line, and usually happens only for lines that contain numbers (other than the line number at the beginning).

The only cure is to make some space somehow, but first delete the line 10 that won't go in. Press EDIT: the screen will go blank, because there is no room to bring the line down.

When EDIT does not work it is sometimes possible to make space by typing a number of spaces until the cursor moves up the screen.

Press NEWLINE, and you will get part of the listing back. Now delete the line 40 (which you didn't really want anyway) by typing

40    (& NEWLINE)

Now try typing in line 10 again - and it still won't go. Rub it out again. You must still find some extra space somewhere.

Bear in mind that the reason that line 10 was rejected was probably that there was no room to check the syntax of the two numbers, 1 & 15: so if you delete line 20 in the program you might have room to enter line 10, and still have room to re-enter line 20 (which contains no number) afterwards. Try this. Type

20

10 FOR N=1 TO 15

20 PRINT N

and the program is entered properly.

Type

GOTO 10

and again you will find that this line is rejected because its syntax cannot be checked; however, if you rub it out and type

RUN

it will work. (RUN clears out the array, making plenty of space.)

Now type in the same as before from NEW up to line 30, and then

40 REM XXXXXXXXXXXX

(12 Xs), which will end up looking like 40 RE. When you press NEWLINE, the listing will just consist of line 30, and in fact line 40 has been completely lost. This is because it was simply too long to fit in the program. The effect is a bit worse when the line is a lengthened version of a line that is already in the program, for you will lose both the old line from the program and the new line that was to replace it.

The ultimate cure for this is to buy a RAM pack, which fits on the back of the computer. The Sinclair 16K RAM pack gives the computer sixteen times as much memory as it has in its unexpanded form.

If you have an old ZX80 3K RAM pack, it will not work on the ZX81.

The behaviour with the RAM pack is rather different, because the display file is filled out with spaces to make each line 32 characters long (note that SCROLL upsets this - see chapter 27). Now printing and listing will not make the computer run out of memory, and you will not see all these shortened listings, and jumping around; but you will see the lines sticking or getting lost, and again the only cure is to find some spare space.

If you have a memory expansion board, put it on and go through the typing in this chapter, using

DIM A(3069)

to replace DIM A(150).

To summarize, this is a tangled tale and the moral is to avoid getting an absolutely jam-packed computer if you can.

However, the second moral is that things are not usually as bad as they look.

    1. If the listing starts shortening or things start jumping around, then the space is getting tight.

    2. If NEWLINE seems to have no effect at the end of a line, then there is probably no room to deal with a number. Rub out the line using EDIT-NEWLINE or RUBOUT.

    3. NEWLINE might lose a line altogether.

For all these oddities, the cure is the same. Don't panic, and look for some spare space.

The first thing to consider is CLEAR. If you have some variables and you do not mind losing any of them, then this is the thing to do.

Failing this, look for unnecessary statements in the program, such as REM statements, and delete some of those.

Summary

When the memory fills up odd things can happen; but they are not usually fatal.

Sinclair ZX Spectrum

  Previous Page Back Next Page