TS1000/1500 Program Chaining, Part Five

Author(s): Earl Dunnington
Pub Details: Time Designs Magazine v3 n2 (Volume 3, Issue 2)
Date: January/February 1987
Pages: 39-40

In the previous episode of this series, the use of an endless tape with a chained program was presented. I failed to mention that the tape recorder could be left running while the program is being used. The maximum access time for the next module would be one minute for the one minute tape or three minutes for the three minute tape. Due to the manner in which these tapes operate, just how long it would take before the tape failed, when used in your own recorder, is a matter for you to investigate. The best method of using a chained program on endless tape, if your tape recorder has a jack for an external motor switch, is to leave the recorder on play and use a foot switch (Radio Shack #44-610 $2.99) to turn the motor on and off. This same method could also be used, if the entire program requires more than a three minute tape or you do not wish to use an endless tape, by recording the modules several times on a regular tape. Using the demonstration program as an example, you would record the modules as follows: RT, TE, PRT, TE, PRT, TE, PRT, ect.

Even those readers with only a 2k RAM, now have a basis for a full-featured word processor, a file program or a data base by adding additional modules. One of the first would probably be a SAVE/LOAD module. Because the data (text) is stored above RAMTOP and BASIC on this computer does not have a command to SAVE or LOAD data from this area, a machine code program is required. Unfortunately there are only so many ways to write a program like this and they have been published and copyrighted, precluding me from presenting a listing in this article. A data SAVE/LOAD program was published August 1984 in the now defunct SYNTAX. A similar program is in David B. Wood‘s book “Machine Language Programming On The Timex/Sinclair” from Siriusware. For thoe readers who have a ZX81 or TS1000 with at least 16k RAM and who do not mind losing some storage space above RAMTOP, as the program itself occupies 2k RAM, there is a faster-than-normal SAVE/LOAD from anywhere in memory program available from Zebra Systems Inc. (Z-XLR8 Cat# GR04 $11 plus $3 for postage). According to Zebra, this program will not work on the TS1500. Perhaps one of our more accomplished Z80 Assembly Language programmers could develop some pokes to this program for the TS1500.

Additional modules you might wish to add to the chained program could be Text Corrections, Cut and Paste, Right Justification, Letter Heading, and Search modules. As the tree modules presented in the previous episode were developed strictly for demonstration purposes, feel free to use them, as is, or changed in your own program. In order to do this, you should know how the value for RAMTOP and the variable B were determined.

For a more detailed explanation of the procedure involved, please see “Adventures In The RAM Jungle” (Sept/Oct ’85 to Jan/Feb ’86 issues of TDM). This method for determining the Upper and Lower Limits of the Safe Area will not work when there are expanding un-dimensioned strings in the program, due to the random use of the Spare Area of the RAM by the ROM routine. The Wicked Wizard of ROM strikes again!

The Spare Area of the user-available RAM is located between the top of the Calculator Stack and the bottom of the Machine Stack (see page 128 of the TS1000 or page 154 of the TS1500 User Manuals). When the computer is turned on, the addresses in this area are filled with zeros. Upon loading and running a program from tape, the Calculator Stack expands upwards and the Machine Stack downwards into the Spare Area leaving, what I call the Safe area untouched. The Upper Limit of the Safe Area is easily determined, as the Machine Stack leaves a trail of values other than zeros as it contracts upwards. Determining the Lower Limit is more difficult, because as the Calculator Stack contracts downwards it either replaces the zeros when RAMTOP is set above address 19711 or fills the addresses with the values stored in the Safe Area just above the Lower Limit, if RAMTOP is set to 19711 or less, an INPUT command is in the program, and the DELETE command is used to correct the input. The Wicked Wizard does not play by the same rules all of the time! In addition, when RAMTOP is set to 19711 or less, the computer is in the minimum display file mode and as characters are printed on the screen, the display file expands, pushing the Calculator stack upwards. Therefore, in the case of the demonstration program, we cannot allow the program to be listed when determining the Lower Limit of the Safe Area.

The number of bytes in the Safe Area plus 36, of the module requiring the most memory in order to operate determines the address to which we can lower RAMTOP and still have both the entire program and the computer operate properly.

I must admit that having a TS1000, I set RAMTOP to 2k (address 18432) and developed the TE module first, as I expected it to require most memory. The text in this case being POKEd to 18433 and above. I then determined the Safe Area for that module. Next I programmed the PRT module, also with RAMTOP set to 2k, and determined the Safe Area for it. Then I programmed the RT module so that it would not move RAMTOP from 18432, as otherwise the Safe Area for that module could not be determined. However, in order that those readers with only 2k RAM can follow the method used in determining the Safe Areas, we will work with RAMTOP set to 1k or address 17408.

Here is some homework to be done in preparation for the conclusion of this series. You will need a tape that is blank on at least one side. Turn on your computer and set RAMTOP to address 17408 by entering the following immediate commands:

POKE 16388,0
POKE 16389,68
NEW

To check that RAMTOP has actually been moved, enter the direct command:

PRINT PEEK 17407

The result should be a 62 printed on the screen.

Load the TE module from your master tape, your operating tape, or type in the TE module from the listing (Fig.2) on page 16 of the Nov/Dec ’86 issue of TDM. Change line 180 to read:

180 LET A=VAL "17409"

Enter the direct commands:

CLEAR
DIM T$(32)
LET B=18401

The variable B used here was computed for 2k RAM, but can be used with larger RAM for the purpose of determining the Safe Areas. After checking the program against the listing, record the TE module on tape using the direct command:

GOTO 140

To clear the computer enter NEW and either load the PRT module from your master tape, your operating tape, or type in the listing (Fig.3) on page 16 of the last issue. Change line 140 to read:

140 FOR N=VAL "17409" TO B

Enter the direct commands:

CLEAR
DIM A$(1)
LET B=18401

After checking against the listing, record the PRT module, as the next program on the tape, using the direct command:

GOTO 10

To clear the computer enter NEW. The RT module must not be loaded from the operating tape, as it would change RAMTOP. It must be revised so that it will not move RAMTOP from 17408 in order to determine the Safe Area of this module. If you recorded it along with lines 141 to 144 on a master tape, you can load it into the computer without running it. Otherwise, type in the listing from page 16 (Fig.1) of the last issue. See if you can make the changes to set RAMTOP to 17408 without referring to Fig.4 in this issue. Check the program very carefully against Fig.4 and then use the direct command:

GOTO 141

To poke the machine code into the REM statement, delete lines 141 to 144 , as they are no longer needed to save memory. Record the module as the next program on the tape, using the direct command:

GOTO 10

When the diagonal LOAD lines appear, use the BREAK key and stop the tape. Enter the direct command:

PRINT PEEK 16388+256*PEEK 16389

If all is well 17408 will be printed on the screen.

Label these recordings as preliminary. They will be used to demonstrate the method of determining the Safe Area of each module and the minimum address to which RAMTOP can be set. This will be covered in the conclusion of this series of articles.

Figure No. 4: Routine to set RAMTOP to 17408

  1 REM 1234
10 SAVE "RT"
20 FAST
30 POKE VAL "16388",VAL "000"
40 POKE VAL "16389",VAL "68"
50 POKE VAL "17407",VAL "62"
60 POKE VAL "17406",VAL "0"
70 POKE VAL "17405",VAL "6"
80 POKE VAL "17404",VAL "118"
90 POKE VAL "16386",VAL "252"
100 POKE VAL "16387",VAL "67"
110 RAND USR VAL "16514"
120 GOSUB VAL "140"
130 LOAD "TE"
140 RETURN
141 POKE 16514,49
142 POKE 16515,252
143 POKE 16516,67
144 POKE 16517,201