This utility program enables you to edit and execute hex Z80 machine code. It derives from a much simpler one in 30 Programs for the ZX80, published by Melbourne House Ltd. It can help you learn to program the Z80 in its native language.
If you’re new to machine language, try this program with the Syntactic Sum assembly listing (p.8 Feb. 81). The actual listing is the single column after 43E0 (the first column lists hex addresses, the third, fourth & fifth show human-readable mnemonics for the instructions, & the sixth explains what the instructions do). Input the hex numbers in the listing, 2 digits at a time. Thus, respond to the number of locations you need with the number of 2-digit hex numbers to enter (31 in this case). Then type in the hex numbers, 2 digits at a time, hitting (NL) after each pair. Type 21 in response to the first data request, 28 to the second, 40 to the third, ED to the fourth, and so on. After you enter EC, the last number in the listing, the computer still expects a number, so hit (NL) to enter 00. (This is because line 120 of the BASIC monitor program sets up a FOR-NEXT loop from 0 to L, L being the number of locations you needed. The number of locations from 0 to L equals L+1, so the computer expects L+1 entries.)
When the BASIC program gets to line 270, it executes a machine language call, which means it runs the machine language program you typed in. Because it is the Syntatic Sum program, the answer you get should be the Syntactic Sum of the hex monitor program.
Always respond to line 60 in decimal; use hex for all other input. The result of the USR subroutine call is decimal.
You can reserve between 9 and 100 locations. If you need fewer than 9, just hit (NL) to enter 00 (for NOP, or no op code) to fill the remaining addresses. After writing to all locations, the computer asks you for any changes. Type Y to change the data. The program re-accesses each location and you can enter new data or hit (NL) to keep the original data. Any answer other than Y executes the machine code, prints the result and asks STOP? Respond Y to stop; default re-accesses the machine code.
Besides returning control to the BASIC interpretor from the machine code, C9H (meaning C9 in hex) causes “STORAGE LOCATIONS” to be printed as a convenience header. But these locations may be used for code or storage.
Line 200 avoids crashing the program when machine code listings fill the screen (see p.123 of the ZX80 operating manual).
This program starts listings at address 16963 and provides up to 100 bytes of storage. Bytes deleted from the monitor listing (characters and tokens, not variables, numbers or dimensioned arrays) free up the same number of bytes for hex code. Note the resulting shift in the starting address of the listing. Reduce the starting address by the number of bytes you delete (2 for each line number, 1 for each keystroke & 1 for end of line).
10 REM BE SURE TO LEAVE RESULT
20 REM IN THE HL REGISTER AND
30 REM INCLUDE A RETURN.
40 PRINT "HOW MANY LOCATIONS NEEDED?"
50 PRINT "(FIGURE ONE BYTE/LOC.)"
60 PRINT ":::9<NUMBER<100:::"
70 INPUT L
80 DIM A(L)
90 LET S=PEEK(16392)+256*PEEK(16393)+9
100 CLS
110 PRINT "LOCATION","CONTENTS"
120 FOR I=0 TO L
130 PRINT S+I,,
140 INPUT A$
150 IF A$="" THEN GO TO 180
160 LET V=16*CODE(A$)+CODE(TL$(A$))-476
170 POKE S+I,V
180 LET V=PEEK(S+I)
190 PRINT CHR$(V/16+28);CHR$((V AND 15)+28)
200 IF PEEK(16421)=9 THEN CLS
210 IF V=201 THEN PRINT "STORAGE LOCATIONS:"
220 NEXT I
230 PRINT
240 PRINT "ANY CHANGES?"
250 INPUT A$
260 IF A$="Y" THEN GO TO 100
270 PRINT "RESULT OF USR IS: ";USR(S)
280 PRINT "STOP?"
290 INPUT A$
300 IF A$="Y" THEN STOP
310 GO TO 100
SYNTACTIC SUM= -23248
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.