Placing USR Calls

Date: 1981
Type: Program
Platform(s): ZX80

A memory-protect utility for the ZX80 with the 4K ROM. Answer the first prompt with the number of K of memory in your machine and the second with the number of bytes to reserve. The program POKEs a six-byte routine at 17152 that loads HL with a new top of memory and jumps into the ROM’s initialisation at 026BH, after the point where the ROM would have found the real memory top. The computer restarts with the bytes above that address set aside, and the BASIC program is cleared, as after NEW.

Then load or type your BASIC program (usually a machine-code loader or monitor); it is kept clear of the reserved area. The first free location is 16382-N+(1024*K). Syntax published its machine-code routines assembled for 1K, so to use them as printed answer the first prompt with 1. Later Syntax articles on loading machine code refer back to this program.

As printed, the program cannot be told about a full 16K: line 7 works out 16384+K*1024, which passes the ZX80’s integer limit of 32767 when K is 16, so it stops with report 6 (arithmetic overflow). With 16K, answer 15 and allow for the extra 1K that stays reserved above the area.

Published in Syntax June 1981 (Placing USR Calls in 4K, 8K).

Related Articles

Differences between both ROMs and machine code locations.

Related Content

Image Gallery

Source Code

   5 INPUT K
   6 INPUT N
   7 LET M=16384+(K*1024)-1-N-1
  10 POKE 17152,33
  20 POKE 17153,M-(M/256)*256
  30 POKE 17154,M/256
  40 POKE 17155,195
  50 POKE 17156,107
  60 POKE 17157,2
  70 LET X=USR(17152)

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.