REM Builder for TS1000

See all articles from T-S Horizons n12
Author(s): Robert Hartung
Publication: T-S Horizons
Pub Details: T-S Horizons n12 (Issue 12)
Date: February/March 1985
Pages: 7

The best of New-Year’s to you and Scott and Randy, and congratulations on the constantly improving quality of T-S H. Thanks also for printing my version of the “Spirograph” routine. (See TSH #10, p. 29)

Seeing Mather White’s REM-expansion routine in T-S H reminded me of a REMBUILDER routine I use with my ZX81 — yes, I still use it, especially for machine code programs, since getting my TS2068. It allows either building a REM to any desired number of characters, or adding just one byte at a time as each data item or machine code is entered to a given address. It is rather lengthy but if SAVEd to tape as a utility routine is very handy for use in any listing requiring the POKEing of data or machine code into a REM statement.

The routine requires first making a short REM line containing code needed to CALL the MAKE-SPACE routine in ROM. These codes may be POKEd directly to the given addresses of an eleven-byte line 1 REM, or else a short listing may be entered for use as a loader as follows:

LISTING 1
1 REM 12345678901
2 FOR N=16516 TO 16522
3 INPUT P
4 PRINT N;"=";P
5 POKE N,P
6 NEXT N

POKE directly or use the loader to enter these codes at the given addresses:

16516,42
16517,130        16520,155
16518,64         16521,9
16519,205        16522,201

REMBUILDER LISTING:

   1 REM (11 bytes)
2 GO TO 5
3 POKE 16523,PEEK 16396
4 POKE 16524,PEEK 16397
5 LET M=PEEK 16523+256*PEEK 16524
6 LET D=M
7 PRINT " INPUT NO. REM SPACES REQUIRED OR ""A"" TO ADD ONE AT A TIME"
8 INPUT B$
9 IF CODE B$>37 THEN GOTO 13
10 LET A=VAL B$
11 LET B$="27"
12 GOTO 20
13 LET A=1
14 CLS
15 PRINT "KEY ENTER TO STOP"
16 PRINT "CODE AT ADDRESS ";D;"=";
17 INPUT B$
18 IF B$="" THEN STOP
19 PRINT B$
20 IF PEEK 16442<3 THEN SCROLL
21 LET D=VAL P$-2
22 FOR J=1 TO A
23 POKE 16515,INT ((D+J)/256)
24 POKE 16514,D+J-256*PEEK 16515
25 RAND USR 16516
26 POKE D+J,VAL B$
27 NEXT J
28 LET D=VAL P$
29 POKE (M-3),INT ((D-M+2)/256)
30 POKE (M-4),D-M+2-256*PEEK (M-3)
31 POKE D,118
32 GOTO 16
33 SAVE "REMBUILDER"
34 LET P$="PEEK 16396+256*PEEK 16397"
35 GOTO 3
50 REM

COMMENTS:

Line 1:      Contains characters POKEd by above codes)
Lines 3-5:   Stores location of start of DFILE (display file) as it
             was with the original empty REM statement at line 50.
             The address (M-1) is the beginning byte of this REM
             statement if no changes are made in the listing after
             the last-line REM is expanded.
Line 16:     Addresses given here mark the location of each code or
             byte of data POKEd in.
Lines 23-24: Address of space currently being added to REM
Line 25:     CALL to MAKE-SPACE routine in ROM at address 2459d
Line 28:     New address for DFILE
Lines 29-30: New length-of-REM bytes at beginning of REM statement
             in RAM
Line 31:     New end-of-REM byte
Line 34:     Definition of beginning of DFILE which follows last
             byte of BASIC listing

Before SAVEing to tape, POKE 16389,76 for shorter SAVE and LOAD times. Start the recorder and enter RUN 33 to make the SAVE. On re-LOADing, the first prompt asks for the entry of either the number of spaces to be defined in the last line 50 REM and filled with periods, or else the letter “A” if you wish to expand the REM just one byte at a time as each code is POKEd into it. To restart, enter line 50 as an empty REM statement and RUN 34.

If your machine code routine is relocatable, i.e. contains only relative JP and CALL addresses or CALLs to ROM, and none of the “forbidden codes” 118 and 126, the completed REM statement in which it is stored may be brought down by EDIT and changed to line 1. Otherwise, no changes may be made in the REM line nor in any of the lines preceding it without disrupting the routine you have POKEd into the last-line REM statement.

Since the variables M and D give the location of the beginning and the ending bytes of the last-line REM, this routine may be quite easily adapted for storing and retrieving data files, with de-limiter characters to make a separation between items in the file. It makes possible the expansion of the file REM only as actually needed to contain the items currently in the file. This can conserve considerable time in making SAVEs and LOADs of shorter files to and from tape with the ZX81/TS1000.

I have used the REMBUILDER as the basis for a filing and sorting routine in BASIC, which is quite slow, but in machine code (see Tom B. Woods “Linear Search” in SYNC 3:6, p.72) a 13K file may be searched in about a second–not at all shabby for a “toy” computer, as so many of its critics have called it! Rather than letting the old ZX81/TS1000 gather dust now that you have up-graded, it could be used as a very practical dedicated filing system, as many are doing with programs like ZX PRO/FILE.

Best regards.
Bob Hartung
[address omitted]

TSH

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.