Introduction
The standard ZX80 is supplied with a 4K ROM and 1K of memory. There are 22 commands that can be used in the Basic provided in the 4K ROM. However, there is no command that will cause the display to be shown for a specified length of time before a change is made to show the next display. The advertisements for the 8K ROM mention a command called PAUSE which is expected to perform this function.
The following program constructs the machine code routine for such a PAUSE command. The actual program occupies about 1/4K, leaving the programmer a little under 3/4K in which he can store his different displays.
The actual displays are constructed using Basic PRINT commands in the version given here, but there is no reason why machine code constructed displays should not be used if greater speed or complexity is required. (See SYNC, vol. 1, no. 1)
A certain amount of ‘flicker’ is produced between displays because the routine ‘returns to Basic’ after the specified time period. This ‘flicker’ can be eliminated only by remaining in machine code and synchronizing the program perfectly.
The Theory
The Screen and Keyboard routine, decimal address 316-437, Hex. address 013C-01B5, in the 4K monitor program can be considered the dominant routine in the operation of the ZX80.
It is this routine that both reads the Keyboard and produces the display on the TV screen. It therefore follows that this routine cannot be called unless a complete display file has already been constructed.
The routine can be divided into three parts:
Part 1. Update the frame counter.
Part 2. Test the Keyboard for new input.
Part 3. Produce the display of the current display file.
If there is no key being pressed, then the whole routine is executed over and over again. However, if a key is being pressed, then an exit is made from the routine to handle the ‘interruption.’ This may lead to the cursor being moved, characters being added to the current E-line, or the RUNning of a Basic program. As long as the programmer has not created a ‘never ending loop,’ the Screen and Keyboard routine will eventually be re-entered and a display will again appear on the TV screen.
The flow diagram below illustrates the normal operation of the ZX80.
[Figure: Flow diagram of the normal ZX80 Screen & Keyboard routine — initialise, complete a display file, update frame counter, read keyboard, is a key being pressed?, produce display, act on key]
The AUTO-DISPLAY-CHANGING program copies most of the Screen and Keyboard routine from the 4K monitor program into the memory and adds a timing loop so that the display can be held for up to 256 frames, about 5 seconds. The programmer is then able to use this ‘new’ routine to produce a display on the TV screen.
It is important to emphasize again that a complete display file of 24 lines must be constructed before the routine is called. In the following program the display file is completed by calling the subroutine at line 16. However, this can also be done in machine code if required.
The following flow diagram shows how the ZX80 operates with the ‘new’ routine:
[Figure: Flow diagram of the ‘new’ Screen & Keyboard routine — run Basic program, initialize timer, construct display in Basic, complete display file, decrease timer, is timer at zero?, is a key being pressed?, produce display, another display?]
The Program
The program, although fairly simple, is quite difficult to enter. Therefore do it slowly and carefully. SAVE the partly entered program often.
Step 1
Enter the following lines and then SAVE:
2 REM 12345678901234567890123456789
01234567890123456789012345678901234
56789012345678901234567890123456789
01234567890123456789012345678901234 } Reserve 134 locations.
} Do not use all spaces!
4 GO TO 28
6 LET A=USR(16428) } A will return the Keyboard codes.
8 CLS
From now on NEVER use LIST or HOME.
Step 2
Make the following check:
Enter as a direct command: PRINT PEEK(64*256+199) & NEWLINE and the value 118 should appear. (This is the ‘end of line marker’ for line 6 and the correct address must be known.)
Step 3
Enter the following lines and then SAVE.
10 LET A=16428
12 POKE A,205 }
14 POKE A+1,59 } Call the routine at line 42
16 POKE A+2,64 }
18 POKE A+3,33 }
20 POKE A+4,199 } The address of the end of line 6
22 POKE A+5,64 }
24 POKE A+6,34 } The return address needs to be stored in
26 POKE A+7,38 } System Variable 16422 and 16423
28 POKE A+8,64 }
30 POKE A+9,96 } Return Keyboard codes in HL register
32 POKE A+10,105 } pair.
34 POKE A+11,201
36 POKE A+12,205 }
38 POKE A+13,173 } Call screen production subroutine.
40 POKE A+14,1 }
42 POKE A+15,58 }
44 POKE A+16,43 } Fetch timer from 16427.
46 POKE A+17,64 }
48 POKE A+18,61 } Decrement timer.
50 POKE A+19,200 } Exit if timer is zero.
52 POKE A+20,50 }
54 POKE A+21,43 } Restore timer.
56 POKE A+22,64 }
58 FOR I=319 TO 427 } Copy most of Screen and Keyboard rou-
60 POKE 16132+I,PEEK(I) } tine from monitor to the memory.
62 NEXT I }
64 POKE A+24,4 } Adjust timing slightly.
66 POKE A+132,135 } Change a JR value.
68 LET T=0 }
70 FOR I=A TO A+132 }
72 PRINT PEEK(I); }
74 LET T=T+PEEK(I) } Form a CHECKSUM
76 NEXT I }
78 PRINT }
80 PRINT "CHECKSUM = ";T }
SAVE.
Now enter RUN 10 & NEWLINE. The screen will now display the machine code that has been entered into line 2 and held off the screen.
The correct CHECKSUM is 14421; correct any errors before proceeding.
Step 4
Delete all the lines from 10 to 80 (inclusive) by entering the line number and NEWLINE over and over again.
SAVE the program. It should consist of lines 4-8 on the screen and line 2, off the screen.
Step 5
Enter the rest of the Basic program:
10 POKE 16427,255 } Initialize timer to 5 seconds.
12 POKE 16421,24 } Create a 24th line so as to give a
14 RETURN 'full display.'
16 LET A=PEEK(16421)-1 } This routine will complete the display
18 IF A=0 THEN RETURN } file. It adds the appropriate number of
20 FOR A=1 TO A } PRINT's to fill the 24 lines.
22 PRINT }
24 NEXT A }
26 RETURN }
28 GO SUB 8 } Initialize timer for 1st display.
30 REM AUTO-DISPLAY-CHANGING } Optional REM line.
The program is now complete, so SAVE this version carefully. Remember, never use LIST or HOME.
Using the program
It is not really the author’s intention in this article to describe at any great length just how the program can be used. The following examples are given so that the reader can start to see for himself how different problems are tackled.
Simple display changing
Enter the lines;
100 PRINT "DISPLAY ONE" } A very simple 1 line display.
196 GO SUB 16 } Complete display file.
198 GO SUB 6 } Produce the display.
200 PRINT "DISPLAY TWO" } Another simple display.
296 GO SUB 16 } Complete the 2nd display.
298 GO SUB 6 } Produce the display.
300 GO TO 100 } LOOP BACK
996 CLS
998 STOP
RUN
As long as the program is entered correctly, the first display should appear on the screen for five seconds. Then the screen will ‘flicker’ and the second display will appear. Because of the LOOP BACK the displays will alternate forever!
Note that all the keys are active. Pressing any key, except BREAK, will cause a switch to the next display. The BREAK key is still active as it is tested at the end of each Basic line. This key can therefore be used to ‘exit’ from the LOOP.
The largest possible display
The following lines show that there are about 550 locations still available for the displays in the standard 1K ZX80.
100 FOR I=1 TO 550
102 PRINT "*"; Display is to have 550 '*'s.
104 NEXT I
106 PRINT Always go to the next line.
196 GO SUB 16 Complete display.
198 GO SUB 6 Produce display.
200 GO TO 198 LOOP BACK.
996 CLS
998 STOP
In the above program the LOOP BACK is used in a different way. By repeating line 198 over and over again, the current display file is used again without any changes.
Find the number
The following game shows how the A variable returns the keyboard code.
In the program a random number in the range 1-5 is the first generated. Then the keys that are pressed by the player are tested for the correct key value.
Each time a key is pressed the score is incremented. At the end of each 5 second period without a key stroke the score is also incremented.
100 REM FIND THE NUMBER
102 LET N=RND(5)
104 LET N=521*(N=1) OR 1033*(N=
2) OR 2057*(N=3) OR 4105*(N=4) O
R 8201*(N=5)
106 LET T=1
108 GO TO 204
200 PRINT "SORRY, TRY AGAIN"
202 LET T=T+1
204 PRINT
206 PRINT "I KNOW THE KEY. DO
YOU? (1-5)"
296 GO SUB 16
298 GO SUB 6
300 IF NOT A=N THEN GO TO 200
302 PRINT "WELL DONE"
304 PRINT "YOU TOOK ";T;" GO";
306 IF NOT T=1 THEN PRINT "ES"
308 PRINT
310 PRINT "PRESS NEWLINE TO RES
TART"
312 INPUT A$
314 IF NOT A$="" THEN STOP
316 CLS
318 RUN
The Key values
The Screen and Keyboard routine scans the keyboard and returns in the BC register pair a KEY VALUE that is different for every stroke. As there are 78 keystrokes, there are 78 different key values.
In the ‘Build up an E-line’ routine these key values are changed to the range 1 to 78; then the look up table is used to find the correct ZX80 character codes.
However, in order to make the AUTO-DISPLAY-CHANGING program as short as possible, the conversion of key values to character codes has not been included.
The following program can be used to show the KEY VALUES:
100 REM KEY VALUES
102 LET A=0
104 PRINT A
196 GO SUB 16
198 GO SUB 6
200 GO TO 104
Conclusion
Many other kinds of programs can be written using the AUTO-DISPLAY-CHANGING routine. The author has a very nice digital clock, but the ‘flicker’ is a little annoying. Much of the background work for this article is discussed in the author’s The ZX80 Companion which contains a more elementary version of this particular program.