
Good morning, Class! How are you? Getting ready for the holidays?
Today’s session will be on the subject of data. We have all seen how data can be created in a program and the program can be saved with the data intact. The GOTO command can execute the program after it has been re-loaded from tape and all the data is back again.
This system works fine for many situations. But, what if we wanted to set up a monthly record of transactions such as a customer file? Let us say that we had a business where we tuck-pointed houses. Let us say that once a year, we tuck-pointed each house. Our customer file program was designed to contain our sales on a monthly basis. With the TS-1000, we must have 12 separate files for each year.
After thinking awhile, we decide it would be much more cost-efficient to try to organize our jobs where we could each day do as many as possible in the same neighborhood with the smallest amount of travel time between jobs. Well, it wouldn’t be that difficult to sort each file by Zip Code or town to get the file in a type of order according to location. But we have 12 such files. It would be nice if a method existed where we could merge them.
Such a method does exist. It is simple in concept but laborious to achieve. It is not too efficient, as far as memory is concerned, but in theory, files that already exist as variables which were generated from the same program, have the potential to be merged. Once they are merged, they can be sorted. Here’s how it works:
First of all, we have to set aside an area of the TS-1000’s memory for the variables to be put into. This is where the inefficiency occurs. The variables are going to exist in two places at once in the computer’s memory banks. Let us say that we are going to change RAMTOP (the area of computer’s memory which is the limit where which no more bytes can be entered after) to 20000. On a 16K machine, RAMTOP is preset at 32768. The computer can tell you this by PEEKing locations 16388 & 16389. If you enter “PRINT PEEK 16388 + 256 * PEEK 16389”, you will see this number displayed. To change it to 20000, we first divide 20,000 by 256 and the integer we get is 78. The remainder is 32. If we enter “POKE 16388,32” & “POKE 16389,78” and then run the previous PEEK command, we find that RAMTOP is now set to 20,000.
Anything that is put in the memory area between 20,000 and 32,768 will be unaffected by any programming commands, including NEW and CLEAR. The only way that those memory locations will have their data altered is by program crashes, shutting the machine off or if different data is entered into those areas. To prove this, enter this program:
10 POKE 16388,32
20 POKE 16389,78
30 PRINT "ENTER YOUR NAME :::"
40 INPUT N$
100 LET N=LEN N$
110 LET A$=STR$(N)
120 FOR I=1 TO LEN A$
130 POKE 19999+N,CODE A$(I)
140 NEXT N
150 FOR I=1 TO N
160 POKE 20001+N,CODE N$(I)
170 NEXT I
Let us look at this portion of the program. Assuming the length of your name does not exceed 99 characters, your name will be assigned to the string “N$” in line #40. Line #100 determines how many characters are in your name and assigns that value to the variable “N”. Line #110 turns that value into the string variable “A$”.
The LOOP between 120 & 140 POKEs the CODEs of numbers which represent the amount of characters in your name, into memory locations 20,000 and 20,001. The LOOP between 150 & 170 POKEs the CODEs of the characters in your name into consecutive locations starting with 20,002.
RUN this program and enter your name. You can now either destroy the original variable or the entire program. Let us do both. Enter “PRINT N$”. You should see the name you entered. Now enter “CLEAR”. Enter “PRINT N$” again. The name is gone!
Save the program on tape, if you wish, for future reference. Now enter “NEW”! Try listing the program! Just as you suspected, everything is gone, right?
Wrong! Enter the following program:
10 LET A$=CHR$(PEEK 20000) +
CHR$(PEEK 20001)
20 LET N=VAL A$
30 LET N$=""
40 FOR I=1 TO N
50 LET N$=N$+CHR$(PEEK (20001+I))
60 NEXT I
70 PRINT N$
RUN the program! Voila! The name appears.
I’m sure many of you have been aware of this technique. The name was stored in an area that was protected by a pre-set RAMTOP and could not be destroyed by RUN, CLEAR or NEW. We can do the same thing with an array that is created. Enter the following program:
10 POKE 16388,32
15 LET EN=10
20 POKE 16389,78
30 DIM A$(100,5)
40 LET C$="BCDFGHJKLMNPQRSTVWXYZ"
50 LET D$="AEIOU"
60 LET P=20000
70 DIM E$(1,5)
80 DIM F$(1,5)
90 LET R1=0
100 FOR N=R1+1 TO 22
110 LET A=INT (21*RND)+1
120 LET A$(N,1)=C$(A)
130 LET A=INT (5*RND)+1
140 LET A$(N,2)=D$(A)
150 LET A=INT (21*RND)+1
160 LET A$(N,3)=C$(A)
170 LET A=INT (5*RND)+1
180 LET A$(N,4)=D$(A)
190 LET A=INT (21*RND)+1
200 LET A$(N,5)=C$(A)
210 PRINT A$(N),
220 NEXT N
300 LET R1=N-1
310 LET E$(1)=STR$ R1
320 FOR N=1 TO 5
330 POKE 19999+N,CODE E$(1,N)
340 NEXT N
350 FOR N=1 TO R1
360 FOR I=1 TO 5
370 POKE 20000+EN,CODE A$(N,I)
380 LET EN=EN+1
390 NEXT I
400 POKE 20000+EN,111
405 LET EN=EN+1
410 NEXT N
420 LET EN=20000+EN+1
430 LET F$(1)=STR$ EN
440 FOR N=1 TO 5
450 POKE 20004+N,CODE F$(1,N)
460 NEXT N
500 LET N=0
505 LET I=0
506 LET R1=VAL (CHR$ PEEK 20000+CHR$ PEEK 20001+CHR$ PEEK 20002+CHR$ PEEK 20003+CHR$ PEEK 20004)
510 CLS
520 PRINT CHR$ PEEK (20000+N);
530 LET N=N+1
540 IF PEEK (20000+N)=111 THEN LET I=I+1
550 IF I=R1 THEN GOTO 600
560 GOTO 520
600 PRINT
605 PRINT
610 FOR N=1 TO 22
620 PRINT A$(N),
630 NEXT N
22 random character strings are created by the routine from lines 40 to 220. The number total (22) is put into a character string “E$(1)”. Lines 320 to 340 POKE the CODEs of the “total string” into memory locations 20000 to 20004. The 22 character strings have their character codes POKEd into memory locations starting with 20010 with the routine from line #350 to #410 with each string separated by the “separator code”, “111”.
Line #420 determines the memory location of the last character that had it character CODE POKEd and line #430 converts that memory location into a string variable
The only area we haven’t examined is the memory locations 20005 to 20009. These locations hold the value of the memory location of the last character of the stored data. We can write a routine to add more data to the existing array held above RAMTOP by simply tacking it on starting with the next memory location beyond the one specified by the characters held in locations 20005 to 20010.
I hear the bell, so we’ll have to continue next session.
I’ll leave you with this poem by one of our country’s founding fathers, that great Pilgrim, Miles Standish:
“We welcome friends and family as the holidays unfold.
We’re thankful for the cheer and food and shelter from the cold.
But as the joyous feast unveils, our thoughts recall the word,
Temperate intake, slowly paced – don’t pig out on the bird!”
Happy Holidays to all my dear friends out there – The Old Professor
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.