TS-2068 VARS Save and Re-Load
For Larken LKDOS or Cassette
UPDATE Donates this utility to Public Domain.
9900 RANDOMIZE USR 100: OPEN #4,"DD": RANDOMIZE USR VAL "100": OPEN #3,"lp": LET elin=1: LET vars=1: LET h80=1: LET x$="111": LET y$="111": LET z$="11111.C1": LET l$="11111"
9910 LET vars=PEEK 23627+256*PEEK 23628: FOR n=1 TO 1: NEXT n
9915 LET elin=PEEK 23641+256*PEEK 23642
9920 LET x$=STR$ (PEEK 23627): LET y$=STR$ (PEEK 23628)
9925 IF LEN x$<3 THEN LET x$=STR$ 0+x$: GO TO VAL "9925"
9930 IF LEN y$<3 THEN LET y$=STR$ 0+y$: GO TO 9930
9935 LET l$=STR$ (elin-vars-1)
9940 IF LEN l$<5 THEN LET l$=STR$ 0+l$: GO TO 9940
9945 LET z$=l$+".C1"
9950 LET h80=PEEK 23641+256*PEEK 23642-1
9965 PRINT "elin=";elin;TAB 12;"Eadr=";PEEK 23641+256*PEEK 23642''"vars=";vars;TAB 12;"Vadr=";PEEK 23627+256*PEEK 23628''"Length=";l$''"Length verif=";(PEEK 23641+256*PEEK 23642)-(PEEK 23627+256*PEEK 23628)-1''"Vlsb=";x$;TAB 14;"Vmsb=";y$''"Vlen=";z$;TAB 15;"is Ser # of SAVE"''"h80=";h80;TAB 14;"Verif=";PEEK (PEEK 23641+256*PEEK 23642-1)
9970 PRINT ''"ENTER When Ready": PAUSE 0: RANDOMIZE USR 100: SAVE z$CODE vars,VAL l$
9972 REM Pad xxxxxxxxxxxxxxxx
9980 CLEAR : RANDOMIZE USR 100: OPEN #4,"dd": RANDOMIZE USR 100: OPEN #3,"LP": RANDOMIZE USR 100: CAT "",
9985 DIM k$(8): INPUT "Input 8 chr Title of Vars CODE ";k$: DIM v$(VAL k$( TO 5)-8)
9990 POKE 23297,INT (VAL k$( TO 5)/256): POKE 23296,(VAL k$( TO 5)-PEEK 23297*256): RANDOMIZE USR 100: LOAD k$CODE (PEEK 23627+256*PEEK 23628):
9995 LET n=PEEK 23627+256*PEEK 23628+PEEK 23296+256*PEEK 23297: POKE n,128: LET n=n+1: POKE 23642,INT (n/256): POKE 23641,n-PEEK 23642*256: POKE n-1,128
TS-2068 VARS SAVE and RE-LOAD
A Useful Utility, and one to Learn with.
While designing software I got kinda used to providing a quick Data CLEAR, and re-LOAD of a program variable file. This lets the user zap out data that has already been printed, or is otherwise useless, and start afresh.
When I got involved in converting some softwares to use with LKDOS, the missing vars SAVE-LOAD was not a BIG deal, but was missed. Now I have always taken the position that ANY THING that can be done in Machine Code programming can also be done in BASIC, albeit slower. Most times a routine in BASIC can be installed with less memory usage. Advantages of BASIC also includes the reduction of EPROM chips. So, the VARS Save-Load utility was designed to prove the point. It turned out to be useful enough to add to software as a GO TO Subroutine.
MOVING TARGETS, are System variables VARS and ELINE. Also, while piddling around I discovered that ole Larry Kenny had fiddled with PROG. I’ll get that one out of the way in a hurry. PROG isn’t one ‘o them amphibian reptiles, but is a System Variable that denotes “the memory address where the first Basic Program line starts” in RAM. Apparantly Larry needed 50 bytes of extra space for part of his new VERSION 3 DOS Printer driver. So he just shifted PROG up 50 addresses.
LKDOS users who do not yet have the Version 3 EPROM, are in about the same shape the girl whose strap broke. LKDOS VERSION 3 kinda holds all of the good curves together. The V-3 EPROM is a substantial upgrade and can be purchased for about $15.
Anyway, when the LKDOS printer driver is initialized via RANDOMIZE USR 100: OPEN #3, “LP”, that frog (PROG) jumps up from address 26710 to 26760, not a big hop, but enough to make a programmer pay attention. Now if PROG has your mind jumping, try PRINT PEEK 23635+256* PEEK 23637. Thats where your program begins in Memory. Where does the program END? Ans: “one address below VARS”.
To find VARS, PRINT PEEK 23627+256 * PEEK 23628. Now thats where your VARIABLE file BEGINS. Normally the frog (PROG) sits at adr 26710. So the Version 3 LKDOS printer driver moves it up 50 spaces. That doesn’t hurt anything, but at the same time, VARS also is moved UP 50 addresses. Programs to work in Dock Bank Memory shifts PROG up to adress 32776. When trapsying around in programming we need to know what log the frog (PROG) is sitting upon.
So, now we know where the Basic Program starts in memory, and where the Variable file starts (or how to PEEK and find out).
Where does the variable file END? Ans: one address below ELINE. To find ELINE, PRINT PEEK 23641+256* PEEK 23642. ELINE is the next memory address UP from the END of the VARS file, so if we PEEK ELINE with the above formula, and subtract 1, we get the TOP address of the Variable file. ELINE starts a small area called “The Edit Buffer”. The edit buffer is where a program line is when you pull it down to the bottom with EDIT.
There is one important address in this discussion. This is one address BELOW ELINE. This is the address that the TS-2068 uses to END “lookin at for Variables”. The TS-2068 puts a “80h” there. You can peek it if you like. PEEK 23641+256* PEEK 23642-1 should return 128, which is decimal for 80 hex. We could say that this is the last address of the variable file, but it does not contain a variable. The TS-2068 puts a 128 there as a “marker signal”.
Lets PEEK and find that “80h” or 128 decimal. PEEK 23641+256* PEEK 23642-1. If you dont get 128 your computer is sick.
Try POKE 23641+256* PEEK 23642-1,0. Now that will mess things up. Doing that eliminates the 128 and the TS-2068 forgets where to store the next variable. After doing that any new variable wont take. Like, LET z1=1. Then PRINT z1 will get “varable not found”.
Now POKE the 128 back where it belongs and your computer will work right again (POKE 23641+256* PEEK 23642-1,128).
COPING with Moving Targets, VARS and ELINE-
Everytime a new variable is initialized, ELINE and “80h” moves up. So, in order to SAVE the variable file one must tie it down so that it doesn’t wiggle around during the SAVE. Then upon RE-LOAD, new variables cannot be introduced to allow the “80h” and ELINE to escape.
PROGRAM ANALYSIS:
The underlined lines are LKDOS syntax. To use with Cassette, change these to regular TS-2068 commands for LOAD or SAVE.
Line 9900 begins by initializing all of the variable that will be used in the program. String variables, such as Z$ must contain exactly the number of characters in the initialization as the string will contain later in the program.
RANDOMIZE USR 100: OPEN #4,”dd” initializes LKDOS. Then RANDOMIZE USR 100: OPEN #3,”LP” initializes the LKDOS V-3 Printer Driver. At that command, Systems Variable PROG jumps up from 26710 to 26760, and a programmer’s life is made tolerable by knowing where these goodies are.
Lines 9910 through 9950 assigns the variables to work with. These vars will be SAVED with the existing variable file, and after re-loading a file from disk they can be used to tie up where “80h” and ELINE must be set. It is significant that Assigning these Varibles does not change the SYSTEM VARIABLES “VARS and ELINE”. This is because they were already initialized to the proper lenght at line 9900.
Line 9965 may be deleted. It is screen print given for understanding the essential variables and to show their correlation.
Line 9970 SAVES the variable file from “VARS”, which is (now) at address 26760 with the Version 3 initialized- to the address that contains “80h”. Remember that 80h is at one address BELOW ELINE.
Since none of these addresses are FIXED, the program PEEKS and finds them “wherever they are”.
It is sigficant that although the contents of address of 80h is included in the CODE SAVE, somehow that address content changes, and a RE-LOAD of a CODE variable file must be followed by finding and POKING that elusive address with 128 (80 hex).
Also note in line 9970 that the CODE file is saved with a NAME that is a number. Z$ contains the “byte length” followed by the LKDOS file extension “.C1”. Upon re-LOAD of a vars file this file name will be used in computations by extracting the five digits. We will do that with the VAL and STR$ functions. For example, if the file name were “02340.C1”, then the file would contain 2340 bytes. We can extract the 02340 by “PRINT VAL Z$ ( TO 5). Try this for proof: <LET z$=”02340.C1”: PRINT VAL Z$( TO 5).
So, the variable file is SAVED with a “File Serial Number” which signifies its Byte Length.
Now note that line 9972 has a REM pad of several characters. This is to let you add more variables if you like, and STOPS, in order to make the utility more flexible. If you add vars, be sure to add their initialization (with their proper length) up in line 9900. You can add a STOP to check out the computations. Compensate for STOP: by deleting two x’s in order to keep ELINE from moving. Add two x’s when you remove the STOP:.
RE-LOADING a Vars file
Note that imediately after the SAVE, line 9980 picks up and operates. First, the vars are CLEARED. Then LKDOS and Version 3 Printer driver are initialized.
Then the LKDOS Disk Catalog is presented on screen for a new Vars File Load.
Line 9985 begins a fancy bit of footwork. We know that all vars file “names” will contain 8 characters, the first five of which will be the data length of the file. So, we DIMENSION K$(8). Then an INPUT is put on screen to INPUT the file name.
Next in line 9985, we DIMENSION V$ to be the length of the code file “minus the length of K$. So, the total dimension of both k$ and V$ equals the byte length of the code file as told by the file name.
Later, when the code file is loaded, it will wipe out (write over) K$ and V$, so we need to preserve the five numbers contained in the title. We do this at line 9990. The five digit number in the title, and now in K$, is factored into a 8 bit word. The most significant byte is poked to address 23297 and the lsb is poked into address 23296. These two addresses are in the TS-2040 Print Buffer, and safe from CLEAR.
For better understanding of the POKES, you can check these formulas out in the Direct Mode with PRINT instead of POKE.
Next, with our file length safely tucked away in the print buffer, Line 9990 continues and LOADS the code file starting at VARS. As the code file loads in it completely writes over both K$ and V$.
Line 9995 applies the Coupe de grace, by using PEEK to assign variable N the value of VARS. Then the byte length of the code is PEEKED out of the print buffer and added to N. N now is the address where “80h” belongs, so it is POKED 128.
N is then incremented by one, to become the address where ELINE should be set.
Then the Most significant byte and lsb of ELINE are POKED the two values of “N address”, so that the TS-2068 will know how we stirred it’s porridge. Finally, for good measure, we POKE the 80h address again.
In line 9995 there appears to be a contradiction. We use “variable N”, and that changes things, doesn’t it? Well, it would, except for the fact that “N” is one of the variables previously initialized in the program that SAVED the variables. See line 9910.
The VARS SAVE and LOAD Utility may be MERGED to any Basic Program and used as a Sub-Routine. Add line 9999 RETURN, for a GO SUB routine, or 9999 GO TO line x, for the routine if GO TO is used. The routine allows a menu item to be included within a program to elect CLEARING the PROGRAM and RE-LOAD of a selected vars file to be added back to the program. These can be either a file to re-initialize for a CLEAN program, or to LOAD a DATA File.
———-BJ———
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.