The purpose of this article is to illustrate the power of the CHR$ function. The argument for the CHR$ function is a numeric value code from 0 to 255. This is the entire character set of single letter characters, keywords, and tokens. Refer at this point to the character set listing in the appendix of your programming manual. You will see that character codes 67-111, 122-125, and 195 are not used in the ZX81 system. You can verify this by running the program in Figure 1. The unused codes are shown as question marks.
Figure 1.
10 FOR N=0 TO 255
20 PRINT CHR$ N;
30 NEXT N
Now change line 10 to 10 FOR N= 128 to 191 and hit RUN then ENTER. The characters displayed cannot be entered from the keyboard itself. The interesting thing about this concept is that graphic strings are printed very rapidly and this may be applied to any work dealing with high speed graphics.
The CHR$ function can also be used to compare other nonprintable functions such as the cursor operation symbols like “↑”; “↓”; “←”; “→”; which cannot be placed onto the screen. This is accomplished by applying a string equivalent, which can be called by using their respective CHR$ codes (112-115). We can examine an example of that code by using the CHR$ (114) for the backspace cursor in Figure 2. Type in Figure 2 at this point.
Figure 2.
10 LET A$=INKEY$
20 IF A$="" THEN GOTO 10
30 IF A$<>CHR$ 114 THEN GOTO 70
40 SCROLL
50 PRINT "LEFT CURSOR ON"
60 GOTO 10
70 SCROLL
80 PRINT A$
90 GOTO 10
In the SLOW mode hit RUN then ENTER. What happens when you depress SHIFT then hit 5? Try the other SHIFTed cursor positions. Experiment with ENTER and other keyboard letters, numbers, and tokens. Hit BREAK to STOP the program when you are finished.
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.