Many “Kaleidoscope” programs have appeared over the years. These simple, but fascinating graphics displays have been adapted to virtually every computer ever built. The ZX81/TS family is no exception. Unfortunately, since the Z80 CPU in these machines is (effectively) clocked at only .5 mHZ in SLOW mode, the result is rather slow and BO-RING. Type in the program Listing #1 (BASIC prototype), and you’ll see what I mean.
Now, let’s take essentially the same program and write it in Z80 machine code. For a graphic demonstration (pun intended) of the speed and compactness of code …start by entering a 1 REM line, followed by 172 X’s or other character. (HINT: use FAST mode.) Now enter the rest of Listing #2 (machine code loader). RUN the program, and input the values given in Table #1 (decimal machine code). Go from left to right, top to bottom. Take your time, and proof each number before you enter it.
When you’re done, your 1 REM line will look like sheer nonsense. Don’t worry about that; just check it against the 1 REM in listing #3 to make sure it’s the same. Enter lines 2-6 of Listing #3, overwriting the loader. Delete lines 7 and 8. SAVE to tape with RUN 5. The program will auto-run when the save is finished. WOW! Press BREAK when you’re adequately hypnotized.
Line 2 contains the fill characters used for the display. Change this however you see fit; there is no limit on length. HINT: use symmetrical characters, like O, *, =, +, the grey squares, spaces, and their inverses.
This will run on 2k machines if you modify the BASIC portion as shown in listing #4 (2k changes). This is because this program relies on a fully padded-out display file.
If you’re interested in studying the machine code, use a disassembler or HOT Z to take a look at the code. As mentioned, it pretty much follows the structure of the BASIC prototype, so you should have little trouble finding your way around. the code from 408Fh to 49B4h gets pseudo-random numbers in B and C. Next are two ways of implementing a modulo function. At 40B5, C is reduced mod 16 (exact power of 2), and at 40BD B is reduced mod 12 (not a power of two). The CALLs to 40F6, 40FB, 4100, 4105 and 410A correspond with the BASIC GOSUBs to 250, 300, 350, 400 and 1000, respectively. The routine at 410A is a “print at BC” routine which is MUCH faster than the comparable ROM call to 08F5 followed by RST 10h. It prints the character pointed to by CH_ADD at row B, column C. NOTE: it does NOT check for over-range.
The next time some smart-aleck ribs you about your “slow” ZX/TS, boot this program and watch his jaw sag. Isn’t this fun?
LISTING 1: BASIC Prototype
10 LET F$="▒ ▒▒"
20 POKE 16418,0
30 LET POINT=0
40 LET POINT=POINT+1
50 IF POINT>LEN F$ THEN GOTO 3
0
60 LET A$=F$(POINT)
70 LET B=INT (RND*12)
80 LET C=INT (RND*16)
90 GOSUB 250
100 GOSUB 350
110 GOSUB 1000
120 GOSUB 250
130 GOSUB 400
140 GOSUB 1000
150 GOSUB 300
160 GOSUB 350
170 GOSUB 1000
180 GOSUB 300
190 GOSUB 400
200 GOSUB 1000
210 GOTO 40
250 LET X=16+C
260 RETURN
300 LET X=16-C
310 RETURN
350 LET Y=12+B
360 RETURN
400 LET Y=12-B
410 RETURN
1000 PRINT AT Y,X;A$
1010 RETURN
LISTING 2: Machine-code Loader
1 REM XXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXX
2 FAST
3 FOR A=16514 TO 16685
4 SCROLL
5 INPUT B
6 POKE A,B
7 PRINT A,PEEK A
8 NEXT A
TABLE 1: Machine-code Decimal Data
17: 51: 65: 19: 26:254:118: 40: 247:237: 83: 22: 64: 17: 75: 0: 237: 75: 50: 64: 3: 98:104:205: 9: 19:229: 98:105:205: 9: 19: 193:124:129: 48: 1: 4:103:125: 144: 48: 1: 37:111: 43: 34: 50: 64: 69: 76:203: 57:203: 57:203: 57:203: 57: 6: 12:184: 56: 3: 144: 24:250: 71:197:205:246: 64: 205: 0: 65:205: 10: 65:193:197: 205:246: 64:205: 5: 65:205: 10: 65:193:197:205:251: 64:205: 0: 65:205: 10: 65:193:205:251: 64: 205: 5: 65:205: 10: 65:205: 70: 15: 56:144:201: 62: 16:129: 79: 201: 62: 16:145: 24:249: 62: 12: 128: 71:201: 62: 12:144: 24:249: 42: 12: 64: 35:197: 14: 0:203: 56:203: 25:203: 56:203: 25:203: 56:203: 25: 9:193:120:129: 6: 0: 79: 9:237: 91: 22: 64: 26: 203:183:119:201:
LISTING 3: M/C KALEIDOSCOPE

LISTING 4: 2K Changes
3 SLOW
4 POKE 16418,0
5 FOR A=0 TO 23
6 PRINT AT A,31;" "
7 NEXT A
8 POKE 16418,2
9 RAND USR 16514
10 SAVE "KSCOPE2K"
11 RUN
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.