TS 1000/TS 1500 Program Chaining, Conclusion

Author(s): Earl Dunnington
Pub Details: Time Designs Magazine v3 n3 (Volume 3, Issue 3)
Date: March/April 1987
Pages: 26-27

A few “bugs” crept into the manuscript and the text of Part Five as published in the last issue. The “tree” in line 4 of the second paragraph, on the left side of page 40, should read “three”. The “TS1000” in the first line of the last paragraph, also on the left side of page 40, should be “TS1500”. The “needed to save memory” starting on line 13, from the bottom of the right column on page 40, should read “needed and to save memory”.

Having completed the homework assigned in Part Five, we are now ready to determine the Upper Limit of the Safe Area, the address of E_Line, the Lower Limit of the Safe Area, for each module and the minimum address to which we can lower RAMTOP and have the entire Chained Program operate properly. We will start with the TE module.

Turn on the computer and set RAMTOP to 17408, by entering the direct commands:

FAST
POKE 16389,68
NEW

Load the preliminary TE module from your homework tape using the direct command:

LOAD "TE"

When the cursor appears, type in one 32 character line (the left hand quote symbol marks the end of the line), then press ENTER. Type in STOP (using the shifted A key), then press ENTER. When the prompt appears, press any key. When the diagonal LOAD lines appear, press BREAK.

To determine the address of the Upper Limit of the Safe Area, starting at RAMTOP minus 50 (in this case 17408-50=17358), PEEK each address downwards in memory, noting the decimal value returned, until you find nothing but zeros for at least ten addresses. The command to be used is:

PRINT PEEK nnnnn

where the “n’s” are the address to be PEEKed. The address just before those with all the zeros should be 17353 and should contain the decimal value 125. As the values used in the Machine Stack and the GOSUB stacks are pairs, in this case the High Byte occupying the higher uneven address (because RAMTOP is set to an even value), the Low Byte is zero in address 17352 and the Upper Limit (UL) of the Safe Area is the address 17351 for the TE module.

To determine the addrss of E_Line use the direct command:

PRINT PEEK 16404+256*PEEK 16405

The value returned should be 16918.

To determine the Lower Limit of the Safe Area and to overcome the curve that the Wicked Wizard of ROM has presented us with, we will use a slightly different “Flypaper” program than the one presented in Part Two of “Adventures In The RAM Jungle And Other Mysteries” (page 12, Nov/Dec ’85 issue of TDM). Instead of POKEing a 5 into the addresses above E_Line, we will POKE a series of numbers from E_Line up in memory, using the Flypaper program (Figure No.5). After loading and operating the TE or other module, the top of the Calculator Stack can be found where the series is broken. The Lower Limit is the address just above this, where the value has not been changed.

If your computer is still on, use NEW to clear the memory, other wise turn on the compute and reset RAMTOP to 17408 as you did before. Type in the program of Figure No.5. Enter the direct commands:

LET A=1
GOTO 10

When the 0/40 appears at the bottom of the display, load the preliminary TE module again from your homework tape using the command:

LOAD "TE"

When the prompt appears on the screen and the cursor appears, type in 62 characters this time before pressing ENTER. We use 62 characters this time to allow for the typist making an error by over-running the end of line marker (the left hand quote symbol). Type the keyword STOP (shifted A key) and press ENTER. When the new prompt appears, press any key. When the diagonal load lines appear on the display, press BREAK. Enter the direct commands:

CLEAR
PRINT PEEK 17172

The value returned should be 255. Continue PEEKing the addresses down in memory until you locate where the series breaks. All going properly it should be at address 17039 with the value returned of 186. This address marks the highest address that the top of the Calculator Stack used during the program run. The Lower Limit of the Safe Area is the next higher address 17040 with the value returned of 123. You must be careful not to do anything that would LIST the program during the determination of the Lower Limit as this would mess up the values and you would have to start over.

We now have the data we need to find out the number of bytes in the Safe Area of the TE module (each address holds one byte or eight bits). The formula for this is:

Upper Limit-Lower Limit+1

For the TE Module:

17351-17040+1=312

As there must always be 36 bytes in the Spare Area of the memory to avoid an out of memory error, the approximate lowest value to which we can set RAMTOP and have the program and the computer operate properly is:

17408-312+36=17132 (APPROXIMATE)

The value is approximate because when the top of the Calculator Stack is at its maximum address, the Machine Stack may extend down a minimum number of addresses below RAMTOP or vice versa. Because of this some programs will operate without adding any or all of the 36 bytes. Trial and error is the way to find out. In this case we do not have to add any of the 36 bytes and the minimum address to which RAMTOP can be set for the final version of the TE module is:

17408-312=17096

