A Practical Study of System Variables: Put Them to Use with BASIC.

Authors

Publication

Pub Details

Date

Pages

See all articles from Update April 1988

Appendix D of the user manual lists the memory addresses of RAM where most of the TS-2068 system variables are stored. The left column “notes” tells whether the variable number is larger or smaller than 255. The significance of this is that system variable numbers larger than 255 require two memory addresses for storage. If the variable is stored in two addresses, the formula PRINT PEEK (low address) + 256 * PEEK (high address) returns the actual system variable number. We started this discussion in the editorial section. Now let us examine some of the system variables.

PEEK K_STATE and LAST_K

These two system vars are used together by the TS-2068 ROM to read the keyboard. Then why are the vars in RAM? Well, the codes stored in ROM cannot be changed, and a keyboard read requires the ability to store changing codes. Then how can we use these two system variables? There are two ways. One is to construct a little machine code loop routine to use the system vars to read the keyboard. The other way is to do it with a BASIC loop. Why do this when the INKEY$ function is already available? The answer is that the INKEY$ function does not employ the debounce and error detection routines in ROM, while K_STATE does.

The following BASIC programming will read the keyboard and assign the key struck to a$:

  150 LET a$="": POKE 23611,220
151 IF PEEK 23611<220 THEN GOTO 151
152 LET c=PEEK 23560
153 IF c<32 THEN GOTO 160
154 LET a$=a$+CHR$ c
155 POKE 23611,220
156 GOTO 151
160 STOP

Explanation: At line 150 we start by initializing a$, then resetting the system var FLAGS. This places the system in a wait state. Next, at line 151 we form a loop to loop as long as FLAG remains in a wait state.

When a key is struck, the error detection and debounce routine in ROM processes the key value and, if no error exists, the code of the key is placed at address 23560. In line 152 we pick up the code number of the key struck and assign it to var c. Then at line 153 we have an escape so that any non-printable key, such as ENTER, will escape the loop to process the results. At line 154 the character key struck is assigned to a$. Line 155 resets FLAGS, and line 156 loops back to another keyboard scan at line 151. Two more variations of this PEEK K_STATE routine for prompts in BASIC are given in the October issue of UP-DATE.

The above programming can be reduced to about three total lines by using chained commands. Another variation, using the Oliger SAFE FOR counter, is:

  151 POKE 23611,220: FOR /65535: IF PEEK 23611<221 THEN NEXT
152 LET c=PEEK 23560: POKE 23611,220: IF c<32 THEN GOTO 160
153 LET a$=a$+CHR$ c: NEXT
160 STOP

REPDEL and REPPER

Want to perk up your keyboard and make it frisky? Page 262 of the user manual gives these two “single byte” system vars. Play around with POKEs to the two addresses to get variations of the speed of repeat keys, and the delay between repeat key actions.

How about making the keys chirp? Do that by POKEing sys var PIP (23609) — try about 10. Then the sys var DF_SZ lets you enlarge the prompt area at the bottom of the screen. For kicks, put on a whole screen and then BREAK and POKE 23659,15. Now the prompt area is 15 lines, which leaves only 9 lines at top!

Other System Variables

We will skip some of the more obvious system vars and deal with some more useful two-byte vars. For these it will help to refer to page 254 of the user manual to visualize the TS-2068 memory map. On page 254, note that PROG is a line drawn without a specific address. This is because the BASIC program, which normally begins at address 23710, may be intentionally changed. The system var PROG is contained in two addresses, 23635 and 23636. Try PRINT PEEK 23635 + 256 * PEEK 23636 — you should get 23710.

We will now find a nook in memory to stash a tiny MC utility to shift the BASIC program up in RAM. The MC utility can go anywhere in RAM, but let’s put it in a most unlikely place. Look on page 255 of the user manual. At the top of the page is a group of blocks — all of these are important places where “functions” are stored. But one can be used for multi-purpose functions. The “printer buffer” is used only for holding data for printing something to paper with the TS-2040 printer, and is an ideal place to stash machine code when the TS-2040 printer is not in use.

So we will do some slick shenanigans. A BASIC utility will be constructed that contains a tiny machine code routine. The utility will put its own MC routine into the printer buffer area and then execute it. The result will be a “selective starting address” of any BASIC program to which the utility is appended. In simplest terms, the utility will move a BASIC program up in memory and also move PROG so that the CPU will know where to go to operate the BASIC program.

Products

 

Downloadable Media

 

Image Gallery

Source Code

People

No people associated with this content.

Scroll to Top