If you need to provide storage space for even a moderately long machine lansuage program, filling a REM statement with exactly the right number of dummy characters can be quite a chore, and making space for a really long problem is sheer drudgery. There is a way that you can provide as many spaces as you like without having to type even 100 dummy characters.
As I am sure you know, the EDIT function can be used to duplicate an existing line. It would seem that this could be used to create as much storage space as required, and it can.
However, there is more to it than just duplicating lines. Since the ZX81 does not store lines exactly as you enter them, this complicates matters a little. The decimal line number is converted and stored as a two byte hexadecimal number. All commands within a statement are stored as a single hexadecimal code byte. Two more bytes are used to store the byte count of the line, starting at the first code byte and including the decimal number 118 with which each line is terminated.
When a series of consecutive REM statements is to be used to provide storage for machine language the leading four bytes of the second and subsequent REMs cannot simply be overwritten. Your machine language program would almost certainly crash.
The solution is relatively simple. Change the byte count of the first REM statement to include the byte count of all of the REM statements to be used for machine language storage. This count must include not only the dummy characters in each REM, but also the other bytes the ROM uses in storing the line. Two for the line number, two for the byte count, one for the command code byte and one for the terminator for a total of six.
Therefore, if you wanted to reserve 500 spaces, it would seem logical to assume that five REMs, each containing 94 dummy characters would do the job. Let’s see if it will.
In the first REM only the terminator will be converted to a storage space. That’s 95 spaces. All 100 bytes of the second, third, and fourth REMs will become storage space, but only 99 of the fifth because the terminator must remain. This makes a total of 494 storage spaces, six short. Five REMs of 95 characters will still be one short. EDIT can be used to add one more character to one of the REMs.
You can find the number of REM statements and the number of dummy characters that should be in each one in the following manner:
1) Add six to the number of storage locations that you need.
2) Divide the result by the number of characters you estimate that you will need in each plus six. If there is no remainder, the result is the number of REMs that you will need.
3) If there is a remainder, and, if it is more than the integer, increase or decrease the number of dummy characters.
4) When the remainder is less than the integer, construct the first REM statement on line number 1 and duplicate it the required number of times. Then add the remainder, if any, to one of the lines using EDIT.
5) To check everything up to this point, add 16514 to the number of storage locations that you intend to create and PEEK the resulting locations that you intend to create and PEEK the resulting address. You should find 118 there which is the terminator of the last REM statement in decimal form.
6) Now add 2 to the number of storage locations you want and divide the result by 256. POKE the remainder, even if it is zero, into 16511 and the integer into 16512, the locations of the byte count.
The first time you use this system, you will probably think it did not work because, when the Basic program is listed, the REMs that were supposed to be eliminated will still be listed. Before you spend a lot of time and effort checking for errors and then writing a letter to the editor if you cannot find any, try this. Use the up and down arrows to move the cursor. You should find that it skips from line 1 to the line following the last REM listed or, if there is no such line, the cursor should stay on line 1. If the cursor does not do this, then start looking for errors.
This system can also be used to add more space for machine language programs if you should need it. In this case it becomes very simple. Just add the total number of bytes in all of the REMs that you add. Although the terminator of the last new REM cannot be converted to storage, the terminator of the existing REM will be, so everything comes out even.