John Judge adds 14 Basic commands to the ZX-81.
From “Your Computer” 1984
THIS SET OF machine-code routines provides the 16K ZX-81 with 14 new Basic statements and commands usually found only on much larger and more expensive machines. The routines take up 1336 bytes in a Rem statement and are designed for ease of use with full error codes. Two of the routines are interrupt driven and allow you to add your own interrupt driven routines.
To enter the program, a 16K ZX-81 with the New run has to be used, it may be possible to use less memory, but some of the routines will crash if the display file is collapsed, ie., RAM is less than 3¼K.
First, line 1 Rem followed by 128 zeros – four lines – is entered. This is then duplicated as line 2 and so on up to line 10. When this has been done, the following are entered as direct commands.
POKE 16511,56
POKE 16512,5
POKE 16509,0
POKE 16510,0
POKE 16514,118
POKE 16515,118
1 REM BETTA BASIC
POKE 16419,1
NEW LINE
You should now have
1 REM BETTA BASIC
on the screen. Anything else means that you have probably done something wrong and it is best to start again.
If all is well then enter the hex-loader program 1, ignoring line 0 as this should already be in memory. Type Run N/L then enter the start address for the machine code data, which will be 16514 if you are just starting or another number if you are continuing from another day or after saving partly completed data. You can now enter the hexadecimal data, as many of the numbers as you like before pressing Newline, but remembering not to enter any of the spaces. There is a check-sum number after each line of data which you can compare with the check-sum number on the screen, if it is different then press S N/L and you can enter the line that is wrong. By pressing Q N/L, you can break out of the program to save it.
Looking through data
Program 2 is for looking through the data for any that is wrong. To use it, type Run 200 then enter the start address. Type Cont after each screenfull.
If all the data is entered and correct, then delete lines 5 onwards and enter program 3. Do not use New to delete the lines. The program is now finished and ready to use, unless some bugs have escaped detection.
You must have Betta Basic present in the computer before you start typing in your program. In this way the machine code routines are saved as you save your program that uses them. Now, whenever you type Run, the variables are initialised ready for use.
INT: Switches on the interrupt routine by Rand USR Int to give the following features:
TRACE ON by POKE TRN, 1 or pressing N/L and 1 together;
MEMORY ON by POKE TRN, 2 or pressing N/L and 5;
MEM/TRACE OFF by POKE TRN, 0 or pressing N/L and 2;
ROUTINE OFF by pressing N/L and 3 or Fast then Slow;
Break out of any program – even machine code – by pressing N/L and 4. This also switches routine off;
TRACE SPEED by POKE LEN, n where n is the length of the pause at each interrupt. Initially 3;
USER ROUTINE: Three bytes – USE, USE + 1 and USE + 2 – are set aside to add to call to your own interrupt driven routine. Initially all are NOPS. Make sure the routine is Off by using Fast followed by Slow before you start Poking or a crash will occur as soon as you Poke in the first number.
When using the trace or memory left features, the number will take up the first five characters in the top left corner of the screen. These numbers are only printed up during the interrupt and the original text or graphics are put back into the screen before control is handed back to the ROM. So as far as the ROM is concerned, the numbers do not even exist on the screen and so will not be “in the way”. But it is important not to use the Sinclair scroll command as this will cause a crash after 23 scrolls.
Pressing N/L and 4 will break out of any machine code programs as long as the routine is switched on by Rand USR Int.
The Trace and Memory Left routines will automatically switch off when program execution ends or any error occurs, though they can operate in command mode by using N/L and the function keys 1 to 5.
The interrupt routine will be switched off by any of the following: Fast, Copy, LPrint, LList, Save, Load, Pause, New or by entering a line. If any of these are used then do not forget to switch on again by using Rand USR Int before using Trace or Memory Left.
LOC: This moves VARS up to Eline so that all the variables temporarily disappear and “load variables” can be used instead, ie., variable names can be used for a second time without altering any or the original variables of values eg.,
VAR: Restores original variables after using LOC. Do not use unless LOC has been used first. For example:
RAND USR VAR.
SCL: Stands for Scroll. Do not use the scroll provided by Sinclair as it will cause some of the routines to crash. For example:
RAND USR SCL.
In the following, X and Y can be any numberical argument in the range 0 to 65535, V any numerical variable, I any numerical dummy variable that is not used for anything else, anything surrounded by [] is optional, all Print statements will be changed to Rem by the routine, and should be changed back to Print if ever the line is edited. The Print lines after the USR lines hold the arguments for each routine.
Function has three uses
PRT: This has three uses, two of which are concerned with the ports.
a) OUT (port), byte. For example:
10 LET I = USR PRT
20 PRINT X, Y [; X, Y . . . . ]
b) IN variable, (port) or LET variable = IN (port). For example:
10 LET I = USR PRT
20 PRINT; X where X = port 0 to 255
c) LD I, X. For example:
10 LET I = USR PRT
20 PRINT; X where X = char set 0 to 255
This one changes the character set and can be used for games or with a graphics ROM – initially 30.
REP: Same as BBC Basic Repeat. The line numbers are stored in R$. Up to 15 Repeats can be nested – inside each other – before an error occurs. For example:
10 LET I = USR REP
UNT: BBC Basic Until. Jumps back to line after last Rep. If a testable condition is not true. For example.
10 LET I = USR UNT
20 PRINT testable condition
ONG: Same as On . . . Go To . . . Jumps to the Xth line number in a list of numbers. If X = 0 or X > number of numbers in list then the line after the ONG is executed. For example:
10 LET I = USR ONG
20 PRINT X ; line [, line . . . ]
Up to 255 lines can be put on the list.
PRC: Def Proc. This is a simulation of procedures, using names instead of line numbers. Each ‘procedure’ has the following structure:
10 REM PROCNAME
20 Subroutine or procedure
30 RETURN
where Name will be the name of the procedure. PRC is called only once at the beginning of the program. For example:
10 LET I = USR PRC
The routine then searches for all the “Rem Procname”s and puts the names into the variables area with their line numbers so that a procedure can be called by:
GOSUB NAME
The name must be three or more characters long and contain only characters legal as a variable name, see page 38 of the Sinclair manual. There is no space between the Proc and the Name.
DYN: Dynamic procedure. This routine tells you whether a name held a string variable is a procedure or not so that it may be used with VAL without an error occuring. If it does not exist. eg.,
10 INPUT A$
20 IF USR DYN THEN GOTO VAL A$
30 REM A$
40 GOTO 10
The above example Gotos a procedure entered in line 10 if it exists, otherwise it waits for you to enter another. The A$ in lines 10, 20 and 30 can be changed to any other string variable.
LST This is a fast scrolling list with a few extra features. To use:
Rand line to list from Rand USR LST
In this routine you can press:
Space to break out of the routine;
Z to copy the screen to the printer;
K to “normal list” the last line on the screen in order to edit;
D to list through slowly;
N/L to list through fast.
USEFUL ROM ROUTINES USED:
08F5h PRINT AT B,C;
0808h PRINT CHR$(A); Chars 0-63 and
their inverses
0948h PRINT CHR$(A); Chars 64-127 and
192-255
0A98h PRINT BC;
0A2Ah CLS
063Eh LIST Same a pressing
Newline
0869h COPY
1620h STK BC Puts BC on calc
stack as "floating
point" number
[illegible]7h UNSTK BC Takes BC off calc.
stack
[illegible]Ch LOOKVARS Finds variable
pointed to by CH-
ADD and puts its
address into HL
If you wish to disassemble the routines, then here are the addresses you will need in Hexadecimal:
40A5 INT
40BC LOC
40CD VAR
40DC SCL
40EE System variables
4108 Interrupt Routine Entry Point
420E Routine to check next line is a
print line and change it to a Rem if
necessary.
4227 PRT 436Z DYN
4270 REP 43EE PRC
42BA UNT 44A6 LST
430D ONG 4585 last address
If the task of typing in this program is a bit daunting, then send £3.00 to the following address and I will send you a copy of the finished program on tape: J D Judge, 147 Hesters Way Road, Cheltenham, Gloucestershire, GL51 0SD.
Program 1.
1 REM 000000 ETC....
5 SCROLL
6 SCROLL
10 PRINT AT 18,0;"START ADDRESS?"
15 LET A$=""
20 INPUT S
30 FOR X=S TO 17795 STEP 7
40 SCROLL
50 PRINT AT 19,0;X;
55 LET C=0
60 FOR T=X TO X+6
70 IF A$="" THEN INPUT A$
80 IF A$="S" THEN RUN
84 IF A$="Q" THEN STOP
86 IF LEN A$/2<>INT (LEN A$/2) THEN LET A$=""
88 IF A$="" THEN GOTO 70
90 LET N=16*CODE A$+CODE A$(2)-476
100 POKE T,N
110 LET C=C+N
120 PRINT " ";A$( TO 2);
125 LET A$=A$(3 TO )
130 NEXT T
140 PRINT ", ";C
150 NEXT X
Program 2.
190 STOP
200 PRINT "START ADDRESS ?"
210 INPUT I
220 FOR X=I TO 17795 STEP 7
230 PRINT X;
240 LET C=0
250 FOR T=X TO X+6
260 LET N=PEEK T
270 LET C=C+N
280 PRINT " ";CHR$ (INT (N/16)+28);CHR$ (N-16*INT (N/16)+28);
290 NEXT T
300 PRINT ", ";C
310 NEXT X
Hex dump and checksums
0\::REM
3\::REM [illegible]
(C) J.JUDGE 1983
10 LET R$=" "
11 LET INT=16516
12 LET LOC=16519
13 LET VAR=16522
14 LET SCL=16525
15 LET PRT=16528
17 LET REP=16531
18 LET UNT=16534
19 LET ONG=16537
20 LET DYN=16540
21 LET PRC=16543
22 LET LST=16546
23 LET LEN=16632
24 LET TRN=16633
25 LET USE=16678