The typist can actually overrun 31 characters and press ENTER without the computer acting up. As it is standard programming procedure never to store any data in the address of RAMTOP, in line 180 of the final version of the TE module and line 140 of the final version of the PRT module, we use 17097.

The value of the variable B used in both the TE and PRT modules is dependent uppon the amount of RAM that you have. As an example, let us compute the value of B for a ZX81 with only 1k RAM. The first nonexistent address is 17408. The number of characters that could be stored would be:

17407-17097+1=311

The number of 32 character lines that can be stored are:

INT (311/32)=9

The number of characters in nine 32 character lines are:

9*32=288

When we are out of space to store a complete 32 character line, we want to stop the text input or the printer and in the TE module, a STOP character code (227) stored at:

B=17097+288=17385

As “repetition is the key to learning” and because each module presents a slightly different problem, let’s determine the addresses of the UL, E_Line, LL, and number of bytes in the Safe Area for the other two modules, starting with PRT.

Clean the memory by turning off the computer. In order to have the printer stop after printing one blank 32 character line, we need to POKE the address:

17409+32=17441

with the code for the BASIC keyword STOP (227). Also we want the fast mode and to set RAMTOP to 17408 prior to loading the preliminary PRT module from the homework tape. Enter the direct commands:

FAST
POKE 17441,227
POKE 16389,68
NEW
LOAD "PRT"

When the PRINT TEXT query appears, energize the TS2040 printer and press the on switch. Type in Y and press ENTER. After one blank line is printed and the query appears again, type in N and press ENTER. When the diagonal load lines appear, press BREAK.

From this point on proceed as before to locate the Upper Limit. The last value prior to nothing but zeros will be a 224 in address 17351 and the UL will be 17349.

Find the address of E_Line for the PRT module by entering the same direct command used for the TE Module. The value returned should be 16859 which will be used in line 10 of the Flypaper program.

To determine the Lower Limit of the Safe Area of the preliminary PRT module, clean the memory by entering NEW. Type in the program of Figure No.5, changing line 10 to read:

10 FOR N=16859 TO 17113

Enter the direct command:

LET A=1
GOTO 10

When 0/40 appears, enter:

LOAD "PRT"

Figure No. 5: Flypaper Program

10 FOR N=16918 TO 17172
20 POKE N,A
30 LET A=A+1
40 NEXT N

Operate the program as before. After using the BREAK key,key, enter the direct command:

CLEAR

This wipes out any reserved space, variables, or strings stored in the VARS area, moving all the areas above it up to the top of the Calculator Stack, down in memory, so that PEEKing the addresses will not write over where the top of the Calculator Stack was during the program run. Locate where the series breaks by PEEKing the addresses down in memory from 17113. You should find this at 16911 with a zero returned. The Lower Limit would be address 16912 with a 54 returned.

The number of bytes in the Safe Area are:

UL-LL+1=17349-16912+1=438

The approximate minimum address for RAMTOP for the PRT module would be:

17408-438+36=17006

By trial and error RAMTOP could be set at 17003 and the PRT module and the computer would operate properly.

If your computer is still on with RAMTOP at 17408, enter NEW to clean the memory. Otherwise POKE 16389 with 68 and use NEW. Then load the preliminary RT module from your homework tape. Proceeding in a similar manner as you did for other modules, find the address of the UL and E_Line which should be 17347 and 16765 respectively.

The program in the RT module does not use the VARS area. Therefore CLEAR will not move the top of the Calculator Stack down in memory so that peeking the addresses to find the Lower Limit would write over where it was during the program run. To fix this problem enter the direct command:

DIM A$(64)

This reserves space in the VARS area for the string A$ and moving the areas above it up in memory including the Calculator Stack. Again find the address of E_Line. It should now be 16835. Re-record the module using GOTO 10.

Clean the memory using NEW and type in the Flypaper program, changing line 10 to read:

10 FOR N=16835 TO 17089

Enter the direct commands:

LET A=1
GOTO 10

After the 0/40 appears, enter:

LOAD "RT"

Use the re-recorded RT module. From this point on proceed in a similar fashion as you did for the other modules to find the Lower Limit. The series breaks at 16870 with a zero returned. The address above is 16871 with a 37 returned. Adjusting this address for the space reserved in VARS, the Lower Limit = 16871-70=16801.

The number of bytes in the Safe Area of the preliminary RT module is:

UL-LL+1=17347-16801+1=547

The approximate minimum address to which RAMTOP can be set for the RT module is:

17408-547+36=16897

As the highest minimum address to which RAMTOP can be set for any of the modules in the chained program is 17096, then this is the value that must be used for the final versions of the modules.

To coin a phrase…explore and “master the possibilities” of your computer. With properly designed software and hardware add-ons, there is nothing a Big Blue, Apple, or AT&T can do that you cannot.