REM lines are often used to store machine code in the ZX81 and TS1000/1500 computer. A few months ago I needed a REM line with 600 spaces in it. Rather than type it in by hand, I developed a machine-code routine to make it. The routine will generate a REM line of any length and insert it anywhere in a program listing. It is relocatable. The line thus generated can be used to hold your machine code, to make space for program merging, or to hold data.
To begin with, enter a program for loading machine code:
1 REM 123456789012345678901234567890123456789012345678901234567890123
10 REM REM GENERATOR
20 REM CHUCK PETERSON
30 DIM A$(4)
40 FOR F=16514 TO 16576
50 INPUT A$
60 POKE F, VAL A$
70 PRINT A$;
80 NEXT F
90 POKE 16510,0
100 STOP
The POKE in line 90 changes the number of the first line from 1 to 0.
RUN the program. When the cursor (in quotes) appears, enter the following numbers one at a time. Go from left to right and top to bottom.
205 35 15 42 10 64 229 205 216 9 43 237 75 50 64 3 3 197 3 3 3 3 205 158 9 193 209 35 35 114 35 115 35 113 35 112 35 54 234 11 11 35 54 27 120 177 32 248 54 117 52 42 12 64 34 41 64 213 205 43 15 193 201
The program will stop with a 9/100 report at the bottom of the screen. Check the numbers on the screen against the above listing. If all is well, try out the routine. Assume a for a moment that a line, 25 REM, is needed which is to have 119 spaces (bytes) in it. In the immediate mode, type the following, pressing ENTER after each:
25
RAND 119
LIST USR 16514
The routine will insert line 25 REM into the program and LIST it. This line can be edited and deleted like any other line.
Now for a warning: don’t try to generate a long REM line just yet. We’ll get to that later.
Whatever can go wrong, will go wrong. So, it is advisable at this point to save the program. Delete line 25, then start your recorder and enter SAVE “REM”.
You can change the character that fills the REM line. Address 16557 holds the character code. It now holds 27, which gets printed as a period. For machine code work, 0’s (NOP or “no operation”) are better, as are 201’s (RETurn). To change to 0’s, for example, type POKE 16557,0 and press ENTER. Call for a REM line and it will be filled with zeros, which are printed as spaces.
For the sake of shortness and simplicity, the routine was written without prompts. It will be easy to forget how to use it. To preserve your own sanity, add the following lines:
30 REM USE IN IMMEDIATE MODE:
40 REM "(LINE NO.)"
50 REM "RAND (NO. OF BYTES)"
60 REM "LIST USR 16514"
70 SAVE "REM"
80 LIST
Delete lines 90 and 100. SAVE this revision for future use by starting your tape recorder and then typing RUN and ENTER. Now, for a diversion, type the following and press ENTER after each:
LIST 30
RAND 23
LIST USR 16514
LIST USR 16514
LIST USR 16514
Delete line 30 three times in a row!
Generated REM lines, especially long ones, can cause big trouble. If you haven’t saved the routine, do it now. Let’s make trouble. Generate a REM line whose line number is 9998, making it 1000 bytes long. Then add the following line:
9999 PRINT
Get ready to pull the plug. Delete line 9999. The computer will unsuccessfully try to list line 9998 and the keyboard will not respond to BREAK. The computer is locked up and the only way to continue is to reset or pull the plug, losing the program. This same lock-up occurs occasionally if the generated REM line is the only or last line of a program.
To avoid catastrophe, always make sure that there is another line, with a higher line number, after your generated REM. If there is none, add one. It can be a short REM line. The added line can be edited or replaced, but never delete it.
[Editor’s note: You can delete a short line after a long REM if you POKE the first two locations of the REM with 118, thus fooling the LIST routine into thinking that the end of the display file has been reached. After deleting the short line, POKE the original values back in. For example, for a 1 REM, POKE 16514 and 16515 with 118, delete the short line (e.g., 2), then POKE 16514 and 16515 with 27 (or the original values). -tb]
Put It Anywhere
REM Generator can be relocated. If you tried the above experiment, load it back into your computer. Transfer the routine to the 8-16K block, if available. Another place to store it is above RAMTOP. The following is one way to transfer it there. Add to lines 0, 10 and 20:
30 SAVE "REM"
40 POKE 16388,88
50 POKE 16389,127
60 FOR F=16514 TO 16576
70 POKE F+16086,PEEK F
80 NEXT F
90 NEW
The program resets RAMTOP to 32600. To use it, start your recorder and RUN the program. Your computer will first save it, then reset RAMTOP, transfer the routine and execute NEW. When the cursor returns to the screen, generate a REM line as before with one exception; for the final command use LIST USR 32600
With the machine code relocated I have been able to generate a REM line which is 15000 bytes long! Don’t worry about asking for too many bytes. If you specify too many, the screen comes back blank with a report code 4/0 (out of memory). The computer will be in FAST mode, and your program will not have been affected.
As with all routines, the best way to learn more about the REM generator is to play with it. So go at it!
TS1000 REM Generator Disassembly
4082 CD230F CALL FAST
4085 2A0A40 LD HL,(E PPC)
4088 E5 PUSH HL
4089 CDD809 CALL LINE
408C 2B DEC HL
408D ED4B3240 LD BC,(SEED)
4091 03 INC BC
4092 03 INC BC
4093 C5 PUSH BC
4094 03 INC BC
4095 03 INC BC
4096 03 INC BC
4097 03 INC BC
4098 CD9E09 CALL SPAC
409B C1 POP BC
409C D1 POP DE
409D 23 INC HL
409E 23 INC HL
409F 72 LD (HL),D
40A0 23 INC HL
40A1 73 LD (HL),E
40A2 23 INC HL
40A3 71 LD (HL),C
40A4 23 INC HL
40A5 70 LD(HL),B
40A6 23 INC HL
40A7 36EA LD (HL),EA
40A9 0B DEC BC
40AA 0B NEXT DEC BC
40AB 23 CHAR INC HL
40AC 361B LD (HL),1B
40AE 78 LD A,B
40AF B1 OR C
40B0 20F8 JR NZ NEXT
40B2 3675 LD (HL),75
40B4 34 INC (HL)
40B5 2A0C40 LD HL,(DFILE)
40B8 222940 LD (NXTLN),HL
40BB D5 PUSH DE
40BC CD2B0F CALL SLOW
40BF C1 POP BC
40C0 C9 RET
40C1 76 HLT
40C2 00 NOP
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.