16514 76 76 C3 A5 40 C3 EC. [illegible]
16521 40 C3 CD 40 C3 DC 40. [illegible]
16528 C3 2[illegible] 42 C3 7D 42 C3. [illegible]
16535 BA 42 C3 0D 43 C3 52. [illegible]
16542 43 C3 EE 43 C3 AB 44. [illegible]
16549 21 3[illegible] 40 CB F6 CD 07. [illegible]
16556 02 3E 00 32 F6 40 21. [illegible]
16563 F9 40 36 00 DD 21 08. [illegible]
16570 41 C3 2A 10 40 22 01. [illegible]
16577 41 2A 14 40 22 03 41. [illegible]
16584 2B 22 10 40 C3 2A 01. [illegible]
16591 41 22 10 40 2A 03 41. [illegible]
16598 22 14 40 E5 36 80 2A. [illegible]
16605 0C 40 E5 11 21 00 19. [illegible]
16612 D1 01 D6 02 ED B0 01. 840
16619 00 00 C9 FE FF 00 00. 710
16626 00 00 00 00 01 01 02. 4
16633 02 00 47 00 00 00 00. 73
16640 00 00 00 00 00 37 0D. [illegible]
16647 76 EC 5F 01 01 [illegible] 3E. [illegible]
16654 F5 [illegible] 55 0[illegible] CD [illegible] 02. [illegible]
16661 C[illegible] 2[illegible] 0[illegible] [illegible]D 21 0[illegible] 41. [illegible]
16668 3A F[illegible] 40 FE 00 [illegible] 0D. [illegible]
16675 [illegible]3 A4 0[illegible] 00 00 00 21. [illegible]
16682 F[illegible] 40 36 00 18 F3 21. [illegible]
[illegible: remaining rows of column 1 (about 36 rows, to the foot of the column) smeared on the scan]
16941 42 DF FE 19 28 47 CD. 884
16948 55 0F CD A7 0E C5 DF. 906
16955 FE 1A 28 02 CF 1C E7. 788
16962 CD 55 0F CD A7 0E 79. 812
16969 C1 ED 79 DF FE 19 28. 1093
16976 05 E1 22 16 40 C9 E7. 782
16983 18 DA DF FE 19 28 10. 800
16990 CD 55 0F CD A7 0E ED. 928
16997 78 06 00 4F E1 22 16. 486
17004 40 C9 E7 CD 55 0F CD. 1006
17011 A7 0E 79 ED 47 18 EF. 873
17018 E7 18 DC 2A 16 40 E5. 832
17025 21 05 41 22 16 40 CD. 428
17032 1C 11 E3 22 16 40 E1. 617
17039 7E FE 57 28 02 CF 1E. 746
17046 23 5E 23 56 23 7B FE. 662
17053 22 38 F4 5E 16 00 7B. 573
17060 FE 1F 38 02 CF 1A 3C. 636
17067 3C 77 19 23 E5 2A 29. 551
17074 40 54 5D E1 73 23 72. 730
17081 C9 2A 16 40 E5 CD 0E. 777
17088 42 CD 55 0F CD A7 0E. 757
17095 78 B1 20 02 18 02 3E. 419
17102 01 F5 21 05 41 22 16. 405
17109 40 CD 1C 11 F1 E3 22. 816
17116 16 40 E1 F5 7E FE 57. 1023
17123 20 AF 23 5E 16 00 23. 393
17130 23 7B FE 22 38 A4 5E. 760
17137 7B FE 00 20 02 CF 1D. 647
17144 F1 FE 01 28 09 1B 56. 658
17151 2B 5E EB 22 29 40 C9. 712
17158 7E 3D 3D 38 EB 77 C9. 859
17165 2A 16 40 E5 CD 0E 42. 642
17172 CD 55 0F CD A7 0E 78. 811
17179 FE 00 20 2E 79 FE 00. 707
17186 28 29 32 F5 40 DF FE. 917
17193 19 28 02 CF 19 3E 00. 361
17200 32 F4 40 E7 CD 55 0F. 894
17207 CD A7 0E 3A F4 40 3C. 812
17214 32 F4 40 57 3A F5 40. 8[illegible]2
17221 BC 23 10 DF FE 1A 28. 7[illegible]
17228 E6 E1 22 16 40 06 00. 581
17235 3A F5 40 4F C9 80 69. 84[illegible]
17242 CD D8 09 22 29 40 18. 5[illegible]
17249 EB 2A 16 40 E5 2A 29. [illegible]
17256 40 [illegible] 23 23 [illegible] 7E FE. [illegible]
[illegible: remaining rows of column 2 (about 15 rows, to the foot of the column) smeared on the scan]
17368 1C 11 CB 7E 28 D6 CB. 831
17375 76 20 D2 CB 6E 28 CE. 919
17382 01 01 00 E1 22 16 40. 347
17389 C9 21 7D 40 18 0C 2A. 501
17396 76 40 ED 4B F0 40 09. 807
17403 23 23 23 23 22 76 40. 356
17410 7E FE 28 D0 47 23 4E. 812
17417 ED 43 07 40 23 4E 23. 523
17424 46 23 ED 43 F0 40 7E. 839
17431 FE EA 20 D8 23 7E FE. 1151
17438 35 20 D2 23 23 23 7E. 526
17445 FE 28 20 CA 23 7E FE. 943
17452 76 CA 8A 43 CB FE CB. 1185
17459 B6 CB EE 22 F2 40 3E. 1025
17466 76 23 BE 28 06 CB BE. 782
17473 CB B6 18 F6 2B CB FE. 1155
17480 CB B6 ED 5B F2 40 AF. 1194
17487 ED 52 CA 8A 43 2B 7C. 893
17494 B5 CA 8A 43 23 E5 ED. 1089
17501 5B 14 40 1B D5 23 23. 485
17508 2[illegible] 23 23 23 44 40 EE. [illegible]20
17515 09 E5 23 23 23 AF ED. 7[illegible]
17522 [illegible]2 3[illegible] 02 CF 03 E1 38. 6[illegible]
17529 80 23 22 14 40 23 36. 370
17536 FE 22 1A 40 22 1C 40. 504
17543 D1 C1 03 2A F2 40 ED. 990
17550 B0 ED 4B 07 40 C5 CD. 9[illegible]1
17557 20 15 EF C0 34 D1 01. 7[illegible]
17564 05 00 21 ED 40 ED B0. [illegible]
17571 C3 F3 43 01 00 14 CD. 7[illegible]1
17578 F8 05 2A 32 40 01 0F. 425
17585 27 AF ED 42 38 02 CF. 782
17592 1F 2A 32 40 CD D8 09. 617
17599 2B 23 E5 3E 00 D7 E1. 809
17606 46 23 4E 23 23 E5 ED. 71[illegible]
17613 43 3E 40 CD 98 0A E1. 7[illegible]
17620 23 E5 CD 6B 0C E5 C1. 1010
17627 51 14 3E 00 28 F5 CD. [illegible]
17634 6D 0[illegible] 7E FE 00 2[illegible] 30. [illegible]
17641 FE 3F 20 05 CD 5[illegible] 08. [illegible]
17648 13 E4 FE 29 20 0A 11. [illegible]
17655 00 06 16 7A B3 20 FB. [illegible]
17662 16 1B FE 30 20 1[illegible] E1. [illegible]
17669 2A [illegible]E 40 CD [illegible] [illegible] 46. [illegible]
17676 23 4E ED 43 0A 40 ED. [illegible]
17683 43 2[illegible] 40 CD 3E 08 CF. [illegible]
17690 0C E1 E5 ED 4B 0C 40. [illegible]
17697 AF ED 42 30 F3 E1 7E. [illegible]
[illegible: remaining rows of column 3 (about 22 rows, 17704 to the foot of the column, ending with a small inverse box) double-printed/smeared on the scan]

ERROR CODES.
Z variable not found, eg., R$ in Rep, Proc name etc 4 out of memory B integer out of range, ie a number less than 0 or greater than 65535 has been used in a routine C number error, ie a number or expression has been left out or does not make sense so the computer can not change it to an integer for it to use. D break Q missing ; R too many repeats (max 17) S syntax error, eg no data or expressions T missing U until without repeat V R$ error, eg., R$ has been DIMed or is too short so that Rep and Unt can not use it. W Rand too high for LST X Proc name error, eg too short (minimum three characters or non- existant Y incorrect string variable in line after DYN
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.